Portfolio Construction
Supported Models
Introduction
This page describes the pre-built Portfolio Construction models in LEAN. The number of models grows over time. To add a model to LEAN, make a pull request to the GitHub repository. If none of these models perform exactly how you want, create a custom Portfolio Construction model.
Null Model
The NullPortfolioConstructionModel
is the default Portfolio Construction model. It doesn't return any PortfolioTarget
objects. It's useful if you need to analyze an Alpha model in isolation.
SetPortfolioConstruction(new NullPortfolioConstructionModel());
self.SetPortfolioConstruction(NullPortfolioConstructionModel())
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.
Equal Weighting Model
The EqualWeightingPortfolioConstructionModel
assigns an equal share of the portfolio to the securities with active insights. This weighting scheme is useful for universe rotation based on simple portfolio strategies.
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
rebalance resolution | Resolution | Rebalancing frequency | Resolution.Daily |
This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.
This model removes expired insights from the Insight Manager during each rebalance. It also removes all insights for a security when the security is removed from the universe.
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.
Confidence Weighted Model
The ConfidenceWeightedPortfolioConstructionModel
generates target portfolio weights based on the Insight.Confidence
for the last Insight of each Symbol. If the Insight has a direction of InsightDirection.Up
, the model generates long targets. If the Insight has a direction of InsightDirection.Down
, the model generates short targets. If the sum of all the last active Insight per Symbol is greater than 1, the model factors down each target percent holdings proportionally so the sum is 1. The model ignores Insight
objects that have no Confidence
value.
SetPortfolioConstruction(new ConfidenceWeightedPortfolioConstructionModel());
self.SetPortfolioConstruction(ConfidenceWeightedPortfolioConstructionModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
rebalance resolution | Resolution | Rebalancing frequency | Resolution.Daily |
portfolioBias | PortfolioBias | The bias of the portfolio | PortfolioBias.LongShort |
This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.
This model removes expired insights from the Insight Manager during each rebalance. It also removes all insights for a security when the security is removed from the universe.
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.
Insight Weighting Model
The InsightWeightingPortfolioConstructionModel
generates target portfolio weights based on the Insight.Weight
for the last Insight of each Symbol. If the Insight has a direction of InsightDirection.Up
, the model generates long targets. If the Insight has a direction of InsightDirection.Down
, the model generates short targets. If the sum of all the last active Insight per Symbol is greater than 1, the model factors down each target percent holdings proportionally so the sum is 1. The model takes the absolute value of the Weight
of each Insight
object and ignores Insight
objects that have no Weight
value.
SetPortfolioConstruction(new InsightWeightingPortfolioConstructionModel());
self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
rebalance resolution | Resolution | Rebalancing frequency | Resolution.Daily |
portfolioBias | PortfolioBias | The bias of the portfolio | PortfolioBias.LongShort |
This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.
This model removes expired insights from the Insight Manager during each rebalance. It also removes all insights for a security when the security is removed from the universe.
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.
Sector Weighting Model
The SectorWeightingPortfolioConstructionModel
generates target portfolio weights based on the CompanyReference.IndustryTemplateCode
provided by the US Fundamental dataset. The target percent holdings of each sector is 1/S where S is the number of sectors and the target percent holdings of each security is 1/N where N is the number of securities of each sector. If the insight has a direction of InsightDirection.Up
, the model generates long targets. If the insight has a direction of InsightDirection.Down
, the model generates short targets. The model ignores Insight
objects for Symbols that have no CompanyReference.IndustryTemplateCode
.
SetPortfolioConstruction(new SectorWeightingPortfolioConstructionModel());
self.SetPortfolioConstruction(SectorWeightingPortfolioConstructionModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
rebalance resolution | Resolution | Rebalancing frequency | Resolution.Daily |
This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.
This model removes expired insights from the Insight Manager during each rebalance. It also removes all insights for a security when the security is removed from the universe.
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.
Accumulative Insight Model
The AccumulativeInsightPortfolioConstructionModel
generates target portfolio weights based on all the active insights of a security. For each active Insight of direction InsightDirection.Up
, it increases the position size by a fixed percent. For each active Insight of direction InsightDirection.Down
, it decreases the position size by a fixed percent. For each active Insight of direction InsightDirection.Flat
, it moves the position size towards 0 by a fixed percent.
SetPortfolioConstruction(new AccumulativeInsightPortfolioConstructionModel());
self.SetPortfolioConstruction(AccumulativeInsightPortfolioConstructionModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
rebalance rebalanceFunc | Func<DateTime, DateTime?>
Any of the following types:
|
A function that receives the algorithm UTC time and returns the next expected rebalance time. If the function returns None null , the portfolio doesn't rebalance.
Rebalancing parameter. If it's a timedelta , DateRules or Resolution , it's converted into a function. If it's None , it's ignored. The function returns the next expected rebalance time for a given algorithm UTC DateTime. The function returns None if unknown, in which case the function will be called again in the
next loop. If the function returns the current time, the portfolio rebalances. | None null |
portfolioBias | PortfolioBias | The bias of the portfolio | PortfolioBias.LongShort |
percent | PortfolioBias | The percentage amount of the portfolio value to allocate to a single insight | 0.03 (3%) |
This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.
This model removes expired insights from the Insight Manager during each rebalance. It also removes all insights for a security when the security is removed from the universe.
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.
Mean Variance Optimization Model
The MeanVarianceOptimizationPortfolioConstructionModel
seeks to build a portfolio with the least volatility possible and achieve a target return.
SetPortfolioConstruction(new MeanVarianceOptimizationPortfolioConstructionModel());
self.SetPortfolioConstruction(MeanVarianceOptimizationPortfolioConstructionModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
rebalance rebalanceResolution | Resolution | Rebalancing frequency | Resolution.Daily |
portfolioBias | PortfolioBias | The bias of the portfolio | PortfolioBias.LongShort |
lookback | int | Historical return lookback period | 1 |
period | int | The time interval of history price to calculate the weight | 63 |
resolution | Resolution | The resolution of the history price | Resolution.Daily |
targetReturn | double float | The target portfolio return | 0.02 (2%) |
optimizer | IPortfolioOptimizer | The portfolio optimization algorithm | null None |
This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency. If you don't provide an optimizer
argument, the default one is the MinimumVariancePortfolioOptimizer with upper and lower weights that respect the portfolioBias
.
This model removes expired insights from the Insight Manager during each rebalance. It also removes all insights for a security when the security is removed from the universe.
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.
Black Litterman Optimization Model
The BlackLittermanOptimizationPortfolioConstructionModel
receives Insight
objects from multiple Alphas and combines them into a single portfolio. These multiple sources of Alpha models can be seen as the "investor views" required in the classical model.
SetPortfolioConstruction(new BlackLittermanOptimizationPortfolioConstructionModel());
self.SetPortfolioConstruction(BlackLittermanOptimizationPortfolioConstructionModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
rebalance rebalanceResolution | Resolution | Rebalancing frequency | Resolution.Daily |
portfolioBias | PortfolioBias | The bias of the portfolio | PortfolioBias.LongShort |
lookback | int | Historical return lookback period | 1 |
period | int | The time interval of history price to calculate the weight | 63 |
resolution | Resolution | The resolution of the history price | Resolution.Daily |
risk_free_rate riskFreeRate | double float | The risk free rate | 0.0 |
delta | double float | The risk aversion coefficient of the market portfolio | 2.5 |
tau | double float | The model parameter indicating the uncertainty of the CAPM prior | 0.05 |
optimizer | IPortfolioOptimizer | The portfolio optimization algorithm | null None |
This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency. If you don't provide an optimizer
argument, the default one is the MinimumVariancePortfolioOptimizer with upper and lower weights that respect the portfolioBias
.
This model removes expired insights from the Insight Manager during each rebalance. It also removes all insights for a security when the security is removed from the universe.
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.
Mean Reversion Model
The MeanReversionPortfolioConstructionModel
implements an on-line portfolio selection technique, named "On-Line Moving Average Reversion" (OLMAR). The basic idea is to represent multi-period mean reversion as "Moving Average Reversion" (MAR), which explicitly predicts next price relatives using moving averages and then forms portfolios with online learning techniques.
SetPortfolioConstruction(new MeanReversionPortfolioConstructionModel());
self.SetPortfolioConstruction(MeanReversionPortfolioConstructionModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
rebalance rebalanceResolution | Resolution | Rebalancing frequency | Resolution.Daily |
portfolioBias | PortfolioBias | The bias of the portfolio | PortfolioBias.LongShort |
reversionThreshold | decimal float | Reversion threshold | 1 |
windowSize | int | The window size of mean price | 20 |
resolution | Resolution | The resolution of the history price | Resolution.Daily |
This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.
This model removes expired insights from the Insight Manager during each rebalance. It also removes all insights for a security when the security is removed from the universe.
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.
Reference:
- Li, B., Hoi, S. C. (2012). On-line portfolio selection with moving average reversion. arXiv preprint arXiv:1206.4626.
Risk Parity Model
The RiskParityPortfolioConstructionModel
seeks to build a portfolio with the equal contribution of risk to the total portfolio risk from all assets.
SetPortfolioConstruction(new RiskParityPortfolioConstructionModel());
self.SetPortfolioConstruction(RiskParityPortfolioConstructionModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
rebalance rebalanceResolution | Resolution | Rebalancing frequency | Resolution.Daily |
portfolioBias | PortfolioBias | The bias of the portfolio | PortfolioBias.LongShort |
lookback | int | Historical return lookback period | 1 |
period | int | The time interval of history price to calculate the weight | 252 |
resolution | Resolution | The resolution of the history price | Resolution.Daily |
optimizer | IPortfolioOptimizer | The portfolio optimization algorithm | null None |
This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency. If you don't provide an optimizer
argument, the default one is the RiskParityPortfolioOptimizer.
This model removes expired insights from the Insight Manager during each rebalance. It also removes all insights for a security when the security is removed from the universe.
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.