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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 24 05:53:06 CET 2009


Author: peter_carl
Date: 2009-11-24 05:53:05 +0100 (Tue, 24 Nov 2009)
New Revision: 124

Added:
   pkg/blotter/R/calcPosValue.R
   pkg/blotter/R/calcTradingPL.R
   pkg/blotter/R/calcUnrealizedPL.R
Modified:
   pkg/blotter/R/addTxn.R
   pkg/blotter/R/updatePosPL.R
Log:
- patches submitted by Daniel Cegielka


Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R	2009-11-24 03:46:44 UTC (rev 123)
+++ pkg/blotter/R/addTxn.R	2009-11-24 04:53:05 UTC (rev 124)
@@ -47,7 +47,7 @@
     Portfolio[[Symbol]]$txn <- rbind(Portfolio[[Symbol]]$txn, NewTxn)
 
     if(verbose)
-        print(paste(Symbol, TxnDate, TxnQty, "@",TxnPrice, sep=" "))
+        print(paste(TxnDate, Symbol, TxnQty, "@",TxnPrice, sep=" "))
     return(Portfolio)
 }
 

Added: pkg/blotter/R/calcPosValue.R
===================================================================
--- pkg/blotter/R/calcPosValue.R	                        (rev 0)
+++ pkg/blotter/R/calcPosValue.R	2009-11-24 04:53:05 UTC (rev 124)
@@ -0,0 +1,4 @@
+calcPosValue <- function(PosQty,ClosePrice) {
+  PosValue <- PosQty * ClosePrice
+  return(PosValue)
+}

Added: pkg/blotter/R/calcTradingPL.R
===================================================================
--- pkg/blotter/R/calcTradingPL.R	                        (rev 0)
+++ pkg/blotter/R/calcTradingPL.R	2009-11-24 04:53:05 UTC (rev 124)
@@ -0,0 +1,4 @@
+calcTradingPL <- function(PosValue,PrevPosValue,TxnValue) {
+  TradingPL <- PosValue - PrevPosValue - TxnValue
+  return(TradingPL)
+}

Added: pkg/blotter/R/calcUnrealizedPL.R
===================================================================
--- pkg/blotter/R/calcUnrealizedPL.R	                        (rev 0)
+++ pkg/blotter/R/calcUnrealizedPL.R	2009-11-24 04:53:05 UTC (rev 124)
@@ -0,0 +1,4 @@
+calcUnrealizedPL <- function(TradingPL, RealizedPL) {
+  UnrealizedPL <- TradingPL - RealizedPL
+  return(UnrealizedPL)
+}

Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R	2009-11-24 03:46:44 UTC (rev 123)
+++ pkg/blotter/R/updatePosPL.R	2009-11-24 04:53:05 UTC (rev 124)
@@ -39,7 +39,7 @@
         TxnFees = getTxnFees(Portfolio, Symbol, CurrentDate)
         PosQty = getPosQty(Portfolio, Symbol, CurrentDate)
         ClosePrice = as.numeric(Prices[CurrentDate, grep("Close", colnames(Prices))]) #not necessary
-        PosValue = PosQty * ClosePrice # @todo: calcPosValue(PosQty, ClosePrice)
+        PosValue = calcPosValue(PosQty,ClosePrice)
 
         if(is.na(PrevDate))
             PrevPosQty = 0
@@ -51,10 +51,8 @@
         else
             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)
-
+        PrevPosValue = calcPosValue(PrevPosQty,PrevClosePrice)
+        TradingPL = calcTradingPL(PosValue, PrevPosValue, TxnValue)
         RealizedPL = getRealizedPL(Portfolio, Symbol, CurrentDate)
         UnrealizedPL = TradingPL - RealizedPL # @todo: calcUnrealizedPL(TradingPL, RealizedPL)
 



More information about the Blotter-commits mailing list