Backtest#
Backtest module
Used to backtest different betting strategies.
- class penaltyblog.backtest.Account(bankroll: float)[source]#
Bases:
objectUsed to make and track bets made during the backtest
- class penaltyblog.backtest.Backtest(data: DataFrame, start_date: str, end_date: str, stop_at_negative: bool = False)[source]#
Bases:
objectUsed to backtest different betting strategies.
- start(bankroll, logic, trainer)[source]#
Runs the backtest using the logic function (and optionally the trainer function)
- results() dict[source]#
Calculates the results of the backtest and returns them as a dict
- Return type:
Dictionary containing metrics about the backtest
- start(bankroll: float, logic: Callable, trainer: Callable | None = None)[source]#
- Parameters:
bankroll (float) – The initial starting value for the bankroll
logic (callable) – The function to apply to each individual fixture. The function should have one argument called ctx, which contains the the information required to run the strategy. See the example notebooks for more examples of the logic function and how to use the ctx object. ctx will contain an instance of the Account class, which contains functions for placing virtual bets, lookback which contains all the fuxtures prior to the date of the current fixture, fixture which is the current fixture being processed, and optionally model if a trainer function is used.
trainer (callable) – The function used to train a model, which is then added to the ctx object passed to the logic function. This function should have one argument called ctx, which contains the the information required to train the model and should return the trained model. See the example notebooks for more examples of the trainer function and how to use the ctx object. The trainer function gets called once per unique date and then is made available to all fixtures for that date.
- Return type:
None