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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 5 01:57:07 CEST 2012


Author: gsee
Date: 2012-07-05 01:57:07 +0200 (Thu, 05 Jul 2012)
New Revision: 1100

Modified:
   pkg/blotter/R/addTxn.R
Log:
 allow TxnFees to be a column in TxnData arg to addTxns. Thanks Hideyoshi Maeda for the report!

Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R	2012-07-04 14:31:08 UTC (rev 1099)
+++ pkg/blotter/R/addTxn.R	2012-07-04 23:57:07 UTC (rev 1100)
@@ -158,15 +158,18 @@
         #TODO create vectorized versions of all these functions so we don't have to loop
         TxnQty         <- as.numeric(TxnData[row,'Quantity'])
         TxnPrice       <- as.numeric(TxnData[row,'Price'])
-        TxnFee         <- 0 #TODO FIXME support transaction fees in addTxns
-        #TxnFee         <- ifelse( is.function(TxnFees), TxnFees(TxnQty, TxnPrice), TxnFees)
-        TxnValue       <- .calcTxnValue(TxnQty, TxnPrice, TxnFee, ConMult)
+        # If TxnFees are to be used, it must be a column in TxnData
+        TxnFees <- if (any(grepl("TxnFees", colnames(TxnData)))) {
+            as.numeric(TxnData[row, "TxnFees"])
+        } else 0
+        #TxnFees         <- ifelse( is.function(TxnFees), TxnFees(TxnQty, TxnPrice), TxnFees)
+        TxnValue       <- .calcTxnValue(TxnQty, TxnPrice, TxnFees, ConMult)
         TxnAvgCost     <- .calcTxnAvgCost(TxnValue, TxnQty, ConMult)
         #PrevPosQty     <- getPosQty(pname, Symbol, index(TxnData[row,]))
         PosQty         <- PrevPosQty+TxnQty
         PosAvgCost     <- .calcPosAvgCost(PrevPosQty, PrevPosAvgCost, 0, PosQty, ConMult) # lag this over the data?
 		GrossTxnRealizedPL = TxnQty * ConMult * (PrevPosAvgCost - TxnAvgCost)
-		NetTxnRealizedPL = GrossTxnRealizedPL - TxnFee
+		NetTxnRealizedPL = GrossTxnRealizedPL - TxnFees
         PrevPosQty     <- PosQty
         PrevPosAvgCost <- PosAvgCost
         
@@ -177,7 +180,7 @@
                          PosQty, 
                          PosAvgCost, 
                          GrossTxnRealizedPL,
-                         TxnFee,
+                         TxnFees,
                          NetTxnRealizedPL,
                          ConMult)),
                          order.by=index(TxnData[row,]))



More information about the Blotter-commits mailing list