<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Some problem in binomial pricing on options in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Some-problem-in-binomial-pricing-on-options/m-p/68832#M19726</link>
    <description>This is my code to do binomial pricing on america options,&lt;BR /&gt;
&lt;BR /&gt;
*************************************************************&lt;BR /&gt;
data data1;&lt;BR /&gt;
input  E F	t opt_price 	r ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1108.48	995	0.041067762	114	0.01107094 &lt;BR /&gt;
1122.22	995	0.032854209	127	0.011018561 &lt;BR /&gt;
1123.67	995	0.030116359	129	0.01098864 &lt;BR /&gt;
1126.33	995	0.027378508	131	0.01092533 &lt;BR /&gt;
1131.92	995	0.024640657	137	0.010853256 &lt;BR /&gt;
1121.86	995	0.021902806	127	0.0108289 &lt;BR /&gt;
1127.23	995	0.013689254	132	0.010809861 &lt;BR /&gt;
1121.22	995	0.010951403	126	0.010954211 &lt;BR /&gt;
1122.22	1010	0.128678987	123	0.011561104 &lt;BR /&gt;
1123.67	1010	0.125941136	124	0.011490423 &lt;BR /&gt;
1126.33	1010	0.123203285	126	0.011465478 &lt;BR /&gt;
1131.92	1010	0.120465435	130	0.011459139 &lt;BR /&gt;
1121.86	1010	0.117727584	121	0.011313808 &lt;BR /&gt;
1127.23	1010	0.109514031	124	0.011324488 &lt;BR /&gt;
1121.22	1010	0.106776181	119	0.011172599 &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc fcmp outlib = work.functions.samples;&lt;BR /&gt;
    function Eurocall(E, t, F, r, sigma, N);&lt;BR /&gt;
        deltaT=T/N;&lt;BR /&gt;
        u=exp(sigma*sqrt(deltaT));&lt;BR /&gt;
        d=1/u;&lt;BR /&gt;
        p=(exp(r*deltaT)-d)/(u-d);&lt;BR /&gt;
        array tree[1]/ nosymbols;&lt;BR /&gt;
        call dynamic_array(tree, n+1, n+1);&lt;BR /&gt;
        call zeromatrix(tree);&lt;BR /&gt;
        &lt;BR /&gt;
        do i=0 to N;&lt;BR /&gt;
            tree[i+1,N+1]=max(0 , E*(u**i)*(d**(N-i)) - F);&lt;BR /&gt;
        end;&lt;BR /&gt;
        do j=(N-1) to 0 by -1;&lt;BR /&gt;
            do  i=0 to j by 1;&lt;BR /&gt;
                tree[i+1,j+1] = exp(-r*deltaT)* (p * tree[i+2,j+2] + (1-p) * tree[i+1,j+2]);&lt;BR /&gt;
            end;  &lt;BR /&gt;
        end;&lt;BR /&gt;
        price = tree[1,1];&lt;BR /&gt;
        return(price);&lt;BR /&gt;
    endsub;&lt;BR /&gt;
run;&lt;BR /&gt;
options cmplib=work.functions.samples;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc fcmp outlib=work.functions.samples;&lt;BR /&gt;
  function impl_volty( opt_price, E, t, F, r,N);&lt;BR /&gt;
&lt;BR /&gt;
array opts[5] initial abconv relconv maxiter&lt;BR /&gt;
( .5 .001 1.0e-6 100 ) ;&lt;BR /&gt;
  &lt;BR /&gt;
bsvolty = solve( "Eurocall", opts, opt_price, E,&lt;BR /&gt;
t, F, r,N, . );&lt;BR /&gt;
return (bsvolty);&lt;BR /&gt;
&lt;BR /&gt;
put 'Option Implied Volatility:'  bsvolty&lt;BR /&gt;
'Initial value: ' opts[1]&lt;BR /&gt;
'Solve status: ' opts[5];&lt;BR /&gt;
endsub;&lt;BR /&gt;
run;&lt;BR /&gt;
data data2;&lt;BR /&gt;
 set data1;&lt;BR /&gt;
 implty=impl_volty(opt_price, E, t, F, r,N);&lt;BR /&gt;
