internal MarginAndQuantityResult Add(MarginAndQuantityResult other) { this.Margin += other.Margin; this.Quantity += other.Quantity; this.PartialMargin += other.PartialMargin; this.PartialQuantity += other.PartialQuantity; return(this); }
internal void Add(bool isBuy, BuySellPair margin, BuySellPair quantity, BuySellPair partialMargin, BuySellPair partialQuantity) { if (isBuy) { this.Margin.AddBuy(margin); this.Quantity.AddBuy(quantity); this.PartialMargin.AddBuy(partialMargin); this.PartialQuantity.AddBuy(partialQuantity); } else { this.Margin.AddSell(margin); this.Quantity.AddSell(quantity); this.PartialMargin.AddSell(partialMargin); this.PartialQuantity.AddSell(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); } }
// given a path to a text file it will return the best buy/sell days public string BestBuySell(string path) { try { // get the list of prices from the file List <decimal> prices = ProcessFile(path); // create the buySellPair object with default values. BuySellPair buySellPair = new BuySellPair { highDay = 0, lowDay = 0, highPrice = 0, lowPrice = 0 }; // loop through the list of prices for (int i = 0; i < prices.Count; i++) { // for every price check each remaining price for (int j = i + 1; j < prices.Count; j++) { // if j - i is greater than the current best buy/sell margin make it the new best margin. if (prices[j] - prices[i] > buySellPair.highPrice - buySellPair.lowPrice) { // assign low/high properties to the buySellPairObject buySellPair.lowPrice = prices[i]; buySellPair.highPrice = prices[j]; buySellPair.lowDay = i + 1; buySellPair.highDay = j + 1; } } } // printing in the format provided - buyDay(buyPrice),sellDay(sellPrice) if (buySellPair.lowDay == 0) { return("There was no suitable buy date as stock prices never increased."); } else { return($"{buySellPair.lowDay}({buySellPair.lowPrice}),{buySellPair.highDay}({buySellPair.highPrice})"); } } catch (Exception e) { throw new Exception(e.Message); } }
private static void InitializeFilledAndMarginArgs(this AccountClass.Instrument instrument, bool isBuy, MarginAndQuantityResult unfilledArgs, MarginAndQuantityResult filledArgs, MarginAndQuantityResult marginArgs) { var physicalInstrument = instrument as Physical.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); }
internal void Add(bool isBuy, MarginAndQuantityResult unfilledResult, MarginAndQuantityResult filledResult) { if (isBuy) { var normalMargin = new BuySellPair(unfilledResult.Normal.Margin.Buy, filledResult.Normal.Margin.Sell); var normalQuantity = new BuySellPair(unfilledResult.Normal.Quantity.Buy, filledResult.Normal.Quantity.Sell); var partialMargin = new BuySellPair(unfilledResult.Partial.Margin.Buy, filledResult.Partial.Margin.Sell); var partialQuantity = new BuySellPair(unfilledResult.Partial.Quantity.Buy, filledResult.Partial.Quantity.Sell); this.Normal += new MarginAndQunatity(normalMargin, normalQuantity); this.Partial += new MarginAndQunatity(partialMargin, partialQuantity); } else { var margin = new BuySellPair(filledResult.Normal.Margin.Buy, unfilledResult.Normal.Margin.Sell); var quantity = new BuySellPair(filledResult.Normal.Quantity.Buy, unfilledResult.Normal.Margin.Sell); var partialMargin = new BuySellPair(filledResult.Partial.Margin.Buy, unfilledResult.Partial.Margin.Sell); var partialQuantity = new BuySellPair(filledResult.Partial.Quantity.Buy, unfilledResult.Partial.Quantity.Sell); this.Normal += new MarginAndQunatity(margin, quantity); this.Partial += new MarginAndQunatity(partialMargin, partialQuantity); } }
internal MarginAndQunatity Add(bool isBuy, BuySellPair margin, BuySellPair quantity) { return(isBuy ? new MarginAndQunatity(this.Margin.AddBuy(margin), this.Quantity.AddBuy(quantity)) : new MarginAndQunatity(this.Margin.AddSell(margin), this.Quantity.AddSell(quantity))); }
internal void Add(bool isBuy, BuySellPair margin, BuySellPair quantity, BuySellPair partialMargin, BuySellPair partialQuantity) { this.Normal = this.Normal.Add(isBuy, margin, quantity); this.Partial = this.Partial.Add(isBuy, partialMargin, partialQuantity); }
internal MarginAndQunatity(BuySellPair margin, BuySellPair quantity) : this() { this.Margin = margin; this.Quantity = quantity; }