Lumibot is a backtesting and trading library for stocks, options, crypto, futures and more. It is made so that the same code you use for backtesting can be used for live trading, making it easy to transition from backtesting to live trading. Lumibot is a highly flexible library that allows you to create your own strategies and indicators, and backtest them on historical data. It is also highly optimized for speed, so you can backtest your strategies quickly and efficiently.
IMPORTANT: This library requires data for backtesting. Our recommended data source is ThetaData because they provide the deepest historical coverage weβve found and directly support BotSpot. Use the promo code BotSpot10 at checkout for 10% off the first order (the code also tells ThetaData you were referred by us).
Contributor note: Read
AGENTS.mdbefore running anything Theta-related. That file spells out the hard rulesβnever launch ThetaTerminal or the shared downloader locally, always point LumiBot at the AWS-hosted downloader, and wrap all long commands with/Users/robertgrzesik/bin/safe-timeout. Breaking these rules kills the only licensed Theta session.
BACKTESTING_ARCHITECTURE.md- Detailed documentation of the backtesting data flow (Yahoo, ThetaData, Polygon data sources, caching, and data flow diagrams)CLAUDE.md- AI assistant instructions for working with the codebaseAGENTS.md- Critical rules for ThetaData and production safety
To get started with Lumibot, you can check out our documentation below.
Check out the documentation for the project here: π http://lumibot.lumiwealth.com/ π
Want 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:
To run a backtest, you can use the following code snippet:
python -m lumibot.example_strategies.stock_buy_and_holdWe made a small example strategy to show you how to use Lumibot in this GitHub repository: Example Algorithm GitHub
To run this example strategy, click on the Deploy to Render button below to deploy the strategy to Render (our recommendation). You can also run the strategy on Repl.it by clicking on the Run on Repl.it button below.
For more information on this example strategy, you can check out the README in the example strategy repository here: Example Algorithm
If you want to contribute to Lumibot, you can check how to get started below. We are always looking for contributors to help us out!
Here's a video to help you get started with contributing to Lumibot: Watch The Video
Steps to contribute:
- Watch the video: Watch The Video
- Clone the repository to your local machine
- Create a new branch for your feature
- Run
pip install -r requirements_dev.txtto install the developer dependencies - Install all the requirements from setup.py:
pip install -e . - Make your changes
- Run
pytestto make sure all the tests pass - Create a pull request to merge your branch into master
We use pytest for our testing framework. Some tests require API keys to be in a .env file in the root directory. To run the tests, you can run the following command:
pytestTo run an individual test file, you can run the following command:
pytest tests/test_asset.pyLumibot can mirror its local parquet caches to AWS S3 when you enable the new
backtest cache manager. The feature is optional and defaults to local storage.
To configure the environment variables, understand the key naming convention,
and follow the manual validation checklist, review docs/remote_cache.md.
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",
}
]
}This table points out some of the differences between the data sources we use in Lumibot. These refer to the data returned in a Bars entity that is returned from calls to get_historical_prices.
| data_source | type | OHLCV | split adjusted | dividends | returns | dividend adjusted returns |
|---|---|---|---|---|---|---|
| yahoo | stock | Yes | Yes | Yes | Yes | Yes |
| alpaca | stock | Yes | Yes | No | Yes | No |
| polygon | stock | Yes | Yes | No | Yes | No |
| Tradier | stock | Yes | Yes | No | Yes | No |
| Pandas* | stock | Yes | Yes | Yes | Yes | Yes |
*Pandas is not a data source per se, but it can load csv files in the same format as Yahoo dataframes, which can contain dividends.
Making a new branch and pulling from main:
git checkout -b my-feature
git fetch origin
git merge origin/devCommitting work to you feature branch:
git add .
git commit -m "my changes"
git push -u origin my-featureIf work on main progressed while you were in another branch, this is how you rebase it into your branch. Note that since you've rebased your local branch, you'll need to force push your changes to update the remote branch. The --force-with-lease option is a safer alternative to --force as it will abort the push if there are any new commits on the remote that you haven't incorporated into your local branch
git checkout dev
git fetch origin
git merge origin/dev
git checkout my-feature
git rebase dev
git checkout my-feature
git push --force-with-lease origin my-featureWhen ready to merge the branch into main, go into github, create a pull request, and await review. When your PR is approved it will automatically be merged into the dev branch remotely. Now, you can delete your local branch and the remote branch.
git checkout dev
git fetch origin
git merge origin/dev
git branch -D my-feature
git push origin --delete my-featureIf you want to learn more about Lumibot or Algorithmic Trading then you will love out communities! You can join us on Discord.
Join us on Discord: https://discord.gg/TmMsJCKY3T
Build AI-powered trading bots on BotSpot.trade - Our platform for creating, testing, and deploying trading strategies with AI assistance!
If you need extra help building your algorithm, we have courses to help you out.
For our Algorithmic Trading course: https://lumiwealth.com/algorithmic-trading-landing-page
For our Machine Learning for Trading course: https://www.lumiwealth.com/product-category/machine-learning-purchase/
For our Options Trading course: https://www.lumiwealth.com/product-category/options-trading-purchase/
Looking for a no-code solution? Build trading bots with AI on BotSpot
This library is covered by the MIT license for open sourced software which can be found here: https://github.com/Lumiwealth/lumibot/blob/master/LICENSE