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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 28 21:55:57 CEST 2012


Author: bodanker
Date: 2012-08-28 21:55:56 +0200 (Tue, 28 Aug 2012)
New Revision: 1142

Modified:
   pkg/blotter/R/PortfReturns.R
   pkg/blotter/R/addTxn.R
   pkg/blotter/R/getAccount.R
   pkg/blotter/R/getEndEq.R
   pkg/blotter/R/tradeStats.R
   pkg/blotter/R/updateAcct.R
   pkg/blotter/R/updateEndEq.R
   pkg/blotter/R/updatePortf.R
   pkg/blotter/R/updatePosPL.R
Log:
- Revert r1141 and add silent=TRUE to several try() calls


Modified: pkg/blotter/R/PortfReturns.R
===================================================================
--- pkg/blotter/R/PortfReturns.R	2012-08-28 16:30:18 UTC (rev 1141)
+++ pkg/blotter/R/PortfReturns.R	2012-08-28 19:55:56 UTC (rev 1142)
@@ -22,8 +22,8 @@
 PortfReturns <- function (Account, method=c('contribution'),...,Dates=NULL,Portfolios=NULL) 
 { # @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(!grepl("account\\.",aname)) Account<-try(get(paste("account",aname,sep='.'),envir=.blotter), silent=TRUE)
+	else Account<-try(get(aname,envir=.blotter), silent=TRUE)
 	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.")

Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R	2012-08-28 16:30:18 UTC (rev 1141)
+++ pkg/blotter/R/addTxn.R	2012-08-28 19:55:56 UTC (rev 1142)
@@ -67,7 +67,7 @@
     Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
 
     if(is.null(ConMult) | !hasArg(ConMult)){
-        tmp_instr<-try(getInstrument(Symbol))
+        tmp_instr<-try(getInstrument(Symbol), silent=TRUE)
         if(inherits(tmp_instr,"try-error") | !is.instrument(tmp_instr)){
             warning(paste("Instrument",Symbol," not found, using contract multiplier of 1"))
             ConMult<-1
@@ -86,8 +86,8 @@
     # FUNCTION
     # Coerce the transaction fees to a function if a string was supplied
     
-    if(is.character(TxnFees) && is.function(TxnFees)) {
-        TF <- try(match.fun(TxnFees))
+    if(is.character(TxnFees)) {
+        TF <- try(match.fun(TxnFees), silent=TRUE)
         if (!inherits(TF,"try-error")) TxnFees<-TF
     }
     # Compute transaction fees if a function was supplied
@@ -157,7 +157,7 @@
     Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
 
     if(is.null(ConMult) | !hasArg(ConMult)){
-        tmp_instr<-try(getInstrument(Symbol))
+        tmp_instr<-try(getInstrument(Symbol), silent=TRUE)
         if(inherits(tmp_instr,"try-error") | !is.instrument(tmp_instr)){
             warning(paste("Instrument",Symbol," not found, using contract multiplier of 1"))
             ConMult<-1
@@ -239,7 +239,7 @@
     Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
 
     if(is.null(ConMult) | !hasArg(ConMult)){
-        tmp_instr<-try(getInstrument(Symbol))
+        tmp_instr<-try(getInstrument(Symbol), silent=TRUE)
         if(inherits(tmp_instr,"try-error") | !is.instrument(tmp_instr)){
             warning(paste("Instrument",Symbol," not found, using contract multiplier of 1"))
             ConMult<-1

Modified: pkg/blotter/R/getAccount.R
===================================================================
--- pkg/blotter/R/getAccount.R	2012-08-28 16:30:18 UTC (rev 1141)
+++ pkg/blotter/R/getAccount.R	2012-08-28 19:55:56 UTC (rev 1142)
@@ -8,8 +8,8 @@
 getAccount <- function(Account) #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(!grepl("account\\.",aname)) Account<-try(get(paste("account",aname,sep='.'),envir=.blotter), silent=TRUE)
+    else Account<-try(get(aname,envir=.blotter), silent=TRUE)
     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.")
@@ -35,8 +35,8 @@
 { # @author Brian Peterson
     if(inherits(x,'account')) return(TRUE)
     else if(is.character(x)){
-        if(!grepl("account\\.",x)) res <- suppressWarnings(try(get(paste("account",x,sep='.'),envir=.blotter),silent=TRUE))
-        else res <- suppressWarnings(try(get(x,envir=.blotter),silent=TRUE))
+        if(!grepl("account\\.",x)) res <- suppressWarnings(try(get(paste("account",x,sep='.'),envir=.blotter), silent=TRUE))
+        else res <- suppressWarnings(try(get(x,envir=.blotter), silent=TRUE))
         #res<-suppressWarnings(try(getaccount(x))) #causes spurious error if you're checking whether account exists
         if(!inherits(res,"account")) {
             message("account ",x," needs to be created first.")

Modified: pkg/blotter/R/getEndEq.R
===================================================================
--- pkg/blotter/R/getEndEq.R	2012-08-28 16:30:18 UTC (rev 1141)
+++ pkg/blotter/R/getEndEq.R	2012-08-28 19:55:56 UTC (rev 1142)
@@ -6,7 +6,7 @@
 getEndEq <- function(Account, Date)
 { # @author Peter Carl
     aname<-Account
-    Account<-try(get(paste("account",aname,sep='.'), envir=.blotter))
+    Account<-try(get(paste("account",aname,sep='.'), envir=.blotter), silent=TRUE)
     if(inherits(Account,"try-error"))
         stop(paste("Account",aname," not found, use initAcct() to create a new account"))
 

Modified: pkg/blotter/R/tradeStats.R
===================================================================
--- pkg/blotter/R/tradeStats.R	2012-08-28 16:30:18 UTC (rev 1141)
+++ pkg/blotter/R/tradeStats.R	2012-08-28 19:55:56 UTC (rev 1142)
@@ -59,8 +59,8 @@
         ## Error Handling Borrowed from getPortfolio
         pname <- Portfolio
         if (!grepl("portfolio\\.", pname)) 
-		Portfolio <- try(get(paste("portfolio", pname, sep = "."), 	envir = .blotter))
-    	else Portfolio <- try(get(pname, envir = .blotter))
+		Portfolio <- try(get(paste("portfolio", pname, sep = "."), envir = .blotter), silent=TRUE)
+    	else Portfolio <- 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")) 
@@ -193,8 +193,8 @@
         ## Error Handling Borrowed from getPortfolio
         pname <- Portfolio
         if (!grepl("portfolio\\.", pname)) 
-            Portfolio <- try(get(paste("portfolio", pname, sep = "."),  envir = .blotter))
-        else Portfolio <- try(get(pname, envir = .blotter))
+            Portfolio <- try(get(paste("portfolio", pname, sep = "."), envir = .blotter), silent=TRUE)
+        else Portfolio <- 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")) 
@@ -236,8 +236,8 @@
         ## Error Handling Borrowed from getPortfolio
         pname <- Portfolio
         if (!grepl("portfolio\\.", pname)) 
-            Portfolio <- try(get(paste("portfolio", pname, sep = "."),  envir = .blotter))
-        else Portfolio <- try(get(pname, envir = .blotter))
+            Portfolio <- try(get(paste("portfolio", pname, sep = "."), envir = .blotter), silent=TRUE)
+        else Portfolio <- 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")) 

Modified: pkg/blotter/R/updateAcct.R
===================================================================
--- pkg/blotter/R/updateAcct.R	2012-08-28 16:30:18 UTC (rev 1141)
+++ pkg/blotter/R/updateAcct.R	2012-08-28 19:55:56 UTC (rev 1142)
@@ -37,7 +37,7 @@
 		if( a.ccy.str != p.ccy.str ){
             # If not, translate the portfolio summary to the account currency
 			CcyMult <- NA
-			port_currency<-try(getInstrument(p.ccy.str))
+			port_currency<-try(getInstrument(p.ccy.str), silent=TRUE)
 			if(inherits(port_currency,"try-error") | !is.instrument(port_currency)){
 				warning("Currency",p.ccy.str," not found, using currency multiplier of 1")
 				CcyMult<-1

Modified: pkg/blotter/R/updateEndEq.R
===================================================================
--- pkg/blotter/R/updateEndEq.R	2012-08-28 16:30:18 UTC (rev 1141)
+++ pkg/blotter/R/updateEndEq.R	2012-08-28 19:55:56 UTC (rev 1142)
@@ -13,7 +13,7 @@
 updateEndEq <- function(Account, Dates=NULL)
 {
 	aname<-Account
-    Account<-try(get(paste("account",aname,sep='.'), envir=.blotter))
+    Account<-try(get(paste("account",aname,sep='.'), envir=.blotter), silent=TRUE)
     if(inherits(Account,"try-error"))
         stop(paste("Account",aname," not found, use initAcct() to create a new account"))
     

Modified: pkg/blotter/R/updatePortf.R
===================================================================
--- pkg/blotter/R/updatePortf.R	2012-08-28 16:30:18 UTC (rev 1141)
+++ pkg/blotter/R/updatePortf.R	2012-08-28 19:55:56 UTC (rev 1142)
@@ -25,7 +25,7 @@
         Symbols = names(Portfolio$symbols)
     } 
     for(symbol in Symbols){
-        tmp_instr<-try(getInstrument(symbol))
+        tmp_instr<-try(getInstrument(symbol), silent=TRUE)
         .updatePosPL(Portfolio=pname, Symbol=as.character(symbol), Dates=Dates, Prices=Prices, ...=...)            
     }
 	

Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R	2012-08-28 16:30:18 UTC (rev 1141)
+++ pkg/blotter/R/updatePosPL.R	2012-08-28 19:55:56 UTC (rev 1142)
@@ -17,7 +17,7 @@
     Portfolio<-getPortfolio(pname) 
 	p.ccy.str<-attr(Portfolio,'currency')
 	if(is.null(p.ccy.str)) p.ccy.str<-'NA'
-    tmp_instr<-try(getInstrument(Symbol))
+    tmp_instr<-try(getInstrument(Symbol), silent=TRUE)
     if(inherits(tmp_instr,"try-error") | !is.instrument(tmp_instr)){
 	    warning(paste("Instrument",Symbol," not found, things may break"))
 		tmp_instr<-list(currency="USD",multiplier=1)
@@ -159,7 +159,7 @@
 		if (tmp_instr$currency==p.ccy.str) {
 			CcyMult<-1			
 		} else {
-			port_currency<-try(getInstrument(p.ccy.str))
+			port_currency<-try(getInstrument(p.ccy.str), silent=TRUE)
 			if(inherits(port_currency,"try-error") | !is.instrument(port_currency)){
 				warning("Currency",p.ccy.str," not found, using currency multiplier of 1")
 				CcyMult<-1



More information about the Blotter-commits mailing list