开始使用免费开始使用

比较 CVaR 与 VaR

条件在险价值(CVaR),也称预期损失(ES),是在给定置信水平下、损失超过某一阈值这一「条件」下的平均损失。它以 VaR 为起点,但包含更多信息,因为它考虑了损失分布的尾部

您将首先针对一个服从正态分布的投资组合损失,计算与 2005–2010 年投行 portfolio_losses 相同均值和标准差下的 95% VaR。然后基于该 VaR 计算 95% CVaR,并将二者与该正态分布一起绘图对比。

工作区中已提供 portfolio_losses,以及来自 scipy.stats 的正态分布对象 norm

本练习是课程的一部分

Python 中的定量风险管理

查看课程

练习说明

  • 计算 portfolio_losses 的均值与标准差,分别赋给 pmps
  • 使用 norm.ppf() 方法求 95% VaR——该方法的参数 loc 表示均值,scale 表示标准差。
  • 使用 95% VaR 和 norm.expect() 方法求 tail_loss,并据此计算相同置信水平下的 CVaR。
  • 在正态分布的直方图上添加竖线,标示 VaR(红色)和 CVaR(绿色)。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Compute the mean and standard deviation of the portfolio returns
pm = portfolio_losses.____
ps = portfolio_losses.____

# Compute the 95% VaR using the .ppf()
VaR_95 = norm.ppf(0.95, loc = ____, scale = ____)
# Compute the expected tail loss and the CVaR in the worst 5% of cases
tail_loss = norm.____(lambda x: x, loc = ____, scale = ____, lb = VaR_95)
CVaR_95 = (1 / (1 - 0.95)) * ____

# Plot the normal distribution histogram and add lines for the VaR and CVaR
plt.hist(norm.rvs(size = 100000, loc = pm, scale = ____), bins = 100)
plt.axvline(x = VaR_95, c='r', label = "VaR, 95% confidence level")
plt.axvline(x = ____, c='g', label = "CVaR, worst 5% of outcomes")
plt.legend(); plt.show()
编辑并运行代码