In this assignment you will conduct time series analysis of the financial data.
Setup your environment to access and download latest stock data. Please see instructions below for different tools you can use to get the data. You can use any of the options provided, either Quandl or Yahoo Finance. If you know of any other service to download the data, please use that service, provide an explanation in the comments.
(2 points) Download the adjusted close prices for FB, MMM, IBM and AMZN for the last 60 months. If you run into any issues downloading the data from online sources, you can use .csv files provided. This will not affect your grade for the assignment.
(3 points) Resample the data to get prices for the end of the business month. Select the Adjusted Close for each stock.
(3 points) Use the pandas autocorrelation_plot() function to plot the autocorrelation of the adjusted month-end close prices for each of the stocks.
Are they autocorrelated?
Provide short explanation.
(4 points)
Calculate the monthly returns for each stock using the "shift trick" explained in the lecture, using shift() function.
Use pandas autotocorrelation_plot() to plot the autocorrelation of the monthly returns.
Are the returns autocorrelated? Provide short explanation.
(3 points)
Combine all 4 time series (returns) into a single DataFrame,
Visualize the correlation between the returns of all pairs of stocks using a scatter plot matrix (use scatter_matrix() function from pandas.plotting).
Explain the results. Is there any correlation?
NOTES:
In this assignment, please make sure the DataFrame(s) do not contain any NAs before you plot autocorrelations or scatter matrix.
Both options explained below use pandas-datareader package for remote data access. To install it, type the following in a command window: conda install pandas-datareader. You will also need to install one or more of the following packages fix_yahoo_finance, quandl. See below.
# all imports and env variables
import pandas as pd
import numpy as np
pd.core.common.is_list_like = pd.api.types.is_list_like
import datetime as datetime
import pandas_datareader.data as web
# This line of code should work on Windows and Mac
%env QUANDL_API_KEY = ""
# If the above line of code does not work on your system,
# You can use this way of setting Quandl env variable
#import quandl
#quandl.ApiConfig.api_key = ""