protected override double GetBidPrice() { double logNormal = getLogNormal(); double price = Orderbook.getLowestAsk() - logNormal + _optimism * Orderbook.getPrice(); double roundedPrice = Math.Round(price*100.0)/100.0; SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "XXX I am "+this.ID+" BID time is "+Scheduler.GetTime()+ " myBidPrice: "+roundedPrice+ " OBprice: "+Orderbook.getPrice()+ " OBspread: "+Orderbook.getSpread() ); return roundedPrice; }
protected override double GetAskPrice() { double mean = Orderbook.getLowestAsk(); double std = Orderbook.getPrice() - Orderbook.getHighestBid(); std = 0.02; double price = SingletonRandomGenerator.Instance.NextGaussianPositive(mean, std); double roundedPrice = Math.Round(price * 100.0) / 100.0; roundedPrice += 0.03; return(roundedPrice); }
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) { return(Orderbook.getLowestAsk()); } // limit order double off = getOffset(); double basePrice = Orderbook.getPrice(); // Orderbook.getLowestAsk(); //Orderbook.getHighestBid() double price = basePrice - off; double roundedPrice = 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); }
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); }