quantlab.risk.base#
The root class of the risk layer: FactorRiskModel, the contract of a factor risk model.
A factor risk model explains each bar’s stock returns by a few factors and forecasts their risk from that (ADR 0024). It is estimated ahead of any backtest, over the whole history, as stores of one row per bar, and each row uses nothing later than its bar. The portfolio layer reads the stores; it does not estimate anything itself.
A store is a RiskStore. It follows the factor lifecycle: compute(start,
end) returns the rows of a range, build writes them, extend appends
the bars after the recorded range and read returns a range of the store,
which must lie inside the range recorded beside it. Its rows are not a
(timestamp, symbol) panel (factor returns are on (timestamp, factor)),
so the store opens its rows itself; the range, build and extend are
quantlab.backend.ranged.RangedStore’s, as a factor’s are. Every row depends only
on a bounded window of bars ending at its own, so a store built in one go and
one built and then extended are identical.
FactorRiskModel fixes what every factor risk model produces, whatever its
method: two stores of one-bar quantities (REGRESSION_VARIABLES and
ESTIMATE_VARIABLES), the factor axis (factor_names) and each symbol’s
exposures to it at a bar (exposure_matrix). The portfolio side
(FactorRiskStoreEstimator) and the bias statistics (quantlab.risk.bias)
read only that. How the factor returns and the forecasts are estimated is a
subclass’s; shipped models live in quantlab.risk.predefined (USE4 on the
BarraStyle exposures).
Classes
A factor risk model's forecast at one bar: the covariance of the next bar's returns. |
|
A factor risk model: the stores estimated ahead of a backtest. |
|
The covariance of one-bar returns at a bar, over the symbols it covers: what a covariance estimator returns. |
|
One store of a factor risk model: rows per bar, written and read by date range. |
Functions
Return the factors of a |