TradingEnvironment<T>

Base Classes · AiDotNet.Finance.Trading.Environments

Base environment for financial trading simulations.

Implements: IMaskedActionEnvironment<T>

Known derived types: MarketMakingEnvironment<T>, PortfolioManagerEnvironment<T>, PortfolioTradingEnvironment<T>, StockTradingEnvironment<T>

For Beginners

This is the “market simulator” shared by all trading environments. It feeds price data to agents, executes trades, and computes rewards based on portfolio changes.

How It Works

TradingEnvironment implements common portfolio bookkeeping for RL trading: positions, cash balance, portfolio value, and windowed market observations. Derived environments specialize how actions are interpreted.

Example

var NumOps = MathHelper.GetNumericOperations<double>();
// TradingEnvironment is abstract; use StockTradingEnvironment or MarketMakingEnvironment
// Example with StockTradingEnvironment for single-asset discrete trading:
var marketData = new Tensor<double>(new[] { 1000, 1 });
var env = new StockTradingEnvironment<double>(
    marketData, windowSize: 20, initialCapital: NumOps.FromDouble(10000.0),
    tradeSize: NumOps.FromDouble(1.0));

Properties

Property Summary
bool IsContinuousActionSpace { get; }
bool[] LegalActionMask { get; } Applies the trading action to update positions and cash.
int ActionSpaceSize { get; }
int ObservationSpaceDimension { get; }

Methods

Method Summary
ValueTuple<Vector<T>, T, bool, Dictionary<string, object>> Step(Vector<T> action)
Vector<T> Reset()
void Close()
void Seed(int seed)