Bentrix Docs
HomePricingDashboard

Episodes and seeds

The three kinds of episode, how a seed chooses where one starts, a curriculum of lengthening episodes, your own sampler, and the ledger hash that proves a run.

Three kinds of episode

env_make takes episode:

KindAn episode isUse it for
window (the default)episode_bars candles, from a start the seed drawstraining: many short, varied episodes
sessionone day, drawn by the seedintraday policies
tapethe whole recording, from its start to its enda final test over everything

episode_bars is 200 by default. An episode is that many steps of the interval's length on the clock: with the default H1, 200 hours — a little over eight days. Hours when the market is shut count too: such a step passes with no new candle, and the agent sees the same market.

01The warm-up

An episode never starts at the very first moment of the recording: the observation needs window closed candles before the first decision. Every episode starts at least window + 1 candles after the recording's first moment. A tape episode starts exactly there.

02Where an episode starts

env_reset rewinds the workbench to its first moment, undoes its deals, and plays it forward — as Play would, tick by tick — to the episode's start. Where that is depends on the seed:

  • A window episode starts on a candle boundary drawn uniformly from every start that leaves room for episode_bars candles before the recording ends.
  • A session episode starts on a day boundary drawn from the recording's days.

The draw is a pure function of two numbers — the seed and the episode's index — so it is the same on every computer and in every language.

You callThe episode
env_reset with seed: 7the first episode of seed 7 (index 0)
env_reset with no seed, nextthe second episode of seed 7 (index 1) — a different window
env_reset with seed: 7 againindex 0 again — the very same window as the first

So training usually passes a seed once and then calls env_reset without one, while evaluation passes each test seed explicitly.

03A curriculum — growing

Long episodes are hard to learn from at first. growing makes window episodes lengthen as training goes on:

"growing": {"first": 24, "last": 240, "over": 100}

Episode i lasts first + (last − first) × min(i / over, 1) candles: 24 candles at the start, growing evenly to 240 by the hundredth episode, then 240.

04Your own sampler

To choose the starts yourself — only the high-volatility weeks, say, or a fixed list for a test — pass start_ms and bars to env_reset:

{"env": "env-1", "start_ms": 1717200000000, "bars": 120}

The episode starts at that moment (brought down to a candle boundary) and lasts bars candles. In Python, TradingEnv(sampler=…) takes a function that does this for every episode.

05Train and test on different windows

A policy that learned one stretch of history by heart is worth nothing on the next. Keep the seeds you train on apart from the seeds you test on — training on seeds 1 to 3 and testing on 101 to 103, for example — and, better still, test on a later part of the recording than you trained on, using your own start_ms. Evaluating honestly goes further.

06The ledger hash

Every env_reset and env_step on a laboratory workbench answers info.ledger_hash: a fingerprint of every deal the workbench holds. The venue is deterministic, so:

i

the same seed and the same actions give the same ledger hash — on any run, in any language.

Record it with a result. Anyone can replay the seed and the actions and check that they get the same deals; a different hash means a different run, however close the numbers look.

07Ruin

ruin is the share of the episode's opening equity at which an episode ends with terminated: 0.5 by default, so losing half of the opening equity ends it. Set it lower to let an agent experience deeper losses, higher to stop it early.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed