btester


Namebtester JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/pawelkn/btester
SummaryPython framework optimized for running backtests on multiple assetss
upload_time2024-01-16 07:57:25
maintainer
docs_urlNone
authorPaweł Knioła
requires_python>=3.7
licenseMIT License Copyright (c) 2024 Paweł Knioła Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords python python3 quantitative analysis backtesting portfolio parallel algorithmic trading
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # btester -   Trading Strategy Backtesting Framework

[![Test btester](https://github.com/pawelkn/btester/actions/workflows/test-btester.yml/badge.svg)](https://github.com/pawelkn/btester/actions/workflows/test-btester.yml) [![PyPi](https://img.shields.io/pypi/v/btester.svg)](https://pypi.python.org/pypi/btester/) [![Downloads](https://img.shields.io/pypi/dm/btester)](https://pypi.python.org/pypi/btester/) [![Codecov](https://codecov.io/gh/pawelkn/btester/branch/master/graph/badge.svg)](https://codecov.io/gh/pawelkn/btester/)

`btester` is a Python framework optimized for running backtests on multiple assets and supports full portfolio backtesting. It provides tools for backtesting trading strategies based on historical market data. The framework includes classes for managing financial positions, completed trades, and a flexible abstract base class for implementing custom trading strategies.

## Installation

You can install `btester` using pip. Simply run the following command:

```bash
pip install btester
```

## Usage

1. Define your custom trading strategy by creating a class that inherits from the `Strategy` abstract class.

2. Implement the required methods in your custom strategy: `init` for initialization and `next` for the core strategy logic.

3. Instantiate the `Backtest` class with your custom strategy, historical market data, and other parameters.

4. Run the backtest using the `run` method, which returns a `Result` object containing backtest results.

## Example Usage

```python
# Example usage of the btester
from btester import Strategy, Backtest
import pandas as pd

# Define a custom strategy by inheriting from the abstract Strategy class
class MyStrategy(Strategy):
    def init(self):
        # Custom initialization logic for the strategy
        pass

    def next(self, i: int, record: Dict[Hashable, Any]):
        # Custom strategy logic for each time step
        pass

# Load historical market data
data = pd.read_csv('historical_data.csv', parse_dates=['Date'])
data.set_index('Date', inplace=True)

# Initialize and run the backtest
backtest = Backtest(strategy=MyStrategy, data=data, cash=10000, commission=0.01)
result = backtest.run()

# Access backtest results
returns_series = result.returns
completed_trades = result.trades
remaining_positions = result.open_positions
```

## Examples

Check out the examples in the `examples` directory for additional use cases and demonstrations. The examples cover various scenarios and strategies to help you understand the versatility of the `btester`.

- [Example 1: Multiple Assets Breakout Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/multiple-assets-brakeout.ipynb)
- [Example 2: Multiple Assets Moving Average Crossover Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/multiple-assets-ma-crossover.ipynb)
- [Example 3: Single Asset Breakout Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/single-asset-brakeout.ipynb)
- [Example 4: Single Asset Moving Average Crossover Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/single-asset-ma-crossover.ipynb)

Feel free to explore and adapt these examples to suit your specific needs and trading strategies.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pawelkn/btester",
    "name": "btester",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "python,python3,quantitative,analysis,backtesting,portfolio,parallel,algorithmic,trading",
    "author": "Pawe\u0142 Knio\u0142a",
    "author_email": "Pawe\u0142 Knio\u0142a <pawel.kn@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/07/9f/7f1e3c7724998d375d8451c79bef7d8f4dd19c8643da2be43f4b0e53759b/btester-0.1.1.tar.gz",
    "platform": null,
    "description": "# btester -   Trading Strategy Backtesting Framework\n\n[![Test btester](https://github.com/pawelkn/btester/actions/workflows/test-btester.yml/badge.svg)](https://github.com/pawelkn/btester/actions/workflows/test-btester.yml) [![PyPi](https://img.shields.io/pypi/v/btester.svg)](https://pypi.python.org/pypi/btester/) [![Downloads](https://img.shields.io/pypi/dm/btester)](https://pypi.python.org/pypi/btester/) [![Codecov](https://codecov.io/gh/pawelkn/btester/branch/master/graph/badge.svg)](https://codecov.io/gh/pawelkn/btester/)\n\n`btester` is a Python framework optimized for running backtests on multiple assets and supports full portfolio backtesting. It provides tools for backtesting trading strategies based on historical market data. The framework includes classes for managing financial positions, completed trades, and a flexible abstract base class for implementing custom trading strategies.\n\n## Installation\n\nYou can install `btester` using pip. Simply run the following command:\n\n```bash\npip install btester\n```\n\n## Usage\n\n1. Define your custom trading strategy by creating a class that inherits from the `Strategy` abstract class.\n\n2. Implement the required methods in your custom strategy: `init` for initialization and `next` for the core strategy logic.\n\n3. Instantiate the `Backtest` class with your custom strategy, historical market data, and other parameters.\n\n4. Run the backtest using the `run` method, which returns a `Result` object containing backtest results.\n\n## Example Usage\n\n```python\n# Example usage of the btester\nfrom btester import Strategy, Backtest\nimport pandas as pd\n\n# Define a custom strategy by inheriting from the abstract Strategy class\nclass MyStrategy(Strategy):\n    def init(self):\n        # Custom initialization logic for the strategy\n        pass\n\n    def next(self, i: int, record: Dict[Hashable, Any]):\n        # Custom strategy logic for each time step\n        pass\n\n# Load historical market data\ndata = pd.read_csv('historical_data.csv', parse_dates=['Date'])\ndata.set_index('Date', inplace=True)\n\n# Initialize and run the backtest\nbacktest = Backtest(strategy=MyStrategy, data=data, cash=10000, commission=0.01)\nresult = backtest.run()\n\n# Access backtest results\nreturns_series = result.returns\ncompleted_trades = result.trades\nremaining_positions = result.open_positions\n```\n\n## Examples\n\nCheck out the examples in the `examples` directory for additional use cases and demonstrations. The examples cover various scenarios and strategies to help you understand the versatility of the `btester`.\n\n- [Example 1: Multiple Assets Breakout Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/multiple-assets-brakeout.ipynb)\n- [Example 2: Multiple Assets Moving Average Crossover Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/multiple-assets-ma-crossover.ipynb)\n- [Example 3: Single Asset Breakout Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/single-asset-brakeout.ipynb)\n- [Example 4: Single Asset Moving Average Crossover Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/single-asset-ma-crossover.ipynb)\n\nFeel free to explore and adapt these examples to suit your specific needs and trading strategies.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Pawe\u0142 Knio\u0142a  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Python framework optimized for running backtests on multiple assetss",
    "version": "0.1.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/pawelkn/btester/issues",
        "Homepage": "https://github.com/pawelkn/btester"
    },
    "split_keywords": [
        "python",
        "python3",
        "quantitative",
        "analysis",
        "backtesting",
        "portfolio",
        "parallel",
        "algorithmic",
        "trading"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cd806de4a391b5571f56b946c561d7bdb80a75e76ecf5107b3445d865f2d29a4",
                "md5": "35bed594e6d6f7706d157c54d1be76e0",
                "sha256": "d3221582cc31a4476fdb9ec1d25d831e435ee87d64e39dd0fdecf7cf297568bb"
            },
            "downloads": -1,
            "filename": "btester-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "35bed594e6d6f7706d157c54d1be76e0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7590,
            "upload_time": "2024-01-16T07:57:23",
            "upload_time_iso_8601": "2024-01-16T07:57:23.224923Z",
            "url": "https://files.pythonhosted.org/packages/cd/80/6de4a391b5571f56b946c561d7bdb80a75e76ecf5107b3445d865f2d29a4/btester-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "079f7f1e3c7724998d375d8451c79bef7d8f4dd19c8643da2be43f4b0e53759b",
                "md5": "e869ec5c3c9cac956293a434d2f56a4b",
                "sha256": "9648e38749f3fb3810b6d428a6be24a649800130f5f7e24fef7b9e74a065c96b"
            },
            "downloads": -1,
            "filename": "btester-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e869ec5c3c9cac956293a434d2f56a4b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9861,
            "upload_time": "2024-01-16T07:57:25",
            "upload_time_iso_8601": "2024-01-16T07:57:25.753478Z",
            "url": "https://files.pythonhosted.org/packages/07/9f/7f1e3c7724998d375d8451c79bef7d8f4dd19c8643da2be43f4b0e53759b/btester-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-16 07:57:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pawelkn",
    "github_project": "btester",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "btester"
}
        
Elapsed time: 0.17138s