[Blotter-commits] r398 - in pkg/blotter: R demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 20 13:52:09 CEST 2010


Author: braverock
Date: 2010-09-20 13:52:08 +0200 (Mon, 20 Sep 2010)
New Revision: 398

Modified:
   pkg/blotter/R/updatePosPL.R
   pkg/blotter/demo/longtrend.R
Log:
- make change to check for no Txns to accommodate newest 'subset' code in xts
- roll back change temporary change to longtrend demo

Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R	2010-09-18 21:24:41 UTC (rev 397)
+++ pkg/blotter/R/updatePosPL.R	2010-09-20 11:52:08 UTC (rev 398)
@@ -50,7 +50,7 @@
 	
 	Txns <- Portfolio$symbols[[Symbol]]$txn[dateRange]
 	# if there are no transactions, get the last one before the current dateRange, we'll discard later
-	if(is.null(nrow(Txns))) {
+	if(nrow(Txns)==0) {
 		Txns <- last(Portfolio$symbols[[Symbol]]$txn[paste('::',startDate,sep='')])
 		rmfirst=TRUE
 	} 

Modified: pkg/blotter/demo/longtrend.R
===================================================================
--- pkg/blotter/demo/longtrend.R	2010-09-18 21:24:41 UTC (rev 397)
+++ pkg/blotter/demo/longtrend.R	2010-09-20 11:52:08 UTC (rev 398)
@@ -82,8 +82,7 @@
     CurrentDate=time(GSPC)[i]
     cat(".")
     equity = getEndEq(ltaccount, CurrentDate)
-	hasTxns= FALSE
-	
+
     ClosePrice = as.numeric(Ad(GSPC[i,]))
     Posn = getPosQty(ltportfolio, Symbol='GSPC', Date=CurrentDate)
     UnitSize = as.numeric(trunc(equity/ClosePrice))
@@ -95,7 +94,6 @@
             cat('\n')
             # Store trade with blotter
             addTxn(ltportfolio, Symbol='GSPC', TxnDate=CurrentDate, TxnPrice=ClosePrice, TxnQty = UnitSize , TxnFees=0, verbose=verbose)
-			hasTxns=TRUE
         } 
     } else {
     # Have a position, so check exit
@@ -103,21 +101,15 @@
             cat('\n')
             # Store trade with blotter
             addTxn(ltportfolio, Symbol='GSPC', TxnDate=CurrentDate, TxnPrice=ClosePrice, TxnQty = -Posn , TxnFees=0, verbose=verbose)
-			hasTxns=TRUE
         } 
     }
 
     # Calculate P&L and resulting equity with blotter
-	if(isTRUE(hasTxns)){
-		updatePortf(ltportfolio, Dates = CurrentDate)
-		updateAcct(ltaccount, Dates = CurrentDate)
-		updateEndEq(ltaccount, Dates = CurrentDate)
-	}
+    updatePortf(ltportfolio, Dates = CurrentDate)
+    updateAcct(ltaccount, Dates = CurrentDate)
+    updateEndEq(ltaccount, Dates = CurrentDate)
 } # End dates loop
 cat('\n')
-updatePortf(ltportfolio, Dates = CurrentDate)
-updateAcct(ltaccount, Dates = CurrentDate)
-updateEndEq(ltaccount, Dates = CurrentDate)
 
 # Chart results with quantmod
 chart.Posn(ltportfolio, Symbol = 'GSPC', Dates = '1998::')



More information about the Blotter-commits mailing list