Code Smells and Refactoring

This exercise asks us to refactor the Stock class and extract all the moving average related calculations into a new class.

The following is the code that we start with:

def get_crossover_signal(self, on_date): NUM_DAYS = self.LONG_TERM_TIMESPAN + 1 closing_price_list = \ self.history.get_closing_price_list(on_date, NUM_DAYS) if len(closing_price_list) < NUM_DAYS: return StockSignal.neutral long_term_series = \ closing_price_list[-self.LONG_TERM_TIMESPAN:] prev_long_term_series = \ closing_price_list[-self.LONG_TERM_TIMESPAN-1:-1] short_term_series = \ closing_price_list[-self.SHORT_TERM_TIMESPAN:] prev_short_term_series = \ closing_price_list[-self.SHORT_TERM_TIMESPAN-1:-1] long_term_ma = sum([update.value for update ...

Get Test-Driven Python Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.