Class MyEngine

All Implemented Interfaces:
IEngine, Runnable

public class MyEngine extends Engine implements IEngine
Simulation engine for the order flow model. This class creates the arrival process, service points, matching components, and statistics collection used during one simulation run. It processes events in stages, updates the order book, sends refresh events to the UI controller, and stores the final results when the run ends.
  • Constructor Details

    • MyEngine

      public MyEngine(IModelToViewController controller, long seed, double meanValidation, double meanMarketMatching, double meanLimitMatching, double meanExecution, double arrivalMean, double marketOrderRatio, double buyOrderRatio, double initialMidPrice, double priceVolatility, double tickSize, String runTitle)
      Creates a simulation engine with the selected run parameters.
      Parameters:
      controller - controller that receives UI updates from the engine
      seed - base random seed for the simulation
      meanValidation - mean service time for validation
      meanMarketMatching - mean service time for market order matching
      meanLimitMatching - mean service time for limit order matching
      meanExecution - mean service time for execution
      arrivalMean - mean time between arrivals
      marketOrderRatio - share of market orders in generated flow
      buyOrderRatio - share of buy orders in generated flow
      initialMidPrice - starting mid price for generated orders
      priceVolatility - volatility used for generated order prices
      tickSize - minimum allowed price step
      runTitle - title stored with the saved run results
  • Method Details

    • initialization

      protected void initialization()
      Schedules the first arrival event before the simulation loop starts.
      Specified by:
      initialization in class Engine
    • afterCycle

      protected void afterCycle()
      Runs after each simulation cycle. Updates collected statistics, builds a fresh order book snapshot, and sends the new table data to the UI.
      Overrides:
      afterCycle in class Engine
    • runEvent

      protected void runEvent(Event t)
      Handles one event from the event list. Orders move through validation, matching, and execution stages, while trades and finished orders are recorded in the statistics collector.
      Specified by:
      runEvent in class Engine
      Parameters:
      t - event selected by the simulation framework
    • results

      protected void results()
      Finalizes the run after the simulation loop ends. Builds the final statistics snapshot, saves the results to the database, and notifies the UI that the simulation has finished.
      Specified by:
      results in class Engine
    • getStatisticsSnapshot

      public StatisticsCollector.Snapshot getStatisticsSnapshot()
      Returns the latest final statistics snapshot created in results().
      Specified by:
      getStatisticsSnapshot in interface IEngine
      Returns:
      final snapshot for the completed run
    • getStatisticsRecord

      public Records.StatisticsAndMetricsRecord getStatisticsRecord()
      Returns the latest database record created for the completed run.
      Specified by:
      getStatisticsRecord in interface IEngine
      Returns:
      saved statistics record for the completed run