Portfolio Construction

Supported Optimizers

Introduction

This page describes the pre-built Portfolio Optimizer 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 Optimizer model.

Maximum Sharpe Ratio Optimizer

The MaximumSharpeRatioPortfolioOptimizer seeks to maximize the portfolio Sharpe Ratio.

var optimizer = new MaximumSharpeRatioPortfolioOptimizer();
optimizer = MaximumSharpeRatioPortfolioOptimizer()

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
minimum_weight lowerdoublefloatThe lower bounds on portfolio weights-1
maximum_weightupperdoublefloatThe upper bounds on portfolio weights1
risk_free_rateriskFreeRatedoublefloatThe risk free rate0

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

Minimum Variance Optimizer

The MinimumVariancePortfolioOptimizer seeks to minimize the portfolio variance and achieve a target return.

var optimizer = new MinimumVariancePortfolioOptimizer();
optimizer = MinimumVariancePortfolioOptimizer()

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
minimum_weight lowerdoublefloatThe lower bounds on portfolio weights-1
maximum_weightupperdoublefloatThe upper bounds on portfolio weights1
target_returntargetReturndoublefloatThe target portfolio return0.02 (2%)

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

Unconstrained Mean Variance Optimizer

The UnconstrainedMeanVariancePortfolioOptimizer seeks to find the optimal risk-adjusted portfolio that lies on the efficient frontier.

var optimizer = new UnconstrainedMeanVariancePortfolioOptimizer(historicalReturns);
optimizer = UnconstrainedMeanVariancePortfolioOptimizer(historical_returns)

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
historicalReturnsdouble[,]DataFrameMatrix of annualized historical returns where each column represents a security and each row returns for the given date/time (size: K x N)
expectedReturnsdouble[]SeriesArray of double with the portfolio annualized expected returns (size: K x 1)nullNone
covariancedouble[,]DataFrameMulti-dimensional array of double with the portfolio covariance of annualized returns (size: K x K)nullNone

If you don't provide an argument for expectedReturns or covariance, it's calculated based on the historicalReturns.

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: