全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 EViews专版
12747 5
2015-09-12
悬赏 100 个论坛币 已解决
如果在EVIEWS中用GARCH模型算VaR(在值风险),计算failure rate,和做LRuc检测?

最佳答案

yenfeng1 查看完整内容

推荐这本书ARCH Models for Financial Applications 作者 Evdokia Xekalaki and Stavros Degiannakis 出版 2010 John Wiley & Sons Ltd. ISBN: 978-0-470-06630-0 该书资讯可参考 https://bbs.pinggu.org/thread-942904-1-1.html 该书的第八章有楼主要的内容,该书有实例说明并附上EViews code (288页) 结果在257页。其中有failure rate,和做LRuc检测,分别在第四栏(N/T)和第五栏(Kupiec’s LRun p-value) 我参考改写, ...
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-9-12 13:19:51
推荐这本书ARCH Models for Financial Applications
作者 Evdokia Xekalaki and Stavros Degiannakis
出版  2010 John Wiley & Sons Ltd. ISBN: 978-0-470-06630-0
该书资讯可参考
https://bbs.pinggu.org/thread-942904-1-1.html

该书的第八章有楼主要的内容,该书有实例说明并附上EViews code (288页)
结果在257页。其中有failure rate,和做LRuc检测,分别在第四栏(N/T)和第五栏(Kupiec’s LRun p-value)

我参考改写,改写的原因是因为他估计GARCH 模型用的是OxMetrics6。为求一致性,我仍用该书第四章的EViews code (145页) 改写,估计条件方差和均数。模型由原本的AR(1)-GARCH(1,1)-n变成AR(0)-GARCH(1,1)-n。

(a) 先在C:\建资料夹,evwork,放入四个档案
evwork.zip
大小:(465.94 KB)

 马上下载

本附件包括:

  • vartest.prg
  • 2.prg
  • chapter2_data.wf1
  • chapter8.var.es.ftse100.wf1


(b) 先执行程式档,2.prg,该档是估计AR(0)-GARCH(1,1)-n,估计条件方差和均数,产生Excel档,ftse100_GARCH_n.xls。
(C) 然后执行程式档,vartest.prg,他会产生报表Result。请对照参考书的257页。

(d)结果-存在Result
95% Var                   95% ES              N/T             Kupiec LRun p-value        Christoffersen LRin p-value        Loss function               
-1.763433        -2.221162         0.056446         0.271880                       0.049263                                0.011925               
                                                       

附带

                    1) 2.prg 的EViews code

cd "c:\evwork"
load chapter2_data.wf1

'*******************************************
'AR(0)-GARCH(1,1)-n
'*******************************************
smpl @all
!ssize = 3000
!length = 4437
series var1
series var2
for !i = 1  to  !length-!ssize-2
        statusline !i
     smpl !i+3 !i+!ssize+2

equation tempg11_1.arch(1,1,m=10000,h) ftse100ret c
tempg11_1.makegarch garchg11_1
tempg11_1.makeresid resg11_1
!ht = garchg11_1(!i+!ssize+2)
!c1 = @coefs(1)
!c2 = @coefs(2)
!c3 = @coefs(3)
!c4 = @coefs(4)
!h_hat = !c2+ (!c3*(resg11_1(!ssize + !i -1)^2) ) + (!c4*!ht)
!y_hat = !c1
var1(!i) = !h_hat
var2(!i)  = !y_hat
next

smpl 1 1435
group var var1 var2

write(t=xls,dates=1435) C:\evwork\ftse100_GARCH_n.xls var


                                     2) vartest.prg的EViews code



cd "c:\evwork"
load chapter8.var.es.ftse100.wf1
!sample = 1435
!models = 1
!model = 1
!ES_repeat = 5000
matrix(!sample,!models) ftse100VaR95L = NA
matrix(!sample,!models) ftse100ES95L = NA
matrix(!sample,!models) ftse100Result95L = NA
matrix(!sample,!models) ftse100Loss95L = NA
matrix(1,!models) average95L = NA
matrix(1,!models) Kupiec95L = NA
matrix(1,!models) Christ95L = NA
scalar place = 1
'*******************************************************
'AR(0)-GARCH(1,1)-n
'*******************************************************

read(t=xls) ftse100_GARCH_n.xls 2
for !i = 1 to !sample
        ftse100VaR95L(!i,place) = @sqrt(var1(!i))*@qnorm(0.05)+var2(!i)
        vector(!ES_repeat) ES = na
        !step1 = (1-0.95)/(!ES_repeat+1)
        !step2 = 0.05
        for !kk = 1 to !ES_repeat
                !step2 = !step2-!step1
                ES(!kk) =  @sqrt(var1(!i))*@qnorm(!step2)+var2(!i)
        next
        ftse100ES95l(!i,place) = @mean(ES)
Statusline Sample ftse100 !model !i
next       
!model = !model +1
for !i = 1 to !sample
        if         ftse100(!i)<ftse100VaR95L(!i,place) then
                        ftse100result95L(!i,place) = 1
        else
                        ftse100result95L(!i,place) = 0
        endif
next

