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