public void AddTx(IPositionTx posTx) { IsOpenClose isOpen = IsOpenClose.Close; InstrumentSize newSize = posTx.Size + Size; if (!posTx.IsCashPosition) { // Determine if it is opening or closing if (Size == null || Size.IsZero) isOpen = IsOpenClose.Open; else if (newSize.Sign != Size.Sign && newSize.IsNotZero) isOpen = IsOpenClose.Both; else { if (posTx.Side == Side.Sell || posTx.Side == Side.XO) isOpen = IsOpenClose.Close; else isOpen = IsOpenClose.Open; } // Realised Amount if (isOpen == IsOpenClose.Close) { Money amount = (posTx.Price - BookPrice) * (posTx.Size * -1); RealisedAmount += amount; RealisedAmountToDate += amount; } else if (isOpen == IsOpenClose.Both) { // Position has swapped -> the old position size has relised Money amount = (posTx.Price - BookPrice) * Size; RealisedAmount += amount; RealisedAmountToDate += amount; } // Book Values if (isOpen == IsOpenClose.Open) { if (BookPrice == null) BookPrice = posTx.Price; else { if (newSize.IsNotZero) BookPrice = ((posTx.Price * posTx.Size) + (Size * BookPrice)) / newSize; } BookValue += (posTx.Value * -1); //if (posTx.IsCashPosition) //{ // //if (posTx.Size.Sign) //} } else if (isOpen == IsOpenClose.Both) { BookPrice = posTx.Price; BookValue = ((newSize * posTx.Price) * -1); } else // Close { if (Size.IsNotZero && newSize.IsNotZero) BookValue = BookValue / (Size.Quantity / newSize.Quantity); else BookValue = BookValue.Clone(0M); } BookChange += (posTx.Value * -1); } else { BookValue += posTx.Value; BookChange += posTx.Value; } Size = newSize; }
internal void AddTx(IPositionTx posTx) { Money amount = posTx.Size.GetMoney(); switch (posTx.ValuationCashTxMapping) { case B4F.TotalGiro.Orders.Transactions.ValuationCashTxTypeMapping.CostsCommission: CostsCommission += amount; CostsCommissionToDate += amount; break; case B4F.TotalGiro.Orders.Transactions.ValuationCashTxTypeMapping.CostsTax: CostsTax += amount; CostsTaxToDate += amount; break; case B4F.TotalGiro.Orders.Transactions.ValuationCashTxTypeMapping.CostFee: CostsFee += amount; CostsFeeToDate += amount; break; case B4F.TotalGiro.Orders.Transactions.ValuationCashTxTypeMapping.CostsOther: CostsOther += amount; CostsOtherToDate += amount; break; case B4F.TotalGiro.Orders.Transactions.ValuationCashTxTypeMapping.IncomeCashDividend: IncomeCashDividend += amount; IncomeCashDividendToDate += amount; break; case B4F.TotalGiro.Orders.Transactions.ValuationCashTxTypeMapping.IncomeInterest: IncomeInterest += amount; IncomeInterestToDate += amount; break; case B4F.TotalGiro.Orders.Transactions.ValuationCashTxTypeMapping.IncomeOther: IncomeOther += amount; IncomeOtherToDate += amount; break; } }
internal void Add(IPositionTx posTx) { DateTime tradeDate = posTx.TransactionDate; ValuationMutation mutation; if (mutations.ContainsKey(tradeDate)) mutation = mutations[tradeDate]; else { mutation = new ValuationMutation(this, tradeDate, LastMutation); if (mutations.Count == 0) FirstMutation = mutation; mutations.Add(tradeDate, mutation); LastMutation = mutation; } mutation.AddTx(posTx); }