【FinE】正态分布和t分布下的CVaR

article/2025/11/7 14:36:18

导航

  • CVaR and VaR
  • Model
    • normal distribution
    • student t distribution
  • Case Study
  • Reference

CVaR and VaR

CVaR(Conditional Value-at-Risk)也被称为Expected Shortfall(ES) 或者 Expected Tail Loss(ETL),可以解释超过给定VaR值的期望损失,在很多风险分析中,CVaR是更具有解释力,当设置了VaR阈值后,CVaR说明了在之后的 h h h天交易中的期望损失风险(即资产价值低于预先设置的VaR值). 显然VaR和资产日回报率的分布有关.

当资产回报率的尾部较厚,使用整态分布刻画是不合适的,考虑使用t分布对资产回报率分布进行描述.

Model

normal distribution

X X X表示 h h h日的回报率,则
V a R h , α = − x h , α VaR_{h, \alpha}=-x_{h, \alpha} VaRh,α=xh,α
其中, P ( X < x h , α ) = α P(X<x_{h, \alpha})=\alpha P(X<xh,α)=α.
CVaR使用条件期望的形式表达
C V a R h , α ( X ) = − E ( X ∣ X < x h , α ) = − α − 1 ∫ − ∞ x h , α = x f ( x ) d x CVaR_{h, \alpha}(X)=-\mathbb{E}(X\mid X<x_{h, \alpha})=-\alpha^{-1}\int_{-\infty}^{x_{h, \alpha}}=xf(x)dx CVaRh,α(X)=E(XX<xh,α)=α1xh,α=xf(x)dx
对于任意连续的概率密度函数 f ( x ) f(x) f(x),需要计算 x ∼ 100 ( 1 − α ) % h x\sim 100(1-\alpha)\%h x100(1α)%hVaR x f ( x ) xf(x) xf(x)积分.
考虑在 X ∼ N ( μ h , σ h 2 ) X\sim N(\mu_h, \sigma_h^2) XN(μh,σh2)的情况下的CVaR
C V a R h , α ( X ) = α − 1 φ ( Φ − 1 ( α ) ) σ h − μ h CVaR_{h, \alpha}(X)=\alpha^{-1}\varphi(\Phi^{-1}(\alpha))\sigma_h-\mu_h CVaRh,α(X)=α1φ(Φ1(α))σhμh
其中 φ ( z ) \varphi(z) φ(z)表示标准正态分布的pdf, Φ ( α ) − 1 \Phi(\alpha)^{-1} Φ(α)1 α \alpha α分位数.
案例:计算 h = 5 h=5 h=5CVaR,股价年化回报率符合 σ = 41 % , μ = 0 \sigma=41\%, \mu=0 σ=41%,μ=0的正态分布,设置一年的交易日为252天计算出
σ h = σ h / 252 = 0.41 5 / 252 = 0.05798 \sigma_h=\sigma\sqrt{h/252}=0.41\sqrt{5/252}=0.05798 σh=σh/252 =0.415/252 =0.05798
python计算gaussian分布VaRCVaR代码如下

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
from math import sqrtdef demo_1():h, D=5, 252mu, sig = 0, 0.41muh, sigh=mu*(h/D), sig*sqrt(h/D)alpha=0.01lev=100*(1-alpha)CVaRh=alpha**(-1)*norm.pdf(norm.ppf(alpha))*sigh-muhVaRh=norm.ppf(1-alpha)*sigh-muhprint('{}% {} day Normal VaR= {:.2f}%'.format(lev, h, VaRh*100))print('{}% {} day Normal CVaR= {:.2f}%'.format(lev, h, CVaRh*100))demo_1()

student t distribution

