LoslegenKostenlos loslegen

PyPortfolioOpt risk functions

The objective of the Markowitz portfolio optimization problem is to minimize the portfolio variance, given a bunch of constraints. Do you remember how you calculate this from chapter 2? Portfolio variance = weights transposed * covariance matrix * weights. WithPyPortfolioOpt we call the covariance matrix sigma, to denote that this is a sample covariance \(\Sigma\).

In this exercise you will see that thePyPortfolioOpt functions to calculate sigma, gives the exact same result if you were to calculate the covariance by hand. The same goes for the expected return calculations, you can also verifyPyPortfolioOpt gives the same output as calculating annualized daily returns by hand. Available are the stock_prices. Let's explore this a bit further…

Diese Übung ist Teil des Kurses

Introduction to Portfolio Analysis in Python

Kurs anzeigen

Interaktive Übung

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

# Get the returns from the stock price data
returns=____.____()
Code bearbeiten und ausführen