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

Provides a base class for portfolio construction models More...

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

Public Member Functions

 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...
 
virtual void OnSecuritiesChanged (QCAlgorithm algorithm, SecurityChanges changes)
 Event fired each time the we add/remove securities from the data feed More...
 

Protected Member Functions

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...
 
virtual bool ShouldCreateTargetForInsight (Insight insight)
 Method that will determine if the portfolio construction model should create a target for this insight More...
 
virtual Dictionary< Insight, double > DetermineTargetPercent (List< Insight > activeInsights)
 Will determine the target percent for each insight 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...
 

Static Protected Member Functions

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

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

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 a base class for portfolio construction models

Definition at line 30 of file PortfolioConstructionModel.cs.

Constructor & Destructor Documentation

◆ PortfolioConstructionModel() [1/2]

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

Initialize a new instance of PortfolioConstructionModel

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 64 of file PortfolioConstructionModel.cs.

◆ PortfolioConstructionModel() [2/2]

QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.PortfolioConstructionModel ( Func< DateTime, DateTime >  rebalancingFunc = null)

Initialize a new instance of PortfolioConstructionModel

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 74 of file PortfolioConstructionModel.cs.

Member Function Documentation

◆ SetPythonWrapper()

void QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.SetPythonWrapper ( PortfolioConstructionModelPythonWrapper  pythonWrapper)
protected

Used to set the PortfolioConstructionModelPythonWrapper instance if any

Definition at line 82 of file PortfolioConstructionModel.cs.

Here is the caller graph for this function:

◆ CreateTargets()

virtual IEnumerable<IPortfolioTarget> QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.CreateTargets ( QCAlgorithm  algorithm,
Insight[]  insights 
)
virtual

Create portfolio targets from the specified insights

Parameters
algorithmThe algorithm instance
insightsThe insights to create portfolio targets from
Returns
An enumerable of portfolio targets to be sent to the execution model

Implements QuantConnect.Algorithm.Framework.Portfolio.IPortfolioConstructionModel.

Reimplemented in QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper, and QuantConnect.Algorithm.Framework.Portfolio.NullPortfolioConstructionModel.

Definition at line 93 of file PortfolioConstructionModel.cs.

Here is the call graph for this function:

◆ OnSecuritiesChanged()

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

◆ GetTargetInsights()

virtual List<Insight> QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.GetTargetInsights ( )
protectedvirtual

Gets the target insights to calculate a portfolio target percent for

Returns
An enumerable of the target insights

Reimplemented in QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.AccumulativeInsightPortfolioConstructionModel, and QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.

Definition at line 164 of file PortfolioConstructionModel.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShouldCreateTargetForInsight()

virtual bool QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.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 in QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.MeanVarianceOptimizationPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.InsightWeightingPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.ConfidenceWeightedPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper, and QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel.

Definition at line 185 of file PortfolioConstructionModel.cs.

Here is the caller graph for this function:

◆ DetermineTargetPercent()

◆ SetRebalancingFunc()

void QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.SetRebalancingFunc ( PyObject  rebalance)
protected

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

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

Definition at line 211 of file PortfolioConstructionModel.cs.

Here is the caller graph for this function:

◆ IsRebalanceDue()

virtual bool QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.IsRebalanceDue ( Insight[]  insights,
DateTime  algorithmUtc 
)
protectedvirtual

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.

Parameters
insightsThe insights to create portfolio targets from
algorithmUtcThe current algorithm UTC time
Returns
True if should rebalance

Reimplemented in QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.

Definition at line 248 of file PortfolioConstructionModel.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RefreshRebalance()

void QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.RefreshRebalance ( DateTime  algorithmUtc)
protected

Refresh the next rebalance time and clears the security changes flag

Definition at line 294 of file PortfolioConstructionModel.cs.

Here is the caller graph for this function:

◆ FilterInvalidInsightMagnitude()

static Insight [] QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.FilterInvalidInsightMagnitude ( IAlgorithm  algorithm,
Insight[]  insights 
)
staticprotected

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

Parameters
algorithmThe algorithm instance
insightsThe insight collection to filter
Returns
Returns a new array of insights removing invalid ones

Definition at line 311 of file PortfolioConstructionModel.cs.

Here is the caller graph for this function:

Member Data Documentation

◆ PythonWrapper

PortfolioConstructionModelPythonWrapper QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.PythonWrapper
protected

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.

Definition at line 56 of file PortfolioConstructionModel.cs.

Property Documentation

◆ RebalanceOnSecurityChanges

virtual bool QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.RebalanceOnSecurityChanges = true
getset

True if should rebalance portfolio on security changes. True by default

Definition at line 39 of file PortfolioConstructionModel.cs.

◆ RebalanceOnInsightChanges

virtual bool QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.RebalanceOnInsightChanges = true
getset

True if should rebalance portfolio on new insights or expiration of insights. True by default

Definition at line 44 of file PortfolioConstructionModel.cs.

◆ Algorithm

IAlgorithm QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.Algorithm
getprotected

The algorithm instance

Definition at line 49 of file PortfolioConstructionModel.cs.


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