public override void FilledOrderNotification(IOrder filledOrder, double price, int volume) { if (Orderbook.isNonDegenerate()) { MyTrajectory.add(TimeNow, Orderbook.getNumBids() + Orderbook.getNumAsks()); } }
public override void CancelOrderNotification(IOrder cancelledOrder) { if (Orderbook.isNonDegenerate()) { MyTrajectory.add(TimeNow, Orderbook.getNumBids() + Orderbook.getNumAsks()); } }
public override void SimulationEndNotification() { // Console.WriteLine("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "+this+"; time now is: "+TimeNow); SingletonLogger.Instance().DebugLog(typeof(TrajectoryFactory_Price), "SimulationEndNotification"); MyTrajectory.add(TimeNow, Orderbook.getNumAsks()); }
public override string ToString() { string s = "SimulationBundle [" + StartTime + "-" + (StartTime + Duration) + "] ==> "; s += "OB asks:" + Orderbook.getNumAsks() + ", bids:" + Orderbook.getNumBids() + "; "; s += "Pop:" + Population.Size; return(s); }
public override void CancelOrderNotification(IOrder cancelledOrder) { SingletonLogger.Instance().DebugLog(typeof(TrajectoryFactory_Price), "CancelOrderNotification"); if (Orderbook.isNonDegenerate()) { MyTrajectory.add(TimeNow, Orderbook.getNumAsks()); } }
public override void PartialFilledOrderNotification(IOrder partialOrder, double price, int volume) { SingletonLogger.Instance().DebugLog(typeof(TrajectoryFactory_Price), "PartialFilledOrderNotification"); if (Orderbook.isNonDegenerate()) { MyTrajectory.add(TimeNow, Orderbook.getNumAsks()); } }
protected override double GetAskPrice() { double mean = (Orderbook.getNumAsks() > 0 ? Orderbook.getLowestAsk() : (Orderbook.getNumBids() > 0 ? Orderbook.getHighestBid() : Orderbook.getPrice())); double std = Orderbook.getSpread(); //std = 0.02; double price = SingletonRandomGenerator.Instance.NextGaussianPositive(mean, std); double roundedPrice = Math.Round(price * 100.0) / 100.0; roundedPrice += 0.03; validateMetrics(7); SingletonLogger.Instance().DebugLog(typeof(Agent0x1), "I am " + this.ID + " GetAskPrice: " + roundedPrice + " -- price = " + price + " ; mean = " + mean + " spread = " + Orderbook.getSpread()); return(roundedPrice); }
protected override double GetBidPrice() { if (_market) { if (Orderbook.getNumAsks() > 0) { return(Orderbook.getLowestAsk()); } else { return(Orderbook.getPrice()); } } double price = _pe.getBidPrice(Orderbook); double roundedPrice = price; // Math.Round(price*100.0)/100.0; /* * SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "XXX I am "+this.ID+" time is "+Scheduler.GetTime() +" myBidPrice: "+roundedPrice+ * " OBprice: "+Orderbook.getPrice()+ * " OBspread: "+Orderbook.getSpread() + " I have "+OpenOrdersCount ()+ " open orders"); */ return(roundedPrice); }
public void Orderbook_AddOrdersTest() { Console.WriteLine("Orderbook_AddOrdersTest"); Orderbook ob = new Orderbook(); Matcher m = new Matcher(); ob.setMatcher(m); // no bids or asks Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 0); // place ask 1 IOrder o1 = ob.addAsk(10.0, 3, null); Assert.AreEqual(ob.getNumAsks(), 1); Assert.AreEqual(ob.getNumBids(), 0); Assert.AreEqual(o1.isAsk(), true); Assert.AreEqual(o1.getPrice(), 10.0); Assert.AreEqual(o1.getVolume(), 3); Assert.AreEqual(o1.isCancelled(), false); Assert.AreEqual(o1.isFilled(), false); Assert.AreEqual(o1.getCapital(), 0.0); Assert.AreEqual(o1.getOwner(), null); // place bid 2 IOrder o2 = ob.addBid(5.0, 3, null); Assert.AreEqual(ob.getNumAsks(), 1); Assert.AreEqual(ob.getNumBids(), 1); Assert.AreEqual(o2.isAsk(), false); Assert.AreEqual(o2.getPrice(), 5.0); Assert.AreEqual(o2.getVolume(), 3); Assert.AreEqual(o2.isCancelled(), false); Assert.AreEqual(o2.isFilled(), false); Assert.AreEqual(o2.getCapital(), 0.0); Assert.AreEqual(o2.getOwner(), null); Assert.AreEqual(ob.getHighestBid(), 5.0); Assert.AreEqual(ob.getLowestAsk(), 10.0); // place bid 3 IOrder o3 = ob.addBid(10.0, 3, null); Assert.AreEqual(ob.getNumAsks(), 1); Assert.AreEqual(ob.getNumBids(), 2); Assert.AreEqual(o3.isAsk(), false); Assert.AreEqual(o3.getPrice(), 10.0); Assert.AreEqual(o3.getVolume(), 3); Assert.AreEqual(o3.isCancelled(), false); Assert.AreEqual(o3.isFilled(), false); Assert.AreEqual(o3.getCapital(), 0.0); Assert.AreEqual(o3.getOwner(), null); Assert.AreEqual(ob.getHighestBid(), 10.0); Assert.AreEqual(ob.getLowestAsk(), 10.0); // execution occurs -- o3 hits o1, leaving just the bid o2 Scheduler.Instance().Run(); Assert.AreEqual(m.NumAddOrdersReceived, 3, "orders = 3"); Assert.AreEqual(m.NumFillsSent, 2, "fills = 2"); Assert.AreEqual(m.NumPartialFillsSent, 0, "partial fills = 0"); Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 1); Assert.AreEqual(o3.isFilled(), true); Assert.AreEqual(o3.getCapital(), -30.0); Assert.AreEqual(o1.isFilled(), true); Assert.AreEqual(o1.getCapital(), 30.0); IOrder o4 = ob.addAsk(5.0, 1, null); IOrder o5 = ob.addAsk(5.0, 1, null); IOrder o6 = ob.addAsk(5.0, 1, null); Assert.AreEqual(o4.isAsk(), true); Assert.AreEqual(o4.getPrice(), 5.0); Assert.AreEqual(o4.getVolume(), 1); Assert.AreEqual(o4.isCancelled(), false); Assert.AreEqual(o4.isFilled(), false); Assert.AreEqual(o4.getCapital(), 0.0); Assert.AreEqual(o4.getOwner(), null); Assert.AreEqual(o5.isAsk(), true); Assert.AreEqual(o5.getPrice(), 5.0); Assert.AreEqual(o5.getVolume(), 1); Assert.AreEqual(o5.isCancelled(), false); Assert.AreEqual(o5.isFilled(), false); Assert.AreEqual(o5.getCapital(), 0.0); Assert.AreEqual(o5.getOwner(), null); Assert.AreEqual(o6.isAsk(), true); Assert.AreEqual(o6.getPrice(), 5.0); Assert.AreEqual(o6.getVolume(), 1); Assert.AreEqual(o6.isCancelled(), false); Assert.AreEqual(o6.isFilled(), false); Assert.AreEqual(o6.getCapital(), 0.0); Assert.AreEqual(o6.getOwner(), null); // execution occurs: 4 5 and 6 to hit o2 Scheduler.Instance().Run(); Assert.AreEqual(o4.isFilled(), true); Assert.AreEqual(o4.getCapital(), 5.0); Assert.AreEqual(o6.isFilled(), true); Assert.AreEqual(o6.getCapital(), 5.0); Assert.AreEqual(o5.isFilled(), true); Assert.AreEqual(o5.getCapital(), 5.0); Assert.AreEqual(o2.isFilled(), true); Assert.AreEqual(o2.getCapital(), -15.0); Assert.AreEqual(m.NumAddOrdersReceived, 6, "orders = 6"); Assert.AreEqual(m.NumFillsSent, 6, "fills = 6"); Assert.AreEqual(m.NumPartialFillsSent, 2, "partial fills = 2"); Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 0); //Assert.AreEqual(1, 0); }
public void Orderbook_ComplexMatcherTest() { Console.WriteLine("Orderbook_ComplexMatcherTest"); Orderbook ob = new Orderbook(); Matcher m = new Matcher(); ob.setMatcher(m); IOrder o2 = ob.addBid(5.0, 3, null); // let o2 fail to execute Scheduler.Instance().Run(); IOrder o3 = ob.addBid(10.0, 5, null); // low asks will hit an existing high bid IOrder o4 = ob.addAsk(5.0, 1, null); Assert.AreEqual(ob.getNumAsks(), 1); Assert.AreEqual(ob.getNumBids(), 2); IOrder o5 = ob.addAsk(5.0, 1, null); Assert.AreEqual(ob.getNumAsks(), 2); Assert.AreEqual(ob.getNumBids(), 2); IOrder o6 = ob.addAsk(5.0, 1, null); Assert.AreEqual(ob.getNumAsks(), 3); Assert.AreEqual(ob.getNumBids(), 2); // execution occurs: 4 5 and 6 partially hit 3 out of 5 units of o3 at the ask price (5) Scheduler.Instance().Run(); Assert.AreEqual(m.NumAddOrdersReceived, 5, "orders = 5"); Assert.AreEqual(m.NumFillsSent, 3, "fills = 3"); Assert.AreEqual(m.NumPartialFillsSent, 3, "partial fills = 3"); Assert.AreEqual(o4.isFilled(), true); Assert.AreEqual(o4.getCapital(), 5.0); Assert.AreEqual(o6.isFilled(), true); Assert.AreEqual(o6.getCapital(), 5.0); Assert.AreEqual(o5.isFilled(), true); Assert.AreEqual(o5.getCapital(), 5.0); Assert.AreEqual(o3.isFilled(), false); Assert.AreEqual(o3.getCapital(), -15.0); Assert.AreEqual(o2.isFilled(), false); Assert.AreEqual(o2.getCapital(), 0.0); Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 2); IOrder o7 = ob.addAsk(20.0, 1, null); IOrder o8 = ob.addAsk(20.0, 2, null); IOrder o9 = ob.addAsk(20.0, 3, null); // load up the new ask orders Scheduler.Instance().Run(); Assert.AreEqual(m.NumAddOrdersReceived, 8, "orders = 8"); Assert.AreEqual(m.NumFillsSent, 3, "fills = 3"); Assert.AreEqual(m.NumPartialFillsSent, 3, "partial fills = 3"); // high bid will hit existing low asks IOrder o10 = ob.addBid(100.0, 7, null); // execution occurs: 7 8 and 9 partially hit 10 out of 6 units of o10 at the ask price (20) Scheduler.Instance().Run(); Assert.AreEqual(o7.isFilled(), true); Assert.AreEqual(o7.getCapital(), 20.0); Assert.AreEqual(o8.isFilled(), true); Assert.AreEqual(o8.getCapital(), 40.0); Assert.AreEqual(o9.isFilled(), true); Assert.AreEqual(o9.getCapital(), 60.0); Assert.AreEqual(o10.isFilled(), false); Assert.AreEqual(o10.getCapital(), -120.0); Assert.AreEqual(m.NumAddOrdersReceived, 9, "orders = 9"); Assert.AreEqual(m.NumFillsSent, 6, "fills = 6"); Assert.AreEqual(m.NumPartialFillsSent, 6, "partial fills = 6"); Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 3); }
public void Orderbook_CancelOrdersTest() { Console.WriteLine("Orderbook_CancelOrdersTest"); Orderbook ob = new Orderbook(); Matcher m = new Matcher(); ob.setMatcher(m); // no bids or asks Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 0); // place ask 1 IOrder o1 = ob.addAsk(10.0, 3, null); // place bid 2 IOrder o2 = ob.addBid(5.0, 3, null); // no bids or asks Assert.AreEqual(ob.getNumAsks(), 1); Assert.AreEqual(ob.getNumBids(), 1); bool cancelResult = ob.cancelOrder(o1); Assert.AreEqual(cancelResult, true); // no asks, 1 bid Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 1); Scheduler.Instance().Run(); // place bid 3 IOrder o3 = ob.addBid(10.0, 5, null); // no asks, 2 bid Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 2); Scheduler.Instance().Run(); // execution is attempted -- but nothing can execute // since o2 cannot match o3 Scheduler.Instance().Run(); Assert.AreEqual(o1.isFilled(), false); Assert.AreEqual(o1.isCancelled(), true); Assert.AreEqual(o1.getCapital(), 0.0); Assert.AreEqual(o2.isFilled(), false); Assert.AreEqual(o2.isCancelled(), false); Assert.AreEqual(o2.getCapital(), 0.0); Assert.AreEqual(o3.isFilled(), false); Assert.AreEqual(o3.isCancelled(), false); Assert.AreEqual(o3.getCapital(), 0.0); Assert.AreEqual(m.NumAddOrdersReceived, 3, "orders = 3"); Assert.AreEqual(m.NumFillsSent, 0, "fills = 0"); Assert.AreEqual(m.NumPartialFillsSent, 0, "partial fills = 0"); Assert.AreEqual(ob.getNumAsks(), 0); Assert.AreEqual(ob.getNumBids(), 2); }
public override void SimulationEndNotification() { MyTrajectory.add(TimeNow, Orderbook.getNumBids() + Orderbook.getNumAsks()); }