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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 12 05:11:14 CET 2010


Author: peter_carl
Date: 2010-01-12 05:11:11 +0100 (Tue, 12 Jan 2010)
New Revision: 136

Modified:
   pkg/blotter/R/initPosPL.R
   pkg/blotter/R/updatePosPL.R
Log:
- edited to use ConMult in calculation functions


Modified: pkg/blotter/R/initPosPL.R
===================================================================
--- pkg/blotter/R/initPosPL.R	2010-01-12 03:27:55 UTC (rev 135)
+++ pkg/blotter/R/initPosPL.R	2010-01-12 04:11:11 UTC (rev 136)
@@ -17,8 +17,8 @@
     # Constructs multi-column xts object used to store derived position information
 
     # FUNCTION
-    posPL <- xts( as.matrix(t(c(initPosQty,0,0,0,0,0,0))), order.by=as.POSIXct(initDate) )
-    colnames(posPL) <- c('Pos.Qty', 'Pos.Value', 'Txn.Value', 'Txn.Fees', 'Realized.PL', 'Unrealized.PL','Trading.PL')
+    posPL <- xts( as.matrix(t(c(initPosQty,0,0,0,0,0,0,0))), order.by=as.POSIXct(initDate) )
+    colnames(posPL) <- c('Pos.Qty', 'Con.Mult', 'Pos.Value', 'Txn.Value', 'Txn.Fees', 'Realized.PL', 'Unrealized.PL','Trading.PL')
     class(posPL)<- c("posPL",class(posPL))
     return(posPL)
 }

Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R	2010-01-12 03:27:55 UTC (rev 135)
+++ pkg/blotter/R/updatePosPL.R	2010-01-12 04:11:11 UTC (rev 136)
@@ -34,11 +34,14 @@
           if(length(PrevDate)==0)
              PrevDate = NA
 
+        ConMult = 1 ## @TODO: Change this to look up the value from instrument
+        PrevConMult = 1 ## @TODO: Change this to look up the value from instrument?
+
         TxnValue = getTxnValue(pname, Symbol, CurrentDate)
         TxnFees = getTxnFees(pname, Symbol, CurrentDate)
         PosQty = getPosQty(pname, Symbol, CurrentDate)
         ClosePrice = as.numeric(Prices[CurrentDate, grep("Close", colnames(Prices))]) #not necessary
-        PosValue = calcPosValue(PosQty,ClosePrice)
+        PosValue = calcPosValue(PosQty, ClosePrice, ConMult)
 
         if(is.na(PrevDate))
             PrevPosQty = 0
@@ -50,13 +53,13 @@
         else
             PrevClosePrice = as.numeric(Prices[PrevDate, grep("Close", colnames(Prices))]) # not necessary
 
-        PrevPosValue = calcPosValue(PrevPosQty,PrevClosePrice)
+        PrevPosValue = calcPosValue(PrevPosQty, PrevClosePrice, ConMult) ### @TODO: PrevConMult?
         TradingPL = calcTradingPL(PosValue, PrevPosValue, TxnValue)
         RealizedPL = getRealizedPL(pname, Symbol, CurrentDate)
         UnrealizedPL = TradingPL - RealizedPL # TODO: calcUnrealizedPL(TradingPL, RealizedPL)
 
-        NewPeriod = as.xts(t(c(PosQty, PosValue, TxnValue, TxnFees, RealizedPL, UnrealizedPL, TradingPL)), order.by=as.POSIXct(CurrentDate))
-        colnames(NewPeriod) = c('Pos.Qty', 'Pos.Value', 'Txn.Value', 'Txn.Fees', 'Realized.PL', 'Unrealized.PL', 'Trading.PL')
+        NewPeriod = as.xts(t(c(PosQty, ConMult, PosValue, TxnValue, TxnFees, RealizedPL, UnrealizedPL, TradingPL)), order.by=as.POSIXct(CurrentDate))
+        colnames(NewPeriod) = c('Pos.Qty', 'Con.Mult', 'Pos.Value', 'Txn.Value', 'Txn.Fees', 'Realized.PL', 'Unrealized.PL', 'Trading.PL')
         Portfolio[[Symbol]]$posPL <- rbind(Portfolio[[Symbol]]$posPL, NewPeriod) 
     }
     # return(Portfolio)



More information about the Blotter-commits mailing list