### Install RegimeLab from PyPI Source: https://github.com/algorithmicmind/regimelab/blob/main/README.md Install the base package or include the TUI extra for interactive terminal dashboard support. ```bash # Install from PyPI pip install regimelab # Or install with interactive TUI support pip install "regimelab[tui]" ``` -------------------------------- ### RegimeLab CLI Commands Source: https://github.com/algorithmicmind/regimelab/blob/main/README.md Shows the main CLI commands: run a full pipeline with HTML report, inspect telemetry for a date, and launch the interactive TUI dashboard. ```bash # 1. Run full walk-forward pipeline and generate interactive HTML report regimelab run --report market_report.html # 2. Inspect point-in-time telemetry for a specific date (JSON output) regimelab asof 2023-10-15 # 3. Launch the full interactive Textual Terminal Dashboard regimelab tui ``` -------------------------------- ### Run Walk-Forward Backtest with run_pipeline Source: https://github.com/algorithmicmind/regimelab/blob/main/README.md Configures a synthetic data provider, HMM classifier with 4 states, and backtest parameters. Runs the pipeline and prints strategy metrics. ```python from regimelab import Settings from regimelab.pipeline import run_pipeline settings = Settings( data={"provider": "synthetic"}, # Fully offline, reproducible dataset model={"classifier": "hmm", "n_states": 4}, backtest={"transaction_cost_bps": 5.0, "confidence_floor": 0.5}, ) result = run_pipeline(settings, command="backtest_run") metrics = result.backtest.metrics print(f"Strategy CAGR: {metrics.cagr:.2%}") print(f"Sharpe Ratio: {metrics.sharpe:.2f}") print(f"Max Drawdown: {metrics.max_drawdown:.2%}") ``` -------------------------------- ### Lint with ruff Source: https://github.com/algorithmicmind/regimelab/blob/main/README.md Runs the ruff linter on the RegimeLab codebase. ```bash uv run ruff check . ``` -------------------------------- ### Detect Current Market Regime with run_single_asof Source: https://github.com/algorithmicmind/regimelab/blob/main/README.md Runs point-in-time regime inference for a specified date using yfinance data. Prints the detected regime, confidence, and target allocation. ```python from regimelab import Settings from regimelab.pipeline import run_single_asof # Run point-in-time regime inference for any historical or current date settings = Settings(data={"provider": "yfinance"}) payload = run_single_asof(settings, asof="2024-12-31") print(f"Detected Regime: {payload.regime.value}") print(f"Confidence: {payload.probabilities.confidence:.2%}") print(f"Target Allocation: {payload.target_weights.weights if payload.target_weights else {}}") ``` -------------------------------- ### build_feature_matrix(panel, settings) Source: https://github.com/algorithmicmind/regimelab/blob/main/docs/architecture.md Builds a feature matrix from an aligned panel and settings. Returns a pandas DataFrame with canonical feature columns. ```APIDOC ## build_feature_matrix(panel, settings) ### Description Builds a feature matrix from an aligned panel and settings. Returns a pandas DataFrame with canonical feature columns. ### Method Function ### Signature `build_feature_matrix(panel: AlignedPanel, settings: Settings) -> pd.DataFrame` ### Parameters - **panel** (AlignedPanel) - Required - Aligned market data panel. - **settings** (Settings) - Required - Configuration settings. ### Returns - **pd.DataFrame** - Feature matrix with canonical columns. ``` -------------------------------- ### Run test suite with pytest Source: https://github.com/algorithmicmind/regimelab/blob/main/README.md Runs the RegimeLab test suite with causality property tests using pytest. ```bash uv run pytest -q ``` -------------------------------- ### RegimeLab TOML configuration Source: https://github.com/algorithmicmind/regimelab/blob/main/README.md TOML configuration for RegimeLab. Sets data provider (yfinance, synthetic, or parquet), model classifier (hmm, gmm, or hamilton), and backtest parameters. Environment variables like REGIMELAB_DATA__PROVIDER=yfinance or Python kwargs can override these settings. ```toml [data] provider = "yfinance" # "yfinance", "synthetic", or "parquet" start = "2005-01-01" benchmark = "SPY" calendar_anchor = "SPY" [model] classifier = "hmm" # "hmm", "gmm", or "hamilton" n_states = 4 covariance_type = "diag" min_train_observations = 756 [backtest] transaction_cost_bps = 5.0 confidence_floor = 0.5 refit_frequency_days = 63 ``` -------------------------------- ### Run strict mypy type checking Source: https://github.com/algorithmicmind/regimelab/blob/main/README.md Runs strict mypy type checking on the RegimeLab source code. ```bash uv run mypy src/regimelab ``` -------------------------------- ### snapshot_at(matrix, asof) Source: https://github.com/algorithmicmind/regimelab/blob/main/docs/architecture.md Extracts a FeatureSnapshot from a feature matrix at a given date. Returns a FeatureSnapshot object. ```APIDOC ## snapshot_at(matrix, asof) ### Description Extracts a FeatureSnapshot from a feature matrix at a given date. Returns a FeatureSnapshot object. ### Method Function ### Signature `snapshot_at(matrix: pd.DataFrame, asof: dt.date | pd.Timestamp) -> FeatureSnapshot` ### Parameters - **matrix** (pd.DataFrame) - Required - Feature matrix. - **asof** (dt.date | pd.Timestamp) - Required - Date for the snapshot. ### Returns - **FeatureSnapshot** - Snapshot of features at the given date. ``` -------------------------------- ### regimelab.features.breadth Source: https://github.com/algorithmicmind/regimelab/blob/main/docs/architecture.md Functions for computing market breadth features. ```APIDOC ## regimelab.features.breadth ### Description Functions for computing market breadth features. ### Functions #### percent_above_sma(prices, *, window=200, min_assets=3) - **prices** (pd.DataFrame) - Required - Asset prices. - **window** (int) - Optional - SMA window. Default 200. - **min_assets** (int) - Optional - Minimum number of assets. Default 3. - **Returns** (pd.Series) - Percentage of assets above SMA. #### breadth_momentum_series(breadth, *, window=21) - **breadth** (pd.Series) - Required - Breadth series. - **window** (int) - Optional - Momentum window. Default 21. - **Returns** (pd.Series) - Breadth momentum series. #### breadth_thrust(breadth, *, fast=10, slow=63) - **breadth** (pd.Series) - Required - Breadth series. - **fast** (int) - Optional - Fast window. Default 10. - **slow** (int) - Optional - Slow window. Default 63. - **Returns** (pd.Series) - Breadth thrust series. #### breadth_features(prices, *, sma_window=200, momentum_window=21, min_assets=3) - **prices** (pd.DataFrame) - Required - Asset prices. - **sma_window** (int) - Optional - SMA window. Default 200. - **momentum_window** (int) - Optional - Momentum window. Default 21. - **min_assets** (int) - Optional - Minimum number of assets. Default 3. - **Returns** (pd.DataFrame) - Breadth features. ``` -------------------------------- ### regimelab.features.volatility Source: https://github.com/algorithmicmind/regimelab/blob/main/docs/architecture.md Functions for computing volatility and related features. ```APIDOC ## regimelab.features.volatility ### Description Functions for computing volatility and related features. ### Functions #### parkinson_volatility(high, low, *, window=21, trading_days=252) - **high** (pd.Series) - Required - High prices. - **low** (pd.Series) - Required - Low prices. - **window** (int) - Optional - Rolling window. Default 21. - **trading_days** (int) - Optional - Trading days per year. Default 252. - **Returns** (pd.Series) - Parkinson volatility series. #### garman_klass_volatility(open_, high, low, close, *, window=21, trading_days=252) - **open_** (pd.Series) - Required - Open prices. - **high** (pd.Series) - Required - High prices. - **low** (pd.Series) - Required - Low prices. - **close** (pd.Series) - Required - Close prices. - **window** (int) - Optional - Rolling window. Default 21. - **trading_days** (int) - Optional - Trading days per year. Default 252. - **Returns** (pd.Series) - Garman-Klass volatility series. #### close_to_close_volatility(close, *, window=21, trading_days=252) - **close** (pd.Series) - Required - Close prices. - **window** (int) - Optional - Rolling window. Default 21. - **trading_days** (int) - Optional - Trading days per year. Default 252. - **Returns** (pd.Series) - Close-to-close volatility series. #### vix_term_spread(vix, vix3m) - **vix** (pd.Series) - Required - VIX series. - **vix3m** (pd.Series) - Required - VIX 3-month series. - **Returns** (pd.Series) - VIX term spread series. #### trailing_log_return(close, *, window=21) - **close** (pd.Series) - Required - Close prices. - **window** (int) - Optional - Return window. Default 21. - **Returns** (pd.Series) - Trailing log return series. #### volatility_features(ohlc, vix=None, vix3m=None, *, window=21, return_window=21, trading_days=252) - **ohlc** (pd.DataFrame) - Required - OHLC data. - **vix** (pd.Series, optional) - Optional - VIX series. - **vix3m** (pd.Series, optional) - Optional - VIX 3-month series. - **window** (int) - Optional - Volatility window. Default 21. - **return_window** (int) - Optional - Return window. Default 21. - **trading_days** (int) - Optional - Trading days per year. Default 252. - **Returns** (pd.DataFrame) - Volatility features. ``` -------------------------------- ### Extract Causal Systemic Risk Features Source: https://github.com/algorithmicmind/regimelab/blob/main/README.md Loads an aligned data panel and builds a causal feature matrix. Prints the tail of the feature matrix for inspection. ```python from regimelab import Settings from regimelab.data.fetcher import load_aligned_panel from regimelab.features import build_feature_matrix settings = Settings(data={"provider": "yfinance"}) panel = load_aligned_panel(settings) features = build_feature_matrix(panel, settings) # Inspect causal feature matrix print(features[["absorption_ratio", "absorption_delta", "vix_term_spread", "breadth"]].tail()) ``` -------------------------------- ### regimelab.features.absorption Source: https://github.com/algorithmicmind/regimelab/blob/main/docs/architecture.md Functions for computing absorption ratio and related features. ```APIDOC ## regimelab.features.absorption ### Description Functions for computing absorption ratio and related features. ### Functions #### leading_eigenvector_count(n_assets, fraction=0.2) - **n_assets** (int) - Required - Number of assets. - **fraction** (float) - Optional - Fraction of eigenvalues to consider. Default 0.2. - **Returns** (int) - Number of leading eigenvectors. #### absorption_ratio_series(returns, *, window=500, eigen_fraction=0.2, min_assets=3) - **returns** (pd.DataFrame) - Required - Asset returns. - **window** (int) - Optional - Rolling window size. Default 500. - **eigen_fraction** (float) - Optional - Fraction of eigenvalues. Default 0.2. - **min_assets** (int) - Optional - Minimum number of assets. Default 3. - **Returns** (pd.Series) - Absorption ratio series. #### absorption_delta_series(absorption_ratio, *, short_window=15, long_window=252) - **absorption_ratio** (pd.Series) - Required - Absorption ratio series. - **short_window** (int) - Optional - Short window. Default 15. - **long_window** (int) - Optional - Long window. Default 252. - **Returns** (pd.Series) - Absorption delta series. #### absorption_features(returns, *, window=500, eigen_fraction=0.2, short_window=15, long_window=252, symbols=None) - **returns** (pd.DataFrame) - Required - Asset returns. - **window** (int) - Optional - Rolling window size. Default 500. - **eigen_fraction** (float) - Optional - Fraction of eigenvalues. Default 0.2. - **short_window** (int) - Optional - Short window. Default 15. - **long_window** (int) - Optional - Long window. Default 252. - **symbols** (list, optional) - Optional - List of symbols. - **Returns** (pd.DataFrame) - Absorption features. ``` -------------------------------- ### regimelab.features.correlation Source: https://github.com/algorithmicmind/regimelab/blob/main/docs/architecture.md Functions for computing correlation-based features. ```APIDOC ## regimelab.features.correlation ### Description Functions for computing correlation-based features. ### Functions #### mean_pairwise_correlation(returns, *, window=63, min_assets=3) - **returns** (pd.DataFrame) - Required - Asset returns. - **window** (int) - Optional - Rolling window. Default 63. - **min_assets** (int) - Optional - Minimum number of assets. Default 3. - **Returns** (pd.Series) - Mean pairwise correlation series. #### pairwise_correlation(left, right, *, window=63) - **left** (pd.Series) - Required - Left series. - **right** (pd.Series) - Required - Right series. - **window** (int) - Optional - Rolling window. Default 63. - **Returns** (pd.Series) - Pairwise correlation series. #### rolling_correlation_matrix(returns, asof, *, window=63) - **returns** (pd.DataFrame) - Required - Asset returns. - **asof** (date) - Required - Date for the matrix. - **window** (int) - Optional - Rolling window. Default 63. - **Returns** (pd.DataFrame) - Rolling correlation matrix. #### correlation_features(returns, *, window=63, risk_asset=None, defensive_assets=(), min_assets=3) - **returns** (pd.DataFrame) - Required - Asset returns. - **window** (int) - Optional - Rolling window. Default 63. - **risk_asset** (str, optional) - Optional - Risk asset identifier. - **defensive_assets** (tuple) - Optional - Defensive asset identifiers. - **min_assets** (int) - Optional - Minimum number of assets. Default 3. - **Returns** (pd.DataFrame) - Correlation features. ```