随机过程matlab程序

上传人:工**** 文档编号:498060097 上传时间:2023-12-03 格式:DOC 页数:17 大小:336.50KB
返回 下载 相关 举报
随机过程matlab程序_第1页
第1页 / 共17页
随机过程matlab程序_第2页
第2页 / 共17页
随机过程matlab程序_第3页
第3页 / 共17页
随机过程matlab程序_第4页
第4页 / 共17页
随机过程matlab程序_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《随机过程matlab程序》由会员分享,可在线阅读,更多相关《随机过程matlab程序(17页珍藏版)》请在金锄头文库上搜索。

1、% PPT 例2 一维正态密度与二维正态密度syms x y;s=1; t=2; mu1=0; mu2=0; sigma1=sqrt(1+s2); sigma2=sqrt(1+t2); x=-6:0.1:6;f1=1/sqrt(2*pi*sigma1)*exp(-(x-mu1).2/(2*sigma12);f2=1/sqrt(2*pi*sigma2)*exp(-(x-mu2).2/(2*sigma22);plot(x,f1,r-,x,f2,k-.) rho=(1+s*t)/(sigma1*sigma2); f=1/(2*pi*sigma1*sigma2*sqrt(1-rho2)*exp(-1/

2、(2*(1-rho2)*(x-mu1)2/sigma12-2*rho*(x-mu1)*(y-mu2)/(sigma1*sigma2)+(y-mu2)2/sigma22);ezsurf(f)% % The daily log returns on the stock have a mean of 0.05/year and a standard deviation of 0.23/year. These can be converted to rates per trading day by deviding by 253 and sqrt(253), respectively.Question

3、 1: What is the probability that the value of the stock will be below $950,000 at the close day of at least one of the next 45 trading days? clear;niter=1.0E5; % number of iterationsbelow=repmat(0,1,niter); % set up storagerandn(seed,0);for i=1:niter r=normrnd(0.05/253,0.23/sqrt(253),1,45); % genera

4、te random numbers logPrice=log(1.0E6)+cumsum(r); minlogP=min(logPrice); % minmum price over next 45 days below(i)=sum(minlogPlog(950000); endPro=mean(below)% P29 随机相位正弦波仿真% 1 time simulationw=2; N=1000; mu=2; sigma=3;s=rand(state);A=mu+sigma*randn(1,N); % A=normrnd(mu,sigma,1,N)theta=-pi+2*pi*rand(1

5、,N);t=1:N;x=A.*cos(w*t+theta); capmu=mean(x) tao=1x1=A.*cos(w*(t+tao)+theta);capgamma=mean(x-capmu).*(x1-capmu) % m time simulationclear; w=2; N=1000; mu=2; sigma=3;m=500;capmu1=;capgamma1=;for i=1:ms=rand(state);A=mu+sigma*randn(1,N);theta=-pi+2*pi*rand(1,N);t=1:N;x=A.*cos(w*t+theta);capmu=mean(x);

6、capmu1=capmu1,capmu; tao=1;x1=A.*cos(w*(t+tao)+theta);capgamma=mean(x-capmu).*(x1-capmu);capgamma1=capgamma1,capgamma;endplot(1:m,capmu1,*,1:m,capgamma1,o) capmu=mean(capmu1);capgamma=mean(capgamma1); err1=mean(capmu1-0).2);gamma=(sigma2+mu2)*cos(w*tao)/2;err2=mean(capgamma1-gamma).2);capmu,capgamma

7、; err1, err2 % 输出: 0.0058 -2.7005 0.0065 0.0736% P37 例3.1.1p1=poisscdf(5,10)p2=poisspdf(0,10)p1,p2%输出p1 =0.0671p2 =4.5400e-005ans =0.0671 0.0000 % P43 例3.2.1p3=poisspdf(9,12)% 输出p3 = 0.0874 % P43 例3.2.2p4=poisspdf(0,12)% 输出p4 = 6.1442e-006% P39-40(Th3.1.1) Solve the difference equation system, find

8、the solution% 输入:syms p0 p1 p2 ;S=dsolve(Dp0=-lamda*p0,Dp1=-lamda*p1+lamda*p0,Dp2=-lamda*p2+lamda*p1,p0(0) = 1,p1(0) = 0,p2(0) = 0);S.p0,S.p1,S.p2% 输出:ans =exp(-lamda*t), exp(-lamda*t)*t*lamda, 1/2*exp(-lamda*t)*t2*lamda2% P43 泊松过程仿真% simulate 10 timesclear;m=10; lamda=1; x=; for i=1:ms=exprnd(lamda

9、,seed,1);x=x,exprnd(lamda);t1=cumsum(x);endx,t1 %输出:ans = 0.6509 0.6509 2.4061 3.0570 0.1002 3.1572 0.1229 3.2800 0.8233 4.1033 0.2463 4.3496 1.9074 6.2570 0.4783 6.7353 1.3447 8.0800 0.8082 8.8882%输入:N=;for t=0:0.1:(t1(m)+1)if tt1(1) N=N,0;elseif tt1(2) N=N,1;elseif tt1(3) N=N,2;elseif tt1(4) N=N,3

10、;elseif tt1(5) N=N,4;elseif tt1(6) N=N,5;elseif tt1(7) N=N,6;elseif tt1(8) N=N,7;elseif tt1(9) N=N,8; elseif tt1(10) N=N,9;else N=N,10;endendplot(0:0.1:(t1(m)+1),N,r-) %输出:% simulate 100 timesclear;m=100; lamda=1; x=; for i=1:ms= rand(seed);x=x,exprnd(lamda);t1=cumsum(x);endx,t1 N=;for t=0:0.1:(t1(m

11、)+1)if t=t1(i) & tt1(m) N=N,m;endendplot(0:0.1:(t1(m)+1),N,r-) % 输出:% P48 非齐次泊松过程仿真% simulate 10 timesclear;m=10; lamda=1; x=; for i=1:ms=rand(seed); % exprnd(lamda,seed,1); set seedsx=x,exprnd(lamda);t1=cumsum(x);endx,t1 N=; T=;for t=0:0.1:(t1(m)+1)T=T,t.3; % time is adjusted, cumulative intensity

12、function is t3. if t=t1(i) & tt1(m) N=N,m; endendplot(T,N,r-) % outputans = 0.4220 0.4220 3.3323 3.7543 0.1635 3.9178 0.0683 3.9861 0.3875 4.3736 0.2774 4.6510 0.2969 4.9479 0.9359 5.8838 0.4224 6.3062 1.7650 8.0712 10 times simulation 100 times simulation% P50 复合泊松过程仿真% simulate 100 timesclear;niter=100; % iterate numberlamda=1; % arriving ratet=input(Input a time:,s)for i=1:niter rand(state,sum(clock); x=exprnd(lamda); % interval time t1=x; while t1t

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号