April 2019
Intermediate to advanced
426 pages
11h 13m
English
Because only the decision-making logic needs to be modified from our parent MeanReversionTrader class, and everything else, including orders, placement, and streaming prices, remains the same, we simply override the generate_signals_and_think() method and implement our new trend-following signal generators using the following code:
def generate_signals_and_think(self): df_resampled = self.df_prices\ .resample(self.resample_interval)\ .ffill().dropna() resampled_len = len(df_resampled.index) if resampled_len < self.long_mean_periods: print( 'Insufficient data size to calculate logic. Need', self.mean_periods - resampled_len, 'more.' ) return mean_short = df_resampled\ .tail(self.mean_periods).mean()[self.symbol] ...
Read now
Unlock full access