Counterfactuals
Run the same agent from the same state, change one controlled input, and inspect where the two runs first diverge.
import tradefloor as tf
u = tf.Universe.random(24, seed=7)
world = tf.World(seed=7, universe=u, agent=Mine())
world.run(50)
control, stress = world.fork("control", "stress")
stress.apply(tf.Scenario.load("liquidity_crisis"))
started = tf.agree(control, stress)
control.run(80)
stress.run(80)
result = tf.compare(control, stress,
agreement=started)
print(result.render())
The three steps
The result is controlled attribution inside the simulated market. It says what this model does under the stated change, and a statement about a real market needs evidence from a real market.
The pieces
Three kinds of fork
Three mechanisms copy a running experiment, at three scopes.
Engine.fork
An in-process copy of the engine: every column, the order book, the day's endogenous news and the generator position. tf.branch calls it. The copy can be checkpointed, forked again and written to a manifest.
Checkpoint
A serialised save of a run that replays the order log. It outlives the process, carries a fingerprint, and RunManifest.of(..., derived_from=checkpoint) records the lineage. The mechanics are on checkpoints and forking, and the reference is the counterfactual API.
World.fork
An experiment-level fork: the engine plus the agent, the portfolio and the trace. The unit this page's comparison operates on.
External agents
The agent is a parameter throughout, so the same experiment runs with an external agent swapped in. tradefloor.integrations.finrobot runs a FinRobot agent behind an observation allowlist that keeps fair value, the attribution and the macro path ahead on the tradefloor side. Install with pip install "tradefloor[finrobot]"; the shipped studies are examples/rate-shock/ and examples/finrobot/.