algo-risk-var

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Value at Risk (VaR)

风险价值(VaR)

Overview

概述

VaR estimates the maximum loss a portfolio can suffer over a given time horizon at a specified confidence level. Example: "95% 1-day VaR of $1M" means there's a 5% chance of losing more than $1M in one day. Three methods: parametric (normal), historical simulation, Monte Carlo.
VaR估算投资组合在特定时间范围内、指定置信水平下可能遭受的最大损失。例如:“95%置信度下1日VaR为100万美元”意味着在单日损失超过100万美元的概率为5%。主要有三种计算方法:参数法(正态分布法)、历史模拟法、蒙特卡洛模拟法。

When to Use

适用场景

Trigger conditions:
  • Quantifying portfolio downside risk for risk management
  • Setting trading limits and capital reserves
  • Regulatory reporting (Basel III requires VaR-based capital)
When NOT to use:
  • When you need to know how bad losses CAN get beyond VaR (use CVaR/Expected Shortfall)
  • For illiquid assets with no price history (VaR needs return data)
触发条件:
  • 为风险管理量化投资组合的下行风险
  • 设定交易限额和准备金
  • 监管报告(巴塞尔协议III要求基于VaR的资本计算)
不适用场景:
  • 当你需要了解VaR阈值之外的极端损失情况时(请使用CVaR/预期短缺)
  • 针对缺乏价格历史的非流动性资产(VaR需要收益数据)

Algorithm

算法

IRON LAW: VaR Does NOT Tell You How Bad It Gets BEYOND the Threshold
VaR says "95% of the time, losses won't exceed $X." It says NOTHING
about the 5% worst case. A portfolio can have low VaR but catastrophic
tail losses. Always supplement with Expected Shortfall (CVaR) which
measures the average loss in the tail.
IRON LAW: VaR Does NOT Tell You How Bad It Gets BEYOND the Threshold
VaR says "95% of the time, losses won't exceed $X." It says NOTHING
about the 5% worst case. A portfolio can have low VaR but catastrophic
tail losses. Always supplement with Expected Shortfall (CVaR) which
measures the average loss in the tail.

Phase 1: Input Validation

阶段1:输入验证

Collect: portfolio positions, historical returns (min 250 days for 1Y), confidence level (typically 95% or 99%), time horizon (1 day or 10 days). Gate: Sufficient return history, positions valued at current market.
收集信息:投资组合持仓、历史收益数据(至少250天,即1年数据)、置信水平(通常为95%或99%)、时间范围(1天或10天)。 准入条件: 具备充足的收益历史数据,持仓以当前市场价值计价。

Phase 2: Core Algorithm

阶段2:核心算法

Parametric VaR: VaR = -μ + zα × σ (assumes normal returns). For portfolio: use covariance matrix for portfolio σ.
Historical Simulation: 1. Compute daily P&L from historical returns. 2. Sort P&L ascending. 3. VaR = the (1-α) percentile loss.
Monte Carlo: 1. Fit return distribution (or use historical). 2. Simulate 10,000+ portfolio paths. 3. VaR = (1-α) percentile of simulated losses.
参数法VaR: VaR = -μ + zα × σ(假设收益服从正态分布)。对于投资组合:使用协方差矩阵计算组合的σ。
历史模拟法: 1. 根据历史收益计算每日盈亏。2. 将盈亏按升序排列。3. VaR = 第(1-α)百分位的损失值。
蒙特卡洛模拟法: 1. 拟合收益分布(或使用历史数据)。2. 模拟10000+次投资组合路径。3. VaR = 模拟损失的第(1-α)百分位值。

Phase 3: Verification

阶段3:验证

Backtest: count how often actual losses exceed VaR over the past year. At 95% confidence, exceedances should be ~5%. Use Kupiec or Christoffersen test. Gate: Backtest exceedance rate within acceptable bounds.
回测:统计过去一年中实际损失超过VaR的次数。在95%置信水平下,超出次数应约为5%。可使用Kupiec或Christoffersen检验。 准入条件: 回测超出率在可接受范围内。

Phase 4: Output

阶段4:输出

Return VaR estimate with backtest results.
返回VaR估算值及回测结果。

Output Format

输出格式

