Created
July 19, 2015 02:11
-
-
Save ramhiser/39b65b264c960285433c to your computer and use it in GitHub Desktop.
Simple EDA of daily Home Depot stock prices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
from yahoo_finance import Share | |
import matplotlib.pylab | |
import pandas as pd | |
import numpy as np | |
thd = Share('HD') | |
thd_prices = thd.get_historical('2010-01-01', '2015-06-01') | |
thd_prices = pd.DataFrame(thd_prices) | |
thd_prices.Date = pd.to_datetime(thd_prices.Date) | |
thd_prices.index = pd.DatetimeIndex(thd_prices.Date) | |
thd_prices.drop(['Date', 'Symbol'], axis=1, inplace=True) | |
thd_prices = thd_prices.convert_objects(convert_numeric=True) | |
monthly_prices = thd_prices.groupby(pd.TimeGrouper("M")).median() | |
monthly_prices.head() | |
monthly_prices['Close'].pct_change().plot() | |
# Average percentage change by month of the year | |
monthly_changes = monthly_prices['Close'].pct_change().groupby(monthly_prices.index.month).agg([np.mean, np.std]) | |
monthly_changes | |
# Same but sorted | |
monthly_changes.sort('mean', ascending=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment