public void AgentOrderbookLoaderTest() { Console.WriteLine("AgentOrderbookLoaderTest"); LoggerInitialization.SetThreshold(typeof(sim_tests), LogLevel.Debug); LoggerInitialization.SetThreshold(typeof(AbstractAgent), LogLevel.Info); LoggerInitialization.SetThreshold(typeof(AgentOrderbookLoader), LogLevel.Info); string PATH = "" + ApplicationConfig.EXECDIR + "orderbooks/orderbook.csv"; AgentOrderbookLoader loader = MakeAgentOrderbookLoader(PATH); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "AgentOrderbookLoader: " + loader); IOrderbook_Observable ob = new Orderbook(); IPopulation pop = new Population(); pop.addAgent(loader); ISimulation sim = new Simulation(pop, ob, 0.0, 100.0); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Running Simulation"); ISimulationResults res = sim.run(); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Stopping Simulation"); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "ob: " + ob.ToStringLong()); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "res: " + res.ToStringLong()); Assert.AreEqual(res.Valid, true); }
public void Agent0x1Simulation_ZeroDimensional() { Console.WriteLine("Agent0x1Simulation_ZeroDimensional"); LoggerInitialization.SetThreshold(typeof(sim_tests), LogLevel.Debug); LoggerInitialization.SetThreshold(typeof(AbstractAgent), LogLevel.Info); LoggerInitialization.SetThreshold(typeof(AgentOrderbookLoader), LogLevel.Info); LoggerInitialization.SetThreshold(typeof(Agent0x0), LogLevel.Info); int dim = 0; string [] names = new string [0]; double [] mins = new double [0]; double [] maxs = new double [0]; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); IBlauPoint mean = new BlauPoint(s); IBlauPoint std = new BlauPoint(s); IDistribution d = new Distribution_Gaussian(s, mean, std); IAgentFactory afact = new Agent0x0_Factory(d); int NUMAGENTS = 10; IPopulation pop = PopulationFactory.Instance().create(afact, NUMAGENTS); foreach (IAgent ag in pop) { SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "agent: " + ag); } string PATH = "" + ApplicationConfig.EXECDIR + "orderbooks/orderbook.csv"; AgentOrderbookLoader loader = MakeAgentOrderbookLoader(PATH); pop.addAgent(loader); IOrderbook_Observable ob = new Orderbook(); string PROPERTY = "NetWorth"; IAgentEvaluationBundle aeb = new AgentEvaluationBundle(PROPERTY); // 1 hours ISimulation sim = new Simulation(pop, ob, 0.0, 3600.0); NamedMetricAgentEvaluationFactory metricEF = new NamedMetricAgentEvaluationFactory(PROPERTY); sim.add(metricEF); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Running Simulation"); ISimulationResults res = sim.run(); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Stopping Simulation"); IAgentEvaluation ae = metricEF.create(); aeb.addAgentEvaluation(ae); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "ob: " + ob.ToStringLong()); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "aeb: " + aeb.ToStringLong()); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "res: " + res.ToStringLong()); Assert.AreEqual(res.Valid, true); }
protected override bool DecideToMakeOrder() { if ( ! Orderbook.isNonDegenerate()) { SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "XXXXXXXXX OB: " + Orderbook.ToStringLong()); return false; } if (_haveOrder) { // SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "I cannot make a new order, I have one"); return false; } bool makeorder = (SingletonRandomGenerator.Instance.NextDouble() <= _aggressiveness); // SingletonLogger.Instance().DebugLog(typeof(Agent1x0), "I am "+this.ID+" DecideToMakeOrder: "+makeorder); if (makeorder) { IncrementTotalOrders(); _haveOrder = true; } return makeorder; }
public override void SimulationEndNotification() { SingletonLogger.Instance().DebugLog(typeof(AgentOrderbookLoader), "*** AgentOrderbookLoader got ISimulationEnd @ " + Scheduler.GetTime()); SingletonLogger.Instance().InfoLog(typeof(AgentOrderbookLoader), "*** OB " + Orderbook.ToStringLong()); }
public override void SimulationEndNotification() { SingletonLogger.Instance().DebugLog(typeof(TrajectoryFactory_Price), "SimulationEndNotification"); Console.WriteLine("DEBUG" + Orderbook.ToStringLong()); }
// receive a signal from the Simulation (via the Population) public override void Recv(ISimEntity src, ISimEvent simEvent) { if (Orderbook == null) { return; } if (LoggerDiags.Enabled) { SingletonLogger.Instance().DebugLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + "recv ISimEvent " + simEvent + " @ " + Scheduler.GetTime()); } // events received from the DES if (simEvent is ActionPrompt) { if (DecideToAct()) { if (LoggerDiags.Enabled) { SingletonLogger.Instance().DebugLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + "acts @ " + Scheduler.GetTime() + " I have " + _orders.Count + " orders open"); } EvaluateAllOpenOrders(); if (DecideToMakeOrder()) { if (LoggerDiags.Enabled) { SingletonLogger.Instance().DebugLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + "makes order @ " + Scheduler.GetTime()); } if (!Orderbook.isNonDegenerate()) { SingletonLogger.Instance().WarningLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " witnesses Orderbook blowup @ " + Scheduler.GetTime() + "\n" + Orderbook.ToStringLong()); } IOrder newOrder = null; if (DecideToSubmitBid()) { if (LoggerDiags.Enabled) { SingletonLogger.Instance().DebugLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " submits bid @ " + Scheduler.GetTime()); } // bid double price = GetBidPrice(); int volume = GetBidVolume(); if (volume > 0) { newOrder = Orderbook.addBid(price, volume, this); } else { if (LoggerDiags.Enabled) { SingletonLogger.Instance().WarningLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " attempts unsuccessful zero sized bid @ " + Scheduler.GetTime()); } } } else { if (LoggerDiags.Enabled) { SingletonLogger.Instance().DebugLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " submits ask @ " + Scheduler.GetTime()); } // ask double price = GetAskPrice(); int volume = GetAskVolume(); if (volume > 0) { newOrder = Orderbook.addAsk(price, volume, this); } else { if (LoggerDiags.Enabled) { SingletonLogger.Instance().WarningLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " attempts unsuccessful zero sized ask @ " + Scheduler.GetTime()); } } } if (newOrder != null) { // may be null if dual volume is 0 preventing creation of new orders AddToOpenOrderList(newOrder); if (LoggerDiags.Enabled) { SingletonLogger.Instance().DebugLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " submitted " + newOrder + " @ " + Scheduler.GetTime()); } } else { throw new Exception("We got a problem"); } } } double timeToNextPrompt = GetTimeToNextActionPrompt(); if (timeToNextPrompt < 0.0) { // agent checks out of ecosystem by indicating a negative time if (LoggerDiags.Enabled) { SingletonLogger.Instance().WarningLog(typeof(AbstractAgent), "AbstractAgent " + GetName() + " leaves simulation by indicating negative prompt time @ " + Scheduler.GetTime()); } } else { this.Send(this, simEvent, timeToNextPrompt); } } }