Skip to main content
Glama
riskprism

riskprism

by wanxinwanxin

riskprism

将美国股票组合风险分解为其因子谱。

探索器: https://risk-prism-production.up.railway.app · Agent 模型卡: /model.md

一个开源的、Barra 风格的基础因子风险模型,旨在开箱即可供 AI 代理使用:一个 Python 库、一个 MCP 服务器,以及每周发布的模型产物,覆盖大多数流动性强的美国普通股。

  • 7 个风格因子(规模、价值、动量、波动性、流动性、质量、杠杆)+ 12 个行业(Fama-French 方案)+ 一个市场因子

  • 免费、可再分发数据链:来自 SEC EDGAR(公共领域)的基础数据和 SIC 代码,价格来自可插拔提供商

  • 混合分发:预计算产物(暴露度、因子协方差、特定风险)按周发布,并且完整流水线开放,任何人都可以复现或扩展它们

免责声明:研究软件,按原样提供。此处内容不构成投资建议。

面向 AI 智能体(MCP)

{
  "mcpServers": {
    "riskprism": {
      "command": "riskprism-mcp",
      "env": { "RISKPRISM_ARTIFACTS": "/path/to/artifacts" }
    }
  }
}

暴露的工具:get_model_info、get_portfolio_risk、get_factor_exposures、stress_test、check_coverage。权重为组合权重(空头为负);波动率为年化小数。

Related MCP server: Portfolio Rotation MCP Server

面向人类(Python)

from riskprism import RiskModel

model = RiskModel.load("artifacts")
report = model.portfolio_risk({"AAPL": 0.4, "MSFT": 0.3, "XOM": 0.3})
print(report["total_vol"], report["factor_var_contributions"])

model.stress_test({"AAPL": 1.0}, {"market": -0.10, "momentum": -0.05})

自行构建模型

pip install -e ".[dev]"
export RISKPRISM_EDGAR_UA="your-project (you@example.com)"   # SEC fair-access policy
riskprism-build --max-names 3000 --out artifacts             # yahoo prices, no key needed
riskprism-build --prior artifacts_prev --out artifacts       # append new weeks to a prior build
riskprism-build --provider tiingo ...                        # licensed data, needs TIINGO_API_KEY

每周 GitHub Action 精确运行此流程并发布产物目录;参见 .github/workflows/build-model.yml。

探索器

一个零后端静态站点(托管在 Railway 上,由每次每周构建重新渲染),用于探索模型:累计因子收益、因子波动率和相关性、带压力测试滑块的客户端组合风险沙盒、每股股票的因子画像,以及可视化方法论讲解。所有数学计算都在浏览器中基于嵌入的产物运行。

智能体可在 /model.md(由 /llms.txt 索引)获得每次构建的纯 Markdown 镜像:模型卡、因子定义、相关性以及完整覆盖列表——无需 DOM 解析。

在本地渲染所有内容:

riskprism-site --artifacts artifacts --out site   # index.html + model.md + llms.txt

模型摘要

组件

选择

时间范围

中期(周收益,年化输出)

估计

横截面 WLS(√市值权重),市值加权行业约束

因子协方差

EWMA——波动率半衰期 13 周,相关性半衰期 26 周,PSD 修复

特定风险

EWMA 残差波动率与按历史长度混合的结构(基于特征)先验

全域

估计:价格 ≥ $2,ADV ≥ $1M,26 周以上历史 · 覆盖:所有存活且 ≥ $1 的股票,先验填补空白

历史

前向捕获:每周构建追加到先前版本;退市股票被推算,幸存者偏差逐渐衰减

完整方法论见 docs/METHODOLOGY.md;设计决策及其理由见 docs/DECISIONS.md。

许可证

代码采用 MIT 许可证。发布的模型产物是从 SEC EDGAR(公共领域)和第三方价格提供商构建的派生数据——数据许可讨论见 docs/DECISIONS.md。

Available Tools

7 tools
check_coverageC

Which of the given tickers the current model build covers.

