Piecewise integration - implied volatility

조회 수: 9 (최근 30일)
Hyunsin Kim
Hyunsin Kim 2018년 12월 15일
답변: Jan 2018년 12월 17일
Hi,
I'm trying to integrate a piecewise function and I'm having slight troubles. The function is as below:
Now I have a column vector for the differing C and S values. However I'm having trouble with the max condition and the differing Ks.
The 5200 and 11150 is the range that I'm specifying as strike prices dont range into the infinity.
Below is my attempt....Would be great if someone could help me out.
I get the error: "Index in position 1 exceeds array bounds (must not exceed 1)".
I've had attempts with varying code and I have not been successful.
fun = piecewise(S-K>0,((C-(S-K))./K^2),S-K<0,((C-0)./K^2));
q = zeros(length(SortedDax),1);
for i = 1:length(SortedDax)
q(i,1) = 2.*integral((@(K)fun(SortedDax(i,4),SortedDax(i,30),K)),5200,11150);
end

답변 (1개)

Jan
Jan 2018년 12월 17일
length(SortedDax) is a frequent source of bugs: You measure the longest dimenion, not a specific one. If SortedDax is a [3 x 30] matrix, length() replies 30, but you want to use an index concerning the first dimension. So determine this size specifically:
nDax = size(SortedDax, 1);
q = zeros(nDax, 1);
for i = 1:nDax
...
end

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by