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.

// Set portfolio construction to NullPortfolioConstructionModel to bypass custom logic, useful for simplifying testing or initial development when you want to manually manage or skip automatic portfolio adjustments.
SetPortfolioConstruction(new NullPortfolioConstructionModel()); 
# Set portfolio construction to NullPortfolioConstructionModel to bypass custom logic, useful for simplifying testing or initial development when you want to manually manage or skip automatic portfolio adjustments.
self.set_portfolio_construction(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.

// Set portfolio construction to EqualWeightingPortfolioConstructionModel to allocate capital equally across selected securities, ensuring balanced exposure and reducing the influence of any single asset on the portfolio.
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
# Set portfolio construction to EqualWeightingPortfolioConstructionModel to allocate capital equally across selected securities, ensuring balanced exposure and reducing the influence of any single asset on the portfolio.
self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalanceresolutionResolutionRebalancing frequencyResolution.DailyResolution.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.Confidenceconfidence for the last Insight of each Symbol. If the Insight has a direction of InsightDirection.UpUP, the model generates long targets. If the Insight has a direction of InsightDirection.DownDOWN, 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.

// Use ConfidenceWeightedPortfolioConstructionModel to assign portfolio weights based on the confidence level of the latest Insights, creating long or short positions accordingly, and normalizing weights if the total exceeds 1, leveraging the strength of predictions for better allocation and risk management.
SetPortfolioConstruction(new ConfidenceWeightedPortfolioConstructionModel());
# Use ConfidenceWeightedPortfolioConstructionModel to assign portfolio weights based on the confidence level of the latest Insights, creating long or short positions accordingly, and normalizing weights if the total exceeds 1, leveraging the strength of predictions for better allocation and risk management.
self.set_portfolio_construction(ConfidenceWeightedPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalanceresolutionResolutionRebalancing frequencyResolution.DailyResolution.DAILY
portfolioBiasportfolio_biasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShortLONG_SHORT

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.Weightweight for the last Insight of each Symbol. If the Insight has a direction of InsightDirection.UpUP, the model generates long targets. If the Insight has a direction of InsightDirection.DownDOWN, 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.

// Use InsightWeightingPortfolioConstructionModel to allocate capital based on the latest Insight weights, generating long or short targets as per the Insight direction and adjusting allocations if total weights exceed 1, ensuring portfolio weights reflect current market insights and maintains proper risk management.
SetPortfolioConstruction(new InsightWeightingPortfolioConstructionModel());
# Use InsightWeightingPortfolioConstructionModel to allocate capital based on the latest Insight weights, generating long or short targets as per the Insight direction and adjusting allocations if total weights exceed 1, ensuring portfolio weights reflect current market insights and maintains proper risk management.
self.set_portfolio_construction(InsightWeightingPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalanceresolutionResolutionRebalancing frequencyResolution.DailyResolution.DAILY
portfolioBiasportfolio_biasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShortLONG_SHORT

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.IndustryTemplateCodecompany_reference.industry_template_code 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.UpUP, the model generates long targets. If the insight has a direction of InsightDirection.DownDOWN, the model generates short targets. The model ignores Insight objects for Symbols that have no CompanyReference.IndustryTemplateCodecompany_reference.industry_template_code.

// Use SectorWeightingPortfolioConstructionModel to ensure diversified sector exposure and balanced allocation, aligning portfolio weights with sector insights while managing long and short positions based on insight direction.
SetPortfolioConstruction(new SectorWeightingPortfolioConstructionModel());
# Use SectorWeightingPortfolioConstructionModel to ensure diversified sector exposure and balanced allocation, aligning portfolio weights with sector insights while managing long and short positions based on insight direction.
self.set_portfolio_construction(SectorWeightingPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalanceresolutionResolutionRebalancing frequencyResolution.DailyResolution.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.UpUP, it increases the position size by a fixed percent. For each active Insight of direction InsightDirection.DownDOWN, 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.

// Use AccumulativeInsightPortfolioConstructionModel to adjust portfolio weights based on the cumulative value of all active insights, increasing position size for insights with UP direction to capitalize on expected upward movements, while reducing position size with down or flat insights to mitigate potential losses.
SetPortfolioConstruction(new AccumulativeInsightPortfolioConstructionModel());
# Use AccumulativeInsightPortfolioConstructionModel to adjust portfolio weights based on the cumulative value of all active insights, increasing position size for insights with UP direction to capitalize on expected upward movements, while reducing position size with down or flat insights to mitigate potential losses.
self.set_portfolio_construction(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
portfolioBiasportfolio_biasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShortLONG_SHORT
percentdoublefloatThe 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.

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.

// Use MeanVarianceOptimizationPortfolioConstructionModel to determine portfolio weights by optimizing for the best risk-return trade-off balancing the expected returns against the risk of each security to construct a portfolio aiming to maximize returns for a given level of risk or minimize risk for a given level of returns.
SetPortfolioConstruction(new MeanVarianceOptimizationPortfolioConstructionModel());
# Use MeanVarianceOptimizationPortfolioConstructionModel to determine portfolio weights by optimizing for the best risk-return trade-off balancing the expected returns against the risk of each security to construct a portfolio aiming to maximize returns for a given level of risk or minimize risk for a given level of returns.
self.set_portfolio_construction(MeanVarianceOptimizationPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalancerebalanceResolutionResolutionRebalancing frequencyResolution.DailyResolution.DAILY
portfolioBiasportfolio_biasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShortLONG_SHORT
lookbackintHistorical return lookback period1
periodintThe time interval of history price to calculate the weight63
resolutionResolutionThe resolution of the history priceResolution.DailyResolution.DAILY
targetReturntarget_returndoublefloatThe 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.

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.

// Use BlackLittermanOptimizationPortfolioConstructionModel to incorporate market equilibrium portfolio and the investor views to create an improved portfolio aligning with both market expectations and investor insights.
SetPortfolioConstruction(new BlackLittermanOptimizationPortfolioConstructionModel());
# Use BlackLittermanOptimizationPortfolioConstructionModel to incorporate market equilibrium portfolio and the investor views to create an improved portfolio aligning with both market expectations and investor insights.
self.set_portfolio_construction(BlackLittermanOptimizationPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalancerebalanceResolutionResolutionRebalancing frequencyResolution.DailyResolution.DAILY
portfolioBiasportfolio_biasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShortLONG_SHORT
lookbackintHistorical return lookback period1
periodintThe time interval of history price to calculate the weight63
resolutionResolutionThe resolution of the history priceResolution.DailyResolution.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.

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.

// Use MeanReversionPortfolioConstructionModel to build a portfolio that capitalizes on the expected mean-reversion of asset prices, adjusting allocations based on deviations from historical averages to potentially enhance returns by exploiting price reversions.
SetPortfolioConstruction(new MeanReversionPortfolioConstructionModel());
# Use MeanReversionPortfolioConstructionModel to build a portfolio that capitalizes on the expected mean-reversion of asset prices, adjusting allocations based on deviations from historical averages to potentially enhance returns by exploiting price reversions.
self.set_portfolio_construction(MeanReversionPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalancerebalanceResolutionResolutionRebalancing frequencyResolution.DailyResolution.DAILY
portfolioBiasportfolio_biasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShortLONG_SHORT
reversionThresholdreversion_thresholddecimalfloatReversion threshold1
windowSizewindow_sizeintThe window size of mean price20
resolutionResolutionThe resolution of the history priceResolution.DailyResolution.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.

// Use RiskParityPortfolioConstructionModel to allocate portfolio weights based on risk contributions, ensuring that each asset contributes equally to the portfolio's overall risk, aiming for balanced risk exposure and potentially improved risk-adjusted returns.
SetPortfolioConstruction(new RiskParityPortfolioConstructionModel());
# Use RiskParityPortfolioConstructionModel to allocate portfolio weights based on risk contributions, ensuring that each asset contributes equally to the portfolio's overall risk, aiming for balanced risk exposure and potentially improved risk-adjusted returns.
self.set_portfolio_construction(RiskParityPortfolioConstructionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
rebalancerebalanceResolutionResolutionRebalancing frequencyResolution.DailyResolution.DAILY
portfolioBiasportfolio_biasPortfolioBiasThe bias of the portfolioPortfolioBias.LongShortLONG_SHORT
lookbackintHistorical return lookback period1
periodintThe time interval of history price to calculate the weight252
resolutionResolutionThe resolution of the history priceResolution.DailyResolution.DAILY
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 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.

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: