## Introduction

The Capital Asset Pricing Model (CAPM) is a financial model that helps investors calculate an investment’s expected return based on risk. It is based on the idea that investors demand a higher return for taking on more risk. The model considers the risk-free rate of return, the expected return of the market, and the investment’s beta (systematic risk).

CAPM is widely used in finance and investment management to help investors make informed decisions about their portfolios. It is also used in academic research to study the relationship between risk and return in financial markets.

### Assumptions

The assumptions of the Capital Asset Pricing Model (CAPM) are as follows:

- Investors are rational and risk-averse: Investors are assumed to be rational and risk-averse, meaning they will always choose the investment with the highest expected return for a given level of risk.
- Perfectly competitive markets: The market is assumed to be perfectly competitive, meaning that there are no barriers to entry or exit, and all investors have access to the same information.
- Homogeneous expectations: All investors have the same expectations about the market’s future performance and individual securities.
- No taxes or transaction costs: Taxes and transaction costs are assumed to be zero so that they do not affect investment decisions.
- Unlimited borrowing and lending: Investors can borrow and lend unlimited amounts of money at a risk-free rate of return.
- All assets are perfectly divisible: All assets are assumed to be perfectly divisible, meaning that investors can buy and sell any fraction of an asset.

These assumptions are important because they allow the model to predict the relationship between risk and return in financial markets. However, they are also idealised and may not always hold in the real world.

### Calculating Beta

In the Capital Asset Pricing Model (CAPM), the beta of an asset is a measure of its systematic risk or the risk that cannot be diversified away by holding a diversified portfolio. Beta is calculated as the covariance between the asset’s returns and the market’s returns, divided by the variance of the market returns.

Here’s the formula for calculating beta:

`beta = cov(asset returns, market returns) / var(market returns)`

Where cov is the covariance function, and var is the variance function.

In practice, you can estimate beta by regressing the asset’s returns against the market’s returns. The slope of the regression line is the beta of the asset. You can use statistical software such as Python’s NumPy or Pandas libraries to perform the regression and calculate beta.

It’s worth noting that beta is a relative measure of risk and is always calculated concerning the market. A beta of 1 indicates that the asset has the same level of risk as the market, while a beta greater than 1 indicates higher risk, and a beta less than 1 indicates lower risk.

### Expected Return

To calculate the expected return on an investment using the Capital Asset Pricing Model (CAPM), you can use the following formula:

`expected return = risk-free rate + beta * (market return - risk-free rate)`

Where:

- risk-free rate Is the rate of return on a risk-free investment, such as a government bond.
- beta Is the systematic risk of the investment as calculated using the formula I provided earlier.
- market return Is the expected return of the market.

The formula tells us that the expected return on investment equals the risk-free rate plus a risk premium, where the risk premium is proportional to the asset’s beta and the difference between the expected return of the market and the risk-free rate.

In practice, you can estimate the market’s expected return by using historical market data or analyst forecasts. You can also estimate the risk-free rate using the yield on a government bond with a maturity that matches the investment horizon.

Once you have estimated the risk-free rate, beta, and expected return of the market, you can plug them into the formula to calculate the expected return on the investment.

### Limitations

While the Capital Asset Pricing Model (CAPM) is a widely used and influential financial model, it has several limitations that should be considered when making investment decisions. Here are some of the main limitations of the CAPM model:

- Assumptions may not hold: The CAPM model relies on several idealized assumptions, such as perfectly competitive markets and homogeneous expectations, that may not hold in the real world. This can lead to inaccurate predictions and investment decisions.
- Beta may be difficult to estimate: Estimating the beta of an asset can be difficult, especially for assets that are not well-diversified or have a limited trading history. This can lead to inaccurate estimates of expected returns.
- Ignores non-systematic risk: The CAPM model only considers systematic risk, which cannot be diversified away by holding a diversified portfolio. It ignores non-systematic risk, or the risk that can be diversified away, which can be an important factor in investment decisions.
- Assumes linear relationship between risk and return: The CAPM model assumes a linear relationship between risk and return, meaning that higher risk always leads to higher returns. In reality, this relationship may be more complex and nonlinear.
- Limited scope: The CAPM model is designed to work for well-diversified portfolios of publicly traded securities. It may not apply to other types of investments, such as private equity or real estate.

