BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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!
3 REPLIES 3
deleted_user
Not applicable
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);
label
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;

cards;
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;
run;
Cynthia_sas
Diamond | Level 26
Hi:
Apparently, in SAS 9.2, there will be a Black-Scholes function.
http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a002979681.htm

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):

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

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.

cynthia
deleted_user
Not applicable
thank you! very helpful, very much appreciated!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2513 views
  • 0 likes
  • 2 in conversation