eviews中的蒙特卡洛模拟程序Word格式.docx
- 文档编号:14327627
- 上传时间:2022-10-22
- 格式:DOCX
- 页数:15
- 大小:112.58KB
eviews中的蒙特卡洛模拟程序Word格式.docx
《eviews中的蒙特卡洛模拟程序Word格式.docx》由会员分享,可在线阅读,更多相关《eviews中的蒙特卡洛模拟程序Word格式.docx(15页珍藏版)》请在冰豆网上搜索。
F(x)≥y}.0≤y≤1.质地均匀的骰子各点数出现的频率的分布函数是
F(x)=p(x≥x)=(i=1)/6,i-1≤x<i,i=1,2,…,7
可求得
F-1(y)=inf{x:
F(x)≥y}.0≤y≤1=i-1,(i-1)/6≤y<i/6,i=1,…,6
因而,可先由产生均匀分布随机数的函数@runif(0,1)抽取y值,再来计算F-1(y)值即可。
程序实现:
worku11000
smpl11000
seriesx
seriesy
seriesa1
seriesa2
seriesa3
seriesa4
seriesa5
seriesa6
i=1to1000
a1(!
i)=1/6
a2(!
i)=2/6
a3(!
i)=3/6
a4(!
i)=4/6
a5(!
i)=5/6
a6(!
i)=1
i)=@runif(0,1)
ifx(!
i)<
i)theny(!
elseifx(!
i)>
=a1(!
i)andx(!
i)=2
=a2(!
i)=3
=a3(!
i)=4
=a4(!
i)=5
=a5(!
i)=6
elsey(!
i)=7
endif
y.hist
1.通过已知总体模型得到多组样本数据,进行多次回归,验证回归结果的特征、性质
最小二乘法的无偏性
worku110
vector(10)v1
v1.fill80,100,120,140,160,180,200,220,240,260
mtos(v1,x)
!
b1=25
b2=0.5
matrix(100,2)f
k=1to100
seriesu=3*nrnd
seriesy=!
b1+!
b2*x+u
equationeq.lsy=c
(1)+c
(2)*x
f(!
k,1)=c
(1)
k,2)=c
(2)
showf
expand1100
smpl1100
mtos(f,gr)
freezeser01.qqplot
freezeser01.hist
freezeser02.qqplot
freezeser02.hist
matrix(1,2)m
m(1,1)=@mean(ser01)
m(1,2)=@mean(ser02)
showm
蒙特卡洛模拟程序:
(最终调试成功)
'
storemontecarleresultsinaseries
checked4/1/2004
setworktonumberofmontecarlereplications
wfcreatemcarleu1100
createdataseriesforx
note:
xisfixedinrepeatedsamples
onlyfirst10observationsareused(remaining90obsmissing)
x.fill80,100,120,140,160,180,200,220,240,260
settrueparametervalues
beta1=2.5
beta2=0.5
setseedforrandomnumbergenerator
rndseed123456
assignnumberofreplicationstoacontrolvariable
reps=100
beginloop
I=1to!
reps
'
setsampletoestimationsample
smpl110
simulateydata(onlyfor10obs)
seriesy=!
beta1+!
beta2*x+3*nrnd
regressyonaconstantandx
Equationeq1.lsycx
setsampletooneobservation
smpl!
I!
i
andstoreeachcoefficientestimateinaseries
seriesb1=eq1.@coefs
(1)
seriesb2=eq1.@coefs
(2)
endofloop
setsampletofullsample
showkerneldensityeatimateforeachcoef
freeze(gra1)b1.distplotkernel
drowverticaldashlineattrueparametervalue
gra1.draw(dashline,bottom,rgb(156,156,156))!
beta1
showgra1
freeze(gra2)b2.distplotkernel
drawverticaldashlineattrueparametervalue
gra2.draw(dashline,bottom,rgb(156,156,156))!
beta2
showgra2
一元回归参数的分布:
Subroutinemoni(scalarn,scalarsum,scalarparam1,scalarparam2,scalartype)
For!
m=1ton
X(!
m)=@rnd*100
Next
n=1tosum
Iftype=0then
U(!
m)=@nrnd
Endif
Iftype=1then
If@rnd<
0.5then
m)=@rnd
Else
m)=@rnd*(-1)
Iftype=2then
U
(1)=@nrnd
m=2ton
m)=u(!
m-1)+@nrnd
Iftype=3then
0.5then
m)=@nrnd*2
Y(!
m)=param1+param2*x(!
m)+u(!
m)
Equationeq.lsycx
B1(!
n)=eq.@coefs
(1)
B2(!
n)=eq.@coefs
(2)
Endsub
Worku110000
Seriesb1
Seriesb2
Seriesx
Seriesy
Seriesu
Callmoni(100,10000,20,0.8,3)
B1.hist
B2.hist
生成季度虚拟变量的程序:
wfcreatedumtestq19701990
%start="
1972:
1"
%end="
1979:
4"
i=@dtoo(%start)to@dtoo(%end)
%obsstr=@otod(!
i)
if(@mid(%obsstr,5,1)="
:
"
)then
%name="
d_"
+@left(%obsstr,4)+"
_"
+@mid(%obsstr,6)
else
+%obsstr
endif
smpl@all
series{%name}=0
smpl{%obsstr}{%obsstr}
series{%name}=1
下面这个执行不了:
n=10000
wfcreatecaou1!
n
matrix(!
n,18)m
groupg
for%1r0b0t0dw0r20f0r1b1t1dw1r21f1r2b2t2dw2r22f2
series{%1}=0
g.add{%1}
k=1to!
smpl1122
for%1y0x0y1x1y2x2
series{%1}=@rnorm
smpl2122
x1=x1(-1)+@rnorm
y1=y1(-1)+@rnorm
x2=2*x2(-1)-x2(-2)+@rnorm
y2=2*y2(-1)-y2(-2)+@rnorm
for%1%2%31y0x07y1x113y2x2
m(!
k,{%1})=@cor({%2},{%3})
equationeq.ls{%2}c{%3}
k,{%1}+1)=eq.c
(2)
k,{%1}+2)=eq.@tstats
(2)
k,{%1}+3)=eq.@dw
k,{%1}+4)=eq.@r2
k,{%1}+5)=eq.@f
smpl1!
T
mtos(m,g)
for%1t0t1t2
seriescao_{%1}=@abs({%1})>
=2
freeze(statby_{%1}){%1}.statby(nomean,nostd)cao_{%1}
freeze(hist_{%1}){%1}.h
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- eviews 中的 蒙特卡洛 模拟 程序