Skip to main content

btester - Multi-Assets Backtesting Framework

Test btester PyPi Downloads Codecov

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:

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

# 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.

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

Metadata

Release files for btester 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for btester 0.2.0
File Size Uploaded
btester-0.2.0.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for btester 0.2.0
File Interpreter ABI Platform
btester-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / btester-0.2.0.tar.gz

Download URL btester-0.2.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a51cf23b24f44ac9bf63f4cb3dc3d8a75c3346d780f6f2ac3f747f35cc93601b
BLAKE2b-256 checksum
How to use checksums
0f4c3e5c8640114fb1c5a90cf2a876be4c2a60cf98d959669aaee3ffa7024e83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / btester-0.2.0-py3-none-any.whl

Download URL btester-0.2.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5516e946dd8de26d974bc1396a2362a95504221a135024494b19bff94ec2b5c3
BLAKE2b-256 checksum
How to use checksums
4a437717854cd6d56561f24ee8cd9f147928ee5153a886cd9855f190e124645d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page