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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 12 19:27:33 CEST 2010


Author: braverock
Date: 2010-09-12 19:27:33 +0200 (Sun, 12 Sep 2010)
New Revision: 394

Modified:
   pkg/blotter/R/addTxn.R
   pkg/blotter/R/updatePosPL.R
Log:
- fix passing of dots and TxnFees.  bug reported by Andre Barosso < andre <dot> barroso <at> gmail <dot> com >


Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R	2010-09-12 17:27:10 UTC (rev 393)
+++ pkg/blotter/R/addTxn.R	2010-09-12 17:27:33 UTC (rev 394)
@@ -15,10 +15,10 @@
 #' @export
 addTxn <- function(Portfolio, Symbol, TxnDate, TxnQty, TxnPrice, ..., TxnFees=0, ConMult=NULL, verbose=TRUE)
 { # @author Peter Carl
-	
+
     pname<-Portfolio
     Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
-    
+
     if(is.null(ConMult) | !hasArg(ConMult)){
         tmp_instr<-try(getInstrument(Symbol))
         if(inherits(tmp_instr,"try-error") | !is.instrument(tmp_instr)){
@@ -26,11 +26,11 @@
             ConMult<-1
         } else {
             ConMult<-tmp_instr$multiplier
-        }  
+        }
     }
-	
-	
-	
+
+
+
 	#If there is no table for the symbol then create a new one
 	if (is.null(Portfolio$symbols[[Symbol]])){ 
 		addPortfInstr(Portfolio=pname, symbols=Symbol)
@@ -43,7 +43,9 @@
 
     # FUNCTION
     # Compute transaction fees if a function was supplied
-    txnfees <- ifelse( is.function(TxnFees), TxnFees(TxnQty, TxnPrice), TxnFees)
+    if (is.function(TxnFees)) txnfees <- TxnFees(TxnQty, TxnPrice) else txnfees<- eval(as.numeric(TxnFees))
+    if(is.null(txnfees) | is.na(txnfees)) txnfees = 0
+
     # Calculate the value and average cost of the transaction
     TxnValue = calcTxnValue(TxnQty, TxnPrice, 0, ConMult) # Gross of Fees
     TxnAvgCost = calcTxnAvgCost(TxnValue, TxnQty, ConMult)

Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R	2010-09-12 17:27:10 UTC (rev 393)
+++ pkg/blotter/R/updatePosPL.R	2010-09-12 17:27:33 UTC (rev 394)
@@ -24,9 +24,10 @@
 		prices=getPrice(get(Symbol, envir=as.environment(.GlobalEnv)))
 	} 
 	
-    if(is.null(Dates)) {# if no date is specified, get all available dates
-        Dates = time(prices)
+        if(is.null(Dates)) {# if no date is specified, get all available dates
+            Dates = time(prices)
 	} else if(!is.timeBased(Dates)) Dates = time(prices[Dates])
+    
 
 	# line up Prices dates with Dates set/index/span passed in.
 	startDate = xts:::.parseISO8601(first(Dates))$first.time-1 #does this need to be a smaller/larger delta for millisecond data?
@@ -179,4 +180,4 @@
 #
 # $Id$
 #
-###############################################################################
\ No newline at end of file
+###############################################################################



More information about the Blotter-commits mailing list