[R-SIG-Finance] tradeStats - Avg.Daily.PL/Med.Daily.PL question
Ilya Kipnis
ilya.kipnis at gmail.com
Thu Sep 25 23:03:11 CEST 2014
For the record, dailyStats is not something that's exclusive to my
packages. It's a blotter function. Also, I highly recommend upgrading to
the latest R-forge TTR and blotter. A lot of the times that people can't
get my code to run usually involves the CRAN version of TTR. For the
record, the way I use dailyStats is like this:
dStats <- dailyStats(Portfolios = portfolio.st, use="Equity")
My version of blotter is blotter_0.8.19
On Thu, Sep 25, 2014 at 4:09 PM, Mark Knecht <markknecht at gmail.com> wrote:
> Hi Brian,
>
> On Thu, Sep 25, 2014 at 12:16 PM, Brian G. Peterson <brian at braverock.com>
> wrote:
> > Mark,
> >
> > tradeStats does exactly what it says it is doing. It gives you the
> number
> > mean or median P&L for days on which you have trading P&L from
> > (Net.Txn.Realized.PL). So, on days in which you realize a gain or loss
> of
> > any sort, (position gets closer to zero), they will be counted for the
> mean
> > daily number in tradeStats.
> >
>
> OK, your description helps. I guess there's a follow-on question as to when
> Avg.Daily.PL & Avg.Trade.PL are ever different (as I've not run across
> that)
> but don't respond on that alone. I'll just do some work and see if I can
> get
> there.
>
> > dailyStats uses days with non=-zero P&L, which isn't quite right, but
> should
> > be much closer to what you're looking for. (it requires a change in
> price or
> > position, so that the mark will differ). The potential error here is if
> you
> > have days of marked P&L that have no change, e.g. days on which you are
> > flat. I'm not sure it makes sense to count these days most of the time
> > anyway, but it is a difference worth describing.
> >
>
> OK. I tried running dailyStats a day or two ago and got nowhere with it but
> I'll see if I can't figure that out. A quick search shows that Ilya
> uses it in his
> IKTrading and DSTrading files so that should be enough to get me going.
>
> Thanks for the quick response.
>
> Cheers,
> Mark
>
>
>
> > Regards,
> >
> > Brian
> >
> >
> > On 09/25/2014 12:47 PM, Mark Knecht wrote:
> >>
> >> Hi,
> >> The help file for tradeStats asks for feedback so here I am.
> >> Reproducible code is the macd.Rebalancing.R demo file with the symbol
> >> changed to "SPY" and these lines added at the end:
> >>
> >> oB = getOrders(portfolio.st, "SPY", status="closed")
> >> tS = t(tradeStats(portfolio.st))
> >> pTS = perTradeStats(portfolio.st, "SPY")
> >>
> >> The tradeStats function works correctly (as best I can tell) for
> >> most values but I'm thinking either I don't understand the
> >> Avg.Daily.PL value or there's a bug. Every time I run the function
> >> Avg.Daily.PL & Med.Daily.PL is always equal to Avg.Trade.PL &
> >> Med.Trade.PL respectively. (NOTE: I'm using daily & weekly data only.)
> >>
> >> From the help file I'm not exactly sure what this is intended to
> mean:
> >>
> >> Avg.Daily.PL - mean daily realized P&L on days there were
> >> transactions, see dailyStats for all days
> >>
> >> Is this supposed to be the total trading profit divided by the
> >> number of days in trades, or the total profit divided by the number of
> >> days from the first entry to the last exit, or something else?
> >>
> >> The code from quantstrat-0.8.2 that's involved seems to be this:
> >>
> >> PL.ne0 <- txn$Net.Txn.Realized.PL[txn$Net.Txn.Realized.PL != 0]
> >>
> >> DailyPL <- apply.daily(PL.ne0, sum)
> >> AvgDailyPL <- mean(DailyPL)
> >> MedDailyPL <- median(DailyPL)
> >>
> >> and
> >>
> >> AvgTradePL <- mean(PL.ne0)
> >> MedTradePL <- median(PL.ne0
> >>
> >> If the intention is to say something about how much money the
> >> strategy makes "per day" then I don't see anything that tallies the
> >> number of days in the simulation run. I got a simplified version of
> >> that using:
> >>
> >> pTS = perTradeStats(portfolio.st, "SPY")
> >> last(pTS$End)-first(pTS$Start)
> >> Time difference of 2729 days
> >>
> >> but I'm sure there are easier/better ways.
> >>
> >> Anyway, is it working correctly, or if not has it been fixed in a
> >> more recent version of quantstrat?
> >>
> >> Thanks,
> >> Mark
> >>
> >> _______________________________________________
> >> 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.
> >>
> >
> > --
> > Brian G. Peterson
> > http://braverock.com/brian/
> > Ph: 773-459-4973
> > IM: bgpbraverock
> >
> > _______________________________________________
> > 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.
>
> _______________________________________________
> 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.
>
[[alternative HTML version deleted]]
More information about the R-SIG-Finance
mailing list