A quickly backtesting library for inversion strategies
Project description
Package nanobt
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
import pandas as pd
INIT_PORTFOLIO = 1000
class BuyAndHoldStrategy(Backtesting):
def __init__(self):
super().__init__()
self.buy_and_hold = False
def next(self):
if not self.buy_and_hold:
self.buy_and_hold = True
self.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
Release history Release notifications | RSS feed
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.0.tar.gz
(3.3 kB
view hashes)