Skip to content

Commit

Permalink
WIP docs update, critical bugfix for pandas upgrade, move to pytest, …
Browse files Browse the repository at this point in the history
…drop older deps, include example notebooks in docs
  • Loading branch information
timkpaine committed Jun 30, 2022
1 parent 6a1253c commit b930085
Show file tree
Hide file tree
Showing 112 changed files with 8,788 additions and 4,972 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
11 changes: 4 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ jobs:

strategy:
matrix:
python-version: [3.7, 3.9]
python-version: [3.9]
os: [ubuntu-latest, macos-latest, windows-latest]
event-name: [push]

steps:
- uses: actions/checkout@v2
Expand All @@ -32,21 +31,19 @@ jobs:

- name: Install dependencies
run: |
python -m pip install -e .[dev]
make develop
python -m pip install -U wheel twine setuptools
- name: Lint
run: |
python -m flake8 bt setup.py
make lint
- name: Test
run: |
python -m nose --with-coverage --cover-package bt
if: ${{ github.event_name == matrix.event-name }}
make test
- name: Coverage
uses: codecov/codecov-action@v2
if: ${{ github.event_name == matrix.event-name }}

- name: Package and check
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ jobs:

- name: Install dependencies
run: |
python -m pip install -e .[dev]
make develop
python -m pip install -U wheel twine setuptools
- name: Lint
run: |
python -m flake8 bt setup.py
make lint
- name: Test
run: |
python -m nose --with-coverage --cover-package bt
make test
- name: Package and check
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
python_junit.xml

# Translations
*.mo
Expand Down Expand Up @@ -70,3 +71,5 @@ docs/source/.ipynb_checkpoints/
# macOS
.DS_Store

# jupyter
.ipynb_checkpoints
30 changes: 16 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ TMPREPO=/tmp/docs/bt

default: build_dev

.PHONY: dist upload docs pages serve klink notebooks test lint fix
.PHONY: dist upload docs pages serve klink notebooks test lint fix develop

develop:
python -m pip install -e .[dev]

test:
python -m nose --with-coverage --cover-package bt
python -m pytest -vvv tests --cov=bt --junitxml=python_junit.xml --cov-report=xml --cov-branch --cov-report term

lint:
python -m flake8 bt setup.py
python -m flake8 bt setup.py docs/source/conf.py

fix:
python -m black bt setup.py

python -m black bt setup.py docs/source/conf.py

dist:
python setup.py sdist
Expand All @@ -25,7 +27,7 @@ docs:
$(MAKE) -C docs/ html

pages:
- rm -rf $(TMPREPO)
rm -rf $(TMPREPO)
git clone -b gh-pages [email protected]:pmorissette/bt.git $(TMPREPO)
rm -rf $(TMPREPO)/*
cp -r docs/build/html/* $(TMPREPO)
Expand All @@ -36,21 +38,21 @@ pages:

serve:
cd docs/build/html; \
python -m SimpleHTTPServer 9087
python -m http.server 9087

build_dev:
- python setup.py build_ext --inplace
python setup.py build_ext --inplace

clean:
- rm -rf build
- rm -rf dist
- rm -rf bt.egg-info
- find . -name '*.so' -delete
- find . -name '*.c' -delete
rm -rf build
rm -rf dist
rm -rf bt.egg-info
find . -name '*.so' -delete
find . -name '*.c' -delete

klink:
git subtree pull --prefix=docs/source/_themes/klink --squash klink master

notebooks:
cd docs/source; \
ipython notebook --no-browser --ip=*
jupyter notebook --no-browser --ip=*
1 change: 1 addition & 0 deletions bt/algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,7 @@ def __call__(self, target):
v = c.notional_value
else:
v = c.value

# if non-zero and non-null, we need to close it out
if v != 0.0 and not np.isnan(v):
target.close(cname, update=False)
Expand Down
1 change: 0 additions & 1 deletion bt/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def __init__(
progress_bar=False,
additional_data=None,
):

if data.columns.duplicated().any():
cols = data.columns[data.columns.duplicated().tolist()].tolist()
raise Exception(
Expand Down
7 changes: 6 additions & 1 deletion bt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas as pd
from future.utils import iteritems


PAR = 100.0
TOL = 1e-16

Expand Down Expand Up @@ -590,7 +591,9 @@ def setup(self, universe, **kwargs):
self._paper = paper

# setup universe
funiverse = universe
# TODO: a copy is made here to avoid polluting the universes
# of substrategies. is this desired?
funiverse = universe.copy()

if self._universe_tickers:
# if we have universe_tickers defined, limit universe to
Expand Down Expand Up @@ -719,6 +722,7 @@ def update(self, date, data=None, inow=None):
# avoid useless update call
if c._issec and not c._needupdate:
continue

c.update(date, data, inow)
val += c.value
# Strategies always have positive notional value
Expand Down Expand Up @@ -1007,6 +1011,7 @@ def rebalance(self, weight, child, base=np.nan, update=True):
# allocate to child
# figure out weight delta
c = self.children[child]

if self.fixed_income:
# In fixed income strategies, the provided "base" value can be used
# to upscale/downscale the notional_value of the strategy, whereas
Expand Down
1 change: 1 addition & 0 deletions docs/source/Buy_and_hold.ipynb
Loading

0 comments on commit b930085

Please sign in to comment.