Capital Asset Pricing Model (CAPM) [Loxx]

loxx Premium Cập nhật   
Capital Asset Pricing Model (CAPM) demonstrates how to calculate the Cost of Equity for an underlying asset using Pine Script. This script will only work on the monthly timeframe . While you can change the default inputs, you should study what CAPM is and how this works before doing so. This indicator pulls various types of data from SPY from various timeframes to calculate risk-free rates, market premiums, and log returns. Alpha and Beta are computed using the regression between underlying asset and SPY . This indicator only calculates on the most recent data. If you wish to change this, you'll have to save the script and make adjustments. A few examples where CAPM is used:

  • Used as the mu factor Geometric Brownian Motion models for options pricing and forecasting price ranges and decay
  • Calculating the Weighted Average Cost of Capital
  • Asset pricing
  • Efficient frontier
  • Risk and diversification
  • Security market line
  • Discounted Cashflow Analysis
  • Investment bankers use CAPM to value deals
  • Account firms use CAPM to verify asset prices and assumptions
  • Real estate firms use variations of CAPM to value properties
  • ... and more

Details of the calculations used here
  • Rm is calculated using yearly simple returns data from SPY , typically this is just hard coded as 10%.
  • Rf is pulled from US 10 year bond yields
  • Beta and Alpha are pulled form monthly returns data of the asset and SPY

In the past, typically this data is purchased from investments banks whose research arms produce values for beta, alpha, risk free rate, and risk premiums. In 2022 ,you can find free estimates for each parameter but these values might not reflect the most current data or research.

The CAPM was introduced by Jack Treynor (1961, 1962), William F. Sharpe (1964), John Lintner (1965) and Jan Mossin (1966) independently, building on the earlier work of Harry Markowitz on diversification and modern portfolio theory. Sharpe, Markowitz and Merton Miller jointly received the 1990 Nobel Memorial Prize in Economics for this contribution to the field of financial economics. Fischer Black (1972) developed another version of CAPM, called Black CAPM or zero-beta CAPM, that does not assume the existence of a riskless asset. This version was more robust against empirical testing and was influential in the widespread adoption of the CAPM.

The CAPM is used to calculate the amount of return that investors need to realize to compensate for a particular level of risk. It subtracts the risk-free rate from the expected rate and weighs it with a factor – beta – to get the risk premium. It then adds the risk premium to the risk-free rate of return to get the rate of return an investor expects as compensation for the risk. The CAPM formula is expressed as follows:

r = Rf + beta ( Rm Rf ) + Alpha


Alpha = R – Rf – beta (Rm-Rf)


  • R represents the portfolio return
  • Rf represents the risk-free rate of return
  • Beta represents the systematic risk of a portfolio
  • Rm represents the market return, per a benchmark

For example, assuming that the actual return of the fund is 30, the risk-free rate is 8%, beta is 1.1, and the benchmark index return is 20%, alpha is calculated as:

Alpha = (0.30-0.08) – 1.1 (0.20-0.08) = 0.088 or 8.8%

The result shows that the investment in this example outperformed the benchmark index by 8.8%.

The alpha of a portfolio is the excess return it produces compared to a benchmark index. Investors in mutual funds or ETFs often look for a fund with a high alpha in hopes of getting a superior return on investment (ROI).

The alpha ratio is often used along with the beta coefficient, which is a measure of the volatility of an investment. The two ratios are both used in the Capital Assets Pricing Model (CAPM) to analyze a portfolio of investments and assess its theoretical performance.

To see CAPM in action in terms of calculate WACC , see here for an example: https://finbox.com/NASDAQGS:GOOG/models/wacc

Further reading
Phát hành các Ghi chú:
Fixed table output error.
Phát hành các Ghi chú:
Updated to work on all timeframes. This won't actually make the indicator work on ll timeframes, but allows you the user to use the constant output on all timeframes. Past beta values are not calculated, only the current month beta is calculated.
Phát hành các Ghi chú:
Removed unused code.

Public Telegram Group, t.me/algxtrading_public

VIP Membership Info: www.patreon.com/algxtrading/membership
Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?