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

When I run the code following 

proc iml;
start main;
varNames = {"tau" "K" "call_option_price" "S" "r" "put_option_price" "T" };
use cboe; * use the import data set;
read all var varNames;
T = tau/365; F = K + exp(r*T) * (call_option_price - put_option_price); K0 = int(F); finish;

It returns 

ERROR: (execution) Matrices do not conform to the operation. 

where

operation : * at line 89 column 14

operands  : r, T

r   2531 rows      1 col     (numeric)

T   2531 rows      1 col     (numeric)

 

I know the calculations should be conducted between matched matrixes. However, I found the variable r and T have the same structure with 2531 rows and 1 col. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
IanWakeling
Barite | Level 11

This error message arises when you try to take the square root of negative numbers, and it clear that this has happened 1437 times.  To see where the problem is occuring, I suggest you split the one line of code into 3 or 4 separate lines and print the values at each step for a small data set. The problem may be the data itself, or it may be that your large compound expression is not evaluated in the way that you expect because of operator precedence, so try adding more parentheses to make the evaluation order unambiguous.

View solution in original post

5 REPLIES 5
Rick_SAS
SAS Super FREQ

You have read in column vectors. There are two ways to multiply with column vectors: the inner product and elementwise multiplication. An inner product will return a scalar. Elementwise multiplication will return a vector.

 

The asterisk (*) is used for matrix and vector operations. So r`*T will return the inner product. The # operator performs elementwise multiplication. So r#T will return a vector.

 

If you are trying to perform the same operation on each row of the data, then the syntax is 

F = K + exp(r#T) # (call_option_price - put_option_price);

   

By the way, you can delete the lines "start main;" and "finish." You might have inserted them because you have a RUN statement at the end of the program. A RUN statement is not necessary.

Sasulee
Fluorite | Level 6

It works. However, when I use this method to run the following syntax, it returns ERROR: Invocation of unresolved module SQR.

 

sigma = sqr(2/T # sum(deltak/K) # exp(R # T) # Q-1/T # (F/K0-1) ## 2);

where deltak is an Integer 5 and all the other variables are read in iml as elementwise I think. Is it caused by the incorrect use of sum function? The parameter k is a vector with n rows and 1 column.

how can I achieve Summation[i] (deltak[i]/k[i]) correctly?

Thanks.

 

Rick_SAS
SAS Super FREQ

The ERROR message tells you the problem: There is no SQR function. Did you mean SQRT for "square root"?  

 

The SUM function looks correct.

Sasulee
Fluorite | Level 6

Yes it is. I have changed it to sqrt(). 

But why it returns following error when I perform sqrt() for this calculation.

ERROR: (execution) Invalid argument to function.

 

count     : number of occurrences is 1437

operation : SQRT at line 93 column 13

operands  : sigma_2

sigma_2   2531 rows      1 col     (numeric)

If I remove the sqrt() function, it works well.

IanWakeling
Barite | Level 11

This error message arises when you try to take the square root of negative numbers, and it clear that this has happened 1437 times.  To see where the problem is occuring, I suggest you split the one line of code into 3 or 4 separate lines and print the values at each step for a small data set. The problem may be the data itself, or it may be that your large compound expression is not evaluated in the way that you expect because of operator precedence, so try adding more parentheses to make the evaluation order unambiguous.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 1228 views
  • 1 like
  • 3 in conversation