[Blotter-commits] r397 - pkg/blotter/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Sep 18 23:24:41 CEST 2010
Author: braverock
Date: 2010-09-18 23:24:41 +0200 (Sat, 18 Sep 2010)
New Revision: 397
Modified:
pkg/blotter/demo/longtrend.R
Log:
- hopefully temporary change to workaround xts dropping columns in merge
Modified: pkg/blotter/demo/longtrend.R
===================================================================
--- pkg/blotter/demo/longtrend.R 2010-09-18 21:04:55 UTC (rev 396)
+++ pkg/blotter/demo/longtrend.R 2010-09-18 21:24:41 UTC (rev 397)
@@ -82,7 +82,8 @@
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))
@@ -94,6 +95,7 @@
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
@@ -101,15 +103,21 @@
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
- updatePortf(ltportfolio, Dates = CurrentDate)
- updateAcct(ltaccount, Dates = CurrentDate)
- updateEndEq(ltaccount, Dates = CurrentDate)
+ if(isTRUE(hasTxns)){
+ 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