Lean  $LEAN_TAG$
QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel Class Reference

Provides an implementation of IPortfolioConstructionModel that generates percent targets based on the CompanyReference.IndustryTemplateCode. The target percent holdings of each sector is 1/S where S is the number of sectors and the target percent holdings of each security is 1/N where N is the number of securities of each sector. For insights of direction InsightDirection.Up, long targets are returned and for insights of direction InsightDirection.Down, short targets are returned. It will ignore Insight for symbols that have no CompanyReference.IndustryTemplateCode value. More...

Inheritance diagram for QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel:
[legend]

Public Member Functions

 SectorWeightingPortfolioConstructionModel (IDateRule rebalancingDateRules)
 Initialize a new instance of SectorWeightingPortfolioConstructionModel More...
 
 SectorWeightingPortfolioConstructionModel (Func< DateTime, DateTime?> rebalancingFunc)
 Initialize a new instance of SectorWeightingPortfolioConstructionModel More...
 
 SectorWeightingPortfolioConstructionModel (Func< DateTime, DateTime > rebalancingFunc)
 Initialize a new instance of SectorWeightingPortfolioConstructionModel More...
 
 SectorWeightingPortfolioConstructionModel (PyObject rebalance)
 Initialize a new instance of SectorWeightingPortfolioConstructionModel More...
 
 SectorWeightingPortfolioConstructionModel (TimeSpan timeSpan)
 Initialize a new instance of SectorWeightingPortfolioConstructionModel More...
 
 SectorWeightingPortfolioConstructionModel (Resolution resolution=Resolution.Daily)
 Initialize a new instance of SectorWeightingPortfolioConstructionModel More...
 
override void OnSecuritiesChanged (QCAlgorithm algorithm, SecurityChanges changes)
 Event fired each time the we add/remove securities from the data feed More...
 
- Public Member Functions inherited from QuantConnect.Algorithm.Framework.Portfolio.EqualWeightingPortfolioConstructionModel
 EqualWeightingPortfolioConstructionModel (IDateRule rebalancingDateRules, PortfolioBias portfolioBias=PortfolioBias.LongShort)
 Initialize a new instance of EqualWeightingPortfolioConstructionModel More...
 
 EqualWeightingPortfolioConstructionModel (Func< DateTime, DateTime?> rebalancingFunc, PortfolioBias portfolioBias=PortfolioBias.LongShort)
 Initialize a new instance of EqualWeightingPortfolioConstructionModel More...
 
 EqualWeightingPortfolioConstructionModel (Func< DateTime, DateTime > rebalancingFunc, PortfolioBias portfolioBias=PortfolioBias.LongShort)
 Initialize a new instance of EqualWeightingPortfolioConstructionModel More...
 
 EqualWeightingPortfolioConstructionModel (PyObject rebalance, PortfolioBias portfolioBias=PortfolioBias.LongShort)
 Initialize a new instance of EqualWeightingPortfolioConstructionModel More...
 
 EqualWeightingPortfolioConstructionModel (TimeSpan timeSpan, PortfolioBias portfolioBias=PortfolioBias.LongShort)
 Initialize a new instance of EqualWeightingPortfolioConstructionModel More...
 
 EqualWeightingPortfolioConstructionModel (Resolution resolution=Resolution.Daily, PortfolioBias portfolioBias=PortfolioBias.LongShort)
 Initialize a new instance of EqualWeightingPortfolioConstructionModel More...
 
- Public Member Functions inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
 PortfolioConstructionModel (Func< DateTime, DateTime?> rebalancingFunc)
 Initialize a new instance of PortfolioConstructionModel More...
 
 PortfolioConstructionModel (Func< DateTime, DateTime > rebalancingFunc=null)
 Initialize a new instance of PortfolioConstructionModel More...
 
virtual IEnumerable< IPortfolioTargetCreateTargets (QCAlgorithm algorithm, Insight[] insights)
 Create portfolio targets from the specified insights More...
 

Protected Member Functions

