Search code examples
matlabreturnfinance

Compute Cumulative Returns in Matlab


If I have a vector of returns, is there a way to convert it to a cumulative returns vector in Matlab?

There is a very useful function in R called chart.CumReturns funcion from the PerformanceAnalytics package. Is there any similar function in Matlab?

Otherwise, I would like to do it manually in Matlab

For example, having the vector of returns:

r = [r1 r2 .. rn]

I would like to obtain the vector of cumulative returns such that:

rc = [rc1 rc2 ..rcn]

where:

rc1 = r1
rc2 = (1+r1)*(1+r2)-1
rcn = (1+r1)*(1+r2)*...(1+rn)-1

Since I'm new to Matlab, I don't know exactly how to structure a loop over this vector.

Thanks,


Solution

  • r = r +1;
    rc = cumprod(r);
    rc= rc-1;
    

    Hope this helps..