Plot histogram on matlab

조회 수: 8 (최근 30일)
Tiancong Sui
Tiancong Sui 2013년 10월 28일
댓글: Tiancong Sui 2013년 10월 28일
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

채택된 답변

Wayne King
Wayne King 2013년 10월 28일
편집: Wayne King 2013년 10월 28일
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)
  댓글 수: 1
Tiancong Sui
Tiancong Sui 2013년 10월 28일
thank you so much!!! !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by