Skip to content

Add Markov regime-switching models#5

Merged
mortentabor merged 3 commits intomainfrom
feature/markov-switching
Feb 19, 2026
Merged

Add Markov regime-switching models#5
mortentabor merged 3 commits intomainfrom
feature/markov-switching

Conversation

@mortentabor
Copy link
Contributor

Summary

  • New markov/ subpackage with MarkovRegression, MarkovAR, and MarkovADL wrapping statsmodels' Markov switching implementation
  • Restricted transition matrices (RestrictedMarkovRegression/AR) for enforcing exact zeros — enables Chib (1998) non-recurring (structural break) structure
  • Sequential restriction testing — novel GETS-style algorithm that tests and imposes individual transition probability restrictions with Holm-Bonferroni correction
  • NonRecurringRegimeTest — LR test for non-recurring vs unrestricted transitions with chi-bar-squared and bootstrap critical values
  • RegimeNumberSelection — select K via AIC/BIC/HQIC or sequential LRT
  • 5 visualization functions: smoothed probabilities, regime shading, transition matrix heatmap, parameter time series, IC comparison plot
  • Convenience methods markov_switching() on OLS, AR, and ADL for one-way mapping to MS models
  • 98 new tests across 7 test files (816 total, all passing)

Architecture

src/regimes/markov/
    __init__.py                     # Re-exports 15 public classes
    models.py                       # MarkovRegression, MarkovAR, MarkovADL
    results.py                      # MarkovSwitchingResultsBase + concrete results
    restricted.py                   # Constrained transition matrices
    sequential_restriction.py       # NonRecurringRegimeTest, SequentialRestrictionTest
    selection.py                    # RegimeNumberSelection

No overlap with PR #4 (Bai-Perron fixes) — these can merge in either order.

Test plan

  • 98 new Markov tests pass (tests/test_markov/, tests/test_visualization/test_markov_viz.py)
  • All 718 existing tests still pass (no regressions)
  • Smoke tested: MarkovRegression, MarkovAR, MarkovADL fit and results
  • Smoke tested: RestrictedMarkovRegression with restrictions enforced
  • Smoke tested: RegimeNumberSelection correctly selects K=2 on 2-regime data
  • All visualization functions produce valid Figure/Axes
  • All imports work from top-level import regimes as rg

🤖 Generated with Claude Code

Morten Tabor and others added 3 commits February 19, 2026 13:34
Implement complete Markov switching framework wrapping statsmodels:

Models:
- MarkovRegression, MarkovAR, MarkovADL with fit() -> Results pattern
- from_model() class methods for one-way mapping from OLS/AR/ADL
- markov_switching() convenience methods on existing model classes
- Label switching resolution via ordering="first_appearance" (default)

Restricted transitions:
- RestrictedMarkovRegression/AR with constrained transition matrices
- non_recurring() factory for Chib (1998) structural break structure
- Override transform_params to enforce exact zeros in transition matrix

Testing algorithms:
- NonRecurringRegimeTest: LR test for non-recurring vs unrestricted
- SequentialRestrictionTest: GETS-style algorithm for transition restrictions
  with Holm-Bonferroni correction and joint test safeguard
- Chi-bar-squared and parametric bootstrap critical values

Regime number selection:
- RegimeNumberSelection with IC (AIC/BIC/HQIC) and sequential LRT methods

Visualization:
- plot_smoothed_probabilities, plot_regime_shading, plot_transition_matrix,
  plot_parameter_time_series, plot_ic

Tests: 98 new tests (816 total), all passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add Markov regime-switching models, restricted transitions, sequential
restriction testing, regime number selection, and visualization functions
to README.md, ROADMAP.md, and CHANGELOG.md.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Auto-fixed: unused imports (F401), f-strings without placeholders (F541),
unsorted __all__ (RUF022). Manually fixed: unused local variables (F841),
unused loop variables (B007), nested if statements (SIM102), unnecessary
generator (C401), TYPE_CHECKING import placement (TC001/TC004). Applied
ruff format for consistent formatting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mortentabor mortentabor merged commit b47d676 into main Feb 19, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant