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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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