0

I want to implement the following function in Matlab, Pnk: Pnk

Following, I want to implement a different function, which uses a double sum over different values of n and k inputted in the Pnk function and another function In:

sumsum

I am having trouble implementing these function in an efficient way in Matlab. I have succesfully implemented them by storing the values of n and k in vectors and evaluating each combination respectively, but this is computationally very intensive. What is the most efficient way so that I can input vectors for n and k in the Pnk function, and later take the double sum for k = 1:n and n = 1:Inf (or cap it at a certain upper bound, i.e. n = 15)?

FYI: these functions are used in the computation of option pricing using the Kou model (http://www.columbia.edu/~sk75/MagSci02.pdf)

EDIT: The model can be succesfully implemented in Mathematica using the code of Andrzej Kozlowski http://demonstrations.wolfram.com/OptionPricesInTheKouJumpDiffusionModel/

The specific part this question is about is coded in Mathematica in the following way:

With[{w = 15},
Exp[(\[Sigma]*\[Eta]1)^2*T/2]/(Sqrt[2*\[Pi]*T]\*\[Sigma]\)*
 Sum[Exp[-\[Lambda]*T*(\[Lambda]*T)^n/n!*
  PP[n, k, p, \[Eta]1, \[Eta]2]*(\[Sigma]*Sqrt[T]*\[Eta]1)^k*
   II[k - 1][a - \[Mu]*T, -\[Eta]1, -1/(\[Sigma]*Sqrt[T]), 
 -\[Sigma] \[Eta]1 Sqrt[T]]
 , {n, 1, w}, {k, 1, n}]

and with PP and II the respective function Pnk and In.

In Mathematica the function: Sum[f,{i,imin,imax},{j,jmin,jmax},…] exists, which is used in the above manner with f evaluated for: {n, 1, w}, {k, 1, n}.

Could somebody help me with the correct Matlab syntax in order to evaluate this double summation in a proper way?

Community
  • 1
  • 1
Peter Lawrence
  • 719
  • 2
  • 10
  • 20
  • Maybe try [this](https://www.mathworks.com/matlabcentral/fileexchange/61348-nck-n-k-), also explained [here](https://stackoverflow.com/questions/39118818/how-to-compute-sum-of-binomial-more-efficiently) – EBH Jun 19 '17 at 19:30
  • Have you tried simplifying those expressions using a CAS? – flawr Jun 19 '17 at 19:36
  • @flawr I am reasonably new to Matlab and have not tried this. Do you mean that I should input the expressions as symbolic functions and then simplify them? – Peter Lawrence Jun 19 '17 at 19:55
  • I actually meant using programs like maple, maxima or mathematica to simplify the expression. – flawr Jun 19 '17 at 20:30

0 Answers0