|
| 1 | +# What's Stochastix? |
| 2 | + |
| 3 | +Stochastix is a high-performance, open-source quantitative **backtesting framework** dedicated exclusively to **crypto-currencies trading**. Engineered in PHP and Symfony, it is designed to provide developers and quantitative analysts with a robust, precise, and extensible environment to build, test, and analyze algorithmic trading strategies. |
| 4 | + |
| 5 | +The framework's primary mission is to enable rigorous, data-driven research by providing tools that ensure simulation realism, computational precision, and deep performance insight. |
| 6 | + |
| 7 | +## The Core Principles |
| 8 | + |
| 9 | +Trading strategy development requires rigorous analysis. Stochastix is founded on three fundamental principles that make this possible: |
| 10 | + |
| 11 | +1. **Realism:** A backtest is only as good as its simulation. Stochastix favors a realistic, event-driven approach that processes data bar-by-bar, handles complex order types natively, and manages portfolio state with precision. |
| 12 | +2. **Performance:** Quantitative analysis involves massive datasets. The framework is architected for speed and memory efficiency, from its custom binary data formats to its use of high-performance PHP extensions, ensuring that your research is not bottlenecked by I/O or processing time. |
| 13 | +3. **Developer experience:** A powerful tool should not be difficult to use. Built on modern PHP and the Symfony framework, Stochastix provides an intuitive, attribute-based system for strategy creation, clear separation of concerns, and a fully automatable command-line interface. |
| 14 | + |
| 15 | +## Key Features at a Glance |
| 16 | + |
| 17 | + * **Event-driven backtesting engine:** Simulates trading on a bar-by-bar basis, providing a realistic environment for strategies that react to market changes as they happen. |
| 18 | + * **Advanced order management:** Native support for `Market`, `Limit`, and `Stop` orders, including automated intra-bar execution of Stop-Loss and Take-Profit levels, partial exits, and programmatic order cancellation. |
| 19 | + * **Multi-timeframe analysis:** Natively request and access secondary timeframes (e.g., 4-hour data within a 1-hour strategy). Data is automatically resampled and aligned with the primary series. |
| 20 | + * **Comprehensive performance analytics:** Go far beyond simple Profit/Loss. The framework automatically generates dozens of institutional-grade summary and time-series metrics, including Sharpe Ratio, Sortino Ratio, Calmar Ratio, CAGR, Max Drawdown, Alpha, and Beta. |
| 21 | + * **High-performance data formats:** Custom binary file formats (`.stchx`, `.stchxi`, `.stchxm`) for storing market data, indicators, and metrics, ensuring minimal storage footprint and maximum read performance. |
| 22 | + * **Integrated data downloader:** A built-in CLI command to fetch high-quality historical OHLCV data from major exchanges via the CCXT library. |
| 23 | + * **Asynchronous & real-time:** Leverages Symfony Messenger and Mercure to run backtests asynchronously while pushing live progress updates to the UI. |
| 24 | + |
| 25 | +## Engineered for Performance |
| 26 | + |
| 27 | +Stochastix is meticulously optimized to handle the demands of quantitative research. |
| 28 | + |
| 29 | +### Optimized Data Storage: The Binary Formats |
| 30 | + |
| 31 | +Text-based data formats like CSV are inefficient for backtesting. They are slow to parse and consume significant disk space. Stochastix solves this with its own family of binary formats: |
| 32 | + |
| 33 | + * **`.stchx`**: For OHLCV market data. |
| 34 | + * **`.stchxi`**: For indicator time-series data. |
| 35 | + * **`.stchxm`**: For performance metric time-series data (e.g., equity curve). |
| 36 | + |
| 37 | +These formats provide several key advantages: |
| 38 | + |
| 39 | + * **Compact:** They use a fraction of the disk space of a comparable CSV file. |
| 40 | + * **Fast:** Data can be read directly into memory without any parsing overhead. |
| 41 | + * **Efficient:** The fixed-size record structure allows for extremely fast time-range lookups using binary search, meaning the engine only reads the data it needs. |
| 42 | + |
| 43 | +### Efficient In-Memory Operations: The `ds` Extension |
| 44 | + |
| 45 | +For operations that occur in memory, such as handling time-series data during a backtest, Stochastix uses the `ext-ds` PHP extension. The `Ds\Vector` object provides a more memory-efficient and performant alternative to standard PHP arrays for large, contiguous lists of numerical data, which is precisely what a time-series is. |
| 46 | + |
| 47 | +## Designed for Developers |
| 48 | + |
| 49 | +Power and performance are meaningless without a great developer experience (DX). |
| 50 | + |
| 51 | +### Intuitive Strategy Creation |
| 52 | + |
| 53 | +Creating a strategy is simple and clean. By extending `AbstractStrategy`, you gain access to a rich set of helper methods. Strategy metadata and configurable parameters are defined with simple PHP attributes, reducing boilerplate and keeping your code declarative and easy to read. |
| 54 | + |
| 55 | +```php |
| 56 | +#[AsStrategy(alias: 'my_strategy', name: 'My Awesome Strategy')] |
| 57 | +class MyStrategy extends AbstractStrategy |
| 58 | +{ |
| 59 | + #[Input(description: 'The period for my indicator.')] |
| 60 | + private int $myPeriod = 20; |
| 61 | + |
| 62 | + public function onBar(OhlcvSeries $bars): void |
| 63 | + { |
| 64 | + // ... your logic here |
| 65 | + } |
| 66 | +} |
0 commit comments