gym.core
gym.core
Gymnasium environments for financial reinforcement learning.
Classes
| Name | Description |
|---|---|
| AccountState | Immutable account snapshot after an environment transition. |
| FinancialEnv | Single-asset financial environment with target-position actions. |
AccountState
gym.core.AccountState(
equity,
peak_equity,
drawdown,
position,
cumulative_cost,
steps,
)Immutable account snapshot after an environment transition.
FinancialEnv
gym.core.FinancialEnv(
returns,
features=None,
*,
window_size=20,
transaction_cost=0.0,
max_drawdown=None,
episode_length=None,
random_start=False,
render_mode=None,
)Single-asset financial environment with target-position actions.
Each action is a target exposure from -1 (fully short) through 0 (flat) to 1 (fully long). The environment charges proportional costs on absolute position turnover, then applies the next simple return. Market observations contain only periods preceding the return being traded.
The first argument may also be an RLlib env_config mapping containing returns and any constructor keyword arguments.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| returns | pd.Series | np.ndarray | list[float] | Mapping[str, Any] | Simple asset returns or an RLlib environment configuration. | required |
| features | pd.DataFrame | pd.Series | np.ndarray | None | Market features aligned one-to-one with returns. The return itself is used as the sole feature when omitted. |
None |
| window_size | int | Number of historical feature rows in each observation. | 20 |
| transaction_cost | float | Proportional cost per unit of position turnover. | 0.0 |
| max_drawdown | float | None | Positive drawdown magnitude that terminates an episode. Set to None to disable the constraint. |
None |
| episode_length | int | None | Number of transitions per episode. By default, an episode consumes all available returns after the initial window. | None |
| random_start | bool | Whether resets sample a valid episode start. This requires episode_length so every sampled episode is equal. |
False |
| render_mode | str | None | "ansi" for a text account summary, otherwise None. |
None |
Attributes
| Name | Description |
|---|---|
| account | Current immutable account snapshot. |
| feature_names | Feature column names in market-observation order. |
Methods
| Name | Description |
|---|---|
| render | Return a compact account summary in ANSI mode. |
| reset | Reset account state and select the next episode range. |
| step | Execute a target position and apply the next market return. |
render
gym.core.FinancialEnv.render()Return a compact account summary in ANSI mode.
reset
gym.core.FinancialEnv.reset(seed=None, options=None)Reset account state and select the next episode range.
step
gym.core.FinancialEnv.step(action)Execute a target position and apply the next market return.