McKinney Chapter 5 - Practice Blank

FINA 6333 for Spring 2024

Author

Richard Herron

1 Announcements

2 10-Minute Recap

3 Practice

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import yfinance as yf
%precision 4
pd.options.display.float_format = '{:.4f}'.format
%config InlineBackend.figure_format = 'retina'
tickers = 'AAPL IBM MSFT GOOG'
prices = yf.download(tickers=tickers)
returns = prices['Adj Close'].pct_change().dropna()
returns
[*********************100%%**********************]  4 of 4 completed
AAPL GOOG IBM MSFT
Date
2004-08-20 0.0029 0.0794 0.0042 0.0029
2004-08-23 0.0091 0.0101 -0.0070 0.0044
2004-08-24 0.0280 -0.0414 0.0007 0.0000
2004-08-25 0.0344 0.0108 0.0043 0.0114
2004-08-26 0.0487 0.0180 -0.0045 -0.0040
... ... ... ... ...
2024-01-23 0.0067 0.0066 0.0064 0.0060
2024-01-24 -0.0035 0.0112 -0.0001 0.0092
2024-01-25 -0.0017 0.0219 0.0949 0.0057
2024-01-26 -0.0090 0.0010 -0.0158 -0.0023
2024-01-29 -0.0036 0.0068 -0.0015 0.0143

4893 rows × 4 columns

3.1 What are the mean daily returns for these four stocks?

3.2 What are the standard deviations of daily returns for these four stocks?

3.3 What are the annualized means and standard deviations of daily returns for these four stocks?

3.4 Plot annualized means versus standard deviations of daily returns for these four stocks

Use plt.scatter(), which expects arguments as x (standard deviations) then y (means).

3.5 Repeat the previous calculations and plot for the stocks in the Dow-Jones Industrial Index (DJIA)

We can find the current DJIA stocks on Wikipedia. We will need to download new data, into tickers2, prices2, and returns2.

3.6 Calculate total returns for the stocks in the DJIA

We can use the .prod() method to compound returns as \(1 + R_T = \prod_{t=1}^T (1 + R_t)\). Technically, we should write \(R_T\) as \(R_{0,T}\), but we typically omit the subscript \(0\).

3.7 Plot the distribution of total returns for the stocks in the DJIA

We can plot a histogram, using either the plt.hist() function or the .plot(kind='hist') method.

3.8 Which stocks have the minimum and maximum total returns?

3.9 Plot the cumulative returns for the stocks in the DJIA

We can use the cumulative product method .cumprod() to calculate the right hand side of the formula above.

3.10 Repeat the plot above with only the minimum and maximum total returns