1. Learn
  2. /
  3. Courses
  4. /
  5. Financial Trading in Python

Connected

Exercise

SMA vs. EMA

SMA and EMA are both commonly-used trend indicators. SMA gives equal weight to all data points, while EMA applies more weight to recent data points. You have some Google stock price data and want to decide on a moving average indicator to use. You plan to calculate both the SMA and EMA with the same lookback period 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 50-day SMA of the Close price and save it in a new column SMA.
  • Calculate a 50-day EMA of the Close price and save it in a new column EMA.
  • Plot the SMA and EMA together with the Close price.