Piecewise integration - implied volatility

8 visualizaciones (últimos 30 días)
Hyunsin Kim
Hyunsin Kim el 15 de Dic. de 2018
Respondida: Jan el 17 de Dic. de 2018
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

Respuestas (1)

Jan
Jan el 17 de Dic. de 2018
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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by