考虑更适合肥尾的t分布进行建模,标准t分布的pdf函数为
f ν ( x ) = ( ( ν − 2 ) π ) − 1 / 2 Γ ( v 2 ) − 1 Γ ( ν + 1 2 ) ⏟ A ( 1 + ( ν − 2 ) − 1 ⏟ a x 2 ) − ( ν + 1 ) / 2 ⏟ b f_\nu(x)=\underbrace{((\nu-2)\pi)^{-1/2}\Gamma(\frac{v}{2})^{-1}\Gamma(\frac{\nu+1}{2})}_{A}(1+\underbrace{(\nu-2)^{-1}}_{a}x^2)^{\underbrace{-(\nu+1)/2}_{b}} fν(x)=A ((ν2)π)1/2Γ(2v)1Γ(2ν+1)(1+a (ν2)1x2)b (ν+1)/2
其中 Γ \Gamma Γ表示gamma函数, ν \nu ν表示自由度,方程一般形式为
f ν ( x ) = A ( 1 + a x 2 ) b f_\nu(x)=A(1+ax^2)^b fν(x)=A(1+ax2)b
代入到CVaR定义中得到
C V a R α , ν = − α − 1 ∫ − ∞ x α , ν x f ν ( x ) d x = − α − 1 ∫ − ∞ x α , ν x A ( 1 + a x 2 ) b d x = − A α ∫ − ∞ x α , ν x ( 1 + a x 2 ⏟ y ) b d x (1) \begin{aligned} CVaR_{\alpha, \nu}&=-\alpha^{-1}\int_{-\infty}^{x_{\alpha, \nu}}xf_\nu(x)dx\\ &=-\alpha^{-1}\int_{-\infty}^{x_{\alpha, \nu}}xA(1+ax^2)^bdx\\ &=-\frac{A}{\alpha}\int_{-\infty}^{x_{\alpha, \nu}}x(\underbrace{1+ax^2}_y)^bdx \end{aligned}\tag{1} CVaRα,ν=α1xα,νxfν(x)dx=α1xα,νxA(1+ax2)bdx=αAxα,νx(y 1+ax2)bdx(1)
y = 1 + a x 2 y=1+ax^2 y=1+ax2进行变换, d y = 2 a x d x , B = 1 + ( ν − 2 ) − 1 x α , ν 2 dy=2axdx,B=1+(\nu-2)^{-1}x^2_{\alpha, \nu} dy=2axdxB=1+(ν2)1xα,ν2,方程 ( 1 ) (1) (1)变换得到
( 1 ) = − A α ∫ − ∞ B x ( 1 + a x 2 ) b 2 a x d y = − A 2 a α ∫ ∞ B y b d y = − A 2 a α B b + 1 b + 1 \begin{aligned} (1)&=-\frac{A}{\alpha}\int_{-\infty}^B\frac{x(1+ax^2)^b}{2ax}dy\\ &=-\frac{A}{2a\alpha}\int_{\infty}^{B}y^bdy\\ &=-\frac{A}{2a\alpha}\frac{B^{b+1}}{b+1} \end{aligned} (1)=αAB2axx(1+ax2)bdy=2aαABybdy=2aαAb+1Bb+1
由于 b + 1 = ( 1 − ν ) / 2 b+1=(1-\nu)/2 b+1=(1ν)/2代入得到 ( 1 ) (1) (1)值为
− A ( ν − 2 ) − 1 α 2 B ( 1 − ν ) / 2 1 − ν -\frac{A}{(\nu-2)^{-1}\alpha}\frac{2B^{(1-\nu)/2}}{1-\nu} (ν2)1αA1ν2B(1ν)/2
根据 f ν ( x ) f_\nu(x) fν(x)的表达式可以知道
f ν ( x ) = A B b ⇒ A = f ν ( x ) B − b = f ν ( x ) B ( 1 + ν ) / 2 f_\nu(x)=AB^b\Rightarrow A=f_\nu(x)B^{-b}=f_\nu(x)B^{(1+\nu)/2} fν(x)=ABbA=fν(x)Bb=fν(x)B(1+ν)/2
代入方程 ( 1 ) (1) (1)得到CVaR值为
( 1 ) = − α − 1 f ν ( x ) B ( 1 + ν ) / 2 2 ( ν − 2 ) − 1 2 B ( 1 − ν ) / 2 1 − ν = − α − 1 f ν ( x ) ( ν − 2 ) ( 1 − ν ) − 1 B = − α − 1 ( ν − 2 ) ( 1 − ν ) − 1 ( 1 + ( ν − 2 ) − 1 x α , ν 2 ) f ν ( x α , ν ) = − α − 1 ( 1 − ν ) − 1 [ ν − 2 + x α , ν 2 ] f ν ( x α , ν ) \begin{aligned} (1)&=-\alpha^{-1}\frac{f_\nu(x)B^{(1+\nu)/2}}{2(\nu-2)^{-1}}\frac{2B^{(1-\nu)/2}}{1-\nu}\\ &=-\alpha^{-1}f_\nu(x)(\nu-2)(1-\nu)^{-1}B\\ &=-\alpha^{-1}(\nu-2)(1-\nu)^{-1}(1+(\nu-2)^{-1}x^2_{\alpha, \nu})f_\nu(x_{\alpha, \nu})\\ &=-\alpha^{-1}(1-\nu)^{-1}[\nu-2+x^2_{\alpha, \nu}]f_\nu(x_{\alpha, \nu}) \end{aligned} (1)=α12(ν2)1fν(x)B(1+ν)/21ν2B(1ν)/2=α1fν(x)(ν2)(1ν)1B=α1(ν2)(1ν)1(1+(ν2)1xα,ν2)fν(xα,ν)=α1(1ν)1[ν2+xα,ν2]fν(xα,ν)
所以, h h h天,t分布下CVaR值为
C V a R h , α , ν ( X ) = − α − 1 ( 1 − ν ) − 1 [ ν − 2 + x α , ν 2 ] f ν ( x α , ν ) σ h − μ h CVaR_{h, \alpha, \nu}(X)=-\alpha^{-1}(1-\nu)^{-1}[\nu-2+x_{\alpha, \nu}^2]f_\nu(x_{\alpha, \nu})\sigma_h-\mu_h CVaRh,α,ν(X)=α1(1ν)1[ν2+xα,ν2]fν(xα,ν)σhμh
案例计算自由度为 6 6 6的t分布的VaRCVaR
python计算t分布下VaRCVaR代码如下

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm, t
from math import sqrtdef demo_2():h, D = 10, 252mu, sig=0, 0.41muh, sigh=mu*(h/D), sig*sqrt(h/D)alpha=0.01lev=100*(1-alpha)nu=6 # 设置自由度xanu=t.ppf(alpha, nu)CVaRh=-1/alpha*(1-nu)**(-1)*(nu-2+xanu**2)*t.pdf(xanu, nu)*sigh-muhVaRh=sqrt(h/D*(nu-2)/nu)*t.ppf(1-alpha, nu)*sig-muprint('{}% {} day t VaR= {:.2f}%'.format(lev, h, VaRh*100))print('{}% {} day t CVaR= {:.2f}%'.format(lev, h, CVaRh*100))demo_2()

