Volatility MCP
by sathanandhh
README.md
# π Volatility MCP
> An MCP (Model Context Protocol) server for iterative volatility analytics: ARCH β GARCH β GJR-GARCH β EGARCH, with pre-flight statistical gates, input optimization, VaR / Expected Shortfall, Basel backtesting, and a stateful feedback loop that guides an LLM agent through every stage of the analysis.
[](https://www.python.org/)
[](LICENSE)
[](https://modelcontextprotocol.io/)
> **Volatility Analytics Lab** Β· Finance Β· Risk Β· Analytics
---
## What This Is
A **feedback-driven** volatility analytics engine wrapped as an MCP server. An LLM agent (Claude, GPT, etc.) calls tools one at a time; each tool returns results **plus recommendations for the next step**. The agent iterates until diagnostics pass, backtests pass, and reports are generated.
```
data.load β preflight.run β optimize.* β models.fit β diagnostics.run
β compare.run β risk.var β backtest.rolling β backtest.coverage
β report.excel β feedback.explain_decision
```
### Three Pillars
| Pillar | What it does | Folder |
|---|---|---|
| π‘οΈ **Pre-flight gates** | 12 statistical checks run BEFORE any model fit. If Engle ARCH-LM fails, GARCH is blocked. | `core/preflight/` |
| π― **Input optimization** | `(p,q)`, distribution, window, refit frequency chosen by AIC/QLIKE β not by guesswork. | `core/optimize/` |
| π **Feedback loop** | Session state + workflow DAG + advisor. Every tool returns `next_actions[]`. | `core/feedback/` |
---
## Quick Start
```bash
# Clone
git clone https://github.com/volatility-analytics-lab/volatility-mcp.git
cd volatility-mcp
# Install
python -m pip install -e ".[dev]"
# Run tests
make test
# Start the MCP server (stdio transport)
make run
# Or SSE transport for remote access
make run-sse
```
### Connect from Claude Desktop
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
```json
{
"mcpServers": {
"volatility": {
"command": "python",
"args": ["-m", "mcp_server.server"],
"cwd": "/path/to/volatility-mcp"
}
}
}
```
Then ask Claude: *"Analyze Reliance Industries volatility using the volatility MCP server."*
---
## Tool Surface
| Category | Tools |
|---|---|
| **Session** | `open_session`, `close_session`, `get_session_state`, `list_sessions`, `reset_session` |
| **Data** | `load_market`, `load_csv`, `list_universes`, `list_assets` |
| **Pre-flight** | `run_preflight`, `get_gate_status`, `explain_gate` |
| **Optimize** | `optimize_order`, `optimize_distribution`, `optimize_mean`, `optimize_window`, `optimize_refit`, `optimize_horizon` |
| **Models** | `fit_model`, `forecast`, `list_models` |
| **Diagnostics** | `run_diagnostics`, `get_diagnostics` |
| **Compare** | `compare_models` |
| **Risk** | `compute_var`, `compute_es`, `basel_es`, `portfolio_var` |
| **Scenario** | `apply_market_shock`, `stressed_var`, `list_stress_scenarios` |
| **Backtest** | `rolling_backtest`, `backtest_kupiec`, `backtest_christoffersen`, `backtest_traffic_light`, `backtest_dynamic_quantile`, `backtest_diebold_mariano`, `backtest_coverage_scorecard` |
| **Report** | `build_excel`, `build_pdf`, `build_markdown` |
| **Feedback** | `get_next_action`, `explain_decision`, `get_recommendations`, `list_valid_transitions` |
See [docs/MCP_PROTOCOL.md](docs/MCP_PROTOCOL.md) for the full surface.
---
## Architecture
```
Presentation: Streamlit Β· Claude Desktop Β· REST clients Β· Jupyter
β HTTP / stdio / SSE
Protocol: FastMCP server (tools Β· resources Β· prompts)
β
Engine: core/ (preflight Β· diagnostics Β· models Β· optimize
Β· risk Β· backtest Β· feedback Β· reporting)
β
Storage: session_store/ (SQLite + parquet)
Data: yfinance Β· CSV Β· Alpha Vantage Β· Polygon Β· Kite
```
See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the full layered design.
---
## Folder Structure
```
volatility-mcp/
βββ mcp_server/ # MCP protocol layer
β βββ server.py # Entry point: registers tools, resources, prompts
β βββ tools/ # Tools callable by the LLM agent
β β βββ session.py # open_session / close_session / get_state
β β βββ data.py # load_market / load_csv / list_universes
β β βββ preflight.py # run_preflight / get_gate_status
β β βββ diagnostics.py # run_diagnostics (LB, ARCH-LM, JB, Q-Q stats)
β β βββ optimize.py # optimize_order / optimize_distribution / optimize_window
β β βββ models.py # fit_model / forecast / list_models
β β βββ compare.py # compare_models (AIC/BIC/QLIKE/RMSE)
β β βββ risk.py # compute_var / compute_es / basel_es
β β βββ scenario.py # apply_shock / stressed_var
β β βββ backtest.py # rolling_backtest / kupiec / christoffersen
β β βββ report.py # build_excel / build_pdf / build_markdown
β β βββ feedback.py # get_next_action / explain_decision
β βββ resources/ # Static context (read by LLM, not executed)
β β βββ model_catalog.md
β β βββ test_catalog.md
β β βββ workflows/ # 01_discovery β 05_validation
β βββ prompts/ # Prompt templates for guided workflows
β βββ schemas/ # JSON schemas for tool I/O contracts
β
βββ core/ # Framework-agnostic engine (no MCP code here)
β βββ data/ # Providers: yfinance, CSV, Alpha Vantage, Polygon, Kite
β βββ preflight/ # 12-check gate layer
β β βββ checks/ # 01_sample_size.py β¦ 12_frequency_adequacy.py
β βββ diagnostics/ # Post-fit: LB, ARCH-LM, JB, sign-bias, Nyblom
β βββ models/
β β βββ univariate/ # ARCH, GARCH, GJR-GARCH, EGARCH, FIGARCH, EWMA
β β βββ multivariate/ # DCC, BEKK, O-GARCH
β β βββ stochastic/ # Heston, SV-Jumps
β β βββ ml/ # LSTM, Transformer, TFT
β βββ optimize/ # order_selector, distribution_selector, window_selectorβ¦
β βββ risk/ # VaR (parametric, historical, FHS, MC), ES, Basel, portfolio
β βββ backtest/ # Kupiec, Christoffersen, DQ, Traffic Light, Diebold-Mariano
β βββ feedback/ # Session, state machine, workflow DAG, advisor, decision log
β βββ reporting/ # Excel, PDF, Markdown, Plotly charts
β
βββ session_store/ # SQLite / DuckDB persistent session backend
βββ tests/ # Mirrors core/ structure; synthetic GARCH fixtures
βββ examples/
β βββ 01_basic_flow.py # preflight β fit β forecast β VaR
β βββ 02_feedback_loop_demo.py # Full iterate-until-stable flow
β βββ 03_optimization_walkthrough.py
β βββ notebooks/mcp_client_demo.ipynb
βββ docker/
β βββ Dockerfile
β βββ docker-compose.yml
β βββ entrypoint.sh
βββ docs/
βββ ARCHITECTURE.md
βββ FEEDBACK_LOOP.md
βββ PREFLIGHT_CHECKS.md
βββ INPUT_OPTIMIZATION.md
βββ MODEL_CATALOG.md
βββ TEST_CATALOG.md
βββ MCP_PROTOCOL.md
βββ DECISION_RULES.md
```
---
## Documentation
| Doc | What it covers |
|---|---|
| [ARCHITECTURE.md](docs/ARCHITECTURE.md) | Layered architecture, data flow, scaling options |
| [FEEDBACK_LOOP.md](docs/FEEDBACK_LOOP.md) | How the iterative workflow works |
| [PREFLIGHT_CHECKS.md](docs/PREFLIGHT_CHECKS.md) | Every gate explained |
| [INPUT_OPTIMIZATION.md](docs/INPUT_OPTIMIZATION.md) | How each input is tuned |
| [MODEL_CATALOG.md](docs/MODEL_CATALOG.md) | When to use which model |
| [TEST_CATALOG.md](docs/TEST_CATALOG.md) | Every statistical test |
| [MCP_PROTOCOL.md](docs/MCP_PROTOCOL.md) | Tool/resource/prompt surface |
| [DECISION_RULES.md](docs/DECISION_RULES.md) | Decision tree for model selection |
---
## Credits & Intellectual Debt
This project is built on the shoulders of the following thinkers and their work.
**Nassim Nicholas Taleb** β *The Black Swan* (2007), *Dynamic Hedging* (1997),
*Antifragile* (2012). The pre-flight normality gate, stressed VaR scenarios,
and the philosophy of iterating toward robustness over point estimates all
trace back here.
**Robert F. Engle** β ARCH paper (*Econometrica*, 1982). The Engle ARCH-LM
test is the single most critical pre-flight gate: if it fails, GARCH is blocked.
**Tim Bollerslev** β GARCH(*p,q*) paper (*Journal of Econometrics*, 1986).
The industry workhorse at the center of the model catalog.
**Nelson (1991), Glosten-Jagannathan-Runkle (1993)** β EGARCH and GJR-GARCH
respectively. The leverage asymmetry gate recommends these when sign-bias fires.
**Philippe Jorion** β *Value at Risk* (3rd ed., 2006). The parametric,
historical, and FHS VaR implementations follow his treatment directly.
**Kupiec (1995), Christoffersen (1998), Engle & Manganelli (2004)** β the
POF, conditional coverage, and Dynamic Quantile backtests that form the
coverage scorecard.
**Patton (2011)** β established QLIKE as the robust loss function for
volatility forecast comparison. Default objective in `optimize_window`.
**Diebold & Mariano (1995)** β the DM test used in `backtest_diebold_mariano`
to compare competing model forecasts.
**Basel Committee on Banking Supervision** β Basel III framework: source of
the 97.5% ES requirement, 10-day horizon, traffic light zones, and capital
multiplier rules.
**Kevin Sheppard** β the [`arch`](https://github.com/bashtage/arch) Python
package that powers all GARCH-family estimation in this project.
---
## License
MIT β see [LICENSE](LICENSE).
Educational use only. Market data may be delayed. Not investment advice.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues