Skip to main content

bybit-backtest

PyPI License: MIT codecov Build Status PyPI - Python Version Downloads

bybit-backtest is a python library for backtest with bybit fx trade on Python 3.7 and above.

backtest data from here

Installation

$ pip install bybit-backtest

Usage

basic run

from bybit_backtest import Backtest

class MyBacktest(Backtest):
    def strategy(self):
        fast_ma = self.sma(period=5)
        slow_ma = self.sma(period=25)
        # golden cross
        self.sell_exit = self.buy_entry = (fast_ma > slow_ma) & (
            fast_ma.shift() <= slow_ma.shift()
        )
        # dead cross
        self.buy_exit = self.sell_entry = (fast_ma < slow_ma) & (
            fast_ma.shift() >= slow_ma.shift()
        )

MyBacktest().run()

advanced run

from bybit_backtest import Backtest

class MyBacktest(Backtest):
    def strategy(self):
        rsi = self.rsi(period=10)
        ema = self.ema(period=20)
        lower = ema - (ema * 0.001)
        upper = ema + (ema * 0.001)
        self.buy_entry = (rsi < 30) & (self.df.C < lower)
        self.sell_entry = (rsi > 70) & (self.df.C > upper)
        self.sell_exit = ema > self.df.C
        self.buy_exit = ema < self.df.C
        self.qty = 0.1 # order quantity (default=0.001)
        self.stop_loss = 50 # stop loss (default=0 stop loss none)
        self.take_profit = 100 # take profit (default=0 take profit none)

MyBacktest(
    symbol="BTCUSD", # default=BTCUSD
    sqlite_file_name="backtest.sqlite3", # (default=backtest.sqlite3)
    from_date="2020-04-01", # (default="")
    to_date="2020-10-25", # (default="")
    interval="1T", # 5-60S(second), 1-60T(minute), 1-24H(hour) (default=1T)
    download_data_dir="data", # download data directory (default=data)
).run("backtest.png")
total profit          491.800
total trades        10309.000
win rate               65.700
profit factor           1.047
maximum drawdown      135.500
recovery factor         3.630
riskreward ratio        0.551
sharpe ratio            0.020
average return          0.001
stop loss            1779.000
take profit            93.000

backtest.png

Supported indicators

  • Simple Moving Average 'sma'
  • Exponential Moving Average 'ema'
  • Moving Average Convergence Divergence 'macd'
  • Relative Strenght Index 'rsi'
  • Bollinger Bands 'bbands'
  • Stochastic Oscillator 'stoch'

Getting started

For help getting started with Bybit APIs and Websocket, view our online documentation.

Metadata

Release files for bybit-backtest 0.1.5

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

Source distribution (sdist)

Source distribution for bybit-backtest 0.1.5
File Size Uploaded
bybit-backtest-0.1.5.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bybit-backtest 0.1.5
File Interpreter ABI Platform
bybit_backtest-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 13.1 kB

Release files / bybit-backtest-0.1.5.tar.gz

Download URL bybit-backtest-0.1.5.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
62defdb8641d620d9d375bd631f47cfdf25dff546316ed7abd575d28c227fb2e
BLAKE2b-256 checksum
How to use checksums
9f8904bfa3b26318486eac607e5dd8b780740aff8a32af04d1284401cf1c17df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.2

Release files / bybit_backtest-0.1.5-py3-none-any.whl

Download URL bybit_backtest-0.1.5-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
322218dbad65e654e60d6c84b18e069f755139ab48d1120fa91af255532d4058
BLAKE2b-256 checksum
How to use checksums
ead11e8f9f170491c62774749a34f46ad3f555eff0919a93b0db88f126b83a63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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