[Blotter-commits] r1637 - in pkg/blotter: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 7 17:51:22 CEST 2014


Author: braverock
Date: 2014-10-07 17:51:21 +0200 (Tue, 07 Oct 2014)
New Revision: 1637

Modified:
   pkg/blotter/DESCRIPTION
   pkg/blotter/R/tradeStats.R
Log:
- divide by zero checks for implausibly perfect systems suggested by Daniel Cegielka

Modified: pkg/blotter/DESCRIPTION
===================================================================
--- pkg/blotter/DESCRIPTION	2014-10-07 15:47:09 UTC (rev 1636)
+++ pkg/blotter/DESCRIPTION	2014-10-07 15:51:21 UTC (rev 1637)
@@ -2,7 +2,7 @@
 Type: Package
 Title: Tools for transaction-oriented trading systems
     development.
-Version: 0.9.1636
+Version: 0.9.1637
 Date: $Date$
 Author: Peter Carl, Brian G. Peterson
 Maintainer: Brian G. Peterson <brian at braverock.com>
@@ -23,7 +23,7 @@
 Suggests:
     Hmisc,
     RUnit,
-Contributors: Dirk Eddelbuettel, Jan Humme, Lance Levenson,
+Contributors: Daniel Cegielka, Dirk Eddelbuettel, Jan Humme, Lance Levenson,
     Ben McCann, Jeff Ryan, Garrett See, Joshua Ulrich, Wolfgang Wu
 URL: https://r-forge.r-project.org/projects/blotter/
 Copyright: (c) 2008-2014

Modified: pkg/blotter/R/tradeStats.R
===================================================================
--- pkg/blotter/R/tradeStats.R	2014-10-07 15:47:09 UTC (rev 1636)
+++ pkg/blotter/R/tradeStats.R	2014-10-07 15:51:21 UTC (rev 1637)
@@ -152,7 +152,7 @@
             AvgTradePL <- mean(PL.ne0)
             MedTradePL <- median(PL.ne0)
             StdTradePL <- sd(as.numeric(as.vector(PL.ne0)))  
-            AnnSharpe  <- AvgDailyPL/StdDailyPL * sqrt(252)
+            AnnSharpe  <- ifelse(StdDailyPL == 0, NA, AvgDailyPL/StdDailyPL * sqrt(252))
             
             NumberOfTxns   <- nrow(txn)-1
             NumberOfTrades <- length(PL.ne0)
@@ -168,8 +168,8 @@
             AvgLossTrade <- mean(PL.lt0)
             MedLossTrade <- median(PL.lt0)
             
-            AvgWinLoss <- AvgWinTrade/-AvgLossTrade
-            MedWinLoss <- MedWinTrade/-MedLossTrade
+            AvgWinLoss <- ifelse(AvgLossTrade == 0, NA, AvgWinTrade/-AvgLossTrade)
+            MedWinLoss <- ifelse(MedLossTrade == 0, NA, MedWinTrade/-MedLossTrade)
             
             Equity <- cumsum(posPL$Net.Trading.PL)
             if(!nrow(Equity)){
@@ -194,7 +194,7 @@
             #TODO we should back out position value if we've got an open position and double check here....
 	
             MaxDrawdown            <- -max(Equity.max - Equity)
-            ProfitToMaxDraw        <- -TotalNetProfit / MaxDrawdown
+            ProfitToMaxDraw  <- ifelse(MaxDrawdown == 0, NA, -TotalNetProfit / MaxDrawdown)
             names(ProfitToMaxDraw) <- 'Profit.To.Max.Draw'
                 
             #TODO add skewness, kurtosis, and positive/negative semideviation if PerfA is available.



More information about the Blotter-commits mailing list