Skip to content

Commit

Permalink
Merge pull request #282 from Lumiwealth/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesir authored Dec 1, 2023
2 parents 744dc10 + 58d1511 commit 87b2a0e
Show file tree
Hide file tree
Showing 671 changed files with 36,590 additions and 1,130,465 deletions.
9 changes: 9 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# These owners will be the default owners for everything in

# the repo. Unless a later match takes precedence

# @grzesir will be requested for

# review when someone opens a pull request

* @grzesir
34 changes: 34 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: LumiBot CI/CD
on: [pull_request]
jobs:
LintAndTest:
runs-on: ubuntu-latest
timeout-minutes: 20
environment: unit-tests
env:
AIOHTTP_NO_EXTENSIONS: 1
POLYGON_API_KEY: ${{secrets.POLYGON_API_KEY}} # Required for Polygon API BackTests
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
cache: pip
- name: Install dependencies
run: |
echo "Set AIOHTTP_NO_EXTENSIONS=$AIOHTTP_NO_EXTENSIONS so that aiohttp doesn't try to install C extensions"
python -m pip install --upgrade pip
pip install requests
pip install -r requirements_dev.txt
# Setup.py was not working for some reason, reverted to using requirements.txt again
# python setup.py install
- name: Run Linter
run: |
# Remove -e flag to fail the run if issues are found
ruff check . -e
- name: Run Unit Tests
run: |
coverage run
coverage report
coverage html
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

# Cache files
lumibot/cache
*cache*
**/*.pkl
.pytest*

# Development files
venv
.venv
logs
credentials.py
*debug.py
Expand All @@ -20,6 +22,7 @@ todos.txt
test_bot.py
.vscode
.coverage*
*secret*/**.env

# Pypi deployment
build
Expand Down
5 changes: 5 additions & 0 deletions .secrets/lumi_secrets.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##### WARNING: THIS IS AN EXAMPLE FILE, DO NOT ADD YOUR KEYS HERE, THEY WILL BE CHECKED IN TO GIT #####

# This file is used to store all the API keys and other sensitive information so that it is not stored in the code.
# This file is not stored in GitHub and is only stored locally on the computer running the code.
POLYGON_API_KEY = '<your key here>'
74 changes: 68 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,81 @@
# Lumibot - Algorithmic Trading Library

Backtesting and trading for stocks, options, crypto, futures and more!

# Documentation
## Documentation - 👇 Start Here 👇

To get started with Lumibot, you can check out our documentation below.

**Check out the documentation for the project here: <http://lumibot.lumiwealth.com/>**
**Check out the documentation for the project here: 👉 <http://lumibot.lumiwealth.com/> 👈**

## Contributors

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!

**Steps to contribute:**

# Running Tests
1. Clone the repository to your local machine
2. Create a new branch for your feature
3. Run `pip install -r requirements_dev.txt` to install the developer dependencies
4. Install all the requriements from setup.py: `pip install -e .`
5. Make your changes
6. Run `pytest` to make sure all the tests pass
7. Create a pull request to merge your branch into master

## Running Tests

We use pytest for our testing framework. To run the tests, you can run the following command:

```bash
pytest
```

### Showing Code Coverage

To show code coverage, you can run the following command:

```bash
coverage run; coverage report; coverage html
```

#### Adding an Alias on Linux or MacOS

This 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:

```bash
alias cover='coverage run; coverage report; coverage html'
```

This will now allow you to run the command by just typing "cover" in the terminal.

```bash
cover
```

If you want to also add it to your .bashrc file. You can do this by running the following command:

```bash
echo "alias cover='coverage run; coverage report; coverage html'" >> ~/.bashrc
```

#### Adding an Alias on Windows

If you are on Windows, you can add an alias by running the following command:

Add to your PowerShell Profile: (profile.ps1)

```powershell
function cover {
coverage run
coverage report
coverage html
}
```

