StockTradingEnvironment<T>

Models & Types · AiDotNet.Finance.Trading.Environments

Simple single-asset trading environment with buy/hold/sell actions.

Inheritance: TradingEnvironment<T> → StockTradingEnvironment<T>

For Beginners

This environment is the “hello world” of trading RL: the agent decides whether to buy one unit, sell one unit, or do nothing.

How It Works

StockTradingEnvironment models a single asset with discrete actions: hold, buy, or sell. It uses the base TradingEnvironment for portfolio bookkeeping and reward calculation.

Example

var NumOps = MathHelper.GetNumericOperations<double>();
// Create a single-asset stock trading environment with buy/hold/sell actions
var marketData = new Tensor<double>(new[] { 1000, 1 }); // 1000 timesteps, 1 asset
var env = new StockTradingEnvironment<double>(
    marketData, windowSize: 20, initialCapital: NumOps.FromDouble(10000.0),
    tradeSize: NumOps.FromDouble(1.0), transactionCost: 0.001);

Constructors

Constructor Summary
StockTradingEnvironment(Tensor<T> marketData, int windowSize, T initialCapital, T tradeSize, double transactionCost, bool allowShortSelling, bool randomStart, int maxEpisodeLength, int? seed) Creates a stock trading environment for a single asset.

Properties

Property Summary
bool IsContinuousActionSpace { get; }
int ActionSpaceSize { get; }