Skip to content

Commit 741a6fe

Browse files
authored
Merge branch 'master' into master
2 parents e5583fc + 6ac0a21 commit 741a6fe

30 files changed

+704
-451
lines changed

.coveragerc

Lines changed: 0 additions & 17 deletions
This file was deleted.

.flake8

Lines changed: 0 additions & 6 deletions
This file was deleted.

.github/issue_template.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@
1717
2.
1818
3.
1919

20+
```python
21+
22+
python code goes here
23+
24+
```
25+
2026
### Additional info
2127

2228
<!-- screenshots, code snippets, ... -->
2329

2430
- Backtesting version: 0.?.? <!-- From backtesting.__version__ -->
31+
- `bokeh.__version__`:
32+
- OS:

.github/workflows/ci.yml

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,49 @@ jobs:
88
build:
99
name: Build
1010
runs-on: ubuntu-18.04
11-
1211
strategy:
1312
matrix:
14-
python-version: [3.6, 3.7]
13+
python-version: [3.7, '3.10']
1514
include:
16-
- python-version: 3.8
15+
- python-version: 3.9
1716
test-type: lint
18-
- python-version: 3.8
17+
- python-version: 3.9
1918
test-type: docs
2019

2120
steps:
22-
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
21+
- uses: actions/setup-python@v4
2422
with:
2523
python-version: ${{ matrix.python-version }}
26-
27-
- uses: actions/cache@v2
28-
name: Set up caches
24+
- uses: actions/cache@v3
2925
with:
3026
path: ~/.cache/pip
3127
key: ${{ runner.os }}-py${{ matrix.python-version }}
32-
33-
- name: Checkout repo
34-
uses: actions/checkout@v2
28+
- uses: actions/checkout@v3
3529
with:
3630
fetch-depth: 3
3731
- name: Fetch tags
3832
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
3933

40-
- name: Install dependencies
41-
run: |
42-
pip install -U pip setuptools wheel
43-
pip install -U --pre .[test]
44-
45-
- name: Install lint dependencies
46-
if: matrix.test-type == 'lint'
47-
run: pip install -U .[dev]
48-
49-
- name: Install docs dependencies
50-
if: matrix.test-type == 'docs'
51-
run: pip install -e .[doc,test] # -e provides _version.py for pdoc
52-
53-
- name: Test w/ Coverage, Lint
54-
if: matrix.test-type == 'lint'
34+
- run: pip install -U pip setuptools wheel
35+
- if: matrix.test-type == 'lint'
36+
run: pip install -U --pre bokeh pandas 'numpy<1.24' && pip install -U .[dev]
37+
- if: matrix.test-type == 'docs'
38+
run: pip install -e .[doc] # -e provides _version.py for pdoc
39+
- run: pip install -U .[test]
40+
41+
- if: matrix.test-type == 'lint'
42+
run: ruff backtesting
43+
- if: matrix.test-type == 'lint'
44+
run: mypy backtesting
45+
- if: matrix.test-type == 'lint'
5546
env: { BOKEH_BROWSER: none }
56-
run: |
57-
flake8
58-
mypy backtesting
59-
time catchsegv coverage run -m backtesting.test
60-
bash <(curl -s https://codecov.io/bash)
47+
run: time catchsegv coverage run -m backtesting.test
48+
- if: matrix.test-type == 'lint'
49+
run: bash <(curl -s https://codecov.io/bash)
6150

62-
- name: Test
63-
if: '! matrix.test-type'
51+
- if: '! matrix.test-type'
6452
env: { BOKEH_BROWSER: none }
6553
run: time catchsegv python -m backtesting.test
6654

67-
- name: Test docs
68-
if: matrix.test-type == 'docs'
55+
- if: matrix.test-type == 'docs'
6956
run: time catchsegv doc/build.sh

CHANGELOG.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,35 @@ What's New
33

44
These were the major changes contributing to each release:
55

6-
76
### 0.x.x
87

98

9+
### 0.3.3
10+
(2021-12-13)
11+
12+
* Fix random generation with recent NumPy.
13+
* Fix Pandas deprecation warnings.
14+
* Replace Bokeh 3.0 deprecations.
15+
16+
17+
### 0.3.2
18+
(2021-08-03)
19+
20+
* New strategy performance method [`backtesting.lib.compute_stats`](https://kernc.github.io/backtesting.py/doc/backtesting/lib.html#backtesting.lib.compute_stats) (#281)
21+
* Improve plotting speed (#329) and optimization performance (#295) on large datasets.
22+
* Commission constraints now allow for market-maker's rebates.
23+
* [`Backtest.plot`](https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Backtest.plot)
24+
now returns the bokeh figure object for further processing.
25+
* Other small bugs and fixes.
26+
27+
28+
### 0.3.1
29+
(2021-01-25)
30+
31+
* Avoid some `pandas.Index` deprecations
32+
* Fix `Backtest.plot(show_legend=False)` for recent Bokeh
33+
34+
1035
### 0.3.0
1136
(2020-11-24)
1237

CONTRIBUTING.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ have been fixed already.
1010
To have your issue dealt with promptly, it's best to construct a
1111
[minimal working example] that exposes the issue in a clear and
1212
reproducible manner. Make sure to understand
13-
[how to report bugs effectively][bugs].
13+
[how to report bugs effectively][bugs] and how to
14+
[craft useful bug reports][bugs2] in Python.
1415

15-
Show verbatim code in [fenced code blocks], and use the
16-
preview function!
16+
In case of bugs, please submit full tracebacks
17+
18+
Wrap verbatim example code/traceback in [fenced code blocks],
19+
and use the preview function!
20+
21+
Many thanks from the maintainers!
1722

1823
[minimal working example]: https://en.wikipedia.org/wiki/Minimal_working_example
1924
[bugs]: https://www.chiark.greenend.org.uk/~sgtatham/bugs.html
25+
[bugs2]: https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports
2026
[fenced code blocks]: https://www.markdownguide.org/extended-syntax/#fenced-code-blocks
2127

2228

@@ -62,4 +68,4 @@ Please use explicit commit messages. See [NumPy's development workflow]
6268
for inspiration.
6369

6470
[code-review]: https://mtlynch.io/code-review-love/
65-
[NumPy's development workflow]: https://docs.scipy.org/doc/numpy/dev/gitwash/development_workflow.html
71+
[NumPy's development workflow]: https://numpy.org/doc/stable/dev/development_workflow.html

README.md

Lines changed: 16 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ Backtesting.py
1010

1111
Backtest trading strategies with Python.
1212

13-
[**Project website**][website]
13+
[**Project website**](https://kernc.github.io/backtesting.py) + [Documentation]
1414

15-
[Documentation]
16-
17-
[website]: https://kernc.github.io/backtesting.py/
1815
[Documentation]: https://kernc.github.io/backtesting.py/doc/backtesting/
1916

2017

@@ -82,6 +79,7 @@ Avg. Trade Duration 32 days 00:00:00
8279
Profit Factor 2.13
8380
Expectancy [%] 6.91
8481
SQN 1.78
82+
Kelly Criterion 0.6134
8583
_strategy SmaCross(n1=10, n2=20)
8684
_equity_curve Equ...
8785
_trades Size EntryB...
@@ -91,6 +89,7 @@ dtype: object
9189

9290
Find more usage examples in the [documentation].
9391

92+
9493
Features
9594
--------
9695
* Simple, well-documented API
@@ -102,101 +101,20 @@ Features
102101
* Detailed results
103102
* Interactive visualizations
104103

104+
![xkcd.com/1570](https://imgs.xkcd.com/comics/engineer_syllogism.png)
105+
106+
107+
Bugs
108+
----
109+
Before reporting bugs or posting to the
110+
[discussion board](https://github.com/kernc/backtesting.py/discussions),
111+
please read [contributing guidelines](CONTRIBUTING.md), particularly the section
112+
about crafting useful bug reports and ```` ``` ````-fencing your code. We thank you!
105113

106-
-------------------------------------------------
107114

108115
Alternatives
109116
------------
110-
The thing with backtesting is, unless you dug into the dirty details yourself,
111-
you can't rely on execution correctness, and you risk losing your house.
112-
In addition, everyone has their own preconveived ideas about how a mechanical
113-
trading strategy should be conducted, so everyone (and their brother)
114-
just rolls their own backtesting frameworks.
115-
116-
If after reviewing the docs and exmples perchance you find
117-
[_Backtesting.py_][website] not your cup of tea,
118-
kindly have a look at some similar alternative Python backtesting frameworks:
119-
120-
- [bt](http://pmorissette.github.io/bt/) -
121-
a framework based on reusable and flexible blocks of
122-
strategy logic that support multiple instruments and
123-
output detailed statistics and useful charts.
124-
- [vectorbt](https://polakowo.io/vectorbt/) -
125-
a pandas-based library for quickly analyzing trading strategies at scale.
126-
- [Backtrader](https://www.backtrader.com/) -
127-
a pure-python feature-rich framework for backtesting
128-
and live algotrading with a few brokers.
129-
- [PyAlgoTrade](https://gbeced.github.io/pyalgotrade/) -
130-
event-driven algorithmic trading library with focus on
131-
backtesting and support for live trading.
132-
- [Zipline](https://www.zipline.io/) -
133-
the backtesting and live-trading engine powering Quantopian — the
134-
community-centered, hosted platform for building and executing strategies.
135-
- [Pinkfish](http://fja05680.github.io/pinkfish/) -
136-
a lightweight backtester for intraday strategies on daily data.
137-
- [finmarketpy](https://github.com/cuemacro/finmarketpy) -
138-
a library for analyzing financial market data.
139-
- [QuantStart QSTrader](https://github.com/mhallsmoore/qstrader/) -
140-
a modular schedule-driven backtesting framework for long-short equities
141-
and ETF-based systematic trading strategies.
142-
- [pysystemtrade](https://github.com/robcarver17/pysystemtrade) -
143-
the open-source version of Robert Carver's backtesting engine that
144-
implements systems according to his book _Systematic Trading:
145-
A unique new method for designing trading and investing systems_.
146-
- [QTPyLib](https://github.com/ranaroussi/qtpylib) -
147-
a versatile, event-driven algorithmic trading library.
148-
- [Gemini](https://github.com/anfederico/Gemini) -
149-
a backtester namely focusing on cryptocurrency markets.
150-
- [Quantdom](https://github.com/constverum/Quantdom) -
151-
a Qt-based framework that lets you focus on modeling financial strategies,
152-
portfolio management, and analyzing backtests.
153-
- [Clairvoyant](https://github.com/anfederico/Clairvoyant) -
154-
software for identifying and monitoring social / historical cues
155-
for short-term stock movement.
156-
- [optopsy](https://github.com/michaelchu/optopsy) -
157-
a nimble backtesting library for options trading.
158-
- [RQalpha](https://github.com/ricequant/rqalpha) -
159-
a complete solution for programmatic traders from data acquisition,
160-
algorithmic trading, backtesting, real-time simulation, live trading
161-
to mere data analysis. Documentation in Chinese.
162-
- [zvt](https://github.com/zvtvz/zvt) -
163-
a quant trading platform which includes data recorder, factor calculation,
164-
stock picking, backtesting, and unified visualization. Documentation in Chinese.
165-
- [AwesomeQuant](https://github.com/wilsonfreitas/awesome-quant#trading--backtesting) -
166-
A somewhat curated list of libraries, packages, and resources for quants.
167-
168-
#### Obsolete / Unmaintained
169-
170-
The following projects are mainly old, stale, incomplete, incompatible,
171-
abandoned, and here for posterity reference only:
172-
173-
- [AlephNull](https://github.com/CarterBain/AlephNull) -
174-
extends the features of Zipline, for use within an institutional environment.
175-
- [ProfitPy](https://code.google.com/p/profitpy/) -
176-
a set of libraries and tools for the development, testing, and execution of
177-
automated stock trading systems.
178-
- [prophet](https://github.com/Emsu/prophet) -
179-
a microframework for financial markets, focusing on modeling
180-
strategies and portfolio management.
181-
- [pybacktest](https://github.com/ematvey/pybacktest) -
182-
a vectorized pandas-based backtesting framework,
183-
designed to make backtesting compact, simple and fast.
184-
- [quant](https://github.com/maihde/quant) -
185-
a technical analysis tool for trading strategies with a particularily
186-
simplistic view of the market.
187-
- [QuantSoftware Toolkit](https://github.com/QuantSoftware/QuantSoftwareToolkit) -
188-
a toolkit by the guys that soon after went to form Lucena Research.
189-
- [QuantStart QSForex](https://github.com/mhallsmoore/qsforex) -
190-
an event-driven backtesting and live-trading platform for use in
191-
the foreign exchange markets,
192-
- [tia: Toolkit for integration and analysis](https://github.com/PaulMest/tia/) -
193-
a toolkit providing Bloomberg data access, PDF generation,
194-
technical analysis and backtesting functionality.
195-
- [TradingWithPython](https://github.com/sjev/trading-with-python) -
196-
boiler-plate code for the (no longer active) course _Trading With Python_.
197-
- [Ultra-Finance](https://github.com/panpanpandas/ultrafinance) -
198-
real-time financial data collection, analyzing and backtesting trading strategies.
199-
- [visualize-wealth](https://github.com/benjaminmgross/visualize-wealth) -
200-
a library to construct, backtest, analyze, and evaluate portfolios
201-
and their benchmarks, with comprehensive documentation illustrating
202-
all underlying methodologies and statistics.
117+
See [alternatives.md] for a list of alternative Python
118+
backtesting frameworks and related packages.
119+
120+
[alternatives.md]: https://github.com/kernc/backtesting.py/blob/master/doc/alternatives.md

backtesting/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"""
2+
3+
![xkcd.com/1570](https://imgs.xkcd.com/comics/engineer_syllogism.png)
4+
25
## Manuals
36
47
* [**Quick Start User Guide**](../examples/Quick Start User Guide.html)
@@ -12,7 +15,7 @@
1215
1316
These tutorials are also available as live Jupyter notebooks:
1417
[![Binder](https://mybinder.org/badge_logo.svg)][binder]
15-
[![Google Colab](https://colab.research.google.com/assets/colab-badge.svg)][colab]
18+
[![Google Colab](https://colab.research.google.com/assets/colab-badge.png)][colab]
1619
<br>In Colab, you might have to `!pip install backtesting`.
1720
1821
[binder]: \
@@ -50,10 +53,10 @@
5053
# API Reference Documentation
5154
"""
5255
try:
53-
from ._version import version as __version__ # noqa: F401
56+
from ._version import version as __version__
5457
except ImportError:
5558
__version__ = '?.?.?' # Package not installed
5659

57-
from .backtesting import Backtest, Strategy # noqa: F401
5860
from . import lib # noqa: F401
5961
from ._plotting import set_bokeh_output # noqa: F401
62+
from .backtesting import Backtest, Strategy # noqa: F401

0 commit comments

Comments
 (0)