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.AddRiskManagement(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.AddRiskManagement(MaximumDrawdownPercentPerSecurity())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
maximumDrawdownPercent | decimal float | The maximum percentage drawdown allowed for any single security holding | 0.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.AddRiskManagement(MaximumDrawdownPercentPortfolio())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
maximumDrawdownPercent | decimal float | Maximum spread accepted comparing to current price in percentage | 0.05 (5%) |
isTrailing | bool | If "false", the drawdown is relative to the starting value of the portfolio. If "true", the drawdown is relative the last maximum portfolio value | False false |
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.AddRiskManagement(MaximumUnrealizedProfitPercentPerSecurity())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
maximumUnrealizedProfitPercent | decimal float | The maximum percentage unrealized profit allowed for any single security holding | 0.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 fine fundamental data. This model can operate even when the Portfolio Construction model provides an empty list of PortfolioTarget
objects.
AddRiskManagement(new MaximumSectorExposureRiskManagementModel());
self.AddRiskManagement(MaximumSectorExposureRiskManagementModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
maximumSectorExposure | decimal float | The maximum exposure for any sector | 0.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.AddRiskManagement(TrailingStopRiskManagementModel())
The following table describes the arguments the model accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
maximumDrawdownPercent | decimal float | The maximum percentage drawdown allowed for algorithm portfolio compared with the highest unrealized profit | 0.05 (5%) |
To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.