Backtest-pro: feature rich backtesting framework
What it is?
backtest-pro is a framework that provides a way to test complex strategies in an environment that is designed to
look as much as possible to the real world. This way, the historical results are more likely to reflect the
real world results. It is an event-driven backtesting framework that is designed to be as flexible as possible and
as complete as possible. It supports end-to-end quant pipeline from data fetching to production release.
Also, it has the broader goal of becoming the most complete backtesting framework available for python finely tuned
for professional applications.
Important notice
backtest-pro is still in development and is not ready for production use. There may be bugs that could make the results of the backtest invalid. Always double-check the results with your own code. If you find a bug, please open an issue on the github page. The api might also change without notice.
Features
Here are just a few of the features that backtest-pro offers:
- DataPiplines
- An easy to use data pipeline api that makes building a data pipeline a breeze.
- A pipeline built with the api is easy to maintain and easy to understand.
- Support caching for more efficient pipelines.
- Backtest
- Backtest with a single or with multiple assets simultaneously
- Feed a moving window to the strategy
- Multiple time resolution simultaneously
- Take into account:
- Trading fees
- Margin rates
- Margin calls
- Stock splits
- Dividends
- Records a lot of metrics for easier analysis and debugging.
- Release
- Use the same code as used in the backtest in production.
- Only a few lines of codes are necessary to build a production pipeline that can run on a server or locally.
- Automatic reporting of the results using report builders. (Html, pdf)
- Easy integration with other services such as api for algorithmic trading.
Installation
To install backtest-pro, you can use pip:
pip install backtest-pro
There a few dependencies that are not installed by default. They are:
- TA-Lib: A technical analysis library that is used to calculate technical indicators.
- Plotly: A plotting library that is used to render charts in the production of reports.
- WeasyPrint: A library that is used to convert html to pdf. It is used to render the reports in pdf format.
- kaleido: An optional library of Plotly that is used to render the charts in the reports.
- schedule: A library that is used to schedule the run of the strategy in production.
- python-crontab: A library that is used to schedule the run of the strategy in production.
To install the dependencies, you can use the following command:
pip install backtest-pro[optional]
Installation from source
To install backtest-pro from source, you can clone the repository and install it using pip:
git clone https://github.com/anthol42/backtestPro.git
Move to the cloned repository:
cd backtestPro
Then, you can install with the following command:
pip install .
Example
from backtest import Strategy, Backtest
from backtest.indicators import IndicatorSet, TA
from backtest.data import FetchCharts, ToTSData, Cache, PadNan
import backtest.engine.functional as F
from datetime import datetime
class MyStrategy(Strategy):
def run(self, data, timestep):
for ticker in data.main.tickers:
chart = data.main[ticker].chart
if len(chart) > 2 and F.crossover(chart["MACD"], chart["MACD_SIGNAL"]) and chart["MACD"].iloc[-1] < 0:
if ticker not in self.broker.portfolio.long:
self.broker.buy_long(ticker, 500)
if ticker in self.broker.portfolio.long and F.crossunder(chart["MACD"], chart["MACD_SIGNAL"]):
self.broker.sell_long(ticker, 500)
# The magnificent 7 tickers
TICKERS = ["META", "AMZN", "AAPL", "NVDA", "GOOGL", "MSFT", "TSLA"]
data_pipeline = FetchCharts(TICKERS, auto_adjust=False) | PadNan() | ToTSData() | Cache()
bt = Backtest(data_pipeline.get(datetime(2010, 1, 1), datetime(2020, 1, 1)),
strategy=MyStrategy(),
indicators=IndicatorSet(TA.MACD()))
results = bt.run()
print(results)
Metadata
Release files for backtest-pro 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| backtest-pro-0.1.4.tar.gz | 147.6 kB | Without provenance | Details |
Release files / backtest-pro-0.1.4.tar.gz
| Download URL | backtest-pro-0.1.4.tar.gz |
|---|---|
| Size | 147.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d66c9ab0e0808643c0d604ed4dce9d4ee9bf048b9031ee183433eda69616f805
|
|
BLAKE2b-256 checksum How to use checksums |
474727c3e12e4239be39c14fa4f2ce0fcf8bed4273b3c3527070919e4823f5a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for backtest-pro 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.