Cumulative Product of Returns from Daily to Monthly Data


The Problem:

We want to find cumulative product of returns from daily to monthly frequency. That is we want geometric cumulative returns in the fashion;
Cumulative Product = (1+R1)*(1+R2)*(1+R3)*......(1+Rn) - 1


Solution: 
First we shall prepare our data, so imagine you have returns data in daily format where variable date tracks the data datewise. To generate sequential monthly identifier, we shall use:

    *Data Preperation
    *--------------------

    gen year=year(date)
    gen month=month(date)

    *one month serial number
    *----------------------------
    sum year
    scalar min = r(min)
    scalar max = r(max)
    gen mon_ser = (year - min)*12 + month
    sum mon_ser
    sca minm = r(min)
    replace mon_ser = mon_ser - minm + 1

    *One month serial number generation completed



We are ready to generate monthly geometric cumulative returns from daily data. Suppose our returns are recorded in variabe rm, then;


   
    gen Period = .
    bys mon_ser: egen SCAR=sum( ln(rm+1))
    replace SCAR = exp(SCAR) - 1
         

                            
What if we want the cumulative returns for more than one month. For example, if we want cumulative returns for 36 months, the code would be

     tsset Period
    loc F "(1+SCAR)"
    sum Period
    forval i = 1 / 36 {
        loc F "`F' * (1+L`i'.SCAR)"
        gen rm`=`i'+1'=`F' - 1
    }




 **********************