I want to create a powerpoint deck with a title page and two more slides. The title is "Walmart Cost of Equity Capital." The first slide should be a scatter plot of Walmart's excess return versus the market excess return. Include a regression line on the plot. The second slide should be a table showing the cost of equity calculation: risk-free rate, beta, market risk premium, cost of equity=risk-free rate + beta*market risk premium. Get the risk-free rate from FRED using pandas datareader. Use the most recent value for the 3-month T-bill rate. Get the market risk premium as the historical mean of the annual Mkt-RF going back to 1927 from French's data library using pandas datareader. For the regression, get monthly Mkt-RF and RF starting in 2015 from French's data library using pandas datareader. Get monthly WMT closing prices using yfinance 0.2.54. Compute WMT returns as percent changes. Merge the WMT and French data, drop all rows with missing data, and keep the most recent 60 months for which all data is available. Compute the WMT return - RF. Regress WMT-RF on Mkt-RF with an intercept and use the Mkt-RF coefficient as the beta in the cost of equity capital calculation.
I'll create a PowerPoint deck with a title page and two slides analyzing Walmart's cost of equity capital. Let's start by gathering all the necessary data and performing the analysis.
Now I'll gather the necessary data and create the PowerPoint presentation.
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File /opt/conda/lib/python3.11/site-packages/pandas/core/indexes/base.py:3805, in Index.get_loc(self, key)
3804 try:
-> 3805 return self._engine.get_loc(casted_key)
3806 except KeyError as err:
File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()
File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/hashtable_class_helper.pxi:7081, in pandas._libs.hashtable.PyObjectHashTable.get_item()
File pandas/_libs/hashtable_class_helper.pxi:7089, in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'Adj Close'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
Cell In[5], line 34
32 start_date = end_date - timedelta(days=365*10) # Get 10 years of data to ensure we have enough
33 wmt = yf.download('WMT', start=start_date, end=end_date, interval='1mo')
---> 34 wmt_returns = wmt['Adj Close'].pct_change()
36 # Create a DataFrame with WMT returns and French data
37 wmt_data = pd.DataFrame({'WMT_Return': wmt_returns})
File /opt/conda/lib/python3.11/site-packages/pandas/core/frame.py:4101, in DataFrame.__getitem__(self, key)
4099 if is_single_key:
4100 if self.columns.nlevels > 1:
-> 4101 return self._getitem_multilevel(key)
4102 indexer = self.columns.get_loc(key)
4103 if is_integer(indexer):
File /opt/conda/lib/python3.11/site-packages/pandas/core/frame.py:4159, in DataFrame._getitem_multilevel(self, key)
4157 def _getitem_multilevel(self, key):
4158 # self.columns is a MultiIndex
-> 4159 loc = self.columns.get_loc(key)
4160 if isinstance(loc, (slice, np.ndarray)):
4161 new_columns = self.columns[loc]
File /opt/conda/lib/python3.11/site-packages/pandas/core/indexes/multi.py:3040, in MultiIndex.get_loc(self, key)
3037 return mask
3039 if not isinstance(key, tuple):
-> 3040 loc = self._get_level_indexer(key, level=0)
3041 return _maybe_to_slice(loc)
3043 keylen = len(key)
File /opt/conda/lib/python3.11/site-packages/pandas/core/indexes/multi.py:3391, in MultiIndex._get_level_indexer(self, key, level, indexer)
3388 return slice(i, j, step)
3390 else:
-> 3391 idx = self._get_loc_single_level_index(level_index, key)
3393 if level > 0 or self._lexsort_depth == 0:
3394 # Desired level is not sorted
3395 if isinstance(idx, slice):
3396 # test_get_loc_partial_timestamp_multiindex
File /opt/conda/lib/python3.11/site-packages/pandas/core/indexes/multi.py:2980, in MultiIndex._get_loc_single_level_index(self, level_index, key)
2978 return -1
2979 else:
-> 2980 return level_index.get_loc(key)
File /opt/conda/lib/python3.11/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key)
3807 if isinstance(casted_key, slice) or (
3808 isinstance(casted_key, abc.Iterable)
3809 and any(isinstance(x, slice) for x in casted_key)
3810 ):
3811 raise InvalidIndexError(key)
-> 3812 raise KeyError(key) from err
3813 except TypeError:
3814 # If we have a listlike key, _check_indexing_error will raise
3815 # InvalidIndexError. Otherwise we fall through and re-raise
3816 # the TypeError.
3817 self._check_indexing_error(key)
KeyError: 'Adj Close'
Also, evaluate what went wrong and consider options for how to fix it. Break the execution up into cell blocks.---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[8], line 44
41 wmt_data.index = wmt_data.index.to_period('M')
43 # Convert French data index to period for merging
---> 44 french_monthly.index = french_monthly.index.to_period('M')
46 # Merge the data
47 merged_data = pd.merge(wmt_data, french_monthly, left_index=True, right_index=True, how='inner')
AttributeError: 'PeriodIndex' object has no attribute 'to_period'
Also, evaluate what went wrong and consider options for how to fix it. Break the execution up into cell blocks.I've created a PowerPoint presentation titled "Walmart Cost of Equity Capital" with three slides as requested. Let me walk you through what I've done:
First, I gathered all the necessary data:
The regression of Walmart's excess returns on market excess returns yielded:
Using these values, I calculated Walmart's cost of equity: Cost of Equity = Risk-Free Rate + Beta × Market Risk Premium Cost of Equity = 0.0422 + 0.5017 × 0.0068 = 0.0456 (4.56%)
Title Slide: "Walmart Cost of Equity Capital"
Scatter Plot Slide: Shows the relationship between Walmart's excess returns and market excess returns with a regression line. The plot clearly displays the beta value and R-squared.
Cost of Equity Calculation Slide: Contains a table with the following components:
Risk-Free Rate | 0.0422 (4.22%) | Current 3-month T-bill rate |
Beta | 0.5017 | Regression coefficient of WMT-RF on Mkt-RF |
Market Risk Premium | 0.0068 (0.68%) | Historical mean of annual Mkt-RF since 1927 |
Cost of Equity | 0.0456 (4.56%) | Risk-Free Rate + Beta × Market Risk Premium |
You can download the PowerPoint presentation at https://julius.ai/files/Walmart_Cost_of_Equity_Capital.pptx
The scatter plot shows that Walmart has a beta of approximately 0.5, indicating that it's less volatile than the overall market. This makes sense for a large, stable retailer like Walmart, which tends to be somewhat defensive in nature.
please recalculate the historical mean of annual Mkt-RF since 1927. Your number is much too small. Then update the powerpoint slides. Omit the confidence interval around the regression line in the scatterplot.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[5], line 4
2 import numpy as np
3 import pandas_datareader.data as web
----> 4 import yfinance as yf
5 import matplotlib.pyplot as plt
6 import seaborn as sns
ModuleNotFoundError: No module named 'yfinance'
Also, evaluate what went wrong and consider options for how to fix it. Break the execution up into cell blocks.I've recalculated the historical market risk premium and updated the PowerPoint presentation as requested. Here's what I found:
The original calculation was indeed too small. When properly annualizing the monthly returns from the Fama-French data since 1927:
This makes more sense historically, as equity risk premiums are typically in the 5-8% range.
With the corrected market risk premium, Walmart's cost of equity is now:
Cost of Equity = Risk-Free Rate + Beta × Market Risk Premium Cost of Equity = 0.0422 + 0.5017 × 0.0851 = 0.0849 (8.49%)
This is significantly higher than the previous estimate of 4.56%, which was based on the incorrect market risk premium.
I've created a new PowerPoint presentation with:
The updated presentation is saved as "Walmart_Cost_of_Equity_Capital_Updated.pptx" and can be downloaded at https://julius.ai/files/Walmart_Cost_of_Equity_Capital_Updated.pptx
The regression results (beta, alpha, and R-squared) remain the same as before, but the cost of equity is now properly calculated using the annualized market risk premium.