2010年1月22日

Ubuntu 8,04 下的 GJR-garchm for gretl 1.8.4

gertl 估計結果
? ret = garchm(r, 1, 2, l1, 1, 0, 0, 0, 0.7, 1, 1, null, null)

================================================================
   GJR-GARCH-in-Mean fucntion for gretl by Yi-Nung Yang
   Chung Yuan Christian University, Taiwan
   http://yaya.it.cycu.edu.tw/gretl
================================================================
The coefficient of GJR Term is gamma_i
Presample variance: backcast (parameter = 0.7)
Initial Values:
b1=-0.131806, omega=1.126780, alpha1=0.120000, alpha2=0.040000, gamma1=0.040000, beta1=0.600000,
-------    mean eq & variance eq in this GARCH model --------
   e= y -b1*X1
   h = omega +alpha1*(e(-1))^2+alpha2*(e(-2))^2+gamma1*(e(-1))^2*(e(-1)<0)+beta1*h(-1)
================================================================
Using numerical derivatives
Tolerance = 1.81899e-012
Function evaluations: 166
Evaluations of gradient: 39

Model 8: 最大概似法 (ML), using observations 3-1361 (T = 1359)
ll = -0.5*(log(2*pi)+log(h) + (e^2)/h)
Standard errors based on Outer Products matrix

              estimate    std. error   t-ratio    p-value
  --------------------------------------------------------
  b1         -0.0670351   0.0246001    -2.725    0.0064    ***
  omega       0.0101593   0.00146715    6.924    4.38e-012 ***
  alpha1     -0.0870361   0.0151949    -5.728    1.02e-08  ***
  alpha2      0.0597284   0.0162602     3.673    0.0002    ***
  gamma1      0.146400    0.0172923     8.466    2.53e-017 ***
  beta1       0.940360    0.00960635   97.89     0.0000    ***

Log-likelihood      -1772.480   Akaike criterion     3556.959
Schwarz criterion    3588.246   Hannan-Quinn         3568.673

Replaced list ret

Evniews 估計結果
Dependent Variable: R               
Method: ML - ARCH (Marquardt) - Normal distribution               
Date: 01/22/10   Time: 01:34               
Sample (adjusted): 1/06/2004 5/29/2009               
Included observations: 1359 after adjustments               
Estimation settings: tol= 0.00010, derivs=accurate numeric (linear)               
Initial Values: C(1)=-0.13181, C(2)=1.19673, C(3)=0.13333, C(4)=0.04444,               
        C(5)=0.04444, C(6)=0.53333               
Convergence achieved after 22 iterations               
Presample variance: backcast (parameter = 0.7)               
GARCH = C(2) + C(3)*RESID(-1)^2 + C(4)*RESID(-1)^2*(RESID(-1)<0) +               
        C(5)*RESID(-2)^2 + C(6)*GARCH(-1)               
               
    Coefficient    Std. Error    z-Statistic    Prob. 
               
R(-1)    -0.068286    0.024528    -2.784002    0.0054
               
    Variance Equation           
               
C    0.010315    0.001488    6.934109    0.0000
RESID(-1)^2    -0.086935    0.015597    -5.573912    0.0000
RESID(-1)^2*(RESID(-1)<0)    0.146578    0.017262    8.491349    0.0000
RESID(-2)^2    0.059067    0.016569    3.564933    0.0004
GARCH(-1)    0.940811    0.009581    98.19407    0.0000
               
R-squared    0.013200        Mean dependent var        -0.015854
Adjusted R-squared    0.009553        S.D. dependent var        1.330019
S.E. of regression    1.323651        Akaike info criterion        2.617407
Sum squared resid    2370.525        Schwarz criterion        2.640429
Log likelihood    -1772.528        Hannan-Quinn criter.        2.626026
Durbin-Watson stat    2.145564       

