ActiveOptimization

class src.boatwright.ActiveOptimization.ActiveOptimization(strategy, optimization, opt_period, opt_length, debug=False, verbose=False)

Every “opt_period” number of bars, run an optimization to determine the new optimal strategy parameters

Parameters:
  • strategy (Strategy) – A strategy

  • optimization (Optimization) – A optimization

  • opt_period (int) – how often the optimization should be run, in number of bars / steps

  • opt_length (int) – the amount of the most recent data to use for the optimization

  • verbose (bool) – (optional) boolean toggle for printing each optimization progress to terminal, defaults to False

  • debug (bool) – (optional) boolean toggle for printing debugging information to terminal, defaults to False

calc_prerequisite_data_length()
Returns:

(int) length of dataframe required to generate all signals in calculate_signals()

calculate_signals(data)

calculates signals by calling self.strategy.calculate_signals() while also periodically optimizing the strategy on the most recent data

Parameters:

data (DataFrame) – pandas dataframe with columns [datetime, open, high, low, close, volume]

Returns:

(pd.DataFrame) dataframe with additional columns of technical indicators

optimize(index)

run the optimization using data taken with repect to the given index

Parameters:

index (int) – the current index in either the Backtest or LiveExecution

Returns:

(dict) the optimal strategy parameters

plot_info()

calls self.strategy.plot_info() and appends columns:

  • reoptimize - indicating when along the dataset the strategy was reoptimized

  • a column for each parameter in the strategy - indicating the optimized parameter values along the dataset

Returns:

(dict) dictionary of information specifying how technical indicators should be plotted.

step(row)

calls self.strategy.step()

Parameters:

row – one row of the pd.Dataframe calculated by calculate_signals()

Returns:

None