The two parts of every observation — the last candles as log ratios to the last close, and the account — with a worked example and why they are scaled this way.
Two parts
Every observation is an object with two arrays:
| Part | Shape | What it holds |
|---|---|---|
market | window × 4 | the last window closed candles: open, high, low, close |
account | 3 | the side held, the equity against the episode's start, the open profit |
window is set in env_make — 32 candles by default. The values are 32-bit floats.
01The market part
Each candle's four prices are written as the natural log of the price divided by the last close:
value = ln(price / last close)
So the last candle's close is always 0, a price above it is positive, a price below it negative, and 0.001 means about one tenth of a percent above the last close.
An example with a window of 3 (the last row is the newest candle):
| Candle | Open | High | Low | Close | → | Open | High | Low | Close |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1.0800 | 1.0815 | 1.0795 | 1.0810 | −0.00185 | −0.00046 | −0.00231 | −0.00092 | |
| 2 | 1.0810 | 1.0830 | 1.0805 | 1.0825 | −0.00092 | 0.00092 | −0.00139 | 0.00046 | |
| 3 | 1.0825 | 1.0828 | 1.0815 | 1.0820 | 0.00046 | 0.00074 | −0.00046 | 0 |
market[0][3] — the first candle's close — is ln(1.0810 / 1.0820) ≈ −0.00092: the price is about 0.09 % higher now than at the oldest candle's close.
Why log ratios: they are the same size on every market and every price level. A model trained on a market at 1.08 reads a market at 2,300 the same way, a rise and a fall of the same size have the same magnitude, and a few candles' change is simply the difference of two values.
02Only closed candles
The market part holds only candles that have closed at the clock. The candle still forming is never in it, so nothing in an observation comes from after the moment the agent chooses. When a workbench holds fewer closed candles than window (right at the start of a recording), the missing rows at the top are zeros.
03The account part
| Index | Value | Example |
|---|---|---|
account[0] | the side held: 1 long, −1 short, 0 flat | 1 |
account[1] | ln(equity / the episode's opening equity) | 0.002 — the account is 0.2 % up this episode |
account[2] | the open position's profit ÷ the opening equity | −0.0004 — the position is 0.04 % of the opening equity in loss |
The account part lets a policy know what it already holds — useful because an action that keeps the side changes nothing (see actions).
04In a library
env_make answers the spaces so a library can size its network:
"observation_space": {
"market": {"shape": [32, 4], "dtype": "float32"},
"account": {"shape": [3], "dtype": "float32"}
}
In Python, bentrix.gym.TradingEnv gives the same as a Gymnasium Dict space, and gymnasium.wrappers.FlattenObservation turns it into one vector of window × 4 + 3 numbers for an MLP policy.