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

Implementation of On-Line Moving Average Reversion (OLMAR) More...

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

Public Member Functions

 MeanReversionPortfolioConstructionModel (IDateRule rebalancingDateRules, PortfolioBias portfolioBias=PortfolioBias.LongShort, decimal reversionThreshold=1, int windowSize=20, Resolution resolution=Resolution.Daily)
 Initializes a new instance of the MeanReversionPortfolioConstructionModel class More...
 
 MeanReversionPortfolioConstructionModel (Resolution rebalanceResolution=Resolution.Daily, PortfolioBias portfolioBias=PortfolioBias.LongShort, decimal reversionThreshold=1, int windowSize=20, Resolution resolution=Resolution.Daily)
 Initializes a new instance of the MeanReversionPortfolioConstructionModel class More...
 
 MeanReversionPortfolioConstructionModel (TimeSpan timeSpan, PortfolioBias portfolioBias=PortfolioBias.LongShort, decimal reversionThreshold=1, int windowSize=20, Resolution resolution=Resolution.Daily)
 Initializes a new instance of the MeanReversionPortfolioConstructionModel class More...
 
 MeanReversionPortfolioConstructionModel (PyObject rebalance, PortfolioBias portfolioBias=PortfolioBias.LongShort, decimal reversionThreshold=1, int windowSize=20, Resolution resolution=Resolution.Daily)
 Initializes a new instance of the MeanReversionPortfolioConstructionModel class More...
 
 MeanReversionPortfolioConstructionModel (Func< DateTime, DateTime > rebalancingFunc, PortfolioBias portfolioBias=PortfolioBias.LongShort, decimal reversionThreshold=1, int windowSize=20, Resolution resolution=Resolution.Daily)
 Initializes a new instance of the MeanReversionPortfolioConstructionModel class More...
 
 MeanReversionPortfolioConstructionModel (Func< DateTime, DateTime?> rebalancingFunc, PortfolioBias portfolioBias=PortfolioBias.LongShort, decimal reversionThreshold=1, int windowSize=20, Resolution resolution=Resolution.Daily)
 Initializes a new instance of the MeanReversionPortfolioConstructionModel class 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...
 
virtual IEnumerable< IPortfolioTargetCreateTargets (QCAlgorithm algorithm, Insight[] insights)
 Create portfolio targets from the specified insights More...
 

Static Public Member Functions

static IEnumerable< double > CumulativeSum (IEnumerable< double > sequence)
 Cumulative Sum of a given sequence More...
 
static double[] SimplexProjection (IEnumerable< double > vector, double total=1)
 Normalize the updated portfolio into weight vector: v_{t+1} = arg min || v - v_{t+1} || ^ 2 More...
 

Protected Member Functions

override Dictionary< Insight, double > DetermineTargetPercent (List< Insight > activeInsights)
 Will determine the target percent for each insight More...
 
virtual double[] GetPriceRelatives (List< Insight > activeInsights)
 Get price relatives with reference level of SMA 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...
 
virtual bool ShouldCreateTargetForInsight (Insight insight)
 Method that will determine if the portfolio construction model should create a target for this 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...
 

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

Implementation of On-Line Moving Average Reversion (OLMAR)

Li, B., Hoi, S. C. (2012). On-line portfolio selection with moving average reversion. arXiv preprint arXiv:1206.4626. Available at https://arxiv.org/ftp/arxiv/papers/1206/1206.4626.pdf

Using windowSize = 1 => Passive Aggressive Mean Reversion (PAMR) Portfolio

Definition at line 35 of file MeanReversionPortfolioConstructionModel.cs.

Constructor & Destructor Documentation

◆ MeanReversionPortfolioConstructionModel() [1/6]

QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel.MeanReversionPortfolioConstructionModel ( IDateRule  rebalancingDateRules,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
decimal  reversionThreshold = 1,
int  windowSize = 20,
Resolution  resolution = Resolution.Daily 
)

Initializes a new instance of the MeanReversionPortfolioConstructionModel class

Parameters
rebalancingDateRulesThe date rules used to define the next expected rebalance time in UTC
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
reversionThresholdReversion threshold
windowSizeWindow size of mean price
resolutionThe resolution of the history price and rebalancing

Definition at line 53 of file MeanReversionPortfolioConstructionModel.cs.

◆ MeanReversionPortfolioConstructionModel() [2/6]

QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel.MeanReversionPortfolioConstructionModel ( Resolution  rebalanceResolution = Resolution.Daily,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
decimal  reversionThreshold = 1,
int  windowSize = 20,
Resolution  resolution = Resolution.Daily 
)

Initializes a new instance of the MeanReversionPortfolioConstructionModel class

