qis.RegimeClassifier

class qis.RegimeClassifier[source]

Bases: ABC

Abstract base class for regime classification.

Regime classifiers partition time periods based on market conditions for conditional performance attribution analysis.

__init__()[source]

Methods

__init__()

class_data_to_colors(regime_data)

Map regime IDs to colors for visualization.

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

Compute regime-conditional performance attribution table.

compute_sampled_returns_with_regime_id(**kwargs)

Compute returns with regime classification.

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'
regime_ids_colors: Dict[str, str]
abstractmethod compute_sampled_returns_with_regime_id(**kwargs)[source]

Compute returns with regime classification.

Returns:

DataFrame with returns and regime ID column

Return type:

DataFrame

get_regime_ids_colors()[source]

Get mapping of regime IDs to visualization colors.

Returns:

Dictionary mapping regime ID strings to color codes

Return type:

Dict[str, str]

get_regime_ids()[source]

Get ordered list of regime IDs.

Returns:

List of regime ID strings

Return type:

List[str]

to_dict()[source]

Convert regime parameters to dictionary.

Generic implementation that extracts public attributes (not starting with ‘_’) from the instance, excluding methods and the REGIME_COLUMN class variable. Subclasses can override to customize serialization.

Returns:

Dictionary of parameter names to values

Return type:

Dict[str, Any]

Examples

>>> classifier = BenchmarkReturnsQuantilesRegime(freq='QE', q=4)
>>> classifier.to_dict()
{'freq': 'QE', 'return_type': <ReturnTypes.RELATIVE: ...>, 'q': 4, ...}
compute_regimes_pa_perf_table(regime_id_func_kwargs, prices, benchmark, freq, perf_params, is_use_benchmark_means=False, is_add_ra_perf_table=True, drop_benchmark=False, additive_pa_returns_to_pa_total=True, regime_ids=None, **kwargs)[source]

Compute regime-conditional performance attribution table.

Parameters:
  • regime_id_func_kwargs (Dict[str, Any]) – Arguments for regime ID computation

  • prices (DataFrame) – Asset price series

  • benchmark (str) – Benchmark asset name

  • freq (str) – Sampling frequency

  • perf_params (PerfParams) – Performance parameters; perf_params.sharpe_convention selects the regime-Sharpe convention (PA default, ARITHMETIC/LOG exactly additive)

  • is_use_benchmark_means (bool) – Use benchmark means for normalization

  • is_add_ra_perf_table (bool) – Include risk-adjusted performance

  • drop_benchmark (bool) – Exclude benchmark from results

  • additive_pa_returns_to_pa_total (bool) – Adjust regime PA to sum to total

  • regime_ids (List[str]) – Ordered list of regime IDs

Returns:

Tuple of (performance table, regime data dictionary)

Return type:

Tuple[DataFrame, Dict[RegimeData, DataFrame]]

class_data_to_colors(regime_data)[source]

Map regime IDs to colors for visualization.

Parameters:

regime_data (Series) – Series of regime IDs

Returns:

Series of color codes

Return type:

Series