开始使用免费开始使用

来自拟合分布的 VaR

要最小化 CVaR,需要在给定置信水平(例如 95%)下计算 VaR。此前,您是从正态(高斯)分布中将 VaR 作为分位数求得的,但要更通用地最小化 CVaR,就需要从最能与数据相"拟合"的分布中计算该分位数。

本练习提供了一个 fitted"损失分布",它对 2005–2010 年等权重投行投资组合的损失进行了拟合。您将先使用其 .evaluate() 方法绘制该分布(第 4 章将更详细介绍拟合分布)。

接着,使用 fitted 对象的 .resample() 方法,从该拟合分布中随机抽取 100,000 个观测,得到随机 sample

最后,对随机 sample 使用 np.quantile() 计算 95% VaR。

本练习是课程的一部分

Python 中的定量风险管理

查看课程

练习说明

  • 绘制 fitted 损失分布。留意 fitted 分布与正态分布的差异。
  • 使用 fitted.resample() 方法,从拟合分布中随机抽取 100,000 个点,生成 sample
  • 使用 np.quantile() 从随机 sample 中求取 95% VaR,并显示结果。

交互式实操练习

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

# Visualize the fitted distribution with a plot
x = np.linspace(-0.25,0.25,1000)
plt.____(x,fitted.evaluate(x))
plt.show()

# Create a random sample of 100,000 observations from the fitted distribution
sample = fitted.____(____)

# Compute and display the 95% VaR from the random sample
VaR_95 = np.____(sample, ____)
print(VaR_95)
编辑并运行代码