楼主: sarah89323
16934 72

[问答] 跪求CKLS GMM法参数估计T_T [推广有奖]

31
epoh 发表于 2011-9-2 23:35:19

CIR model 亦找出原因了

程序更改如下

请自行更改.

v(i,1)=((P(3,1)^2)*(exp(2*P(2,1)*dt)-1))*X(i-1)/(2*P(2,1));

low_P4=[-400;-400;-400;0.5];%parameter restriction for CIR
up_P4=[400;400;400;0.5];
[P4,lnL4]=fmincon(@(P)CIR_Calibration(P,X,dt),ini_P,[],[],[],[],low_P4,up_P4,[],opts)
P4 =

    0.1132
   -5.5061
    0.2366
    0.5000


lnL4 =

-9.7917e+003

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 1 + 1 + 1 非常热心

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

32
epoh 发表于 2011-9-3 09:02:40
你的数据,哪个模型较合适
可以仔细看gmmdoc.pdf
Page 29/38
5.6 Term Structure Models CKLS
%%%%%%
J-statistic
  The J-statistic is the minimized value of the objective function.
  A simple application of the J-statistic is to test the validity
  of overidentifying restrictions.
  If the equation excluding suspect instruments is exactly identi…ed,
  the J-statistic will be zero.
%%%%%%
这在s-plus有很多例子说明.
page 53/61,
SV-model
  Test of Overidentification:
  J-stat      Df   P.value
  39.9342 21   0.0076
  The low p-value on the J -statistic indicates that the
  SV model (21.43) does not fit S&P 500 daily returns.
%%%%%%
page 57/61,
CKLS model
  Test of Overidentification:
  model is just-identified
%%%%%%
page 58/61,
CIR model
  Test of Overidentification:
  J-stat Df P.value
  3.7977 1  0.0513
  The low p-value on the J−statistic indicates a potentially
  mis-specified model.
      gmm_SPLUS.pdf (600.78 KB)

33
sarah89323 发表于 2011-9-4 07:50:16
epoh 发表于 2011-9-3 09:02
你的数据,哪个模型较合适
可以仔细看gmmdoc.pdf
Page 29/38
epoh:

Thxs!!! 我又检查运行了一遍, Finanlly It WORKS!!!!!

In sample:
P1 =

   -0.0158
    2.2296
  100.0000
    2.1604

P2 =

   -0.0007
         0
    0.0481
         0

P3 =

    0.3289
  -15.9347
    0.0488
         0

P4 =

    0.1132
   -5.5072
    0.2366
    0.5000

P5 =

         0
    0.8312
    1.3187
    1.0000
P6 =

    0.0308
   -0.8919
    1.3224
    1.0000

Out of sample:
P1 =

    0.4218
    0.9157
    0.7922
    0.9595
P2 =

    0.4218
         0
    0.7922
         0
P3 =

    0.4218
    0.9157
    0.7922
         0
P4 =

    0.4218
    0.9157
    0.7922
    0.5000
P5 =

         0
    0.9157
    0.7922
    1.0000
P6 =

    0.4218
    0.9157
    0.7922
    1.0000

我还有三个问题想请教:
1. MLE算的LnL 都很小, 几乎为0.
2. 你所显示的:
   parameters      se          t-value        p-value
    -0.0157        0.0168       -0.9365       0.3490
    2.2243         0.0115       192.5849      0.0000
    100.0000       4.3790       22.8365       0.0000
    2.1604         0.0282       76.4878       0.0000
   其中 se, t-value, p-value都代表什么? p-value是选择多少confidence level得到的?如何编程,code从何而来,我有看你上传的关于J-value的附件,但是太技术了,看的头晕。。。可不可以传code给我看一下。

3. GMM算出来的结果和MLE的相差很大, 比如MLE的CKLS: -0.0158,2.2296, 100.0000,2.1604。 GMM的CKLS 结果:0.014720, -0.713333, 729.803367, 2.222879.这个现象正常么? 有没有可能GMM的code还是存在些许问题,因为daily data 和monthly data 的原因?

谢谢:))


34
epoh 发表于 2011-9-4 10:11:21

1. MLE算的LnL 都很小,几乎为0.

   您头晕,看错了,都很大

   lnL1 = -1.0643e+004

        = -10643

