I'd like to work with complex numbers in SAS/IML. In particular, I'd like to do option pricing in the Heston model as described in Kahl and Jaeckel.
I assume the complex numbers will be represented as two-component matrices. I also assume I'll be using modules to do complex arithmetic, including multiplication and division, as well as things like arg(c), |c|, exp(c), ln(c), for complex c.
Is there a standard implementation of these compex arithmetic modules that I can use, or will I have to write my own?
You will have to write your own modules. The functions you specify are all elementwise operations, so they don't require any linear algegra. Be sure to vectorize your functions for efficiency.
As an example, the Arg function returns the polar angle. You can use some of the ideas in this blog post about "Computing polar angles from data."
Another example is complex multiplication, which I would implement as follows:
proc iml;
/* Complex multiplication of A*B.
A vector of complex numbers is a two-column
matrix where Re(A)=A[,1] and Im(A)=A[,2].
If A = x + iy and B = u + iv then
C = A*B = (x#u - y#v) + i(x#v + y#u)
*/
start cplxMult(A, B);
C = j(nrow(A),2);
C[,1] = A[,1]#B[,1] - A[,2]#B[,2];
C[,2] = A[,1]#B[,2] + A[,2]#B[,1];
return( C );
finish;
/* test it */
A = {2 0, /* pure real */
0 3, /* pure imag */
1 3,
-1 -5};
B = {3 0, /* pure real */
0 -4, /* pure imag */
1 -3, /* conjugate */
4 2};
C = cplxMult(A, B);
print C;
If you create a nice library of complex operations, I encourage you post it to the SAS/IML File Exchange when you are finished. I think others might find it interesting and potentially useful.
Ohh, I would doubt SAS can do some complex arithmetic. I never saw the function or operator related to complex number in SAS/IML .
You need Mathematics or Matlab .
Maybe @Rick Wicklin could guide you to somewhere . He is PhD of Applied Mathematic .
You will have to write your own modules. The functions you specify are all elementwise operations, so they don't require any linear algegra. Be sure to vectorize your functions for efficiency.
As an example, the Arg function returns the polar angle. You can use some of the ideas in this blog post about "Computing polar angles from data."
Another example is complex multiplication, which I would implement as follows:
proc iml;
/* Complex multiplication of A*B.
A vector of complex numbers is a two-column
matrix where Re(A)=A[,1] and Im(A)=A[,2].
If A = x + iy and B = u + iv then
C = A*B = (x#u - y#v) + i(x#v + y#u)
*/
start cplxMult(A, B);
C = j(nrow(A),2);
C[,1] = A[,1]#B[,1] - A[,2]#B[,2];
C[,2] = A[,1]#B[,2] + A[,2]#B[,1];
return( C );
finish;
/* test it */
A = {2 0, /* pure real */
0 3, /* pure imag */
1 3,
-1 -5};
B = {3 0, /* pure real */
0 -4, /* pure imag */
1 -3, /* conjugate */
4 2};
C = cplxMult(A, B);
print C;
If you create a nice library of complex operations, I encourage you post it to the SAS/IML File Exchange when you are finished. I think others might find it interesting and potentially useful.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.