[R-SIG-Finance] P&L Calculation

Joshua Ulrich josh.m.ulrich at gmail.com
Fri Aug 17 02:49:43 CEST 2012


Hi Nikos,

See ?na.locf.

quantstrat et al are under heavy development but they're also used by
professionals every day, so there's no reason you can't use them.

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com


On Thu, Aug 16, 2012 at 7:44 PM, Nikos Rachmanis
<nikos.rachmanis at gmail.com> wrote:
> Hi all,
>
> I would appreciate if someone could give me some feedback on the following
> problem.
>
> I am trying to estimate the P&L of a strategy based on the trade entries.
> as you will see in the data below the entries are indicated by 0,1,-1 and
> they are suppose to be active until the next position follows.
> the object is xts and my difficulty is updating the vector between the
> trades. as an example between 05-15 and 05-29 the series should have been
> -1.
>
> i am using an excel like macro command  to achieve this
>
> perfdata$trade[2:n]<-ifelse(is.na
> (perfdata$trade[2:n]),perfdata$trade[1:n-1],perfdata$trade[2:n])
>
> however i have noticed that the command will update only one element after
> a !=NA which i guess is using the data on the memory and not the updated
> one.
>
> is there are any other way to write the command without using a for loop?
>
> also, i have read about the blotter package and quant strat but it seems
> that they are still under heavy development. Are there any other libraries
> to run trading strategies?
>
> Thank you in advance,
>
> Nikos
>
>
>               CL trade
> 1990-04-27 18.54    NA
> 1990-04-30 18.54    NA
> 1990-05-01 18.88    NA
> 1990-05-02 18.68    NA
> 1990-05-03 17.99    NA
> 1990-05-04 17.98    NA
> 1990-05-07 18.27    NA
> 1990-05-08 18.28    NA
> 1990-05-09 18.99    NA
> 1990-05-10 19.02    NA
> 1990-05-11 18.95    NA
> 1990-05-14 19.71    NA
> 1990-05-15 19.59    -1
> 1990-05-16 19.03    NA
> 1990-05-17 18.87    NA
> 1990-05-18 18.76    NA
> 1990-05-21 18.26    NA
> 1990-05-22 17.68    NA
> 1990-05-23 18.14    NA
> 1990-05-24 17.83    NA
> 1990-05-25 17.80    NA
> 1990-05-29 17.98    -1
> 1990-05-30 18.08    NA
> 1990-05-31 17.40    NA
> 1990-06-01 17.50    NA
> 1990-06-04 17.14    NA
> 1990-06-05 16.68    NA
> 1990-06-06 16.92    NA
> 1990-06-07 16.67     0
> 1990-06-08 16.78    NA
> 1990-06-11 16.82    NA
> 1990-06-12 17.51     1
> 1990-06-13 17.58    NA
> 1990-06-14 17.13    NA
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at 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.



More information about the R-SIG-Finance mailing list