0

I want to calculate the skew of a timeseries (stock returns) of the previous 30 days on a rolling basis (thus, getting daily values).

Dataset looks like:

Stock   date    month   year    return
1SF7    1/07/2016   7   2016    0.94
1SF7    5/07/2016   7   2016    0.91
1SF7    6/07/2016   7   2016    0.82
1SF7    7/07/2016   7   2016    0.95

..........

Currently, I tried proc means and just calculate month-end skewness

            proc means data=have; by year month;
                output out= want (drop= _freq_ _type_ ) skew(return)=Skew_monthly; 
            run;

Anyone has an idea for rolling skewness? I know there is a question here that asks for rolling skewness, but the answer to that only outputs one value per 30 days, but I want daily values.

Thankful for any input! Marc

MaBo88
  • 97
  • 1
  • 1
  • 9
  • Do you have SAS/ETS? If so, look at PROC EXPAND. Please post what you've tried as well. – Reeza Feb 19 '17 at 08:06
  • Possible duplicate of [Calculating moving average/stdev in SAS?](http://stackoverflow.com/questions/2460970/calculating-moving-average-stdev-in-sas) – Reeza Feb 19 '17 at 08:11
  • 1
    If not, this is for min/max but can easily be extended for skewness. https://gist.github.com/statgeek/27e23c015eae7953eff2 – Reeza Feb 19 '17 at 08:13

1 Answers1

0

Thanks, I managed it with the array version:

data want; array p{0:29} _temporary_;
    set have; by symbol;
        if symbol then call missing(of p{*});
            p{mod(_n_,30)} = return;
                skew = skewness(of p{*});
run;
MaBo88
  • 97
  • 1
  • 1
  • 9
  • 1
    I'm not sure if that IF statement is correct. Make sure to double check your answer. If expect it to be if FIRST.Symbol ... – Reeza Feb 20 '17 at 11:42
  • Reezea, you're absolutely right. It's first.symbol. Thanks! – MaBo88 Feb 21 '17 at 23:11