这个是生成价格路径的代码
function SPaths=AssetPaths(S0,mu,sigma,T,NSteps,NRepl)
%生成价格路径
SPaths = zeros(NRepl, 1+NSteps);
SPaths(:,1) = S0;
dt = T/NSteps;
nudt = (mu-0.5*sigma^2)*dt;
sidt = sigma*sqrt(dt);
for i=1:NRepl
for j=1:NSteps
SPaths(i,j+1)=SPaths(i,j)*exp(nudt + sidt*randn);
end
end
%作图
x1=0:dt:T;
y1=SPaths';
y2=mean(SPaths);
figure
subplot(2,1,1);
plot(x1,y1)
subplot(2,1,2);
plot(x1,y2)
xlabel('期权存续期间')
ylabel('股票价格模拟路径')
SPaths(:,1) = [];
|