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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 9 22:08:19 CEST 2011


Author: braverock
Date: 2011-04-09 22:08:19 +0200 (Sat, 09 Apr 2011)
New Revision: 593

Modified:
   pkg/blotter/R/getBySymbol.R
   pkg/blotter/R/getPortfAcct.R
   pkg/blotter/R/getPortfolio.R
   pkg/blotter/R/updatePortf.R
Log:
- make blotter less 'chatty' with Warnings

Modified: pkg/blotter/R/getBySymbol.R
===================================================================
--- pkg/blotter/R/getBySymbol.R	2011-04-09 18:03:21 UTC (rev 592)
+++ pkg/blotter/R/getBySymbol.R	2011-04-09 20:08:19 UTC (rev 593)
@@ -16,7 +16,7 @@
 { # @author Peter Carl
 
     # FUNCTION
-    if(is.null(Dates) | is.na(Dates)) # if no date is specified, get all available dates
+    if(all(is.null(Dates)) || all(is.na(Dates))) # if no date is specified, get all available dates
         Dates = time(Portfolio$symbols[[1]]$posPL)
     # else  Dates = time(Portfolio$symbols[[1]]$posPL[Dates])
     if(!is.null(attr(Portfolio,'currency')) & native==FALSE) {

Modified: pkg/blotter/R/getPortfAcct.R
===================================================================
--- pkg/blotter/R/getPortfAcct.R	2011-04-09 18:03:21 UTC (rev 592)
+++ pkg/blotter/R/getPortfAcct.R	2011-04-09 20:08:19 UTC (rev 593)
@@ -4,11 +4,11 @@
 #' @param Dates date subset as an xts style ISO 8601 string
 .getPortfAcct <- function(Account,Portfolio, Dates=NULL) #should symbol subsets be supported too?  probably not.
 { # @author Brian Peterson
-    acct<-try(get(paste("account",Account,sep='.'),envir=.blotter),silent=TRUE)
+    acct<-suppressWarnings(try(get(paste("account",Account,sep='.'),envir=.blotter),silent=TRUE))
     if(inherits(acct,"try-error"))
         stop(paste("Account",Account,"not found, use initAcct() to create a new account."))
     pname=Portfolio
-    Portfolio<-try(acct[[paste("portfolio",pname,sep='.')]],silent=TRUE)
+    Portfolio<-suppressWarnings(try(acct[[paste("portfolio",pname,sep='.')]],silent=TRUE))
     if(inherits(Portfolio,"try-error"))
         stop(paste("Portfolio",pname,"not found, use initPortf() to create a new portfolio or initAcct() to place it in",Account))
     

Modified: pkg/blotter/R/getPortfolio.R
===================================================================
--- pkg/blotter/R/getPortfolio.R	2011-04-09 18:03:21 UTC (rev 592)
+++ pkg/blotter/R/getPortfolio.R	2011-04-09 20:08:19 UTC (rev 593)
@@ -5,8 +5,8 @@
 getPortfolio <- function(Portfolio, Dates=NULL) #should symbol subsets be supported too?  probably not.
 { # @author Brian Peterson
     pname<-Portfolio
-    if(!grepl("portfolio\\.",pname)) Portfolio<-try(get(paste("portfolio",pname,sep='.'),envir=.blotter))
-    else Portfolio<-try(get(pname,envir=.blotter))
+    if(!grepl("portfolio\\.",pname)) Portfolio<-suppressWarnings(try(get(paste("portfolio",pname,sep='.'),envir=.blotter),silent=TRUE))
+    else Portfolio<-suppressWarnings(try(get(pname,envir=.blotter),silent=TRUE))
     if(inherits(Portfolio,"try-error"))
         stop(paste("Portfolio",pname," not found, use initPortf() to create a new portfolio"))
     if(!inherits(Portfolio,"portfolio")) stop("Portfolio",pname,"passed is not the name of a portfolio object.")
@@ -32,7 +32,9 @@
 { # @author Brian Peterson
     if(inherits(x,'portfolio')) return(TRUE)
     else if(is.character(x)){
-        res<-try(getPortfolio(x))
+        if(!grepl("portfolio\\.",x)) res <- suppressWarnings(try(get(paste("portfolio",x,sep='.'),envir=.blotter),silent=TRUE))
+        else res <- suppressWarnings(try(get(x,envir=.blotter),silent=TRUE))
+        #res<-suppressWarnings(try(getPortfolio(x))) #causes spurious error if you're checking whether portfolio exists
         if(!inherits(res,"portfolio")) {
             message("Portfolio",x,"needs to be created first.")
             return(FALSE)

Modified: pkg/blotter/R/updatePortf.R
===================================================================
--- pkg/blotter/R/updatePortf.R	2011-04-09 18:03:21 UTC (rev 592)
+++ pkg/blotter/R/updatePortf.R	2011-04-09 20:08:19 UTC (rev 593)
@@ -1,18 +1,18 @@
-#' Function goes through each symbol and calculates the PL for each period prices are available
+#' update Portfilio P&L over a Dates range
 #' 
-#' Inputs
-#' Portfolio: a portfolio object containing transactions
-#' Symbol: an instrument identifier for a symbol included in the portfolio
-#' Dates: Dates for which to calculate equity account
-#' These dates must appear in the price stream
+#' The \code{updatePortf} function goes through each symbol and calculates the PL for each period prices are available.
+#'
+#' Note that the portfolio will be marked on every time stamp where prices are available.  
+#' As such, your \code{Dates} range must reflect timestamps which appear in the price stream.
+#' Also note that you probably don't want to mark the portfolio on every tick, 
 #' 
-#' Outputs
-#' assigns position information and PL into the environment
 #' 
-#' @param Portfolio 
-#' @param Symbols
-#' @param Dates 
-#' @param Prices
+#' @return assigns position information and PL into the environment
+#' 
+#' @param Portfolio string identifying a portfolio
+#' @param Symbols character vector identifying symbols to update the portfolio for, default NULL 
+#' @param Dates xts-style ISO-8601 time range to run updatePortf over, default NULL (will use times from Prices
+#' @param Prices optional xts object containing prices and timestamps to mark the book on, default NULL
 #' @param dots any other passthrough parameters
 #' @export
 #' @callGraph
@@ -77,9 +77,9 @@
     }
 	
 	if(!is.timeBased(Dates)) Dates = time(Portfolio$symbols[[1]][Dates])
-	startDate = first(xts:::.parseISO8601(Dates))$first.time-1 #does this need to be a smaller delta for millisecond data?
+	startDate = first(xts:::.parseISO8601(Dates))$first.time-.00001 
 	# trim summary slot to not double count, related to bug 831 on R-Forge, and rbind new summary 
-	if(attr(Portfolio,'initDate')>=startDate | length(Portfolio$summary)==0){
+	if( as.POSIXct(attr(Portfolio,'initDate'))>=startDate || length(Portfolio$summary)==0 ){
 		Portfolio$summary<-summary #changes to subset might not return a empty dimnames set of columns
 	}else{
 		Portfolio$summary<-rbind(Portfolio$summary[paste('::',startDate,sep='')],summary)



More information about the Blotter-commits mailing list