MATLAB: Plot histogram on matlab

histogram

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

Best Answer

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)