Cumulative Returns

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Cumulative Returns

Hi everyone,

 

I have the below SAS code for calculating cumulative returns. The code works fine for one period but I need to get it worked for multiple periods.

 

proc sql;
create table returns as
select *
from amirkhan.mydata
order by permno, date
;
create table cum_returns as
select permno , exp(sum(log(1+ret))) - 1 as cum_return
, min(ret) as minret , max(ret) as maxret
, n(ret) as n_periods , nmiss(ret) as n_miss
, sum(ret=.P) as n_dot_p , min(date) as first_date
, max(date) as last_date
from returns
where ('01apr1991'd <= date <= '31mar1992'd)
group by permno
;
quit;

 

This code generates the cumulative returns for the period April 01, 1991 to March 31, 1992. I need to modify the code so that it could give me the results for multiple periods. I need cumulative returns for the following periods as well:

 April 01, 1992 to March 31, 1993

April 01, 1993 to March 31, 1994

April 01, 1994 to March 31, 1995

.....

 

Thanks for your time and help.


Accepted Solutions
Solution
‎11-18-2016 04:42 PM
Super User
Posts: 1,235

Re: Cumulative Returns

[ Edited ]

Add to your data, according to dates, a period code as new variable (the fiscal_year),

then run your SQL with a light change:

 /* where ('01apr1991'd <= date <= '31mar1992'd) <<< drop this line */

   group by fiscal_year, permno

View solution in original post


All Replies
Solution
‎11-18-2016 04:42 PM
Super User
Posts: 1,235

Re: Cumulative Returns

[ Edited ]

Add to your data, according to dates, a period code as new variable (the fiscal_year),

then run your SQL with a light change:

 /* where ('01apr1991'd <= date <= '31mar1992'd) <<< drop this line */

   group by fiscal_year, permno

Occasional Contributor
Posts: 17

Re: Cumulative Returns

Thank you for your reply!
That solved the problem!
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 249 views
  • 0 likes
  • 2 in conversation