void MoneyTransaction(ref Bids bid, long quanity) { //if (bid.Price != offer.Price) { // Console.WriteLine("Bid Price and Offer Price not the same!"); //} _TradePrice = bid.Price; }
public void ProRata(ref Bids bid, ref List <Offers> offers, int ProRataMinimumAlloaction) { long TotalQuanityOfOffers = 0; long BidQuanity = bid.Quanity; foreach (Offers o in offers) { TotalQuanityOfOffers += o.Quanity; } for (int i = 0; i < offers.Count; i++) { offers[i].ProRata = (float)offers[i].Quanity / (float)TotalQuanityOfOffers; int ProRataAmount = (int)(offers[i].ProRata * BidQuanity); if (ProRataAmount >= ProRataMinimumAlloaction) { if (ProRataAmount > offers[i].Quanity) { Offers o2 = offers[i]; new Trade(ref bid, ref o2, offers[i].quanity); offers[i] = o2; } else { Offers o2 = offers[i]; new Trade(ref bid, ref o2, ProRataAmount); offers[i] = o2; } } } }
public Trade(ref Bids bid, long quanity) { UpdateQuanities(ref bid, quanity); MoneyTransaction(ref bid, quanity); UpdateDatabase(ref bid, quanity); AddToTransactionList(ref bid, quanity); }
void UpdateQuanities(ref Bids bid, long quanity) { bid.Quanity -= quanity; if (bid.Owner.OnBuy != null) { bid.Owner.OnBuy(quanity); } }
void DisplayDetails(Bids bid, List <Offers> offers) { Console.WriteLine(); Console.WriteLine("Price: {0} Bid Qaunity: {1}", bid.Price, bid.Quanity); Console.WriteLine("Offers:"); foreach (Offers o in offers) { Console.WriteLine("Client {0} is offering {1}", o.Owner.ID, o.Quanity); } }
void UpdateQuanities(ref Bids bid, ref Offers offer, long quanity) { bid.Quanity -= quanity; offer.quanity -= quanity; if (bid.Owner.OnBuy != null) { bid.Owner.OnBuy(quanity); } if (offer.Owner.OnSell != null) { offer.Owner.OnSell(quanity); } }
public void ProRataWithLMM(List <BidPriceLevel> BidsPool, List <OfferPriceLevel> OffersPool) { BidsPool = BidsPool.OrderBy((BidPriceLevel b) => b.Price).ToList(); OffersPool = OffersPool.OrderByDescending((OfferPriceLevel o) => o.Price).ToList(); foreach (BidPriceLevel BPL in BidsPool) { for (int j = 0; j < OffersPool.Count; j++) { if (OffersPool[j].Price <= BPL.Price) { while (BPL.bids.Count != 0 && OffersPool[j].offers.Count != 0) { Bids b = BPL.bids[0]; List <Offers> offers = OffersPool[j].offers; //DisplayDetails(b, offers); LMMRound(ref b, ref offers); //DisplayDetails(b, offers); ProRata(ref b, ref offers, 1); //DisplayDetails(b, offers); FIFO(ref b, ref offers); //DisplayDetails(b, offers); BPL.bids[0] = b; OffersPool[j].offers = offers; if (BPL.bids[0].Quanity == 0) { BPL.bids.RemoveAt(0); } OffersPool[j].offers.RemoveAll((Offers o) => o.Quanity == 0); } } } } foreach (BidPriceLevel BPL in BidsPool) { foreach (Bids b in BPL.bids) { b.TurnsInPool++; } } foreach (OfferPriceLevel OPL in OffersPool) { foreach (Offers o in OPL.offers) { o.TurnsInPool++; } } UpdatePools(BidsPool, OffersPool); }
public static void AddBid(Bids bid) { for (int i = 0; i < BidsPool.Count; i++) { if (bid.Price == BidsPool[i].Price) { BidsPool[i].bids.Add(bid); return; } } BidsPool.Add(new BidPriceLevel { Price = bid.Price, bids = new List <Bids>() { bid } }); BidsPool = BidsPool.OrderBy((BidPriceLevel b) => b.Price).ToList(); }
public void FIFO(ref Bids bid, ref List <Offers> offers) { //foreach (Offers o in offers) { for (int i = 0; i < offers.Count; i++) { if (offers[i].Quanity > bid.Quanity) { Offers o2 = offers[i]; new Trade(ref bid, ref o2, bid.Quanity); offers[i] = o2; break; } else { Offers o2 = offers[i]; new Trade(ref bid, ref o2, offers[i].quanity); offers[i] = o2; } } }
public void LMMRound(ref Bids bid, ref List <Offers> offers) { long BidQuanity = bid.Quanity; for (int i = 0; i < offers.Count; i++) { if (offers[i].Owner.LMMPercentage > 0f) { int LMMAmount = (int)(BidQuanity * offers[i].Owner.LMMPercentage); if (LMMAmount > offers[i].Quanity) { Offers o2 = offers[i]; new Trade(ref bid, ref o2, offers[i].quanity); offers[i] = o2; } else { Offers o2 = offers[i]; new Trade(ref bid, ref o2, LMMAmount); offers[i] = o2; } } } }
public void AddJob(Bids bid) { Queue.Add(new Job(JobType.Bid, bid)); }
public Job(JobType jobType, Bids Bid = null, Offers Offer = null) { this.jobType = jobType; this.Bid = Bid; this.Offer = Offer; }
void AddToTransactionList(ref Bids bid, long quanity) { StockTicker.TradesThisTurn.Add(this); }
void UpdateDatabase(ref Bids bid, long quanity) { }
void UpdateDatabase(ref Bids bid, ref Offers offer, long quanity) { }