On 10/07/2014 01:22 AM, Daniel Cegiełka wrote:
2014-10-07 7:38 GMT+02:00 Daniel Cegiełka <daniel.cegie...@gmail.com>:
https://github.com/rforge/blotter/blob/master/pkg/blotter/R/tradeStats.R#L147

GrossProfits <- sum(PL.gt0)
GrossLosses <- sum(PL.lt0)
if(GrossLosses == 0) ProfitFactor <- NA
else  ProfitFactor <- abs(GrossProfits/GrossLosses)

more compact:

GrossProfits <- sum(PL.gt0)
GrossLosses <- sum(PL.lt0)
ProfitFactor <- ifelse(GrossLosses == 0, NA, abs(GrossProfits/GrossLosses))

Maybe we should add more such checks to the code (for div ops)? eg:

AnnSharpe  <- ifelse(StdDailyPL == 0, NA, AvgDailyPL/StdDailyPL * sqrt(252))
AvgWinLoss <- ifelse(AvgLossTrade == 0, NA, AvgWinTrade/-AvgLossTrade)
MedWinLoss <- ifelse(MedLossTrade == 0, NA, MedWinTrade/-MedLossTrade)
ProfitToMaxDraw  <- ifelse(MaxDrawdown == 0, NA, -TotalNetProfit / MaxDrawdown)

btw. NA looks better than Inf.

Thanks, patches applied in svn r1637.

Of course, a backtest with zero losing trades is implausibly perfect...

Regards,

Brian


--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

_______________________________________________
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.

Reply via email to