Plot histogram on matlab
조회 수: 8 (최근 30일)
이전 댓글 표시
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
채택된 답변
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!