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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 16 23:16:27 CEST 2014


Author: efmrforge
Date: 2014-04-16 23:16:27 +0200 (Wed, 16 Apr 2014)
New Revision: 1600

Modified:
   pkg/blotter/R/addTxn.R
Log:
Added checking for TxnQty and TxnPrice column names


Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R	2014-04-16 16:09:40 UTC (rev 1599)
+++ pkg/blotter/R/addTxn.R	2014-04-16 21:16:27 UTC (rev 1600)
@@ -173,9 +173,19 @@
     # initialize new transaction object
     NewTxns <- xts(matrix(NA_real_, nrow(TxnData), 10L), index(TxnData))
     colnames(NewTxns) <- c('Txn.Qty', 'Txn.Price', 'Txn.Value', 'Txn.Avg.Cost', 'Pos.Qty', 'Pos.Avg.Cost', 'Gross.Txn.Realized.PL', 'Txn.Fees', 'Net.Txn.Realized.PL', 'Con.Mult')
-
-    NewTxns$Txn.Qty <- as.numeric(TxnData$TxnQty)
-    NewTxns$Txn.Price <- as.numeric(TxnData$TxnPrice)
+1
+    if(!("TxnQty" %in% colnames(TxnData))) {
+	warning(paste("No TxnQty column found, what did you call it?"))
+    } else {
+      NewTxns$Txn.Qty <- as.numeric(TxnData$TxnQty)
+	}
+    if(!("TxnPrice" %in% colnames(TxnData))) {
+	warning(paste("No TxnPrice column found, what did you call it?"))
+    } else {
+      NewTxns$Txn.Qty <- as.numeric(TxnData$TxnPrice)
+	}
+    #NewTxns$Txn.Qty <- as.numeric(TxnData$TxnQty)
+    #NewTxns$Txn.Price <- as.numeric(TxnData$TxnPrice)
     if("TxnFees" %in% colnames(TxnData)) {
       NewTxns$Txn.Fees <- as.numeric(TxnData$TxnFees)
     } else {
@@ -303,7 +313,7 @@
 ###############################################################################
 # Blotter: Tools for transaction-oriented trading systems development
 # for R (see http://r-project.org/)
-# Copyright (c) 2008-2014 Peter Carl and Brian G. Peterson
+# Copyright (c) 2008-2011 Peter Carl and Brian G. Peterson
 #
 # This library is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING



More information about the Blotter-commits mailing list