Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Optimize a Three-Asset Portfolio | Risk Analysis and Portfolio Optimization
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Financial Analysts

bookChallenge: Optimize a Three-Asset Portfolio

As you have learned, mean-variance optimization is a cornerstone of modern portfolio theory. It allows you to select asset weights that maximize expected return for a given level of risk, or minimize risk for a given expected return. However, in practice, the analytical solution can become complex, especially with more assets and constraints. This is where simulation-based approaches—such as Monte Carlo simulations—become powerful. By generating thousands of random portfolios and calculating their risk and return, you can visualize the opportunity set and identify optimal portfolios based on your chosen criteria, such as the Sharpe ratio.

1234567891011121314
import numpy as np # Example expected annual returns for three assets expected_returns = np.array([0.08, 0.12, 0.10]) # Asset A, B, C # Example standard deviations (annualized) std_devs = np.array([0.15, 0.20, 0.18]) # Example correlation matrix correlation_matrix = np.array([ [1.0, 0.3, 0.5], [0.3, 1.0, 0.4], [0.5, 0.4, 1.0] ])
copy

To proceed, you will first need to construct the covariance matrix using the standard deviations and correlation matrix. Then, simulate 10,000 random portfolios by generating random weights for each asset (ensuring all weights are non-negative and sum to one—no short selling). For each simulated portfolio, calculate the expected return as the weighted sum of asset returns, and the risk as the portfolio's standard deviation using the covariance matrix. Finally, plot all simulated portfolios on a scatter plot of risk (x-axis) versus return (y-axis), and highlight the portfolio with the highest Sharpe ratio (assuming a risk-free rate of zero).

Aufgabe

Swipe to start coding

Construct a simulation that generates 10,000 random three-asset portfolios, calculates their expected return and risk, and identifies the optimal portfolio by Sharpe ratio.

  • Build the covariance matrix from the given standard deviations and correlation matrix.
  • Generate random weights for each portfolio, ensuring all weights are non-negative and sum to one.
  • For each portfolio, compute expected return as the weighted sum of expected returns.
  • For each portfolio, compute risk as the standard deviation using the covariance matrix.
  • Calculate the Sharpe ratio for each portfolio, assuming a risk-free rate of zero.
  • Identify the portfolio with the highest Sharpe ratio.
  • Plot all simulated portfolios on a risk-return scatter plot, highlighting the optimal portfolio.

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 5
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

close

bookChallenge: Optimize a Three-Asset Portfolio

Swipe um das Menü anzuzeigen

As you have learned, mean-variance optimization is a cornerstone of modern portfolio theory. It allows you to select asset weights that maximize expected return for a given level of risk, or minimize risk for a given expected return. However, in practice, the analytical solution can become complex, especially with more assets and constraints. This is where simulation-based approaches—such as Monte Carlo simulations—become powerful. By generating thousands of random portfolios and calculating their risk and return, you can visualize the opportunity set and identify optimal portfolios based on your chosen criteria, such as the Sharpe ratio.

1234567891011121314
import numpy as np # Example expected annual returns for three assets expected_returns = np.array([0.08, 0.12, 0.10]) # Asset A, B, C # Example standard deviations (annualized) std_devs = np.array([0.15, 0.20, 0.18]) # Example correlation matrix correlation_matrix = np.array([ [1.0, 0.3, 0.5], [0.3, 1.0, 0.4], [0.5, 0.4, 1.0] ])
copy

To proceed, you will first need to construct the covariance matrix using the standard deviations and correlation matrix. Then, simulate 10,000 random portfolios by generating random weights for each asset (ensuring all weights are non-negative and sum to one—no short selling). For each simulated portfolio, calculate the expected return as the weighted sum of asset returns, and the risk as the portfolio's standard deviation using the covariance matrix. Finally, plot all simulated portfolios on a scatter plot of risk (x-axis) versus return (y-axis), and highlight the portfolio with the highest Sharpe ratio (assuming a risk-free rate of zero).

Aufgabe

Swipe to start coding

Construct a simulation that generates 10,000 random three-asset portfolios, calculates their expected return and risk, and identifies the optimal portfolio by Sharpe ratio.

  • Build the covariance matrix from the given standard deviations and correlation matrix.
  • Generate random weights for each portfolio, ensuring all weights are non-negative and sum to one.
  • For each portfolio, compute expected return as the weighted sum of expected returns.
  • For each portfolio, compute risk as the standard deviation using the covariance matrix.
  • Calculate the Sharpe ratio for each portfolio, assuming a risk-free rate of zero.
  • Identify the portfolio with the highest Sharpe ratio.
  • Plot all simulated portfolios on a risk-return scatter plot, highlighting the optimal portfolio.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 5
single

single

some-alt