BookmarkSubscribeRSS Feed
Akarsh91
Calcite | Level 5

Dear experts, 

 

I have the following data: 

 

data have;
  infile datalines dlm=',' dsd truncover;
  input ID Date:anydtdte. Returns Delisting_return month newmonth year;
  format date date9.;
  datalines;
1,1968-01-28,1.01,,1,10,1968
1,1968-02-28,1.04,,2,11,1968
1,1968-03-28,1.001,,3,12,1968
1,1968-04-28,1.005,,4,01,1968
1,1968-05-28,1.02,,5,02,1968
1,1968-06-28,1.02,,6,03,1968
1,1968-07-28,1.06,,7,04,1968
1,1968-08-28,1.06,,8,05,1968
1,1968-09-28,1.0014,1.0014,9,06,1968;
run; 

ID    Date                Returns      Delisting return        month   newmonth      year

 

1    1968-01-28      1.01                                             1               10                1968

1    1968-02-28    1.04                                              2                11                  1968

1    1968-03-28     1.001                                           3                12                 1968

1   1968 -04-28     1.005   .                                       4                1                  1968

1   1968-05-28     1.02                                              5                 2                 1968

1   1968-06-28      1.02                                             6                 3              1968

1    1968-07-28     1.06                                              7                4               1968

1    1968-08-28      1.06                                             8                 5           1968

1   1968-09-28       1.0014                    1.0014          9                 6            1968

 

I would like to calculate rolling returns. The example above is just a sample. My original dataset however has more that 500000 observations. I would like to do the following: 

 

My portfolio in this case has only one stock. So ID = 1. I want to calculate the return of this stock for 2 months after I buy it on a rolling basis. For example if I bought it on 1968-01-28 then I want to calulate the return up to 1968-03-28. If I buy it on 1968-02-28 then I want to calculate the return until 1968-04-28. And so on until the last available formation period. 

 

I would later like to implement the same methodology on the large dataset with many stocks and larger formation periods. 

 

Could you please help me with an appropriate code or procedure for this task? If you need any more information please write. Thank you in advance. 

 

Regards

Akarsh91

1 REPLY 1

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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