Path: blob/master/09_Time_Series/Getting_Financial_Data/Exercises.ipynb
613 views
Kernel: Python 3
Getting Financial Data - Pandas Datareader
Introduction:
This time you will get data from a website.
Step 1. Import the necessary libraries
In [ ]:
Step 2. Create your time range (start and end variables). The start date should be 01/01/2015 and the end should today (whatever your today is).
In [ ]:
Step 3. Get an API key for one of the APIs that are supported by Pandas Datareader, preferably for AlphaVantage.
If you do not have an API key for any of the supported APIs, it is easiest to get one for AlphaVantage. (Note that the API key is shown directly after the signup. You do not receive it via e-mail.)
(For a full list of the APIs that are supported by Pandas Datareader, see here. As the APIs are provided by third parties, this list may change.)
Step 4. Use Pandas Datarader to read the daily time series for the Apple stock (ticker symbol AAPL) between 01/01/2015 and today, assign it to df_apple and print it.
In [ ]:
Step 5. Add a new column "stock" to the dataframe and add the ticker symbol
In [ ]:
Step 6. Repeat the two previous steps for a few other stocks, always creating a new dataframe: Tesla, IBM and Microsoft. (Ticker symbols TSLA, IBM and MSFT.)
In [ ]:
Step 7. Combine the four separate dataFrames into one combined dataFrame df that holds the information for all four stocks
In [ ]:
Step 8. Shift the stock column into the index (making it a multi-level index consisting of the ticker symbol and the date).
In [ ]:
Step 7. Create a dataFrame called vol, with the volume values.
In [ ]:
Step 8. Aggregate the data of volume to weekly.
Hint: Be careful to not sum data from the same week of 2015 and other years.
In [ ]:
Step 9. Find all the volume traded in the year of 2015
In [ ]: