Migration & Backward Compatibility
Relevant source files
The following files were used as context for generating this wiki page:
This page outlines the transition from the original Backtrader implementation to "Slim Backtrader" (backtrader2) and the mechanisms provided to maintain compatibility with legacy data and configurations. The project aims to modernize the codebase while preserving the core logic that made the original platform a standard for backtesting.
The migration involves slimming down unnecessary features, updating syntax for modern Python versions, and removing deprecated integrations. Despite these changes, the system maintains a versioning scheme and tools to ensure that existing user strategies and historical data formats remain functional.
Sources: README.md:1-24, README.rst:11-22
Transition Strategy: Backtrader to Slim Backtrader
The fork from the original Backtrader repository introduces a "slimmed down" approach. The primary goal is to improve performance and ensure compatibility with newer Python environments (>= 3.10) while removing heavy or outdated dependencies.
Modernization Goals
The migration focuses on several key areas of technical debt and modernization:
- Syntax Updates: Transitioning to modern Python 3 idioms.
- Dependency Reduction: Removing heavy backends like
matplotlibfor interactive plotting and deprecated libraries such aspyfolio,IbPy, andcomtypes. - Architecture Cleanup: Removal of unnecessary imports and streamlining the core engine for parallel processing.
Sources: README.md:3-19, README.rst:11-22
Versioning Logic
Backward compatibility is tracked through a four-part versioning scheme (X.Y.Z.I) to signal the impact of changes to the user.
| Version Part | Designation | Description |
|---|---|---|
| X | Major | Stable unless significant overhauls (e.g., NumPy integration) occur. |
| Y | Minor | Changed upon adding new features or incompatible API changes. |
| Z | Revision | Documentation updates, small bug fixes, and minor changes. |
| I | Indicator | Indicates the count of built-in indicators available in the platform. |
Sources: README.md:94-100, README.rst:133-140
Data Migration and Conversion
To support legacy data formats within the updated framework, the project includes utility tools to rewrite and standardize data feeds.
Data Format Standardization
The tools/rewrite-data.py utility allows users to migrate various historical data formats into the native BacktraderCSVData format. This ensures that data collected under the original project remains compatible with the new implementation.
The diagram shows the flow of historical data from legacy formats through the conversion tool into the standardized CSV format used by the current engine.
Sources: tools/rewrite-data.py:31-43
Supported Migration Formats
The system supports converting from the following legacy data providers:
- Standard CSVs:
btcsv,vchartcsv,sierracsv,mt4csv. - Financial Feeds:
ibdata(Interactive Brokers),yahoo/yahoocsv(Yahoo Finance). - Platform Specific:
vchart,vcdata,vcfile.
Sources: tools/rewrite-data.py:31-43
Backward Compatibility with External Stores
The migration addresses the replacement of legacy communication libraries with modern alternatives, particularly for Interactive Brokers (IB).
From IbPy to ib-insync
The project has shifted from the deprecated IbPy towards ib-insync for IB connectivity. The backtrader/feeds/btcsv.py file demonstrates this transition by utilizing ibstore_insync instead of the legacy ibstore.
# backtrader/feeds/btcsv.py
from backtrader.stores import ibstore_insync
class IBCSVData(feed.CSVDataBase):
# ...
# _store = ibstore.IBStore # Legacy store reference
_store = ibstore_insync.IBStoreInsync # Modernized store reference
Sources: backtrader/feeds/btcsv.py:44-93
Legacy IB Interface Support
The system provides a high-level interface to Interactive Brokers that maintains the method names and parameters found in the original EClient implementation, but abstracts the reqId management. This allows strategies developed for the original API to function with minimal modification.
Sources: backtrader/stores/ibstores/ib.py:53-75
Dependency and Environment Migration
Migration from Python 2.x/early 3.x to Python 3.10+ requires adjustments to the setup and installation process.
Python Version Support
The project previously supported Python versions as low as 3.2. The modernized fork requires Python version >= 3.10.
Sources: README.md:90-92, README.rst:110-114, the_backtradersold_setup.py:73-81
Package Requirements
Legacy dependencies have been replaced or made optional to reduce the footprint of the installation:
- Pytz: Retained for timezone management in data feeds.
- Matplotlib: Moved to an optional extra (
[plotting]) rather than a core requirement to avoid heavy backend issues.
Sources: the_backtradersold_setup.py:108-115, README.md:85-88
Conclusion
Migration and backward compatibility in this project are handled by isolating modernized logic from legacy data structures. By providing robust data rewriting tools and maintaining familiar API signatures for external stores like Interactive Brokers, the project allows developers to transition to a leaner, Python 3.10+ compliant environment without losing access to historical data or having to entirely rewrite existing trading strategies.
Sources: README.md:1-24, tools/rewrite-data.py:31-43