Session Ready
Exercise

Transforming raw data

In the last chapter, you calculated the rolling mean. In this exercise, you will define a function that calculates the percent change of the latest data point from the mean of a window of previous data points. This function will help you calculate the percent change over a rolling window.

This is a more stable kind of time series that is often useful in machine learning.

Instructions
100 XP
  • Define a percent_change function that takes an input time series and does the following:
    • Extract all but the last value of the input series (assigned to previous_values) and the only the last value of the timeseries ( assigned to last_value)
    • Calculate the percentage difference between the last value and the mean of earlier values.
  • Using a rolling window of 20, apply this function to prices, and visualize it using the given code.