26 private DateTime _lastSettlementDate;
27 private decimal _settledFutureQuantity;
28 private decimal _settlementPrice;
36 if(_settledFutureQuantity != 0)
38 var fill = applyFundsParameters.
Fill;
39 var security = applyFundsParameters.
Security;
42 var absoluteQuantityClosed = Math.Min(fill.AbsoluteFillQuantity, security.Holdings.AbsoluteQuantity);
44 var absoluteQuantityClosedSettled = Math.Min(absoluteQuantityClosed, Math.Abs(_settledFutureQuantity));
45 var quantityClosedSettled = Math.Sign(-fill.FillQuantity) * absoluteQuantityClosedSettled;
48 var factor = quantityClosedSettled / _settledFutureQuantity;
49 _settledFutureQuantity -= quantityClosedSettled;
52 var removedSettledProfit = factor * futureHolding.SettledProfit;
53 futureHolding.SettledProfit -= removedSettledProfit;
58 base.ApplyFunds(applyFundsParameters);
67 var security = settlementParameters.
Security;
70 if (_lastSettlementDate.Date < security.LocalTime.Date)
72 if ((_lastSettlementDate !=
default) && security.Invested)
76 _settlementPrice = futureCache.SettlementPrice;
77 _settledFutureQuantity = security.Holdings.
Quantity;
80 var dailyProfitLoss = futureHolding.TotalCloseProfit(includeFees:
false, exitPrice: _settlementPrice) - futureHolding.SettledProfit;
81 if (dailyProfitLoss != 0)
83 futureHolding.SettledProfit += dailyProfitLoss;
85 settlementParameters.
Portfolio.
CashBook[security.QuoteCurrency.Symbol].AddAmount(dailyProfitLoss);
86 Log.
Trace($
"FutureSettlementModel.Scan({security.Symbol}): {security.LocalTime} Daily P&L: {dailyProfitLoss} " +
87 $
"Quantity: {_settledFutureQuantity} Settlement: {_settlementPrice} UnrealizedProfit: {futureHolding.UnrealizedProfit}");
90 _lastSettlementDate = security.LocalTime.Date;
100 _lastSettlementDate = newLocalTime.Date;