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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 14 19:56:32 CET 2010


Author: braverock
Date: 2010-01-14 19:56:32 +0100 (Thu, 14 Jan 2010)
New Revision: 155

Modified:
   pkg/blotter/R/addTxn.R
   pkg/blotter/R/calcTxnAvgCost.R
Log:
- fix average cost calcs with contract multiplier

Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R	2010-01-14 18:18:15 UTC (rev 154)
+++ pkg/blotter/R/addTxn.R	2010-01-14 18:56:32 UTC (rev 155)
@@ -36,7 +36,7 @@
     txnfees <- ifelse( is.function(TxnFees), TxnFees(TxnQty, TxnPrice), TxnFees)
     # Calculate the value and average cost of the transaction
     TxnValue = calcTxnValue(TxnQty, TxnPrice, txnfees, ConMult)
-    TxnAvgCost = calcTxnAvgCost(TxnValue, TxnQty, ConMult)
+    TxnAvgCost = calcTxnAvgCost(TxnValue, TxnQty)
 
     # Calculate the change in position
     PrevPosQty = getPosQty(pname, Symbol, TxnDate)
@@ -44,7 +44,7 @@
 
     # Calculate the resulting position's average cost
     PrevPosAvgCost = getPosAvgCost(pname, Symbol, TxnDate)
-    PosAvgCost = calcPosAvgCost(PrevPosQty, PrevPosAvgCost, TxnValue, PosQty,ConMult)
+    PosAvgCost = calcPosAvgCost(PrevPosQty, PrevPosAvgCost, TxnValue, PosQty)
 
     # Calculate any realized profit or loss (net of fees) from the transaction
     RealizedPL = calcRealizedPL(TxnQty, TxnAvgCost, PrevPosAvgCost, PosQty, PrevPosQty, ConMult)
@@ -93,7 +93,7 @@
         TxnFee         <- 0 #TODO FIXME support transaction fees in addTxns
         #TxnFee         <- ifelse( is.function(TxnFees), TxnFees(TxnQty, TxnPrice), TxnFees)
         TxnValue       <- calcTxnValue(TxnQty, TxnPrice, TxnFee, ConMult)
-        TxnAvgCost     <- calcTxnAvgCost(TxnValue, TxnQty, ConMult)
+        TxnAvgCost     <- calcTxnAvgCost(TxnValue, TxnQty)
         #PrevPosQty     <- getPosQty(pname, Symbol, index(TxnData[row,]))
         PosQty         <- PrevPosQty+TxnQty
         PosAvgCost     <- calcPosAvgCost(PrevPosQty, PrevPosAvgCost, TxnValue, PosQty) # lag this over the data?

Modified: pkg/blotter/R/calcTxnAvgCost.R
===================================================================
--- pkg/blotter/R/calcTxnAvgCost.R	2010-01-14 18:18:15 UTC (rev 154)
+++ pkg/blotter/R/calcTxnAvgCost.R	2010-01-14 18:56:32 UTC (rev 155)
@@ -1,5 +1,5 @@
 `calcTxnAvgCost` <-
-function(TxnValue, TxnQty, ConMult=1)
+function(TxnValue, TxnQty)
 { # @author Peter Carl
 
     # DESCRIPTION:
@@ -14,7 +14,7 @@
     # Outputs
     # TxnAvgCost: unit normalized (per share) cost implied by the transaction
 
-    TxnAvgCost = TxnValue/(TxnQty*ConMult)
+    TxnAvgCost = TxnValue/TxnQty
     return(TxnAvgCost)
 }
 



More information about the Blotter-commits mailing list