from matplotlib.finance import quotes_historical_yahoo from datetime import date import numpy as np from scipy import stats from statsmodels.stats.stattools import jarque_bera import matplotlib.pyplot as plt def get_close(symbol): today = date.today() start = (today.year - 1, today.month, today.day) quotes = quotes_historical_yahoo(symbol, start, today) quotes = np.array(quotes) return quotes.T[4] spy = np.diff(np.log(get_close("SPY"))) dia = np.diff(np.log(get_close("DIA"))) print "Means comparison", stats.ttest_ind(spy, dia) print "Kolmogorov smirnov test", stats.ks_2samp(spy, dia) print "Jarque Bera test", jarque_bera(spy - dia)[1] plt.hist(spy, histtype="step", lw=1, label="SPY") plt.hist(dia, histtype="step", lw=2, label="DIA") plt.hist(spy - dia, histtype="step", lw=3, label="Delta") plt.legend() plt.show()