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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 28 14:59:01 CET 2010


Author: braverock
Date: 2010-01-28 14:59:01 +0100 (Thu, 28 Jan 2010)
New Revision: 211

Added:
   pkg/blotter/R/getAccount.R
Modified:
   pkg/blotter/NAMESPACE
   pkg/blotter/R/initAcct.R
Log:
- add getAccount function
- add class to account object to facilitate testing
- export getAccount

Modified: pkg/blotter/NAMESPACE
===================================================================
--- pkg/blotter/NAMESPACE	2010-01-28 13:42:31 UTC (rev 210)
+++ pkg/blotter/NAMESPACE	2010-01-28 13:59:01 UTC (rev 211)
@@ -1,6 +1,7 @@
 export(addTxn)
 export(addTxns)
 export(chart.Posn)
+export(getAccount)
 export(getEndEq)
 export(getPosQty)
 export(getPortfAcct)

Added: pkg/blotter/R/getAccount.R
===================================================================
--- pkg/blotter/R/getAccount.R	                        (rev 0)
+++ pkg/blotter/R/getAccount.R	2010-01-28 13:59:01 UTC (rev 211)
@@ -0,0 +1,28 @@
+getAccount <- function(Account, Dates=NULL) #should symbol subsets be supported too?  probably not.
+{ # @author Brian Peterson
+    aname<-Account
+    if(!grepl("account",aname)) Account<-try(get(paste("account",aname,sep='.'),envir=.blotter))
+    else Account<-try(get(aname,envir=.blotter))
+    if(inherits(Account,"try-error"))
+        stop(paste("Account ",aname," not found, use initAcct() to create a new account"))
+    if(!inherits(Account,"account")) stop("Account ",aname," passed is not the name of an account object.")
+    
+    if(!is.null(Dates)){
+        message("date subsetting not yet supported")
+        #TODO add date subsetting in getAccount
+    }
+    
+    return(Account)
+}
+
+###############################################################################
+# 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$
+#
+###############################################################################


Property changes on: pkg/blotter/R/getAccount.R
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Modified: pkg/blotter/R/initAcct.R
===================================================================
--- pkg/blotter/R/initAcct.R	2010-01-28 13:42:31 UTC (rev 210)
+++ pkg/blotter/R/initAcct.R	2010-01-28 13:59:01 UTC (rev 211)
@@ -62,7 +62,7 @@
         colnames(account[[paste("portfolio",portfolio,sep=".")]]) = c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Txn.Fees','Realized.PL', 'Unrealized.PL', 'Trading.PL')
     }
     # return(account)
-    class("portfolio_account")
+    class(account)<-c("portfolio_account","account")
     assign(paste("account",as.character(name),sep='.'),account,envir=.blotter)  
     return(name) # not sure this is a good idea
 }



More information about the Blotter-commits mailing list