function list garchm (series depvar "Dep. var (應變數)", int GARCH[0:9:1] "GARCH p", int ARCH[1:9:1] "ARCH q", list indepvar[null] "Indpe var (自變數) list", int gjr_order[0:9:0] "GJR order (階次)", int option[0:3:0] "GRACH-in-Mean  (選項 0:none; 1:stdev; 2:h; 3:lnh)", int LB_Q[0:200:0] "Ljung-Box Q (殘差 Q 檢定階次)", int LB_Q2[0:200:0] "Ljung-Box Q2 (殘差 Q2 檢定階次)", scalar backcast[0:1:0.7] "backcasting (參數)", bool ShowInit[0] "Show Init. (顯示起始值)?", bool save_resid[0] "Save standardized residual and h (儲存殘差和 h)?", string res_name[null] "User-defined residual (自訂殘差名稱)", string ht_name[null] "User-defined h (自訂 h 名稱)")
  #================================================================
  #   GJR-GARCH-in-Mean fucntion for gretl by Yi-Nung Yang
  #   Chung Yuan Christian University, Taiwan
  #   http://yaya.it.cycu.edu.tw/gretl
  #================================================================
  set echo off
  set messages off
  # -------- variance equation -----------
  #       series h = omega + alpha*(e(-1))^2 + beta*h(-1)
  if ARCH=0
    funcerr "ARCH q 必須大於 0"
  else
    string v_eq = "h = omega "
    string arch_param = "omega "
    loop j=1..ARCH  --quiet
      sprintf arch_term "+alpha%d*(e(-%d))^2",j,j
      sprintf v_param "alpha%d ",j
      scalar @v_param = 0.04
      string v_eq = v_eq ~ arch_term
      string arch_param = arch_param ~ v_param
    endloop
    if gjr_order>0
      loop j=1..gjr_order  --quiet
        sprintf arch_term "+gamma%d*(e(-%d))^2*(e(-%d)<0)",j,j,j
        sprintf v_param "gamma%d ",j
        scalar @v_param = 0.05
        string v_eq = v_eq ~ arch_term
        string arch_param = arch_param ~ v_param
      endloop
    endif
    if GARCH>0
      loop j=1..GARCH  --quiet
        sprintf arch_term "+beta%d*h(-%d)",j,j
        sprintf v_param "beta%d ",j
        scalar @v_param = 0.04
        string v_eq = v_eq ~ arch_term
        string arch_param = arch_param ~ v_param
      endloop
    endif
  endif
  #   printf "%s\n", v_eq
  #   printf "%s\n", arch_param
  tL2 = indepvar
  tL3 = indepvar || const
  genr is_const = (tL2 = tL3)
  if is_const = 1
    tL2 -= const
  endif
  i=1
  loop foreach j tL2  --quiet
    string temp="x"
    sprintf temp "X%d",i
    #producing tmp%d independent variables
    genr @temp = tL2.$j
    i=i+1
  endloop
  scalar n_x = i-1
  scalar j=1
  # define ---------->  mean eq.
  if is_const = 1
    string m_eq = "e = y - b0 "
    string tParam = "b0 "
  else
    string m_eq = "e= y "
    string tParam = " "
  endif
  if n_x >=1
    loop j=1..n_x  --quiet
      sprintf tx "-b%d*X%d", j,j
      sprintf tparameter "b%d ", j
      scalar @tparameter = 0.0001
      string m_eq = m_eq ~ tx
      string tParam = tParam ~ tparameter
    endloop
  endif
  if option>0
    if option=1
      string m_eq = m_eq ~ "-theta*h^0.5"
      string tPremium="SQRT(h)"
    endif
    if option=2
      string m_eq = m_eq ~ "-theta*h"
      string tPremium="h"
    endif
    if option=3
      string m_eq = m_eq ~ "-theta*log(h)"
      string tPremium="ln(h)"
    endif
    if option>3
      funcerr "The GARCH-in-mean options are 1, 2, 3."
    endif
    string tParam = "theta " ~ tParam
  else
    string tPremium="None"
  endif
  #       printf "%s\n", m_eq
  #scalar backcast=0.7
  series y=depvar
  scalar mu = -0.037
  scalar alpha1 = 0.15 - 0.03*(ARCH>1)
  scalar beta1 = 0.6 - 0.12*(GARCH>1)
  scalar gamma1=0.05 - 0.01*(ARCH>1)
  ####  scalar theta =0.01879
  scalar b0=-0.00377
  scalar b1=0.5
  scalar b2=0.4
  #scalar omega = 1.149
  #scalar omega =var(y)*(1-alpha1-beta1)
  scalar omega =var(y)*backcast*0.91
  printf "\n\n\n\n"
  printf "================================================================\n"
  printf "   GJR-GARCH-in-Mean fucntion for gretl by Yi-Nung Yang\n"
  printf "   Chung Yuan Christian University, Taiwan\n"
  printf "   http://yaya.it.cycu.edu.tw/gretl\n"
  printf "================================================================\n"
  if gjr_order>0
    printf "The coefficient of GJR Term is gamma_i\n"
  endif
  if option>0
    printf "GARCH in mean Term is %s\n",tPremium
    printf "The coefficient of GARCH in mean Term is theta\n"
    printf "----------------------------------------------------------------\n"
  endif
  printf "Presample variance: backcast (parameter = %.1f)\n",backcast
  # obtaining intiatial values from OLS and printing intial values
  # -----------ols ty const
  # -----------printf "islist()=%d, nelem()=%d ===>\n",islist(indepvar) ,nelem(indepvar)
  if nelem(indepvar) > 0
    ols y indepvar --quiet
    # to keep the sample in use
    genr dum_original = $sample
    /*
    garch GARCH ARCH ; y indepvar
    if option=1
      series tInMean=$h^0.5
    elif option=2
      series tInMean=$h
    elif option=3
      series tInMean=log($h)
    endif
    */
    # ----- obtaining initial value for theta (nelem>0)
    if option > 0
      #garch GARCH ARCH ; y indepvar
      ols y indepvar --quiet
      if option=1
        series tInMean=($uhat^2)^0.5
      elif option=2
        series tInMean=($uhat^2)
      elif option=3
        series tInMean=log(($uhat^2))
      endif
      ols y indepvar --quiet
      #series tInMean=($uhat^2)^0.5
      ols y indepvar tInMean --quiet
      #ols y tInMean --quiet
      scalar theta= $coeff(tInMean)
    endif
    if ShowInit = 1  ### --- printing intial values
      printf "Initial Values:\n"
      if option >0
        printf "theta=%.6f, ",theta
      endif
    endif
    ols y indepvar --quiet
    if is_const = 1
      scalar b0=$coeff(const)
      if ShowInit = 1  ### --- printing intial values
        printf "b0=%.6f, ",b0
      endif
      matrix B=$coeff
      k=$ncoeff-1
      loop j=1..k --quiet
        scalar b$j = B[j+1]
        if ShowInit = 1  ### --- printing intial values
          printf "b%d=%.6f, ",j,b$j
        endif
      endloop
    else
      matrix B=$coeff
      k=$ncoeff
      loop j=1..k --quiet
        scalar b$j = B[j]
        if ShowInit = 1  ### --- printing intial values
          printf "b%d=%.6f, ",j,b$j
        endif
      endloop
    endif
  else   # ======================--------if nelem = 0
    ols y const --quiet
    # to keep the sample in use
    genr dum_original = $sample
    # ----- obtaining initial value for theta (nelem=0)
    if option > 0
      #garch GARCH ARCH ; y indepvar
      if option=1
        series tInMean=($uhat^2)^0.5
      elif option=2
        series tInMean=($uhat^2)
      elif option=3
        series tInMean=log(($uhat^2))
      endif
      ols y tInMean --quiet
      scalar theta= $coeff(tInMean)
    endif
    if ShowInit = 1  ### --- printing intial values
      printf "Initial Values:\n"
      if option >0
        printf "theta=%.6f, ",theta
      endif
    endif
  endif
  if ShowInit = 1  ### --- printing intial values
    printf "omega=%.6f, ",omega
    loop j=1..ARCH  --quiet
      printf "alpha%d=%.6f, ",j, alpha$j
    endloop
    if gjr_order>0
      loop j=1..gjr_order  --quiet
        printf "gamma%d=%.6f, ",j, gamma$j
      endloop
    endif
    if GARCH>0
      loop j=1..GARCH  --quiet
        printf "beta%d=%.6f, ",j, beta$j
      endloop
    endif
  endif
  string tAllParams = tParam ~ " " ~ arch_param
  # --- delete ---> printf "%s\n", tParam
  printf "\n-------    mean eq & variance eq in this GARCH model --------\n"
  printf "   %s\n",m_eq
  printf "   %s\n",v_eq
  printf "================================================================\n"
  scalar presample=0 ####y[1]/backcast  #see Eviews 6 Users guide, p.320 for algorithm
  loop j=2..100  --quiet
    presample = presample + backcast^(j-2)*y[j]^2
  endloop
  mle ll = -0.5*(log(2*pi)+log(h) + (e^2)/h)
    series h = backcast^($nobs)*var(y) + (1-backcast)*presample
    #####series h = backcast^($nobs)*var(y) + (1-backcast)*(y[2]^2+backcast*y[3]^2+backcast^2*y[4]^2+backcast^3*y[5]^2+backcast^4*y[6]^2+backcast^5*y[7]^2)
    #------------------------series e = y - theta*h^0.5
    series @m_eq
    #------------------------series e= y - b0 -b1*X1-b2*X2
    # ---> to be deleted -----> series h = omega + alpha*(e(-1))^2 + beta*h(-1)
    series @v_eq
    params @tAllParams
  end mle
  genr dum_in_mle = $sample
  ##### printf ">>>>>>>>>>>>>>>>>>sample size in MLE, nobs=%d, T=%d\n",$nobs, $T
  # 定義計算 estimated residuals 要取幾個落後期
  scalar start = $nobs-$T+1
  # --- to be deleted ---> printf "NOBS=%d  T=%d\n",$nobs,$T
  # ---- generating standardized residual and ht
  # ---- diagnosis of standardized residuals
  /*
  if LB_Q>0 && LB_Q2>0
    smpl full
    series h = backcast^($nobs)*var(y) + (1-backcast)*presample
    series e=0
    if option>0
      End=$T-1
      loop for j=1..End
        smpl j j
        genr @m_eq
        smpl +1 +1
        genr @v_eq
      endloop
      genr @m_eq
      smpl full
    else
      series @m_eq
      series @v_eq
    endif
    series stz_u=e/h^0.5
    series stz_u2 = stz_u^2
    corrgm stz_u  LB_Q  --quiet
    corrgm stz_u2 LB_Q2  --quiet
  endif
  */
  # ---- generating standardized residual (=e/h^0.5) and ht (=h)
  series h = backcast^($nobs)*var(y) + (1-backcast)*presample
  #series e=0
  if option>0
    End=$T-1
    loop for j=start..End --quiet
      smpl j j
      genr @m_eq
      smpl +1 +1
      genr @v_eq
    endloop
    genr @m_eq
    # 回復為原來的樣本
    smpl dum_original --dummy --replace
  else
    series @m_eq
    series @v_eq
  endif
  if isstring(res_name) =0
    sprintf res_name "stz_u" # default name for e(t)
  endif
  if isstring(ht_name) =0
    sprintf ht_name "h"   # default name for h(t)
  endif
  # 回復為原來的樣本
  smpl dum_original --dummy --replace
  series  @res_name =e/h^0.5
  series @ht_name=h
  if LB_Q >0
    corrgm @res_name  LB_Q  --quiet
  endif
  if LB_Q2>0
    series stz_u2=@res_name^2
    corrgm stz_u2 LB_Q2  --quiet
  endif
  if save_resid=1
    list retlist= @res_name @ht_name
    return retlist
  else
    list retlist = const
    return retlist
  endif
end function

沒有留言: