[Blotter-commits] r1573 - in pkg/blotter: R src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Nov 17 15:13:54 CET 2013


Author: bodanker
Date: 2013-11-17 15:13:54 +0100 (Sun, 17 Nov 2013)
New Revision: 1573

Modified:
   pkg/blotter/R/calcPosAvgCost.R
   pkg/blotter/src/calcPosAvgCost.c
Log:
- Fix PosAvgCost bug when prices are negative. Thanks to Shang Gao for spotting the issue.
  Previous bugfix probably addressed something fixed in r1007 or r1051.


Modified: pkg/blotter/R/calcPosAvgCost.R
===================================================================
--- pkg/blotter/R/calcPosAvgCost.R	2013-11-13 20:58:15 UTC (rev 1572)
+++ pkg/blotter/R/calcPosAvgCost.R	2013-11-17 14:13:54 UTC (rev 1573)
@@ -16,8 +16,6 @@
         # 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)
     }
     return(PosAvgCost)

Modified: pkg/blotter/src/calcPosAvgCost.c
===================================================================
--- pkg/blotter/src/calcPosAvgCost.c	2013-11-13 20:58:15 UTC (rev 1572)
+++ pkg/blotter/src/calcPosAvgCost.c	2013-11-17 14:13:54 UTC (rev 1573)
@@ -32,8 +32,6 @@
             /* position is decreasing, pos avg cost for the open position remains the same */
             d_PosAvgCost[i] = d_PrevPosAvgCost;
         } else {
-            if(d_PrevPosAvgCost<0)
-                d_TxnValue[i]= -1.0 * d_TxnValue[i]; /* fix bug with negative average cost */
             d_PosAvgCost[i] = (d_PrevPosQty * d_PrevPosAvgCost * d_ConMult + d_TxnValue[i])/(d_PosQty[i]*d_ConMult);
         }
         d_PrevPosQty = d_PosQty[i];



More information about the Blotter-commits mailing list