Firstly, this tutorial is really good, both in finance, math, and python. I like it a lot.
I was reading the tutorial of Markowitz Portfolio Optimization (Markowitz Portfolio Optimization | Python/v3 | Plotly). There is an issue about calculation the optimal risk level.
in the optimal_portfolio function,
Hi Ken, I think the reason why they do it this way around is: When you plot x=risk and y=returns, you get a Markowitz bullet with an efficient frontier that sketches out a parabola thatโs โlying on its sideโ. That is, the tapered end is to the left, and the โarmsโ that extend out to infinity are to the right.
On the other hand a 2nd order polynomial either sketches out a parabola where the tapered end is at the bottom and the the โarmsโ are at the top, or visa versa.
So in order to fit a second order polynomial as a line of best fit to the efficient frontier, we first need to switch the axis around (returns = x, risks = y), so that the parabola is correctly oriented.