<?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: Computing zero-centered standard deviation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613982#M179407</link>
    <description>&lt;P&gt;I know that the formulas are the same. What I mean difference is r. In the latter, r are just normal returns, whereas in the former, I think r are standardized (de-meaned).&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Dec 2019 21:26:23 GMT</pubDate>
    <dc:creator>somebody</dc:creator>
    <dc:date>2019-12-26T21:26:23Z</dc:date>
    <item>
      <title>Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613699#M179263</link>
      <description>&lt;P&gt;I am trying to replicate a finance paper in which standard deviation is computed differently to the traditional way. Accordingly,&lt;/P&gt;&lt;P&gt;"To measure the volatility of a firm’s stock returns, we use a proxy, centered around zero rather than the rolling 3-month mean, for daily variation of returns&amp;nbsp;computed as an annualized 3-month rolling sample standard deviation:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 374px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35028iCCBE8848D1481D1E/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;where t denotes month. How do I compute this metric? Do I use PROC STANDARD to make returns be centered around zero? and then compute rolling standard deviation?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the link to the paper if you are interested:&lt;/P&gt;&lt;P&gt;&lt;A href="https://scholar.harvard.edu/files/campbell/files/campbellhilscherszilagyi_jf2008.pdf" target="_blank"&gt;https://scholar.harvard.edu/files/campbell/files/campbellhilscherszilagyi_jf2008.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 07:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613699#M179263</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2019-12-24T07:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613718#M179276</link>
      <description>&lt;P&gt;Standard deviation centered around zero instead of the mean ... the square of this found by the USS() function in a data step, or the USS option in PROC MEANS/PROC SUMMARY.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 11:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613718#M179276</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-24T11:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613725#M179283</link>
      <description>&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 12:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613725#M179283</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-24T12:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613728#M179285</link>
      <description>&lt;P&gt;If you want exact that formula combine the USS function and the LAG1, LAG2, and LAG3 functions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input Y @@;
t = _N_;
datalines;
4 5 6 5 7 6 4 3 4 6 3 5 7 7 7 8 7 6 7
;

data Want;
set Have nobs=N;
Y1 = lag1(Y); Y2 = lag2(Y); Y3 = lag3(Y); 
sigma3 = sqrt(252/(N-1) * uss(Y1, Y2, Y3));
run;

proc sgplot data=Want;
series x=t y=sigma3;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2019 12:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613728#M179285</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-12-24T12:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613843#M179336</link>
      <description>&lt;P&gt;Thanks. But doesnt&amp;nbsp;it have to be calculated using daily returns? I think your code uses monthly standard deviation of past 3 months. This is also the part that I dont understand &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 02:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613843#M179336</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2019-12-26T02:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613861#M179350</link>
      <description>&lt;P&gt;Here is another paper doing the same thing ( I think they are different).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35041iE27CE8FB0F562E0B/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 07:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613861#M179350</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2019-12-26T07:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613881#M179362</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/98381"&gt;@somebody&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks. But doesnt&amp;nbsp;it have to be calculated using daily returns? I think your code uses monthly standard deviation of past 3 months. This is also the part that I dont understand&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't see why you say this. Nothing in Rick's code indicates that it uses monthly returns. Nothing indicates it uses daily returns. His answer is general, not specific to a given time period. If you need it to work on daily returns, you can do the calculations based on daily returns; if you want it to work on monthly returns, you can do the calculations on monthly returns.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 11:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613881#M179362</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-26T11:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613886#M179365</link>
      <description>&lt;P&gt;I guess the question is what are the r_k values and what is the range of the index k?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you talk to your manager/mentor/advisor and figure out what you want to compute. After you know what you want to compute, provide example data and we can help you compute it in SAS.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 11:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613886#M179365</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-12-26T11:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613966#M179400</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/98381"&gt;@somebody&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Here is another paper doing the same thing ( I think they are different).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35041iE27CE8FB0F562E0B/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To be just slightly obnoxious, if you think the formula here and in your first post are different then you need a serious refresher of mathematic symbiology.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;(&amp;lt;values&amp;gt;) to the 1/2 power IS square root,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;252* 1/(n-1) is the same as 252/(n-1)&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 20:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613966#M179400</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-26T20:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613982#M179407</link>
      <description>&lt;P&gt;I know that the formulas are the same. What I mean difference is r. In the latter, r are just normal returns, whereas in the former, I think r are standardized (de-meaned).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 21:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613982#M179407</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2019-12-26T21:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613984#M179408</link>
      <description>&lt;P&gt;I think k indexes the trading days. So to compute this, we use all trading days within that past 3 months. I can use PROC EXPAND to compute rolling standard deviation. However, how can I tell SAS just look at the past 3 months rather than using previous 66 obs (assuming 22 trading days in a month)&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 21:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613984#M179408</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2019-12-26T21:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613989#M179410</link>
      <description>&lt;P&gt;&amp;gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;EM&gt;how can I tell SAS just look at the past 3 months rather than using previous 66 obs (assuming 22 trading days in a month)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each date in your data, &lt;A href="https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html" target="_self"&gt;use the INTNX function to compute the "3 month prior" date.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;For example, the following DATA step tells you the beginning of the three-month window for three dates in 2019.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
