1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//!
//! ## Where things are
//!
//! [`engine::Engine`] owns a market and runs the day loop. It takes its
//! coefficients from a [`params::ModelParams`], which is one of the named
//! presets ([`params::ModelParams::preset`]) or a preset with overrides, and
//! its roster from [`universe`]. The rest are the parts the engine is built
//! from, and each can be called on its own:
//!
//! - [`market`]: the tick, the factor model, GARCH and the trading clock.
//! - [`economy`]: the macro chain (GDP, inflation, unemployment, the VIX,
//! the business cycle) and the central bank.
//! - [`order_book`], [`agent_book`], [`market_maker`] and
//! [`microstructure`]: the limit order book and the depth around it.
//! - [`fair_value`] and [`mispricing`]: what a stock is worth and how far
//! its price has strayed from it.
//! - [`rates`]: bond indices priced off the engine's yield curve.
//! - [`derivatives`]: what futures and options read: the engine's forecast
//! of its own state. The price index is [`market::IndexLevel`].
//! - [`flow`]: the shock flow each preset was fitted at, and a tally a host
//! keeps of the news, shocks and revisions it adds.
//! - [`rng`] and [`mathx`]: the random streams and the transcendental
//! maths, both written here so that a seed gives the same bits on every
//! platform.
//! - [`widths`]: how many numbers each state row and record holds, for a
//! host that saves state into buffers. Re-exported at the root.
//!
//! The `python` feature builds the Python extension module and the `wasm`
//! feature builds the WebAssembly binding. Both drive
//! [`engine::Engine::close_day`], so a day in Python and a day in a browser
//! run the same code.
//!
//! A program that runs its own day loop, such as a game, should read
//! [Embedding the engine in a host](https://github.com/simoncoombes/tradefloor/blob/main/docs/EMBEDDING.md)
//! first: which constructor to open with, the day loop the presets were
//! certified on, and how much news and how many shocks of its own a preset
//! takes before its measured statistics stop describing the market.
//!
//! Many modules began as line-for-line ports of an earlier reference
//! implementation, and their comments still cite it. The crate has since
//! changed the model on purpose and is now its only definition.
//!
//! What it promises is determinism: the same seed, roster and preset give
//! the same market, bit for bit, on every supported platform and in every
//! patch release of an LTS line.
// `!(x > 0.0)` rather than `x <= 0.0` is a deliberate, load-bearing idiom
// throughout this crate: the negated form also rejects NaN, and it is how the
// reference-implementation guards are written. Clippy reads it as an
// accident of style.
// Rewriting to `partial_cmp` would obscure the one property the guards exist
// for, so the lint is silenced here with the reason rather than at each site.
/// Engines whose build played a market prehistory, kept per process.
/// The runtime parameter seam: `ModelParams` and the preset table.
/// Simulated constant-maturity bond indices priced off the engine's curve.
/// The twelve sectors and their model parameters.
/// Universe generation - plausible rosters, deterministically.
/// The single place a factor of 100 exists - see the module docs.
/// The widths a host sizes state buffers by, all re-exported below.
/// Python bindings. Feature-gated: the WASM consumer never compiles PyO3.
/// Order-book bindings, split out because `python` is already long.
/// Engine bindings - Layer 2.
/// ModelParams bindings - the runtime parameter seam's boundary.
/// Arrow record batches for the results surface.
/// The run log: every input, in order, sufficient to replay.
/// Vectorised engines for sweeps and vector envs.
pub use ;
/// The state widths, at the crate root so a host finds them first: see
/// [`widths`] for what each one sizes and why a change to one is breaking.
pub use ;