Date: Apr 20,2026
In this analysis, we aim to optimize a portfolio of various Exchange Traded Funds (ETFs) using Modern Portfolio Theory (MPT). The goal is to find the optimal allocation for each ETF to maximize returns while minimizing risk. We will calculate the efficient frontier, the Sharpe ratio, and determine the optimal weights for each ETF in the portfolio.
#Data Retrieval We use the yfinance Python library to retrieve historical price data for each ETF in our list. The data includes the adjusted closing prices, which are crucial for accurate return calculations.
We read the CSV files saved in the specified directory and convert them to time series data. Each file is assumed to contain cdates in the first column and prices in the second column, without headers.
Calculate the daily returns from the adjusted closing prices.
Modern Portfolio Theory (MPT) aims to construct a portfolio that offers the maximum expected return for a given level of risk. Using MPT, we can plot the efficient frontier, which shows the best possible returns for a specific level of risk.
The Sharpe ratio helps to assess the risk-adjusted return of a portfolio. A higher Sharpe ratio indicates a more favorable risk-return profile.
The tangency portfolio is the portfolio with the highest Sharpe ratio. Here, we determine the optimal allocation for each ETF in the portfolio.
## Percentages Tickers
## SGOV 26.030438 SGOV
## GLD 9.788462 GLD
## XLV 2.000000 XLV
## XLP 2.000000 XLP
## XLU 8.139131 XLU
## VIG 35.000000 VIG
## XLE 12.981812 XLE
## SCHD 4.060156 SCHD
We visualize the optimized allocation of each ETF in the portfolio using a bar chart.
Here, we calculate the key metrics for the optimized portfolio, including the annualized return, risk, and Sharpe ratio.
## **Portfolio Average Return:** 17.97 %
## **Portfolio Standard Deviation:** 5.62 %
## **Portfolio Sharpe Ratio:** 2.84
This analysis demonstrates how to optimize a portfolio of ETFs using Modern Portfolio Theory, calculate the efficient frontier, and determine the ideal allocation for each asset to achieve the best risk-adjusted return. The resulting optimized portfolio is designed to balance risk and return according to the specified constraints.