run;&lt;BR /&gt;
*************************************************&lt;BR /&gt;
the log file have problem as follow:&lt;BR /&gt;
ERROR: An ARRAY index is out of bounds in function 'Eurocall' in statement number 9 at line 13 column 1.&lt;BR /&gt;
       The statement was:&lt;BR /&gt;
    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)) -&lt;BR /&gt;
(F=1010) )&lt;BR /&gt;
ERROR: Exception occurred during subroutine call.&lt;BR /&gt;
E=1121.22 F=1010 t=0.106776181 opt_price=119 r=0.011172599 implty=. _ERROR_=1 _N_=15&lt;BR /&gt;
***************************************************&lt;BR /&gt;
I can not to solve this wrong in log file,&lt;BR /&gt;
Please give me a sample to solve this problem,&lt;BR /&gt;
Thx!!

Message was edited by: nolonglove</description>
    <pubDate>Tue, 24 May 2011 12:36:01 GMT</pubDate>
    <dc:creator>nolonglove</dc:creator>
    <dc:date>2011-05-24T12:36:01Z</dc:date>
    <item>
      <title>Some problem in binomial pricing on options</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Some-problem-in-binomial-pricing-on-options/m-p/68832#M19726</link>
      <description>This is my code to do binomial pricing on america options,&lt;BR /&gt;
&lt;BR /&gt;
*************************************************************&lt;BR /&gt;
data data1;&lt;BR /&gt;
input  E F	t opt_price 	r ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1108.48	995	0.041067762	114	0.01107094 &lt;BR /&gt;
1122.22	995	0.032854209	127	0.011018561 &lt;BR /&gt;
1123.67	995	0.030116359	129	0.01098864 &lt;BR /&gt;
1126.33	995	0.027378508	131	0.01092533 &lt;BR /&gt;
1131.92	995	0.024640657	137	0.010853256 &lt;BR /&gt;
1121.86	995	0.021902806	127	0.0108289 &lt;BR /&gt;
1127.23	995	0.013689254	132	0.010809861 &lt;BR /&gt;
1121.22	995	0.010951403	126	0.010954211 &lt;BR /&gt;
1122.22	1010	0.128678987	123	0.011561104 &lt;BR /&gt;
1123.67	1010	0.125941136	124	0.011490423 &lt;BR /&gt;
1126.33	1010	0.123203285	126	0.011465478 &lt;BR /&gt;
1131.92	1010	0.120465435	130	0.011459139 &lt;BR /&gt;
1121.86	1010	0.117727584	121	0.011313808 &lt;BR /&gt;
1127.23	1010	0.109514031	124	0.011324488 &lt;BR /&gt;
1121.22	1010	0.106776181	119	0.011172599 &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc fcmp outlib = work.functions.samples;&lt;BR /&gt;
    function Eurocall(E, t, F, r, sigma, N);&lt;BR /&gt;
        deltaT=T/N;&lt;BR /&gt;
        u=exp(sigma*sqrt(deltaT));&lt;BR /&gt;
        d=1/u;&lt;BR /&gt;
        p=(exp(r*deltaT)-d)/(u-d);&lt;BR /&gt;
        array tree[1]/ nosymbols;&lt;BR /&gt;
        call dynamic_array(tree, n+1, n+1);&lt;BR /&gt;
        call zeromatrix(tree);&lt;BR /&gt;
        &lt;BR /&gt;
        do i=0 to N;&lt;BR /&gt;
            tree[i+1,N+1]=max(0 , E*(u**i)*(d**(N-i)) - F);&lt;BR /&gt;
        end;&lt;BR /&gt;
        do j=(N-1) to 0 by -1;&lt;BR /&gt;
            do  i=0 to j by 1;&lt;BR /&gt;
                tree[i+1,j+1] = exp(-r*deltaT)* (p * tree[i+2,j+2] + (1-p) * tree[i+1,j+2]);&lt;BR /&gt;
            end;  &lt;BR /&gt;
        end;&lt;BR /&gt;
        price = tree[1,1];&lt;BR /&gt;
        return(price);&lt;BR /&gt;
    endsub;&lt;BR /&gt;
