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

Provides an implementation of IPortfolioConstructionModel that wraps a PyObject object More...

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

Public Member Functions

 PortfolioConstructionModelPythonWrapper (PyObject model)
 Constructor for initialising the IPortfolioConstructionModel class with wrapped PyObject object More...
 
override IEnumerable< IPortfolioTargetCreateTargets (QCAlgorithm algorithm, Insight[] insights)
 Create portfolio targets from the specified insights 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.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...
 

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 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...
 
override List< InsightGetTargetInsights ()
 Gets the target insights to calculate a portfolio target percent for More...
 
override Dictionary< Insight, double > DetermineTargetPercent (List< Insight > activeInsights)
 Will determine the target percent for each insight More...
 
- Protected Member Functions inherited from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel
void SetPythonWrapper (PortfolioConstructionModelPythonWrapper pythonWrapper)
 Used to set the PortfolioConstructionModelPythonWrapper instance if any 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...
 
void RefreshRebalance (DateTime algorithmUtc)
 Refresh the next rebalance time and clears the security changes flag More...
 

Properties

override bool RebalanceOnSecurityChanges [get, set]
 True if should rebalance portfolio on security changes. True by default More...
 
override bool RebalanceOnInsightChanges [get, set]
 True if should rebalance portfolio on new insights or expiration of insights. True by default 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...
 

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...
 

Detailed Description

Provides an implementation of IPortfolioConstructionModel that wraps a PyObject object

Definition at line 28 of file PortfolioConstructionModelPythonWrapper.cs.

Constructor & Destructor Documentation

◆ PortfolioConstructionModelPythonWrapper()

QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.PortfolioConstructionModelPythonWrapper ( PyObject  model)

Constructor for initialising the IPortfolioConstructionModel class with wrapped PyObject object

Parameters
modelModel defining how to build a portfolio from alphas

Definition at line 67 of file PortfolioConstructionModelPythonWrapper.cs.

Here is the call graph for this function:

Member Function Documentation

◆ CreateTargets()

override IEnumerable<IPortfolioTarget> QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.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

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

Definition at line 92 of file PortfolioConstructionModelPythonWrapper.cs.

◆ OnSecuritiesChanged()

override void QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.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 102 of file PortfolioConstructionModelPythonWrapper.cs.

◆ ShouldCreateTargetForInsight()

override bool QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.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 113 of file PortfolioConstructionModelPythonWrapper.cs.

Here is the caller graph for this function:

◆ IsRebalanceDue()

override bool QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.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 from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.

Definition at line 126 of file PortfolioConstructionModelPythonWrapper.cs.

◆ GetTargetInsights()

override List<Insight> QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.GetTargetInsights ( )
protectedvirtual

Gets the target insights to calculate a portfolio target percent for

Returns
An enumerable of the target insights

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

Definition at line 135 of file PortfolioConstructionModelPythonWrapper.cs.

Here is the caller graph for this function:

◆ DetermineTargetPercent()

override Dictionary<Insight, double> QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.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.PortfolioConstructionModel.

Definition at line 145 of file PortfolioConstructionModelPythonWrapper.cs.

Here is the caller graph for this function:

Property Documentation

◆ RebalanceOnSecurityChanges

override bool QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.RebalanceOnSecurityChanges
getset

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

Definition at line 37 of file PortfolioConstructionModelPythonWrapper.cs.

◆ RebalanceOnInsightChanges

override bool QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.RebalanceOnInsightChanges
getset

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

Definition at line 52 of file PortfolioConstructionModelPythonWrapper.cs.


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