可以发现,随着自由度的上升,t分布的VaRCVaR逐渐收敛到gaussian分布的VaRCVaR

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm, t
from math import sqrtdef demo_3():h, D = 10, 252mu, sig=0, 0.41muh, sigh=mu*(h/D), sig*sqrt(h/D)alpha=0.01lev=100*(1-alpha)data=[]for nu in range(5, 101):xanu=t.ppf(alpha, nu)CVaRt=-1/alpha*(1-nu)**(-1)*(nu-2+xanu**2)*t.pdf(xanu, nu)*sigh-muhVaRt=sqrt(h/D*(nu-2)/nu)*t.ppf(1-alpha, nu)*sig-muhdata.append([nu, VaRt, CVaRt])CVaRn=alpha**(-1)*norm.pdf(norm.ppf(alpha))*sigh-muhVaRn=norm.ppf(1-alpha)*sigh-muhdata=np.array(data)fig, ax=plt.subplots(figsize=(8, 6))plt.plot(data[:, 0], data[:, 1]*100, 'b-', label='VaRt')plt.plot(np.arange(5, 100), VaRn*np.ones(95)*100, 'b:', label='VaRn')plt.plot(data[:, 0], data[:, 2]*100, 'r-', label='CVaRt')plt.plot(np.arange(5, 100), CVaRn*np.ones(95)*100, 'r:', label='CVaRn')plt.xlabel('student t. d.o.f')plt.ylabel('%')plt.legend()plt.show()demo_3()

