Expand description
§OpenOutcry — the trading-agent environment
A leak-free, point-in-time market environment with a dead-simple, language-agnostic
agent contract: the harness sends an MarketObservation, the agent returns a
Decision, repeat. Look-ahead is structurally impossible — Dataset never hands
out a future bar — and trajectories are recompute-from-raw-decisions, so an agent cannot
lie about its returns.
§M0 — extraction scaffold
This crate currently re-exports the point-in-time simulator that already lives in
sharpebench-sim, promoting it from “the benchmark’s internal engine” to a standalone
environment whose public reason to exist is “run an agent in a market.” The Gym-style
reset/step lifecycle, the frozen CONTRACT_VERSION, the WASM/npm + Python
surfaces, and the ecosystem wiring land in later milestones (see
specs/SPEC-trading-agent-env.md). v0.1 depends on sharpebench-sim; the gl-sim-core
extraction is a follow-up refactor, not a blocker.
Re-exports§
pub use contract::CONTRACT_VERSION;pub use scenario_gen::generate_scenario;pub use scenario_gen::level_seed;pub use scenario_gen::train_test_split;pub use scenario_gen::DistributionMode;pub use scenario_gen::ScenarioSpec;pub use vec_env::BatchStep;pub use vec_env::LaneConfig;pub use vec_env::VecTradingEnv;pub use mandate::mandate_breach;pub use mandate::sample_mandate;pub use mandate::Mandate;pub use mandate::MandateStyle;pub use exec_noise::perturb as perturb_action;pub use exec_noise::ExecNoise;pub use lob_market::Fill;pub use lob_market::LadderSnapshot;pub use lob_market::OrderBook;pub use lob_market::OrderKind;pub use lob_market::RestingOrder;pub use lob_market::Side;pub use market::clear_bar;pub use market::AgentFill;pub use market::ClearResult;pub use market::MarketClearing;pub use market::MarketParams;
Modules§
- contract
- The frozen wire contract version.
- exec_
noise - Execution-noise perturbation — the determinism-sensitive core of the trading
analog of ALE sticky actions, moved down from the Python
ExecutionNoiseWrapper. - lob_
market - Deterministic continuous-double-auction limit-order book (M3) — price-time priority.
- mandate
- Per-scenario trading mandates — MiniGrid’s
Missionpattern for trading. - market
- Endogenous price-impact shared-book market (M2) — the flagship multi-agent engine.
- scenario_
gen - Seeded procedural scenario generation — Procgen’s
(start_level, num_levels)integer-seed-interval model, ported to the trading environment. - vec_env
- Vectorized, batched environment — gym3’s “vectorized-first” design ported to the
trading env. A
VecTradingEnvholdsBindependentTradingEnvlanes (each a distinct seed/scenario/window) and steps them as a batch.
Structs§
- Agent
Trajectory - An agent’s full captured trajectory: every (window × seed) run’s raw decisions. Serde-(de)serializable to JSON; this is the on-disk artifact a separate verifier ingests to recompute the score from raw decisions alone.
- BuyAnd
Hold - Equal-weight buy-and-hold across all symbols — the baseline every agent must beat.
- Cost
Model - Basis-point transaction cost model.
- Dataset
- A point-in-time price dataset.
- Decision
- What the agent returns.
- Decision
Step - One captured decision step of a single backtest run: the agent’s raw output
at one point-in-time observation. This is the persisted artifact — it holds the
agent’s
Decision(orders, sizing, conviction, reasoning) tagged with the observation it was made against, and deliberately stores no returns, NAV, or any self-reported metric. The score is recomputed by replaying these decisions through the engine, never read from the agent’s word. - EnvState
- An O(1), serializable snapshot of a
TradingEnv’s mutable state — the time cursor plus the full [Book] (holdings, cash, RNG cursor, decision trace, prior NAV). Everything an env needs to resume an exact trajectory; the immutable config (frozen data, window, costs, seed) lives in the env and is not copied. - External
Agent - Drives an external agent subprocess over newline-delimited JSON.
- Hold
Agent - The do-nothing agent: always holds (empty orders). A trivial baseline, and the graceful fallback when an external agent process can’t be spawned mid-run — consistent with how the external transports already degrade to a hold on error.
- Http
Agent - Drives an external agent over HTTP/1.1 — one request/response per decision.
- Market
Observation - What the agent sees at one decision point.
- Momentum
- Cross-sectional momentum: equal-weight the symbols with positive trailing return.
- Order
- A single per-instrument instruction.
- Position
State - The agent’s current holding in one instrument.
- Random
Agent - A coin-flip “monkey”: a fully-invested, long-only portfolio with random weights each step. Seeded so it is reproducible. Run many of these to draw the luck floor — the distribution of outcomes from zero skill that a genuine agent must clear to be rank-eligible.
- Run
- One seed×window run of an agent: its per-period returns plus the decision trace and (optionally) per-decision confidences/outcomes.
- RunTrajectory
- One captured backtest run (a single window × seed): the ordered sequence of the agent’s raw decision steps, plus the (window, seed) coordinates needed to replay it through the identical point-in-time engine path.
- Scenario
- A named bundle of a dataset, the windows to evaluate over it, and the cost model — so “run my agent through the crisis suite under worst-case execution” is one object rather than three loose arguments.
- Step
Info - Per-step side channel: the post-step NAV and the process events generated during the step (fills, sim-exploitation guards, captured rationale).
- Step
Result - The result of one environment step: the next point-in-time observation, this step’s portfolio return (the reward), whether the window is exhausted, and the per-step side channel.
- Symbol
Snapshot - Point-in-time data for one instrument.
- Team
Agent - A trading team: several member agents whose target weights are averaged into
one consensus decision (a symbol only one member likes is down-weighted by the
whole team’s size). Modelled on the TradingAgents multi-agent firm — the team
is scored as a unit while [
sharpebench_core::attribute_roles] estimates each member’s load on the team outcome. - Trading
Env - A steppable, leak-free trading environment over a frozen dataset. The caller
drives it:
resetreturns the first observation, then eachstepapplies the supplied decision and advances one bar. - Window
- A simulation window over the dataset’s date axis: steps
[start, end).
Enums§
- Action
- Discrete action label (sizing is carried by
target_weight). - Cost
Profile - Execution-robustness profile: a named bundle of a
CostModelplus a logical decision-to-fill delay (how many sim-bars an order waits before it becomes eligible to fill). Lets “score this agent under worst-case execution” be a single swappable axis rather than hand-tuned cost fields scattered per test. - Regime
- Coarse market regime over a window.
Traits§
- Agent
- Something that turns a point-in-time observation into trading orders.
Functions§
- replay_
run - Replay one captured run’s raw decisions through the identical point-in-time
engine to regenerate its
Run. The frozendataandcostsmust match those the trajectory was captured against; the window and seed come from the artifact. - replay_
submission - Replay a whole
AgentTrajectoryback into thesharpebench_core::AgentSubmissionthe scoring kernel consumes — recomputing everyRunfrom raw decisions alone. This is the engine half of the separate-verifier path: the resulting submission is derived only from the persisted decisions + the frozen dataset, never from any metric the agent reported. - run_
backtest - Run a single backtest of
agentoverwindowwith seeded execution noise, returning ansharpebench_core::Run(per-period returns + decision trace). The closed-loop driver: it owns thedecide → steploop, calling the same [step_once] body the open-loopcrate::env::TradingEnvuses. - run_
backtest_ capture - Run a backtest while capturing the agent’s raw decisions. Returns the same
Runrun_backtestwould produce, plus theRunTrajectoryartifact (the per-step decisions + the window/seed coordinates needed to replay it). - tag_
regime - Tag a window’s regime by the equal-weight average total return across symbols (>+3% = bull, < -3% = bear, else chop).
- walk_
forward - Generate disjoint-start walk-forward test windows of
testlength, stepping bystep, after awarmupburn-in (so features have history). Each window is an out-of-sample slice[start, start + test).