<?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 Re: How to replace variable for matching right opt_price in my marco?? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-replace-variable-for-matching-right-opt-price-in-my-marco/m-p/68214#M19530</link>
    <description>Did you have a working version of this procedure without the macro approach?</description>
    <pubDate>Mon, 23 May 2011 17:06:03 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2011-05-23T17:06:03Z</dc:date>
    <item>
      <title>How to replace variable for matching right opt_price in my marco??</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-replace-variable-for-matching-right-opt-price-in-my-marco/m-p/68213#M19529</link>
      <description>This is my SAS marco to calculate american  put or call by Cox-Ross-Rubinstein method:&lt;BR /&gt;
&lt;BR /&gt;
Macro to Calculate the call Intrinsic Option Value at Each NodeThis &lt;BR /&gt;
&lt;BR /&gt;
%macro cval(si,xi);&lt;BR /&gt;
  (&amp;amp;si-ξ+abs(&amp;amp;si-ξ))/2&lt;BR /&gt;
%mend cval;&lt;BR /&gt;
* Macro to Calculate the callOption Price at Each Node;&lt;BR /&gt;
%macro c(ni,ss);&lt;BR /&gt;
  %if ∋=&amp;amp;n %then &lt;BR /&gt;
   %do;&lt;BR /&gt;
      %cval (&amp;amp;ss,&amp;amp;x)&lt;BR /&gt;
   %end;&lt;BR /&gt;
      %else %do;&lt;BR /&gt;
          max(%cval(&amp;amp;ss,&amp;amp;x),((%c(∋+1,&amp;amp;ss*&amp;amp;u))*&amp;amp;p+(%c(∋+1,&amp;amp;ss*&amp;amp;d))*(1-&amp;amp;p))/&amp;amp;rq)&lt;BR /&gt;
      %end;&lt;BR /&gt;
%mend c; &lt;BR /&gt;
* Macro to Calculate the put Intrinsic Option Value at Each Node;&lt;BR /&gt;
%macro pval(si,xi);&lt;BR /&gt;
  (&amp;amp;xi-&amp;amp;si+abs(&amp;amp;xi-&amp;amp;si))/2&lt;BR /&gt;
%mend pval;&lt;BR /&gt;
&lt;BR /&gt;
* Macro to Calculate the put Option Price at Each Node;&lt;BR /&gt;
%macro p(ni,ss);&lt;BR /&gt;
  %if ∋=&amp;amp;n %then &lt;BR /&gt;
   %do;&lt;BR /&gt;
      %pval (&amp;amp;ss,&amp;amp;x)&lt;BR /&gt;
   %end;&lt;BR /&gt;
      %else %do;&lt;BR /&gt;
          max(%pval(&amp;amp;ss,&amp;amp;x),((%p(∋+1,&amp;amp;ss*&amp;amp;u))*&amp;amp;p+(%p(∋+1,&amp;amp;ss*&amp;amp;d))*(1-&amp;amp;p))/&amp;amp;rq)&lt;BR /&gt;
      %end;&lt;BR /&gt;
%mend p; &lt;BR /&gt;
&lt;BR /&gt;
data data1;&lt;BR /&gt;
input  eq_price	strike	time	opt_price	intrate;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1108.48	995	0.041067762	0.8	0.01107094&lt;BR /&gt;
1122.22	995	0.032854209	0.35	0.011018561&lt;BR /&gt;
1123.67	995	0.030116359	0.3	0.01098864&lt;BR /&gt;
1126.33	995	0.027378508	0.2	0.01092533&lt;BR /&gt;
1131.92	995	0.024640657	0.2	0.010853256&lt;BR /&gt;
1121.86	995	0.021902806	0.175	0.0108289&lt;BR /&gt;
1127.23	995	0.013689254	0.075	0.010809861&lt;BR /&gt;
1121.22	995	0.010951403	0.1	0.010954211&lt;BR /&gt;
1122.22	1010	0.128678987	3.5	0.011561104&lt;BR /&gt;
1123.67	1010	0.125941136	3	0.011490423&lt;BR /&gt;
1126.33	1010	0.123203285	2.4	0.011465478&lt;BR /&gt;
1131.92	1010	0.120465435	2.4	0.011459139&lt;BR /&gt;
1121.86	1010	0.117727584	3.1	0.011313808&lt;BR /&gt;
1127.23	1010	0.109514031	2.45	0.011324488&lt;BR /&gt;
1121.22	1010	0.106776181	2.9	0.011172599&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
* Set the Option Variables and Call the Macros;&lt;BR /&gt;
data b;&lt;BR /&gt;
set data1;&lt;BR /&gt;
  %let s=eq_price; * underlying security price;&lt;BR /&gt;
  %let x=strike; * strike price;&lt;BR /&gt;
  %let n=7; * nt = n = number of subperiods;&lt;BR /&gt;
  %let t=time; * time to maturity, in years;&lt;BR /&gt;
  %let h=&amp;amp;t/&amp;amp;n;* it=h=T/n= size of the sub-period;&lt;BR /&gt;
  %let r=intrate; * r = continuously compounded risk free rate;&lt;BR /&gt;
  %let q=0.0254; * dividend yield;&lt;BR /&gt;
  %let sig=0.24; *implied Volatility;&lt;BR /&gt;
&lt;BR /&gt;
  %let u =exp(&amp;amp;sig*sqrt(&amp;amp;h));&lt;BR /&gt;
  %let d =exp(-&amp;amp;sig*sqrt(&amp;amp;h));&lt;BR /&gt;
  %let rq=exp((&amp;amp;r-&amp;amp;q)*&amp;amp;h);&lt;BR /&gt;
  %let p =(&amp;amp;rq-&amp;amp;d)/(&amp;amp;u-&amp;amp;d);&lt;BR /&gt;
&lt;BR /&gt;
  p=%p(0,&amp;amp;s);&lt;BR /&gt;
  c=%c(0,&amp;amp;s);&lt;BR /&gt;
  output;&lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
and the out put is&lt;BR /&gt;
&lt;BR /&gt;
                                            The SAS System            11:42 Saturday, May 21, 2011   5&lt;BR /&gt;
&lt;BR /&gt;
            Obs    eq_price    strike      time     opt_price     intrate       p        c&lt;BR /&gt;
&lt;BR /&gt;
             1     1108.48      995     0.04107    0.800    0.011071    0.17516    113.487&lt;BR /&gt;
             2     1122.22      995     0.03285    0.350    0.011019    0.00000    127.220&lt;BR /&gt;
             3     1123.67      995     0.03012    0.300    0.010989    0.00000    128.670&lt;BR /&gt;
             4     1126.33      995     0.02738    0.200    0.010925    0.00000    131.330&lt;BR /&gt;
             5     1131.92      995     0.02464    0.200    0.010853    0.00000    136.920&lt;BR /&gt;
             6     1121.86      995     0.02190    0.175    0.010829    0.00000    126.860&lt;BR /&gt;
             7     1127.23      995     0.01369    0.075    0.010810    0.00000    132.230&lt;BR /&gt;
             8     1121.22      995     0.01095    0.100    0.010954    0.00000    126.220&lt;BR /&gt;
             9     1122.22     1010     0.12868    3.500    0.011561    4.54713    115.75&lt;BR /&gt;
            10     1123.67     1010     0.12594    3.000    0.011490    4.33255    117.00&lt;BR /&gt;
            11     1126.33     1010     0.12320    2.400    0.011465    4.04350    119.39&lt;BR /&gt;
            12     1131.92     1010     0.12047    2.400    0.011459    3.57726    124.54&lt;BR /&gt;
            13     1121.86     1010     0.11773    3.100    0.011314    4.04854    114.96&lt;BR /&gt;
            14     1127.23     1010     0.10951    2.450    0.011324    3.31856    119.67&lt;BR /&gt;
            15     1121.22     1010     0.10678    2.900    0.011173    3.54189    113.90&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
But my marco use the sig which is only at 0.24,at this level, the answer p is not same to opt_price.&lt;BR /&gt;
I want to change sig in my marco util the  answer for p is same to opt_price.&lt;BR /&gt;
&lt;BR /&gt;
please hlep me to solve this problem? &lt;BR /&gt;
Thx!I need help!