cvar

Case Study

使用IBM数据进行实证分析, 使用gaussian分布和t分布拟合IBM日回报收益率得到拟合图像如下
fit
可以发现,t分布更适合拟合这种存在高噪声的尖峰厚尾的数据,不同分布计算的CVaR和VaR值如下

99.0% 1 day gaussian VaR= 2.81%
99.0% 1 day gaussian CVaR= 3.22%
99.0% 1 day student t VaR= 2.22%
99.0% 1 day student t CVaR= 3.91%

ibmcvar
案例python代码

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm, t, skew, kurtosis, kurtosistest
from math import sqrt
import pandas_datareader.data as web
import pickle# Fetching Yahoo Finance for IBM stock data
def data_fetch():data = web.DataReader('IBM', data_source='yahoo', start='2010-12-31', end='2015-12-31')['Adj Close']adj_close=np.array(data.values)ret=adj_close[1:]/adj_close[:-1]-1file=open('ibm_ret', 'wb')pickle.dump(ret, file)with open('ibm_ret', 'rb') as file:ret=pickle.load(file)dx=0.0001
x=np.arange(-0.1, 0.1, dx)# gaussian fit
mu_norm, sig_norm=norm.fit(ret)
pdf_norm=norm.pdf(x, mu_norm, sig_norm)# student t fit
nu, mu_t, sig_t=t.fit(ret)
nu=np.round(nu)
pdf_t=t.pdf(x, nu, mu_t, sig_t)# VaR and CVaR
h=1
alpha=0.01
lev=100*(1-alpha)
xanu=t.ppf(alpha, nu)CVaRn=alpha**(-1)*norm.pdf(norm.ppf(alpha))*sig_norm-mu_norm
VaRn=norm.ppf(1-alpha)*sig_norm-mu_norm
CVaRt=-1/alpha*(1-nu)**(-1)*(nu-2+xanu**2)*t.pdf(xanu, nu)*sig_t-h*mu_t
VaRt=sqrt((nu-2)/nu)*t.ppf(1-alpha, nu)*sig_t-h*mu_tprint('{}% {} day gaussian VaR= {:.2f}%'.format(lev, h, VaRn*100))
print('{}% {} day gaussian CVaR= {:.2f}%'.format(lev, h, CVaRn*100))
print('{}% {} day student t VaR= {:.2f}%'.format(lev, h, VaRt*100))
print('{}% {} day student t CVaR= {:.2f}%'.format(lev, h, CVaRt*100))plt.figure(figsize=(12, 8))
grey=0.75, 0.75, 0.75
plt.hist(ret, bins=50, density=True, color=grey, edgecolor='none')
plt.axis('tight')
plt.plot(x, pdf_norm, 'b-.', label='Guassian Fit')
plt.plot(x, pdf_t, 'g-.', label='Student t Fit')
plt.xlim([-0.2, 0.1])
plt.ylim([0, 50])
plt.legend(loc='best')
plt.xlabel('IBM daily return')
plt.ylabel('ret. distr.')# plt.savefig('ibm_fit')
# inset local
sub=plt.axes([0.22, 0.35, 0.3, 0.4])
plt.hist(ret, bins=50, density=True, color=grey, edgecolor='none')
plt.plot(x, pdf_norm, 'b')
plt.plot(x, pdf_t, 'g')
plt.plot([-CVaRt, -CVaRt], [0, 3], 'g:')
plt.plot([-CVaRn, -CVaRn], [0, 4], 'b:')
plt.text(-CVaRt-0.015, 3.1, 'Stu. t', color='g')
plt.text(-CVaRn-0.015, 4.1, 'Gaussian CVaR', color='b')
plt.xlim([-0.09, -0.02])
plt.ylim([0, 5])# plt.savefig('ibmcvar')
plt.show()

从数据和图像可以看出,Gaussian拟合计算的CVaR值存在低估风险的倾向.

