Results#

class backtest_lib.backtest.results.BacktestResults(periods: Sequence[IndexT], securities: Sequence[str], weights: PastView[float, IndexT], asset_returns: PastView[float, IndexT], initial_capital: float, portfolio_returns: Timeseries[float, IndexT], nav: Timeseries[float, IndexT], drawdowns: Timeseries[float, IndexT], gross_exposure: Timeseries[float, IndexT], net_exposure: Timeseries[float, IndexT], turnover: Timeseries[float, IndexT], total_return: float, annualized_return: float, annualized_volatility: float, sharpe: float | None, max_drawdown: float, avg_turnover: float, market: MarketView[IndexT], _backend: str, _backend_pastview_type: type[PastView], _backend_timeseries_type: type[Timeseries])#

Snapshot of a backtest’s results, with key statistics pre-computed.

static from_weights_and_returns(weights: PastView[float, Any], returns: PastView[float, Any], market: MarketView[IndexT], *, initial_capital: float = 1.0, periods_per_year: float = 252.0, risk_free_annual: float | None = None, backend: str = 'polars') BacktestResults[Any]#

Build results from pre-computed per-security simple returns.

Assumptions: - weights.periods and returns.periods are aligned 1:1. - weights.securities and returns.securities are aligned 1:1. - Returns are simple returns over the same period labels as weights.

static from_weights_market_initial_capital(weights: PastView[float, Any], market: MarketView[Any], initial_capital: float, *, periods_per_year: float = 252.0, risk_free_annual: float | None = 0.02, backend: str) BacktestResults[Any]#

Convenience constructor that derives per-security returns from market.prices.close and then computes all stats.

Still continuous weight-space (no discrete quantities).