# vanshmohla29/sector_rotation_quantstrategy architecture

> Architecture diagram of the GitHub repository vanshmohla29/sector_rotation_quantstrategy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vanshmohla29/sector_rotation_quantstrategy
- Repository: https://github.com/vanshmohla29/sector_rotation_quantstrategy

## Overview

This repository detects Indian market regimes, converts them into sector allocations, and supports both historical validation and frozen-model paper trading. The main workflow in regime_detector_v2.py gathers market and macro data, builds the documented 11-signal feature set, decodes four HMM regimes, learns sector mixes, and writes results consumed by paper_portfolio.py and the production interfaces. The README also documents risk controls, robustness analysis, visualizations, and alerts. Some branches are documented but their implementation was not sampled; those relationships cite the README rather than implying source inspection.

Main entry points: [`paper_portfolio.py`](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/paper_portfolio.py) (Frozen-model paper portfolio), [`regime_detector_v2.py`](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py) (HMM regime detection), [`hmm_model.pkl`](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/hmm_model.pkl) (Frozen model artifacts), [`regime_history_v2.csv`](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_history_v2.csv) (Regime history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Market Data"]
  node_market_ingest["Market and macro ingest"]
  node_clean_features["Cleaning and features"]
end

subgraph group_model["Regime Modeling"]
  node_hmm["HMM regime detection"]
  node_sector_opt["Sector mix optimization"]
  node_model_artifacts["Frozen model artifacts<br/>[hmm_model.pkl]"]
  node_regime_history[("Regime history")]
end

subgraph group_strategy["Strategy and Validation"]
  node_validation["Walk-forward robustness"]
  node_paper_engine["Frozen-model paper portfolio<br/>[paper_portfolio.py]"]
  node_portfolio_history[("Paper portfolio history")]
  node_visuals["Performance visualizations<br/>[paper_portfolio.py]"]
end

subgraph group_ops["Live Interfaces"]
  node_alerts["Transition and daily alerts"]
  node_api["FastAPI service<br/>[regime_api.py]"]
  node_telegram["Telegram command interface<br/>[telegram_bot.py]"]
end

node_analyst(("Market user"))
node_nse["NSE market data"]
node_macro_sources["Official macro sources"]
node_telegram_service["Telegram service"]

node_nse -->|"supplies prices"| node_market_ingest
node_macro_sources -->|"supplies indicators"| node_market_ingest
node_market_ingest -->|"builds features"| node_clean_features
node_clean_features -->|"provides signals"| node_hmm
node_hmm -->|"informs allocation"| node_sector_opt
node_hmm -.->|"saves model"| node_model_artifacts
node_sector_opt -.->|"saves sector mix"| node_model_artifacts
node_hmm -.->|"records regimes"| node_regime_history
node_hmm -->|"validated by"| node_validation
node_model_artifacts -->|"loads frozen model"| node_paper_engine
node_regime_history -->|"sets freeze date"| node_paper_engine
node_sector_opt -->|"provides sector mix"| node_paper_engine
node_paper_engine -.->|"records trades"| node_portfolio_history
node_paper_engine -->|"renders dashboard"| node_visuals
node_paper_engine -->|"emits transitions"| node_alerts
node_model_artifacts -->|"loads artifacts"| node_api
node_regime_history -->|"serves current state"| node_api
node_analyst -->|"requests predictions"| node_api
node_analyst -->|"issues commands"| node_telegram
node_telegram -.->|"sends notifications"| node_telegram_service
node_alerts -.->|"delivers alerts"| node_telegram_service

click node_market_ingest "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py"
click node_clean_features "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py"
click node_hmm "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py"
click node_sector_opt "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py"
click node_model_artifacts "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/hmm_model.pkl"
click node_regime_history "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_history_v2.csv"
click node_validation "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/parameter_stability_test.py"
click node_paper_engine "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/paper_portfolio.py"
click node_portfolio_history "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/paper_portfolio_history.csv"
click node_visuals "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/paper_portfolio.py"
click node_alerts "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py"
click node_api "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_api.py"
click node_telegram "https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/telegram_bot.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_market_ingest,node_clean_features,node_analyst toneBlue
class node_hmm,node_sector_opt,node_model_artifacts,node_regime_history toneAmber
class node_validation,node_paper_engine,node_portfolio_history,node_visuals toneMint
class node_alerts,node_api,node_telegram toneRose
class node_nse,node_macro_sources,node_telegram_service toneIndigo
```

## Components

### Market Data

- [Market and macro ingest](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py): `regime_detector_v2.py`
- [Cleaning and features](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py): `regime_detector_v2.py`

### Regime Modeling

- [HMM regime detection](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py): `regime_detector_v2.py`
- [Sector mix optimization](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py): `regime_detector_v2.py`
- [Frozen model artifacts](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/hmm_model.pkl): `hmm_model.pkl`
- [Regime history](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_history_v2.csv): `regime_history_v2.csv`

### Strategy and Validation

- [Walk-forward robustness](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/parameter_stability_test.py): `parameter_stability_test.py`
- [Frozen-model paper portfolio](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/paper_portfolio.py): `paper_portfolio.py`
- [Paper portfolio history](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/paper_portfolio_history.csv): `paper_portfolio_history.csv`
- [Performance visualizations](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/paper_portfolio.py): `paper_portfolio.py`

### Live Interfaces

- [Transition and daily alerts](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_detector_v2.py): `regime_detector_v2.py`
- [FastAPI service](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/regime_api.py): `regime_api.py`
- [Telegram command interface](https://github.com/vanshmohla29/sector_rotation_quantstrategy/blob/main/telegram_bot.py): `telegram_bot.py`

### Other components

- **Market user**
- **NSE market data**
- **Official macro sources**
- **Telegram service**

## Connections

- NSE market data → Market and macro ingest: supplies prices (evidence: `README.md`)
- Official macro sources → Market and macro ingest: supplies indicators (evidence: `README.md`)
- Market and macro ingest → Cleaning and features: builds features (evidence: `README.md`)
- Cleaning and features → HMM regime detection: provides signals (evidence: `README.md`)
- HMM regime detection → Sector mix optimization: informs allocation (evidence: `README.md`)
- HMM regime detection → Frozen model artifacts: saves model
- Sector mix optimization → Frozen model artifacts: saves sector mix
- HMM regime detection → Regime history: records regimes
- HMM regime detection → Walk-forward robustness: validated by (evidence: `README.md`)
- Frozen model artifacts → Frozen-model paper portfolio: loads frozen model (evidence: `paper_portfolio.py`)
- Regime history → Frozen-model paper portfolio: sets freeze date (evidence: `paper_portfolio.py`)
- Sector mix optimization → Frozen-model paper portfolio: provides sector mix (evidence: `README.md`)
- Frozen-model paper portfolio → Paper portfolio history: records trades
- Frozen-model paper portfolio → Performance visualizations: renders dashboard (evidence: `paper_portfolio.py`)
- Frozen-model paper portfolio → Transition and daily alerts: emits transitions (evidence: `README.md`)
- Frozen model artifacts → FastAPI service: loads artifacts (evidence: `regime_api.py`)
- Regime history → FastAPI service: serves current state (evidence: `regime_api.py`)
- Market user → FastAPI service: requests predictions (evidence: `regime_api.py`)
- Market user → Telegram command interface: issues commands (evidence: `README.md`)
- Telegram command interface → Telegram service: sends notifications
- Transition and daily alerts → Telegram service: delivers alerts
