一変量のAGARCH type2プロセスのパラメータ推定

Fortranによるサンプルソースコード : 使用ルーチン名:g13fcf

ホーム > 製品 > nAG数値計算ライブラリ > nAG Fortranライブラリ > サンプルソースコード集 > 一変量のAGARCH type2プロセスのパラメータ推定

Keyword: 一変量時系列, GARCH, 非対称, パラメータ推定

概要

本サンプルは一変量のAGARCH type2プロセスのパラメータ推定を行うFortranによるサンプルプログラムです。 本サンプルでは以下に示される時系列を分析対象とし下記の式で表されるAGARCH type2プロセスのパラメータ推定を行います。

GARCH IIプロセスのデータ 

GARCH IIプロセスのデータ 

※本サンプルはnAG Fortranライブラリに含まれるルーチン g13fcf() のExampleコードです。本サンプル及びルーチンの詳細情報は g13fcf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで

入力データ

(本ルーチンの詳細はg13fcf のマニュアルページを参照)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

このデータをダウンロード
 G13FCF Example Program Data
100 1 2                                      :: NUM,MN,NREG
 8.87  9.82  9.02  9.24  9.46 
 8.93 10.20  9.19  8.27  9.08 
 9.11  9.95  8.11  9.13  9.49 
10.08  9.74 10.72  8.94 10.10 
10.19  9.68  9.09  9.88  9.55 
 9.52  8.45  9.14  9.52  9.27 
 9.50  9.93  9.86  9.16  9.00 
 9.28  9.83  9.86  9.55 10.12 
 8.47 10.10  8.70  9.44  9.10 
 7.54  8.08  9.47 12.32 10.75 
11.66 10.59 10.93 10.21  9.39 
 9.74 10.91  9.46 10.32 11.00 
 9.47  8.14  9.88 11.15 11.21 
10.06  9.50  9.56  9.23 10.88 
10.93  9.89  9.89  9.37 10.44 
 9.52  9.92  7.44 10.36  7.73 
10.53  9.38 11.14 10.73 10.02 
10.36 10.18  9.52  9.59 12.73 
 9.38  8.69  9.78 11.85  9.23 
10.13 10.77  8.68 10.39  9.74                :: End of Y
 0.12  2.40      0.12  2.40 
 0.13  2.40      0.14  2.40 
 0.14  2.40      0.15  2.40 
 0.16  2.40      0.16  2.40 
 0.17  2.40      0.18  2.41 
 0.19  2.41      0.19  2.41 
 0.20  2.41      0.21  2.41 
 0.21  2.41      0.22  2.41 
 0.23  2.41      0.23  2.41 
 0.24  2.41      0.25  2.42 
 0.25  2.42      0.26  2.42 
 0.26  2.42      0.27  2.42 
 0.28  2.42      0.28  2.42 
 0.29  2.42      0.30  2.42 
 0.30  2.42      0.31  2.43 
 0.32  2.43      0.32  2.43 
 0.33  2.43      0.33  2.43 
 0.34  2.43      0.35  2.43 
 0.35  2.43      0.36  2.43 
 0.37  2.43      0.37  2.44 
 0.38  2.44      0.38  2.44 
 0.39  2.44      0.39  2.44 
 0.40  2.44      0.41  2.44 
 0.41  2.44      0.42  2.44 
 0.42  2.44      0.43  2.45 
 0.43  2.45      0.44  2.45 
 0.45  2.45      0.45  2.45 
 0.46  2.45      0.46  2.45 
 0.47  2.45      0.47  2.45 
 0.48  2.45      0.48  2.46 
 0.49  2.46      0.49  2.46 
 0.50  2.46      0.50  2.46 
 0.51  2.46      0.51  2.46 
 0.52  2.46      0.52  2.46 
 0.53  2.46      0.53  2.47 
 0.54  2.47      0.54  2.47 
 0.54  2.47      0.55  2.47 
 0.55  2.47      0.56  2.47 
 0.56  2.47      0.57  2.47 
 0.57  2.47      0.57  2.48 
 0.58  2.48      0.58  2.48 
 0.59  2.48      0.59  2.48 
 0.59  2.48      0.60  2.48 
 0.60  2.48      0.61  2.48 
 0.61  2.48      0.61  2.49 
 0.62  2.49      0.62  2.49 
 0.62  2.49      0.63  2.49 
 0.63  2.49      0.63  2.49 
 0.64  2.49      0.64  2.49 
 0.64  2.49      0.64  2.50                  :: End of X
 'T' 1 1                                     :: DIST,IP,IQ
 T T 200 0.00001                             :: COPTS,MAXIT,TOL
 0.05                                        :: ALPHA_0
 0.05                                        :: ALPHA_I
 0.40                                        :: BETA_I
