[R-SIG-Finance] tradeStats - Avg.Daily.PL/Med.Daily.PL question

Mark Knecht markknecht at gmail.com
Thu Sep 25 19:47:28 CEST 2014


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



More information about the R-SIG-Finance mailing list