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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 9 17:03:05 CEST 2010


Author: braverock
Date: 2010-09-09 17:03:04 +0200 (Thu, 09 Sep 2010)
New Revision: 391

Added:
   pkg/blotter/R/extractTests.R
Log:
- initial revision of extractTxns fn

Added: pkg/blotter/R/extractTests.R
===================================================================
--- pkg/blotter/R/extractTests.R	                        (rev 0)
+++ pkg/blotter/R/extractTests.R	2010-09-09 15:03:04 UTC (rev 391)
@@ -0,0 +1,48 @@
+
+extractTxns <- function(Portfolio)
+{ # @author Brian G. Peterson, Josh Ulrich
+	
+	pname <- Portfolio	
+	Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
+	if(inherits(Portfolio,"try-error"))
+		stop(paste("Portfolio",name," not found, use initPortf() to create a new portfolio first"))
+	out<-NULL
+	symbolnames<-names(Portfolio[['symbols']])
+	for (Symbol in symbolnames) {
+		tmpTxns<-Portfolio$symbols[[Symbol]]$txn[-1,]
+		if (nrow(tmpTxns)>=1){
+			tmpout<-NULL
+			
+			for (i in 1:nrow(tmpTxns)){
+				tmpout[i]<- paste(  "addTxn(Portfolio ='",pname,
+								"', Symbol ='",Symbol,
+								"', TxnDate = '",index(tmpTxns)[i],
+								"', TxnQty =",tmpTxns[i,'Txn.Qty'],
+								", TxnPrice =",tmpTxns[i,'Txn.Price'],
+								", TxnFees =",tmpTxns[i,'Txn.Fees'],
+								", ConMult =",tmpTxns[i,'Con.Mult'],
+								")",
+								sep=''
+							)
+				
+			}
+									
+			if(is.null(out)) out <- tmpout
+			else out<- c(out,tmpout)
+		}
+	}
+	return(out)
+}
+
+
+###############################################################################
+# Blotter: Tools for transaction-oriented trading systems development
+# for R (see http://r-project.org/) 
+# Copyright (c) 2008-2010 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
+#
+# $Id: getTxn.R 378 2010-08-20 18:12:00Z braverock $
+#
+###############################################################################



More information about the Blotter-commits mailing list