Scenario API
Reference for Scenario, Intervention, Firing, the target registry and run_scenario. Signatures are the package's own, and usage and examples are on Scenarios.
Scenario
A macro path and a set of explicit interventions, applied a day at a time, imported from the top level as tradefloor.Scenario.
Scenario(
label: str = "",
*,
name: str | None = None,
description: str = "",
interventions: Sequence[Intervention] = (),
shocks: Sequence[Intervention] = (),
transmission: Sequence[Intervention] = (),
)
Intervention
One explicit change to one target at one time, immutable and validated at construction, imported from the top level as tradefloor.Intervention.
Intervention(
target: str,
*,
operation: str = "multiply", # "set" | "add" | "multiply"
value: Any = None,
at: int = 0, # days from scenario start
duration: int | None = None,
shape: str | None = None, # "impulse" | "permanent" | "hold" | "ramp"
role: str = "shock", # "shock" | "transmission"
)
The target registry
tradefloor.TARGETS maps the twelve target names to Target objects; tradefloor.UNSUPPORTED_TARGETS maps refused names to the mechanism to use instead. The names, what each reaches and what a move measures are tabulated on Scenarios.
run_scenario
tf.run_scenario(
scenario: Scenario,
*,
seed: int,
universe: Sequence[Instrument],
days: int,
macro: Macro | None = None,
ticks_per_day: int = 390,
start: tuple[int, int, int] = (9, 30, 3),
record: bool = False,
model: str | ModelParams | None = None,
) -> Engine
Runs a market under the scenario and returns the finished engine. The scenario is applied at the start of each day, so day zero is already under the path. days < 1 raises ValidationError. tf.evaluate, tf.rank, tf.tca.analyse and tf.run_many take the same scenario= keyword.
See also
Scenarios for usage, the shipped files and the CLI. Counterfactual API for World.apply. Evaluate for the evaluation entry points that accept a scenario.