override bool ShouldCreateTargetForInsight (Insight insight)
 Method that will determine if the portfolio construction model should create a target for this insight More...
 
override Dictionary< Insight, double > DetermineTargetPercent (List< Insight > activeInsights)
 Will determine the target percent for each insight More...
 
virtual string GetSectorCode (Security security)
 Gets the sector code More...
 
- Protected Member Functions inherited from QuantConnect.Algorithm.Framework.Portfolio.EqualWeightingPortfolioConstructionModel
bool RespectPortfolioBias (Insight insight)
 Method that will determine if a given insight respects the portfolio bias More...
 
- Protected Member Functions inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
void SetPythonWrapper (PortfolioConstructionModelPythonWrapper pythonWrapper)
 Used to set the PortfolioConstructionModelPythonWrapper instance if any More...
 
virtual List< InsightGetTargetInsights ()
 Gets the target insights to calculate a portfolio target percent for More...
 
void SetRebalancingFunc (PyObject rebalance)
 Python helper method to set the rebalancing function. This is required due to a python net limitation not being able to use the base type constructor, and also because when python algorithms use C# portfolio construction models, it can't convert python methods into func nor resolve the correct constructor for the date rules, timespan parameter. For performance we prefer python algorithms using the C# implementation More...
 
virtual bool IsRebalanceDue (Insight[] insights, DateTime algorithmUtc)
 Determines if the portfolio should be rebalanced base on the provided rebalancing func, if any security change have been taken place or if an insight has expired or a new insight arrived If the rebalancing function has not been provided will return true. More...
 
void RefreshRebalance (DateTime algorithmUtc)
 Refresh the next rebalance time and clears the security changes flag More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
static Insight[] FilterInvalidInsightMagnitude (IAlgorithm algorithm, Insight[] insights)
 Helper class that can be used by the different IPortfolioConstructionModel implementations to filter Insight instances with an invalid Insight.Magnitude value based on the IAlgorithmSettings More...
 
- Protected Attributes inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
PortfolioConstructionModelPythonWrapper PythonWrapper
 This is required due to a limitation in PythonNet to resolved overriden methods. When Python calls a C# method that calls a method that's overriden in python it won't run the python implementation unless the call is performed through python too. More...
 
- Properties inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
virtual bool RebalanceOnSecurityChanges = true [get, set]
 True if should rebalance portfolio on security changes. True by default More...
 
virtual bool RebalanceOnInsightChanges = true [get, set]
 True if should rebalance portfolio on new insights or expiration of insights. True by default More...
 
IAlgorithm Algorithm [get]
 The algorithm instance More...
 

Detailed Description

Provides an implementation of IPortfolioConstructionModel that generates percent targets based on the CompanyReference.IndustryTemplateCode. The target percent holdings of each sector is 1/S where S is the number of sectors and the target percent holdings of each security is 1/N where N is the number of securities of each sector. For insights of direction InsightDirection.Up, long targets are returned and for insights of direction InsightDirection.Down, short targets are returned. It will ignore Insight for symbols that have no CompanyReference.IndustryTemplateCode value.

Definition at line 37 of file SectorWeightingPortfolioConstructionModel.cs.

Constructor & Destructor Documentation

◆ SectorWeightingPortfolioConstructionModel() [1/6]

QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.SectorWeightingPortfolioConstructionModel ( IDateRule  rebalancingDateRules)

Initialize a new instance of SectorWeightingPortfolioConstructionModel

Parameters
rebalancingDateRulesThe date rules used to define the next expected rebalance time in UTC

Definition at line 46 of file SectorWeightingPortfolioConstructionModel.cs.

◆ SectorWeightingPortfolioConstructionModel() [2/6]

QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.SectorWeightingPortfolioConstructionModel ( Func< DateTime, DateTime?>  rebalancingFunc)

Initialize a new instance of SectorWeightingPortfolioConstructionModel

Parameters
rebalancingFuncFor a given algorithm UTC DateTime returns the next expected rebalance time or null if unknown, in which case the function will be called again in the next loop. Returning current time will trigger rebalance. If null will be ignored

