Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Image: ubuntu2004
Mean-variance analysis with simulated data
Camilo A. Garcia Trillos - 2020
In this class
Markowitz mean-variance analysis
In this class we will start by simulated random data. Later we will learn how to use actual stock data.
Assume that we have assets, each with a return series of length . We can use numpy.random.randn to sample returns from a normal distribution (recall Class A).
Random portfolios
Let's generate a couple of random portfolios. Let's assume for the moment that we restrict ourselves to have "long-only" portfolios, that is, the weights are nonnegative.
Let's next compute the expected return and standard deviation for a portfolio.
Now, let's plot several such random risk-return profiles:
Let us now check the covariance matrix and find its inverse.
Let us check the stability of the matrix with the condioned number
This is not too bad. We could move on without expecting major stability problems.
Markowitz, as done in the lecture notes
Remark: recall from the lecture that Markowitz needs at least two expected returns to differ. This is not the case via our simulated data. Indeed, any portfolio will have a zero expected return and the equally weighted portfolio will have the smallest variance. Let's just proceed, nevertheless, and see how far we get ...
Markowitz via an optimization algorithm
Next a different that also allows for additional constraints (e.g., nonnegative portfolio weights).
In the following yet another implementation. Now, we are using the constraint instead of .
All three methods therefore yield more or less the same portfolio, which is nice ... (Markowitz_weights_optIneq only have an inequality constraint and yields results that have further away from the other two approaches).
(If we run again the problem with different means and variances the solution with inequality constraints drift further away. This is simply because those means cannot be attained using only positive portfolios).