Parameters
rebalanceResolutionRebalancing frequency
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
reversionThresholdReversion threshold
windowSizeWindow size of mean price
resolutionThe resolution of the history price and rebalancing

Definition at line 70 of file MeanReversionPortfolioConstructionModel.cs.

◆ MeanReversionPortfolioConstructionModel() [3/6]

QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel.MeanReversionPortfolioConstructionModel ( TimeSpan  timeSpan,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
decimal  reversionThreshold = 1,
int  windowSize = 20,
Resolution  resolution = Resolution.Daily 
)

Initializes a new instance of the MeanReversionPortfolioConstructionModel class

Parameters
timeSpanRebalancing frequency
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
reversionThresholdReversion threshold
windowSizeWindow size of mean price
resolutionThe resolution of the history price and rebalancing

Definition at line 87 of file MeanReversionPortfolioConstructionModel.cs.

◆ MeanReversionPortfolioConstructionModel() [4/6]

QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel.MeanReversionPortfolioConstructionModel ( PyObject  rebalance,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
decimal  reversionThreshold = 1,
int  windowSize = 20,
Resolution  resolution = Resolution.Daily 
)

Initializes a new instance of the MeanReversionPortfolioConstructionModel class

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
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
reversionThresholdReversion threshold
windowSizeWindow size of mean price
resolutionThe resolution of the history price and rebalancing

Definition at line 107 of file MeanReversionPortfolioConstructionModel.cs.

Here is the call graph for this function:

◆ MeanReversionPortfolioConstructionModel() [5/6]

QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel.MeanReversionPortfolioConstructionModel ( Func< DateTime, DateTime >  rebalancingFunc,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
decimal  reversionThreshold = 1,
int  windowSize = 20,
Resolution  resolution = Resolution.Daily 
)

Initializes a new instance of the MeanReversionPortfolioConstructionModel class

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

will trigger rebalance. If null will be ignored

Parameters
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
reversionThresholdReversion threshold
windowSizeWindow size of mean price
resolutionThe resolution of the history price and rebalancing

Definition at line 127 of file MeanReversionPortfolioConstructionModel.cs.

◆ MeanReversionPortfolioConstructionModel() [6/6]

QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel.MeanReversionPortfolioConstructionModel ( Func< DateTime, DateTime?>  rebalancingFunc,
PortfolioBias  portfolioBias = PortfolioBias.LongShort,
decimal  reversionThreshold = 1,
int  windowSize = 20,
Resolution  resolution = Resolution.Daily 
)

Initializes a new instance of the MeanReversionPortfolioConstructionModel class

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.
portfolioBiasSpecifies the bias of the portfolio (Short, Long/Short, Long)
reversionThresholdReversion threshold
windowSizeWindow size of mean price
resolutionThe resolution of the history price and rebalancing

Definition at line 147 of file MeanReversionPortfolioConstructionModel.cs.

Member Function Documentation

◆ DetermineTargetPercent()

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

Will determine the target percent for each insight

Parameters
activeInsightslist of active insights

<return>dictionary of insight and respective target weight</return>

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

Definition at line 169 of file MeanReversionPortfolioConstructionModel.cs.

Here is the call graph for this function:

◆ GetPriceRelatives()

virtual double [] QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel.GetPriceRelatives ( List< Insight activeInsights)
protectedvirtual

Get price relatives with reference level of SMA

Parameters
activeInsightslist of active insights

<return>array of price relatives vector</return>

Definition at line 231 of file MeanReversionPortfolioConstructionModel.cs.

Here is the caller graph for this function:

◆ OnSecuritiesChanged()

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

◆ CumulativeSum()

static IEnumerable<double> QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel.CumulativeSum ( IEnumerable< double >  sequence)
static

Cumulative Sum of a given sequence

Parameters
sequencesequence to obtain cumulative sum

<return>cumulative sum</return>

Definition at line 284 of file MeanReversionPortfolioConstructionModel.cs.

Here is the caller graph for this function:

◆ SimplexProjection()

static double [] QuantConnect.Algorithm.Framework.Portfolio.MeanReversionPortfolioConstructionModel.SimplexProjection ( IEnumerable< double >  vector,
double  total = 1 
)
static

Normalize the updated portfolio into weight vector: v_{t+1} = arg min || v - v_{t+1} || ^ 2

<remark>Duchi, J., Shalev-Shwartz, S., Singer, Y., and Chandra, T. (2008, July). Efficient projections onto the l1-ball for learning in high dimensions. In Proceedings of the 25th international conference on Machine learning (pp. 272-279).</remark>

Parameters
vectorunnormalized weight vector
totalregulator, default to be 1, making it a probabilistic simplex

<return>normalized weight vector</return>

Definition at line 304 of file MeanReversionPortfolioConstructionModel.cs.

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

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