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:

ArgumentData TypeDescriptionDefault Value
rebalanceresolutionResolutionRebalancing frequencyResolution.Daily

This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.

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:

ArgumentData TypeDescriptionDefault Value
rebalanceresolutionResolutionRebalancing frequencyResolution.Daily
portfolioBiasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShort

This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.

To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.

Insighted 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 ignores Insight objects that have no Weight value.

SetPortfolioConstruction(new InsightWeightingPortfolioConstructionModel());
self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalanceresolutionResolutionRebalancing frequencyResolution.Daily
portfolioBiasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShort

This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.

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:

ArgumentData TypeDescriptionDefault Value
rebalanceresolutionResolutionRebalancing frequencyResolution.Daily

This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.

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:

ArgumentData TypeDescriptionDefault Value
rebalancerebalanceFuncFunc<DateTime, DateTime?> Any of the following types:
  • timedelta
  • Resolution
  • DateRules
  • None
  • Callable[[datetime], datetime]
A function that receives the algorithm UTC time and returns the next expected rebalance time. If the function returns Nonenull, 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.Nonenull
portfolioBiasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShort
percentPortfolioBiasThe percentage amount of the portfolio value to allocate to a single insight0.03 (3%)

This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.

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:

ArgumentData TypeDescriptionDefault Value
rebalancerebalanceResolutionResolutionRebalancing frequencyResolution.Daily
portfolioBiasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShort
lookbackintHistorical return lookback period1
periodintThe time interval of history price to calculate the weight63
resolutionResolutionThe resolution of the history priceResolution.Daily
targetReturndoublefloatThe target portfolio return0.02 (2%)
optimizerIPortfolioOptimizerThe portfolio optimization algorithmnullNone

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.

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:

ArgumentData TypeDescriptionDefault Value
rebalancerebalanceResolutionResolutionRebalancing frequencyResolution.Daily
portfolioBiasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShort
lookbackintHistorical return lookback period1
periodintThe time interval of history price to calculate the weight63
resolutionResolutionThe resolution of the history priceResolution.Daily
risk_free_rateriskFreeRatedoublefloatThe risk free rate0.0
deltadoublefloatThe risk aversion coefficient of the market portfolio2.5
taudoublefloatThe model parameter indicating the uncertainty of the CAPM prior0.05
optimizerIPortfolioOptimizerThe portfolio optimization algorithmnullNone

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.

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 learn portfolios by online learning techniques.

Reference:

  • Li, B., Hoi, S. C. (2012). On-line portfolio selection with moving average reversion. arXiv preprint arXiv:1206.4626.

SetPortfolioConstruction(new MeanReversionPortfolioConstructionModel());
self.SetPortfolioConstruction(MeanReversionPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalancerebalanceFuncFunc<DateTime, DateTime?> Any of the following types:
  • timedelta
  • Resolution
  • DateRules
  • None
  • Callable[[datetime], datetime]
A function that receives the algorithm UTC time and returns the next expected rebalance time. If the function returns Nonenull, 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.Nonenull
portfolioBiasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShort
reversionThresholddecimalfloatReversion threshold1
windowSizeintThe window size of mean price20
resolutionResolutionThe resolution of the history priceResolution.Daily

This model supports other data types for the rebalancing frequency argument. For more information about the supported types, see Rebalance Frequency.

To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: