楼主: 东西方咨询
3378 4

[程序分享] Dueker JBES 1997 MS-GARCH models using Winrats [推广有奖]

  • 0关注
  • 1粉丝

已卖:347份资源

博士生

73%

还不是VIP/贵宾

-

TA的文库  其他...

Research Paper Writing(写作)

OxMetrics NewOccidental

Eviews NewOccidental

威望
0
论坛币
2817 个
通用积分
6.1195
学术水平
48 点
热心指数
19 点
信用等级
46 点
经验
4060 点
帖子
115
精华
4
在线时间
7 小时
注册时间
2014-6-21
最后登录
2016-8-20

楼主
东西方咨询 发表于 2014-6-23 23:57:57 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

Dueker JBES 1997 MS-GARCH models

by TomDoan » Mon Sep 12, 2011 1:30 pm

These are replication files for Dueker(1997), "Markov Switching in GARCH Processes and Mean-Reverting Stock-Market Volatility," J of Business & Economic Statistics, vol. 15, no 1, 26-34 using a reconstruction of the original data file. Dueker fits several different models with different types of switching. All of models allow the mean to switch, but two of these have "variances" switching, and two have the degrees of freedom in the conditional t density switching in different ways.

Switching GARCH (as opposed to ARCH) models require "collapsing" the history of the regimes in some fashion. Dueker waits one period longer for this than Gray(1996) does. This actually makes it easier to adapt the technique to different models than Gray's.

Switching ARCH/GARCH models is one of the topics in the Structural Breaks and Switching Models course materials.

dueker_swgarch.rpfGARCH model with switching mean (only)(4.66 KiB) Downloaded 363 times

dueker_swgarch_nf.rpfGARCH model with switching variance(5.53 KiB) Downloaded 374 times

dueker_swgarch_df.rpfGARCH model with switching degrees of freedom in t error process(5.26 KiB) Downloaded 279 times

dueker_swgarch_k.rpfGARCH model with switching degrees of freedom(5.29 KiB) Downloaded 278 times

dueker_swarch.rpfSWARCH model(4.65 KiB) Downloaded 317 times

sp500.xls(Reconstructed) data file(93 KiB) Downloaded 333 times


二维码

扫码加我 拉你入群

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

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

关键词:GARCH Models WinRATS models winrat model different Business original several files

本帖被以下文库推荐

沙发
songlinjl 发表于 2014-6-24 05:51:04 来自手机
东西方咨询 发表于 2014-6-23 23:57
Dueker JBES 1997 MS-GARCH modelsby TomDoan » Mon Sep 12, 2011 1:30 pmThese are re ...
手机版上链接无效

藤椅
gssdzc 在职认证  发表于 2014-7-27 09:10:58
貌似无法打开链接

