StockBuyerX

An academic reinforcement-learning experiment with a custom trading simulator.

Concept illustration of a learning policy interacting with a historical-data trading simulator
Concept illustration of a learning policy, simulation state, and reward feedback.

Study the behavior of a learned policy

StockBuyerX was a team project exploring reinforcement learning on historical equity data. We built a custom Gym environment, trained PPO policies, and examined the simulated decisions through profit, drawdown, Sharpe-ratio, and allocation plots.

Our academic simulation used daily data from 2018 through 2022 for AAPL, MSFT, GOOGL, AMZN, and SPLG.


Define what an action means

The environment combines a five-day price-and-volume window with portfolio state such as cash, shares held, cost basis, and net worth. Actions represent buying, selling, or holding, with an amount parameter controlling the scale.

A simulated execution price updates the portfolio, after which the environment calculates the reward and records diagnostics. We trained a separate policy for each asset rather than optimizing a joint portfolio across all five.


Look beyond the final balance

A profit curve alone does not explain the policy’s behavior. We also examined drawdown and a holding-ratio diagnostic to see whether a policy tended to remain invested or keep cash. Training, validation, and test splits gave us separate views of that behavior.

The pipeline used Stable-Baselines3, PyTorch, yfinance, NumPy, and Matplotlib, with a vectorized environment wrapper for training and evaluation. We also used standard control tasks to check parts of the reinforcement-learning setup before applying it to the market data.


Evaluation assumptions

The environment omitted transaction costs and slippage. Execution within a daily price bar was idealized, and the policies operated independently by asset. Data preparation and reward design also affect what a policy can appear to learn.

These limitations keep the results in context. A profitable replay in this simulator would not establish a profitable real-world strategy, and a risk metric is only as meaningful as its calculation and assumptions.


What I learned

The project made the environment and evaluation feel as important as the learning algorithm. Changing a reward or an execution rule can change behavior without changing PPO itself.

If extending the work, I would first improve realism and evaluation: explicit costs, a joint multi-asset action model, chronological walk-forward tests, and closer inspection of preprocessing for information leakage. The lesson was to scrutinize the experiment before interpreting the policy.