From doncram Sun Jun 30 15:24:00 1996 Subject: Summary on "Cumulate CRSP returns in SAS" To: CRSP-L@TAMVM1.TAMU.EDU Date: Sun, 30 Jun 1996 15:24:00 -0700 (PDT) [edited very slightly, later, for clarity] Summary of question and responses. I posed that I could "cumulate" returns (and cumulate a simple version of market-adjusted returns) by multiplying daily returns, and asked for SAS code that would let me calculate returns from beginning price, ending price, and dividends paid, instead. My question was poorly worded: Arnold R. Cowan pointed out that: "Cumulative" tends to refer to summed returns in the literature; from your formula below, you want "compounded" or "buy and hold" returns. Yes. I received other valuable comments on the CRSP-L and by private email: a) establishing a common interest in code to do compounding by prices and dividends b) suggestion that I could do the daily compounding more efficiently than I already was, using logs and PROC MEANS, and discussion including continuous vs. daily compounding d) 2 comments suggesting other methods of market-adjustment but I received no SAS code to do the compounding by prices and dividends. Can anyone point me to FORTRAN or any other code that does, or give suggestions on how to do it in SAS. Honestly I don't know CRSP well enough to start to pull the dividend info I want. To do it in SAS, I suppose dividends must be in the PROC DATASOURCE events output, but I am not yet familiar with that. Thank you to those who responded. Don My question and detail on a, b, c follows: -------------------------------------------------- My question: >How can one calculate a cumulative return directly from beginning and >ending prices, and dividends paid, rather than by compounding daily >and/or monthly returns over N days? And market-adjusted cumulative returns? > >For concreteness, consider calculating IBM's cumulative return from >1/01/65 to 12/31/94, with and without market adjustment. > >I see how to cumulate returns in SAS, implementing > cumret = (1+ret_1)(1+ret_2) ... (1+ret_N) - 1 >and how to cumulate returns market-adjusted as > cumretma = (1+ret_1-vwretd_1)(1+ret_2-vwretd_2) ... (1+ret_N-vwretd_N) - 1 >if first I proc datasourced out a SAS dataset holding IBM's return ret >and the market-wide return vwretd for each trading day in the relevant >period. But note this approach won't work if returns are available >for every day in the period, and it is subject to rounding errors. > >An alternative approach would be to calculate cumret simply from >begindate and enddate PRC, if no dividends were paid out, otherwise >dividends would have to be incorporated. Can anyone send me code that >would extract the relevant dividend data from CRSP and/or do the whole >calculation? ---------------------------------------------------- a) Common interest in code to do compounding using prices and dividends Cyndi McDonald (cmcdona@unix1.sncc.lsu.edu) agrees that what I was asking for would be helpful: > >I have been accumulating returns for my programs, but >would prefer to use the method below to calculate holding >period returns for long intervals. >> An alternative approach would be to calculate cumret simply from >> begindate and enddate PRC, if no dividends were paid out, otherwise >> dividends would have to be incorporated. Can anyone send me code that >> would extract the relevant dividend data from CRSP and/or do the whole >> calculation? > >If you get a response directly, I would appreciate a copy as well. ----------------------------------------------------- b) suggestions to code in SAS more easily than I had done, and discussion of continuous vs. daily compounding Peter Luan ( Peter.Luan@asu.edu ) suggested > Instead of taking the product, you may want to: > 1) take the LOG of each return > 2) use PROC MEANS or UNIVARIATE to take the sum of all log terms > 3) exponential the sum back to actual value Cyndi clarified that Peter meant log of 1+ret: > >Returns are sometimes negative? Should take the >log of (1 + return). > >Just curious-- >Is this more precise than multiplying the product directly? It is mathematically the same: Product_i (1 + r_i) = e^log(Product_i (1 + r_i)) = e^(Sum_i log(1+r_i)) but perhaps Cyndi is suggesting that rounding errors may be greater in one method than the other. Indeed I was concerned about accuracy, which is one reason why I asked for a method based on beginning and end prices and dividends. Peter's approach may well be more efficient in run-time than the SAS coding approach I used, which involved RETAIN in a data step: data CUMULAT; set MYDATA; tempobs = _N_; if _N_ = 1 or lag(crspitem) ne crspitem then do; cumret = (1+ret); cumretma = (1+ret-crspvret); ndays = 1; holdc = 0; end; else do; cumret = holda * (1 + ret); cumretma = holdb * (1 + ret - crspvret); ndays = holdc + 1; end; holda = cumret; holdb = cumretma; holdc = ndays; retain holda holdb holdc; David Ellis (dmellis@tamu.edu) commented: >By taking the log of (1+return) you are creating continuously compounded >returns. The other method proposed on the list this morning was creating >discretely compounded returns. So which method you use should depend on >what type of returns you want to create. However, based on my formula of logs and exponentiations above, I think that Peter's and my approaches calculate exactly the same thing: daily compounded returns. David is correct to point out there is a distinction. Whenever I do get a means to extract prices and dividends, I will write a version that calculates compound average daily returns and one that calculates a continuously compounding return rate. ----------------------------------------------------- c) Arnie Cowan and Spencer Martin pointed out my market-adjustment method is not good. I had posed that I wanted to cumulate returns over several decades to dramatize how painful cumulating daily returns would be, but actually my application is for a much shorter period where my method would be okay for some purposes. Their alternative suggestions are well-taken, however: Arnie Cowan (arnie@pop-1.iastate.edu) commented: >>and how to cumulate returns market-adjusted as >> cumretma = (1+ret_1-vwretd_1)(1+ret_2-vwretd_2) ... (1+ret_N-vwretd_N) - 1 > Think carefully about whether you want to do this regardless of what >data you start with. Investors don't earn market-adjusted returns over a day >or a month; they earn raw returns. It would make more sense to compound the >raw stock and market returns separately to mimic feasible investment >strategies over N periods, then take the difference at the end to see the >difference between the stock and the market. Spencer Martin commented: >> For concreteness, consider calculating IBM's cumulative return from >> 1/01/65 to 12/31/94, with and without market adjustment. >> >> I see how to cumulate returns in SAS, implementing >> cumret = (1+ret_1)(1+ret_2) ... (1+ret_N) - 1 >> and how to cumulate returns market-adjusted as >> cumretma = (1+ret_1-vwretd_1)(1+ret_2-vwretd_2) ... (1+ret_N-vwretd_N) - 1 >Don, > >For 30 years of data, it doesn't seem reasonable to call the difference >between ibm's and the index's return a 'market adjusted' return. >It's unlikely that IBM had a beta of 1 (or even a constant beta) over that >long a time period. > >Also, as someone else pointed out, if you make log returns you can have >proc means do the cumulation for you at less pain. end of summary ---------------------------------------