<?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 3 months rolling volatility in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/3-months-rolling-volatility/m-p/752811#M237168</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hi Experts, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am going to calculate sigma following the paper Campbell et al. (2008), where he defines sigma as&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ruhul_0-1625734220759.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61060i20DA59AD43C349DE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ruhul_0-1625734220759.png" alt="Ruhul_0-1625734220759.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Where r^2 is the firm-level daily return and N is the number of trading days in three months period. K is the index of trading days in months t-1, t-2, t-3.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;They require a firm have at least 5 nonzero daily observations. In this case, they report sigma as missing and replace it with the annual cross-sectional mean.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the attached code (I do not have much idea of such hash function), can you look into this and tell me whether the 3 months rolling volatility/standard deviation calculated perfectly or not and how can I annualize it? I am attaching the code and data for you. If you think there is any other efficient way or the code need modification please post it. Thanks in advance.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Link of the paper:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://scholar.harvard.edu/files/campbell/files/campbellhilscherszilagyi_jf2008.pdf" target="_blank" rel="nofollow noopener noreferrer"&gt;https://scholar.harvard.edu/files/campbell/files/campbellhilscherszilagyi_jf2008.pdf&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Portion of code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;if 0 then set have(rename=(ret=_ret));&lt;BR /&gt;declare hash h(multidata:'y');&lt;BR /&gt;h.definekey('Date');&lt;BR /&gt;h.definedata('_ret');&lt;BR /&gt;h.definedone();&lt;/P&gt;
&lt;P&gt;/**********/&lt;BR /&gt;declare hash m();&lt;BR /&gt;m.definekey('_monyy');&lt;BR /&gt;m.definedata('_ret');&lt;BR /&gt;m.definedone();&lt;BR /&gt;/**********/&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;array x{100} _temporary_;&lt;BR /&gt;do until(last.PERMNO);&lt;BR /&gt;set have;&lt;BR /&gt;by PERMNO;&lt;BR /&gt;_ret=ret;h.add();&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;do until(last.PERMNO);&lt;BR /&gt;set have;&lt;BR /&gt;by PERMNO;&lt;BR /&gt;n=0;call missing(of x{*});&lt;BR /&gt;m.clear(); /**&amp;lt;---***/&lt;BR /&gt;do i=intnx('month',monyy,-3) to intnx('month',monyy,-1,'e');&lt;BR /&gt;rc=h.find(key:i);&lt;BR /&gt;do while(rc=0);&lt;BR /&gt;if not missing(_RET) then do;n+1;x{n}=_ret; _monyy=intnx('month',i,0); m.replace(); end; /**&amp;lt;---***/&lt;BR /&gt;rc=h.find_next(key:i);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;std=std(of x{*});&lt;BR /&gt;if n&amp;lt;5 then std=.; /**&amp;lt;-----****/&lt;BR /&gt;if m.num_items&amp;lt;3 then std=.; /**&amp;lt;----EDIT HERE-****/&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jul 2021 09:06:00 GMT</pubDate>
    <dc:creator>Ramin1</dc:creator>
    <dc:date>2021-07-08T09:06:00Z</dc:date>
    <item>
      <title>3 months rolling volatility</title>
      <link>https://communities.sas.com/t5/SAS-Programming/3-months-rolling-volatility/m-p/752811#M237168</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi Experts, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am going to calculate sigma following the paper Campbell et al. (2008), where he defines sigma as&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ruhul_0-1625734220759.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61060i20DA59AD43C349DE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ruhul_0-1625734220759.png" alt="Ruhul_0-1625734220759.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Where r^2 is the firm-level daily return and N is the number of trading days in three months period. K is the index of trading days in months t-1, t-2, t-3.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;They require a firm have at least 5 nonzero daily observations. In this case, they report sigma as missing and replace it with the annual cross-sectional mean.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the attached code (I do not have much idea of such hash function), can you look into this and tell me whether the 3 months rolling volatility/standard deviation calculated perfectly or not and how can I annualize it? I am attaching the code and data for you. If you think there is any other efficient way or the code need modification please post it. Thanks in advance.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Link of the paper:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://scholar.harvard.edu/files/campbell/files/campbellhilscherszilagyi_jf2008.pdf" target="_blank" rel="nofollow noopener noreferrer"&gt;https://scholar.harvard.edu/files/campbell/files/campbellhilscherszilagyi_jf2008.pdf&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Portion of code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;if 0 then set have(rename=(ret=_ret));&lt;BR /&gt;declare hash h(multidata:'y');&lt;BR /&gt;h.definekey('Date');&lt;BR /&gt;h.definedata('_ret');&lt;BR /&gt;h.definedone();&lt;/P&gt;
&lt;P&gt;/**********/&lt;BR /&gt;declare hash m();&lt;BR /&gt;m.definekey('_monyy');&lt;BR /&gt;m.definedata('_ret');&lt;BR /&gt;m.definedone();&lt;BR /&gt;/**********/&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;array x{100} _temporary_;&lt;BR /&gt;do until(last.PERMNO);&lt;BR /&gt;set have;&lt;BR /&gt;by PERMNO;&lt;BR /&gt;_ret=ret;h.add();&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;do until(last.PERMNO);&lt;BR /&gt;set have;&lt;BR /&gt;by PERMNO;&lt;BR /&gt;n=0;call missing(of x{*});&lt;BR /&gt;m.clear(); /**&amp;lt;---***/&lt;BR /&gt;do i=intnx('month',monyy,-3) to intnx('month',monyy,-1,'e');&lt;BR /&gt;rc=h.find(key:i);&lt;BR /&gt;do while(rc=0);&lt;BR /&gt;if not missing(_RET) then do;n+1;x{n}=_ret; _monyy=intnx('month',i,0); m.replace(); end; /**&amp;lt;---***/&lt;BR /&gt;rc=h.find_next(key:i);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;std=std(of x{*});&lt;BR /&gt;if n&amp;lt;5 then std=.; /**&amp;lt;-----****/&lt;BR /&gt;if m.num_items&amp;lt;3 then std=.; /**&amp;lt;----EDIT HERE-****/&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 09:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/3-months-rolling-volatility/m-p/752811#M237168</guid>
      <dc:creator>Ramin1</dc:creator>
      <dc:date>2021-07-08T09:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: 3 months rolling volatility</title>
      <link>https://communities.sas.com/t5/SAS-Programming/3-months-rolling-volatility/m-p/753066#M237300</link>
      <description>&lt;P&gt;Have you checked with a few dozen test records that the calculations are performed as you expect?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 05:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/3-months-rolling-volatility/m-p/753066#M237300</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-09T05:29:51Z</dc:date>
    </item>
  </channel>
</rss>