Reference

CVaR Quant at risk


http://chatgpt.dhexx.cn/article/f3mV4oeg.shtml

相关文章

条件风险价值CVaR

产生背景 &ThickSpace;&ThickSpace;&ThickSpace;&ThickSpace;&ThickSpace;&ThickSpace; \;\;\;\;\;\; CVaR即条件风险价值&#xff0c;是由RockafeUar和Uryasev等于1997年提出的一种较VaR更优的风险计量技术&#xff0c;其含义为在投资组合的损失超过某…

VaR和CVaR举例说明_笔记转载

风险价值VaR成为金融市场风险度量的主流指标 VaR自1993年发展至今已作为金融市场风险度量的主流指标被各银行、投资公司、证券公司及金融监管机构广泛采用。VaR不仅具有概念简单&#xff0c;易于沟通和理解的优点&#xff0c; 而且为不同金融工具构成的复杂的投资组合提供了一…

两个命令行应用程序的交互——使用Java的Process类完成复杂控制台程序的自动化操作(以围棋GTP协议为例)

GitHub地址链接&#xff1a;https://github.com/zhmgczh/GTPService 这个项目其实继承并发展于我的上一个项目——用模式识别实现围棋转接器的开源Java项目——一个类似GTool2.exe的工具&#xff0c;是一个变相的补充&#xff0c;主要解决如何使用Java完成两个控制台应用程序相…

GTP(GPRS Tunnelling Protocol)协议http://blog.csdn.net/stephen_yin/article/details/6951237

GTP&#xff08;GPRS Tunnelling Protocol&#xff09;协议 标签&#xff1a; extensionheaderinternet网络wapxhtml 2011-11-09 10:15 6097人阅读 评论(0) 收藏 举报 GTP&#xff08;GPRS Tunnelling Protocol&#xff09; 协议在 GPRS 骨干网中在GSNs 之间&#xff08;…

GTP(GPRS Tunnelling Protocol)协议

GTP&#xff08;GPRS Tunnelling Protocol&#xff09; 协议在 GPRS 骨干网中在GSNs 之间&#xff08;如 SGSN 和 GGSN&#xff09;提供协议信道&#xff0c;所有的 PTP 分组数据协议的PDUs 应由GTP 协议进行封装。 GTP概述 GTP 协议应用在SGSN 和GGSN 之间&#xff0c;为各…

移动互联网新协议 GTP 中被曝多个高危漏洞,影响4G和5G 用户

聚焦源代码安全&#xff0c;网罗国内外最新资讯&#xff01; 编译&#xff1a;奇安信代码卫士团队 Positive Technologies 公司上周发布报告《2020年 LTE 和5G 网络中的漏洞》指出&#xff0c;移动网络运营商 (MNOs) 使用的当代通信协议中被曝多个高危漏洞&#xff0c;可被用于…

GPRS核心网-GTP-C协议解析

GPRS隧道协议&#xff08;GTP&#xff09;是3GPP标准定义的隧道协议&#xff0c;用于在3G /4G/5G网络中承载通用分组无线服务&#xff08;GPRS&#xff09;。 GTP用于在服务网关&#xff08;S-GW&#xff09;和分组数据网络网关&#xff08;P-GW&#xff09;以及S-GW和移动性管…

网络协议 终章 - GTP 协议:复杂的移动网络

前面都是讲电脑上网的情景&#xff0c;今天我们就来认识下使用最多的移动网络上网场景。 移动网络的发展历程 你一定知道手机上网有 2G、3G、4G 的说法&#xff0c;究竟这都是什么意思呢&#xff1f;有一个通俗的说法就是&#xff1a;用 2G 看 txt&#xff0c;用 3G 看 jpg&…

gtp传输java_一种GTP数据包传输方法、相关装置及存储介质与流程

