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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 15 17:39:44 CEST 2012


Author: braverock
Date: 2012-06-15 17:39:44 +0200 (Fri, 15 Jun 2012)
New Revision: 1051

Modified:
   pkg/blotter/R/calcPosAvgCost.R
Log:
- don't change posAvgCost if position is decreasing (getting closer to flat), posAvgCost for remaining open position is the same

Modified: pkg/blotter/R/calcPosAvgCost.R
===================================================================
--- pkg/blotter/R/calcPosAvgCost.R	2012-06-15 12:48:56 UTC (rev 1050)
+++ pkg/blotter/R/calcPosAvgCost.R	2012-06-15 15:39:44 UTC (rev 1051)
@@ -11,7 +11,10 @@
 { # @author Peter Carl
     if(PosQty == 0)
         PosAvgCost = 0
-    else {
+    else if(abs(PrevPosQty) > abs(PosQty)){
+        # position is decreasing, pos avg cost for the open position remains the same
+        PosAvgCost = PrevPosAvgCost   
+    } else {
         if(PrevPosAvgCost<0) TxnValue= -1*TxnValue #fix bug with negative average cost 
         # PosAvgCost = abs((PrevPosQty * PrevPosAvgCost * ConMult + TxnValue)/(PosQty*ConMult))
         PosAvgCost = (PrevPosQty * PrevPosAvgCost * ConMult + TxnValue)/(PosQty*ConMult)



More information about the Blotter-commits mailing list