<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def moving_average(self, window, method=SIMPLE):
        '''Calculate a moving average using the specified method and window'''
        if len(self.points) < window:
            raise ArithmeticError('Not enough points for moving average')
        numpy = LazyImport.numpy()
        if method == TimeSeries.SIMPLE:
            weights = numpy.ones(window) / float(window)
        ma_x = self.timestamps[window-1:]
        ma_y = numpy.convolve(self.values, weights)[window-1:-(window-1)].tolist()
        return TimeSeries(zip(ma_x, ma_y))