First of all, I think, the example (from the SAS 9.2 documentation) in your link is flawed: The array OPTS has 5 dimensions, but only 4 variables and initial values have been specified. This is not literally an error, but it causes an unnecessary note in the log. It is particularly odd that they present an output where the computed result of the SOLVE function is missing. Moreover, they use the DATE() function (=current date at run time), so that you can't really replicate their example as the result would depend on when you run it.
Not surprisingly, they corrected all this in the SAS 9.4 documentation:
http://support.sas.com/documentation/cdl/en/proc/68954/HTML/default/viewer.htm#p1xoknqns865t7n1wehj6xarwhdb.htm
However, it is still strange to me that they present an example of a function call where the arguments (opt_price, strike, etc.) are hardcoded in the PROC FCMP step. Wouldn't it make much more sense, if users like you were able to apply the function to their data without having to modify the PROC FCMP code?
Well, it takes only a few changes to their code to create at least a draft version of what I think that function should look like:
proc fcmp outlib=work.funcs.test;
function blksch(strike, time, eq_price, intrate, volty);
return(blkshclprc(strike, time/365.25,
eq_price, intrate, volty));
endsub;
function implvola(opt_price, strike, eq_price, intrate, time);
array opts[5] initial abconv relconv maxiter status
(.5 .001 1.0e-6 100 -1);
bsvolty=solve("blksch", opts, opt_price, strike,
time, eq_price, intrate, .);
return(bsvolty);
endsub;
run;
options cmplib=work.funcs;
With this definition of the new function IMPLVOLA you're in a position to compute the implied volatility for a given option price, strike price, equity price, interest rate and time to expiry (in days):
data have;
input opt_price strike eq_price intrate time;
cards;
5 50 50 .05 93
;
data want;
set have;
impl_vola=implvola(opt_price, strike, eq_price, intrate, time);
run;
proc print;
format impl_vola best12.;
run;
As you can see, the result matches the value in the example. I haven't done further tests of my function definition, though.
Unfortunately, I have no experience using the Black-Scholes formula. Therefore, I am not sure how sensitive the above function is to the initial value (opts[1]=initial), which is set to .5 in the code. I cannot rule out that there are realistic input data which would require a different initial value to make the SOLVE algorithm converge.
That said, I was also a bit surprised to read that your data contains "all the required fields, i.e. strike price, time to expiry, equity price, interest rate and volatility." Do you refer to realized volatility? However, you did not mention option price, but this would be a required argument in order to calculate the implied volatility.
... View more