Giter Site home page Giter Site logo

nikoelvambuena95 / financialanalysis_portfoliotheorybasics Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 124 KB

Basics of modern portfolio theory demonstrated via Python for efficiency

Jupyter Notebook 100.00%
data-analysis data-visualization financial-analysis financial-data jupyter-notebook python python3 stooq stooq-finance-api niko-elvambuena

financialanalysis_portfoliotheorybasics's Introduction

Portfolio Theory Basics: The Efficient Frontier, the CAPM, and the Sharpe Ratio

In this project I outline the beginning foundation of modern portfolio theory and its underlying basics. I calculate and graph key portfolio performance indicators - the Efficient Frontier, the CAPM, and the Sharpe Ratio - using Python. Hopefully this highlights how powerful, efficient, and informative using programming is for financial analysis.


Markowitz's Efficient Frontier

Harry Markowitz was an American economist that created the Efficient Frontier model in 1952. This model finds optimal asset portfolios that give the highest returns with minimal risk. To achieve this optimal portfolio, different weights for assets in the portfolio are used to produce desired returns. This concept is central to the risk-return trade-off at the cornerstone of modern portfolio management philosophies.

To find the Efficient Frontier, also known as Markowitz's Bullet, we plot the Expected Return on the y-axis and the Portfolio Risk (as Standard Deviation) on the x-axis.

To calculate the Expected Return we use the formula below:

$R = (w_{1}*r_{1}) + (w_{2}*r_{2}) + (w_{3}*r_{3}) + ...$

  • Expected Return ($R$)
  • Portfolio Weight of Asset ($w_{x}$)
  • Rate of Return of Asset ($r_{x}$)

By using this formula with various assets' weights we can calculate different Expected Returns for a portfolio.

To calculate the Portfolio Risk we use the formula below:

$\sigma P = \sqrt{(w_{1}^{2}*\sigma_{1}^{2})+(w_{2}^{2}*\sigma_{2}^{2})+((2*Corr)*\sigma_{1}*\sigma_{2}})$

  • Portfolio Risk ($\sigma P$)
  • Portfolio Weight of Asset ($w_{x}$)
  • Standard Deviation of Asset ($\sigma_{x}$)
  • Correlation Coefficient ($Corr$)

Lucky for us, all these calculations can be handled using Python.

The Capital Asset Pricing Model

The Capital Assest Pricing Model (CAPM) formula:

$r_{i} = r_{f} + \beta_{im}(r_{m}-r_{f})$

The CAPM is a measure of the the risk and return of a security investment. There are three essential components to the CAPM:

  • Risk-Free Return ($r_{f}$)
  • Market Risk Premium ($r_{m}-r_{f}$)
  • Beta of the investment ($\beta_{im}$)

The Risk-Free Return ($r_{f}$) is the value of an investment that carries zero risk. In reality there is no investment that carries a true risk rate equal to zero. A close investment that actually nears zero is the US 10-year government bond. This is because the US government is extremely unlikely not to pay back its bond holders - hence the near risk-free status and why it is often used in CAPM calculations for US markets.

The Market Risk Premium $(r_{m}-r_{f})$ is the return that is expected from the portfolio beyond the risk-free assets. This premium rate is a strong determinant in whether or not pursuing the given portfolio will produce significant returns. In other words, this return is crucial in measuring portfolio performance in the CAPM.

The Beta ($\beta_{im}$) is a measure of the stock's volatility. More specifically, this component of the CAPM is a measure of the idiosyncratic or unsystematic risk. This is the risk that can be mitigated through investment diversification throughout a portfolio.

Beta value

We get the Beta ($\beta$) value using the formula below:

$\large \beta = {Cov(r_{x},r_{m}) \over \sigma^{2}_{m}}$

The Beta value indicates the relationship the investment has in relation to the market. In other words, this metric will show if an investment will or will not behave similarly to the rest of the market.

If $\beta = 0$, then the stock behaves indepdently of the market.

If $\beta < 1$, then the stock is defensive because they will lose less in poor markets - i.e. they are safe in poor markets.

If $\beta = 1$, then the stock performs the same as the market.

If $\beta > 1$, then the stock is aggresive because they are riskier investments BUT they perform better than the market.

The Sharpe Ratio

The Sharpe ratio formula:

$\large {r_{i}-r_{f} \over\sigma_{i}}$

  • Risk-Free Return ($r_{f}$)
  • Return of the investment ($r_{i}$)
  • Standard Deviation of the investment ($\sigma_{i}$)

The Sharpe ratio is a metric used to calculate an investment or portfolio's risk-adjusted return. It also highlights any additional return that is gained after taking on the risk.

Considered simply, a higher Sharpe ratio or index indicates a better return relative to the risk of the investment or the relationship of the investments in the portfolio.

financialanalysis_portfoliotheorybasics's People

Contributors

nikoelvambuena95 avatar

Watchers

 avatar

Forkers

wy6688

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.