Introduction

In this notebook, we will explore Modern Portfolio Theory (MPT) and construct the Efficient Frontier for a portfolio of three stocks: Amazon (AMZN), Coca-Cola (KO), and Microsoft (MSFT). The Efficient Frontier represents the set of optimal portfolios that offer the highest expected return for a given level of risk.

By the end of this notebook, you will:

Step 1: Import Libraries and Define Tickers

We start by importing the necessary libraries and defining the tickers for our portfolio.

Step 2: Fetch Historical Data

We use yfinance to download historical stock prices for the selected tickers. The data is fetched from January 1, 2011, to January 1, 2019.

Step 3: Compute Daily Returns

We calculate the daily returns for each stock using the closing prices. Daily returns are essential for computing annualized returns and the covariance matrix.

The daily return for a stock is calculated as:

$$ R_t = \frac{P_t - P_{t-1}}{P_{t-1}} $$

where:

Step 4: Compute Annualized Returns and Covariance Matrix

We annualize the daily returns and compute the covariance matrix of daily returns. These metrics are crucial for portfolio optimization.

Annualized Returns

The annualized return is calculated as:

$$ \text{Annualized Return} = \left( \prod_{t=1}^{T} (1 + R_t) \right)^{\frac{n}{T}} - 1 $$

where:

Covariance Matrix

The covariance matrix $\Sigma$ is computed as:

$$ \Sigma_{ij} = \text{Cov}(R_i, R_j) $$

where $R_i$ and $R_j$ are the returns of assets $i$ and $j$, respectively.

Step 5: Simulate Random Portfolios

We simulate thousands of random portfolios by assigning random weights to the assets. For each portfolio, we compute the annualized return, volatility, and Sharpe ratio.

Portfolio Return

The portfolio return $R_p$ is calculated as:

$$ R_p = \sum_{i=1}^{N} w_i \cdot R_i $$

where:

Portfolio Volatility

The portfolio volatility $\sigma_p$ is calculated as:

$$ \sigma_p = w^T \Sigma w $$

where:

Sharpe Ratio

The Sharpe ratio $S$ is calculated as:

$$ S = \frac{R_p - R_f}{\sigma_p} $$

where:

Step 6: Identify Key Portfolios

From the simulated portfolios, we identify two key portfolios:

Step 7: Plot the Efficient Frontier

We visualize the simulated portfolios and the Efficient Frontier. The GMV and MSR portfolios are highlighted on the plot.

Step 8: Conclusion

In this notebook, we:

The Efficient Frontier plot provides a visual representation of the optimal portfolios. The GMV Portfolio represents the portfolio with the lowest risk, while the MSR Portfolio offers the highest return per unit of risk. These portfolios are essential for investors seeking to optimize their portfolios based on their risk tolerance.

Backtest Results: Portfolio Performance Comparison

The chart above compares the cumulative returns of three different portfolio strategies:

Key Observations:

  1. Performance: The Maximum Sharpe Ratio (MSR) portfolio outperforms the other two, delivering the highest cumulative return over time.
  2. Risk vs. Return: The Global Minimum Variance (GMV) portfolio has the lowest volatility, leading to a smoother but lower return trajectory.
  3. Balanced Approach: The Equal-Weighted portfolio lies between the two in terms of performance and risk, benefiting from diversification.

These results highlight the trade-offs between risk and return when selecting an optimal portfolio strategy.