backtestΒΆ

Defined in fynance.backtest

backtest(data, positions, cost=None, capital=1.0, returns_input=True, shift=True)[source]

Run a vectorized backtest.

Parameters:
dataarray-like

Asset returns (default) or prices (returns_input=False). Shape (T,) for a single asset or (T, n_assets) for a book.

positionsarray-like

Position/weight series aligned with data.

costCostModel, optional

Per-step transaction cost model (e.g. ProportionalCost).

capitalfloat

Initial capital.

returns_inputbool

If True (default) data are returns; otherwise prices (converted to pct returns; the first observation is dropped).

shiftbool

If True (default) positions are shifted one step (the position decided at t earns the return at t+1), guaranteeing causality.

Returns:
BacktestResult

Equity, net/gross returns, positions and per-step costs.