[Blotter-commits] r584 - pkg/blotter/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 17 19:28:56 CET 2011


Author: braverock
Date: 2011-03-17 19:28:56 +0100 (Thu, 17 Mar 2011)
New Revision: 584

Modified:
   pkg/blotter/R/tradeStats.R
Log:
- robustness checks for incomplete backtest P&L

Modified: pkg/blotter/R/tradeStats.R
===================================================================
--- pkg/blotter/R/tradeStats.R	2011-03-17 16:01:47 UTC (rev 583)
+++ pkg/blotter/R/tradeStats.R	2011-03-17 18:28:56 UTC (rev 584)
@@ -112,7 +112,15 @@
             StdDailyPL <- as.numeric(sd(DailyPL))
             
             Equity <- cumsum(posPL$Net.Trading.PL)
+            if(!nrow(Equity)){
+                warning('No Equity rows for',symbol)
+                next()
+            }    
             TotalNetProfit <- last(Equity)
+            if(is.na(TotalNetProfit)) {
+                warning('TotalNetProfit NA for',symbol)
+                next()
+            }
             Equity.max <- cummax(Equity)
             maxEquity <- max(Equity)
             minEquity <- min(Equity)
@@ -200,7 +208,10 @@
             txn <- txn[-1,] # remove initialization row
             
             PL.ne0 <- txn$Net.Txn.Realized.PL[txn$Net.Txn.Realized.PL != 0]
-            
+            if(!nrow(PL.ne0)){
+                warning('No P&L rows for',symbol)
+                next()
+            }             
             DailyPL <- apply.daily(PL.ne0,sum)
             colnames(DailyPL)<-paste(symbol,'DailyTxnPL',sep='.')
             if(is.null(ret)) ret=DailyPL else ret<-cbind(ret,DailyPL)
@@ -239,6 +250,10 @@
             posPL <- posPL[-1,] # remove initialization row
             
             Equity <- cumsum(posPL$Net.Trading.PL)
+            if(!nrow(Equity)){
+                warning('No P&L rows for',symbol)
+                next()
+            }             
             
             #DailyPL <- apply.daily(Equity,last)
             DailyPL <- apply.daily(posPL$Net.Trading.PL,colSums)


Property changes on: pkg/blotter/R/tradeStats.R
___________________________________________________________________
Added: svn:keywords
   + Id Revision Date Author



More information about the Blotter-commits mailing list