The Ultimate Backtesting and Live Trading Library for Stocks, Options, Crypto, Futures, FOREX and More!
Lumibot is a comprehensive, production-ready algorithmic trading framework designed for quantitative researchers, portfolio managers, and algorithmic traders. Built with modern Python practices, it seamlessly bridges the gap between backtesting and live trading with the same codebase.
- π Unified Codebase: Same code for backtesting and live trading
- π Multi-Asset Support: Stocks, Options, Crypto, Futures, FOREX
- β‘ High Performance: Optimized for speed and efficiency
- π Multiple Brokers: Alpaca, Interactive Brokers, Tradier, Schwab, and more
- π Rich Analytics: Built-in performance metrics and visualization
- π‘οΈ Risk Management: Advanced position sizing and risk controls
- π Modern Python: Type hints, async support, and clean architecture
π Complete Documentation: lumibot.lumiwealth.com
Before installing Lumibot, ensure you have:
# Install python-dotenv (required for private packages)
pip install python-dotenv
# Or with uv (recommended)
uv pip install python-dotenv# Install from PyPI (recommended for most users)
pip install lumibot
# Or with uv (faster and more reliable)
uv pip install lumibot
# Or install from source
pip install -e .For contributors and developers who want access to the latest features:
# Clone the repository
git clone https://github.com/AI-Ahmed/lumibot.git
cd lumibot
# Create virtual environment with Python 3.12 (required for TA libraries)
python3.12 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install python-dotenv first (required for private packages)
pip install python-dotenv
# Install development dependencies
pip install -r requirements_dev.txt
# Install package in editable mode
pip install -e .# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone the repository
git clone https://github.com/AI-Ahmed/lumibot.git
cd lumibot
# Create virtual environment with Python 3.12
uv venv --python 3.12
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install python-dotenv first
uv pip install python-dotenv
# Install development dependencies
uv pip install -r requirements_dev.txt
# Install package in editable mode
uv pip install -e .Lumibot supports several installation extras for different use cases:
# Technical Analysis tools
# - Python >= 3.12: pandas-ta (fully supported)
pip install -e ".[ta]"
# All public packages (includes TA tools)
pip install -e ".[all]"
# Private packages (for contributors with access)
pip install -e ".[private]" # Requires GIT_TOKEN# Technical Analysis tools with uv
uv pip install -e ".[ta]"
# All public packages with uv
uv pip install -e ".[all]"
# Private packages with uv (requires GIT_TOKEN)
uv pip install -e ".[private]"
# Install all extras at once
uv pip install -e ".[all,private]"Due to conflicting numpy version requirements, the dependency resolver cannot install both packages simultaneously:
- FPAP: Declares
numpy==1.26.4(pinned version) - pandas-ta: Requires
numpy>=2.2.6(newer version)
Note: While both packages may work together at runtime with numpy 2.2.6, the strict dependency declarations prevent automatic co-installation.
Installation Options:
-
FPAP Only (Recommended for contributors):
uv pip install -e ".[private]" # Installs FPAP without pandas-ta
-
pandas-ta Only (Public users):
uv pip install -e ".[ta]" # Installs pandas-ta without FPAP
-
Separate Environments (Advanced users):
# Environment 1: FPAP uv venv fpap-env --python 3.12 source fpap-env/bin/activate uv pip install -e ".[private]" # Environment 2: pandas-ta uv venv ta-env --python 3.12 source ta-env/bin/activate uv pip install -e ".[ta]"
Compatibility Matrix:
| Installation | FPAP | pandas-ta | Core Trading | Notes |
|---|---|---|---|---|
.[private] |
β | β | β | For contributors with access |
.[ta] |
β | β | β | For public users needing TA |
.[all] |
β | β | β | Public packages only |
.[all,private] |
β | β | FPAP conflicts with pandas-ta |
Contributors with access to private packages can install additional proprietary tools:
# Set your GitHub token
export GIT_TOKEN=your_github_personal_access_token
# Install with private packages using pip
pip install -e ".[private]"
# Or with uv (recommended)
uv pip install -e ".[private]"
# Or install everything (public + private)
uv pip install -e ".[all,private]"Create a .env file in the project root:
GIT_TOKEN=your_github_personal_access_tokenThen install (the token will be automatically detected):
# With pip
pip install -e ".[private]"
# With uv (recommended)
uv pip install -e ".[private]"# 1. Clone and setup
git clone https://github.com/AI-Ahmed/lumibot.git
cd lumibot
# 2. Create .env file
echo "GIT_TOKEN=your_github_token" > .env
# 3. Setup with uv (recommended)
uv venv --python 3.12
source .venv/bin/activate
uv pip install python-dotenv
uv pip install -e ".[all,private]"
# 4. Verify installation
uv pip list | grep fpap # Should show FPAP packageNote: Private packages include advanced analytics tools (FPAP) and are only available to authorized contributors. The package works fully without these dependencies.
- Python 3.10+ (Python 3.12+ recommended for best performance)
- Virtual Environment (strongly recommended)
- Data Source: Polygon.io (free tier available)
- Use coupon code
LUMI10for 10% off π°
- Use coupon code
from lumibot.strategies import Strategy
from lumibot.backtesting import YahooDataBacktesting
from lumibot.traders import Trader
from datetime import datetime
class BuyAndHold(Strategy):
def initialize(self):
self.sleeptime = 1 # Sleep for 1 day between iterations
def on_trading_iteration(self):
if self.first_iteration:
# Buy $10,000 worth of SPY on first iteration
order = self.create_order("SPY", 10000, "buy")
self.submit_order(order)
# Backtest the strategy
backtesting_start = datetime(2020, 1, 1)
backtesting_end = datetime(2023, 12, 31)
BuyAndHold.backtest(
YahooDataBacktesting,
backtesting_start,
backtesting_end,
)# Run a built-in example
python -m lumibot.example_strategies.stock_buy_and_holdWant to build trading bots without code? Check out our new platform BotSpot where you can create and deploy trading strategies using AI! BotSpot allows you to:
- Build trading bots using natural language and AI
- Test your strategies with historical data
- Deploy your bots to trade automatically
- Join a community of algorithmic traders
Visit BotSpot.trade to get started building AI-powered trading bots today!
Our blog has lots of example strategies and shows you how to run a bot using LumiBot. Check the blog out here:
# Run a simple buy and hold backtest
python -m lumibot.example_strategies.stock_buy_and_holdExplore our comprehensive example strategy: Stock Example Algorithm
Deploy it instantly:
For more information on this example strategy, you can check out the README in the example strategy repository here: Example Algorithm
We welcome contributions from the community! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated.
Watch our contributor onboarding video: Watch The Video
# 1. Fork and clone the repository
git clone https://github.com/yourusername/lumibot.git
cd lumibot
# 2. Create virtual environment with Python 3.12
uv venv --python 3.12
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# 3. Install python-dotenv first
uv pip install python-dotenv
# 4. Install development dependencies
uv pip install -r requirements_dev.txt
# 5. Install package in editable mode with all extras
uv pip install -e ".[all]"
# 6. Install pre-commit hooks (optional but recommended)
pre-commit install# 1. Fork and clone the repository
git clone https://github.com/yourusername/lumibot.git
cd lumibot
# 2. Create virtual environment with Python 3.12
python3.12 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# 3. Install python-dotenv first
pip install python-dotenv
# 4. Install development dependencies
pip install -r requirements_dev.txt
# 5. Install package in editable mode
pip install -e ".[all]"
# 6. Install pre-commit hooks (optional but recommended)
pre-commit install- Watch the video: Contributing Guide
- Fork the repository on GitHub
- Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes with proper tests and documentation
- Run tests:
pytest(ensure all tests pass) - Check code quality:
ruff check .andruff format . - Commit your changes:
git commit -m "feat: add amazing feature" - Push to your fork:
git push origin feature/your-feature-name - Create a Pull Request targeting the
devbranch
- Code Style: We use Ruff for linting and formatting
- Testing: Add tests for new features using
pytest - Documentation: Update docstrings and README as needed
- Commit Messages: Use conventional commits (feat:, fix:, docs:, etc.)
- Branch Naming: Use descriptive names like
feature/options-tradingorfix/memory-leak
Contributors with access to private packages can install additional development tools:
# Create .env file with your GitHub token
echo "GIT_TOKEN=your_github_token" > .env
# Install with private dependencies
pip install -e ".[private]"Our build system supports:
- Dynamic dependency resolution based on Python version
- Private package integration for authorized contributors
- Modern Python packaging with
pyproject.tomlandsetuptools
We maintain high code quality with comprehensive testing using pytest.
# Run all tests
pytest
# Run with coverage report
pytest --cov=lumibot --cov-report=html
# Run specific test file
pytest tests/test_asset.py
# Run tests matching a pattern
pytest -k "test_order"
# Run tests with verbose output
pytest -vSome tests require API keys in a .env file:
# Required for broker integration tests
ALPACA_API_KEY=your_alpaca_key
ALPACA_SECRET_KEY=your_alpaca_secret
POLYGON_API_KEY=your_polygon_key- Unit Tests: Fast, isolated component tests
- Integration Tests: Broker and data source integration
- Backtest Tests: Strategy backtesting validation
- Performance Tests: Speed and memory benchmarks
To show code coverage, you can run the following command:
coverage run; coverage report; coverage htmlThis will show you the code coverage in the terminal and also create a folder called "htmlcov" which will have a file called "index.html". You can open this file in your browser to see the code coverage in a more readable format.
If you don't want to keep typing out the command, you can add it as an alias in bash. To do this, you can run the following command:
alias cover='coverage run; coverage report; coverage html'This will now allow you to run the command by just typing "cover" in the terminal.
coverIf you want to also add it to your .bashrc file. You can do this by running the following command:
echo "alias cover='coverage run; coverage report; coverage html'" >> ~/.bashrcIf you are on Windows, you can add an alias by running the following command:
Add to your PowerShell Profile: (profile.ps1)
function cover {
coverage run
coverage report
coverage html
}To set up in VS Code for debugging, you can add the following to your launch.json file under "configurations". This will allow you to go into "Run and Debug" and run the tests from there, with breakpoints and everything.
NOTE: You may need to change args to the path of your tests folder.
{
"name": "Python: Pytest",
"type": "python",
"request": "launch",
"module": "pytest",
"args": [
"lumibot/tests"
],
"console": "integratedTerminal",
}Here's an example of an actual launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Pytest",
"type": "python",
"request": "launch",
"module": "pytest",
"args": [
"lumibot/tests"
],
"console": "integratedTerminal",
}
]
}Lumibot supports multiple data providers for comprehensive market coverage:
| Data Source | Asset Types | OHLCV | Split Adjusted | Dividends | Returns | Dividend Adjusted |
|---|---|---|---|---|---|---|
| Polygon | Stocks, Options, Crypto, Forex | β | β | β | β | β |
| Yahoo Finance | Stocks, ETFs, Indices | β | β | β | β | β |
| Alpaca | Stocks, Crypto | β | β | β | β | β |
| Interactive Brokers | All Asset Classes | β | β | β | β | β |
| Tradier | Stocks, Options | β | β | β | β | β |
| CSV/Pandas | Custom Data | β | β | β | β | β |
- Real-time Data: Live market data for active trading
- Historical Data: Extensive historical coverage for backtesting
- Multiple Timeframes: From tick data to daily bars
- Corporate Actions: Automatic adjustment for splits and dividends
- Alternative Data: Support for custom data feeds
Recommended: Polygon.io offers the best balance of features, reliability, and cost. Use code
LUMI10for 10% off.
- Strategies: Define your trading logic and rules
- Brokers: Execute trades across multiple platforms
- Data Sources: Feed market data to your strategies
- Risk Management: Built-in position sizing and risk controls
- Analytics: Performance tracking and visualization
- Backtesting: Historical strategy validation
- Modularity: Plug-and-play components
- Extensibility: Easy to add new brokers and data sources
- Performance: Optimized for speed and memory efficiency
- Reliability: Production-tested with error handling
- Maintainability: Clean, well-documented codebase
# Create and switch to feature branch
git checkout -b feature/your-feature-name
# Keep your branch updated with latest dev
git fetch origin
git merge origin/dev# Stage and commit your changes
git add .
git commit -m "feat: add your feature description"
# Push to your fork
git push -u origin feature/your-feature-name# Update dev branch
git checkout dev
git fetch origin
git merge origin/dev
# Rebase your feature branch
git checkout feature/your-feature-name
git rebase dev
# Force push (safely) to update remote branch
git push --force-with-lease origin feature/your-feature-name# Clean up after merge
git checkout dev
git fetch origin
git merge origin/dev
git branch -D feature/your-feature-name
git push origin --delete feature/your-feature-nameProblem: No solution found when resolving dependencies with numpy versions
Solution: This occurs when trying to install both FPAP and pandas-ta together:
# Error message example:
# fpap==0.4.6 depends on numpy==1.26.4
# pandas-ta==0.4.71b0 depends on numpy>=2.2.6
# Solution 1: Install FPAP only (recommended for contributors)
uv pip install -e ".[private]"
# Solution 2: Install pandas-ta only (recommended for public users)
uv pip install -e ".[ta]"
# Solution 3: Use separate environments
uv venv separate-env --python 3.12Alternative Solutions for FPAP + TA Users:
# Install FPAP first
uv pip install -e ".[private]"
# Then install numpy 1.26.4 compatible TA libraries
uv pip install finta # Financial Technical Analysis
uv pip install ta # Technical Analysis Library
# Note: talib-binary requires Python < 3.12# Install FPAP first
uv pip install -e ".[private]"
# Force install pandas-ta (may work despite version conflict)
uv pip install pandas-ta --force-reinstall
# Verify both work (they often do despite the version warning)
python -c "import fpap, pandas_ta; print('β
Both packages working')"
β οΈ Warning: Option B bypasses dependency resolution and may cause instability. Use at your own risk and test thoroughly.
Problem: python3.12 not found
Solution: Install Python 3.12 or use available version:
# Check available Python versions
ls /usr/bin/python*
# Use available version (e.g., python3.11)
uv venv --python python3.11
# Or install Python 3.12
# macOS: brew install [email protected]
# Ubuntu: sudo apt install python3.12- Never commit API keys to version control
- Use environment variables or
.envfiles - Rotate keys regularly for production systems
- Use separate keys for development and production
- Test thoroughly in paper trading mode first
- Monitor positions and risk metrics continuously
- Implement circuit breakers for unexpected behavior
- Keep logs for audit and debugging purposes
- Position sizing: Never risk more than you can afford to lose
- Diversification: Don't put all capital in one strategy
- Stop losses: Implement proper exit strategies
- Monitoring: Set up alerts for unusual behavior
Join our thriving community of algorithmic traders and developers!
Join our Discord Server - Connect with other traders, get help, and share strategies
BotSpot.trade - Build, test, and deploy trading strategies using AI assistance (no coding required!)
Enhance your algorithmic trading skills with our comprehensive courses:
- Algorithmic Trading Course - Master the fundamentals
- Machine Learning for Trading - Advanced ML techniques
- Options Trading Course - Options strategies and Greeks
- Blog - Strategy examples and tutorials
- Documentation - Complete API reference
- YouTube Channel - Video tutorials and webinars
- GitHub Discussions - Technical discussions
Special thanks to all our contributors who make Lumibot better every day!
- Robert Grzesik - Original creator and maintainer
- Ahmed - Advanced features and architecture improvements
- Community Contributors - Bug fixes, documentation, and feature requests
- Polygon.io - Market data provider
- Alpaca - Commission-free trading API
- Interactive Brokers - Professional trading platform
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 Lumiwealth
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
β Star this repository if Lumibot helps you build better trading strategies! β
π Get Started | π Documentation | π¬ Discord | π¦ Twitter