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?

 Respuesta aceptada

Image Analyst
Image Analyst el 28 de Oct. de 2013

0 votos

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 comentario

Tiancong Sui
Tiancong Sui el 28 de Oct. de 2013
Thank you SO MUCH ! very helpful! I can keep going now

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Parallel Server en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Oct. de 2013

Comentada:

el 28 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by