Today I’m open sourcing my Forex backtesting / trading engine. It can run a trading algorithm against historical market data by downloading thousands of candlesticks and running the algorithm against EACH candlestick. The goal is the engine runs nearly identically for both backtesting and live trading, which is why the algorithm runs for each candlestick in the simulation. Many other trading engines I’ve found run the algorithm over all candles at once.
Considering that for each candlestick, nearly every previous candlestick up to some limit is accounted for in the resulting trade decisions, there are many millions and millions of calculations per second, so Go was a great choice for such a program. A large backtest runs in just seconds without any multithreading at all on my M1 MacBook Pro.
The new license is 0BSD. Please do whatever you want with it. PRs and bug fixes welcome.
There are many bugs, and I admittedly did a poor job at the time of writing test cases for the software, so it’s hard to know whether it’s actually valid. I mostly laid the groundwork for future development. The code is also pretty messy in the backtest.go file, so refactorings are very much welcome!
The following is from the project README (if it sounds sales-ey that’s because it came from my LinkedIn):
Autotrader is a forex quantitative trading engine I developed in two weeks using Go. The unique backtesting simulations runs a user-designed trading algorithm against historical market data. The simulation accounts for brokerage fees, hedging, leverage, market orders, limit orders, stop orders, and more. Once a reliable strategy has been identified, the user can run the trading algorithm they created on their live brokerage account.
Autotrader inserts layers of abstraction all the way down from the implementation of the trading strategy to the orders and positions maintained by the brokers over their JSON REST APIs. All financial algorithms and data structures used in this project were developed from scratch, including a time series table inspired by the NumPy Python data science library.