Risk metrics#

sigtech.framework.analytics.math.var.var(ts: pandas.core.series.Series, alpha=0.05, horizon=1, short=False, percentage=False, var_type='HISTORICAL') float

Compute the value at risk for a timeseries. The VaR is the value of the loss corresponding to the given quantile.

Parameters
  • ts – TimeSeries to compute VaR from.

  • alpha – The desired quantile (optional, default is 0.05).

  • horizon – The desired time horizon for the returns (optional, default is 1 day).

  • short – Specifies if the strategy intends to short the instrument.

  • percentage – If False (default), the return value is the cash loss, otherwise it’s the corresponding return.

  • var_type – choose ‘HISTORICAL’ or ‘VAR_COV’, i.e. variance-covariance approach.

Returns

VaR.

sigtech.framework.analytics.math.var.cvar(ts: pandas.core.series.Series, alpha=0.05, horizon=1, short=False, percentage=False) float

Compute the conditional value at risk (aka expected shortfall) for a timeseries. The CVaR is the average loss that happens if the value of the time series falls at or below the given quantile.

Parameters
  • ts – TimeSeries to compute CVaR from.

  • alpha – the desired quantile (optional, default is 0.05).

  • horizon – The desired time horizon for the returns (optional, default is 1 day).

  • short – Specifies if the strategy intends to short the instrument.

  • percentage – If False (default), the return value is the cash loss, otherwise it’s the corresponding return.

Returns

CVaR.

sigtech.framework.analytics.math.var.parametric_cvar(ts: pandas.core.series.Series, alpha=0.05, horizon=1, short=False, percentage=False) float

Compute the conditional value at risk (aka expected shortfall) for a timeseries using the parametric (gaussian) covariance-variance approach. The CVaR is the average loss that happens if the value of the time series falls at or below the given quantile.

Parameters
  • ts – TimeSeries to compute CVaR from.

  • alpha – the desired quantile (optional, default is 0.05).

  • horizon – The desired time horizon for the returns (optional, default is 1 day).

  • short – Specifies if the strategy intends to short the instrument.

  • percentage – If False (default), the return value is the cash loss, otherwise it’s the corresponding return.

Returns

CVaR.

sigtech.framework.analytics.math.var.parametric_var(ts: pandas.core.series.Series, alpha=0.05, horizon=1, short=False, percentage=False) float

Compute the value at risk for a timeseries using the parametric (gaussian) covariance-variance approach. The VaR is the value of the loss corresponding to the given quantile.

Parameters
  • ts – TimeSeries to compute VaR from.

  • alpha – The desired quantile (optional, default is 0.05).

  • horizon – The desired time horizon for the returns (optional, default is 1 day).

  • short – Specifies if the strategy intends to short the instrument.

  • percentage – If False (default), the return value is the cash loss, otherwise it’s the corresponding return.

Returns

VaR.

sigtech.framework.analytics.math.var.historical_var(ts: pandas.core.series.Series, alpha=0.05, horizon=1, short=False, percentage=False) float

Compute the value at risk for a timeseries using the historical timeseries. The VaR is the value of the loss corresponding to the given quantile.

Parameters
  • ts – TimeSeries to compute VaR from.

  • alpha – The desired quantile (optional, default is 0.05).

  • horizon – The desired time horizon for the returns (optional, default is 1 day).

  • short – Specifies if the strategy intends to short the instrument.

  • percentage – If False (default), the return value is the cash loss, otherwise it’s the corresponding return.

Returns

VaR.

sigtech.framework.analytics.math.var.portfolio_var(portfolio: list[tuple[float, pandas.core.series.Series]], alpha=0.05, horizon=1, short=False, percentage=False, var_type='HISTORICAL') float

Compute the value at risk for a portfolio. The VaR is the value of the loss corresponding to the given quantile.

Parameters
  • portfolio – list of Tuples containing portfolio units and TimeSeries.

  • alpha – The desired quantile (optional, default is 0.05).

  • horizon – The desired time horizon for the returns (optional, default is 1 day).

  • short – Specifies if the strategy intends to short the instrument.

  • percentage – If False (default), the return value is the cash loss, otherwise it’s the corresponding return.

  • var_type – choose ‘HISTORICAL’ or ‘VAR_COV’, i.e. variance-covariance approach.

Returns

VaR.

sigtech.framework.analytics.math.var.portfolio_var_historical(portfolio: list[tuple[float, pandas.core.series.Series]], alpha=0.05, horizon=1, short=False, percentage=False) float

Compute the value at risk for a portfolio using the historical timeseries and correlations from portfolio components. The VaR is the value of the loss corresponding to the given quantile.

Parameters
  • portfolio – list of Tuples containing portfolio units and TimeSeries.

  • alpha – The desired quantile (optional, default is 0.05).

  • horizon – The desired time horizon for the returns (optional, default is 1 day).

  • short – Specifies if the strategy intends to short the instrument.

  • percentage – If False (default), the return value is the cash loss, otherwise it’s the corresponding return.

Returns

VaR.

sigtech.framework.analytics.math.var.portfolio_var_parametric(portfolio: list[tuple[float, pandas.core.series.Series]], alpha=0.05, horizon=1, short=False, percentage=False) float

Compute the value at risk for a portfolio using the parametric (gaussian) covariance-variance approach. The VaR is the value of the loss corresponding to the given quantile.

Parameters
  • portfolio – list of Tuples containing portfolio units and TimeSeries

  • alpha – The desired quantile (optional, default is 0.05).

  • horizon – The desired time horizon for the returns (optional, default is 1 day).

  • short – Specifies if the strategy intends to short the instrument.

  • percentage – If False (default), the return value is the cash loss, otherwise it’s the corresponding return.

  • var_type – choose ‘HISTORICAL’ or ‘VAR_COV’, i.e. variance-covariance approach.

Returns

VaR.