# 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:
```commandline
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:
```commandline
pip install backtest-pro[optional]
```
## Installation from source
To install **backtest-pro** from source, you can clone the repository and install it using pip:
```commandline
git clone https://github.com/anthol42/backtestPro.git
```
Move to the cloned repository:
```commandline
cd backtestPro
```
Then, you can install with the following command:
```commandline
pip install .
```
## Example
```python
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)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/anthol42/backtestPro",
"name": "backtest-pro",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "backtest-pro, backtestpro, backtest, pybacktest, py-backtest, backtesting, quant, finance, stocks, crypto, cryptocurrency, derivatives, trading, investing, financial, technical, fundamental, ai, machine, learning, neural, network, deep, reinforcement, algorithm, strategy, portfolio, optimization, risk, management",
"author": "Anthony Lavertu",
"author_email": "alavertu2@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/de/53/d813d3581baf8b51e95dde5cf948ccd963a7568d393d9f94805dbb2c4ced/backtest-pro-0.1.3.tar.gz",
"platform": null,
"description": "# Backtest-pro: feature rich backtesting framework\n\n## What it is?\n**backtest-pro** is a framework that provides a way to test complex strategies in an environment that is designed to \nlook as much as possible to the real world. This way, the historical results are more likely to reflect the\nreal world results. It is an **event-driven** backtesting framework that is designed to be as flexible as possible and\nas complete as possible. It supports **end-to-end** quant pipeline from data fetching to production release. \n**Also, it has the broader goal of becoming the most complete backtesting framework available for python finely tuned \nfor professional applications.**\n\n## Important notice\n**backtest-pro** is still in development and is not ready for production use. There may be bugs that could\nmake the results of the backtest invalid. Always double-check the results with your own code. If you find a bug, please\nopen an issue on the github page. The api might also change without notice.\n\n\n## Features\nHere are just a few of the features that **backtest-pro** offers:\n- **DataPiplines**\n - An easy to use data pipeline api that makes building a data pipeline a breeze.\n - A pipeline built with the api is easy to maintain and easy to understand.\n - Support caching for more efficient pipelines.\n- **Backtest**\n - Backtest with a single or with multiple assets simultaneously\n - Feed a moving window to the strategy\n - Multiple time resolution simultaneously\n - Take into account:\n - Trading fees\n - Margin rates\n - Margin calls\n - Stock splits\n - Dividends\n - Records a lot of metrics for easier analysis and debugging.\n- **Release**\n - Use the same code as used in the backtest in production.\n - Only a few lines of codes are necessary to build a production pipeline that can run on a server or locally.\n - Automatic reporting of the results using report builders. (Html, pdf)\n - Easy integration with other services such as api for algorithmic trading.\n\n## Installation\nTo install **backtest-pro**, you can use pip:\n```commandline\npip install backtest-pro\n```\nThere a few dependencies that are not installed by default. They are:\n- TA-Lib: A technical analysis library that is used to calculate technical indicators.\n- Plotly: A plotting library that is used to render charts in the production of reports.\n- WeasyPrint: A library that is used to convert html to pdf. It is used to render the reports in pdf format.\n- kaleido: An optional library of Plotly that is used to render the charts in the reports.\n- schedule: A library that is used to schedule the run of the strategy in production.\n- python-crontab: A library that is used to schedule the run of the strategy in production.\n\nTo install the dependencies, you can use the following command:\n```commandline\npip install backtest-pro[optional]\n```\n\n## Installation from source\nTo install **backtest-pro** from source, you can clone the repository and install it using pip:\n```commandline\ngit clone https://github.com/anthol42/backtestPro.git\n```\nMove to the cloned repository:\n```commandline\ncd backtestPro\n```\nThen, you can install with the following command:\n```commandline\npip install .\n```\n\n## Example\n```python\nfrom backtest import Strategy, Backtest\nfrom backtest.indicators import IndicatorSet, TA\nfrom backtest.data import FetchCharts, ToTSData, Cache, PadNan\nimport backtest.engine.functional as F\nfrom datetime import datetime\n\nclass MyStrategy(Strategy):\n def run(self, data, timestep):\n for ticker in data.main.tickers:\n chart = data.main[ticker].chart\n if len(chart) > 2 and F.crossover(chart[\"MACD\"], chart[\"MACD_SIGNAL\"]) and chart[\"MACD\"].iloc[-1] < 0:\n if ticker not in self.broker.portfolio.long:\n self.broker.buy_long(ticker, 500)\n if ticker in self.broker.portfolio.long and F.crossunder(chart[\"MACD\"], chart[\"MACD_SIGNAL\"]):\n self.broker.sell_long(ticker, 500)\n\n# The magnificent 7 tickers\nTICKERS = [\"META\", \"AMZN\", \"AAPL\", \"NVDA\", \"GOOGL\", \"MSFT\", \"TSLA\"]\ndata_pipeline = FetchCharts(TICKERS, auto_adjust=False) | PadNan() | ToTSData() | Cache()\nbt = Backtest(data_pipeline.get(datetime(2010, 1, 1), datetime(2020, 1, 1)),\n strategy=MyStrategy(),\n indicators=IndicatorSet(TA.MACD()))\nresults = bt.run()\nprint(results)\n\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "A feature-rich event driven backtesting framework",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/anthol42/backtestPro",
"Issues": "https://github.com/anthol42/backtestPro/issues"
},
"split_keywords": [
"backtest-pro",
" backtestpro",
" backtest",
" pybacktest",
" py-backtest",
" backtesting",
" quant",
" finance",
" stocks",
" crypto",
" cryptocurrency",
" derivatives",
" trading",
" investing",
" financial",
" technical",
" fundamental",
" ai",
" machine",
" learning",
" neural",
" network",
" deep",
" reinforcement",
" algorithm",
" strategy",
" portfolio",
" optimization",
" risk",
" management"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "de53d813d3581baf8b51e95dde5cf948ccd963a7568d393d9f94805dbb2c4ced",
"md5": "0a07ad4b5f6fb1de8f53a7ea1a9affba",
"sha256": "3b8dd9c0cff44dd38e93f37792a31c63735b573a1b0fa2f9ba4b2467c411cc92"
},
"downloads": -1,
"filename": "backtest-pro-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "0a07ad4b5f6fb1de8f53a7ea1a9affba",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 147590,
"upload_time": "2024-08-08T20:37:35",
"upload_time_iso_8601": "2024-08-08T20:37:35.129115Z",
"url": "https://files.pythonhosted.org/packages/de/53/d813d3581baf8b51e95dde5cf948ccd963a7568d393d9f94805dbb2c4ced/backtest-pro-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-08 20:37:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "anthol42",
"github_project": "backtestPro",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "pandas",
"specs": []
},
{
"name": "numpy",
"specs": []
},
{
"name": "matplotlib",
"specs": []
},
{
"name": "psutil",
"specs": []
},
{
"name": "py-cpuinfo",
"specs": []
},
{
"name": "mplfinance",
"specs": []
},
{
"name": "tqdm",
"specs": []
},
{
"name": "setuptools",
"specs": []
},
{
"name": "schedule",
"specs": []
},
{
"name": "plotly",
"specs": []
},
{
"name": "kaleido",
"specs": []
},
{
"name": "python-crontab",
"specs": []
},
{
"name": "pdoc3",
"specs": []
},
{
"name": "notebook",
"specs": []
},
{
"name": "nbconvert",
"specs": []
}
],
"lcname": "backtest-pro"
}