qis.BenchmarkReturnsPositiveNegativeRegime¶
- class qis.BenchmarkReturnsPositiveNegativeRegime(freq='QE', return_type=ReturnTypes.RELATIVE, regime_ids_colors=None)[source]¶
Bases:
RegimeClassifierRegime classifier based on positive vs negative benchmark returns.
Classifies periods into two ordered regimes based on benchmark return sign, useful for up/down market analysis. Both regime categories remain available for aggregation when one is unobserved, while missing benchmark returns remain unclassified.
- Parameters:
freq (str)
return_type (ReturnTypes)
- __init__(freq='QE', return_type=ReturnTypes.RELATIVE, regime_ids_colors=None)[source]¶
Initialize positive/negative regime classifier.
- Parameters:
freq (str) – Sampling frequency (default: ‘QE’ for quarter-end)
return_type (ReturnTypes) – Type of returns to compute
regime_ids_colors (Dict[str, str]) – Optional ordered mapping of exactly two regime names to colors. The first entry classifies negative returns and the second classifies zero or positive returns.
- Raises:
ValueError – If an explicit mapping does not contain exactly two entries.
Methods
__init__([freq, return_type, regime_ids_colors])Initialize positive/negative 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.
Classify periods by benchmark return sign.
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- compute_sampled_returns_with_regime_id(prices, benchmark, include_start_date=True, include_end_date=True, **kwargs)[source]¶
Classify periods by benchmark return sign.
- Parameters:
- Returns:
DataFrame with returns and an ordered categorical regime classification containing both configured IDs. Missing benchmark returns have a missing regime ID.
- Raises:
ValueError – If insufficient data for classification
- Return type:
- 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; perf_params.sharpe_convention selects the regime-Sharpe convention (PA default, ARITHMETIC/LOG exactly additive)
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: