BookmarkSubscribeRSS Feed
nolonglove
Calcite | Level 5
This is my code to do binomial pricing on america options,

*************************************************************
data data1;
input E F t opt_price r ;
datalines;
1108.48 995 0.041067762 114 0.01107094
1122.22 995 0.032854209 127 0.011018561
1123.67 995 0.030116359 129 0.01098864
1126.33 995 0.027378508 131 0.01092533
1131.92 995 0.024640657 137 0.010853256
1121.86 995 0.021902806 127 0.0108289
1127.23 995 0.013689254 132 0.010809861
1121.22 995 0.010951403 126 0.010954211
1122.22 1010 0.128678987 123 0.011561104
1123.67 1010 0.125941136 124 0.011490423
1126.33 1010 0.123203285 126 0.011465478
1131.92 1010 0.120465435 130 0.011459139
1121.86 1010 0.117727584 121 0.011313808
1127.23 1010 0.109514031 124 0.011324488
1121.22 1010 0.106776181 119 0.011172599
;
run;

proc fcmp outlib = work.functions.samples;
function Eurocall(E, t, F, r, sigma, N);
deltaT=T/N;
u=exp(sigma*sqrt(deltaT));
d=1/u;
p=(exp(r*deltaT)-d)/(u-d);
array tree[1]/ nosymbols;
call dynamic_array(tree, n+1, n+1);
call zeromatrix(tree);

do i=0 to N;
tree[i+1,N+1]=max(0 , E*(u**i)*(d**(N-i)) - F);
end;
do j=(N-1) to 0 by -1;
do i=0 to j by 1;
tree[i+1,j+1] = exp(-r*deltaT)* (p * tree[i+2,j+2] + (1-p) * tree[i+1,j+2]);
end;
end;
price = tree[1,1];
return(price);
endsub;
run;
options cmplib=work.functions.samples;


proc fcmp outlib=work.functions.samples;
function impl_volty( opt_price, E, t, F, r,N);

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

bsvolty = solve( "Eurocall", opts, opt_price, E,
t, F, r,N, . );
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, E, t, F, r,N);
run;
*************************************************
the log file have problem as follow:
ERROR: An ARRAY index is out of bounds in function 'Eurocall' in statement number 9 at line 13 column 1.
The statement was:
0 (13:1) tree[(i=0) + 1,(N=0.5005) + 1] = MAX( 0, (E=1121.22) * (u=.) ** (i=0) * (d=.) ** ((N=0.5005) - (i=0)) -
(F=1010) )
ERROR: Exception occurred during subroutine call.
E=1121.22 F=1010 t=0.106776181 opt_price=119 r=0.011172599 implty=. _ERROR_=1 _N_=15
***************************************************
I can not to solve this wrong in log file,
Please give me a sample to solve this problem,
Thx!! Message was edited by: nolonglove
1 REPLY 1
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Nologlove,

I found a formal error in your code:

call dynamic_array(tree, n+1, n+1);

implies that tree contains n+1 elements but

do i=0 to N;
tree[i+1,N+1]=max(0 , E*(u**i)*(d**(N-i)) - F);
end;

uses n+2 elements. Changing

call dynamic_array(tree, n+2, n+2);

runs the program without errors but with a few notes.

HTH,
SPR

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1626 views
  • 0 likes
  • 2 in conversation