Plot histogram on matlab
8 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Wayne King
on 28 Oct 2013
Edited: Wayne King
on 28 Oct 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)
More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!