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) Daniel