Use the INTCK and INTNX functions:
https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html
*/
data Trade3;
input TradeDate anydtdte12.;
BeginDate = intnx('month', TradeDate, -3, 'same');
format TradeDate BeginDate DATE9.;
datalines;
Mar 4, 2019
Apr 30, 2019
Dec 14, 2019
;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Dec 2019 21:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613989#M179410</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-12-26T21:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613990#M179411</link>
      <description>&lt;P&gt;Thanks. But how do I tell PROC EXPAND to use obs within the past 3 months? I would use the following code to compute rolling standard deviation&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC EXPAND DATA=sigma OUT=sigma method=none;
	convert r=r_moving_sum / TRANSFORMOUT= (MOVSTD 66);
	by stock;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This would work if we have all trading days. However, some stocks don't trade often. For example, stock XYZ trade 20 days over the past 3 months, say from 1 June to 31 August. So on 1st Sep, I would like to use only those 20 trading days. But the code above would include other trading days prior to 1 June. Can I restrict PROC EXPAND to use only the past 3 months? if so, How?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 22:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/613990#M179411</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2019-12-26T22:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/614000#M179414</link>
      <description>&lt;P&gt;Since you want to compute a nonstandard rolling statistic, I suspect you will have to program this statistic yourself by using the DATA step or PROC IML. For DATA step techniques, see the references in the article &lt;A href="https://blogs.sas.com/content/iml/2016/01/27/moving-average-in-sas.html" target="_self"&gt;"Compute a moving average in SAS."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I suspect PROC IML will be easier if you know vector/matrix programming. For SAS/IML tips, see the article, &lt;A href="https://blogs.sas.com/content/iml/2016/02/03/rolling-statistics-sasiml.html" target="_self"&gt;"Rolling statistics in SAS/IML."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 00:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/614000#M179414</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-12-27T00:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/752736#M237145</link>
      <description>&lt;P&gt;Hi Rick, I am going to calculate sigma following the above-mentioned paper in the posted question Campbell et al. (2008),&lt;BR /&gt;I have the attached code, 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 then you can post it. Thanks in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 21:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/752736#M237145</guid>
      <dc:creator>Ramin1</dc:creator>
      <dc:date>2021-07-07T21:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Computing zero-centered standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/752737#M237146</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;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?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are asking the wrong person. Your computation uses hash objects and DATA step arrays, so you should talk to someone who is skilled in using those tools.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 21:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-zero-centered-standard-deviation/m-p/752737#M237146</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-07-07T21:32:25Z</dc:date>
    </item>
  </channel>
</rss>

