Zachary

Great thanks! That is simple. I invert the sign to arrive at the right
return. Delt only gives me the differentials but it will not give me the
correct amount without the inverted signal. (P2-P1)/P1 is positive if it is
long (sig=1) but it will be negative if you are short when P2>p1 etc.

Do you think there exists any other elegant solution?

Also do you think rollapply or apply.fromstart etc could also be used to
solve such problems?

Many thanks
Raghu

On Mon, Jun 25, 2012 at 9:02 PM, Zachary Mayer <zach.mayer@gmail.com> wrote:

> You want the "cumprod" function, e.g:
>
> library(quantmod)
>
> a = c(20,30,40,50)
> sig = c(1,-1,1,-1)
>
> ret = Delt(a)
> ret[1]= 0
> ret = ret*-1*sig
>
> cumprod(1+ret)
> 100*cumprod(1+ret)
>
> Out of curiosity, why do you multiply your signal by -1 before applying it?
>
> On Mon, Jun 25, 2012 at 3:53 PM, Raghuraman Ramachandran <
> optionsraghu@gmail.com> wrote:
>
>> Dear All
>>
>> I have a price vector a which i defined as a = c(20,30,40,50)
>>
>> I have an indicator signal sig which I define as sig = c(1,-1,1,-1) where
>> 1
>> is long and -1 is short.
>>
>> I am trying to calculate the rolling profit/loss and equity but unable to
>> do so because I do not understand the rolling concept using vectors.
>>
>> I am able to calculate the final equity by the following function:
>>
>> Amount*prod*(1+na.omit(Delt(a)*-1*sig))
>>
>> which gives $375 as the final equity. I started off with $100.
>>
>> Is there a function that can calculate the total profits in the interim
>> please? I know that by subscripting a and sig I can find out that easily
>> but that is not on a rolling basis. The problem is the current value of
>> the
>> equity is a function of the previous values and hence I wish to know if
>> there are any vectorisable solutions please?
>>
>>  Appreciate the kind help.
>>
>> Many thanks
>> Raghu
>>
>>        [[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]]

