Skip to content

Commit b930085

Browse files
committed
WIP docs update, critical bugfix for pandas upgrade, move to pytest, drop older deps, include example notebooks in docs
1 parent 6a1253c commit b930085

File tree

112 files changed

+8788
-4972
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+8788
-4972
lines changed

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/build.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ jobs:
1717

1818
strategy:
1919
matrix:
20-
python-version: [3.7, 3.9]
20+
python-version: [3.9]
2121
os: [ubuntu-latest, macos-latest, windows-latest]
22-
event-name: [push]
2322

2423
steps:
2524
- uses: actions/checkout@v2
@@ -32,21 +31,19 @@ jobs:
3231

3332
- name: Install dependencies
3433
run: |
35-
python -m pip install -e .[dev]
34+
make develop
3635
python -m pip install -U wheel twine setuptools
3736
3837
- name: Lint
3938
run: |
40-
python -m flake8 bt setup.py
39+
make lint
4140
4241
- name: Test
4342
run: |
44-
python -m nose --with-coverage --cover-package bt
45-
if: ${{ github.event_name == matrix.event-name }}
43+
make test
4644
4745
- name: Coverage
4846
uses: codecov/codecov-action@v2
49-
if: ${{ github.event_name == matrix.event-name }}
5047

5148
- name: Package and check
5249
run: |

.github/workflows/deploy.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ jobs:
2424

2525
- name: Install dependencies
2626
run: |
27-
python -m pip install -e .[dev]
27+
make develop
2828
python -m pip install -U wheel twine setuptools
2929
3030
- name: Lint
3131
run: |
32-
python -m flake8 bt setup.py
32+
make lint
3333
3434
- name: Test
3535
run: |
36-
python -m nose --with-coverage --cover-package bt
36+
make test
3737
3838
- name: Package and check
3939
run: |

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ htmlcov/
3535
.cache
3636
nosetests.xml
3737
coverage.xml
38+
python_junit.xml
3839

3940
# Translations
4041
*.mo
@@ -70,3 +71,5 @@ docs/source/.ipynb_checkpoints/
7071
# macOS
7172
.DS_Store
7273

74+
# jupyter
75+
.ipynb_checkpoints

Makefile

+16-14
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ TMPREPO=/tmp/docs/bt
22

33
default: build_dev
44

5-
.PHONY: dist upload docs pages serve klink notebooks test lint fix
5+
.PHONY: dist upload docs pages serve klink notebooks test lint fix develop
6+
7+
develop:
8+
python -m pip install -e .[dev]
69

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

1013
lint:
11-
python -m flake8 bt setup.py
14+
python -m flake8 bt setup.py docs/source/conf.py
1215

1316
fix:
14-
python -m black bt setup.py
15-
17+
python -m black bt setup.py docs/source/conf.py
1618

1719
dist:
1820
python setup.py sdist
@@ -25,7 +27,7 @@ docs:
2527
$(MAKE) -C docs/ html
2628

2729
pages:
28-
- rm -rf $(TMPREPO)
30+
rm -rf $(TMPREPO)
2931
git clone -b gh-pages [email protected]:pmorissette/bt.git $(TMPREPO)
3032
rm -rf $(TMPREPO)/*
3133
cp -r docs/build/html/* $(TMPREPO)
@@ -36,21 +38,21 @@ pages:
3638

3739
serve:
3840
cd docs/build/html; \
39-
python -m SimpleHTTPServer 9087
41+
python -m http.server 9087
4042

4143
build_dev:
42-
- python setup.py build_ext --inplace
44+
python setup.py build_ext --inplace
4345

4446
clean:
45-
- rm -rf build
46-
- rm -rf dist
47-
- rm -rf bt.egg-info
48-
- find . -name '*.so' -delete
49-
- find . -name '*.c' -delete
47+
rm -rf build
48+
rm -rf dist
49+
rm -rf bt.egg-info
50+
find . -name '*.so' -delete
51+
find . -name '*.c' -delete
5052

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

5456
notebooks:
5557
cd docs/source; \
56-
ipython notebook --no-browser --ip=*
58+
jupyter notebook --no-browser --ip=*

bt/algos.py

+1
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,7 @@ def __call__(self, target):
17981798
v = c.notional_value
17991799
else:
18001800
v = c.value
1801+
18011802
# if non-zero and non-null, we need to close it out
18021803
if v != 0.0 and not np.isnan(v):
18031804
target.close(cname, update=False)

bt/backtest.py

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ def __init__(
148148
progress_bar=False,
149149
additional_data=None,
150150
):
151-
152151
if data.columns.duplicated().any():
153152
cols = data.columns[data.columns.duplicated().tolist()].tolist()
154153
raise Exception(

bt/core.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pandas as pd
1212
from future.utils import iteritems
1313

14+
1415
PAR = 100.0
1516
TOL = 1e-16
1617

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

592593
# setup universe
593-
funiverse = universe
594+
# TODO: a copy is made here to avoid polluting the universes
595+
# of substrategies. is this desired?
596+
funiverse = universe.copy()
594597

595598
if self._universe_tickers:
596599
# if we have universe_tickers defined, limit universe to
@@ -719,6 +722,7 @@ def update(self, date, data=None, inow=None):
719722
# avoid useless update call
720723
if c._issec and not c._needupdate:
721724
continue
725+
722726
c.update(date, data, inow)
723727
val += c.value
724728
# Strategies always have positive notional value
@@ -1007,6 +1011,7 @@ def rebalance(self, weight, child, base=np.nan, update=True):
10071011
# allocate to child
10081012
# figure out weight delta
10091013
c = self.children[child]
1014+
10101015
if self.fixed_income:
10111016
# In fixed income strategies, the provided "base" value can be used
10121017
# to upscale/downscale the notional_value of the strategy, whereas

docs/source/Buy_and_hold.ipynb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../examples/buy_and_hold.ipynb

0 commit comments

Comments
 (0)