Dividend-adjusted US equity total returns, risk decomposition, attribution & ETF hedge ratios
io.github.BlueWaterCorp/riskmodels β MCP Server
RiskModels provides dividend-adjusted US equity total returns, factor risk decomposition, return attribution, and ETF-executable hedge ratios for US equities. It serves this dataset via REST, a typed SDK, and a built-in MCP server. The included output is simulation-grade and designed for monthly end model surfaces.
π οΈ Key Features
Dividend-adjusted US equity total returns
Factor risk decomposition and explained-risk decompositions
Return attribution
ETF hedge ratios that are executable
Post-regression outputs, including related L1βL3 series
π Use Cases
Computing everyday returns, risk, and hedging for the surfaced equity universe
Performing risk decomposition and return attribution on US stocks
Generating ETF hedge ratios for portfolio-level hedging
β‘ Developer Benefits
Built-in MCP server alongside REST and a typed SDK
Typed outputs including hedge ratios and related L1βL3 series
β οΈ Limitations
Headline universe at each month end is the largest ~3,000 by market cap, even though the full panel covers on the order of 16,000 US stocks.
RiskModels provides clean dividend-adjusted total returns, factor risk decomposition, return attribution, and ETF-executable hedge ratios for US equities β over REST, a typed SDK, and a built-in MCP server. The dataset is simulation-grade: it covers on the order of 16,000 US stocks across the full historical panel, while at each month end the modelβs headline universe is the largest ~3,000 by market capβthe set the API surfaces for everyday returns, risk, and hedging.
Post-regression outputs (hedge ratios, explained-risk decompositions, and related L1βL3 series) are on daily history from 2007 through present; split- and dividend-adjusted returns (the inputs to the rolling regressions) begin 2006-01-04. The API is AI-agent ready, including a built-in Model Context Protocol (MCP) server for seamless integration with LLMs.
Important: The hostname api.riskmodels.app is not used for the public API or machine-readable docs. Older links or docs that mention it should be treated as obsolete; use riskmodels.app (apex) as above.
π API Overview
The RiskModels API provides institutional-grade equity risk analysis:
Daily factor decompositions β market, sector, subsector explained-risk fractions for the headline ~3,000 largest US stocks by market cap (month-end universe)
Hedge ratios β dollar-denominated ETF hedge amounts (L1/L2/L3) designed to remain executable with liquid raw ETFs
Historical time series β split- and dividend-adjusted returns (2006βpresent) plus rolling hedge ratios and ER (2007βpresent; factor outputs need a full regression window)
Data coverage:~16,000 US stocks in the historical panel; ~3,000 largest by market cap at each month end for headline outputs. Updated daily. Factor outputs (HR/ER):2007 through present. Adjusted return series:2006-01-04 through present.
Why The Engine Matters
RiskModels is designed to be useful for real portfolio work, not just descriptive analytics:
Built to be time-safe β the engine is designed to avoid common sources of forward contamination such as recycled tickers, snapshot shares, and retroactive universe contraction
Grounded in a real Security Master β ticker-level outputs sit on top of a point-in-time identity layer built for identifier continuity, symbol changes, and historically defensible shares data
Hierarchical by design β the model separates market, sector, and subsector structure rather than collapsing everything into a flat beta view
Tradeable in practice β the published hedge ratios are designed to work with liquid ETFs at execution time, not only with synthetic or orthogonalized factors
Built on adjusted return series β split- and dividend-adjusted returns make the decomposition and hedge ratios more economically consistent over long horizons
For a deeper explanation of the engine design choices behind these claims, see the methodology docs and API reference.
π Python SDK (riskmodels-py)
Prefer the Python SDK over raw REST for agent-native workflows β ticker resolution, semantic field normalization, validation with instructional errors, and LLM-ready context formatting are built in.
Charts below are generated from live API data (get_rankings + MAG7 L3 batch metrics) via scripts/generate_readme_assets.py. Set RISKMODELS_API_KEY (free tier is sufficient), run the script from the repo root, then commit ./assets/ and ./public/docs/readme/.
MAG7 β L3 Ο-scaled decomposition
Same βtechβ label, different subsector DNA β bar length β annualized Ο; segments = Ο Γ L3 market/sector/subsector risk ratios + residual (HR share). POST /batch/analyze via SDK save_mag7_l3_sigma_rr_png
Authentication: Bearer token (API key or OAuth2 JWT)
Discovery:https://riskmodels.app/.well-known/mcp.json (see OPENAPI_SPEC.yaml)
Local MCP server (mcp/ in this repo) β stdio transport for Cursor / Claude Desktop / Zed: discovers capabilities, schemas, OpenAPI, and SDK-backed live-paper risk tools. Tools shipped here include:
riskmodels_list_endpoints β List API capabilities (id, method, endpoint, short description)
riskmodels_get_capability β Full capability record by id (parameters, pricing, examples)
riskmodels_get_schema β JSON Schema for a response type (e.g. ticker-returns-v2.json)
riskmodels_decompose, riskmodels_compare, riskmodels_hedge_position, riskmodels_portfolio_decompose, riskmodels_whitepaper_example β Agent-ready SDK outputs with chart_data, suggested_chart, and plain-English summaries
For live risk data and portfolio math, call the REST API (e.g. GET /api/metrics/{ticker}, POST /api/batch/analyze, GET /api/l3-decomposition), the Python SDK (riskmodels-py), or the listed MCP tools.
Anthropic Claude (Managed Agents vs Messages API): internal engineering design for optional cloud-hosted agents, billing, and compliance β see docs/ANTHROPIC_CLOUD_AGENTS.md.
β¨οΈ Command-line CLI (riskmodels)
The npm package in cli/ installs the riskmodels binary: config, SQL query (billed API or direct Supabase), schema introspection, balance, and static agent manifests.
Install from npm:
bash
npm install -g riskmodels
riskmodels --help
Develop from this repo:
bash
cd cli
npm ci
npm run build
npm run install:global # optional: npm link for local testing
Publish to npm (maintainers): procedure is documented in the private BWMACRO monorepo (docs/RISKMODELS_CLI_NPM_PUBLISHING.md), not here. Only publish from the cli/ directory β the repo root Next.js app is not published to npm.
π» Developer Portal (This Repo)
This repo now includes a Next.js developer portal with:
π Interactive API reference (Redoc OpenAPI viewer)
π‘ Code examples with syntax highlighting and copy buttons
π― Step-by-step quickstart guide
Local Development
bash
# Install dependencies
npm install
# Option A: Copy env template and fill in Supabase/Stripe keys manuallycp .env.example .env.local
# Option B: Use Doppler (recommended for team consistency)# Ensure `doppler login` is done, then:
doppler secrets download --no-file --format env > .env.local
# Generate OpenAPI JSON for Redoc
npm run build:openapi
# Run dev server
npm run dev
Screenshot Capture Hygiene:
When capturing site screenshots for audit or documentation:
Ensure the build passes first:npm run build must complete without errors
Verify the dev server serves HTTP 200: Visit http://localhost:3000 and confirm pages render (not "Internal Server Error")
Run the capture script:python3 capture_site.py (requires Playwright)
The script will skip pages returning HTTP 500 or containing "Internal Server Error" content. Screenshots with server errors should never be committed to the repository.
Environment Management with Doppler:
This repo uses Doppler for secrets management. The doppler.yaml is pre-configured for the erm3 project:
bash
# Verify setup (should show project: erm3, config: dev)
doppler setup
# List all secrets
doppler secrets
# Get a specific secret
doppler secrets get STRIPE_SECRET_KEY
# Export dev secrets to .env.local for curl testing and local dev
npm run doppler:env# Push production secrets to Vercel (requires vercel login + project link)
npm run vercel:sync-env:doppler
For curl/API testing with Doppler secrets:
bash
# 1. Export secrets to .env.local
npm run doppler:env# 2. Source them for your shell sessionsource .env.local
# 3. Use in curl commands
curl -H "Authorization: Bearer $RISKMODELS_API_SERVICE_KEY" \
https://riskmodels.app/api/health
See DEPLOYMENT.md for detailed Vercel/Doppler integration.