BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mcs
Obsidian | Level 7 mcs
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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.

View solution in original post

2 REPLIES 2
Ksharp
Super User

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 .

Rick_SAS
SAS Super FREQ

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 2549 views
  • 1 like
  • 3 in conversation