Thank you for watching the video and the comment! “Beta is a measure of the covariance of a stock with the market. It is calculated using regression analysis.” (campusguides.lib.utah.edu/c.php?g=160745&p=1052911#:~:text=Beta%20is%20also%20a%20measure,more%20volatile%20than%20the%20market.) We could calculate the beta with the numpy covariance function instead of direct regression: #Convert to arrays stock = np.array(stock_returns) market = np.array(market_returns) # Calculate covariance and variance covariance = np.cov(stock, market)[0][1] market_variance = np.var(market) # Calculate beta beta = covariance / market_variance print(f"Beta: {beta}")
Thank you, well explained.
Thank you for watching and your comment! Let me know if there’s other coding topics you’d like to see!
Why did you use regression for calculating alpha and beta?
Why didnt we use the CAPM formula?
Thank you for watching the video and the comment! “Beta is a measure of the covariance of a stock with the market. It is calculated using regression analysis.” (campusguides.lib.utah.edu/c.php?g=160745&p=1052911#:~:text=Beta%20is%20also%20a%20measure,more%20volatile%20than%20the%20market.)
We could calculate the beta with the numpy covariance function instead of direct regression:
#Convert to arrays
stock = np.array(stock_returns)
market = np.array(market_returns)
# Calculate covariance and variance
covariance = np.cov(stock, market)[0][1]
market_variance = np.var(market)
# Calculate beta
beta = covariance / market_variance
print(f"Beta: {beta}")