Skip to main content

A quickly backtesting library for inversion strategies

Project description

Package nanobt (v 0.1.0)

A quickly backtesting library for inversion strategies

Install package

pip install nanobt

Data as pd.DataFrame

Columns required = ['datetime', 'open', 'high', 'low', 'close', 'volume']

Column 'datetime' must be datetime object.

Code example

from nanobt.backtesting import Backtesting
from nanobt.trades import TradeHistory, SideOrder
import pandas as pd

INIT_PORTFOLIO = 1000
class BuyAndHoldStrategy(Backtesting):
    def next(self):
        if not self.position:
            self.entry(SideOrder.BUY)

data = pd.read_csv('./data/binance_BTCUSDT_5m.csv')
data['datetime'] = pd.to_datetime(data['time'], unit='s')
data = data.drop(columns=['time'])

strategy = BuyAndHoldStrategy()
strategy.setdata(data)
trades = strategy.run()

th = TradeHistory(trades=trades)
print("Init Portfolio: ", INIT_PORTFOLIO)
print("Buy and Hold Strategy: ", th.study(cash=INIT_PORTFOLIO, sizer=1, commision=0.04, show_plot=False))

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

nanobt-0.1.1.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file nanobt-0.1.1.tar.gz.

File metadata

  • Download URL: nanobt-0.1.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for nanobt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3838b96355ff49d6572385e27aa4d08bb97353b68d53b2853124398ba8ff00d1
MD5 a148c5362285776306d331cb0c06caf2
BLAKE2b-256 a2708af8dad5d50ab6450fad4085cc54299495bdf61995d4c8d1202811ba4306

See more details on using hashes here.

Supported by

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