Herron Topic 1 - Practice Blank

FINA 6333 for Spring 2024

Author

Richard Herron

1 Announcements

2 Practice

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
%precision 4
pd.options.display.float_format = '{:.4f}'.format
%config InlineBackend.figure_format = 'retina'
import yfinance as yf
import pandas_datareader as pdr

2.1 Download all available daily price data for tickers TSLA, F, AAPL, AMZN, and META to data frame histories

Remove time zone information from the index and use histories.columns.names to label the variables and tickers as Variable and Ticker.

2.2 Calculate all available daily returns and save to data frame returns

2.3 Slices returns for the 2020s and assign to returns_2020s

2.4 Download all available data for the Fama and French daily benchmark factors to dictionary ff_all

I often use the following code snippet to find the exact name for the the daily benchmark factors file.

pdr.famafrench.get_available_datasets()[:5]
['F-F_Research_Data_Factors',
 'F-F_Research_Data_Factors_weekly',
 'F-F_Research_Data_Factors_daily',
 'F-F_Research_Data_5_Factors_2x3',
 'F-F_Research_Data_5_Factors_2x3_daily']

2.5 Slice the daily benchmark factors, convert them to decimal returns, and assign to ff

2.6 Use the .cumprod() method to plot cumulative returns for these stocks in the 2020s

2.7 Use the .cumsum() method with log returns to plot cumulative returns for these stocks in the 2020s

2.8 Use price data only to plot cumulative returns for these stocks in the 2020s

2.9 Calculate the Sharpe Ratio for TSLA

Calculate the Sharpe Ratio with all available returns and 2020s returns. Recall the Sharpe Ratio is \(\frac{\overline{R_i - R_f}}{\sigma_i}\), where \(\sigma_i\) is the volatility of excess returns.

I suggest you write a function named sharpe() to use for the rest of this notebook.

2.10 Calculate the market beta for TSLA

Calculate the market beta with all available returns and 2020s returns. Recall we estimate market beta with the ordinary least squares (OLS) regression \(R_i-R_f = \alpha + \beta (R_m-R_f) + \epsilon\). We can estimate market beta with the covariance formula above for a univariate regression if we do not need goodness of fit statistics.

I suggest you write a function named beta() to use for the rest of this notebook.

2.11 Guess the Sharpe Ratios for these stocks in the 2020s

2.12 Guess the market betas for these stocks in the 2020s

2.13 Calculate the Sharpe Ratios for these stocks in the 2020s

How good were your guesses?

2.14 Calculate the market betas for these stocks in the 2020s

How good were your guesses?

2.15 Calculate the Sharpe Ratio for an equally weighted portfolio of these stocks in the 2020s

What do you notice?

2.16 Calculate the market beta for an equally weighted portfolio of these stocks in the 2020s

What do you notice?

2.17 Calculate the market betas for these stocks every calendar year for every possible year

Save these market betas to data frame betas. Our current Python knowledge limits us to a for-loop, but we will learn easier and faster approaches soon!

2.18 Plot the time series of market betas