qis.BenchmarkVolsQuantilesRegime

class qis.BenchmarkVolsQuantilesRegime(freq='QE', return_type=ReturnTypes.RELATIVE, q=4)[source]

Bases: RegimeClassifier

Regime classifier based on benchmark volatility quantiles.

Classifies periods based on realized volatility levels, enabling analysis of performance in different volatility environments. After classification, the data-derived threshold IDs and their colors are available through the inherited regime metadata interface.

Parameters:
__init__(freq='QE', return_type=ReturnTypes.RELATIVE, q=4)[source]

Initialize volatility quantiles regime classifier.

Parameters:
  • freq (str) – Sampling frequency for volatility calculation

  • return_type (ReturnTypes) – Type of returns to compute

  • q (int) – Positive integer number of quantile buckets. NumPy integer scalars are accepted; booleans are invalid.

Raises:

ValueError – If q is not a positive integer.

Methods

__init__([freq, return_type, q])

Initialize volatility quantiles regime classifier.

class_data_to_colors(regime_data)

Map regime IDs to colors for visualization.

compute_regimes_pa_perf_table(prices, ...[, ...])

Compute regime performance attribution table.

compute_sampled_returns_with_regime_id(...)

Classify periods by benchmark volatility quantiles.

get_regime_colors()

Get list of regime colors in order.

get_regime_ids()

Get ordered list of regime IDs.

get_regime_ids_colors()

Get mapping of regime IDs to visualization colors.

to_dict()

Convert regime parameters to dictionary.

Attributes

REGIME_COLUMN

regime_colors: Dict[str, Tuple[float, ...]]
compute_sampled_returns_with_regime_id(prices, benchmark, include_start_date=True, include_end_date=True, **kwargs)[source]

Classify periods by benchmark volatility quantiles.

Parameters:
  • prices (DataFrame) – Asset prices

  • benchmark (str) – Benchmark column name

  • include_start_date (bool) – Include first period

  • include_end_date (bool) – Include last period

Returns:

DataFrame with returns and regime classification. The ordered threshold IDs and one color per ID are also available through get_regime_ids_colors().

Raises:

ValueError – If the benchmark has no finite volatility observations or fewer than q volatility quantile bands contain observations.

Return type:

DataFrame

compute_regimes_pa_perf_table(prices, benchmark, perf_params, drop_benchmark=False, additive_pa_returns_to_pa_total=True, **kwargs)[source]

Compute regime performance attribution table.

Parameters:
  • prices (DataFrame) – Asset prices

  • benchmark (str) – Benchmark asset name

  • perf_params (PerfParams) – Performance parameters

  • drop_benchmark (bool) – Exclude benchmark from results

  • additive_pa_returns_to_pa_total (bool) – Shift the per-annum regime contributions in proportion to regime frequency so they add up to the table’s PA_RETURN; False reports the unpatched exp(af * p_s * m_s) - 1

  • **kwargs – Accepted for call compatibility (plotting functions pass their own options through) and ignored

Returns:

Tuple of (performance table, regime data dictionary)

Return type:

Tuple[DataFrame, Dict[RegimeData, DataFrame]]

get_regime_colors()[source]

Get list of regime colors in order.

Return type:

List[Tuple[float, …]]