2. MLE所显示的:

   parameters      se          t-value        p-value

    -0.0157        0.0168       -0.9365       0.3490

    2.2243         0.0115       192.5849      0.0000

    100.0000       4.3790       22.8365       0.0000

    2.1604         0.0282       76.4878       0.0000

    se, t-value, p-value ,如何编程,code从何而来

    code 在9/2我上传的GMM_MLE.rar

    就在CIR_matlab script

    根据[P1,lnL1,...,hessian]=fmincon(@(Params) CIRobjective1....)

    算出hessian.

    有了hessian,就可算出 se, t-value, p-value

   

3. GMM算出来的结果和MLE的系数不同

   应该是正常的

   ML can be more efficient than GMM

       ML uses the entire distribution while

       GMM only uses specified moments

   GMM can be produce estimators using few assumptions

       More robust, less efficient

   哪个比较准确你用out_sampl 做预测

   画出如gmmdoc figure(7)就知道了

4.An Empirical Comparison of Alternative Models of the Short-Term Interest Rate

  http://rady.ucsd.edu/faculty/directory/valkanov/classes/mfe/docs/Longstaff_JoF_1992.pdf

35
epoh 发表于 2011-9-4 14:16:46

系数方向都调对了.

init values很重要(花较多时间)

%%%%%%%%%

load in_sample
X=in_sample/100;
n=length(X);
dt=1/260;
% option settings for optimization algorithm
opts=optimset( 'Display',             'notify', ...
                    'MaxIter',              1000,   ...
                    'MaxFunEvals',          4000,   ...
                    'LargeScale',           'off',  ...
                    'HessUpdate',           'bfgs', ...
                    'TolX',                 1e-8,   ...
                    'TolFun',               1e-11   ...
                    );  
ini_P=[0.3;-10;50;2];
%%%%%%%%%%%%CKLS
low_P=[0.3;-50;0.1;0.1];
up_P=[5;-0.3;400;4];
[P1,lnL1]=fmincon(@(P)CKLS_Calibration(P,X,dt),ini_P,[],[],[],[],low_P,up_P,[],opts)
%%%%%%%%%%%%Merton
low_P2=[0.3;0;0.1;0];
up_P2=[5;0;400;0];
[P2,lnL2]=fmincon(@(P)Merton_Calibration(P,X,dt),ini_P,[],[],[],[],low_P2,up_P2,[],opts)
%%%%%%%%%%%%VASICEK
low_P3=[0.3;-50;0.1;0];
up_P3=[5;-0.3;400;0];
[P3,lnL3]=fmincon(@(P)VASICEK_Calibration(P,X,dt),ini_P,[],[],[],[],low_P3,up_P3,[],opts)
%%%%%%%%%%%%CIR
low_P4=[0.3;-50;0.1;0.5];
up_P4=[5;-0.3;400;0.5];
[P4,lnL4]=fmincon(@(P)CIR_Calibration(P,X,dt),ini_P,[],[],[],[],low_P4,up_P4,[],opts)
%%%%%%%%%%%% Dothan
low_P5=[0;-50;0.1;1];
up_P5=[0;-0.3;400;1];
[P5,lnL5]=fmincon(@(P)Dothan_Calibration(P,X,dt),ini_P,[],[],[],[],low_P5,up_P5,[],opts)
%%%%%%%%%%%%Brennan_Schwartz
low_P6=[0.3;-100;0.1;1];
up_P6=[5;-0.3;400;1];
[P6,lnL6]=fmincon(@(P)Brennan_Schwartz_Calibration(P,X,dt),ini_P,[],[],[],[],low_P6,up_P6,[],opts)
%%%%%%%%%%%
%%result
P1 =

    0.3000
  -21.4332
  110.1831
    2.1431


lnL1 =

-1.0449e+004
%%
P2 =

    0.3000
         0
    0.1000
         0


lnL2 =

   -5.0625
%%
P3 =

    1.0333
-50.0000
    0.1000
         0


lnL3 =

-8.6186e+003
%%
P4 =

    0.3000
  -14.5800
    0.2428
    0.5000


lnL4 =

-9.7769e+003
%%
P5 =

         0
   -1.5481
    0.1000
    1.0000


lnL5 =

   -9.1663
%%
P6 =

    1.6587
-100.0000
    0.1000
    1.0000


