This repository is a small C++ backtester for exploring a Simple Moving Average (SMA) crossover trading strategy as a probabilistic experiment. It is intended for research and learning — not for live trading.
The engine simulates trades on historical candlestick data and reports per-trade statistics such as expected value, variance, and win probability.
Notes about the current codebase
- The CMake target is
trading_bot(seeCMakeLists.txt). - By default
src/main.cpploadsdata/NVDA.csv(NVIDIA historical prices). You can replace the CSV indata/or editmain.cppto point to a different file (for exampledata/BTC-USD.csv). - Two Python downloader scripts are included to fetch sample CSVs:
NVDA_Downloader.py— downloadsdata/NVDA.csvusing yfinance.BTC_USD_Downloader.py— downloadsdata/BTC-USD.csvusing yfinance.
include/— public headers (backtester.hpp,strategy.hpp, etc.)src/— implementation (main.cpp,backtester.cpp,strategy.cpp)data/— sample CSVs (committed or generated by the downloaders)BTC_USD_Downloader.py,NVDA_Downloader.py— convenience scripts to fetch CSVs using Python
- A C++17-compatible compiler (Clang/GCC on macOS/Linux, MSVC on Windows)
- CMake (>= 3.15)
- Internet access for CMake's FetchContent (it downloads
cprandnlohmann_jsonduring configure) - Optional (for dataset downloading): Python 3 with
pandasandyfinanceif you want to use the included downloader scripts
Install the Python deps if you plan to use the scripts:
python3 -m pip install --user pandas yfinanceGenerate build files and build the executable using CMake:
cmake -S . -B build
cmake --build buildThe resulting executable is build/trading_bot (or build\\trading_bot.exe on Windows).
By default main.cpp is configured to load data/NVDA.csv. To run the backtester:
./build/trading_botIf you want to run the bot on Bitcoin data, either:
- Use the provided downloader to create
data/BTC-USD.csvand editsrc/main.cppto point todata/BTC-USD.csv, or - Replace
data/NVDA.csvwith your CSV namedNVDA.csv(same format), or - Modify
main.cppto accept a command-line path and recompile (recommended if you plan to run different datasets often).
CSV format expected by the loader
- Header line (ignored by the loader)
- Each subsequent line:
Timestamp,Open,High,Low,Close
Example downloader usage (creates CSVs under data/):
python3 NVDA_Downloader.py
python3 BTC_USD_Downloader.pyThe CMakeLists.txt uses FetchContent to download and make available:
cpr— a C++ HTTP client library (used if you add network code)nlohmann_json— JSON handling library
These are fetched automatically during the CMake configure step.
See the repository root for licensing information.