[Blotter-commits] r1683 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 8 19:55:18 CEST 2015
Author: bodanker
Date: 2015-04-08 19:55:18 +0200 (Wed, 08 Apr 2015)
New Revision: 1683
Modified:
pkg/blotter/R/addTxn.R
Log:
Warn if txn timestamp is not after initDate
It doesn't make sense for a portfolio to have a transaction before it
was created, and it can cause problems for other functions that
operate on the portfolio.
Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R 2015-04-02 01:06:31 UTC (rev 1682)
+++ pkg/blotter/R/addTxn.R 2015-04-08 17:55:18 UTC (rev 1683)
@@ -142,6 +142,11 @@
#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')
Portfolio$symbols[[Symbol]]$txn<-rbind(Portfolio$symbols[[Symbol]]$txn, NewTxn)
+ # Warn if the transaction timestamp is not after initDate
+ if(.index(NewTxn) <= .index(Portfolio$symbols[[Symbol]]$txn[1L,1L]))
+ warning("Transaction timestamp (", index(NewTxn[1L,]), ") ",
+ "is not after initDate (", index(Portfolio$symbols[[Symbol]]$txn[1L,1L]), ").")
+
if(verbose)
# print(paste(TxnDate, Symbol, TxnQty, "@",TxnPrice, sep=" "))
print(paste(format(TxnDate, "%Y-%m-%d %H:%M:%S"), Symbol, TxnQty, "@",TxnPrice, sep=" "))
@@ -181,6 +186,11 @@
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')
+ # Warn if the transaction timestamp is not after initDate
+ if(.index(NewTxns[1L,1L]) <= .index(Portfolio$symbols[[Symbol]]$txn[1L,1L]))
+ warning("First transaction timestamp (", index(NewTxns[1L,1L]), ") ",
+ "is not after initDate (", index(Portfolio$symbols[[Symbol]]$txn[1L,1L]), ").")
+
if(!("TxnQty" %in% colnames(TxnData))) {
warning(paste("No TxnQty column found, what did you call it?"))
} else {
More information about the Blotter-commits
mailing list