Have you ever wanted to backtest your trading strategies in PHP, instead of Python or MQL5? Well, probably not, as PHP is not the first language that comes to mind for algotrading. However, I have been working on a project that might change that perception.
Stochastix is a high-performance quantitative backtesting engine designed for PHP developers. It allows you to test your trading strategies against historical data, providing insights into their performance, visual analysis, and more. The engine is built with performance in mind, leveraging PHP's ds
and bcmath
extensions to handle large datasets efficiently, using a custom binary format.
If you've worked with Freqtrade or MQL5, you should feel at home as most concepts are similar. The engine is architectured as a Symfony bundle, which facilitates the engine upgrades and allows you to build your own application on top of it.
Tech stack
The engine is built with the following technologies:
- PHP 8.4
- Symfony 7.3
- Nuxt 3
- Mercure for real-time updates
- Docker for containerization
- SQLite for the message queue
Features overview
- bar-by-bar processing
- market, limit, stop orders
- multi-timeframe strategies
- custom indicators
- binary formats to speed up data loading
- automatic data download from lots of exchanges (ccxt lib)
- UI built with Nuxt with real-time updates with Mercure
- chart plotting showing indicators and executed trades
- number metrics and visual metrics (equity curve, drawdown, etc.)
- default docker install using FrankenPHP (one-liner installation)
- background jobs with Symfony Messenger
Web interface
Although the framework is usable from the terminal, I've also created a web interface to make it easier to visualize the results of your backtests. The interface is built with Nuxt 3 and provides real-time updates using Mercure. It's an easier way to interact with the engine, especially if you want to get visual analysis with interactive charts.
Here are some screenshots:
What does a strategy look like?
Here's a simple example of a strategy that uses a moving average crossover to generate buy and sell signals.
Installation
I recommend you to read the official documentation at https://phpquant.github.io/stochastix-docs/ to be sure to not miss anything, but here's how you can install a new project, using this one-liner:
docker run --rm -it --pull=always -e HOST_PWD="$PWD" \
-v "$PWD":/app -v /var/run/docker.sock:/var/run/docker.sock \
ghcr.io/phpquant/stochastix-installer your-project-name
I'd be happy to get some feedback, suggestions or contributions. If you want to try it out, you can find the code on GitHub below. Leave a star if you like it!
phpquant
/
stochastix-core
High-Performance Quantitative Backtesting Engine
Stochastix
Stochastix is a high-performance, event-driven quantitative trading backtesting engine built with PHP and Symfony. It provides a modular and extensible framework for developing, testing, and analyzing algorithmic trading strategies.
Key Features
- Event-Driven Architecture: Built for performance and realism.
- Advanced Order Types: Supports Market, Limit, and Stop orders with a full pending order book.
- Multi-Timeframe Engine: Develop strategies that analyze data across multiple timeframes simultaneously.
- Extensible Metrics: A full suite of performance metrics (Sharpe, Sortino, Calmar, etc.) with a dependency-aware calculation engine.
- High-Performance Storage: Custom binary file formats for efficient market data storage and retrieval.
- User Interface: Modern web interface to download market data, launch backtest and analyze results.
- REST API: A complete API for building custom interfaces, including real-time progress updates via Mercure.
Documentation
For the latest official documentation, visit the Stochastix Documentation.
Installation
This project is a Symfony bundle. To install it in your application:
-
Require the…
Top comments (0)