Back

Question about the Bootcamp lesson :Sector Weighted Portfolio Construction

Hi, I have a question about the new Bootcamp lesson. In the final walkthrough of this tutorial, it's written:

Finally, iterate through the insights and multiply the equal weight by the insight direction to return a target percent, and save as a value in self.result. Through inheritance, the target percent is turned into a target number of shares (Portfolio Targets) and delivered to the execution model.

Why is the target percent is turned into a target number of shares due to inheritance? I do not see any call to the parent DetermineTargetPercent() function. Or is the parent function is automatically called? But if this the case, how is the self.result from the current class being taken into account by the parent class since the parent class should not be able to access its child class instance in my knowledge. I tried to use the debugger and read through the codes in Github but I couldn't find an answer. 

Also, is it legitimate to do self.result[insight] = insight.Direction * self.percent? So in this case, this value is acting in some sense like the magnitude property of the insight?

Any kind of help is appreciated. Thank you.

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.


Hi Chai Jiazheng ,

Great question!
DetermineTargetPercent is a virtual method of PortfolioConstructionModel (PCM) (that serves as a parent class for all portfolio construction models) that determine the target percent for each security. It is called by the CreateTargets method where the percentages are converted into shares (PortfolioTarget object).

SectorWeightingPortfolioConstructionModel (SWPCM) inherits PCM implementation, overrides DetermineTargetPercent and OnSecuritiesChanged method.

Here is the relevant part of the stack:
1. AlphaModel creates Insights with Update method:

var insightsEnumerable = Alpha.Update(this, slice);

2. SectorWeightingPortfolioConstructionModel create portfolio targets with CreateTargets method (implemented in PCM): 

var targetsEnumerable = PortfolioConstruction.CreateTargets(this, insights);
// where insights is insightsEnumerable and PortfolioConstruction is SWPCM

3. In CreateTargets, DetermineTargetPercent is called:

public virtual IEnumerable<IPortfolioTarget> CreateTargets(
QCAlgorithm algorithm,
Insight[] insights)
{
// other statements and lastActiveInsights definition

var percents = DetermineTargetPercent(lastActiveInsights); // <===

foreach (var insight in lastActiveInsights)
{
// Not exactly the next three statements. Just to keep it simple.
percent = percents[insight.Symbol];

// Convert the percentage to a PortfolioTarget (Symbol/Quantity pair)
var target = PortfolioTarget.Percent(algorithm, insight.Symbol, percent);
targets.Add(target);
}

// other statements
return targets;
}

4. Finally, targetsEnumerable will be risk-adjusted by the RiskModel and used by the ExecutionModel to place orders. 

2

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