随机过程matlab程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
% PPT 例2 一维正态密度与二维正态密度
syms x y;
s=1; t=2;
mu1=0; mu2=0; sigma1=sqrt((1+s^2)); sigma2=sqrt((1+t^2));
x=-6:0.1:6;
f1=1/sqrt(2*pi*sigma1)*exp(-(x-mu1).^2/(2*sigma1^2));
f2=1/sqrt(2*pi*sigma2)*exp(-(x-mu2).^2/(2*sigma2^2));
plot(x,f1,'r-',x,f2,'k-.')
rho=(1+s*t)/(sigma1*sigma2);
f=1/(2*pi*sigma1*sigma2*sqrt(1-rho^2))*exp(-1/(2*(1-rho^2))*((x-mu1)^2/sigma1^2-2*rho*(x-mu1)*(y-mu2)/(sigma1*sigma2)+(y-mu2)^2/sigma2^2));
ezsurf(f)
-6-4-20246
x 44798133900177/281474976710656 exp(-5/2 x 2+3 x y-y 2)
y
% % 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 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 iterations
below=repmat(0,1,niter); % set up storage
randn('seed',0);
for i=1:niter
r=normrnd(0.05/253,0.23/sqrt(253),1,45); % generate random numbers
logPrice=log(1.0E6)+cumsum(r);
minlogP=min(logPrice); % minmum price over next 45 days
below(i)=sum(minlogP<log(950000));
end
Pro=mean(below)
% P29 随机相位正弦波仿真
% 1 time simulation
w=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,N);
t=1:N;
x=A.*cos(w*t+theta);
capmu=mean(x)
tao=1
x1=A.*cos(w*(t+tao)+theta);
capgamma=mean((x-capmu).*(x1-capmu))
% m time simulation
clear;
w=2; N=1000; mu=2; sigma=3;
m=500;capmu1=[];capgamma1=[];
for i=1:m
s=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);
capmu1=[capmu1,capmu];
tao=1;
x1=A.*cos(w*(t+tao)+theta); capgamma=mean((x-capmu).*(x1-capmu)); capgamma1=[capgamma1,capgamma];
end
plot(1:m,capmu1,'*',1:m,capgamma1,'o')
capmu=mean(capmu1);
capgamma=mean(capgamma1);
err1=mean((capmu1-0).^2);
gamma=(sigma^2+mu^2)*cos(w*tao)/2;
err2=mean((capgamma1-gamma).^2); [capmu,capgamma; err1, err2]
% 输出:
0.0058 -2.7005
0.0065 0.0736。