Every reward the environment computes, with its formula, what it teaches an agent, and which to start with.
Choosing a reward
env_make takes reward, a name with a version: dsr_dd_penalty@1 by default. The version is part of the name, so a result recorded with pnl@1 always means the same formula.
Every reward is computed at the close of each step from two figures:
- E₀ — the account's equity just before the step's action,
- E₁ — the equity at the close the clock reached.
Equity is the balance plus the open position's profit, after the spread, the commission and the swap the venue charged. Most rewards use the step's return:
r = (E₁ − E₀) / E₀
A reward's running state — averages, the peak, the list of returns — starts afresh at each env_reset.
01At a glance
| Reward | In one line | Start with it when |
|---|---|---|
pnl@1 | money made this step | you want to read rewards in money |
log_return@1 | the log of the equity's growth | you want rewards that add up across a whole episode |
dsr@1 | the change in a running Sharpe ratio | you want return per unit of risk |
dsr_dd_penalty@1 | the same, minus growth of the drawdown | the default — risk-aware and drawdown-aware |
cvar_lagrangian@1 | the return, minus the worst tail's loss | you care most about the bad steps |
cost_aware_vol_scaled@1 | the return divided by recent volatility | markets of very different volatility |
rule_adherence@1 | −1 for each refused order | a product hypothesis: learning to act within the rules |
risk_budget@1 | a penalty for using more margin than the equity | a product hypothesis: learning to stay inside a budget |
02Profit and loss — pnl@1
reward = E₁ − E₀
The money the step made or lost, in the account currency. Easy to read; its size depends on the account and on lots, so a learning rate tuned for one account may not suit another.
03Log return — log_return@1
reward = ln(E₁ / E₀) (−1 if either equity is zero or below)
The episode's rewards add up to ln(final equity / opening equity) — the log of the whole episode's growth. A step that halves the account costs as much as two steps that double it bring.
04Differential Sharpe ratio — dsr@1
A Sharpe ratio is return per unit of volatility. The differential Sharpe ratio (Moody and Saffell) is how much one step's return changes a running estimate of it, so it can be given at every step. With exponential averages of the return, A, and of its square, B, kept with η = 0.01:
ΔA = r − A ΔB = r² − B reward = (B·ΔA − ½·A·ΔB) / (B − A²)^1.5 then A ← A + η·ΔA, B ← B + η·ΔB
It is 0 until the average has some variance. A return that is large compared with the recent volatility is rewarded; the same return in a volatile stretch is worth less.
05Differential Sharpe with a drawdown penalty — dsr_dd_penalty@1 (the default)
The differential Sharpe ratio, minus half of any growth of the drawdown:
drawdown = (peak equity − E₁) / peak equity reward = dsr − 0.5 × max(0, drawdown now − drawdown before)
Falling further below the episode's best equity costs; recovering does not earn back the penalty, it only stops it. This is why it is the default: it rewards consistency and punishes the deep losses an agent would otherwise learn to accept.
06Return with a tail-risk penalty — cvar_lagrangian@1
CVaR = −(the mean of the worst 5 % of this episode's step returns so far, at least one) reward = r − 0.5 × max(0, CVaR)
CVaR (conditional value at risk) is the average of the worst returns. The agent is paid its return and charged for how bad its worst steps have been, so a strategy with rare large losses scores worse than one with the same average and no such tail.
07Volatility-scaled return — cost_aware_vol_scaled@1
σ = the standard deviation of the last 50 step returns reward = r / σ (0 while σ is zero)
The return measured in units of recent volatility, so a quiet market and a wild one give rewards of similar size. Costs are already in r — the spread and commission are taken from the equity — which is why the name says cost-aware.
08Rule adherence — rule_adherence@1
reward = −1 if the step's order was refused, otherwise 0
It rewards nothing about the market: only staying within what the venue accepts. Use it beside another objective in your own code, or to study refusals. It is marked a product hypothesis — info.product_hypothesis is true — because whether it helps learning is not established.
09Risk budget — risk_budget@1
exposure = margin in use / E₁ reward = −max(0, exposure − 1)
Zero while the margin in use stays within the equity; below zero beyond it. Also a product hypothesis.
10Combining rewards
An environment computes one reward. To combine several — a return with a refusal penalty, say — compute your own in your program from what every step answers: info.equity and info.refused, and the observation's account part, are everything the eight are made from. Two environments on one workbench are not the way: each would trade on its own.
11Participation impact
With a participation cap (see actions), impact × units ÷ the candle's volume is subtracted from the reward — never from the account. It lets an agent learn that large orders cost more, without inventing a fill price the venue did not give.