Back

Making a market capitalization weighted portfolio constrution model

I'm inheriting from PortfolioConstructionModel and want to give each security a target percentage based on the security's market cap. However I'm not sure how to get access to the security within the DetermineTargetPercent method that I'm overriding as it doesn't pass in the QCAlgorithm instance, only the list of insights.

Update Backtest







0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


I think I'll need to maintain state in my portfolio construction model class to store the securities, and update this state in the OnSecuritiesChanges method.

0

I also realized the PortfolioConstructionModel sets a protected property for the algorithm instance on itself so subclasses can access it.

0

Hi Mark,

We can track the market cap of the securities in our universe via fine universe selection. We can then create a portfolio construction model that scales the holding weights by accessing the market cap values stored in the algorithm class.

def CreateTargets(self, algorithm, insights):
market_cap_sum = 0
for market_cap in self.algo.market_cap_by_symbol.values():
market_cap_sum += market_cap

targets = []
for symbol in self.symbols:
pct = self.algo.market_cap_by_symbol[symbol] / market_cap_sum
target = PortfolioTarget.Percent(algorithm, symbol, pct)
targets.append(target)
return targets

See the attached backtest for a full example of this.

Best,
Derek Melchin

1

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed