Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Diversification and Portfolio Optimization | Investment Metrics and Portfolio Analysis
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Investors

bookDiversification and Portfolio Optimization

Diversification is a fundamental concept in investing that involves spreading your investments across different assets to reduce overall risk. By holding a mix of assets that do not move perfectly in sync, you can potentially lower the impact of any single asset's poor performance on your entire portfolio. The main benefit of diversification is risk reduction without necessarily sacrificing expected returns. This is possible because the prices of different assets often do not move together, so losses in one can be offset by gains in another.

Portfolio optimization takes diversification a step further by using mathematical techniques to determine the best asset allocation for a given objective, such as maximizing expected return for a certain level of risk or minimizing risk for a target return. In its simplest form, portfolio optimization involves adjusting the weights of assets in your portfolio to find the most efficient balance between risk and return. The process relies on estimates of each asset's expected return, volatility, and their correlations.

12345678910111213141516171819202122232425262728
import numpy as np import pandas as pd # Simulated historical returns for three assets np.random.seed(42) returns = pd.DataFrame({ "Stock_A": np.random.normal(0.08/252, 0.15/np.sqrt(252), 252), "Stock_B": np.random.normal(0.06/252, 0.10/np.sqrt(252), 252), "Stock_C": np.random.normal(0.09/252, 0.20/np.sqrt(252), 252), }) num_portfolios = 5000 results = np.zeros((num_portfolios, 3)) # columns: return, volatility, weight_A for i in range(num_portfolios): weights = np.random.random(3) weights /= np.sum(weights) portfolio_return = np.sum(returns.mean() * weights) * 252 portfolio_volatility = np.sqrt( np.dot(weights.T, np.dot(returns.cov() * 252, weights)) ) results[i, 0] = portfolio_return results[i, 1] = portfolio_volatility results[i, 2] = weights[0] # just as an example, store weight of Stock_A # Create a DataFrame for easier analysis portfolios = pd.DataFrame(results, columns=["Return", "Volatility", "Weight_A"]) print(portfolios.head())
copy

The simulation above generates thousands of random portfolios by assigning different weights to three hypothetical assets. For each portfolio, it calculates the expected annual return and volatility (risk). This approach helps visualize the range of possible risk-return combinations you might achieve through diversification. Typically, you will notice that as you aim for higher returns, you must accept higher risk, and vice versa. This relationship is at the heart of the risk-return trade-off in investing. Diversification allows you to achieve a more favorable balance, potentially reducing risk for the same level of return compared to investing in a single asset.

123456789
import matplotlib.pyplot as plt plt.figure(figsize=(8, 6)) plt.scatter(portfolios["Volatility"], portfolios["Return"], c=portfolios["Return"] / portfolios["Volatility"], cmap="viridis", alpha=0.5) plt.xlabel("Volatility (Risk)") plt.ylabel("Expected Return") plt.title("Simulated Efficient Frontier") plt.colorbar(label="Sharpe Ratio") plt.show()
copy

1. What is the main goal of diversification?

2. How does portfolio optimization help investors?

3. What does each point on a risk-return scatter plot represent?

question mark

What is the main goal of diversification?

Select the correct answer

question mark

How does portfolio optimization help investors?

Select the correct answer

question mark

What does each point on a risk-return scatter plot represent?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 6

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

bookDiversification and Portfolio Optimization

Veeg om het menu te tonen

Diversification is a fundamental concept in investing that involves spreading your investments across different assets to reduce overall risk. By holding a mix of assets that do not move perfectly in sync, you can potentially lower the impact of any single asset's poor performance on your entire portfolio. The main benefit of diversification is risk reduction without necessarily sacrificing expected returns. This is possible because the prices of different assets often do not move together, so losses in one can be offset by gains in another.

Portfolio optimization takes diversification a step further by using mathematical techniques to determine the best asset allocation for a given objective, such as maximizing expected return for a certain level of risk or minimizing risk for a target return. In its simplest form, portfolio optimization involves adjusting the weights of assets in your portfolio to find the most efficient balance between risk and return. The process relies on estimates of each asset's expected return, volatility, and their correlations.

12345678910111213141516171819202122232425262728
import numpy as np import pandas as pd # Simulated historical returns for three assets np.random.seed(42) returns = pd.DataFrame({ "Stock_A": np.random.normal(0.08/252, 0.15/np.sqrt(252), 252), "Stock_B": np.random.normal(0.06/252, 0.10/np.sqrt(252), 252), "Stock_C": np.random.normal(0.09/252, 0.20/np.sqrt(252), 252), }) num_portfolios = 5000 results = np.zeros((num_portfolios, 3)) # columns: return, volatility, weight_A for i in range(num_portfolios): weights = np.random.random(3) weights /= np.sum(weights) portfolio_return = np.sum(returns.mean() * weights) * 252 portfolio_volatility = np.sqrt( np.dot(weights.T, np.dot(returns.cov() * 252, weights)) ) results[i, 0] = portfolio_return results[i, 1] = portfolio_volatility results[i, 2] = weights[0] # just as an example, store weight of Stock_A # Create a DataFrame for easier analysis portfolios = pd.DataFrame(results, columns=["Return", "Volatility", "Weight_A"]) print(portfolios.head())
copy

The simulation above generates thousands of random portfolios by assigning different weights to three hypothetical assets. For each portfolio, it calculates the expected annual return and volatility (risk). This approach helps visualize the range of possible risk-return combinations you might achieve through diversification. Typically, you will notice that as you aim for higher returns, you must accept higher risk, and vice versa. This relationship is at the heart of the risk-return trade-off in investing. Diversification allows you to achieve a more favorable balance, potentially reducing risk for the same level of return compared to investing in a single asset.

123456789
import matplotlib.pyplot as plt plt.figure(figsize=(8, 6)) plt.scatter(portfolios["Volatility"], portfolios["Return"], c=portfolios["Return"] / portfolios["Volatility"], cmap="viridis", alpha=0.5) plt.xlabel("Volatility (Risk)") plt.ylabel("Expected Return") plt.title("Simulated Efficient Frontier") plt.colorbar(label="Sharpe Ratio") plt.show()
copy

1. What is the main goal of diversification?

2. How does portfolio optimization help investors?

3. What does each point on a risk-return scatter plot represent?

question mark

What is the main goal of diversification?

Select the correct answer

question mark

How does portfolio optimization help investors?

Select the correct answer

question mark

What does each point on a risk-return scatter plot represent?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 6
some-alt