How to Calculate Alpha and Beta of a Stock in Python

Поділитися
Вставка
  • Опубліковано 17 січ 2025

КОМЕНТАРІ • 4

  • @jburns3210
    @jburns3210 2 місяці тому +1

    Thank you, well explained.

    • @Intrendias
      @Intrendias  2 місяці тому

      Thank you for watching and your comment! Let me know if there’s other coding topics you’d like to see!

  • @vidittayal
    @vidittayal Місяць тому +2

    Why did you use regression for calculating alpha and beta?
    Why didnt we use the CAPM formula?

    • @Intrendias
      @Intrendias  Місяць тому

      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}")