Optimizations

class src.boatwright.Optimizations.Optimization.Optimization(strategy_class, symbol, broker, loss_function, data, executer=<src.boatwright.BacktestExecutors.SequentialExecutor.SequentialExecutor object>)

Optimizations here are considered to be any routine which systematicly runs backtests searching for better performing strategy parameters by means of a loss function

Parameters:
  • strategy – the strategy being optimized

  • loss_function – a method taking a backtest which is minimized by the optimization, e.g. f_loss = -ROI(backtest) would maximize profit

  • broker (BacktestBroker) – broker object.

  • data (DataFrame) – candle stick data to conduct backtests on

  • executer (BacktestExecutor) – handles the running of all the backtests

  • strategy_class (Strategy)

  • symbol (str)

Variables:

backtests – (list) the list of backtests each optimization generates as it runs

Methods

abstract calc_prerequisite_data_length()

calculates the largest possible prerequiste data length possible for the strategy and parameter space

abstract run(verbose=False)

runs backtests using the backtest executer

Parameters:

verbose (bool) – boolean toggle for printing progress to the terminal

Returns:

(Strategy) The strategy which minimizes self.loss_function

Utility Functions:

src.boatwright.Optimizations.Optimization.generate_parameter_combinations(parameter_values)
Parameters:

parameter_values (dict) – like {“fast_period”: [10,20,30], “slow_period”:[50,100]}

Returns:

list of parameter combinations like [{“fast_period”:10, “slow_period”: 50}, {“fast_period”:10, “slow_period”: 100}, {“period”:20, “slow_period”: 50} … ]