本申请实施例涉及通信领域,尤其涉及一种GTP数据包传输方法、相关装置及存储介质。 背景技术: 通用分组无线服务隧道协议(General Packet Radio Service Tunnelling Protocol,GTP)是一种用于传输分组数据的通信协议。目前,己使用的GTP协议可被分为通用分组无线服务(General …

GTP协议

GTP协议 (2010-08-27 17:20:54) 转载▼ 标签&#xff1a; 杂谈 分类&#xff1a; 计算机网络 摘要&#xff1a;本文分析GPRS的GSN之间的GTP协议&#xff0c;阐述GTP协议的含义及用法。 关键词&#xff1a;GPRS GTP 协议 一、 引言 在GPRS系统的GSN&#xff08;GPRS Support …

GTP协议格式分析

点击上方↑↑↑蓝字 [ 协议分析与还原 ] 关注我们 “ 分析GTP协议。” 本文对比较枯燥的协议资料进行学习&#xff0c;有需要可继续阅读&#xff0c;找到自己关注的知识点&#xff0c;暂时无需要可直接拉到文末表示阅读结束&#xff0c;让微信记下热爱学习的你的痕迹。 如果说T…

关于GTPv1协议解析

概述&#xff1a; ***&#xff08;简单说一下&#xff0c;不重点讲述啦&#xff09; GPRS 隧道协议 (GTP) 是一种隧道协议&#xff0c;用于 GPRS、UMTS、LTE 和 5G 网络。它分为两个独立的协议&#xff1a;GTP-C 和 GTP-U。GTP-C用于GPRS核心网络中&#xff0c;用于不同网络节…

GTP-U协议总结

1、​参考资料 3gpp TS 29.060 V17.1.0-GPRS Tunnelling Protocol (GTP) TS 29.281 V17.1.0-GPRS Tunnelling Protocol User Plane (GTPv1-U) 2、GTP协议 GTP&#xff08;GPRS隧道协议(GPRSTunnelingProtocol)&#xff09;&#xff0c;可以分解成三种独立的协议&#xff0…

【5G核心网】 GTP协议

GTP 可以提供移动性的功能。 使用 GTP&#xff0c;网络的终端能够在网络中移动位置&#xff0c;各个端点集之间可以建立多个隧道&#xff0c;从而根据业务不同可以提供不同的 Qos&#xff0c;可以隐藏 IP&#xff0c;安全性更高。 1. 定义概念 GTP-U Message: GTP-U&#xff…

GTP协议的分析

一、 引言 在GPRS系统的GSN&#xff08;GPRS Support Node&#xff0c;包括SGSN和GGSN&#xff09;之间采用GTP&#xff08;GPRS Tunnel Protocol&#xff09;协议&#xff0c;GTP在整个GPRS协议栈中起着举足轻重的作用&#xff0c;GTP协议承载在TCP或UDP协议之上&#xff0c;分…

JS JQuery添加、替换、删除元素class属性

1、先声明一个div和两个class样式&#xff0c;用来测试&#xff1a; <html><head><meta charset"utf-8"><title></title><script src"https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script><s…

jquery动态添加和删除class属性

在用jquery时&#xff0c;遇到一个问题&#xff0c;就是如何动态得添加和删除class的属性&#xff0c;下面是我的解决代码&#xff1a; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitio…

用jQuery的.addClass()方法给元素加class

Target Elements by Class Using jQuery 你看到我们是怎么给所有的按钮做弹回效果了吗&#xff1f;我们用 $("button")来选中按钮&#xff0c;然后用.addClass("animated bounce")给按钮加CSS class。 你只需要用jQuery的.addClass()方法&#xff0c;就可…

js 关于动态添加class样式的学习

如果&#xff0c;我这里有一个需求。如下的页面代码 <body> <input type"button" value"红" id"btn1"/> <p id"p1"> 2016年圣诞前的一个星期天下午&#xff0c;我推开窗&#xff0c;加州明媚的阳光洒在街道上&…

jQuery通过id属性来获取元素,通过.addClass()方法来添加class.

Target Elements by ID Using jQuery 你还可以根据id属性来获取元素 首先用$("#target3")来选择id为target3的button元素。 注意&#xff0c;就像CSS一样&#xff0c;在id的名字前加上 #。 然后使用jQuery的.addClass()方法来添加 animated和fadeOutclass. 例如…