-0.20                                        :: GAMMA
 2.60                                        :: DF
 1.50                                        :: MEAN
 4                                           :: NT

  • 1行目はタイトル行で読み飛ばされます。
  • 2行目に時系列のデータの数(num=100)、切片がモデルに含まれかどうか(mn=1:含まれる)、 回帰係数の数(nreg=2)を指定しています。
  • 3~22行目に時系列の観測値(y)を指定しています。
  • 23~72行目に時間依存の外因性変数の要素(x)を指定しています。
  • 73行目に分布の種類(dist='T')、係数βの数(ip=1)、係数αの数(iq=1)を指定しています。
  • 74行目に定常状態が強制されるかどうか(copts(1)=T:強制される)、ルーチンが初期のパラメータ推定を与えるかどうか(copsts(2)=T:与える)、最大反復数(maxit=200)、最適化ルーチンで使用される許容値(tol=0.00001)を指定しています。
  • 75行目に係数α0(alpha_0)を指定しています。
  • 76行目に係数α1(alpha_i)を指定しています。
  • 77行目に係数β1(beta_i)を指定しています。
  • 78行目に非対称パラメータγ(gamma)を指定しています。
  • 79行目に自由度(df)を指定しています。
  • 80行目に切片(mean)を指定しています。
  • 81行目に予測期間(nt)を指定しています。

出力結果

(本ルーチンの詳細はg13fcf のマニュアルページを参照)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

この出力例をダウンロード
 G13FCF Example Program Results

                Parameter        Standard
                estimates         errors
 Alpha0             6.82            1.68
 Alpha1             0.00            1.00

  Beta1             0.00            3.17

  Gamma            -0.36            1.01

     DF             2.10            0.33

     B0           -25.14            4.80
     B1            -0.95            0.90
     B2            14.41            2.08


 Volatility forecast =         6.82


  • 5行目に係数α0のパラメータ推定値、標準誤差が出力されています。
  • 6行目に係数α1のパラメータ推定値、標準誤差が出力されています。
  • 8行目に係数β1のパラメータ推定値、標準誤差が出力されています。
  • 10行目に非対称パラメータγのパラメータ推定値、標準誤差が出力されています。
  • 12行目に自由度のパラメータ推定値、標準誤差が出力されています。
  • 14行目に切片のパラメータ推定値、標準誤差が出力されています。
  • 15~16行目に線形回帰係数のパラメータ推定値、標準誤差が出力されています。
  • 19行目には4step先のボラティリティ予測値が出力されています。

ソースコード

(本ルーチンの詳細はg13fcf のマニュアルページを参照)

※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

このソースコードをダウンロード
    PROGRAM g13fcfe

!      G13FCF Example Program Text

!      Mark 23 Release. nAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13fcf, g13fdf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: gamma, hp, lgf, tol
       INTEGER                         :: i, ifail, ip, iq, l, ldcovr, ldx,    &
                                          lwork, maxit, mn, npar, nreg, nt,    &
                                          num, pgamma, tdx
       LOGICAL                         :: tdist
       CHARACTER (1)                   :: dist
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: covr(:,:), et(:), fht(:), ht(:),     &
                                          sc(:), se(:), theta(:), work(:),     &
                                          x(:,:), yt(:)
       LOGICAL                         :: copts(2)
!      .. Intrinsic Functions ..
       INTRINSIC                          max
!      .. Executable Statements ..
       WRITE (nout,*) 'G13FCF Example Program Results'
       WRITE (nout,*)

!      Skip heading in data file
       READ (nin,*)

!      Read in the problem size
       READ (nin,*) num, mn, nreg

       ldx = num
       tdx = max(nreg+mn,1)
       ALLOCATE (yt(num),x(ldx,tdx))

!      Read in the series
       READ (nin,*) yt(1:num)

!      Read in the exogenous variables
       IF (nreg>0) THEN
          READ (nin,*) (x(i,1:nreg),i=1,num)
       END IF

