Skip to main content

Python framework optimized for running backtests on multiple assetss

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

btester-0.2.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

btester-0.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file btester-0.2.0.tar.gz.

File metadata

  • Download URL: btester-0.2.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for btester-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a51cf23b24f44ac9bf63f4cb3dc3d8a75c3346d780f6f2ac3f747f35cc93601b
MD5 b8829f4b7254845d8c161659c368dcca
BLAKE2b-256 0f4c3e5c8640114fb1c5a90cf2a876be4c2a60cf98d959669aaee3ffa7024e83

See more details on using hashes here.

File details

Details for the file btester-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: btester-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for btester-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5516e946dd8de26d974bc1396a2362a95504221a135024494b19bff94ec2b5c3
MD5 3d233ee2ed37b5ccd8fb823ca0d2c0de
BLAKE2b-256 4a437717854cd6d56561f24ee8cd9f147928ee5153a886cd9855f190e124645d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page