Vectorized Environment

VecEnv runs many independent simulation episodes in parallel for reinforcement learning. Supports GBM, Heston, and Bates market processes.

Configuration

VecEnvConfig specifies the full environment. The process field selects the market process via the VecEnvProcess enum:

#![allow(unused)]
fn main() {
pub enum VecEnvProcess {
    GBM {
        mu: f64,
        sigma: f64,
        initial_price: f64,
    },
    Heston {
        mu: f64,
        kappa: f64,
        theta: f64,
        sigma_v: f64,
        rho: f64,
        initial_price: f64,
        initial_variance: f64,
    },
    Bates {
        mu: f64,
        kappa: f64,
        theta: f64,
        sigma_v: f64,
        rho: f64,
        lambda_jump: f64,
        mu_jump: f64,
        sigma_jump: f64,
        initial_price: f64,
        initial_variance: f64,
    },
}
}

Other configuration fields:

FieldDescription
processMarket process type and parameters (see above)
spread, dt, max_stepsSimulation mechanics
impact_factorPrice impact per unit filled
k, aPoisson matcher parameters
hawkes_alpha, hawkes_betaHawkes intensity parameters
initial_cash, transaction_costAgent capital
reward_typePnL or DiffSharpe
inventory_penaltyPenalty for holding non-zero position
matcher_dtSub-step resolution for the stochastic matcher

State space

Depends on the process type:

  • GBM (5D): [mid, inventory, hawkes_buy, hawkes_sell, time]
  • Heston (6D): [mid, inventory, variance, hawkes_buy, hawkes_sell, time]
  • Bates (6D): [mid, inventory, variance, hawkes_buy, hawkes_sell, time]

Usage

Rust

#![allow(unused)]
fn main() {
use engine::vec_env::{VecEnv, VecEnvConfig, VecEnvProcess, RewardType};

let config = VecEnvConfig {
    process: VecEnvProcess::Heston {
        mu: 0.0,
        kappa: 2.0,
        theta: 0.04,
        sigma_v: 0.3,
        rho: -0.7,
        initial_price: 100.0,
        initial_variance: 0.04,
    },
    reward_type: RewardType::DiffSharpe,
    max_steps: 1000,
    ..Default::default()
};

let mut env = VecEnv::new(config, 64); // 64 parallel environments

// Reset to start new episodes.
let states = env.reset();

// Step with actions: (64, 2) flattened row-major [bid_dist, ask_dist, ...]
let actions = vec![0.01f32; 128];
let (next_states, rewards, dones) = env.step(&actions);

// State dimension
assert_eq!(env.state_dim(), 6); // Heston: 6D
}

Python

from market_solve import MarketVecEnv

# Heston (default)
env = MarketVecEnv(num_envs=64, max_steps=10000)

# GBM
env_gbm = MarketVecEnv(
    num_envs=64,
    process_type="gbm",
    mu=0.05,
    sigma=0.2,
)

# Bates
env_bates = MarketVecEnv(
    num_envs=64,
    process_type="bates",
    lambda_jump=0.1,
    mu_jump=-0.02,
)

states = env.reset()                # (64, state_dim) float32
states, rewards, dones = env.step(actions)  # actions: (64, 2)