財務計量期末報告
蒙地卡羅模擬
授課老師:楊奕農 老師
班 級:國貿碩1
學 生:9792011 粘豪承
9792024 鍾安民
Q:
一般OLS檢定,測試AIC、BIC、HQC及z-test之lag選擇評估,
利用蒙地卡羅模型,假設AR(q)未知,對於不同的b係數是否有影響。
A:
假設迴歸模型為
y = 0.02+ 0.2*x + u
u = 0.5*u(-1) – 0.2*u(-2) + 0.3*u(-3) + e
e = normal()
令q=3時,最大落後期為6期,gretl程式如下
nulldata 100
set seed 89675430
scalar rho1 = 0.5
scalar rho2 = -0.2
scalar rho3 = 0.3
scalar a = 0.02
scalar b = 0.2
series x = 10*uniform()
scalar maxlag = 6
scalar zval, pz, zlag, pzstar
scalar replics = 1000
matrix se = zeros(replics, 4)
loop j=1..replics -q
series u = 0
series e = normal()
u = rho1*u(-1) + rho2*u(-2) + rho3*u(-3) + e
series y = 0
series y = a + b*x + u
dy = diff(y)
lags maxlag ; dy
list dyL = dy_*
matrix IC = zeros(3, maxlag+1)
zlag = 0
loop for (i=maxlag; i>=0; i--) -q
ols y const x dyL -q
IC[1,i+1] = $aic
IC[2,i+1] = $bic
IC[3,i+1] = $hqc
if (i > 0 && zlag == 0)
# we haven't yet found a significant "final lag"
zval = abs($coeff(dy_$i)/$stderr(dy_$i))
pz = 2 * pvalue(z, zval)
# printf "pz = %g\n", pz
if (pz <= 0.10)
zlag = i
pzstar = pz
endif
endif
if i > 0
# discard the last lag
dyL -= dy_$i
endif
endloop
matrix iCmin = iminr(IC) - 1
se[j,1:3] = iCmin'
se[j,4] = zlag
endloop
# Uncomment to print the full results
# print lsel
matrix stats = meanc(se) | sdc(se)
colnames(stats, "AIC BIC HQC z-test")
printf "\n%d replications, test down from %d lags\n", replics, maxlag
print "Lag order selected: mean on row 1, s.d. on row 2"
printf "\n%8.2f\n", stats
AIC BIC HQC z-test
5.95 3.45 5.30 3.65
0.25 2.10 1.24 2.00
由上表得知,模擬結果BIC和z-test為選擇lag為3期比較正較。
以下為檢定不同的b係數是否有影響?
Gretl程式如下:
nulldata 100
seed 547 ---> with this to fixe and repeat the random number generated
set echo off
series x = 10 * uniform()
rho1=0.5
rho2=-0.2
rho3=0.3
a=0.02
b=0.2
err_std=1
# open a "progressive" loop, to be repeated 100 times
loop 1000 --progressive --quiet
smpl full
series u = 0
series e = normal()
u = rho1*u(-1) + rho2*u(-2) + rho3*u(-3)+ e
# construct the dependent variable
series y = a + b*x + u
dy = diff(y)
lags 6 ; dy
list dyL = dy_*
# run gretl ols y const x
ols y const x dyL # exact ML
# grab the coefficient estimates
genr b_ = $coeff(x)
# 假設H0 為真
# H0: b_ = b
genr t_b_=($coeff(x)-b)/$stderr(x)
# calculate p-vlaue of correct H0
if t_b_>0
genr pv_b_=2*pvalue(t,$df,t_b_)
else
genr pv_b_=2*(1-pvalue(t,$df,t_b_))
endif
if pv_b_<=0.05
genr rej_b_005=1
else
genr rej_b_005=0
endif
# 假設H0 為偽
# H0: b_ = 0
genr t_b__=($coeff(x)-0)/$stderr(x)
# calculate p-vlaue of wrong H0
if t_b__>0
genr pv_b__=2*pvalue(t,$df,t_b__)
else
genr pv_b__=2*(1-pvalue(t,$df,t_b__))
endif
if pv_b__<=0.05
genr rej_b__005=1
else
genr rej_b__005=0
endif
print b_ rej_b_005 rej_b__005
# save the results to a file
store coeffs1.gdt t_b_ pv_b_ t_b__ pv_b__
endloop
Generated scalar a = 0.02
Generated scalar b = 0.2
Statistics for 1000 repetitions
Variable mean std. dev.
b_ 0.195903 0.0402690
rej_b_005 0.0580000 0.233743
rej_b__005 0.995000 0.0705337
令 H0:b為0.2
H1:b不為0.2
在95%顯著水準之下,b_平均數為0.195903;b_標準差為0.0402690,
臨界值為Z0.025=1.96,利用公式求得Z=(0.195903-0.2)/0.0402690=-0.10174,
無法拒絕虛無假設,表示沒有充分證實b 0.2。故我們設立b值為0.2成立。
Generated scalar a = 0.02
Generated scalar b = 0.5
Statistics for 1000 repetitions
Variable mean std. dev.
b_ 0.493902 0.0421504
rej_b_005 0.0560000 0.229922
rej_b__005 1.00000 0.000000
令 H0:b為0.5
H1:b不為0.5
在95%顯著水準之下,b_平均數為0.493902;b_標準差為0.0421504,
臨界值為Z0.025=1.96,利用公式求得Z=(0.493902-0.5)/0.0421504=-0.14467,
無法拒絕虛無假設,表示沒有充分證實b 0.5。故我們若設立b值為0.5成立。
總結
利用一般OLS檢定,設立落後期為3期,證實BIC與z-test為選擇lag期比較正確,
再者,對於不同b係數是否有影響,我們證實不同係數是不會有影響。