lnL6 =

   -9.3434

36
epoh 发表于 2011-9-4 16:06:20

为了释疑

这里有篇博士论文

chap3 做了 ckls model,GMM &EMM 系数的比较

  http://www.ma.hw.ac.uk/~cl259/papers/thesis/phdthesis_charnchai.pdf

GMM: page 102/243
                 coef       se          t          p
  alpha       0.0039  0.0078   0.5039  0.6144
  beta       -0.0847  0.1628  -0.5202  0.603
  sigma      0.0233  0.0266   0.8785  0.3798

  gamma    0.6642  0.3821   1.7384  0.0823
       (mu = -alpha/beta = 0.0461, k = -beta = 0.0847)

%%%%
EMM: page 105/243
                 coef       se            95% Confidence Interval
  alpha       0.00175  0.00014  (0.00162, 0.00185)
  beta       -0.03725  0.00371  (-0.04104, -0.03381)
  sigma      2.34047  1.26179  (1.16214, 3.20102)

  gamma    2.43216  0.19977  (2.24033, 2.56582)
       (mu = -alpha/beta = 0.04706, k = -beta = 0.03725)

37
epoh 发表于 2011-9-4 19:36:11

数据型态:

GMM Libraries 的ckls.dat

是monthly data

原始数据是:

640630  0.002856

640731  0.002714

640831  0.002718

.....

.....

891031  0.006536

891130  0.006754

%%%%%%%%

但我们计算是annual

所以需要乘上12

12*0.002856= 0.034272,

12*0.002714= 0.032568

12*0.002718= 0.032616

..........

ckls.dat就是已经转换过的数据

一年有12个数据,以年为单位,所以间隔

dt=1/12.

38
sarah89323 发表于 2011-9-4 21:02:16
epoh 发表于 2011-9-4 19:36
数据型态:GMM Libraries 的ckls.dat是monthly data原始数据是:640630  0.002856640731  0.002714640831  0. ...
thxs!
1.我的数据是daily的(260天一年), code把12的地方都替换成260,请问就ok了么?

2. MLE 的inital parameters value你是如何确定方向的?为甚么针对不同的model要设置不同的初始值?

3. p_value, t_value 是CIR-matlab scipt是针对CIR之前的code, 替换成我们最终敲定的code的话, 该如何修改主文件和对应的副文件?我没有看明白CIR的那个code, 主要是对这些test知识匮乏, 对hessian matrix也完全不了解,因此不知道该如何借鉴应用到我们最后的code.

sarah

39
epoh 发表于 2011-9-5 16:57:29

   MLE & GMM forecast.rar (139.82 KB)

MLE 经微调后结果如下:

Dothan需要Dothan_Calibration1.m

Merton需要Merton_Calibration1.m

%%%%%%%%CKLS Model

ckls_graph.jpg

%%%%%%%%CIR Model

   cir_graph.jpg

%%%%%%%VASICEK Model

   vasicek_graph.jpg

40
sarah89323 发表于 2011-9-5 18:39:08
epoh 发表于 2011-9-5 16:57
MLE 经微调后结果如下:Dothan需要Dothan_Calibration1.mMerton需要Merton_Calibration1.mP1:
parameter ...
epoh:
图片看上去很棒!有几点疑惑:
1. 刚打开Merton 和Dothan调整过的程序, sum都是在loop里面的。Merton:v(i,1)=(P(2,1)^2)*dt,而P(2,1)是beta, merton model 设置应该为0, 是不是程序打包的时候选择错了文件?呵呵
n=length(X);
    for i =2:n
        sum=0;
        v=zeros(n,1);
        v(i,1)=(P(2,1)^2)*dt;
        ita=zeros(n,1);
        ita(i,1)=X(i)-X(i-1)-P(1,1)*dt;
        sum=sum+log(v(i,1))+(ita(i,1)^2)/v(i,1)

2. 那几个很beautiful的图片背后是什么样的理论? 请教一下什么是roll MLE 和roll GMM?

3. 现在我的code totally in a mass:( 有修正过的和旧的, 实在不是个well-organized的人。可以把你那的MLE和roll Pictured 的code 打包发我么? 我这没有Dothan 和Merton的 p value 的maincode. 还有如何得到精致图片的code我也很有兴趣想研究一下。

thxs

sarah

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-3 04:43