LoslegenKostenlos loslegen

Compute dynamic portfolio variance

In this exercise, you will practice computing the variance of a simple two-asset portfolio with GARCH dynamic covariance.

The Modern Portfolio Theory states that there is an optimal way to construct a portfolio to take advantage of the diversification effect, so one can obtain a desired level of expected return with the minimum risk. This effect is especially evident when the covariance between asset returns is negative.

Suppose you have a portfolio with only two assets: EUR/USD and CAD/USD currency pairs. Their variance from the GARCH models have been saved in variance_eur and variance_cad, and their covariance has been calculated and saved in covariance. Compute the overall portfolio variances by varying the weights of the two assets, and visualize their differences.

Diese Übung ist Teil des Kurses

GARCH Models in Python

Kurs anzeigen

Anleitung zur Übung

  • Set the EUR/USD weight Wa1 in portfolio a to 0.9, and Wb1 in portfolio b to 0.5.
  • Calculate the variance portvar_a for portfolio a with variance_eur, variance_cad and covariance; do the same to compute portvar_b for portfolio b.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Define weights
Wa1 = ____
Wa2 = 1 - Wa1
Wb1 = ____
Wb2 = 1 - Wb1

# Calculate portfolio variance
portvar_a = Wa1**2 * ____ + Wa2**2 * ____ + 2*Wa1*Wa2 *____
portvar_b = Wb1**2 * ____ + Wb2**2 * ____ + 2*Wb1*Wb2*____

# Plot the data
plt.plot(portvar_a, color = 'green', label = 'Portfolio a')
plt.plot(portvar_b, color = 'deepskyblue', label = 'Portfolio b')
plt.legend(loc = 'upper right')
plt.show()
Code bearbeiten und ausführen