Git Product home page Git Product logo

btester_mtx's Introduction

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

btester_mtx's People

Contributors

pawelkn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.