1. Learn
  2. /
  3. Courses
  4. /
  5. Importing and Managing Financial Data in Python

Exercise

Visualize a stock price trend

Google Finance has deprecated their API but DataReader now makes available the data source 'iex'. To experiment with the data outside DataCamp environment, you will need an IEX Cloud account.

The most important change to the functionality is the limitation of the data to the last five years. The DataFrame returned by the DataReader has the same columns, but in lower case.

The matplotlib.pyplot package is essential to visualizing stock price trends in Python.

In this exercise, you will import 2016 stock price data for Facebook, and then plot its closing price for the entire period! DataReader and date have already been imported.

Instructions

100 XP
  • Import matplotlib.pyplot as plt.
  • Using date(), set the start and end dates to January 1, 2016 and December 31, 2016, respectively.
  • Set ticker to Facebook's stock ticker 'FB' and data_source to 'iex'.
  • Create a DataReader() object to import the stock prices and assign to stock_prices.
  • Plot the 'close' data in stock_prices, set ticker as the title, and show the result.