Building a simulation engine

Introducing the stochadex project

The building blocks of simulations that we have discussed can now be pieced together to form a complete simulation engine.

The stochadex project is an actual simulation engine written in Go which is based on these basic conceptual building blocks.

Armed with the fundamentals, we can now describe how this simulation engine was built in specific detail, supported by the appropriate system diagrams.

Interfaces and data types

The fundamental data types in the stochadex simulation engine are Go types which can be configured as Settings (pure data) or Implementations (code which implements the provided interfaces).

For example, the Iteration interface can be implemented.

The Iteration interface is very general. For example, it can support the Wiener process.

Or Itô’s lemma, which has more function calls inside to, e.g., calculate the derivatives.

Or the time-inhomogeneous Poisson process, as an example of a event-based process with discrete sample paths, which varies its event rate in time.

Or the Hawkes process, which couples the history of events to the current event rate (making it non-Markovian).

Serial dependency graphs and modularity

Multiple Iterations can run within the stochadex for each step in time. In order to construct serial dependency graphs between them, we can utilise upstream-downstream Iteration relationships.

Structuring groups of Iterations in this way can increase modularity. For example, the time-inhomogeneous Poisson process can be implemented serially.

Simulation loop and embedded simulation runs

The full simulation loop coordinates the serial relationships between Iterations while maximising concurrency in execution of each Iteration per step in time.

Given that this loop always runs for any stochadex simulation, it is sufficient to describe any simulation uniquely through the dependency diagram between its Iterations.

Embedded simulation runs are Iterations which perform entire simulations from start to end for every step in time. Their presence can make dependency diagrams a little more complex, but much more flexible.