qis.RegimeClassifier¶
- class qis.RegimeClassifier[source]¶
Bases:
ABCAbstract base class for regime classification.
Regime classifiers partition time periods based on market conditions for conditional performance attribution analysis.
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 ordered list of regime IDs.
Get mapping of regime IDs to visualization colors.
to_dict()Convert regime parameters to dictionary.
Attributes
- REGIME_COLUMN = 'regime'¶
- abstractmethod compute_sampled_returns_with_regime_id(**kwargs)[source]¶
Compute returns with regime classification.
- Returns:
DataFrame with returns and regime ID column
- Return type:
- 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.
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
- Returns:
Tuple of (performance table, regime data dictionary)
- Return type: