<?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: Annual buy and hold return computation from monthly return in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/296579#M62167</link>
    <description>Thank you for your kind response&lt;BR /&gt;&lt;BR /&gt;It will be grateful if you can provide further guidance regarding how to obtain annual holding return in three months after fiscal year-end. How can I revise your code that produces annual buy and hold return using monthly return.&lt;BR /&gt;&lt;BR /&gt;For instance, if fiscal year-end is 12/31/2014,&lt;BR /&gt;&lt;BR /&gt;beginning date (begdate): 04/01/2014&lt;BR /&gt;ending date (enddate)? : 03/31/2015&lt;BR /&gt;Thanks again for your help&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 05 Sep 2016 17:08:25 GMT</pubDate>
    <dc:creator>kimx0961</dc:creator>
    <dc:date>2016-09-05T17:08:25Z</dc:date>
    <item>
      <title>Annual buy and hold return computation from monthly return</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/296195#M61992</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to compute annual buy and hold return using monthly return like the following.&lt;/P&gt;&lt;P&gt;annual ruturn = (1+January return)(1+February return)(1+March return)-----(1+December return) - 1&lt;/P&gt;&lt;P&gt;The data structure I have is as follows:&lt;/P&gt;&lt;P&gt;gvkey&amp;nbsp;&amp;nbsp;&amp;nbsp; year month monthly return&lt;/P&gt;&lt;P&gt;00001&amp;nbsp;&amp;nbsp; 2000&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.002&lt;/P&gt;&lt;P&gt;00001&amp;nbsp;&amp;nbsp; 2000&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.001&lt;/P&gt;&lt;P&gt;00001&amp;nbsp;&amp;nbsp; 2000&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.003&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have a simple SAS code I can refer using retain statement (without using macro)?&lt;/P&gt;&lt;P&gt;Thank you for your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 18:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/296195#M61992</guid>
      <dc:creator>kimx0961</dc:creator>
      <dc:date>2016-09-02T18:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Annual buy and hold return computation from monthly return</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/296205#M61996</link>
      <description>&lt;P&gt;This should do what you want but the value is only going to be for the entire year if the last value in each year corresponds to Dec.&lt;/P&gt;
&lt;P&gt;I assumed that since you have a key value that you wanted this for each key and that the data is sorted by gvkey year and month.&lt;/P&gt;
&lt;P&gt;If you only want the final value add at the end of the datastep: If Last.year then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by gvkey year;
   retain AnReturn;
   if first.year then AnReturn= (1+ MonthReturn);
   else AnReturn= AnReturn*(1+MonthReturn);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However&amp;nbsp;I suspect you are going to run into precision problems (under flow). you may need to consider an approach with logs or shift ot integer arithmetic and shift back.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 19:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/296205#M61996</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-02T19:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Annual buy and hold return computation from monthly return</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/296579#M62167</link>
      <description>Thank you for your kind response&lt;BR /&gt;&lt;BR /&gt;It will be grateful if you can provide further guidance regarding how to obtain annual holding return in three months after fiscal year-end. How can I revise your code that produces annual buy and hold return using monthly return.&lt;BR /&gt;&lt;BR /&gt;For instance, if fiscal year-end is 12/31/2014,&lt;BR /&gt;&lt;BR /&gt;beginning date (begdate): 04/01/2014&lt;BR /&gt;ending date (enddate)? : 03/31/2015&lt;BR /&gt;Thanks again for your help&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Sep 2016 17:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/296579#M62167</guid>
      <dc:creator>kimx0961</dc:creator>
      <dc:date>2016-09-05T17:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Annual buy and hold return computation from monthly return</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/665120#M198807</link>
      <description>data want;&lt;BR /&gt;set have;&lt;BR /&gt;ln_return = log(monthlyreturn+1);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data = want by permno year month;&lt;BR /&gt;&lt;BR /&gt;proc means data = have noprint;&lt;BR /&gt;by gvkey year;&lt;BR /&gt;var ln_return;&lt;BR /&gt;output out = want1 sum = ln_annreturn;&lt;BR /&gt;annreturn = exp(ln_annreturn) - 1;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 25 Jun 2020 18:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/665120#M198807</guid>
      <dc:creator>xiaobao</dc:creator>
      <dc:date>2020-06-25T18:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Annual buy and hold return computation from monthly return</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/665241#M198877</link>
      <description>&lt;P&gt;If YEAR designates fiscal year, then you want to accumulate up through the 3rd record following the last month record for a given year, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bhret;
  set have;
  by gvkey year;
  bhret+log(1+ret);
  if lag3(last.year);
  bhret=exp(bhret)-1;
  output;
  call missing bhret;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note this assumes that there are no missing monthly returns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But maybe (you're using Compustat data right?) you have a variable FYR indicating the month number for the end of fiscal year (i.e. if FYR=6 then fiscal year ends in June).&amp;nbsp; If so, then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bhret;
  set have;
  by gvkey;
  bhret+log(1+ret);
  if lag3(month)=fyr;
  bhret=exp(bhret)-1;
  output;
  call missing bhret;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This also assume no missing months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The&amp;nbsp; "bhret+log(1+ret);" is a "summing statement", which tells sas to retain the resulting value in variable bhret.&amp;nbsp; I.e. don't automatically reset bhret to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The "if lag3(...)" statement is a subsetting if, keeping only those records in which the 3rd preceding record satisfy the specified condition.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; One a record is output, the programmer now needs to reset the bhret to missing, so every record has only results built on record following the previous annual return.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 04:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Annual-buy-and-hold-return-computation-from-monthly-return/m-p/665241#M198877</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-06-26T04:47:46Z</dc:date>
    </item>
  </channel>
</rss>