Inputs: tickers (required).

get_etf_riskA

Look-through risk report for one ETF or mutual fund: the latest SEC N-PORT holdings resolve to model tickers and the portfolio math runs on those weights. Reports total/factor/specific vol, factor exposures, top contributions, and the fund block with the holdings date and coverage. Returns an error dict when the ticker locates no fund, or when the model covers less than half of the holdings (bond and international funds). Needs RISKPRISM_EDGAR_UA (an identifying User-Agent, per SEC fair-access policy) for the EDGAR fetches.

Inputs: ticker (required), horizon.

get_factor_exposuresB

Per-asset factor exposures and total/factor/specific vol for each ticker.

Inputs: tickers (required), horizon.

get_model_infoA

Model version, as-of date, factor list, and asset coverage count. horizon: "medium" (default) or "short" — the responsive variant with halved risk half-lives, when available.

Inputs: horizon.

get_portfolio_riskA

Full risk report for a portfolio: total/factor/specific vol, factor exposures, top factor variance contributions, and top asset risk contributions. weights maps ticker -> portfolio weight. ETF and mutual fund tickers expand into their filed holdings before the math runs (set lookthrough=false to disable); funds the model cannot cover are reported in lookthrough.notes. Set optimized=true if the weights came from optimizing against this model: reported vols then include the Shepard second-order correction (optimizers exploit covariance estimation noise, so raw forecasts understate an optimized portfolio's risk). horizon: "medium" or "short" (responsive variant, when available).

Inputs: weights (required), horizon, optimized, lookthrough.

list_model_versionsA

Catalog of published model builds (the versioned registry): release tag, model version, publish date, available horizons, and artifact download URLs. The hosted server always serves the latest build; any historical build can be downloaded by its tag's asset URL.

Inputs: limit.

stress_testB

Estimate portfolio P&L under factor shocks (return units: -0.10 = -10%). Example: {"market": -0.10, "momentum": -0.05}. Use get_model_info for valid factor names.

Inputs: weights (required), factor_shocks (required), horizon.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 7 tools

    Disambiguation4/5

    Most tools target distinct actions: check_coverage checks ticker coverage, get_factor_exposures returns per-asset exposures, get_portfolio_risk returns a full portfolio report, and stress_test applies factor shocks. However, get_model_info also reports asset coverage count, which slightly overlaps with check_coverage, and get_portfolio_risk duplicates some get_factor_exposures output. Descriptions clarify boundaries, so misselection is unlikely.

    Naming Consistency5/5

    All names use snake_case with a verb_noun pattern (check_coverage, get_factor_exposures, list_model_versions, etc.). stress_test is the only minor deviation from the get_* prefix but still fits the verb_noun convention. Consistent and predictable throughout.

    Tool Count5/5

    Seven tools is well-scoped for a risk-model analytics server. Each tool addresses a distinct capability—coverage, exposures, metadata, versions, portfolio risk, ETF look-through, and stress testing—without redundant endpoints.

    Completeness4/5

    Core workflows are covered: coverage checks, model metadata/versions, per-asset exposures, portfolio/ETF risk, and stress testing. Minor gaps include no direct factor covariance/correlation retrieval or historical backtesting, though these are mostly available indirectly or outside the stated scope.

    Maintenance

    ActivityActive
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Portfolio risk analytics MCP server — VaR, Monte Carlo simulation, stress testing, portfolio optimization, options Greeks, and correlation analysis. Real market data via Yahoo Finance. Free tier available, Pro at $29/mo.
      10
      2
      MIT
    • F
      license
      A
      quality
      D
      maintenance
      MCP server providing portfolio analytics tools: beta to a benchmark, sector correlation, and FIFO trade matching with realized/unrealized P&L using Yahoo Finance prices.
      3
      -
    • A
      license
      A
      quality
      A
      maintenance
      MCP server exposing Interactive Brokers' portfolio risk analysis, including model greeks, implied volatility surface, what-if margin, and a local stress engine for P&L curve analysis.
      9
      MIT