Time for action – comparing stock log returns

We will download the stock quotes for the last year of two trackers using matplotlib. As mentioned in the previous Chapter 9, Plotting with matplotlib, we can retrieve quotes from Yahoo Finance. We will compare the log returns of the close price of DIA and SPY (DIA tracks the Dow Jones index; SPY tracks the S & P 500 index). We will also perform the Jarque–Bera test on the difference of the log returns.

  1. 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]
  2. Calculate the log returns for DIA and ...

Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.