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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 2 15:11:37 CET 2011


Author: braverock
Date: 2011-03-02 15:11:37 +0100 (Wed, 02 Mar 2011)
New Revision: 564

Modified:
   pkg/blotter/NAMESPACE
   pkg/blotter/R/getPortfolio.R
Log:
- add is.portfolio function

Modified: pkg/blotter/NAMESPACE
===================================================================
--- pkg/blotter/NAMESPACE	2011-02-28 15:54:58 UTC (rev 563)
+++ pkg/blotter/NAMESPACE	2011-03-02 14:11:37 UTC (rev 564)
@@ -22,3 +22,4 @@
 export(updateAcct)
 export(updateEndEq)
 export(updatePortf)
+export(is.portfolio)

Modified: pkg/blotter/R/getPortfolio.R
===================================================================
--- pkg/blotter/R/getPortfolio.R	2011-02-28 15:54:58 UTC (rev 563)
+++ pkg/blotter/R/getPortfolio.R	2011-03-02 14:11:37 UTC (rev 564)
@@ -19,6 +19,29 @@
     return(Portfolio)
 }
 
+
+#' generic is.function for portfolio, will take either a string or an object
+#' 
+#' If \code{x} is a string, \code{\link{getPortfolio}} will be called with 
+#' string \code{x} and tested.  Otherwise, the object passed will be tested.
+#' 
+#' @param x an object or string to be tested as a portfolio
+#' @seealso \code{\link{getPortfolio}}
+#' @export
+is.portfolio <- function(x,...) 
+{ # @author Brian Peterson
+    if(inherits(x,'portfolio')) return(TRUE)
+    else if(is.character(x)){
+        res<-try(getPortfolio(x))
+        if(!inherits(res,"portfolio")) {
+            message("Portfolio",x,"needs to be created first.")
+            return(FALSE)
+        } else {
+            return(TRUE)
+        }
+    } else return(FALSE)    
+}
+
 ###############################################################################
 # Blotter: Tools for transaction-oriented trading systems development
 # for R (see http://r-project.org/) 



More information about the Blotter-commits mailing list