全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
6092 2
2006-05-26

哪位高手帮忙看看下面MATLAB进行模拟股票价格的程序是否有问题啊

function [St]=Stock(T,dt,S0,mu,sigma)
% Simulation of a Stock Price with constant Volatility
clc;

T=input('Specify the desired long time period ');
dt=input('Specify time internals ');
S0=input('Specify the initial Stock Price ');
mu=input('Specify the expected rate of return ');
sigma=input('Specify the volatility ');

%Number of time intervals of length dt in long time period T
N=T/dt;

%Simulation of the stock prices
S=1+mu*(1/N)+sqrt(1/N)*normrnd(0,1,N,1)*sigma;
St=cumprod(S,1);
St=S0*[1;St];

%Plot of the stock prices vs time
k=input('Do you want a graph, Y/N? ','s');
if k=='Y'
for i=1:length(St)
figure(1)
clf
x=0:dt:T;
plot(x(1:i),St(1:i),'b-');
xlim([0 T]);
grid on
xlabel('Time')
ylabel('Stock Prices')
title('Stock Price Simulation (\sigma=35%)')
pause(0.003);
end
else
end

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2006-6-28 11:12:00

看不出什么问题,我运行了一下,没图的。

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2006-7-1 08:07:00

1、pause(0.003);时间太短,建议改为0。1
2、x=0:dt:T;放在循环里,浪费资源

3、plot(x(1:i),St(1:i),'b-');

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群