Strategy¶
- class src.boatwright.Strategy.Strategy(symbol, strategy_id=None)¶
Strategies systematically place and manage orders with the broker. This parent class imposes the methods necessary for the rest of package to run backtests and live execution instances.
- Parameters:
symbol (str) – symbol being to be traded by the strategy, e.g. “AAPL” or “BTC”
strategy_id – optional strategy ID, defaults to the class name
- Variables:
broker – upon the initialization of a
Backtest
orLiveExecution
instance aBroker
is attributed to the strategy which it can place orders to and query
- abstract calc_prerequisite_data_length()¶
- Returns:
length of dataframe required to generate all signals in
calculate_signals()
- Return type:
int
- abstract calculate_signals(data)¶
takes a dataframe and returns an updated dataframe with additional columns for any technical inidcator signals required for the strategy
- Parameters:
data (DataFrame) – pandas dataframe with columns [datetime, open, high, low, close, volume]
- Returns:
(
pd.DataFrame
) dataframe with additional columns of technical indicators
- plot_info()¶
This optional method is called by
Visualization.plot_backtest()
for instruction on how to plot signals. :return: (dict
) dictionary of information specifying how technical indicators should be plotted.Note
See Examples.Strategy and Examples.Backtest for an example of how the dict should be structured
- abstract step(row)¶
actions to taken on each ‘bar’ of data in a
Backtest
orLiveExecution
instance. e.g. check buy/sell triggers and create or check orders accordingly.- Parameters:
row – one row of the pd.Dataframe calculated by
calculate_signals()
- Returns:
None
Note
logic should only be applied to the passed row, and not self.dataframe. avoid accessing other rows such as self.df.iloc[i-10]; rather in ‘calculate signals’ calculate another pd.Series of the delayed data