Skip to main content

A simple backtesting engine for trading strategies

Project description

ncBacktester

ncBacktester is a small, opinionated Python package for backtesting simple long-only strategies driven by a Hold_Signal column on OHLCV data. It is designed for clarity and education rather than exhaustive feature coverage.

Quick summary: feed time-series OHLCV data with a Hold_Signal (1 = hold, 0 = not hold), instantiate Backtest, call .run() and examine metrics and plots.

Install (development)

pip install ncBacktester

Minimal Quick Start

import pandas as pd
from ncBacktester.backtest import Backtest

# data must include: Open, High, Low, Close, Volume, Hold_Signal
data = pd.read_csv('your_data.csv', parse_dates=['Date'], index_col='Date')

bt = Backtest(data=data, initial_capital=10000.0, stop_loss_pct=0.05, commission=0.001)
results = bt.run()

print(results['metrics'])          # key performance metrics
results['equity_curve'].plot()     # equity curve
bt.plot(save_path='backtest.png')  # static plots

Required data format

  • Columns: Open, High, Low, Close, Volume, Hold_Signal.
  • Hold_Signal should be 0 or 1; changes 0→1 trigger buys, 1→0 trigger sells.

Main components

Behavior & assumptions

  • Buys and sells are executed at the bar Close where the Hold_Signal changes.
  • On a buy the framework purchases as many shares as possible with available capital; on sell it liquidates the full position.
  • Stop loss (fixed or trailing) is optional and configured via Backtest(stop_loss_pct=..., trailing_stop_pct=...).

Advanced usage

  • If you want to reuse StrategyExecutor or StopLossManager directly, import them from their modules and instantiate with the same parameters used by Backtest.

Contributing & license

  • This project is intended for learning; contributions and issues are welcome.
  • Licensed under the MIT License.

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

ncbacktester-0.1.1.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

ncbacktester-0.1.1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ncbacktester-0.1.1.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for ncbacktester-0.1.1.tar.gz
Algorithm Hash digest
SHA256 30af352f147f0813ce232a6272cf324167855d6fe0ff3865a63240ae05206f0c
MD5 c521efe3136a00ee0d79f7885ee8fede
BLAKE2b-256 d41389d85ad89c78a16d8ad1f9a03e4b9cef763d19aefd31721f749a52b79e08

See more details on using hashes here.

File details

Details for the file ncbacktester-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ncbacktester-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for ncbacktester-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e24073063ffad7b1f5ec394d6899d96eea9ccd0bb9f69b8525ce26dff66ba166
MD5 7dc523d51b02918f23bf9a4d60ed0345
BLAKE2b-256 b373a1d84aa6ad4095fb2136d53c5adfc4ca60c1d91945a6f460be6c18c9a596

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