So, we transform our training data by looping over each mid-price value, updating the smoothing coefficient, and then applying it to the current price value. Note that we update the smoothing coefficient using the previously shown formula, which allows us to weight each observation in the time series as a function weighting the current and previous observations:
Smoothing = 0.0 #Initialize smoothing value as zero gamma = 0.1 #Define decay for i in range(1000): Smoothing = gamma*train_data[i] + (1-gamma)*Smoothing # Update
smoothing value train_data[i] = Smoothing # Replace datapoint with smoothened value