public void BasicAuctionTestMethod() { List <DisplayOrder> bids = new List <DisplayOrder>(); List <DisplayOrder> asks = new List <DisplayOrder>(); bids.Add(new DisplayOrder(1, 100)); bids.Add(new DisplayOrder(0.99, 500)); asks.Add(new DisplayOrder(0.99, 500)); asks.Add(new DisplayOrder(0.99, 500)); AuctionMatchResult r = AsxAuctionMatchCalculator.Calc(bids, asks); Assert.AreEqual(0.99, r.IEP); Assert.AreEqual(600, r.IEV); }
private double GetContinuousPotDollar(List <DisplayOrder> bids, List <DisplayOrder> asks, AuctionMatchResult r, double fv) { double bidPot = 0; double askPot = 0; foreach (DisplayOrder o in bids) { if (o.Px >= fv) { double refPx = o.Px; bidPot += o.Qty * (refPx - fv); } } foreach (DisplayOrder o in asks) { if (o.Px <= fv) { double refPx = o.Px; askPot += o.Qty * (fv - refPx); } } return(Math.Max(bidPot, askPot)); }
private double GetMMPotDollar(List <DisplayOrder> bids, List <DisplayOrder> asks, AuctionMatchResult r, double fv) { double bidPot = 0; double askPot = 0; foreach (DisplayOrder o in bids) { if (o.Px >= fv) { double refPx = o.Px; if (r.IEP != 0) { refPx = Math.Min(r.IEP, refPx); } bidPot += o.Qty * (refPx - fv); } } foreach (DisplayOrder o in asks) { if (o.Px <= fv) { double refPx = o.Px; if (r.IEP != 0) { refPx = Math.Max(r.IEP, refPx); } askPot += o.Qty * (fv - refPx); } } return(Math.Max(bidPot, askPot)); }
private void CalcButton_OnClick(object sender, EventArgs e) { List <DisplayOrder> bids = bidDataGridView.Rows.Cast <DataGridViewRow>().Select(r1 => r1.DataBoundItem as DisplayOrder).ToList(); List <DisplayOrder> asks = askDataGridView.Rows.Cast <DataGridViewRow>().Select(r2 => r2.DataBoundItem as DisplayOrder).ToList(); AuctionMatchResult r = AsxAuctionMatchCalculator.Calc(bids, asks); IEPValue_label.Text = r.IEP.ToString(); IEQValue_Label.Text = r.IEV.ToString(); BindingSource bs = (BindingSource)bidDataGridView.DataSource; int cumMatchQty = 0; foreach (DisplayOrder o in bs) { o.MatchingQty = Math.Max(0, Math.Min(r.IEV - cumMatchQty, o.Qty)); cumMatchQty += o.MatchingQty; } bs = (BindingSource)askDataGridView.DataSource; cumMatchQty = 0; foreach (DisplayOrder o in bs) { o.MatchingQty = Math.Max(0, Math.Min(r.IEV - cumMatchQty, o.Qty)); cumMatchQty += o.MatchingQty; } if (string.IsNullOrEmpty(FvTextBox.Text)) { Redraw(); return; } try { double fv = double.Parse(FvTextBox.Text); PotDollarDB_Label.Text = GetDbPotDollar(bids, asks, r, fv).ToString(); PotDollarMM_Label.Text = GetMMPotDollar(bids, asks, r, fv).ToString(); PotDollarContinuous_Label.Text = GetContinuousPotDollar(bids, asks, r, fv).ToString(); bs = (BindingSource)bidDataGridView.DataSource; double ownPnl = 0; foreach (DisplayOrder o in bs) { o.Pnl = o.MatchingQty * (fv - r.IEP); if (o.IsOwnOrder) { ownPnl += o.Pnl; } } bs = (BindingSource)askDataGridView.DataSource; foreach (DisplayOrder o in bs) { o.Pnl = o.MatchingQty * (r.IEP - fv); if (o.IsOwnOrder) { ownPnl += o.Pnl; } } OwnPnlLabel.Text = ownPnl.ToString(); } catch (Exception ex) { }; Redraw(); }