Skip to main content

Overview

NanoARB provides a complete RL environment for training market-making agents using:
  • Gym-style environment for market making
  • State representations from order book data
  • Action spaces for quote placement
  • Reward functions for profit optimization
  • Support for IQL and Decision Transformer algorithms

MarketMakingEnv

The RL environment simulates market-making dynamics:
Location: nano-strategy/src/rl_env.rs:160-186

Creating an Environment

Location: nano-strategy/src/rl_env.rs:188-207

Environment Configuration

Location: nano-strategy/src/rl_env.rs:115-140

Default Configuration

Location: nano-strategy/src/rl_env.rs:142-158

Action Space

Actions control quote placement:
Location: nano-strategy/src/rl_env.rs:8-21

Creating Actions

Location: nano-strategy/src/rl_env.rs:36-58

Action Validation

Location: nano-strategy/src/rl_env.rs:60-72

State Space

The state representation includes:
Location: nano-strategy/src/rl_env.rs:75-92

State Features

  1. LOB features - Flattened order book snapshot (prices, quantities, depths)
  2. Inventory - Current position normalized by max_inventory
  3. Unrealized P&L - Mark-to-market P&L
  4. Time since trade - Normalized time since last fill
  5. Spread - Current bid-ask spread
  6. Imbalance - Order book imbalance
  7. Recent returns - Last N price returns

Converting State to Array

Location: nano-strategy/src/rl_env.rs:95-106

Reward Function

The reward balances multiple objectives:
Location: nano-strategy/src/rl_env.rs:388-422

Reward Components

  1. Spread Capture - Positive reward for fills that capture spread
  2. Inventory Penalty - Quadratic penalty for large positions
  3. Adverse Selection - Penalty when market moves against position
  4. Fee Costs - Maker/taker fees reduce reward

Tuning Reward Coefficients

Training Loop

Standard RL training loop:

Environment API

reset

Location: nano-strategy/src/rl_env.rs:209-223

step

Location: nano-strategy/src/rl_env.rs:225-264

Fill Simulation

The environment simulates realistic fills:
Location: nano-strategy/src/rl_env.rs:266-325

IQL Training

Implicit Q-Learning for offline RL:

Decision Transformer

Sequence modeling approach to RL:

Deployment

Deploy trained RL agent:

Best Practices

  1. Start with imitation learning - Pre-train on data from profitable strategies
  2. Tune reward coefficients - Balance spread capture vs inventory risk:
  3. Use sufficient context - Include enough history for informed decisions:
  4. Normalize state features - Ensure all features are on similar scales
  5. Monitor out-of-distribution - Track when live conditions differ from training
  6. Use offline RL for safety - Train on historical data before live deployment

Next Steps

Strategy Trait

Understand the core Strategy trait

Market Making

Combine RL with traditional market making