Skip to main content

A vectorized backtesting library for trading strategies

Project description

BacktesterLib

A lightweight vectorized backtesting library for testing trading strategies.

Installation

pip install backtesterlib

Usage

import pandas as pd
from backtesterlib import Backtester, BuyAndHold

MINUTES_PER_DAY = 60 * 24
MINUTES_PER_MONTH = MINUTES_PER_DAY * 30
MINUTES_PER_YEAR = MINUTES_PER_DAY * 365

# Load csv containing a column of close prices. This one has minute intervals
df = pd.read_csv("data/SOLUSDT-1.csv", sep="|", index_col=0) 

# Select the last month of data for example purposes
df = df.iloc[-MINUTES_PER_MONTH:].reset_index() 
    
# Create Backtester object
backtester = Backtester(
    df=df, close_column="close", # Name of close price column in your data
    bars_per_year=MINUTES_PER_YEAR, 
    windows_per_year=12, # 12 months per year
    fee_rate=0.00001, fee_in_usd=False # False since we specify fees in SOL
)

# Example buy and hold strategy holding 2 SOL
backtester.run(BuyAndHold(amount=2.0), n_mote_carlo_paths=1000)

# Baseline strategy
backtester.run(BuyAndHold(amount=1.0), n_mote_carlo_paths=0, baseline=True)

# Display strategy performance
backtester.plot_results(figsize=(12, 8), plot_correlations=False)
backtester.log_results()

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

backtesterlib-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

backtesterlib-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file backtesterlib-0.1.0.tar.gz.

File metadata

  • Download URL: backtesterlib-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for backtesterlib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fc3807900c4722a228ed908c08638a33355ccd1ae4e1d5159990db958e89c164
MD5 c2fa6126c4045021274a171b0e31df75
BLAKE2b-256 6ef1f262ac7481ea1b4531be2c46dcca9dce283a8a7d5bbd862add2b32fa1e76

See more details on using hashes here.

File details

Details for the file backtesterlib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: backtesterlib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for backtesterlib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a3046e3068dc72473462ba89678be23a736e5bb4977ce49f01d0518ee7b4825
MD5 e263dd4f155bddd880f303d6a1409d0f
BLAKE2b-256 4a3dceef754902dc3a9f09a8fb33e3ba90a983eadcab92a0868dc7a2147a4ef9

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