turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Help with finding code for the Black-Scholes formu...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-20-2008 03:56 AM

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!

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

Any help would be greatly appreciated!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-20-2008 03:58 AM

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;

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-20-2008 10:41 AM

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

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-20-2008 11:47 PM

thank you! very helpful, very much appreciated!