RL API¶
The lumina_lob.rl package provides a Gymnasium environment and training helpers for reinforcement-learning market makers.
lumina_lob.rl.env
¶
Gymnasium environment for training an RL market maker.
Classes¶
MarketMakerEnv
¶
Bases: Env[ndarray, ndarray]
A Gymnasium environment where an agent acts as a single market maker.
The observation combines the current limit-order-book state, the agent's inventory, and its mark-to-market P&L. The action is a continuous vector that controls bid/ask quote offsets and sizes.
Parameters¶
max_steps: Maximum number of steps per episode. warmup_steps: Number of steps to run before the agent starts observing, so the book has initial liquidity. tick_size: Price tick size used for rounding and normalisation. max_quote_offset_ticks: Maximum number of ticks away from the mid price the agent may quote. min_quote_size: Minimum quantity per quote. max_quote_size: Maximum quantity per quote. inventory_penalty: Coefficient for the quadratic inventory penalty applied each step. seed: Optional global RNG seed.
Source code in lumina_lob/rl/env.py
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
Methods:¶
step(action)
¶
Advance the market by one step and return the new observation.
Source code in lumina_lob/rl/env.py
lumina_lob.rl.train
¶
Training and evaluation helpers for RL market makers.
Classes¶
Functions:¶
evaluate_agent(model, env, n_eval_episodes=5)
¶
Evaluate a trained model and return mean and std episode reward.
Source code in lumina_lob/rl/train.py
make_env(seed=0)
¶
Return a no-argument factory that creates a fresh MarketMakerEnv.
The environment is wrapped with SB3's Monitor so training/evaluation
logs episode statistics without warnings.
Source code in lumina_lob/rl/train.py
save_model(model, path)
¶
train_ppo(env, total_timesteps=10000, verbose=0, **kwargs)
¶
Train a PPO agent on MarketMakerEnv.
Parameters¶
env:
A Gymnasium environment (typically MarketMakerEnv).
total_timesteps:
Number of timesteps to train for.
verbose:
SB3 verbosity level.
kwargs:
Extra keyword arguments forwarded to PPO.
Returns¶
A trained PPO model.
Source code in lumina_lob/rl/train.py
train_sac(env, total_timesteps=10000, verbose=0, **kwargs)
¶
Train an SAC agent on MarketMakerEnv.
Parameters¶
env:
A Gymnasium environment (typically MarketMakerEnv).
total_timesteps:
Number of timesteps to train for.
verbose:
SB3 verbosity level.
kwargs:
Extra keyword arguments forwarded to SAC.
Returns¶
A trained SAC model.
Source code in lumina_lob/rl/train.py
lumina_lob.rl.compare
¶
Compare PPO and SAC market-maker agents on MarketMakerEnv.
Functions:¶
compare_ppo_sac(env_factory, total_timesteps=10000, n_eval_episodes=5)
¶
Train PPO and SAC agents and return their evaluation statistics.
Parameters¶
env_factory: Callable that returns a fresh Gymnasium environment. total_timesteps: Number of timesteps to train each agent for. n_eval_episodes: Number of evaluation episodes per agent.
Returns¶
A dictionary with ppo and sac keys, each mapping to
{"mean": float, "std": float} reward statistics.
Source code in lumina_lob/rl/compare.py
lumina_lob.rl.evaluate
¶
Evaluate heuristic and trained RL market-making policies.
Classes¶
EpisodeResult
dataclass
¶
SimpleMarketMakerPolicy
¶
Deterministic heuristic that skews quotes based on inventory.
Long inventory widens the bid offset and tightens the ask offset to encourage selling; short inventory does the opposite. Quote sizes are always at the configured minimum.
Source code in lumina_lob/rl/evaluate.py
Methods:¶
__call__(env)
¶
Return an action vector for the current env state.
Source code in lumina_lob/rl/evaluate.py
Functions:¶
evaluate_heuristic_policy(env_factory, policy, n_episodes=5)
¶
Run a heuristic policy for several episodes and return summaries.
Source code in lumina_lob/rl/evaluate.py
summarize_results(results)
¶
Return mean and std of key metrics across episodes.