The Capital Asset Pricing Model: Learn financial analysis in Python

corporate training and solutions

The Capital Asset Pricing Model: Learn financial analysis in Python

What is CAPM?

The Capital Asset Pricing Model (CAPM) is the relationship between systematic risk and expected return for assets, especially stocks. In simple terms, the CAPM model generates the expected return for any asset, like stocks, by analyzing the risks involved. CAPM is usually determined by financial analysts.

Mathematically, CAPM is represented as,



ri is the expected return of a security

rf is the risk-free rate

βi is the beta of the security relative to the market

rm−rf is the risk premium

What is Python?

Python is a high-level programming language used for complex and dynamic analysis and problem-solving in various fields, and one such field is finance. Python is becoming the first choice of many financial organizations because of its versatile, dynamic, robust, and easy-to-learn nature. Financial analysts use Python rigorously on an everyday basis, especially for stock analysis.

This article will help you get a brief idea about what Imarticus offers in the Financial Modelling Course of Capital Asset Pricing Model: Learn financial analysis in Python.

Capital Asset Pricing Model with Python

Step 1: Download the data. This data consists of the price of stocks for any company or company for the required period.

Step 2: Organise the data using suitable functions like "concatenate."

Step 3: Normalise the data with the help of the "normalize" function. Normalization is done by dividing all prices of each stock by its first value price. It is done to make different stock prices comparable.

Step 4: Verify the output. Then plot the graph for different prices of the stocks for performance comparison.

Step 5: Analyse and interpret the plot. 

Step 6: Calculate the daily returns using the 'daily_return' function.

Step 7: Once the data normalization is done and daily returns are calculated, CAPM can be applied to calculate the risk-adjusted expected return. For this, the value of beta is calculated first. Beta is the measure of a stock's volatility compared to the overall market's volatility. The beta value of the market is 1. The stocks with beta values more than 1 are more volatile than the market, and the stocks with beta values less than 1 are less volatile than the market.

Step 8: Once we have the beta value for all the stocks, we can apply the CAPM estimation according to the following formula,

ER= rf + beta* (rm-rf)

Step 9: Finally, we calculate the expected return for each stock in the portfolio. The expected portfolio return can be calculated by multiplying the portfolio weights by the sum of expected returns for the individual stocks using the 'portfolio_weights' function.

 The CAPM has many advantages, like calculating the expected return with accuracy. It helps financial analysts analyze their portfolio, calculate the expected return, determine how relevant an investment can be, and do any rebalancing of investments and correction of the portfolio if required. Moreover, the CAPM formula is comparatively easy. It is one of the very few formulas that help calculate systematic risk. But some critics say that the CPM model can never be accurate and that it is too good to be a true formula to calculate all the components for an investment accurately.

The main idea while using CAPM is to calculate the expected return of any asset after analyzing the systematic risks involved. An ideal situation would be if the return is high and the risk involved is low.

If you want to find the correct stock to invest in and reduce the risks involved, a financial analyst or Imarticus's Financial Modelling Courses can help you. You can contact us through our 24*7 chat support or drive to any training centers in Mumbai, Thane, Pune, Chennai, Bengaluru, Delhi, and Gurgaon

Share This Post

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Our Programs

Do You Want To Boost Your Career?

drop us a message and keep in touch