板凳
农村固定观察点 发表于 2017-2-12 23:22:37
  1. *
  2. * Replication file for Dueker(1997),  "Markov Switching in GARCH
  3. * Processes and Mean-Reverting Stock-Market Volatility," J of Business &
  4. * Economic Statistics, vol. 15, no 1, 26-34.
  5. *
  6. * Data set is a reconstruction.
  7. *
  8. * SWARCH(2) model with switching normalization factors and means with
  9. * conditionally t distributed errors.
  10. *
  11. open data sp500.xls
  12. data(format=xls,org=columns,top=17,left=2,nolabels) 1 2529 spchange
  13. *
  14. * Copy the data over to y to make it easier to change the program.
  15. *
  16. set y = spchange
  17. *
  18. * This is the number of ARCH lags.
  19. *
  20. compute q=2
  21. *
  22. @MSSetup(states=2,lags=q)
  23. *
  24. * GV will be the relative variances in the regimes.
  25. *
  26. dec vect gv(nstates)
  27. *
  28. * This will be the vector of ARCH parameters. The constant in the ARCH
  29. * equation is fixed at 1 as the normalization.
  30. *
  31. dec vect msg(q)
  32. dec real nu
  33. *
  34. * We have three parts of the parameter set: the mean equation parameters
  35. * (separate mu's for each regime), the GARCH model parameters, and the
  36. * Markov switching parameters.
  37. *
  38. dec vector mu(nstates)
  39. nonlin(parmset=meanparms) mu
  40. nonlin(parmset=archparms) msg gv nu
  41. nonlin(parmset=msparms)   p
  42. *
  43. * uu and u are used for the series of squared residuals and the series of
  44. * residuals needed to compute the ARCH variances.
  45. *
  46. clear uu u
  47. *
  48. * These for the lagged residuals and lagged squared residuals, which are
  49. * regime-dependent because of the regime-dependent means.
  50. *
  51. dec vect[series] uus(nstates) us(nstates)
  52. ************************************************************************
  53. *
  54. * ARCHRegimeH returns the VECTOR of the H values across augmented regime
  55. * settings.
  56. *
  57. function ARCHRegimeH time
  58. type vector         ARCHRegimeH
  59. type integer         time
  60. *
  61. local integer i k
  62. *
  63. dim ARCHRegimeH(nexpand)
  64. do i=1,nexpand
  65.    compute h=1.0
  66.    do k=1,q
  67.       compute h=h+msg(k)*uus(%MSLagState(i,k))(time-k)/gv(%MSLagState(i,k))
  68.    end do k
  69.    compute ARCHRegimeH(i)=h
  70. end do i
  71. end
  72. ************************************************************************
  73. *
  74. * ARCHRegimeVGaussF returns a vector of likelihoods for the expanded
  75. * regimes at <<time>> given regime "h" factors <<hv> and regime residuals
  76. * <<ev>> using conditionally Gaussian errors.
  77. *
  78. function ARCHRegimeVGaussF time hv ev
  79. type vector          ARCHRegimeVGaussF
  80. type integer         time
  81. type vector                hv ev
  82. *
  83. local integer         i k
  84. local real                 h
  85. *
  86. dim ARCHRegimeVGaussF(nexpand)
  87. do i=1,nexpand
  88.    compute k=%MSLagState(i,0)
  89.    compute ARCHRegimeVGaussF(i)=%if(hv(i)>0,exp(%logdensity(hv(i)*gv(k),ev(k))),0.0)
  90. end do i
  91. end
  92. ************************************************************************
  93. *
  94. * ARCHRegimeVTF returns a vector of likelihoods for the expanded
  95. * regimes at <<time>> given regime "h" factors <<hv> and regime residuals
  96. * <<ev>> using conditionally student-t errors.
  97. *
  98. function ARCHRegimeVTF time hv ev
  99. type vector          ARCHRegimeVTF
  100. type integer         time
  101. type vector                hv ev
  102. *
  103. local integer         i k
  104. local real                 h
  105. *
  106. dim ARCHRegimeVTF(nexpand)
  107. do i=1,nexpand
  108.    compute k=%MSLagState(i,0)
  109.    compute ARCHRegimeVTF(i)=%if(hv(i)>0,exp(%logtdensity(hv(i)*gv(k),ev(k),nu)),0.0)
  110. end do i
  111. end
  112. *********************************************************************
  113. function ARCHRegimeResids time
  114. type vector         ARCHRegimeResids
  115. type integer        time
  116. *
  117. * Compute the residuals for each current regime
  118. *
  119. local integer i
  120. *
  121. dim ARCHRegimeResids(nstates)
  122. do i=1,nstates
  123.    compute ARCHRegimeResids(i)=y(time)-mu(i)
  124. end do i
  125. end
  126. *********************************************************************
  127. linreg y
  128. # constant y{1}
  129. set uu = %seesq
  130. set u  = %resids
  131. do i=1,nstates
  132.    set uus(i) = %sigmasq
  133.    set us(i)  = %resids
  134. end do i
  135. *
  136. * Run a GARCH model for guess values. Use the same range that will be
  137. * used for the MS process.
  138. *
  139. garch(q=2,distrib=t) 3 * y
  140. compute gstart=%regstart(),gend=%regend()
  141. *
  142. ewise mu(i)=%beta(1)
  143. compute msg=%xsubvec(%beta,3,4),nu=%beta(5)
  144. *
  145. * Start with guess values for GV that scale the original constant down
  146. * and up.
  147. *
  148. compute gv(1)=%beta(2)/2.0
  149. compute gv(2)=%beta(2)*2.0
  150. *
  151. * These are our guess values for the P matrix.
  152. *
  153. compute p=||.80,.20||
  154. *
  155. gset pt_t  gstart gend = %zeros(nexpand,1)
  156. gset pt_t1 gstart gend = %zeros(nexpand,1)
  157. *
  158. frml logl = hvec=ARCHRegimeH(t),evec=ARCHRegimeResids(t),f=ARCHRegimeVTF(t,hvec,evec),$
  159.    %pt(us,t,evec),%pt(uus,t,evec.^2),fpt=%MSProb(t,f),log(fpt)
  160. *
  161. maximize(parmset=meanparms+archparms+msparms,$
  162.   start=%(pstar=%MSInit()),$
  163.   method=bfgs,iters=400,pmethod=simplex,piters=5) logl gstart gend
  164. *
  165. @MSSmoothed gstart gend psmooth
  166. set p1 = psmooth(t)(1)
  167. set p2 = psmooth(t)(2)
  168. graph(max=1.0,footer="Probabilities of Regimes in Two Lag Two-Regime student t SWARCH",$
  169.   style=stacked) 2
  170. # p1
  171. # p2
复制代码

报纸
ReneeBK 发表于 2017-2-12 23:26:03
  1. *
  2. * Replication file for Dueker(1997),  "Markov Switching in GARCH
  3. * Processes and Mean-Reverting Stock-Market Volatility," J of Business &
  4. * Economic Statistics, vol. 15, no 1, 26-34.
  5. *
  6. * GARCH model with switching intercepts only.
  7. *
  8. open data sp500.xls
  9. data(format=xls,org=columns,top=17,left=2,nolabels) 1 2529 spchange
  10. *
  11. * Copy the data over to y to make it easier to change the program.
  12. *
  13. set y = spchange
  14. *
  15. * This sets the number of regimes. The analysis requires one lagged
  16. * regime.
  17. *
  18. @MSSetup(states=2,lags=1)
  19. *
  20. * GV will be the relative variances in the regimes.
  21. *
  22. dec vect gv(nstates)
  23. *
  24. * This will be the vector of GARCH parameters. The constant in the GARCH
  25. * equation is fixed at 1 as the normalization.
  26. *
  27. dec vect msg(2)
  28. dec real nu
  29. *
  30. * We have three parts of the parameter set: the mean equation parameters
  31. * (separate mu's for each regime),  the GARCH model parameters, and the
  32. * Markov switching parameters.
  33. *
  34. dec vect mu(nstates)
  35. nonlin(parmset=meanparms)  mu
  36. nonlin(parmset=garchparms) msg gv nu
  37. nonlin(parmset=msparms)    p
  38. *
  39. * uu and u are used for the series of squared residuals and the series of
  40. * residuals needed to compute the GARCH variances.
  41. *
  42. clear uu u h
  43. *
  44. * These are used for the lagged variance for each regime.
  45. *
  46. compute DFFilterSize=nstates^nlags
  47. dec vect[series] hs(DFFilterSize)
  48. *
  49. * And these for the lagged squared residuals
  50. *
  51. dec vect[series] uus(nstates)
  52. ************************************************************************
  53. *
  54. * GARCHRegimeH returns the VECTOR of the H values across augmented
  55. * regime settings.
  56. *
  57. function GARCHRegimeH time
  58. type vector GARCHRegimeH
  59. type integer time
  60. *
  61. local integer i
  62. *
  63. dim GARCHRegimeH(nexpand)
  64. do i=1,nexpand
  65.    compute GARCHRegimeH(i)=1.0+msg(2)*hs(%MSLagState(i,1))(time-1)+$
  66.        msg(1)*uus(%MSLagState(i,1))(time-1)/gv(%MSLagState(i,1))
  67. end do i
  68. end
  69. **************************************************************************
  70. *
  71. * Do a GARCH model to get initial guess values and matrices for random
  72. * walk M-H.
  73. *
  74. linreg y
  75. # constant y{1}
  76. set u  = %resids
  77. set uu = %sigmasq
  78. do i=1,nstates
  79.    set uus(i) = %sigmasq
  80. end do i
  81. *
  82. * We'll start this at entry 2 to match the MS model
  83. *
  84. garch(p=1,q=1,distrib=t) 2 * y
  85. compute gstart=%regstart(),gend=%regend()
  86. *
  87. * Spread the mu's apart since they're the only thing switching in this
  88. * model.
  89. *
  90. compute mu(1)=%beta(1)-%stderrs(1)
  91. compute mu(2)=%beta(1)+%stderrs(1)
  92. *
  93. compute msg=%xsubvec(%beta,3,4)
  94. compute nu=%beta(5)
  95. *
  96. * The "H" series used in the Hamilton-Susmel formulation need scaling by
  97. * the normalization factor to become variances. So we scale the
  98. * pre-sample values down to match.
  99. *
  100. set h  = %sigmasq/%beta(2)
  101. do i=1,nstates
  102.    set hs(i) = %sigmasq/%beta(2)
  103. end do i
  104. *
  105. * These are the same (and will be pegged to stay that way).
  106. *
  107. compute gv(1)=%beta(3)
  108. compute gv(2)=%beta(3)
  109. *
  110. compute p=||.9,.1||
  111. **************************************************************************
  112. *
  113. * This does a single step of the Dueker (approximate) filter
  114. *
  115. function DuekerFilter time
  116. type integer                 time
  117. *
  118. local real               e
  119. local vector      fvec evec hvec ph
  120. *
  121. dim fvec(nexpand) evec(nstates)
  122. *
  123. * Compute the "H" matrices for each expanded regime
  124. *
  125. compute hvec=GARCHRegimeH(time)
  126. *
  127. * Compute the residuals for each current regime
  128. *
  129. do i=1,nstates
  130.    compute evec(i)=y(time)-mu(i)
  131. end do i
  132. *
  133. * Compute the likelihood for each expanded regime.
  134. *
  135. do i=1,nexpand
  136.    compute e=evec(%MSLagState(i,0))
  137.    compute fvec(i)=%if(hvec(i)>0,exp(%logtdensity(hvec(i)*gv(%MSLagState(i,0)),e,nu)),0.0)
  138. end do i
  139. *
  140. * Do a filter step to update the probabilities. The log likelihood
  141. * element is returned in the LOGF option.
  142. *
  143. @MSFilterStep(logf=DuekerFilter) time fvec
  144. *
  145. * Take probability weighted averages of the h's for each regime.
  146. *
  147. compute ph=pt_t(time).*hvec
  148. compute pdiv  =%sumc(%reshape(pt_t(time),nstates,DFFilterSize))
  149. compute phstar=%sumc(%reshape(ph,nstates,DFFilterSize))./pdiv
  150. *
  151. * Push them out into the HS vector
  152. *
  153. compute %pt(hs,t,phstar)
  154. compute %pt(uus,t,evec.^2)
  155. end
  156. **************************************************************************
  157. function DFStart
  158. @MSFilterInit
  159. end
  160. **************************************************************************
  161. frml LogDFFilter = DuekerFilter(t)
  162. *
  163. @MSFilterSetup(noem)
  164. nonlin(parmset=fixgv) gv(2)=gv(1)
  165. *
  166. maximize(start=DFStart(),parmset=meanparms+garchparms+msparms+fixgv,$
  167.   pmethod=simplex,piters=5,method=bfgs) logDFFilter gstart gend
  168. @MSSmoothed gstart gend psmooth
  169. set p1 = psmooth(t)(1)
  170. set p2 = psmooth(t)(2)
  171. graph(max=1.0,footer="Probabilities of Regimes in Two Regime Gaussian model",$
  172.   style=stacked) 2
  173. # p1
  174. # p2
复制代码

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-6 04:52