freeze(test) ftse100result95l.stats
average95L(1,place) = test(5,place+1)
delete test
'________________________
'Kupiec test
smpl @all
'Create the vector for the probabilities of default
vector(1) probab
probab(1)=0.05
'How many forecasts have you made?
vector(1) T
T(1)=!sample
'What is the average (expected)?
vector(1) average
average(1)= probab(1)*T(1)
'The number of brakes for long
vector(1) NLong = na
NLong(1)=@round(average95l(1,place)*!sample)
'Vectors for LR tests
vector(1) LRunLong = na
series kupiecresult1=-2*log(((1-probab(1))^(t(1)-NLong(1)))*(probab(1)^NLong(1))*1e+150)
series kupiecresult2=2*log(((1-NLong(1)/t(1))^(t(1)-NLong(1)))*((NLong(1)/t(1))^NLong(1))*1e+150)
LRunLong(1)=kupiecresult1(1)+kupiecresult2(1)
Kupiec95L(1,place) = 1-@cchisq(LRunLong(1),1)
delete average
delete NLong
delete LRunLong
delete kupiecresult1
delete kupiecresult2
'________________________
'Christoffersen test
smpl @all
'Create the vector for the conditional coverage test
vector(1) LRcc=na
'Create the coef for the independence
'The number of observations with value 0 followed by 0
coef(1) n00=0
'The number of observations with value 0 followed by 1
coef(1) n01=0
'The number of observations with value 1 followed by 1
coef(1) n11=0
'The number of observations with value 1 followed by 0
coef(1) n10=0
'Create the probability to go to 0 given that we are at 0
coef(1) pr00(1)=0
'Create the probability to go to 1 given that we are at 0
coef(1) pr01(1)=0
'Create the probability to go to 0 given that we are at 1
coef(1) pr10(1)=0
'Create the probability to go to 1 given that we are at 1
coef(1) pr11(1)=0
'Create the series for the independence coverage
series LRin
'Estimate the nij
for !i=1 to !sample-1
        if ftse100result95l(!i,place)=0 and ftse100result95L(!i+1,place)=0 then
                n00(1)=n00(1)+1
        else
                n00(1)=n00(1)
        endif
        if ftse100result95l(!i,place)=0 and ftse100result95L(!i+1,place) =1 then
                n01(1)=n01(1)+1
        else
                n01(1)=n01(1)
        endif
        if ftse100result95l(!i,place)=1 and ftse100result95L(!i+1,place)=1 then
                n11(1)=n11(1)+1
        else
                n11(1)=n11(1)
        endif               
        if ftse100result95l(!i,place)=1 and ftse100result95L(!i+1,place)=0 then
                n10(1)=n10(1)+1
        else
                n10(1)=n10(1)
        endif
next
pr01(1)=n01(1)/(n00(1)+n01(1))
pr11(1)=n11(1)/(n10(1)+n11(1))
series LRin1=(((1-pr01(1))^n00(1))*(pr01(1)^n01(1))*((1-pr11(1))^n10(1))*pr11(1)^n11(1))*1e+150
coef(1) p2 = (n01(1)+n11(1))/(n01(1)+n00(1)+n10(1)+n11(1))
series LRin2 = (((1-p2(1))^(n00(1)+n10(1)))*(p2(1)^(n01(1)+n11(1))))*1e+150
LRcc(1) = -2*(log(lrin2(1)/lrin1(1)))
Christ95L(1,place) = 1-@cchisq(LRcc(1),1)
'___________________________________________
'MSE Loss function
for !i = 1 to !sample
        if ftse100result95l(!i,place) = 1 then
                ftse100loss95l(!i,place) = (ftse100(!i)-ftse100es95l(!i,place))^2
        else
                ftse100loss95l(!i,place) = 0
        endif
next
place = place + 1
for !i = 1 to 2
delete var!i
next
mtos(ftse100es95l,ees)
mtos(ftse100loss95l, loss)
mtos(ftse100result95l, resul)
mtos(ftse100var95l, var)
scalar f=average95l
scalar k=kupiec95l
scalar ch=christ95l
group g1 ees loss resul var
Table(2, 6) Result
Result(1,1)= "95% Var"
Result(1,2)= "95% ES"
Result(1,3)= "N/T"
Result(1,4)= "Kupiec LRun p-value"
Result(1,5)= "Christoffersen LRin p-value"
Result(1,6)= "Loss function"
Result(2,1)=@mean(ftse100var95l)
Result(2,2)=@mean(ftse100es95l)
Result(2,3)=f
Result(2,4)=k
Result(2,5)=ch
Result(2,6)=@mean(ftse100loss95l)
show result


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-20 11:54:56
yenfeng1 发表于 2015-9-12 13:19
推荐这本书ARCH Models for Financial Applications
作者 Evdokia Xekalaki and Stavros Degiannakis
出版 ...
谢谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-22 21:17:44
It's good for me. Thanks!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2020-3-6 14:04:53
yenfeng1 发表于 2015-9-12 13:19
推荐这本书ARCH Models for Financial Applications
作者 Evdokia Xekalaki and Stavros Degiannakis
出版 ...
您好,在根据您提供的PROGRAM 2.prg代码之后,修改成我自己的数据,我一个代码一个代码的排查,把所选 27.png 取数据都换成我自己的GARCH模型,GARCH残差序列,GRACH方差序列,可是VaR值还是run不出来,这是为什么呢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2024-3-22 16:22:22

It's good for me. Thanks!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群