[Blotter-commits] r93 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jul 18 15:49:15 CEST 2009


Author: peter_carl
Date: 2009-07-18 15:49:15 +0200 (Sat, 18 Jul 2009)
New Revision: 93

Modified:
   pkg/R/updatePosPL.R
Log:
- fixes selection of prior date to support single day update


Modified: pkg/R/updatePosPL.R
===================================================================
--- pkg/R/updatePosPL.R	2009-07-17 03:51:17 UTC (rev 92)
+++ pkg/R/updatePosPL.R	2009-07-18 13:49:15 UTC (rev 93)
@@ -29,15 +29,16 @@
     for(i in 1:length(Dates)){ ##
         # Get the current date and close price
         CurrentDate = Dates[i]
-        if(i>1) # if it isn't the first price in the time series
-            PrevDate = Dates[i-1]
-        else
-            PrevDate = NA
+#          if(i>1) # if it isn't the first price in the time series
+            PrevDate = time(Prices[grep(CurrentDate,time(Prices))-1])
+#          else
+          if(length(PrevDate)==0)
+             PrevDate = NA
 
         TxnValue = getTxnValue(Portfolio, Symbol, CurrentDate)
         TxnFees = getTxnFees(Portfolio, Symbol, CurrentDate)
         PosQty = getPosQty(Portfolio, Symbol, CurrentDate)
-        ClosePrice = as.numeric(Prices[i, grep("Close", colnames(Prices))]) #not necessary
+        ClosePrice = as.numeric(Prices[CurrentDate, grep("Close", colnames(Prices))]) #not necessary
         PosValue = PosQty * ClosePrice # @todo: calcPosValue(PosQty, ClosePrice)
 
         if(is.na(PrevDate))
@@ -48,7 +49,8 @@
         if(PrevPosQty==0)
             PrevClosePrice = 0
         else
-            PrevClosePrice = as.numeric(Prices[i-1,grep("Close", colnames(Prices))]) # not necessary
+            PrevClosePrice = as.numeric(Prices[PrevDate, grep("Close", colnames(Prices))]) # not necessary
+
         PrevPosValue = PrevPosQty * PrevClosePrice # @todo: use calcPosValue()
 
         TradingPL = PosValue - PrevPosValue - TxnValue # @todo: calcTradingPL(PosValue, PrevPosValue, TxnValue)



More information about the Blotter-commits mailing list