private double getLogNormal () { double normal = SingletonRandomGenerator.Instance.NextGaussian (0.0, 1.0); // offset from best opposing order double x = 2.0 * _lambda - 1.0; double a = 0.14; double pi = Math.PI; double q = (2.0 / (pi * a) + Math.Log (1.0 - x * x) / 2.0); double q2 = Math.Log (1.0 - x * x) / a; if (q * q < q2) throw new Exception ("qq < q2"); double erfinvx = Math.Sqrt (Math.Sqrt (q * q - q2) - q); if (Math.Sqrt (q * q - q2) < q) throw new Exception ("Math.Sqrt(q*q - q2) < q"); double sigma = -1.0 * Math.Sqrt (2.0) * erfinvx; // gamma fraction captured in twice spread if (Orderbook.getSpread () < 0) { return 0.0; // throw new Exception ("Orderbook.getSpread() < 0"); } double mu = sigma*sigma + Math.Log( _gamma * Orderbook.getSpread() ); double logNormal = Math.Exp(mu + sigma * normal); return logNormal; }
private double getOffset() { double W = Orderbook.getSpread(); double uniformToss = SingletonRandomGenerator.Instance.NextUniform(0.0, 1.0); double logNormalToss = getLogNormalToss(W, uniformToss); return(logNormalToss); }
public override void PartialFilledOrderNotification(IOrder partialOrder, double price, int volume) { AccumulateNetWorth( ValuateTransaction(partialOrder, price, volume) ); SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "XXX I am "+this.ID+" PARTLYEXECUTED time is "+Scheduler.GetTime()+ " filledOrder: "+partialOrder+ " Filled "+volume+" AT : "+price+ " OBprice: "+Orderbook.getPrice()+ " OBspread: "+Orderbook.getSpread() + " My net worth is "+GetMetricValue(NetWorth_METRICNAME)); }
public override void CancelOrderNotification(IOrder cancelledOrder) { if (Orderbook.isNonDegenerate()) { if (Orderbook.getSpread() >= 0.0) { MyTrajectory.add(TimeNow, Orderbook.getSpread()); } } }
public override void FilledOrderNotification(IOrder filledOrder, double price, int volume) { if (Orderbook.isNonDegenerate()) { if (Orderbook.getSpread() >= 0.0) { MyTrajectory.add(TimeNow, Orderbook.getSpread()); } } }
protected override double GetAskPrice() { double logNormal = getLogNormal(); double price = Orderbook.getHighestBid() + logNormal + _optimism * Orderbook.getPrice(); double roundedPrice = Math.Round(price*100.0)/100.0; SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "XXX I am "+this.ID+" ASK time is "+Scheduler.GetTime()+ " myAskPrice: "+roundedPrice+ " OBprice: "+Orderbook.getPrice()+ " OBspread: "+Orderbook.getSpread() ); 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); }
public override void FilledOrderNotification(IOrder filledOrder, double price, int volume) { if (Orderbook.getSpread() <= 0.0) { return; } SingletonLogger.Instance().DebugLog(typeof(TrajectoryFactory_Price), "FilledOrderNotification"); if (Orderbook.isNonDegenerate() && MyTrajectory.ThresholdTimePassed(TimeNow)) { MyTrajectory.add(TimeNow, GetPriceNormalizedAlphaSpread()); } }
public override void SimulationEndNotification() { MyTrajectory.add(TimeNow, Orderbook.getSpread()); }