[Blotter-commits] r286 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Mar 16 14:58:10 CET 2010
Author: braverock
Date: 2010-03-16 14:58:10 +0100 (Tue, 16 Mar 2010)
New Revision: 286
Modified:
pkg/blotter/R/updatePosPL.R
Log:
- fix date subsetting
- improve Close price location
Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R 2010-03-15 21:04:09 UTC (rev 285)
+++ pkg/blotter/R/updatePosPL.R 2010-03-16 13:58:10 UTC (rev 286)
@@ -70,7 +70,7 @@
#TODO write a single getTxn and use the values instead of these lines
TxnValue = getTxnValue(pname, Symbol, CurrentSpan)
TxnFees = getTxnFees(pname, Symbol, CurrentSpan)
- PosQty = getPosQty(pname, Symbol, CurrentDate)
+ PosQty = getPosQty(pname, Symbol, as.character(CurrentDate))
ClosePrice = as.numeric(last(Prices[CurrentDate, grep("Close", colnames(Prices))])) #not necessary
PosValue = calcPosValue(PosQty, ClosePrice, ConMult)
@@ -78,12 +78,12 @@
if(is.na(PrevDate))
PrevPosQty = 0
else
- PrevPosQty = getPosQty(pname, Symbol, PrevDate)
+ PrevPosQty = getPosQty(pname, Symbol, as.character(PrevDate))
if(PrevPosQty==0)
PrevClosePrice = 0
else
- PrevClosePrice = as.numeric(Prices[PrevDate, grep("Close", colnames(Prices))]) # not necessary
+ PrevClosePrice = as.numeric(Cl(Prices)[as.character(PrevDate)])
PrevPosValue = calcPosValue(PrevPosQty, PrevClosePrice, ConMult) ### @TODO: PrevConMult?
TradingPL = calcTradingPL(PosValue, PrevPosValue, TxnValue)
More information about the Blotter-commits
mailing list