internal MarginAndQuantityResult Add(MarginAndQuantityResult other) { this.Margin += other.Margin; this.Quantity += other.Quantity; this.PartialMargin += other.PartialMargin; this.PartialQuantity += other.PartialQuantity; return(this); }
private static decimal CalculateNecessary(Instrument instrument, bool isBuy, MarginAndQuantityResult marginArgs, MarginAndQuantityResult filledArgs) { MarginAndQuantityResult necessaryParams = new MarginAndQuantityResult(); necessaryParams.Add(isBuy, marginArgs, filledArgs); var result = instrument.CalculateNecessary(necessaryParams); return(result.NetNecessary + result.HedgeNecessary); }
internal MarginAndQuantityResult CalculateUnfilledMarginArgsForPlacePendingOrder(Instrument instrument, Transaction tran, bool isBuy, out Dictionary <Guid, decimal> remainFilledLotPerOrderDict) { MarginAndQuantityResult result = new MarginAndQuantityResult(); bool isAutoClose = tran.Owner.IsAutoClose || instrument.IsPhysical; decimal totalUnfilledLot = this.CalculateUnfilledLot(instrument, tran, isBuy, isAutoClose, out remainFilledLotPerOrderDict); if (isAutoClose && totalUnfilledLot > 0) { decimal totalAutoCloseLot = FilledCalculator.Default.CalculateTotalAutoCloseLot(instrument, isBuy, totalUnfilledLot, remainFilledLotPerOrderDict); var unfilledLotPerTran = this.CalculateUnfilledLotPerTransaction(instrument, isBuy, totalAutoCloseLot); result = this.CalculateUnfilledMarginAndQuantity(instrument, isBuy, unfilledLotPerTran); } return(result); }
private MarginAndQuantityResult CalculateUnfilledMarginAndQuantity(Instrument instrument, bool isBuy, Dictionary <Guid, decimal> unfilledLotsPerTran) { MarginAndQuantityResult result = new MarginAndQuantityResult(); foreach (Transaction eachTran in instrument.GetTransactions()) { decimal?unfilledLot; if (eachTran.ShouldCalculatePreCheckNecessary(instrument, isBuy, unfilledLotsPerTran, out unfilledLot)) { result += eachTran.CalculateUnfilledMarginAndQuantity(unfilledLot); } } return(result); }
internal MarginAndQuantityResult CalculateFillMarginAndQuantity(Instrument instrument, bool isBuy, Dictionary <Guid, decimal> remainFilledLotPerOrderDict) { var result = new MarginAndQuantityResult(); foreach (Transaction eachTran in instrument.GetTransactions()) { foreach (Order eachOrder in eachTran.Orders) { if (eachOrder.ShouldCalculateFilledMarginAndQuantity(isBuy)) { result += eachOrder.CalculateFilledMarginAndQuantity(isBuy, remainFilledLotPerOrderDict); } } } return(result); }
internal void Add(bool isBuy, MarginAndQuantityResult other) { if (isBuy) { this.Margin.AddBuy(other.Margin); this.Quantity.AddBuy(other.Quantity); this.PartialMargin.AddBuy(other.PartialMargin); this.PartialQuantity.AddBuy(other.PartialQuantity); } else { this.Margin.AddSell(other.Margin); this.Quantity.AddSell(other.Quantity); this.PartialMargin.AddSell(other.PartialMargin); this.PartialQuantity.AddSell(other.PartialQuantity); } }
internal void Add(bool isBuy, MarginAndQuantityResult unfilledResult, MarginAndQuantityResult filledResult) { if (isBuy) { this.Margin += new BuySellPair(unfilledResult.Margin.Buy, filledResult.Margin.Sell); this.Quantity += new BuySellPair(unfilledResult.Quantity.Buy, filledResult.Quantity.Sell); this.PartialMargin += new BuySellPair(unfilledResult.PartialMargin.Buy, filledResult.PartialMargin.Sell); this.PartialQuantity += new BuySellPair(unfilledResult.PartialQuantity.Buy, filledResult.PartialQuantity.Sell); } else { this.Margin += new BuySellPair(filledResult.Margin.Buy, unfilledResult.Margin.Sell); this.Quantity += new BuySellPair(filledResult.Quantity.Buy, unfilledResult.Margin.Sell); this.PartialMargin += new BuySellPair(filledResult.PartialMargin.Buy, unfilledResult.PartialMargin.Sell); this.PartialQuantity += new BuySellPair(filledResult.PartialQuantity.Buy, unfilledResult.PartialQuantity.Sell); } }
private static decimal InnerCalculatePreCheckNecessary(Instrument instrument, Transaction tran, bool isBuy) { TradePolicyDetail tradePolicyDetail = instrument.TradePolicyDetail; MarginAndQuantityResult unfilledArgs = new MarginAndQuantityResult(); Dictionary <Guid, decimal> remainFilledLotPerOrderDict = null; if (tran.IsPending) { unfilledArgs = UnfilledCalculator.Default.CalculateUnfilledMarginArgsForPlacePendingOrder(instrument, tran, isBuy, out remainFilledLotPerOrderDict); } MarginAndQuantityResult filledArgs = new MarginAndQuantityResult(); MarginAndQuantityResult marginArgs = new MarginAndQuantityResult(); instrument.InitializeFilledAndMarginArgs(isBuy, unfilledArgs, filledArgs, marginArgs); filledArgs += FilledCalculator.Default.CalculateFillMarginAndQuantity(instrument, isBuy, remainFilledLotPerOrderDict); return(CalculateNecessary(instrument, isBuy, marginArgs, filledArgs)); }
public static CalculateNecessaryResult CalculateNecessary(this Instrument instrument, MarginAndQuantityResult necessaryParams) { var result = new CalculateNecessaryResult(); if (necessaryParams.PartialQuantity.Sell > 0) { result.PartialPaymentPhysicalNecessary = necessaryParams.PartialMargin.Sell; } else if (necessaryParams.PartialQuantity.Buy > 0) { result.PartialPaymentPhysicalNecessary = necessaryParams.PartialMargin.Buy; } instrument.CalculateNecessaryHelper(necessaryParams.Margin.Buy, necessaryParams.Quantity.Buy, necessaryParams.Margin.Sell, necessaryParams.Quantity.Sell, ref result.PartialPaymentPhysicalNecessary, out result.NetNecessary, out result.HedgeNecessary); return(result); }
private static void InitializeFilledAndMarginArgs(this Instrument instrument, bool isBuy, MarginAndQuantityResult unfilledArgs, MarginAndQuantityResult filledArgs, MarginAndQuantityResult marginArgs) { var physicalInstrument = instrument as PhysicalInstrument; BuySellPair margin, quantity, partialMargin, partialQuantity; margin = new BuySellPair(instrument.TotalBuyMargin, instrument.TotalSellMargin); quantity = new BuySellPair(instrument.TotalBuyQuantity, instrument.TotalSellQuantity); if (physicalInstrument != null) { partialMargin = new BuySellPair(physicalInstrument.TotalBuyMarginForPartialPaymentPhysicalOrder, physicalInstrument.TotalSellMarginForPartialPaymentPhysicalOrder); partialQuantity = new BuySellPair(physicalInstrument.TotalBuyLotBalanceForPartialPaymentPhysicalOrder, physicalInstrument.TotalSellLotBalanceForPartialPaymentPhysicalOrder); } else { partialMargin = BuySellPair.Empty; partialQuantity = BuySellPair.Empty; } filledArgs.Add(isBuy, margin, quantity, partialMargin, partialQuantity); marginArgs.Add(isBuy, unfilledArgs); marginArgs.Add(isBuy, margin, quantity, partialMargin, partialQuantity); }