A web-based backtesting application written in C++ with Dear ImGui and ImPlot, compiled to WebAssembly via Emscripten. This tool allows you to load historical market data and custom trading strategy configurations, then run simulations to evaluate the performance of those strategies over time.
- Features
- Getting Started
- Using the Application
- Sample Files
- Trade Record Details
- Summary Window
- Project Structure
- Contributing
- License
- Strategy Backtesting: Simulate how a trading strategy would have performed on historical data.
- Web-Based GUI: Powered by Dear ImGui and ImPlot, compiled to WebAssembly for browser usage.
- Candlestick & Volume Charts: Visualize market data with candlestick charts and volume bars.
- Trade Tracking: Each executed trade is recorded and can be viewed in a table (trading journal).
- Performance Summary: Key performance metrics (e.g., total profit/loss, winning trades, etc.) are shown.
- Configurable Strategies: Use JSON files to define signals (entry, exit) and parameters such as stop loss and take profit rules.
- C++23 or later: Required by the C++ codebase.
- CMake: Used to configure and build the project.
- Emscripten SDK: To compile and run in a web environment. Follow the Emscripten Getting Started Guide to install and activate it.
-
Clone the repository:
git clone /janucaria/pludux.git cd pludux # Make sure you are on the correct branch (if needed): git checkout main
-
Configure with Emscripten:
emcmake cmake -B build
-
Build:
cmake --build build
-
Output:
- The build process will create the Wasm and HTML files in the
build
directory (or wherever your build directory is). - You can serve these files locally (e.g., using
emrun
) to run the web application in your browser.
- The build process will create the Wasm and HTML files in the
-
Local Host:
emrun --no_browser --port 8080 build/apps/backtest/gui/
Then open
http://localhost:8080
in your web browser. -
Alternatively, you can use any simple HTTP server (like Python’s
http.server
) pointed to the build output directory and load the HTML file in your browser.
Once the application is running in your browser, you will see a Dear ImGui-based interface. The primary menu items for backtesting are:
- File → Open Strategy (JSON)
- File → Open Data (CSV)
- Click File → Open Strategy (JSON).
- Select your strategy configuration file (e.g.,
macd.json
). - The application will parse the JSON to apply your strategy’s parameters:
- Entry signal logic
- Exit signal logic
- Stop loss threshold
- Take profit target
- Click File → Open Data (CSV).
- Select your historical data file (e.g.,
BTC-USD.csv
). - The application will parse each row, and then run the backtest with the previously loaded strategy.
- Candlestick & Volume: A chart displays price movements over time with corresponding volume bars.
- Trade Journal: Shows each executed trade (entry and exit) in a table.
- Summary Window: Provides metrics such as total profit, number of trades, average profit/loss, etc.
Example configuration and historical data files are available under the data/backtest/samples folder:
-
Strategies:
-
Historical Data:
Feel free to modify these files or create your own.
Each trade record contains crucial information about the simulation’s executed trades. Fields include:
- Entry/Exit Time
- Entry/Exit Price
- Stop Loss / Take Profit Levels
- Profit/Loss
These records are displayed in the application’s trading table, giving you a clear look at how your strategy performed on each trade.
The application also provides a Backtesting Summary where you can see high-level metrics of your strategy’s performance. Metrics may include:
- Total Net Profit
- Number of Trades
- Percentage of Winning Trades
- Average Win/Loss per Trade
- Other performance indicators
A simplified overview of the relevant directories:
pludux/
├── apps/
│ └── backtest/
│ ├── gui/
│ │ ├── src/
│ │ │ └── windows/ # ImGui window implementations
│ │ └── ... # Build logic & other source files
│ └── lib/
│ └── include/
│ └── pludux/backtest/ # Core backtest logic, trade_record.hpp, etc.
├── data/
│ └── backtest/
│ └── samples/ # Sample strategy JSON & CSV data
└── CMakeLists.txt
- apps/backtest/gui: Contains the ImGui-based GUI front end.
- apps/backtest/lib: Core backtesting logic and data structures.
- data/backtest/samples: Sample strategy files (JSON) and sample historical data (CSV).
Contributions are welcome! If you find bugs, have features to propose, or want to improve documentation:
- Fork the repository.
- Create a new feature branch (
git checkout -b feature/my-feature
). - Commit your changes.
- Push to your fork and submit a pull request.
Please ensure your contributions align with the project’s coding style and include appropriate tests or examples.
Distributed under the MIT License. See LICENSE.txt for more information.
Happy Backtesting!
If you have questions or suggestions, feel free to open an issue or reach out. Enjoy exploring and testing your trading strategies with Pludux!
Thank you ChatGPT for this README :')