Definition at line 57 of file SectorWeightingPortfolioConstructionModel.cs.

◆ SectorWeightingPortfolioConstructionModel() [3/6]

QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.SectorWeightingPortfolioConstructionModel ( Func< DateTime, DateTime >  rebalancingFunc)

Initialize a new instance of SectorWeightingPortfolioConstructionModel

Parameters
rebalancingFuncFor a given algorithm UTC DateTime returns the next expected rebalance UTC time. Returning current time will trigger rebalance. If null will be ignored

Definition at line 67 of file SectorWeightingPortfolioConstructionModel.cs.

◆ SectorWeightingPortfolioConstructionModel() [4/6]

QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.SectorWeightingPortfolioConstructionModel ( PyObject  rebalance)

Initialize a new instance of SectorWeightingPortfolioConstructionModel

Parameters
rebalanceRebalancing func or if a date rule, timedelta will be converted into func. For a given algorithm UTC DateTime the func returns the next expected rebalance time or null if unknown, in which case the function will be called again in the next loop. Returning current time will trigger rebalance. If null will be ignored

This is required since python net can not convert python methods into func nor resolve the correct constructor for the date rules parameter. For performance we prefer python algorithms using the C# implementation

Definition at line 82 of file SectorWeightingPortfolioConstructionModel.cs.

Here is the call graph for this function:

◆ SectorWeightingPortfolioConstructionModel() [5/6]

QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.SectorWeightingPortfolioConstructionModel ( TimeSpan  timeSpan)

Initialize a new instance of SectorWeightingPortfolioConstructionModel

Parameters
timeSpanRebalancing frequency

Definition at line 92 of file SectorWeightingPortfolioConstructionModel.cs.

◆ SectorWeightingPortfolioConstructionModel() [6/6]

QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.SectorWeightingPortfolioConstructionModel ( Resolution  resolution = Resolution.Daily)

Initialize a new instance of SectorWeightingPortfolioConstructionModel

Parameters
resolutionRebalancing frequency

Definition at line 101 of file SectorWeightingPortfolioConstructionModel.cs.

Member Function Documentation

◆ ShouldCreateTargetForInsight()

override bool QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.ShouldCreateTargetForInsight ( Insight  insight)
protectedvirtual

Method that will determine if the portfolio construction model should create a target for this insight

Parameters
insightThe insight to create a target for
Returns
True if the portfolio should create a target for the insight

Reimplemented from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.

Definition at line 112 of file SectorWeightingPortfolioConstructionModel.cs.

◆ DetermineTargetPercent()

override Dictionary<Insight, double> QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.DetermineTargetPercent ( List< Insight activeInsights)
protectedvirtual

Will determine the target percent for each insight

Parameters
activeInsightsThe active insights to generate a target for
Returns
A target percent for each insight

Reimplemented from QuantConnect.Algorithm.Framework.Portfolio.EqualWeightingPortfolioConstructionModel.

Definition at line 122 of file SectorWeightingPortfolioConstructionModel.cs.

◆ OnSecuritiesChanged()

override void QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.OnSecuritiesChanged ( QCAlgorithm  algorithm,
SecurityChanges  changes 
)
virtual

Event fired each time the we add/remove securities from the data feed

Parameters
algorithmThe algorithm instance that experienced the change in securities
changesThe security additions and removals from the algorithm

Reimplemented from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.

Definition at line 173 of file SectorWeightingPortfolioConstructionModel.cs.

Here is the call graph for this function:

◆ GetSectorCode()

virtual string QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.GetSectorCode ( Security  security)
protectedvirtual

Gets the sector code

Parameters
securityThe security to create a sector code for
Returns
The value of the sector code for the security

Other sectors can be defined using AssetClassification

Definition at line 203 of file SectorWeightingPortfolioConstructionModel.cs.

Here is the caller graph for this function:

The documentation for this class was generated from the following file: