Skip to content

Instantly share code, notes, and snippets.

@ramhiser
Created July 19, 2015 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramhiser/39b65b264c960285433c to your computer and use it in GitHub Desktop.
Save ramhiser/39b65b264c960285433c to your computer and use it in GitHub Desktop.
Simple EDA of daily Home Depot stock prices
%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