Help using Base SAS procedures

Help with finding code for the Black-Scholes formula

Posts: 0

Help with finding code for the Black-Scholes formula

Does anyone have any source code for running a black scholes call option pricing test?

Additionally, how does one increase the number of future sample paths for such a test?

Any help would be greatly appreciated!
Posts: 0

Re: Help with finding code for the Black-Scholes formula

I am a student of SAS and am not terribly familliar with this type of code... Would this be appropriate code for Black Scholes?

data BS;
input S X r v T;
d1 = (log(S/X) + (r+v**2/2)*T)/v/sqrt(T);
d2 = d1 - v*sqrt(T);
C = S*cdf('Normal',d1) - X*exp(-r*T)*cdf('Normal',d2);
P = X*exp(-r*T)*cdf('Normal',-d2) - S*cdf('Normal',-d1);
S = 'Spot Price'
X = 'Strike Price'
r = 'Risk Free Rate'
v = 'Volatility'
T = 'Time Periods'
C = 'BS Call Price'
P = 'BS Put Price' ;

* Input as many input values as needed;

120 95 0.08 0.2 3
120 100 0.08 0.2 3
120 110 0.08 0.2 3
120 120 0.08 0.2 3
proc print label;
var S X r v T C P;
Posts: 8,743

Re: Help with finding code for the Black-Scholes formula

Apparently, in SAS 9.2, there will be a Black-Scholes function.

Until then, depending on who you got this program from, this might be performing the right calculation for you.

In brief, this is a DATA step program. It is creating a SAS data set called WORK.BS. The program is reading "raw" data that comes after the cards; statement -- what you see in the INPUT statement are the variables or columns being read...and in what order.

So, you have this INPUT statement:
input S X r v T;
and if you substitute the LABEL statement meanings for the single letters, what is being read is:
Spot Price ... Strike Price ... Risk Free Rate.... Volatility.... Time Periods

It looks like d1 and d2 are being used to hold values used in the calculation of BS Call Price (C) and BS Put Price (P). The 4 statements after the input statement will be executed for each row of "raw" data that you type or enter in the "cards;" section. The whole program, data included, starts with the keyword DATA and ends with the semi-colon at the bottom of the data. The "program code" portion starts with the keyword data and ends at the CARDS statement. The 'raw" data portion starts with the CARDS; statement and the "raw" data ends with the single semi-colon after the last line of data--but the step boundary for the program happens when the PROC PRINT is encountered. The PROC PRINT is a SAS procedure that is just printing out the SAS dataset WORK.BS -- the most recently created data set.

To find out what/how D1, D2, C and P are calculated, you need to look up functions ... for example, d1 uses 2 functions -- the LOG function and the SQRT function (I added some white space to make the formula easier to follow):

d1 = ( log(S/X) + (r + v**2/2 ) *T ) / v / sqrt(T);

To understand the DATA step and what it's doing, reading the SAS basic concepts section of the documentation would be a help. To understand the math behind the Black-Scholes model, I'd guess you have to look at Finance textbooks or Stat textbooks. SAS Tech Support can also help you with the program or making modifications to the program, if it is not calculating according to the kind of analysis you need to do.

Posts: 0

Re: Help with finding code for the Black-Scholes formula

thank you! very helpful, very much appreciated!
Ask a Question
Discussion stats
  • 3 replies
  • 2 in conversation