name: value-at-risk-calculator description: 用于金融和操作风险评估的风险价值(VaR)及相关风险指标计算技能 allowed-tools:
- Read
- Write
- Glob
- Grep
- Bash
metadata:
specialization: decision-intelligence
domain: business
category: risk
priority: medium
tools-libraries:
- scipy.stats
- numpy
- arch
- riskfolio-lib
风险价值(VaR)计算器
概述
风险价值计算器技能提供全面的能力,使用多种方法计算VaR及相关风险指标。它通过参数法、历史法和模拟法支持金融风险评估、操作风险量化和监管合规。
功能
- 历史模拟VaR
- 参数法VaR(方差-协方差)
- 蒙特卡洛VaR
- 条件风险价值(CVaR/期望损失)
- 增量VaR和成分VaR
- 压力测试
- 回测和验证
- 监管报告支持
使用流程
- 决策支持的蒙特卡洛模拟
- 风险评估
- 决策质量评估
使用方法
历史模拟VaR
# 历史VaR配置
historical_var_config = {
"method": "historical_simulation",
"data": {
"returns": portfolio_returns, # 历史收益序列
"period": "daily",
"history_length": 252 # 1年交易日
},
"confidence_levels": [0.95, 0.99],
"holding_period": 1, # 天数
"options": {
"age_weighting": {
"enabled": True,
"decay_factor": 0.97
}
}
}
参数法VaR
# 参数法(方差-协方差)VaR
parametric_var_config = {
"method": "parametric",
"portfolio": {
"positions": {
"Asset_A": {"value": 1000000, "weight": 0.4},
"Asset_B": {"value": 750000, "weight": 0.3},
"Asset_C": {"value": 750000, "weight": 0.3}
}
},
"parameters": {
"volatilities": {"Asset_A": 0.20, "Asset_B": 0.15, "Asset_C": 0.25},
"correlation_matrix": [
[1.0, 0.3, 0.2],
[0.3, 1.0, 0.5],
[0.2, 0.5, 1.0]
]
},
"confidence_level": 0.99,
"holding_period": 10 # 天数
}
蒙特卡洛VaR
# 蒙特卡洛VaR配置
monte_carlo_var_config = {
"method": "monte_carlo",
"simulations": 100000,
"model": {
"type": "geometric_brownian_motion",
"parameters": {
"drift": "historical",
"volatility": "garch"
}
},
"portfolio_valuation": "full_revaluation",
"confidence_levels": [0.95, 0.99],
"holding_period": 10
}
条件风险价值(期望损失)
CVaR表示超过VaR时的预期损失:
- 95% CVaR = 最差5%情景的平均损失
- 巴塞尔协议III/IV要求用于市场风险资本
- 比VaR更一致的风险度量
压力测试
# 压力测试情景
stress_tests = {
"scenarios": [
{
"name": "2008年金融危机",
"shocks": {"equity": -0.40, "credit_spreads": 0.03, "rates": -0.02}
},
{
"name": "2020年3月新冠疫情",
"shocks": {"equity": -0.30, "volatility": 0.50, "credit_spreads": 0.02}
},
{
"name": "利率飙升",
"shocks": {"rates": 0.03, "equity": -0.15}
}
],
"output": ["portfolio_loss", "position_contributions"]
}
输入模式
{
"method": "historical|parametric|monte_carlo",
"portfolio": {
"positions": "object",
"total_value": "number"
},
"data": {
"returns": "array or path",
"period": "string"
},
"parameters": {
"confidence_levels": ["number"],
"holding_period": "number",
"volatility_model": "string"
},
"stress_testing": {
"scenarios": ["object"]
},
"backtesting": {
"enabled": "boolean",
"test_period": "string"
}
}
输出模式
{
"var_results": {
"confidence_level": {
"VaR": "number",
"VaR_percent": "number",
"CVaR": "number",
"CVaR_percent": "number"
}
},
"component_var": {
"position": {
"marginal_var": "number",
"component_var": "number",
"contribution_percent": "number"
}
},
"stress_test_results": {
"scenario_name": {
"portfolio_loss": "number",
"loss_percent": "number"
}
},
"backtesting": {
"exceptions": "number",
"exception_rate": "number",
"traffic_light": "green|yellow|red",
"kupiec_test": "object",
"christoffersen_test": "object"
},
"risk_attribution": "object"
}
最佳实践
- 使用多种方法并比较结果
- 定期进行回测验证
- 包含厚尾分布(t分布或历史数据用于参数法)
- 频繁更新参数(波动率、相关性)
- 用压力测试补充VaR
- 报告CVaR以及VaR以衡量尾部风险
- 记录所有假设和限制
VaR解释
| 指标 | 含义 |
|---|---|
| VaR 95% = $1M | 95%置信度下损失不会超过$1M |
| CVaR 95% = $1.5M | 如果损失超过VaR,平均损失为$1.5M |
| 增量VaR | 添加头寸后投资组合VaR的变化 |
| 成分VaR | 头寸对总VaR的贡献 |
回测标准
| 例外情况(250天) | 区域 | 解释 |
|---|---|---|
| 0-4 | 绿色 | 模型可接受 |
| 5-9 | 黄色 | 模型可能有问题 |
| 10+ | 红色 | 模型需要审查 |
集成点
- 从蒙特卡洛引擎接收模拟
- 与风险登记管理器连接进行风险评估
- 支持风险分析师代理
- 与决策可视化集成以生成风险图表