Risk Management

Supported Models

Introduction

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

Null Model

The NullRiskManagementModel is the default Risk Management model. It doesn't adjust any of the PortfolioTarget objects it receives from the Portfolio Construction model.

AddRiskManagement(new NullRiskManagementModel());
self.add_risk_management(NullRiskManagementModel())

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

Maximum Security Drawdown Model

The MaximumDrawdownPercentPerSecurity model monitors the unrealized profit percentage of each security in the portfolio. When the percentage drops below a threshold relative to the opening price, it liquidates the position and cancels all insights in the Insight Manager that are for the security. This model can operate even when the Portfolio Construction model provides an empty list of PortfolioTarget objects.

AddRiskManagement(new MaximumDrawdownPercentPerSecurity());
self.add_risk_management(MaximumDrawdownPercentPerSecurity())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
maximumDrawdownPercentdecimalfloatThe maximum percentage drawdown allowed for any single security holding0.05 (5%)

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

Maximum Portfolio Drawdown Model

The MaximumDrawdownPercentPortfolio model monitors the portfolio drawdown. The drawdown can be relative to the starting portfolio value or the maximum portfolio value. When the portfolio value drops below a percentage threshold, the model liquidates the portfolio and cancels all insights in the Insight Manager. To liquidate the portfolio, the model must receive at least 1 PortfolioTarget after the drawdown threshold is passed. After the portfolio is liquidated, the model resets. This model can operate even when the Portfolio Construction model provides an empty list of PortfolioTarget objects.

AddRiskManagement(new MaximumDrawdownPercentPortfolio());
self.add_risk_management(MaximumDrawdownPercentPortfolio())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
maximumDrawdownPercentdecimalfloatMaximum spread accepted comparing to current price in percentage0.05 (5%)
isTrailingboolIf "false", the drawdown is relative to the starting value of the portfolio. If "true", the drawdown is relative the last maximum portfolio valueFalsefalse

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

Maximum Unrealized Profit Model

The MaximumUnrealizedProfitPercentPerSecurity model monitors the unrealized profit of each security in the portfolio. When the unrealized profit exceeds a profit threshold, it liquidates the position and cancels all insights in the Insight Manager that are for the security. This model can operate even when the Portfolio Construction model provides an empty list of PortfolioTarget objects.

AddRiskManagement(new MaximumUnrealizedProfitPercentPerSecurity());
self.add_risk_management(MaximumUnrealizedProfitPercentPerSecurity())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
maximumUnrealizedProfitPercentdecimalfloatThe maximum percentage unrealized profit allowed for any single security holding0.05 (5%)

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

Maximum Sector Exposure Model

The MaximumSectorExposureRiskManagementModel limits the absolute portfolio exposure in a each industry sector to a predefined maximum percentage. If the absolute portfolio exposure exceeds the maximum percentage, the weight of each Equity in the sector is scaled down so the sector doesn't exceed the maximum percentage. This process requires assets that are selected by Morningstar fundamental data. This model can operate even when the Portfolio Construction model provides an empty list of PortfolioTarget objects.

AddRiskManagement(new MaximumSectorExposureRiskManagementModel());
self.add_risk_management(MaximumSectorExposureRiskManagementModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
maximumSectorExposuredecimalfloatThe maximum exposure for any sector0.2 (20%)

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

Trailing Stop Model

The TrailingStopRiskManagementModel monitors the drawdown of each security in the portfolio. When the peak-to-trough drawdown of the unrealized profit exceeds a threshold, it liquidates the position and cancels all insights in the Insight Manager that are for the security. This model can operate even when the Portfolio Construction model provides an empty list of PortfolioTarget objects.

AddRiskManagement(new TrailingStopRiskManagementModel());
self.add_risk_management(TrailingStopRiskManagementModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
maximumDrawdownPercentdecimalfloatThe maximum percentage drawdown allowed for algorithm portfolio compared with the highest unrealized profit0.05 (5%)

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: