from simple_backtest import (
Backtest, BacktestConfig,
MovingAverageStrategy,
)
strategy = MovingAverageStrategy(
short_window=10, long_window=30, shares=10
)
config = BacktestConfig.default(
initial_capital=100_000
)
Sample output · not a performance claim
One price series, one cash-funded portfolio.
Each backtest accepts one OHLC or OHLCV series. The accounting model tracks a cash-funded spot position and makes the unsupported cases explicit.
Supported
- Cash-funded spot
- Fractional units
- Custom strategies
- Commission models
Out of scope
- Shorting
- Leverage
- Derivatives
- Live execution
You supply the data and the trading rules.
The library takes your price series and strategy objects, then returns portfolio state, trade history, metrics, and Plotly charts you can inspect in Python.
-
01
Load one price series
Pass an OHLC or OHLCV DataFrame from an API, CSV, database, or notebook.
-
02
Choose or write a strategy
Use a built-in strategy or subclass
Strategyand implement your own signals. -
03
Run and compare
Inspect trades, equity, metrics, benchmarks, and parameter searches from the result object.
Install it and pass in a DataFrame.
There is no hosted service or account. The package runs locally and accepts ordinary pandas data.
pip install simple-backtest
from simple_backtest import (
Backtest,
BacktestConfig,
MovingAverageStrategy,
)
strategy = MovingAverageStrategy(
short_window=10,
long_window=30,
shares=10,
)
config = BacktestConfig.default(
initial_capital=10_000
)
backtest = Backtest(data, config)
results = backtest.run([strategy])
print(results.compare())
What the library handles after a signal.
Run several strategies against the same series, tune parameters, validate across time windows, and plot the results with Plotly.
Measure
Sharpe, Sortino, Calmar, CAGR, drawdown, win rate, alpha, beta, and more.
Optimize
Grid search, random search, and chronological walk-forward evaluation.
Model costs
Percentage, flat, tiered, or custom commission behavior.
Six notebooks with working code.
Start with data loading and a first strategy, then move through commissions, technical signals, machine learning, and walk-forward optimization.