Algorithm Framework

Risk Management

Introduction

The Risk Management Model seeks to manage risk on the PortfolioTarget collection created by the Portfolio Construction Model. It is applied to the targets before they reach the Execution Model. There are many creative ways to manage risk, some examples of this might be:

  • "Trailing Stop Risk Management Model"
    Seek to automatically create and manage trailing stop-loss orders for open positions.
  • "Option Hedging Risk Management Model"
    Automatically purchase options to hedge large equity exposures.
  • "Sector Exposure Risk Management Model"
    Seek to reduce position sizes when overexposed to sectors or individual assets. Keeping the portfolio within diversification requirements.
  • "Flash Crash Detection Risk Management Model"
    Scan for strange market situations which might be precursors to a flash crash and attempt to protect the portfolio when detected.

To set a Risk Management Model use the SetRiskManagement() method:

 # Setting a risk management model
self.SetRiskManagement( NullRiskManagementModel() )
// Setting a risk management model
SetRiskManagement( new NullRiskManagementModel() );

Risk Management Model Structure

The Risk Management Model should extend the RiskManagementModel class and has one required method: ManageRisk() which receives an array of PortfolioTarget objects. When an adjustment of the targets is required you should return the changed targets only. Optionally you can also use the OnSecuritiesChanged() event.

class MaximumDrawdownPerSecurity : RiskManagementModel
{
    // Adjust the portfolio targets and return them. If no changes emit nothing.
    List<PortfolioTarget> ManageRisk(QCAlgorithmFramework algorithm, PortfolioTarget[] targets)      {
    }

    // Optional: Be notified when securities change
    void OnSecuritiesChanged(QCAlgorithmFramework algorithm, SecurityChanges changes)
    {
    }
}
class MaximumDrawdownPerSecurity(RiskManagementModel):
    # Adjust the portfolio targets and return them. If no changes emit nothing.
    def ManageRisk(self, algorithm, targets):
        return []

    # Optional: Be notified when securities change
    def OnSecuritiesChanged(self, algorithm, changes):
        pass

Maximum Drawdown Risk Management Module

The Maximum Drawdown Risk Management Module monitors portfolio holdings and when extended beyond a predefined drawdown limit it liquidates the portfolio.

You can view the C# implementation of this model in GitHub.You can view the Python implementation of this model in GitHub.

Sector Exposure Risk Management Module

The Sector Exposure Risk Management Module limits the exposure to a specific industry sector to predefined maximum percentage. This requires assets that are selected by Morningstar fine fundamental data.

You can view the C# implementation of this model in GitHub.You can view the Python implementation of this model in GitHub.

You can also see our Tutorials and Videos. You can also get in touch with us via Chat.

Did you find this page Helpful ?