json
{
  "var": {"amount": 1250000, "confidence": 0.95, "horizon_days": 1, "currency": "TWD"},
  "cvar": {"amount": 1800000},
  "backtest": {"exceedances": 13, "expected": 12.5, "days_tested": 250, "pass": true},
  "metadata": {"method": "historical_simulation", "portfolio_value": 50000000}
}
json
{
  "var": {"amount": 1250000, "confidence": 0.95, "horizon_days": 1, "currency": "TWD"},
  "cvar": {"amount": 1800000},
  "backtest": {"exceedances": 13, "expected": 12.5, "days_tested": 250, "pass": true},
  "metadata": {"method": "historical_simulation", "portfolio_value": 50000000}
}

Examples

示例

Sample I/O

输入输出示例

Input: Portfolio value = $1,000,000. Last 20 sorted daily returns (descending loss):
[-0.050, -0.040, -0.035, -0.030, -0.025, -0.020, -0.015, -0.010, -0.005, 0.000,
  0.005,  0.010,  0.015,  0.020,  0.025,  0.030,  0.035,  0.040,  0.045,  0.050]
Confidence = 95%, horizon = 1 day.
Expected (Historical Simulation):
  • 5th percentile index = floor(20 × 0.05) = 1 → return[1] = -0.040
  • VaR = $1,000,000 × 0.040 = $40,000
  • CVaR (Expected Shortfall) = mean of returns worse than VaR = (-0.050) × $1M = $50,000
Verify: VaR ≤ CVaR always (tail loss ≥ threshold loss). Count of losses > VaR should be ≤ 5% of observations (1 of 20).
输入: 投资组合价值=100万美元。最近20个排序后的日收益(按损失降序):
[-0.050, -0.040, -0.035, -0.030, -0.025, -0.020, -0.015, -0.010, -0.005, 0.000,
  0.005,  0.010,  0.015,  0.020,  0.025,  0.030,  0.035,  0.040,  0.045,  0.050]
置信度=95%,时间范围=1天。
预期结果(历史模拟法):
  • 第5百分位索引= floor(20 × 0.05)=1 → 收益[1]=-0.040
  • VaR=100万美元 × 0.040= 4万美元
  • CVaR(预期短缺)= 劣于VaR的收益平均值=(-0.050) × 100万美元= 5万美元
验证:VaR始终≤CVaR(尾部损失≥阈值损失)。损失超过VaR的次数应≤观测值的5%(20次中的1次)。

Edge Cases

边缘情况

InputExpectedWhy
Normal market conditionsVaR looks adequateBut misses tail events
2008-like crisis in historyHigher VaR from historical methodCaptures fat tails if crisis is in window
Very short history (30 days)Unreliable VaRInsufficient data for tail estimation
输入预期结果原因
正常市场环境VaR看似合理但会遗漏尾部事件
历史数据包含类似2008年的危机历史法计算出的VaR更高若窗口期包含危机,可捕捉厚尾特征
历史数据极短(30天)VaR不可靠尾部估算数据不足

Gotchas

注意事项

  • Normality assumption: Parametric VaR assumes normal returns. Financial returns have fat tails — parametric VaR UNDERESTIMATES tail risk.
  • Historical window: Historical simulation is only as good as the history. If the past 250 days were calm, VaR will be low even if a crisis is coming.
  • Time scaling: VaR scales with √T only under independence and normality. For volatile or trending markets, this approximation is poor.
  • Diversification illusion: VaR from correlated assets using normal-times correlations understates risk. Correlations spike during crises (correlation breakdown).
  • Gaming VaR: Traders can structure positions that look safe under VaR but have catastrophic tail risk. This is why regulators also require stress testing.
  • 正态分布假设: 参数法VaR假设收益服从正态分布。但金融收益存在厚尾特征——参数法VaR会低估尾部风险。
  • 历史窗口期: 历史模拟法的效果取决于所选历史数据。若过去250天市场平稳,即使危机即将来临,VaR仍会偏低。
  • 时间缩放: 仅在收益独立且服从正态分布时,VaR才随√T缩放。对于波动剧烈或趋势性市场,该近似效果较差。
  • 分散化错觉: 使用正常时期相关性计算的相关资产VaR会低估风险。危机期间相关性会飙升(相关性破裂)。
  • VaR操纵: 交易者可构建在VaR模型下看似安全,但存在灾难性尾部风险的头寸。这也是监管机构同时要求压力测试的原因。

References

参考文献

  • For Expected Shortfall (CVaR) calculation, see
    references/expected-shortfall.md
  • For VaR backtesting methods, see
    references/backtesting.md
  • 关于预期短缺(CVaR)的计算,请参阅
    references/expected-shortfall.md
  • 关于VaR回测方法,请参阅
    references/backtesting.md