Sorry, it should be

asset_ret$cum.pnl <- cumprod( 1 + asset_ret$pnl)

On Mon, May 6, 2013 at 3:17 PM, Chinmay Patil <chinmay.patil@gmail.com>
wrote:

Hi,
>
> You should use cumprod
>
> asset_ret$cum.pnl <- cumprod(1 + pnl)
>
>
>
> On Mon, May 6, 2013 at 3:12 PM, Nikos Rachmanis <nikos.rachmanis@gmail.com
> > wrote:
>
>> Hi all,
>>
>> I would appreciate if someone could help me out with the following
>> problem. I am trying to calculate the cumulative returns of simple
>> returns (P(i)-P(i-1))/P(i-1).
>>
>> I am using the following code:
>>
>> #calculate simple returns
>> asset_ret$pnl<-Return.calculate(asset_prices, method="simple")
>>
>> #zero first observation in daily P&L
>> asset_ret$pnl[1]<-0
>>
>> #create the cum P&L
>> asset_ret$cum.pnl<-1
>>
>> #calculate cum P&L
>> asset_ret$cum.pnl<-(1+asset_ret$pnl)*lag(asset_ret$cum.pnl,k=1)
>> #also tried to following
>> #
>>
>> asset_ret$cum.pnl[2:len]<-(1+asset_ret$pnl[2:len])*(asset_ret$cum.pnl[1:len-1])
>>
>> Both ways produce the same result.
>>
>>         pnl     cum.pnl
>> 12/31/1999      0       1
>> 1/7/2000        -0.026414344    0.973585656
>> 1/14/2000       0.042927439     1.042927439
>> 1/21/2000       -0.005207309    0.994792691
>> 1/28/2000       0.001524739     1.001524739
>> 2/4/2000        -0.070445196    0.929554804
>> 2/11/2000       0.011650011     1.011650011
>> 2/18/2000       -0.051197015    0.948802985
>> 2/25/2000       0.003199086     1.003199086
>> 3/3/2000        -0.053000533    0.946999467
>>
>>
>> while the correct is
>>
>>         pnl     cum.pnl
>> 12/31/1999
>>         1
>> 1/7/2000        -0.026414344    0.973585656
>> 1/14/2000       0.042927439     1.015379194
>> 1/21/2000       -0.005207309    1.010091802
>> 1/28/2000       0.001524739     1.011631928
>> 2/4/2000        -0.070445196    0.940367318
>> 2/11/2000       0.011650011     0.951322608
>> 2/18/2000       -0.051197015    0.902617731
>> 2/25/2000       0.003199086     0.905505283
>> 3/3/2000        -0.053000533    0.857513021
>>
>>
>> It seems that R uses the original values from the vector filled with
>> ones instead the new calculated values.
>>
>> I apologize if the topic was discussed previously but was not able to
>> find the answer.
>>
>> Thank you,
>>
>> Nikos
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-SIG-Finance@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions
>> should go.
>>
>
>

	[[alternative HTML version deleted]]

