slickbet.backtest¶

Backtesting for evaluating prediction accuracy against historical data.

Runs the betting model on past matches (simulating pre-match knowledge), compares predictions to actual outcomes, and reports win / double-chance accuracy metrics via BacktestResults and format_backtest_report.

Classes¶

BacktestResults

Aggregated results from a backtest run.

Backtester

Backtester for evaluating betting model against historical data.

PredictionResult

Result of a single prediction compared to actual outcome.

Functions¶

format_backtest_report(→ str)

Generate a formatted report of backtest results.

Module Contents¶

class slickbet.backtest.BacktestResults[source]¶

Aggregated results from a backtest run.

property accuracy: float¶

Overall accuracy (0-1).

property accuracy_excluding_draws: float¶

Accuracy excluding matches that ended in draws.

property away_accuracy: float¶

Accuracy for away win predictions.

property away_or_draw_accuracy: float¶

Accuracy for X2 (Away or Draw) double chance bets.

property away_predictions: list[PredictionResult]¶

Predictions where we bet on away team.

property best_double_chance_accuracy: float¶

Accuracy when following the recommended double chance bet.

by_probability_threshold(threshold: float) BacktestResults[source]¶

Filter results by minimum probability threshold.

Parameters:

threshold (float) – Minimum prediction probability (inclusive).

Returns:

BacktestResults – New results object with filtered predictions.

competition: str = ''¶
property correct_predictions: int¶

Number of correct predictions.

property draws_encountered: int¶

Number of matches that ended in a draw.

from_date: datetime.datetime | None = None¶
property high_confidence_accuracy: float¶

Accuracy for high confidence predictions.

property high_confidence_accuracy_excl_draws: float¶

Accuracy for high confidence predictions, excluding draws.

property high_confidence_results: list[PredictionResult]¶

Predictions with confidence > 0.3.

property high_probability_accuracy: float¶

Accuracy for high probability predictions (>60%).

property high_probability_accuracy_excl_draws: float¶

Accuracy for high probability predictions (>60%), excluding draws.

property high_probability_results: list[PredictionResult]¶

Predictions with probability > 60%.

property home_accuracy: float¶

Accuracy for home win predictions.

property home_or_draw_accuracy: float¶

Accuracy for 1X (Home or Draw) double chance bets.

property home_predictions: list[PredictionResult]¶

Predictions where we bet on home team.

property low_draw_risk_accuracy: float¶

Accuracy for low draw risk predictions.

property low_draw_risk_results: list[PredictionResult]¶

Predictions where draw risk < 30%.

property no_draw_accuracy: float¶

Accuracy for 12 (No Draw) double chance bets.

results: list[PredictionResult] = []¶
to_date: datetime.datetime | None = None¶
property total_predictions: int¶

Total number of predictions made.

class slickbet.backtest.Backtester(client: slickbet.api.LivescoreClient | None = None, model: slickbet.model.BettingModel | None = None, cache_dir: str | pathlib.Path | None = None, cache_only: bool = False)[source]¶

Backtester for evaluating betting model against historical data.

Examples

>>> backtester = Backtester()
>>> results = backtester.run(
...     competition_id="1",  # Premier League
...     weeks=4,
... )
>>> print(f"Accuracy: {results.accuracy:.1%}")
BUNDESLIGA = '1'¶
LA_LIGA = '3'¶
LIGUE_1 = '5'¶
PREMIER_LEAGUE = '2'¶
SERIE_A = '4'¶
model¶
run(competition_id: str = '1', weeks: int = 4, from_date: datetime.datetime | None = None, to_date: datetime.datetime | None = None, min_probability: float = 0.0, verbose: bool = True, debug: bool = False) BacktestResults[source]¶

Run backtest on historical data.

Parameters:
  • competition_id (str, optional) – Competition ID to backtest

  • weeks (int, optional) – Number of weeks of history (if from_date not specified)

  • from_date (datetime or None, optional) – Start date for historical data

  • to_date (datetime or None, optional) – End date for historical data (defaults to today)

  • min_probability (float, optional) – Minimum probability threshold for predictions

  • verbose (bool, optional) – Print progress information

  • debug (bool, optional) – Print detailed match-by-match predictions and results

Returns:

BacktestResults – BacktestResults with all predictions and accuracy metrics

class slickbet.backtest.PredictionResult[source]¶

Result of a single prediction compared to actual outcome.

actual_outcome: str¶
property actual_winner: str¶

Name of the actual winner (or ‘Draw’).

away_or_draw_correct: bool = False¶
property best_double_chance_correct: bool¶

Whether the recommended double chance bet would have won.

confidence: float¶
home_or_draw_correct: bool = False¶
is_correct: bool¶
match: slickbet.api.HistoricalMatch¶
no_draw_correct: bool = False¶
predicted_outcome: str¶
property predicted_team: str¶

Name of the team we predicted to win.

prediction: slickbet.model.BetPrediction¶
probability: float¶
slickbet.backtest.format_backtest_report(results: BacktestResults) str[source]¶

Generate a formatted report of backtest results.

Parameters:

results (BacktestResults) – Aggregated backtest results.

Returns:

str – Multi-line human-readable report.