全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Gauss专版
10098 8
2011-02-25
最近看van Dijk的Nonlinear time series models in empirical finance遇到一个困惑,希望得到大家的帮助。

在第三章里,程序forwtare.e里有这样一条指令:  tdat=trimr(shiftr(ty[maxc(1|(1-maxl)):tn]',seqa(0,1,maxl+1),0)',maxl,0);

请问这条指令的目的是什么呢?

希望和正在学习这本书的朋友一起研究学习写程序。
二维码

扫码加我 拉你入群

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

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

全部回复
2011-2-25 01:25:32
如下是这个程序的内容:

/*
** FXWTARE.e
** Estimate SETAR models for weekly exchange rate returns with various
** AR-orders in different regimes and compute information criteria
**
** This program makes use of procedures based on GAUSS code of Bruce Hansen
**
** Written by Dick van Dijk
** Last revision on May 28, 1999
**
*/

new;
cls;
__maxvec=100000;
_graph=0;

let omit = 0;   /* lags omitted from autoregression, if all included set omit=0  */
h = 1;          /* set h=1 for heteroskedasticity-correction else set h=0 */
trim_per = .15; /* percentage of sample to trim from ends for test, e.g., trim_per=.15 */
rep = 1000;     /* number of bootstrap replications */
maxp=5;         /* maximum AR order */

iind={1,2,3,4,5,6,7,8}; /* series for which to perform computations */
ni=rows(iind);
ydind={1,2,3,4};        /* delay parameters for lagged return */
nyd=rows(ydind);
maxyd=maxc(ydind);      /* maximum delay parameter */
wvind={1,2,3,4};        /* number of weeks j in average absolute returns v(t-1,j) */
nwv=rows(wvind);
maxwv=maxc(wvind);      /* maximum delay parameter */

_conf1=.95;             /* confidence level for threshold */
_conf2=.8;              /* confidence level for AR parameters */
_nonpar=2;              /* See THR_EST.g */
if (h==0);
  _quick=1;
else;
  _quick=2;
endif;

dataset="FOREXWR";
y=loadd(dataset);
vnames=getname(dataset);
nos=rows(vnames);
ny=rows(y);

/*
** Specify first and last observation of subsample for which model
** is to be estimated.
** Years begin with observation number 1 (1980) , 53 (1981), 105 (1982),
** 157 (1983), 209 (1984), 261 (1985), 313 (1986), 366 (1987), 418 (1988),
** 470 (1989), 522 (1990), 574 (1991), 626 (1992), 679 (1993), 731 (1994),
** 783 (1995), 835 (1996), 887 (1997), 940 (1998) */
T_byv = {209,1,1,1,1,1,1,1};
T_eyv = 521.*ones(nos,1);

tim=date;
i=0;
do until (i==ni);
  i=i+1;
  ctr=iind[i];

  AIC=zeros(maxp+1,nyd+nwv);
  BIC=zeros(maxp+1,nyd+nwv);
  pvtest1=zeros(maxp+1,nyd+nwv);

  T_by = T_byv[ctr];
  T_ey = T_eyv[ctr];

  format 12,6;
  fstr = "" $+ vnames[ctr] $+ "e.OUT";
  output file = ^fstr reset; screen off;
  output off; screen on;

  ty=packr(y[T_by:T_ey,i]);
  tn=rows(ty);

  /* construct data-matrix */
  maxl=maxc(maxyd|maxwv|maxp);
  tdat=trimr(shiftr(ty[maxc(1|(1-maxl)):tn]',seqa(0,1,maxl+1),0)',maxl,0);
  l=0;
  do until (l==nwv);
    l=l+1;
    t2dat=meanc(abs(tdat[.,2:2+wvind[l]-1]'));
    tdat=tdat~t2dat;
  endo;
  tdat=ones(tn-maxl,1)~tdat;

  /* construct vector with names of variables */
  names = "const";
  namej = "y(t)";
  names = names|namej;
  l=0;
  do until (l==maxl);
    l=l+1;
    if sumc(omit .== l)==0;
      if l<10;
        pn = ftocv(l,1,0);
      else;
        pn = ftocv(l,2,0);
      endif;
      namej = "" $+ "y(t-" $+ pn $+ ")";
      names = names|namej;
    endif;
  endo;

  l=0;
  do until (l==nwv);
    l=l+1;
    if wvind[l]<10;
      pn = ftocv(wvind[l],1,0);
    else;
      pn = ftocv(wvind[l],2,0);
    endif;
    namej = "" $+ "wv(t-" $+ pn $+ ")";
    names = names|namej;
  endo;

  j=-1;
  do until (j==maxp); /* loop over AR orders */
    j=j+1;
    yi=2;
    xi = 1;
    if (j GT 0);
      xi=xi|seqa(3,1,j);
    endif;
    if j==0;
      _nonpar=1;
    else;
      _nonpar=2;
    endif;

    d = 0;
    do until (d==(nyd+nwv));
      /* loop over transition variables (lagged returns and avg. abs. return) */
      d=d+1;
      if (d LE nyd);
        qi = 2+ydind[d];
      else;
        qi= 2+maxl+d-nyd;
      endif;

      /* estimate threshold model */
      {beta,se,ee,sig,r_2,pv_het,qhat1,qhat2,ee1,ee2,sig_jt,r2_joint,pv_hetj,qhat,
      beta1,se1,beta1l,beta1u,n1,sig1,r2_1,beta2,se2,beta2l,beta2u,n2,sig2,r2_2}=
      thr_est(tdat,names,yi,xi,qi,h,trim_per);

      /* compute information criteria */
      AIC[j+1,d]=n1*ln(sig1) + n2*ln(sig2) +4*(j+1);
      BIC[j+1,d]=n1*ln(sig1) + n2*ln(sig2) +(j+1)*(ln(n1)+ln(n2));

      /* write output */
      yname=names[yi];
      xname=names[xi];
      qname=names[qi];
      tn=rows(tdat);
      k=rows(xi);
      screen off;
      call THR_outp(fstr,yname,xname,qname,tn,k,h,beta,se,ee,sig,r_2,pv_het,
               qhat1,qhat2,ee1,ee2,sig_jt,r2_joint,pv_hetj,qhat,beta1,se1,
               beta1l,beta1u,n1,sig1,r2_1,beta2,se2,beta2l,beta2u,n2,sig2,r2_2,(d==1));
      screen on;

      /* compute (bootstrap) test against TAR */
      if h==0;
         {f_test,p_value,q_max} = thr_test(tdat,yi,xi,qi,trim_per,rep);
        output file = ^fstr on; screen off;
        "";"";
        "Test of Null of No Threshold Against Alternative of Threshold";
        "Under Maintained Assumption of Homoskedastic Errors";
        "";
        "Number of Bootstrap Replications " rep;
        "Trimming Percentage              " trim_per;
        "";
        "Threshold Estimate               " q_max;
        "F-test for no threshold          " f_test;
        "Bootstrap P-Value                " p_value;
        "";""; output off; screen on;
      elseif h==1;
        {f_test,p_value,q_max} = thr_het(tdat,yi,xi,qi,trim_per,rep);
        output file = ^fstr on; screen off;
        "Test of Null of No Threshold Against Alternative of Threshold";
        "Allowing Heteroskedastic Errors (White Corrected)";
        "";
        "Number of Bootstrap Replications " rep;
        "Trimming Percentage              " trim_per;
        "";
        "Threshold Estimate               " q_max;
        "LM-test for no threshold         " f_test;
        "Bootstrap P-Value                " p_value;
        "";""; output off; screen on;
      endif;
      pvtest1[j+1,d]=p_value;
   
      info((i-1)*(nyd+nwv)*(maxp+1)+j*(nyd+nwv)+d,(maxp+1)*(nyd+nwv)*ni,tim);
    endo;
  endo;

  output file = ^fstr on; screen off;
  format /rd 6,3;
    "AIC";"";
    AIC'; "";
    "BIC";"";
    BIC';
    "p_value";"";
    pvtest1';
  output off; screen on;
endo;
二维码

扫码加我 拉你入群

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

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

2011-2-25 01:29:22
至于其他需要运行的程序和函数请在如下地址下载:

http://people.few.eur.nl/djvandijk/nltsmef/nltsmef.htm
二维码

扫码加我 拉你入群

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

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

2011-2-25 03:35:50
问题已经解决了,
不过还是和大家交流一下心得!
我用“最傻”的方法,在命令窗口,一行一行看程序运行的结果。
希望和一起在专研这本书的朋友一起学习讨论!!
二维码

扫码加我 拉你入群

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

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

2011-2-25 09:24:12
zengsongl 发表于 2011-2-25 03:35
问题已经解决了,
不过还是和大家交流一下心得!
我用“最傻”的方法,在命令窗口,一行一行看程序运行的结果。
希望和一起在专研这本书的朋友一起学习讨论!!
基本上对不懂的程序,大家都只能这么看.........
二维码

扫码加我 拉你入群

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

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

2011-2-25 10:47:02
tdat=trimr(shiftr(ty[maxc(1|(1-maxl)):tn]',seqa(0,1,maxl+1),0)',maxl,0);
其实就是处理数据的语句
trimr
shiftr
这两个命令你要知道干什么的
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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