Building a SQLite Data Store for Cointegrated-Stock Arbitrage
Summary
This installment of a statistical-arbitrage series explains why a live system based on cointegrated stock baskets needs persistent market data and a way to update its models. Cointegration relationships can weaken or emerge as fundamentals change, while portfolio weights can shift and alter the direction and size of trades. The proposed workflow separates Python-based analysis from MetaTrader 5 execution and aims to provide an Expert Advisor with current symbols and weights, or signal when a basket needs to change.
For an individual trader, the article starts with MetaTrader 5’s integrated SQLite database rather than a specialized time-series platform. It describes using an MQL5 Service to update stored price bars and a script to initialize the database from a versioned schema, with Python helpers for loading historical quotes. The design is intentionally small and intended to evolve. The text notes a SQLite limitation around as-of joins that may complicate combining timestamped market data. It presents an implementation approach, not evidence that database-driven rotation improves trading returns.
Key ideas
- Cointegrated relationships and portfolio weights can change, so a stat-arbitrage system needs ongoing model updates.
- A persistent database can avoid repeatedly downloading market data and support analysis across a wider symbol universe.
- The proposed workflow uses Python for analysis and a MetaTrader 5 Service to keep SQLite market data current.
- The initial database design favors a simple, extensible setup for an individual trader over large-scale infrastructure.
- SQLite’s lack of as-of joins may make timestamp-based data from separate tables harder to combine.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.