BookmarkSubscribeRSS Feed
nolonglove
Calcite | Level 5
This is my SAS marco to calculate american put or call by Cox-Ross-Rubinstein method:

Macro to Calculate the call Intrinsic Option Value at Each NodeThis

%macro cval(si,xi);
(&si-ξ+abs(&si-ξ))/2
%mend cval;
* Macro to Calculate the callOption Price at Each Node;
%macro c(ni,ss);
%if ∋=&n %then
%do;
%cval (&ss,&x)
%end;
%else %do;
max(%cval(&ss,&x),((%c(∋+1,&ss*&u))*&p+(%c(∋+1,&ss*&d))*(1-&p))/&rq)
%end;
%mend c;
* Macro to Calculate the put Intrinsic Option Value at Each Node;
%macro pval(si,xi);
(&xi-&si+abs(&xi-&si))/2
%mend pval;

* Macro to Calculate the put Option Price at Each Node;
%macro p(ni,ss);
%if ∋=&n %then
%do;
%pval (&ss,&x)
%end;
%else %do;
max(%pval(&ss,&x),((%p(∋+1,&ss*&u))*&p+(%p(∋+1,&ss*&d))*(1-&p))/&rq)
%end;
%mend p;

data data1;
input eq_price strike time opt_price intrate;
datalines;
1108.48 995 0.041067762 0.8 0.01107094
1122.22 995 0.032854209 0.35 0.011018561
1123.67 995 0.030116359 0.3 0.01098864
1126.33 995 0.027378508 0.2 0.01092533
1131.92 995 0.024640657 0.2 0.010853256
1121.86 995 0.021902806 0.175 0.0108289
1127.23 995 0.013689254 0.075 0.010809861
1121.22 995 0.010951403 0.1 0.010954211
1122.22 1010 0.128678987 3.5 0.011561104
1123.67 1010 0.125941136 3 0.011490423
1126.33 1010 0.123203285 2.4 0.011465478
1131.92 1010 0.120465435 2.4 0.011459139
1121.86 1010 0.117727584 3.1 0.011313808
1127.23 1010 0.109514031 2.45 0.011324488
1121.22 1010 0.106776181 2.9 0.011172599
;
run;
* Set the Option Variables and Call the Macros;
data b;
set data1;
%let s=eq_price; * underlying security price;
%let x=strike; * strike price;
%let n=7; * nt = n = number of subperiods;
%let t=time; * time to maturity, in years;
%let h=&t/&n;* it=h=T/n= size of the sub-period;
%let r=intrate; * r = continuously compounded risk free rate;
%let q=0.0254; * dividend yield;
%let sig=0.24; *implied Volatility;

%let u =exp(&sig*sqrt(&h));
%let d =exp(-&sig*sqrt(&h));
%let rq=exp((&r-&q)*&h);
%let p =(&rq-&d)/(&u-&d);

p=%p(0,&s);
c=%c(0,&s);
output;
run;

and the out put is

The SAS System 11:42 Saturday, May 21, 2011 5

Obs eq_price strike time opt_price intrate p c

1 1108.48 995 0.04107 0.800 0.011071 0.17516 113.487
2 1122.22 995 0.03285 0.350 0.011019 0.00000 127.220
3 1123.67 995 0.03012 0.300 0.010989 0.00000 128.670
4 1126.33 995 0.02738 0.200 0.010925 0.00000 131.330
5 1131.92 995 0.02464 0.200 0.010853 0.00000 136.920
6 1121.86 995 0.02190 0.175 0.010829 0.00000 126.860
7 1127.23 995 0.01369 0.075 0.010810 0.00000 132.230
8 1121.22 995 0.01095 0.100 0.010954 0.00000 126.220
9 1122.22 1010 0.12868 3.500 0.011561 4.54713 115.75
10 1123.67 1010 0.12594 3.000 0.011490 4.33255 117.00
11 1126.33 1010 0.12320 2.400 0.011465 4.04350 119.39
12 1131.92 1010 0.12047 2.400 0.011459 3.57726 124.54
13 1121.86 1010 0.11773 3.100 0.011314 4.04854 114.96
14 1127.23 1010 0.10951 2.450 0.011324 3.31856 119.67
15 1121.22 1010 0.10678 2.900 0.011173 3.54189 113.90


But my marco use the sig which is only at 0.24,at this level, the answer p is not same to opt_price.
I want to change sig in my marco util the answer for p is same to opt_price.

please hlep me to solve this problem?
Thx!I need help! Message was edited by: nolonglove
2 REPLIES 2
ballardw
Super User
Did you have a working version of this procedure without the macro approach?
nolonglove
Calcite | Level 5
This is another version to calculate the
implied bolatility until the put option
price issame to opt_price(open markets price);
but this way only use to SAS 9.2:
data data1;
input eq_price strike time opt_price intrate;
datalines;
1108.48 995 0.041067762 0.8 0.01107094
1122.22 995 0.032854209 0.35 0.011018561
1123.67 995 0.030116359 0.3 0.01098864
1126.33 995 0.027378508 0.2 0.01092533
1131.92 995 0.024640657 0.2 0.010853256
1121.86 995 0.021902806 0.175 0.0108289
1127.23 995 0.013689254 0.075 0.010809861
1121.22 995 0.010951403 0.1 0.010954211
1122.22 1010 0.128678987 3.5 0.011561104
1123.67 1010 0.125941136 3 0.011490423
1126.33 1010 0.123203285 2.4 0.011465478
1131.92 1010 0.120465435 2.4 0.011459139
1121.86 1010 0.117727584 3.1 0.011313808
1127.23 1010 0.109514031 2.45 0.011324488
1121.22 1010 0.106776181 2.9 0.011172599
;
run;

proc fcmp outlib=work.functions.samples;
function blksch( strike, time, eq_price, intrate, volty );
return (blkshptprc( strike, time,eq_price, intrate, volty ));
endsub;
run;

options cmplib=work.functions.samples;

proc fcmp outlib=work.functions.samples;
function impl_volty( opt_price, strike, time, eq_price, intrate);

array opts[5] initial abconv relconv maxiter
( .5 .001 1.0e-6 100 ) ;

bsvolty = solve( "blksch", opts, opt_price, strike,
time, eq_price, intrate, .);

return (bsvolty);
put 'Option Implied Volatility:' bsvolty
'Initial value: ' opts[1]
'Solve status: ' opts[5];
endsub;
run;

data data2;
set data1;
implty=impl_volty(opt_price, strike, time, eq_price, intrate);
run;

In this version, I use B-S model to
find the answer of implied bolatility,
but,B-S model have function
"blkshptprc( strike, time,eq_price, intrate, volty )"
in SAS, and B-S model only use
to price the euro options.

In my macro prblem, the price of option is
America options, it can not use B-S model,
it must use binomial method to price. i did
not find the function of "Binomial method "
in SAS , so i use macro to calculat the
America put price.
Finally, i need help to slove this problem for any way!
THX!

Message was edited by: nolonglove

Message was edited by: nolonglove Message was edited by: nolonglove

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 895 views
  • 0 likes
  • 2 in conversation