




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
模拟程序案例例 1,在做抛掷一枚质地均匀的硬币的试验中发“正面朝上”的事件(用 1 表示)和“正面朝下”的事件 A(用 0 表示)的情况。历史上一些学者得到的具体试验结果如下:现在需要利用 eviews 来模拟上述三位学者的实验。算法分析:上述三学者的实验均为二项分布的实验,可以直接利用 eviews 产生二项分布随机数的函数rbinom(n,p).编程如下:workfile binom u 1 2048series resultfor !i=0 to 1smpl 1 2048series xx(1)=0for !cou=1 to 2048x(!cou)=rbinom(!i,0.5)nextnextx.hist例 2(投掷骰子)(1)投掷一颗质地均匀的骰子,令 X 表示其出现的点数,分析各点数出现的频率的稳定性及变化规律;(2)利用统计的方法,根据“频率的稳定性”规律求投掷一枚质地不均匀的骰子出现某点数的概率;(3)演示随机变量 X 的数学期望的统计意义。算法分析:根据逆变换法产生来自分布函数F(x)的随机数,就要求出 F-1(y),其中 F-1(y)infx:F(x)y.0y1.质地均匀的骰子各点数出现的频率的分布函数是F(x)=p(xx)=(i=1)/6,i-1xi,i=1,2,7可求得F-1(y)=infx:F(x)y.0y1=i-1,(i-1)/6yi/6,i=1,6因而,可先由产生均匀分布随机数的函数 runif(0,1)抽取 y 值,再来计算 F-1(y)值即可。程序实现:workfile binom u 1 1000smpl 1 1000series x series yseries a1series a2series a3series a4series a5series a6for !i=1 to 1000a1(!i)=1/6a2(!i)=2/6a3(!i)=3/6a4(!i)=4/6a5(!i)=5/6a6(!i)=1x(!i)=runif(0,1)if x(!i)=a1(!i) and x(!i)=a2(!i) and x(!i)=a3(!i) and x(!i)=a4(!i) and x(!i)=a5(!i) and x(!i)a6(!i) then y(!i)=6else y(!i)=7endifendifendifendifendifendifnexty.hist1.通过已知总体模型得到多组样本数据,进行多次回归,验证回归结果的特征、性质最小二乘法的无偏性workfile mc u 1 10vector(10) v1v1.fill 80, 100,120,140,160,180,200,220,240,260mtos(v1,x)!b1=25!b2=0.5matrix(100,2) ffor !k=1 to 100series u=3*nrndseries y=!b1+!b2*x+uequation eq.ls y=c(1)+c(2)* xf(!k,1)=c(1)f(!k,2)=c(2)nextshow fexpand 1 100smpl 1 100mtos(f,gr)freeze ser01.qqplotfreeze ser01.histfreeze ser02.qqplotfreeze ser02.histmatrix(1,2) mm(1,1)=mean(ser01)m(1,2)=mean(ser02)show m蒙特卡洛模拟程序:(最终调试成功)store monte carle results in a serieschecked 4/1/2004set workfile range to number of monte carle replicationswfcreate mcarle u 1 100create data series for xnote: x is fixed in repeated samplesonly first 10 observations are used (remaining 90 obs missing)series x x.fill 80,100,120,140,160,180,200,220,240,260set true parameter values!beta1=2.5!beta2=0.5set seed for random number generatorrndseed 123456assign number of replications to a control variable!reps=100begin loopfor !I=1 to !reps set sample to estimation sample smpl 1 10 simulate y data (only for 10 obs) series y=!beta1+!beta2*x+3*nrnd regress y on a constant and x Equation eq1.ls y c xset sample to one observationsmpl !I !iand store each coefficient estimate in a series series b1=eq1.coefs(1)series b2=eq1.coefs(2)nextend of loopset sample to full samplesmpl 1 100show kernel density eatimate for each coeffreeze(gra1) b1.distplot kerneldrow vertical dashline at true parameter valuegra1.draw(dashline,bottom,rgb(156,156,156) !beta1show gra1freeze(gra2) b2.distplot kerneldraw vertical dashline at true parameter valuegra2.draw(dashline,bottom,rgb(156,156,156) !beta2show gra2一元回归参数的分布:Subroutine moni (scalar n, scalar sum, scalar param1, scalar param2, scalar type)For !m=1 to nX(!m)=rnd*100NextFor !n=1 to sumIf type=0 thenFor !m=1 to nU(!m)=nrndNextEndifIf type=1 thenFor !m=1 to nIf rnd0.5 thenU(!m)=rndElseU(!m)=rnd*(-1)EndifNextEndifIf type=2 thenU(1)=nrndFor !m=2 to nU(!m)=u(!m-1)+nrndNextEndifIf type=3 thenFor !m=1 to nIf rnd=2freeze(statby_%1) %1.statby(nomean,nostd)cao_%1nextfor %1 r0 b0 t0 dw0 r20 f0 r1 b1 t1 dw1 r21 f1 r2 b2 t2 dw2 r22 f2freeze(hist_%1) %1.histnext伪回归相关系数模拟(不行)workfile corr u 1 500series resultfor !i=1 to 500smpl 1 100series x=nrndseries y=nrndseries xxseries yyscalar sum1=0scalar sum2=0for !counter=1 to 100sum1=sum1+x(!counter)sum2=sum2+y(!counter)xx(!counter)=sum1yy(!counter)=sum2nextnextscalar r=cor(xx,yy)result(!i)=r时变贝塔系数的模拟(执行不了): BETA.PRG (3/7/2007) Time varying beta demonstrates several ways to obtain beta between assets 1) constant beta 2) rolling beta by regression/moving cov/var 3) using state space 4) using multivariate ARCH Checked 3/20/2007change path to program path%path = runpathcd %path load workfileload fx.wf1 dependent variables of series must be continuoussmpl allseries y1 = pch(index)series y2 = pch(jy)- calculate the constant beta using OLS-smpl 1990 lastequation constant_beta.ls y2 c y1series beta_const=c(2)- calculating time varying beta with rolling regression for a bi-variate case can use moving cov/var instead of OLS regression-!ssize = 200series beta_roll=movcov(y1,y2,!ssize)/movvar(y1,!ssize) code for running a rolling regression: commented out right now!length = obs(y1)equation roll_beta.ls y2 c y1show roll_betafor !i = 1 to !length-!ssize+1 smpl first+!i-1 first+!i+!ssize-2 equation roll_beta.ls y2 c y1 smpl first+!i+!ssize-2 first+!i+!ssize-2 beta_roll = roll_beta.coefs(2)next- calculate beta with State Space via a time-varying coefficient for Y1-smpl 1990 lastsspace ssbetassbeta.append y2=c(1)+sv1*y1+var=exp(c(2)ssbeta.append state sv1 = sv1(-1)ssbeta.mlssbeta.makestates beta_*rename beta_sv1 beta_ss- calculate beta with system ARCH by estimating the covariance and variance of the two series using Multivariate ARCH-system arbetaarbeta.append y1 = c(1) arbeta.append y2 = c(2)arbeta.arch Diagvech c(indef) arch(1,indef) garch(1,indef)arbeta.makegarch(name=arch)series beta_arch = arch01_02/arch01- display the different betas-group betas_ls_roll beta_const beta_rollgroup betas_roll_ss_arch beta_roll beta_ss beta_archshow betas_ls_roll.lineshow betas_roll_ss_arch.line在生成服从某种分布(标准正态分布白噪声序列)的随机序列的基础上 生成各种ARIMA序列:AR(1)、MA(1)、ARMA(1,1)、ARIMA(1,1,1)n Workfile random2 u 1 1000n Series u=nrnd n U(1)=0n Series x1n X1(1)=0n Series x2n X2(1)=0n Series x3n X3(1)=0n Series x4 n X4(1)=0n Smpl 2 1000n x1=0.8*x1(-1)+un X2=u+0.8*u(-1)n X3=0.8*x3(-1)+u+0.8*u(-1)n X4=x4(-1)+x3n Smpl al
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 拱门建筑改造方案设计(3篇)
- 网红带货课件
- 有关兴趣的课件
- 学校寒假学生安全管理方案
- 城墙建筑重构方案设计(3篇)
- 2025年口腔医学科口腔种植术后护理技巧考核试卷答案及解析
- 用户习惯学习算法-洞察及研究
- 建筑工地安全措施执行方案
- 仿宋建筑寺庙规划方案设计(3篇)
- 月子会所厨师长培训
- 2025 年西安市一年级语文秋季开学摸底考 - 基础卷及答案(人教版)
- 2025年秋新教科版三年级上册科学全册教案教学设计(新教材)
- 2025年云南省中考语文真题(附答案解析)
- 河南省洛阳市宜阳县2024-2025学年七年级下学期期末考试数学试卷(含答案)
- 第3讲 文言文内容概述题-据文比对判正误2026年高三语文第一轮总复习
- 房产抵押合同范本标准模板
- 二零二五年度汽车销售商与汽车电子设备供应商合作协议范本
- 2025版小学语文新课程标准
- 2025年中盐安徽红四方肥业股份有限公司招聘笔试参考题库附带答案详解
- GB/T 17642-2025土工合成材料非织造布复合土工膜
- ISO 37001-2025 反贿赂管理体系要求及使用指南(中文版-雷泽佳译-2025)
评论
0/150
提交评论