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.
This exercise is part of the course
GARCH Models in Python
Exercise instructions
- Set the EUR/USD weight
Wa1in portfolio a to 0.9, andWb1in portfolio b to 0.5. - Calculate the variance
portvar_afor portfolio a withvariance_eur,variance_cadandcovariance; do the same to computeportvar_bfor portfolio b.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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()