Plot histogram on matlab
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tiancong Sui
el 28 de Oct. de 2013
Comentada: Tiancong Sui
el 28 de Oct. de 2013
How to plot Histogram of all 10000 values of C ? Thank you!!
stock(1) = 675.15;
delta_t = 1 / 30;
volatility = 0.2;
drift = 0.02;
for n = 1 : 10000
for i = 2 : 30
stock(i) = stock(i-1) .* exp( volatility .* sqrt ( delta_t ) .* randn(1) + drift .* delta_t );
end
r = 0.01;
S = stock(30);
K = 690;
T = 1/6; %Originally 3 months, after 1 month we have 2 months left
v = 0.2;
d1 = (log(S/K) + (r + (v^2)/2) .* T) / (v .* sqrt(T));
d2 = (log(S/K) + (r - (v^2)/2) .* T) / (v .* sqrt(T));
C = normcdf(d1) .* S - normcdf(d2) .* K .* exp(-r .* T);
end
0 comentarios
Respuesta aceptada
Wayne King
el 28 de Oct. de 2013
Editada: Wayne King
el 28 de Oct. de 2013
You just have to save each value of C as an element of a vector.
stock(1) = 675.15;
delta_t = 1 / 30;
volatility = 0.2;
drift = 0.02;
C = zeros(10000,1);
for n = 1 : 10000
for i = 2 : 30
stock(i) = stock(i-1) .* exp( volatility .* sqrt ( delta_t ) .* randn(1) + drift .* delta_t );
end
r = 0.01;
S = stock(30);
K = 690;
T = 1/6; %Originally 3 months, after 1 month we have 2 months left
v = 0.2;
d1 = (log(S/K) + (r + (v^2)/2) .* T) / (v .* sqrt(T));
d2 = (log(S/K) + (r - (v^2)/2) .* T) / (v .* sqrt(T));
C(n) = normcdf(d1) .* S - normcdf(d2) .* K .* exp(-r .* T);
end
hist(C)
Más respuestas (0)
Ver también
Categorías
Más información sobre Histograms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!