楼主: tulipsliu
5318 17

[程序分享] 关于DynamicCopulaToolbox3.0 (VineCopula)的教学 [推广有奖]

促进中国计量经济学发展学科带头人

学科带头人

43%

还不是VIP/贵宾

-

威望
0
论坛币
386093 个
通用积分
469.9098
学术水平
127 点
热心指数
140 点
信用等级
103 点
经验
46957 点
帖子
1769
精华
0
在线时间
2471 小时
注册时间
2007-11-5
最后登录
2024-4-19

初级热心勋章

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
教学编号:2019-001号

那么这个文件夹出来很多年,怎么使用很多新学的学生还不会,这里只给出一个我修改的使用程序。其实严格来说不太规范的使用,因为可以按照作者的PDF说明用作者的两步法:第一步估计garch 分布函数(使用作者的文件夹里的函数,其中很多函数直接引用英国牛津大学keven sheppard 的 MFETOOLBOX 里的garch函数),那么如果需要用作者的原方法的,有必要的话我发帖 2019-002号教学。

这里是我个人使用 MATLABR R2019a ,利用官方econometric toolbox 里的garch 估计函数来修改的。请看源代码,文件名为:
garch_copula_test.m   ,下划线最后test代表是我做的一个小测试。

  1. %% Import the Supporting Historical Dataset
  2. % tulips  2019年7月8日 修改
  3. % Load a daily historical Dataset of 3-month Euribor, the trading dates spanning
  4. % the interval 07-Feb-2001 to 24-Apr-2006, and the closing index levels of the
  5. % following representative large-cap equity indices:
  6. %
  7. % * TSX Composite (Canada)
  8. % * CAC 40 (France)
  9. % * DAX (Germany)
  10. % * Nikkei 225 (Japan)
  11. % * FTSE 100 (UK)
  12. clc
  13. clear;close all
  14. % Clear Up
  15. load Data_GlobalIdx1   % Import daily index closings
  16. % The next line ,chang data read for your dataset
  17. % [Data,~]=xlsread('YourDataset.xlsx');

  18. returns = price2ret(Data);    % Logarithmic returns
  19. T       = size(returns,1);    % # of returns (i.e., historical sample size)
  20. %%
  21. % Since the first step in the overall modeling approach involves a repeated
  22. % application of GARCH filtration and Extreme Value Theory to characterize
  23. % the distribution of each individual equity index return series, it is
  24. % helpful to examine the details for a particular country. You can change the
  25. % next line of code to any integer in the set {1,2,3,4,5,6} to examine the
  26. % details for any index.

  27. index = 1;  % 1 = Canada, 2 = France, 3 = Germany, 4 = Japan, 5 = UK, 6 = US

  28. figure
  29. plot(dates(2:end), returns(:,index))
  30. datetick('x')
  31. xlabel('Date')
  32. ylabel('Return')
  33. title('Daily Logarithmic Returns')

  34. %%
  35. % To produce a series of i.i.d. observations, fit a first order
  36. % autoregressive model to the conditional mean of the returns of each
  37. % equity index
  38. %
  39. % $r_t = c + \theta r_{t-1} + \epsilon_t$
  40. %
  41. % and an asymmetric GARCH model to the conditional variance
  42. %
  43. % $\sigma^2_t = \kappa + \alpha\sigma^2_{t-1} + \phi\epsilon^2_{t-1} + \psi[\epsilon_{t-1}<0]\epsilon^2_{t-1}$
  44. %
  45. % The first order autoregressive model compensates for autocorrelation,
  46. % while the GARCH model compensates for heteroskedasticity. In particular,
  47. % the last term incorporates asymmetry (leverage) into the variance by a
  48. % Boolean indicator that takes the value 1 if the prior model residual
  49. % is negative and 0 otherwise (see Glosten, Jagannathan, & Runkle [3]).
  50. %
  51. % Additionally, the standardized residuals of each index are modeled
  52. % as a standardized Student's t distribution to compensate for the fat
  53. % tails often associated with equity returns. That is
  54. %
  55. % $z_t = \epsilon_t/\sigma_t$ i.i.d. distributed $t(\nu)$
  56. %
  57. % The following code segment extracts the filtered residuals and conditional
  58. % variances from the returns of each equity index.

  59. model     = arima('AR', NaN, 'Distribution', 't', 'Variance', gjr(1,1));
  60. nIndices  = size(Data,2);        % # of indices
  61. residuals = NaN(T, nIndices);    % preallocate storage
  62. variances = NaN(T, nIndices);
  63. fit       = cell(nIndices,1);

  64. options   = optimoptions(@fmincon, 'Display', 'off', ...
  65.     'Diagnostics', 'off', 'Algorithm', 'sqp', 'TolCon', 1e-7);

  66. for i = 1:nIndices
  67.     fit{i} = estimate(model, returns(:,i), 'Display', 'off', 'Options', options);
  68.     summarize(fit{i})
  69.     [residuals(:,i), variances(:,i)] = infer(fit{i}, returns(:,i));
  70. end

  71. %%
  72. % Having filtered the model residuals from each return series, standardize
  73. % the residuals by the corresponding conditional standard deviation. These
  74. % standardized residuals represent the underlying zero-mean, unit-variance,
  75. % i.i.d. series upon which the EVT estimation of the sample CDF tails is based.
  76. residuals = residuals ./ sqrt(variances);
  77. uData = zeros(T,nIndices);  % Cell array of Pareto tail objects

  78. for i = 1:nIndices
  79.     uData(:,i) = empiricalCDF(residuals(:,i));
  80. end
  81. %% TWO STEP COPULA OR COPULA VINE
  82. % STEP ONE (ASSUMES GARCH TYPE MARGINS). CALL:

  83. % specM = modelspec(rets) %Data is the Data set. Choose "GARCH model for each series"
  84. % and make the desired choices for the margins. Then call:

  85. % [parsM, LogLM, evalM, GradHessM, uData] = fitModel(specM, rets, 'fmincon');

  86. % if you do not care for standard errors you can use 'fmincon'. parsM
  87. % contains the estimated parameters, in the form of table 5, in the pdf
  88. % LogLM is the vector of the marginal log likelihoods at the optimum
  89. % evalM is a cell that contains structures
  90. % GradHessM is a cell that contains structures
  91. % uData is the matrix of sample GARCH residuals turned to uniform.

  92. %%  STEP TWO.  
  93. % STEP TWO.
  94. % Define your copula or copula vine by:
  95. % specC = modelspec(uData)
  96. % Estimate the copula parameters, by:
  97. % [parsC, LogLC, evalC, GradHessC] = fitModel(specC, uData, 'fminunc');

  98. %% STARTING VALUES
  99. % In case you want to estimate the same model in one step it would be wise
  100. % to create a vector of starting values for the one step procedure, as
  101. % follows:
  102. % p=size(uData,1);
  103. % p=size(parsM,1);
  104. % test = [reshape(parsM,[p,1]),parsC]; %p is the dimension
  105. % If you want to fit a copula vine you are advised to use good starting
  106. % values. To obtain such values, one more step is needed, prior to step two
  107. % call:
  108. specS = modelspec(uData);
  109. % and define the model as "copula vine sequentially"
  110. % Estimate the copula parameters, by:
  111. [parsC, LogLC, evalC, GradHessC] = fitModel(specS, uData, 'fmincon');
  112. % the array parsS is a good initial guess for the model parameters. Then go
  113. % to step two (line 18)



  114. %%

  115. % NOTES:
  116. % 1. Fminunc should be used when asymptotic standard errors are to be
  117. % computed. Fmincon is more robust than fminunc, in the sence that it
  118. % always converges to a solution unlike fminunc

  119. % 2. The estimated parameters are always ordered as in the tables in the
  120. % pdf. For the marginal models, the correct order is:
  121. % [mean parameters;GARCH parameters;marginal distribution parameters]
  122. % For the t DCC copula the order is
  123. % [copula DoF;alphaDCC;bDCC];
  124. % For the SJC copula the first parameter(s) always corresponds to the upper
  125. % tail (equation).
