stock(1) = 675.15;
delta_t = 1 / 30;
volatility = 0.2;
drift = 0.02;
for i = 2 : 30
stock(i) = stock(i-1) .* exp( volatility .* sqrt ( delta_t ) .* randn(1) + drift .* delta_t );
end
disp( stock(30) )
How do I generate 10,000 random results?

 채택된 답변

Image Analyst
Image Analyst 2013년 10월 28일

0 개 추천

Just wrap the for loop in another loop that runs 10,000 experiments, like this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
stock(1) = 675.15;
delta_t = 1 / 30;
volatility = 0.2;
drift = 0.02;
for experiment = 1 : 10000
for i = 2 : 30
stock(i) = stock(i-1) .* exp( volatility .* sqrt ( delta_t ) .* randn(1) + drift .* delta_t );
end
lastPrice(experiment) = stock(end);
disp( stock(30) )
end
plot(lastPrice, 'b-');
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
title('Monte Carlo Experiment on Ending Stock Price', 'fontSize', fontSize);
ylabel('Ending Stock Price', 'fontSize', fontSize);
xlabel('Experiment number', 'fontSize', fontSize);

댓글 수: 1

Tiancong Sui
Tiancong Sui 2013년 10월 28일
Thank you SO MUCH ! very helpful! I can keep going now

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Parallel Server에 대해 자세히 알아보기

태그

질문:

2013년 10월 28일

댓글:

2013년 10월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by