Metadata-Version: 2.4
Name: btester
Version: 0.2.0
Summary: Python framework optimized for running backtests on multiple assetss
Home-page: https://github.com/pawelkn/btester
Author: Paweł Knioła
Author-email: Paweł Knioła <pawel.kn@gmail.com>
License: MIT 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.
        
Project-URL: Homepage, https://github.com/pawelkn/btester
Project-URL: Bug Tracker, https://github.com/pawelkn/btester/issues
Keywords: python,python3,quantitative,analysis,backtesting,portfolio,parallel,algorithmic,trading
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas>=0.22
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# btester -   Multi-Assets 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 asset portfolios.

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, leverage=1.0, 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: Multi-Assets Moving Average Crossover Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/multi-assets-ma-crossover.ipynb)
- [Example 2: Multi-Assets Breakout Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/multi-assets-brakeout.ipynb)
- [Example 3: Single Asset Moving Average Crossover Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/single-asset-ma-crossover.ipynb)
- [Example 4: Single Asset Breakout Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/single-asset-brakeout.ipynb)
- [Example 5: Index Short-Long Day Trading Strategy](https://colab.research.google.com/github/pawelkn/btester/blob/master/examples/index-short-long-day-trading.ipynb)

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