BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
somebody
Lapis Lazuli | Level 10

How can I calculate the standard deviation of returns over the past 12 months? I have a dataset of daily observations. I have a yearmonth variable. I can use PROC EXPAND and get a rolling standard deviation over the past 252 days using the following code: 

PROC EXPAND DATA=daily_returns OUT=daily_returns2;

CONVERT return=std / TRANSFORMOUT=(MOVSTD 252);

by stock;

RUN;

This would work for most cases, but what if a stock halts trading for several months, this would include returns of days that are more than 1 year ago. I want to use only observations that are strictly within the past 12 months.

Another related issue is that, say a stock stops trading for more than a year, and then reappear. These days without trading would still appear in my dataset with missing values for returns. However, my code still returns the rolling standard deviation values for these observations when it should not. How can I solve this?

1 ACCEPTED SOLUTION

Accepted Solutions
tomrvincent
Rhodochrosite | Level 12
Create a table that fills in any missing dates for each stock ahead of time.

View solution in original post

1 REPLY 1
tomrvincent
Rhodochrosite | Level 12
Create a table that fills in any missing dates for each stock ahead of time.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 861 views
  • 0 likes
  • 2 in conversation