|
Lean
$LEAN_TAG$
|
Provides a base class for portfolio construction models More...
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< IPortfolioTarget > | CreateTargets (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< Insight > | GetTargetInsights () |
| 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... | |
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... | |
| PortfolioConstructionModelPythonWrapper | PythonWrapper [get, set] |
| 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... | |
Provides a base class for portfolio construction models
Definition at line 30 of file PortfolioConstructionModel.cs.
| QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.PortfolioConstructionModel | ( | Func< DateTime, DateTime?> | rebalancingFunc | ) |
Initialize a new instance of PortfolioConstructionModel
| rebalancingFunc | For 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.
| QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.PortfolioConstructionModel | ( | Func< DateTime, DateTime > | rebalancingFunc = null | ) |
Initialize a new instance of PortfolioConstructionModel
| rebalancingFunc | For 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.
|
protected |
Used to set the PortfolioConstructionModelPythonWrapper instance if any
Definition at line 82 of file PortfolioConstructionModel.cs.
|
virtual |
Create portfolio targets from the specified insights
| algorithm | The algorithm instance |
| insights | The insights to create portfolio targets from |
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.
|
virtual |
Event fired each time the we add/remove securities from the data feed
| algorithm | The algorithm instance that experienced the change in securities |
| changes | The security additions and removals from the algorithm |
Implements QuantConnect.Algorithm.Framework.INotifiedSecurityChanges.
Reimplemented in QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.MeanVarianceOptimizationPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.RiskParityPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel, and QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.
Definition at line 150 of file PortfolioConstructionModel.cs.
|
protectedvirtual |
Gets the target insights to calculate a portfolio target percent for
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.
|
protectedvirtual |
Method that will determine if the portfolio construction model should create a target for this insight
| insight | The insight to create a target for |
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.
|
protectedvirtual |
Will determine the target percent for each insight
| activeInsights | The active insights to generate a target for |
Reimplemented in QuantConnect.Algorithm.Framework.Portfolio.BlackLittermanOptimizationPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.MeanVarianceOptimizationPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.RiskParityPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.AccumulativeInsightPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper, QuantConnect.Algorithm.Framework.Portfolio.InsightWeightingPortfolioConstructionModel, QuantConnect.Algorithm.Framework.Portfolio.SectorWeightingPortfolioConstructionModel, and QuantConnect.Algorithm.Framework.Portfolio.EqualWeightingPortfolioConstructionModel.
Definition at line 195 of file PortfolioConstructionModel.cs.
|
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
| rebalance | Rebalancing 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.
|
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.
| insights | The insights to create portfolio targets from |
| algorithmUtc | The current algorithm UTC time |
Reimplemented in QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.
Definition at line 248 of file PortfolioConstructionModel.cs.
|
protected |
Refresh the next rebalance time and clears the security changes flag
Definition at line 294 of file PortfolioConstructionModel.cs.
|
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
| algorithm | The algorithm instance |
| insights | The insight collection to filter |
Definition at line 311 of file PortfolioConstructionModel.cs.
|
getset |
True if should rebalance portfolio on security changes. True by default
Definition at line 39 of file PortfolioConstructionModel.cs.
|
getset |
True if should rebalance portfolio on new insights or expiration of insights. True by default
Definition at line 44 of file PortfolioConstructionModel.cs.
|
getprotected |
The algorithm instance
Definition at line 49 of file PortfolioConstructionModel.cs.
|
getsetprotected |
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.