!      Read in details of the model to fit
       READ (nin,*) dist, ip, iq

!      Read in control parameters
       READ (nin,*) copts(1:2), maxit, tol

!      Calculate NPAR
       npar = 2 + iq + ip + mn + nreg
       IF (dist=='T' .OR. dist=='t') THEN
          npar = npar + 1
          tdist = .TRUE.
       ELSE
          tdist = .FALSE.
       END IF

       ldcovr = npar
       lwork = (nreg+3)*num + npar + 403
       ALLOCATE (theta(npar),se(npar),sc(npar),covr(ldcovr,npar),et(num), &
          ht(num),work(lwork))

!      Read in initial values
!      alpha_0
       READ (nin,*) theta(1)
       l = 2
!      alpha_i       
       IF (iq>0) THEN
          READ (nin,*) theta(l:(l+iq-1))
          l = l + iq
       END IF
!      beta_i
       IF (ip>0) THEN
          READ (nin,*) theta(l:(l+ip-1))
          l = l + ip
       END IF
!      gamma
       READ (nin,*) theta(l)
       pgamma = l
       l = l + 1
!      degrees of freedom
       IF (tdist) THEN
          READ (nin,*) theta(l)
          l = l + 1
       END IF
!      mean
       IF (mn==1) THEN
          READ (nin,*) theta(l)
          l = l + 1
       END IF
!      Regression parameters and pre-observed conditional variance
       IF ( .NOT. copts(2)) THEN
          READ (nin,*) theta(l:(l+nreg-1))
          READ (nin,*) hp
       END IF

!      Fit the GARCH model
       ifail = 0
       CALL g13fcf(dist,yt,x,ldx,num,ip,iq,nreg,mn,npar,theta,se,sc,covr, &
          ldcovr,hp,et,ht,lgf,copts,maxit,tol,work,lwork,ifail)

!      Read in forecast horizon
       READ (nin,*) nt

       ALLOCATE (fht(nt))

!      Extract the estimate of the asymmetry parameter from theta
       gamma = theta(pgamma)

!      Calculate the volatility forecast
       ifail = 0
       CALL g13fdf(num,nt,ip,iq,theta,gamma,fht,ht,et,ifail)

!      Output the results
       WRITE (nout,*) '               Parameter        Standard'
       WRITE (nout,*) '               estimates         errors'
!      Output the coefficient alpha_0
       WRITE (nout,99999) 'Alpha', 0, theta(1), se(1)
       l = 2
!      Output the coefficients alpha_i
       IF (iq>0) THEN
          WRITE (nout,99999) ('Alpha',i-1,theta(i),se(i),i=l,l+iq-1)
          l = l + iq
       END IF
       WRITE (nout,*)
!      Output the coefficients beta_j
       IF (ip>0) THEN
          WRITE (nout,99999) (' Beta',i-l+1,theta(i),se(i),i=l,l+ip-1)
          l = l + ip
          WRITE (nout,*)
       END IF
!      Output the estimated asymmetry parameter, gamma
       WRITE (nout,99998) ' Gamma', theta(l), se(l)
       WRITE (nout,*)
       l = l + 1
!      Output the estimated degrees of freedom, df
       IF (dist=='T') THEN
          WRITE (nout,99998) '    DF', theta(l), se(l)
          WRITE (nout,*)
          l = l + 1
       END IF
!      Output the estimated mean term, b_0
       IF (mn==1) THEN
          WRITE (nout,99999) '    B', 0, theta(l), se(l)
          l = l + 1
       END IF
!      Output the estimated linear regression coefficients, b_i
       IF (nreg>0) THEN
          WRITE (nout,99999) ('    B',i-l+1,theta(i),se(i),i=l,l+nreg-1)
       END IF
       WRITE (nout,*)

!      Display the volatility forecast
       WRITE (nout,*)
       WRITE (nout,99997) 'Volatility forecast = ', fht(nt)
       WRITE (nout,*)

99999  FORMAT (1X,A,I0,1X,2F16.2)
99998  FORMAT (1X,A,1X,2F16.2)
99997  FORMAT (1X,A,F12.2)
    END PROGRAM g13fcfe


関連情報
© 日本ニューメリカルアルゴリズムズグループ株式会社 2025
Privacy Policy  /  Trademarks