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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 30 23:37:25 CEST 2016


Author: bodanker
Date: 2016-03-30 23:37:25 +0200 (Wed, 30 Mar 2016)
New Revision: 1741

Modified:
   pkg/blotter/DESCRIPTION
   pkg/blotter/R/tradeStats.R
Log:
Determine 'trades' without fees, with scratches

Transaction fees are realized on every transaction, so do not use
non-zero net realized P&L to determine 'trades' for tradeStats. Use
non-zero gross realized P&L instead.

Also include scratch trades for tradeStats' purposes. The amzn_demo
has 5 scratch trades (of 7 total), and that showed the number of
transactions (among other things) were not being calculated correctly.



Modified: pkg/blotter/DESCRIPTION
===================================================================
--- pkg/blotter/DESCRIPTION	2016-03-30 19:40:41 UTC (rev 1740)
+++ pkg/blotter/DESCRIPTION	2016-03-30 21:37:25 UTC (rev 1741)
@@ -2,7 +2,7 @@
 Type: Package
 Title: Tools for Transaction-Oriented Trading Systems
     Development
-Version: 0.9.1695
+Version: 0.9.1741
 Date: $Date$
 Author: Peter Carl [aut],
   Brian G. Peterson [aut, cre],
@@ -39,5 +39,5 @@
     Hmisc,
     RUnit,
 URL: https://r-forge.r-project.org/projects/blotter/
-Copyright: (c) 2008-2015
+Copyright: (c) 2008-2016
 ByteCompile: TRUE

Modified: pkg/blotter/R/tradeStats.R
===================================================================
--- pkg/blotter/R/tradeStats.R	2016-03-30 19:40:41 UTC (rev 1740)
+++ pkg/blotter/R/tradeStats.R	2016-03-30 21:37:25 UTC (rev 1741)
@@ -114,9 +114,13 @@
             posPL <- Portfolio$symbols[[symbol]]$posPL
             posPL <- posPL[-1,]
 
-            PL.gt0 <- txn$Net.Txn.Realized.PL[txn$Net.Txn.Realized.PL  > 0]
-            PL.lt0 <- txn$Net.Txn.Realized.PL[txn$Net.Txn.Realized.PL  < 0]
-            PL.ne0 <- txn$Net.Txn.Realized.PL[txn$Net.Txn.Realized.PL != 0]
+            # Use gross transaction P&L to identify transactions that realized
+            # (non-fee) P&L, but use net transaction P&L to calculate statistics.
+            PL.gt0 <- txn$Net.Txn.Realized.PL[txn$Gross.Txn.Realized.PL  > 0]
+            PL.lt0 <- txn$Net.Txn.Realized.PL[txn$Gross.Txn.Realized.PL  < 0]
+            PL.scratch <- txn$Pos.Qty == 0 & lag(txn$Pos.Qty) != 0
+            PL.scratch[1] <- FALSE  # Set first NA to FALSE
+            PL.ne0 <- txn$Net.Txn.Realized.PL[txn$Gross.Txn.Realized.PL != 0 | PL.scratch]
 
             if(length(PL.ne0) == 0)
             {



More information about the Blotter-commits mailing list