Piecewise integration - implied volatility

8 次查看(过去 30 天)
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