Exercise

Calculate and plot two EMAs

A 12-period EMA and 26-period EMA are two moving averages used in calculating a more complex indicator called MACD (Moving Average Convergence Divergence). The MACD turns two EMAs into a momentum indicator by subtracting the longer EMA from the shorter one. Before learning more about MACD, you want to get familiar with its components first. You decide to calculate two EMAs using the Google daily stock prices and plot them in one chart.

The daily historical price data of the Google stock has been loaded in stock_data. Also, talib has been imported for you, and matplotlib.pyplot has been imported as plt.

Instructions

100 XP
  • Calculate a 12-day EMA of the Close price and save it in a new column EMA_12.
  • Calculate a 26-day EMA of the Close price and save it in a new column EMA_26.
  • Plot the 12-day EMA and 26-day EMA together with the Close price.