A real-time 3D stock-trading simulator written in C++ and OpenGL. TradeSim loads real historical AAPL price data, renders it as an interactive 3D candlestick chart you can pan and zoom, and lets you trade against it day by day through a Dear ImGui heads-up display with market orders, limit orders, and live portfolio profit and loss.
Provenance: originally developed in autumn 2025 for UVM CS2300 (a console version in October 2025, this OpenGL rebuild in November 2025). This public repository is a fresh, cleaned version of that project, re-published from a single clean commit with build output and local IDE config removed. The code is the original work. See the Lineage section below.
TradeSim is a self-contained desktop trading sandbox. It reads a CSV of historical daily open, high, low, and close prices, builds a 3D scene where every trading day is a candlestick (a colored body plus a wick), and steps forward one day at a time on command. As you advance through the data, you place market and limit orders, and the HUD updates cash, shares, and net worth in real time. It sits somewhere between a graphics demo and a minimal trading terminal, and it was built to practice real-time rendering, an event-driven UI, and object-oriented order modeling in modern C++.
- Real historical market data. Daily AAPL open, high, low, and close values are loaded from
data/AAPL.csv(roughly 1,250 trading days).DataLoaderparses the CSV, skips malformed rows, and buildsCandlestickobjects held by aStock. - 3D candlestick rendering. Each trading day is drawn as two extruded cubes, a body and a wick, laid out oldest to newest from left to right. Prices are normalized into view space so the whole series fits on screen. Up days render green and down days render red.
- Pan and zoom camera. Arrow keys pan the camera across the chart and the
/and.keys zoom in and out, with the zoom step scaled to the current distance for smooth control. - ImGui HUD. A docked heads-up display shows the ticker, current day index and total, date, close price, cash, shares held, and net worth, plus a live count of visible candles.
- Scrolling trade log. Every order and result is appended to an in-window log that keeps the most recent activity in view.
- Market and limit orders. Buy and sell at the current close through on-screen buttons or hotkeys. Limit orders are queued with a target price and a buy or sell side.
- Day-by-day stepping. Advancing to the next day reveals the next candle, moves the simulation clock forward, and re-evaluates any pending limit orders.
- Limit orders trigger on a next-day price cross. A queued buy fills when the new day's close falls to or below its limit price, and a sell fills when the close rises to or above its limit price.
- Polymorphic order model. An abstract
Orderbase class declares a pure virtualgetOrderDetails(), andMarketOrderandLimitOrderderive from it. The portfolio executes orders through the base class, so behavior is dispatched at runtime. - Portfolio profit and loss.
Portfoliotracks cash and per-ticker holdings, values net worth at the current close, validates trades against available cash and shares, and reports total and percentage change against the starting balance.
| Area | Technology |
|---|---|
| Language | C++17 |
| Graphics API | OpenGL 3.3 Core Profile |
| GL loader | GLAD |
| Windowing and input | GLFW 3.3.9 |
| Immediate-mode UI | Dear ImGui |
| Math | GLM 1.0.1 |
| Build system | CMake 3.20+ |
GLFW and GLM are fetched automatically at configure time through CMake FetchContent. GLAD and Dear ImGui are vendored under external/ so the project builds without extra setup. All four are third-party dependencies and are not authored here.
- CMake 3.20 or newer
- A C++17 compiler (the project was developed with the MinGW g++ toolchain bundled with CLion)
- A GPU and drivers that support OpenGL 3.3
- An internet connection for the first configure, so
FetchContentcan download GLFW and GLM
The top of CMakeLists.txt pins absolute paths to a specific CLion MinGW compiler. Edit or remove those two set(CMAKE_..._COMPILER ...) lines so they point at your own compiler, or delete them to let CMake detect the default toolchain.
cmake -S . -B build
cmake --build build --target TradeSimThen run the TradeSim binary produced in the build directory. Resource loading (shaders under res/ and data under data/) assumes the CLion build layout, so if the app cannot find its shaders you may need to launch it from the build directory or adjust the working directory.
Open the project folder, let CMake configure, choose the TradeSim run target, and build and run. This is the configuration the project was developed and tested in.
TradeSimis the full interactive simulator described above.TradeSim_testingruns an assertion-based test suite that exercises CSV parsing, buy and sell execution, limit-order triggering, and order polymorphism.M4OEP-hgricharis an early minimal graphics harness that opens a window and renders the scene, kept from the initial bring-up.
| Input | Action |
|---|---|
| B | Market buy at the current close |
| S | Market sell at the current close |
| L | Place a limit order using the quantity, price, and side in the HUD |
| N | Advance one day |
| Q | Quit |
| Arrow keys | Pan the camera |
/ and . |
Zoom in and out |
Quantity, limit price, and buy or sell side are set in the HUD, and every action is also available as an on-screen button.
TradeSim grew across several iterations before reaching this graphics version.
- M2 was the first console-based C++ TradeSim, written for CS2300 Module 2. It established the core idea of loading price data and simulating trades in a terminal.
- M3 refined the console version, improving the data handling and the order and portfolio logic.
- M4 (this repository) rebuilt the simulator around a real-time OpenGL and ImGui 3D graphics layer. The trading and portfolio classes from the earlier console versions were carried forward and wired into a rendering engine, a candlestick visualizer, and an interactive HUD.
The concept later evolved into Kabu, a separate iOS application: https://github.com/HoldenRichard/kabu
To be clear, Kabu is a different, standalone project that this work grew toward. This repository is the C++ and OpenGL desktop simulator, not Kabu.
open_ended/ Trading domain model: Stock, Candlestick, DataLoader,
Order (abstract), MarketOrder, LimitOrder, Portfolio,
the interactive main entry point, and the test suite
src/ Rendering engine, candlestick visualizer, shader
management, cube geometry, and utilities
res/shaders/ GLSL vertex and fragment shaders (OpenGL 3.3 core)
data/ Historical AAPL OHLC CSV
external/ Vendored third-party dependencies (Dear ImGui, GLAD)