Lean
$LEAN_TAG$
|
Implementation of On-Line Moving Average Reversion (OLMAR) More...
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< IPortfolioTarget > | CreateTargets (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< 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... | |
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... | |
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.
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
rebalancingDateRules | The date rules used to define the next expected rebalance time in UTC |
portfolioBias | Specifies the bias of the portfolio (Short, Long/Short, Long) |
reversionThreshold | Reversion threshold |
windowSize | Window size of mean price |
resolution | The resolution of the history price and rebalancing |
Definition at line 53 of file MeanReversionPortfolioConstructionModel.cs.
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
rebalanceResolution | Rebalancing frequency |
portfolioBias | Specifies the bias of the portfolio (Short, Long/Short, Long) |
reversionThreshold | Reversion threshold |
windowSize | Window size of mean price |
resolution | The resolution of the history price and rebalancing |
Definition at line 70 of file MeanReversionPortfolioConstructionModel.cs.
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
timeSpan | Rebalancing frequency |
portfolioBias | Specifies the bias of the portfolio (Short, Long/Short, Long) |
reversionThreshold | Reversion threshold |
windowSize | Window size of mean price |
resolution | The resolution of the history price and rebalancing |
Definition at line 87 of file MeanReversionPortfolioConstructionModel.cs.
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
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 |
portfolioBias | Specifies the bias of the portfolio (Short, Long/Short, Long) |
reversionThreshold | Reversion threshold |
windowSize | Window size of mean price |
resolution | The resolution of the history price and rebalancing |
Definition at line 107 of file MeanReversionPortfolioConstructionModel.cs.
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
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 |
will trigger rebalance. If null will be ignored
portfolioBias | Specifies the bias of the portfolio (Short, Long/Short, Long) |
reversionThreshold | Reversion threshold |
windowSize | Window size of mean price |
resolution | The resolution of the history price and rebalancing |
Definition at line 127 of file MeanReversionPortfolioConstructionModel.cs.
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
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. |
portfolioBias | Specifies the bias of the portfolio (Short, Long/Short, Long) |
reversionThreshold | Reversion threshold |
windowSize | Window size of mean price |
resolution | The resolution of the history price and rebalancing |
Definition at line 147 of file MeanReversionPortfolioConstructionModel.cs.
|
protectedvirtual |
Will determine the target percent for each insight
activeInsights | list 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.
|
protectedvirtual |
Get price relatives with reference level of SMA
activeInsights | list of active insights |
<return>array of price relatives vector</return>
Definition at line 231 of file MeanReversionPortfolioConstructionModel.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 |
Reimplemented from QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModel.
Definition at line 256 of file MeanReversionPortfolioConstructionModel.cs.
|
static |
Cumulative Sum of a given sequence
sequence | sequence to obtain cumulative sum |
<return>cumulative sum</return>
Definition at line 284 of file MeanReversionPortfolioConstructionModel.cs.
|
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>
vector | unnormalized weight vector |
total | regulator, default to be 1, making it a probabilistic simplex |
<return>normalized weight vector</return>
Definition at line 304 of file MeanReversionPortfolioConstructionModel.cs.