Message was edited by: nolonglove</description>
      <pubDate>Sun, 22 May 2011 04:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-replace-variable-for-matching-right-opt-price-in-my-marco/m-p/68213#M19529</guid>
      <dc:creator>nolonglove</dc:creator>
      <dc:date>2011-05-22T04:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace variable for matching right opt_price in my marco??</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-replace-variable-for-matching-right-opt-price-in-my-marco/m-p/68214#M19530</link>
      <description>Did you have a working version of this procedure without the macro approach?</description>
      <pubDate>Mon, 23 May 2011 17:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-replace-variable-for-matching-right-opt-price-in-my-marco/m-p/68214#M19530</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2011-05-23T17:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace variable for matching right opt_price in my marco??</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-replace-variable-for-matching-right-opt-price-in-my-marco/m-p/68215#M19531</link>
      <description>This is another version to calculate the &lt;BR /&gt;
implied bolatility until the put option &lt;BR /&gt;
price issame to opt_price(open markets price);&lt;BR /&gt;
but this way only use to SAS 9.2:&lt;BR /&gt;
data data1;&lt;BR /&gt;
input  eq_price	strike	time	opt_price	intrate;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1108.48	995	0.041067762	0.8	0.01107094&lt;BR /&gt;
1122.22	995	0.032854209	0.35	0.011018561&lt;BR /&gt;
1123.67	995	0.030116359	0.3	0.01098864&lt;BR /&gt;
1126.33	995	0.027378508	0.2	0.01092533&lt;BR /&gt;
1131.92	995	0.024640657	0.2	0.010853256&lt;BR /&gt;
1121.86	995	0.021902806	0.175	0.0108289&lt;BR /&gt;
1127.23	995	0.013689254	0.075	0.010809861&lt;BR /&gt;
1121.22	995	0.010951403	0.1	0.010954211&lt;BR /&gt;
1122.22	1010	0.128678987	3.5	0.011561104&lt;BR /&gt;
1123.67	1010	0.125941136	3	0.011490423&lt;BR /&gt;
1126.33	1010	0.123203285	2.4	0.011465478&lt;BR /&gt;
1131.92	1010	0.120465435	2.4	0.011459139&lt;BR /&gt;
1121.86	1010	0.117727584	3.1	0.011313808&lt;BR /&gt;
1127.23	1010	0.109514031	2.45	0.011324488&lt;BR /&gt;
1121.22	1010	0.106776181	2.9	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 blksch( strike, time, eq_price, intrate, volty );&lt;BR /&gt;
return (blkshptprc( strike, time,eq_price, intrate, volty ));&lt;BR /&gt;
endsub;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
options cmplib=work.functions.samples;&lt;BR /&gt;
&lt;BR /&gt;
proc fcmp outlib=work.functions.samples;&lt;BR /&gt;
  function impl_volty( opt_price, strike, time, eq_price, intrate);&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( "blksch", opts, opt_price, strike,&lt;BR /&gt;
time, eq_price, intrate, .);&lt;BR /&gt;
&lt;BR /&gt;
return (bsvolty);&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;
&lt;BR /&gt;
data data2;&lt;BR /&gt;
 set data1;&lt;BR /&gt;
 implty=impl_volty(opt_price, strike, time, eq_price, intrate);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
In this version, I  use B-S model to &lt;BR /&gt;
find the answer of implied bolatility,&lt;BR /&gt;
but,B-S model have function &lt;BR /&gt;
"blkshptprc( strike, time,eq_price, intrate, volty )" &lt;BR /&gt;
in SAS, and B-S model only use &lt;BR /&gt;
to price the euro options.&lt;BR /&gt;
&lt;BR /&gt;
In my macro prblem, the price of option is &lt;BR /&gt;
America options, it can not use B-S model,&lt;BR /&gt;
it must use binomial method to price. i did&lt;BR /&gt;
not find the function of "Binomial method " &lt;BR /&gt;
in SAS , so i use  macro to calculat the &lt;BR /&gt;
America put price.&lt;BR /&gt;
Finally, i need help to slove this problem for any way!&lt;BR /&gt;
THX!&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: nolonglove&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: nolonglove

Message was edited by: nolonglove</description>
      <pubDate>Mon, 23 May 2011 19:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-replace-variable-for-matching-right-opt-price-in-my-marco/m-p/68215#M19531</guid>
      <dc:creator>nolonglove</dc:creator>
      <dc:date>2011-05-23T19:51:12Z</dc:date>
    </item>
  </channel>
</rss>