run;&lt;BR /&gt;
options cmplib=work.functions.samples;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc fcmp outlib=work.functions.samples;&lt;BR /&gt;
  function impl_volty( opt_price, E, t, F, r,N);&lt;BR /&gt;
&lt;BR /&gt;
array opts[5] initial abconv relconv maxiter&lt;BR /&gt;
( .5 .001 1.0e-6 100 ) ;&lt;BR /&gt;
  &lt;BR /&gt;
bsvolty = solve( "Eurocall", opts, opt_price, E,&lt;BR /&gt;
t, F, r,N, . );&lt;BR /&gt;
return (bsvolty);&lt;BR /&gt;
&lt;BR /&gt;
put 'Option Implied Volatility:'  bsvolty&lt;BR /&gt;
'Initial value: ' opts[1]&lt;BR /&gt;
'Solve status: ' opts[5];&lt;BR /&gt;
endsub;&lt;BR /&gt;
run;&lt;BR /&gt;
data data2;&lt;BR /&gt;
 set data1;&lt;BR /&gt;
 implty=impl_volty(opt_price, E, t, F, r,N);&lt;BR /&gt;
run;&lt;BR /&gt;
*************************************************&lt;BR /&gt;
the log file have problem as follow:&lt;BR /&gt;
ERROR: An ARRAY index is out of bounds in function 'Eurocall' in statement number 9 at line 13 column 1.&lt;BR /&gt;
       The statement was:&lt;BR /&gt;
    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)) -&lt;BR /&gt;
(F=1010) )&lt;BR /&gt;
ERROR: Exception occurred during subroutine call.&lt;BR /&gt;
E=1121.22 F=1010 t=0.106776181 opt_price=119 r=0.011172599 implty=. _ERROR_=1 _N_=15&lt;BR /&gt;
***************************************************&lt;BR /&gt;
I can not to solve this wrong in log file,&lt;BR /&gt;
Please give me a sample to solve this problem,&lt;BR /&gt;
Thx!!

Message was edited by: nolonglove</description>
      <pubDate>Tue, 24 May 2011 12:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Some-problem-in-binomial-pricing-on-options/m-p/68832#M19726</guid>
      <dc:creator>nolonglove</dc:creator>
      <dc:date>2011-05-24T12:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: Some problem in binomial pricing on options</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Some-problem-in-binomial-pricing-on-options/m-p/68833#M19727</link>
      <description>Hello Nologlove,&lt;BR /&gt;
&lt;BR /&gt;
I found a formal error in your code:&lt;BR /&gt;
&lt;BR /&gt;
call dynamic_array(tree, n+1, n+1);&lt;BR /&gt;
&lt;BR /&gt;
implies that tree contains n+1 elements but &lt;BR /&gt;
&lt;BR /&gt;
do i=0 to N;&lt;BR /&gt;
   tree[i+1,N+1]=max(0 , E*(u**i)*(d**(N-i)) - F);&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
uses n+2 elements. Changing &lt;BR /&gt;
&lt;BR /&gt;
call dynamic_array(tree, n+2, n+2);&lt;BR /&gt;
&lt;BR /&gt;
runs the program without errors but with a few notes.&lt;BR /&gt;
&lt;BR /&gt;
HTH, &lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 25 May 2011 14:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Some-problem-in-binomial-pricing-on-options/m-p/68833#M19727</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-25T14:09:47Z</dc:date>
    </item>
  </channel>
</rss>

