Risk Model

A financial risk model codifies a particular view of the market. Currently, the Quantopian Risk Model codifies a view of the US equity market. The risk model consists of a series of cascading linear regressions on each asset. In each step in the cascade, we calculate a regression, and pass the residual returns for each asset to the next step. The process is explained in depth in the risk model white paper.

Risk Factors

The Quantopian Risk Model considers the following types of risk.

Sector returns. The Quantopian risk model has 11 sectors. A sector ETF is specified to represent each sector factor. Each stock is assigned to a sector. We perform a regression to calculate each stock's beta to its respective sector. A portion of each stock's return is attributable to its sector. The residual return is calculated and passed to the next step.

Style risk. We start with the residual from the sector return, above. We then regress the stock against the 5 style factors together. There are five styles in the Quantopian risk model:

  1. Momentum: The momentum factor captures return differences between stocks on an upswing (winner stocks) and the stocks on a downswing (loser stocks) over 11 months.
  2. Company size: The size factor captures return differences between big-cap stocks and small-cap stocks.
  3. Value: The value factor captures return differences between expensive stocks and in-expensive stocks (measured by the ratio of book value of company to the price of the stock).
  4. Short-term reversal: The short-term reversal factor captures return differences between stocks with strong losses to reverse (recent loser stocks) and the stocks with strong gains (recent winner stocks) to reverse in a short time period.
  5. Volatility: The volatility factor captures return differences between high volatility stocks and low volatility stocks in the market. The volatility can be measured in historical long term or near-term.

Once the sector and style components have all been removed, the residual is the specific return.


The Quantopian Risk Model has two primary use cases:

  1. Portfolio Construction. Factors from the Quantopian Risk Model can be used to build constraints in the Optimize API.
  2. Performance Analysis. The risk model can be used to break down the returns of an algorithm into common and specific returns.

Portfolio Construction

When defining a portfolio optimization problem, it is usually a good idea to constrain the problem to a particular level of risk. One such definition of risk to consider is exposure to factors in the Quantopian Risk Model. Risk model data can be loaded via a pre-configured pipeline that produces a column of output for each factor in the risk model. The pre-configured pipeline is called risk_loading_pipeline() and is currently available in the quantopian.pipeline.experimental module.

from quantopian.pipeline.experimental import risk_loading_pipeline

The Pipeline created by risk_loading_pipeline() works just like any other pipeline instance. For example, you could attach the Pipeline returned by risk_loading_pipeline() to your algorithm like this:

from quantopian.pipeline.experimental import risk_loading_pipeline

def initialize(context):
    attach_pipeline(risk_loading_pipeline(), 'risk_loading_pipeline')

def before_trading_start(context, data):
    context.risk_loading_pipeline = pipeline_output('risk_loading_pipeline')
    # Multiple pipelines are supported in an algorithm.
    context.my_other_pipeline = pipeline_output('my_other_pipeline')

def my_method(context, data):
    # Access context.risk_loading_pipeline in your methods.


You can attach multiple pipelines to an algorithm. Beyond the risk loading pipeline, you can attach additional pipelines to compute a tradable universe and alpha factors.

Once you have the factor data from the risk loading pipeline, you can construct a RiskModelExposure constraint and provide it the output of the risk loading pipeline. You can then include this constraint when you construct your portfolio. Passing a RiskModelExposure constraint to Optimize constrains your portfolio based on historical per-asset risk exposures.


Constraining a portfolio based on historical per-asset risk exposures is generally effective, but it does not guarantee that future exposures will be constrained.

Performance Analysis

The Quantopian Risk Model can also be used to conduct performance attribution on a backtest result. When you run a full backtest, the you can see the performance attribution of your algorithm by navigating to the "Risk" tab in the upper left corner of the full backtest screen.

On Quantopian, the Risk Model is also incorporated in pyfolio tearsheets -- the full pyfolio tearsheet includes a plot that reports the performance attribution of the strategy.