Bentrix Docs
HomePricingDashboard

What an observation holds

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:

PartShapeWhat it holds
marketwindow × 4the last window closed candles: open, high, low, close
account3the 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:

i

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):

CandleOpenHighLowClose→OpenHighLowClose
11.08001.08151.07951.0810−0.00185−0.00046−0.00231−0.00092
21.08101.08301.08051.0825−0.000920.00092−0.001390.00046
31.08251.08281.08151.08200.000460.00074−0.000460

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

IndexValueExample
account[0]the side held: 1 long, −1 short, 0 flat1
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.

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