复制代码



程序到90行那里估计了garch 边缘分布,garch为非对称gjrGARCH模型,分布为 student t 分布 。
90行后工具箱函数会弹出对话框,点第二个选项,估计copula ,其中可以设定 tvp-copula 或者 Vine copula
这里只展示边缘分布估计gjrGARCH 的估计值和一个非vine copula 的估计值。

ARIMA(1,0,0) Model (t Distribution)

    Effective Sample Size: 2664
    Number of Estimated Parameters: 7
    LogLikelihood: 7827.51
    AIC: -15641
    BIC: -15599.8

                Value    StandardError    TStatistic    PValue
                _____    _____________    __________    ______

    Constant    -0.00        0.00           -0.86        0.39
    AR{1}       -0.01        0.02           -0.48        0.63
    DoF          8.97        1.24            7.26        0.00



   GJR(1,1) Conditional Variance Model (t Distribution)

                   Value    StandardError    TStatistic    PValue
                   _____    _____________    __________    ______

    Constant       0.00         0.00            2.72        0.01
    GARCH{1}       0.91         0.01           71.79        0.00
    ARCH{1}        0.02         0.01            2.48        0.01
    Leverage{1}    0.10         0.02            5.60        0.00
    DoF            8.97         1.24            7.26        0.00



copula 估计值:

Estimation output
parameter   St. Error    t-stats
---------------------------------
0.1908                 0.029                 6.6079                       
0.2263                 0.026                 8.6863                       
---------------------------------
Akaike: -455.7162
BIC: -443.9410
Log Likelihood: 229.858
---------------------------------
Estimation time is 120.07 seconds




     enjoyi                                           yours: daniel tulips  liu
二维码

扫码加我 拉你入群

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

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

关键词:toolbox Dynamic Copula opula Dynam

已有 1 人评分经验 学术水平 收起 理由
317792209 + 100 + 3 精彩帖子

总评分: 经验 + 100  学术水平 + 3   查看全部评分

劳动经济学
沙发
xujingjun 发表于 2019-9-23 13:00:06 |只看作者 |坛友微信交流群

使用道具

藤椅
梅贤 发表于 2019-12-2 23:46:10 |只看作者 |坛友微信交流群
老师,您好,我用这个包做了dcc-copula,之后想计算covar,请问有相关的程序可以直接用吗?

使用道具

板凳
3633011 发表于 2019-12-3 14:06:07 |只看作者 |坛友微信交流群
老师能给个QQ号吗

使用道具

报纸
tulipsliu 在职认证  发表于 2019-12-4 09:03:00 |只看作者 |坛友微信交流群
梅贤 发表于 2019-12-2 23:46
老师,您好,我用这个包做了dcc-copula,之后想计算covar,请问有相关的程序可以直接用吗?
这个是藤copula 然后做成 动态藤copula 。暂时没公开的代码。

我论坛发了另一个ZIP文件,是  dcc_gjrGARCH CoVaR; 那个没有copula 估计的过程。

你可以github 搜索 Copula CoVaR 有一个意大利学者的。
它的是R 语言的,我还没上传人大经济论坛。

你关注我的帖子吧,我发一个。 不过哪个的使用得需要更多的编程经验;

你可以加我的QQ: 280201722 潇湘旭

使用道具

地板
tulipsliu 在职认证  发表于 2019-12-4 09:04:00 |只看作者 |坛友微信交流群
3633011 发表于 2019-12-3 14:06
老师能给个QQ号吗
280201722  在我的其他帖子已经给了号码的。你既然问那么发给你。
有问题欢迎随时交流。

最近忙我不一定每天都上论坛,有下载资料需要的时候才会上。

使用道具

7
tulipsliu 在职认证  发表于 2019-12-4 09:04:54 |只看作者 |坛友微信交流群
梅贤 发表于 2019-12-2 23:46
老师,您好,我用这个包做了dcc-copula,之后想计算covar,请问有相关的程序可以直接用吗?
你等一下,刚才回复了比较详细结果在审核中。
你看不到我回复你的上一条,你加我QQ
280201722

使用道具

8
tianwk 发表于 2020-2-19 00:44:51 |只看作者 |坛友微信交流群
thanks for sharing

使用道具

9
tulipsliu 在职认证  发表于 2020-2-20 09:36:40 |只看作者 |坛友微信交流群
tianwk 发表于 2020-2-19 00:44
thanks for sharing
呵呵 有用就好;

使用道具

10
zwzhai 发表于 2020-4-5 19:41:52 |只看作者 |坛友微信交流群
非常感谢。

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-20 13:17