A modular backtesting engine for financial trading strategies, written in Java. This is still work in progress, but it is already functional.
This project allows you to test and compare trading strategies on historical data. The system is modular, so stock universes, strategies and signals can easily be switched. The system takes CSV-files on Date-OHLCV format. They can easily be downloaded from Yahoo Finance using import_data.py. The script now accepts tickers and date ranges on the command line for quick test setup
- Strategy Framework: Implement and plug in custom strategies using existing signals if desired
- Portfolio Simulation: Simulate portfolio value, positions, and trades over time
- Multiple Built-in Strategies: Includes EMA, Momentum, Stop Loss, and Buy & Hold strategies
- Performance Analytics: Summarizes returns, cash, positions, and more
- Visualization: Plots portfolio value over time using XChart
- Logging: Detailed logging for debugging and analysis
src/main/java/app/– Orchestration and entry point (App.java,BacktestOrchestrator.java)src/main/java/strategies/– Strategy implementations (e.g.,EMAStrategy,MomentumStrategy)src/main/java/accounts/– Portfolio, Order, and related classessrc/main/java/io/– Logging utilitiessrc/main/java/engine/– Market data and simulation engine
- Java 21
- Maven
-
Fetch example data using the helper script:
python import_data.py AAPL MSFT SPY --start 2000-01-01 --end 2010-01-01
-
Compile and run the tests:
mvn test -
Launch the backtester (charts are skipped automatically when no display is available):
mvn exec:java
The orchestrator will write each strategy's performance to CSV files under the
results/directory. -
Visualize the results:
python visualize_results.py results
Modify App.java to configure which strategies to test and with what parameters. Example strategies include:
- Buy & Hold
- EMA Crossover
- Momentum
- Stop Loss
After running, the orchestrator will print portfolio summaries and plot performance charts.
To add your own strategy:
- Create a new class in
strategies/extendingStrategy. - Implement the
onBarsmethod with your trading logic. - Register your strategy in
App.javausingBacktestOrchestrator.StrategyConfig.
This project has been created with the help of ChatGPT-4.1, especially for writing printing and visualization logic, as well as implementing several of the strategies.

