To weight each stock proportional to its market cap use the TargetWeightWeights
objective. You know the weights you want to assign so that is the objective to use and not MaximizeAlpha
.
The MaximizeAlpha
objective is best used when you have a factor which one feels is proportional to the outcome one wants. If one wants high returns then that factor should be proportional to returns, If one wants a high sharpe ratio then that factor should be proportional to the sharpe ratio. Typically this objective starts with the highest alpha value, orders as much of that until some constraint is reached, and then begins ordering the second highest alpha and so forth. It generally will end up ordering only a small subset of the universe.
One can set the weight as a percent of the total market cap inside the pipeline definition by using the recently added summary methods (see the docs here) Something like this
def make_pipeline():
# Gets the latest market cap.
mkt_cap = morningstar.valuation.market_cap.latest
screen = mkt_cap.top(1000, mask=(QTradableStocksUS()))
# Weight each of the top 1000 by their market cap
total_market_cap = mkt_cap.sum(mask=screen)
weight = mkt_cap / total_market_cap
return Pipeline(
columns={
'mkt_cap': mkt_cap,
'weight': weight,
},
domain=US_EQUITIES,
screen=screen,
)
Then simply use the 'weight' column as the target weight in TargetWeightWeights
objective. See the attached backtest. Good luck.
Disclaimer
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.