We will download the stock quotes for the last year of two trackers using Matplotlib. As mentioned in the previous chapter, we can retrieve quotes from Yahoo! Finance. We will compare the log returns of the close price of DIA and SPY. Also we will perform the Jarque-Bera test on the difference of the log returns. Perform the following steps to do so:
Write a function that can return the close price for a specified stock.
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]
Calculate the log returns for DIA and SPY. The log returns are calculated by taking the natural logarithm of the close price and then taking the difference of consecutive values.
spy = np.diff(np.log(get_close(“SPY”))) dia = np.diff(np.log(get_close(“DIA”)))
The means comparison test checks whether two different samples...