# Introduction
**fastbt** is a simple and dirty way to do backtests based on end of day data, especially for day trading.
The main purpose is to provide a simple framework to weed out bad strategies so that you could test and improve your better strategies further.
It is based on the assumption that you enter into a position based on some pre-defined rules for a defined period and exit either at the end of the period or when stop loss is triggered. See the [rationale](https://github.com/uberdeveloper/fastbt/blob/master/docs/rationale.md) for this approach and the built-in assumptions. _fastbt is rule-based and not event-based._
If your strategy gets you good results, then check them with a full featured backtesting framework such as [zipline](http://www.zipline.io/) or [backtrader](https://www.backtrader.com/) to verify your results.
If your strategy fails, then it would most probably fail in other environments.
This is **alpha**
Most of the modules are stand alone and you could use them as a single file. See embedding for more details
# Features
- Create your strategies in Microsoft Excel
- Backtest as functions so you can parallelize
- Try different simulations
- Run from your own datasource or a database connection.
- Run backtest based on rules
- Add any column you want to your datasource as formulas
# Installation
fastbt requires python **>=3.6** and can be installed via pip
```
pip install fastbt
```
# Quickstart
Fastbt assumes your data have the following columns (rename them in case of other names)
- timestamp
- symbol
- open
- high
- low
- close
- volume
```python
from fastbt.rapid import *
backtest(data=data)
```
would return a dataframe with all the trades.
And if you want to see some metrics
```python
metrics(backtest(data=data))
```
You now ran a backtest without a strategy! By default, the strategy buys the top 5 stocks with the lowest price at open price on each period and sells them at the close price at the end of the period.
You can either specify the strategy by way of rules (the recommended way) or create your strategy as a function in python and pass it as a parameter
```python
backtest(data=data, strategy=strategy)
```
If you want to connect to a database, then
```python
from sqlalchemy import create_engine
engine = create_engine('sqlite:///data.db')
backtest(connection=engine, tablename='data')
```
And to SELL instead of BUY
```python
backtest(data=data, order='S')
```
Let's implement a simple strategy.
> **BUY** the top 5 stocks with highest last week returns
Assuming we have a **weeklyret** column,
```python
backtest(data=data, order='B', sort_by='weeklyret', sort_mode=False)
```
We used sort_mode=False to sort them in descending order.
If you want to test this strategy on a weekly basis, just pass a dataframe with weekly frequency.
See the Introduction notebook in the examples directory for an in depth introduction.
## Embedding
Since fastbt is a thin wrapper around existing packages, the following files can be used as standalone without installing the fastbt package
- datasource
- utils
- loaders
Copy these files and just use them in your own modules.
=========
History
=========
v0.6.0
------
* New methods added to `TradeBook` object
* mtm - to calculate mtm for open positions
* clear - to clear the existing entries
* helper attributes for positions
* `order_fill_price` method added to utils to simulate order quantity
v0.5.1
------
* Simple bug fixes added
v0.5.0
------
* `OptionExpiry` class added to calculate option payoffs based on expiry
v0.4.0
-------
* Brokers module deprecation warning added
* Options module revamped
v0.3.0 (2019-03-15)
--------------------
* More helper functions added to utils
* Tradebook class enhanced
* A Meta class added for event based simulation
v0.2.0 (2018-12-26)
--------------------
* Backtest from different formats added
* Rolling function added
v0.1.0. (2018-10-13)
----------------------
* First release on PyPI
Raw data
{
"_id": null,
"home_page": "https://github.com/uberdeveloper/fastbt",
"name": "fastbt",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "fastbt,backtesting,algorithmic trading,quantitative finance,research,finance",
"author": "UM",
"author_email": "uberdeveloper001@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ce/b0/ce9934665449f659cc0bf77a9ac0dab2ff44ac4f5d148a7771b21692bbf4/fastbt-0.6.0.tar.gz",
"platform": null,
"description": "# Introduction\n\n**fastbt** is a simple and dirty way to do backtests based on end of day data, especially for day trading.\nThe main purpose is to provide a simple framework to weed out bad strategies so that you could test and improve your better strategies further.\n\nIt is based on the assumption that you enter into a position based on some pre-defined rules for a defined period and exit either at the end of the period or when stop loss is triggered. See the [rationale](https://github.com/uberdeveloper/fastbt/blob/master/docs/rationale.md) for this approach and the built-in assumptions. _fastbt is rule-based and not event-based._\n\nIf your strategy gets you good results, then check them with a full featured backtesting framework such as [zipline](http://www.zipline.io/) or [backtrader](https://www.backtrader.com/) to verify your results.\nIf your strategy fails, then it would most probably fail in other environments.\n\nThis is **alpha**\n\nMost of the modules are stand alone and you could use them as a single file. See embedding for more details\n\n# Features\n\n- Create your strategies in Microsoft Excel\n- Backtest as functions so you can parallelize\n- Try different simulations\n- Run from your own datasource or a database connection.\n- Run backtest based on rules\n- Add any column you want to your datasource as formulas\n\n# Installation\n\nfastbt requires python **>=3.6** and can be installed via pip\n\n```\npip install fastbt\n```\n\n# Quickstart\n\nFastbt assumes your data have the following columns (rename them in case of other names)\n\n- timestamp\n- symbol\n- open\n- high\n- low\n- close\n- volume\n\n```python\nfrom fastbt.rapid import *\nbacktest(data=data)\n```\n\nwould return a dataframe with all the trades.\n\nAnd if you want to see some metrics\n\n```python\nmetrics(backtest(data=data))\n```\n\nYou now ran a backtest without a strategy! By default, the strategy buys the top 5 stocks with the lowest price at open price on each period and sells them at the close price at the end of the period.\n\nYou can either specify the strategy by way of rules (the recommended way) or create your strategy as a function in python and pass it as a parameter\n\n```python\nbacktest(data=data, strategy=strategy)\n```\n\nIf you want to connect to a database, then\n\n```python\nfrom sqlalchemy import create_engine\nengine = create_engine('sqlite:///data.db')\nbacktest(connection=engine, tablename='data')\n```\n\nAnd to SELL instead of BUY\n\n```python\nbacktest(data=data, order='S')\n```\n\nLet's implement a simple strategy.\n\n> **BUY** the top 5 stocks with highest last week returns\n\nAssuming we have a **weeklyret** column,\n\n```python\nbacktest(data=data, order='B', sort_by='weeklyret', sort_mode=False)\n```\n\nWe used sort_mode=False to sort them in descending order.\n\n If you want to test this strategy on a weekly basis, just pass a dataframe with weekly frequency.\n\nSee the Introduction notebook in the examples directory for an in depth introduction.\n\n## Embedding\n\nSince fastbt is a thin wrapper around existing packages, the following files can be used as standalone without installing the fastbt package\n\n- datasource\n- utils\n- loaders\n\nCopy these files and just use them in your own modules.\n\n=========\nHistory\n=========\nv0.6.0\n------\n* New methods added to `TradeBook` object\n * mtm - to calculate mtm for open positions\n * clear - to clear the existing entries\n * helper attributes for positions\n* `order_fill_price` method added to utils to simulate order quantity\n\nv0.5.1\n------\n* Simple bug fixes added\n\nv0.5.0\n------\n* `OptionExpiry` class added to calculate option payoffs based on expiry\n\nv0.4.0\n-------\n* Brokers module deprecation warning added\n* Options module revamped\n\nv0.3.0 (2019-03-15)\n--------------------\n* More helper functions added to utils\n* Tradebook class enhanced\n* A Meta class added for event based simulation\n\nv0.2.0 (2018-12-26)\n--------------------\n* Backtest from different formats added\n* Rolling function added\n\n\nv0.1.0. (2018-10-13)\n----------------------\n\n* First release on PyPI\n",
"bugtrack_url": null,
"license": "MIT license",
"summary": "A simple framework for fast and dirty backtesting",
"version": "0.6.0",
"project_urls": {
"Homepage": "https://github.com/uberdeveloper/fastbt"
},
"split_keywords": [
"fastbt",
"backtesting",
"algorithmic trading",
"quantitative finance",
"research",
"finance"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "01e4950fdb849addda44ac3f3092fe7207d1d36baed6d9c2f7619d1e1fbcdb40",
"md5": "114d85566c4e528519102babb8d632a3",
"sha256": "7ee8d1ca21cab5753727916d420bc074e7dd6135ea9e78be34ac2ac6c02f59f3"
},
"downloads": -1,
"filename": "fastbt-0.6.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "114d85566c4e528519102babb8d632a3",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 4042800,
"upload_time": "2023-06-12T16:44:08",
"upload_time_iso_8601": "2023-06-12T16:44:08.488488Z",
"url": "https://files.pythonhosted.org/packages/01/e4/950fdb849addda44ac3f3092fe7207d1d36baed6d9c2f7619d1e1fbcdb40/fastbt-0.6.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ceb0ce9934665449f659cc0bf77a9ac0dab2ff44ac4f5d148a7771b21692bbf4",
"md5": "7ddb158ebf9df6569c2df45c26d01374",
"sha256": "ba9b8a2daef6e163c2370162135cf3627fd35d86853a667ce18e45a42f54c8b8"
},
"downloads": -1,
"filename": "fastbt-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "7ddb158ebf9df6569c2df45c26d01374",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4705975,
"upload_time": "2023-06-12T16:44:22",
"upload_time_iso_8601": "2023-06-12T16:44:22.176482Z",
"url": "https://files.pythonhosted.org/packages/ce/b0/ce9934665449f659cc0bf77a9ac0dab2ff44ac4f5d148a7771b21692bbf4/fastbt-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-12 16:44:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "uberdeveloper",
"github_project": "fastbt",
"travis_ci": true,
"coveralls": true,
"github_actions": false,
"tox": true,
"lcname": "fastbt"
}