Research project for order flow analysis on futures markets using VectorBT Pro.
This project explores order flow dynamics in futures markets, leveraging high-frequency data, advanced indicators, and portfolio simulation techniques. Built on Python with GPU acceleration support (MPS on Apple Silicon).
- Order Flow Analysis: Imbalance detection, footprint charts, volume profile analysis
- VectorBT Pro Integration: Signal generation, backtesting, portfolio simulation, parameter optimization
- Multi-Timeframe Support: Tick, minute, and higher timeframe analysis
- GPU Acceleration: PyTorch MPS backend enabled for Apple Silicon (torch 2.12.0)
- Numba-Optimized Indicators: Fast computation of 500+ built-in and TA-Lib indicators
- Risk Management: Stop orders, cross-validation, deflated Sharpe ratio analysis
- Python 3.11+ via Conda/Mamba
- VectorBT Pro — backtesting and portfolio simulation
- PyTorch 2.12.0 — ML with MPS GPU support
- TA-Lib — technical analysis indicators
- Numba — JIT compilation for performance
- direnv — automatic environment activation
- uv — fast Python package management
- macOS (Apple Silicon recommended for MPS GPU)
- miniforge3 (or Anaconda/Miniconda)
- direnv
- uv
# 1. Clone the repository
git clone https://github.com/davidleconte/OrderFlowOnFutures.git
cd OrderFlowOnFutures
# 2. Create conda environment (uses local .conda/ directory)
conda create --prefix .conda python=3.11
# 3. Install dependencies
uv pip install vectorbtpro torch torchvision
# 4. Install TA-Lib (macOS)
brew install ta-lib
pip install TA-Lib
# 5. Configure direnv for auto-activation
cp .envrc .envrc.backup # if you want to keep a copy
# Edit .envrc paths if your conda base differs from /Users/david.leconte/miniforge3
direnv allowThe .envrc file automatically:
- Activates the local conda environment
- Sets
KMP_DUPLICATE_LIB_OK=TRUEto resolve torch/libomp conflicts on macOS ARM
import vectorbtpro as vbt
# Load futures data
data = vbt.YFData.download('ES=F', start='2024-01-01')
# Generate signals
short_ma = vbt.MA.run(data.get('Close'), 10)
long_ma = vbt.MA.run(data.get('Close'), 50)
entries = short_ma.ma_crossed_above(long_ma)
exits = short_ma.ma_crossed_below(long_ma)
# Backtest
portfolio = vbt.Portfolio.from_signals(
data.get('Close'),
entries,
exits,
init_cash=100_000,
fees=0.0001
)
print(portfolio.stats())OrderFlowOnFutures/
├── .envrc # direnv auto-activation
├── .gitignore # Git ignore rules
├── .conda/ # Local conda environment (gitignored)
├── LICENSE # MIT License
├── README.md # This file
├── CONTRIBUTING.md # Development guidelines
└── .github/
└── workflows/
└── python-ci.yml # CI/CD pipeline
# Activate environment (direnv should auto-activate)
direnv allow
# Run the test suite
python -m pytest tests/ -vruff check .
ruff format --check .GitHub Actions workflows are configured to run on every push and pull request:
- Linting:
rufffor code style and quality checks - Testing:
pytestfor unit and integration tests - Build Validation: Ensures the conda environment spec is valid
Contributions are welcome! Please read CONTRIBUTING.md for guidelines on:
- Setting up the development environment
- Code style and linting standards
- Testing requirements
- Pull request process
This project is licensed under the MIT License — see the LICENSE file for details.
- VectorBT Pro for the backtesting framework
- PyPortfolioOpt for portfolio optimization
- Riskfolio-Lib for risk management