Considering these limitations when using the CAPM model to make investment decisions is important. While the model can be useful for estimating expected returns, it should be used with other methods and with a critical eye towards its assumptions and limitations.

## A Worked Example

Suppose you are considering investing in a stock with a beta of 1.5. The risk-free rate is currently 2%, and the expected market return is 8%.

Using the CAPM formula, we can calculate the required rate of return for the stock as follows:

```
required rate of return = risk-free rate + beta * (market return - risk-free rate)
required rate of return = 0.02 + 1.5 * (0.08 - 0.02)
required rate of return = 0.02 + 1.5 * 0.06
required rate of return = 0.02 + 0.09
required rate of return = 0.11 or 11%
```

So, the required rate of return for the stock is 11%. This means that to justify investing in the stock, you would need to expect a return of at least 11%, given its level of risk as measured by its beta.

Remember that this is just an example, and the actual required rate of return for a stock will depend on various factors, including the stock’s beta, the risk-free rate, and the expected return of the market.

### Algorithm

A general algorithm for calculating the required rate of return using the Capital Asset Pricing Model (CAPM):

1. Input the risk-free rate, beta, and expected return of the market.

2. Calculate the risk premium by subtracting the risk-free rate from the expected market return.

3. Multiply the risk premium by the beta to get the asset’s risk premium.

4. Add the risk-free rate to the asset’s risk premium to get the required rate of return.

5. Output the required rate of return.

### Python Code

```
import numpy as np
def test_capm() -> None:
assert np.isclose(capm(0.02, 0.08, 1.5), 0.17, rtol=1e-2)
assert np.isclose(capm(0.01, 0.1, 0.8), 0.09, rtol=1e-2)
assert np.isclose(capm(0.03, 0.12, 1.2), 0.15, rtol=1e-2)
def capm(risk_free_rate: float, market_return: float, beta: float) -> float:
"""
Calculates the expected return of an asset using the Capital Asset Pricing Model (CAPM).
Parameters:
risk_free_rate (float): The risk-free rate of return.
market_return (float): The expected return of the market.
beta (float): The asset's beta.
Returns:
float: The expected return of the asset.
"""
return risk_free_rate + beta * (market_return - risk_free_rate)
```

C++

```
#include <iostream>
#include <cmath>
#include <cassert>
double calculate_required_rate_of_return(double risk_free_rate, double beta, double expected_market_return) {
// Calculate the risk premium
double risk_premium = expected_market_return - risk_free_rate;
// Calculate the asset's risk premium
double asset_risk_premium = beta * risk_premium;
// Calculate the required rate of return
double required_rate_of_return = risk_free_rate + asset_risk_premium;
// Return the required rate of return
return required_rate_of_return;
}
int main() {
// Test the CAPM formula
double risk_free_rate = 0.02;
double beta = 1.5;
double expected_market_return = 0.08;
double required_rate_of_return = calculate_required_rate_of_return(risk_free_rate, beta, expected_market_return);
// Check that the result is within 0.01 of the expected value
assert(fabs(required_rate_of_return - 0.11) < 0.01);
// Test with different inputs
risk_free_rate = 0.01;
beta = 0.8;
expected_market_return = 0.12;
required_rate_of_return = calculate_required_rate_of_return(risk_free_rate, beta, expected_market_return);
// Check that the result is within 0.01 of the expected value
assert(fabs(required_rate_of_return - 0.106) < 0.01);
std::cout << "All tests passed!" << std::endl;
return 0;
}
```

## The last byte…

The Capital Asset Pricing Model (CAPM) is a widely used tool for estimating an asset’s required rate of return based on its risk level. The model considers the risk-free rate, the expected return of the market, and the asset’s beta, which measures its sensitivity to market movements.

While the CAPM has its limitations and critics, it remains useful for investors and financial analysts. Using the CAPM, investors can estimate the expected return of an asset and compare it to the required rate of return to determine whether the asset is overvalued or undervalued.

To use the CAPM effectively, it’s important to understand its assumptions and limitations and to use it in conjunction with other tools and techniques for financial analysis. By combining the CAPM with other models and methods, investors can better understand the risks and returns associated with different investments.

Overall, the CAPM is a valuable tool for investors and financial analysts, and its insights can help guide investment decisions and portfolio management strategies.

inC++## Capital Asset Pricing Model (CAPM)

byAli Kayani