### Setting Up PyTest in VS Code

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.
Expand Down Expand Up @@ -51,13 +113,13 @@ Here's an example of an actual launch.json file:
}
```

# Community
## Community

If 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>**

# Courses
## Courses

If you need extra help building your algorithm, we have courses to help you out.

Expand All @@ -67,6 +129,6 @@ If you need extra help building your algorithm, we have courses to help you out.

**For our Options Trading course: <https://www.lumiwealth.com/product-category/options-trading-purchase/>**

# License
## License

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>
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 3a1a810cf90a8c6fea45b3cc662d47f6
config: 52422e79752ce83df7742446c340d415
tags: 645f666f9bcd5a90fca523b33c5a78b7
41 changes: 29 additions & 12 deletions docs/_sources/backtesting.pandas.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,21 @@ There is also a returns plot. By default this will show in a browser. You may su

.. code-block:: python
strategy_class.backtest(
PandasDataBacktesting,
backtesting_start,
backtesting_end,
pandas_data=pandas_data,
budget=100000,
)
trader = Trader(backtest=True)
data_source = PandasDataBacktesting(
pandas_data=pandas_data,
datetime_start=backtesting_start,
datetime_end=backtesting_end,
)
broker = BacktestingBroker(data_source)
strat = strategy_class(
broker=broker,
backtesting_start=backtesting_start,
backtesting_end=backtesting_end,
budget=100000,
)
trader.add_strategy(strat)
trader.run_all()
Putting all of this together, and adding in budget and strategy information, the code would look like the following:

Expand Down Expand Up @@ -184,14 +192,23 @@ Putting all of this together, and adding in budget and strategy information, the
backtesting_end = datetime.datetime(2021, 7, 20)
# Run the backtesting
MyStrategy.backtest(
PandasDataBacktesting,
backtesting_start,
backtesting_end,
trader = Trader(backtest=True)
data_source = PandasDataBacktesting(
pandas_data=pandas_data,
datetime_start=backtesting_start,
datetime_end=backtesting_end,
)
broker = BacktestingBroker(data_source)
strat = strategy_class(
broker=broker,
backtesting_start=backtesting_start,
backtesting_end=backtesting_end,
budget=100000,
)
trader.add_strategy(strat)
trader.run_all()
Getting Data
----------------

If you would like an easy way to download pricing data from Alpaca then you can use this code: https://github.com/Lumiwealth/lumibot/blob/master/download_price_data_alpaca.py
If you would like an easy way to download pricing data from Alpaca then you can use this code: https://github.com/Lumiwealth/lumibot/blob/master/download_price_data_alpaca.py
44 changes: 28 additions & 16 deletions docs/_sources/backtesting.polygon.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@ Finally, run the backtest:

.. code-block:: python
CryptoEMACross.backtest(
PolygonDataBacktesting,
backtesting_start,
backtesting_end,
benchmark_asset=Asset(symbol="BTC", asset_type="crypto")
trader = Trader(backtest=True)
data_source = PolygonDataBacktesting(
datetime_start=backtesting_start,
datetime_end=backtesting_end,
api_key="YOUR_POLYGON_API_KEY",
)
broker = BacktestingBroker(data_source)
crypto_strat = CryptoEMACross(
broker=broker,
backtesting_start=backtesting_start,
backtesting_end=backtesting_end,
quote_asset=quote_asset,
benchmark_asset=Asset(symbol="BTC", asset_type="crypto")
buy_trading_fees=[trading_fee],
sell_trading_fees=[trading_fee],
polygon_api_key="YOUR_POLYGON_API_KEY",
polygon_has_paid_subscription=False,
)
trader.add_strategy(crypto_strat)
trader.run_all()
Here's another example but for for stocks:

Expand Down Expand Up @@ -74,15 +81,20 @@ Here's another example but for for stocks:
backtesting_start = datetime(2023, 1, 1)
backtesting_end = datetime(2023, 5, 1)
MyStrategy.backtest(
PolygonDataBacktesting,
backtesting_start,
backtesting_end,
benchmark_asset=Asset(symbol="SPY", asset_type="stock")
polygon_api_key="YOUR_POLYGON_API_KEY",
polygon_has_paid_subscription=False,
trader = Trader(backtest=True)
data_source = PolygonDataBacktesting(
datetime_start=backtesting_start,
datetime_end=backtesting_end,
api_key="YOUR_POLYGON_API_KEY",
)
broker = BacktestingBroker(data_source)
my_strat = MyStrategy(
broker=broker,
backtesting_start=backtesting_start,
backtesting_end=backtesting_end,
benchmark_asset=Asset(symbol="BTC", asset_type="crypto")
)
trader.add_strategy(crypto_strat)
trader.run_all()
In summary, the polygon.io backtester is a powerful tool for fetching pricing data for backtesting various strategies. With its capability to cache data for faster subsequent backtesting and its easy integration with polygon.io API, it is a versatile choice for any backtesting needs.

18 changes: 13 additions & 5 deletions docs/_sources/backtesting.yahoo.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ There is also a returns plot. By default this will show in a browser. You may su
backtesting_end = datetime(2020, 12, 31)
# Run the backtest
MyStrategy.backtest(
YahooDataBacktesting,
backtesting_start,
backtesting_end,
)
trader = Trader(backtest=True)
data_source = YahooDataBacktesting(
datetime_start=backtesting_start,
datetime_end=backtesting_end,
)
broker = BacktestingBroker(data_source)
strat = strategy_class(
broker=broker,
backtesting_start=backtesting_start,
backtesting_end=backtesting_end,
)
trader.add_strategy(strat)
trader.run_all()
5 changes: 4 additions & 1 deletion docs/_sources/getting_started.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Here it is all together:
trader.add_strategy(strategy)
trader.run_all()
Or you can download the file here: https://github.com/Lumiwealth/lumibot/blob/master/example_strategies/simple_start_single_file.py
Or you can download the file here: https://github.com/Lumiwealth/lumibot/blob/dev/lumibot/example_strategies/simple_start_single_file.py


Adding Trading Fees
Expand All @@ -177,6 +177,9 @@ If you want to add trading fees to your backtesting, you can do so by setting up

.. code-block:: python
from lumibot.backtesting import YahooDataBacktesting
from lumibot.entities import TradingFee
# Create two trading fees, one that is a percentage and one that is a flat fee
trading_fee_1 = TradingFee(flat_fee=5) # $5 flat fee
trading_fee_2 = TradingFee(percent_fee=0.01) # 1% trading fee
Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ And that's it! Easy-peasy.

If you would like to learn how to modify your strategies we suggest that you first learn about Lifecycle Methods, then Strategy Methods and Strategy Properties. You can find the documentation for these in the menu, with the main pages describing what they are, then the sub-pages describing each method and property individually.

We also have some more sample code that you can check out here: https://github.com/Lumiwealth/lumibot/tree/master/getting_started
We also have some more sample code that you can check out here: https://github.com/Lumiwealth/lumibot/tree/dev/lumibot/example_strategies

We wish you good luck with your trading strategies, don't forget us when you're swimming in cash!

Expand Down
Loading

0 comments on commit 87b2a0e

Please sign in to comment.