The Efficient Frontier in 16 Lines of Python, and Whether Its Numbers Hold Up
Watch on TikTok
Every figure this video states is reproducible from the code shown on screen, and I reproduced all of them. The clip is Part 13 of the QuantFinanceToGo series. It builds Markowitz's efficient frontier by brute force: take three made-up assets, draw 5,000 random weight combinations, plot each one on a risk-versus-return map, and keep only the mixes that beat every safer mix. The screen shows the whole program, all sixteen lines, with a fixed random seed. That makes it checkable rather than assertable, which is rare for finance content on this platform. I ran the code and compared the output to an exact constrained optimizer. The claimed numbers survive. Two framing details do not survive as cleanly, and I cover those below.
The inputs are assumptions, and the video says so
The three assets are labeled on the chart with their numbers legible in the code panel:
| Asset | Stand-in for | Expected return | Risk (annual volatility) |
|---|---|---|---|
| A | bonds | 4% | 6% |
| B | stocks | 7% | 18% |
| C | a riskier stock | 11% | 25% |
Line 5 of frontier.py sets the correlation matrix to [[1, 0, 0], [0, 1, .5], [0, .5, 1]]. A is uncorrelated with both B and C. B and C correlate at 0.5. Line 6 converts correlation to covariance with C = np.array(corr) * np.outer(s, s), which is the standard identity: covariance between two assets equals their correlation times the product of their standard deviations.
The video is explicit that these are assumed values, not forecasts. The on-screen badge reads "SIMULATED ASSETS · ASSUMED NUMBERS" and the footer carries "education only · not financial advice" on every frame I sampled. The narration adds that for real assets these inputs would have to be estimated from data. That caveat matters more than the clip has time to explain, because estimated expected returns carry enough error that frontier weights built on them are famously unstable. The video does not claim otherwise.
What 5,000 Dirichlet draws actually cover
Line 7 reads w = rng.dirichlet([1, 1, 1], 5000). A Dirichlet distribution with all concentration parameters set to 1 is uniform over the simplex, so each draw is a valid long-only portfolio: three weights between 0 and 1 that sum to 1. No short selling, no leverage. The seed on line 2 is np.random.default_rng(13), matching the "Part 13" branding.
This sampling choice has a consequence the chart glosses over. Uniform sampling on a simplex almost never lands on a corner. In the 5,000 draws the largest weight placed on asset C is 0.9953, so the highest sampled return is 10.97% rather than C's full 11%, and the highest sampled risk is 24.89% rather than 25%. The animated white frontier curve is drawn as if it terminates at the circled C marker. It stops just short of it. This is a rendering detail, not a numerical error, and it does not change any stated figure.
The filter on line 12, and where 825 comes from
Lines 10 through 12 are the whole algorithm:
o = np.argsort(v) # low to high
top = np.maximum.accumulate(r[o]) # best so far
edge = o[r[o] >= top] # the frontier
Sort the 5,000 mixes by risk, walk left to right, and keep a mix whenever its return matches or exceeds the best return seen at any lower risk. This is a running-maximum record filter. The narration describes it as keeping a mix "only if it earns more than every mix with less risk," while the code uses >= and so also keeps ties. That difference is immaterial here.
Running the code with seed 13 gives exactly 825 kept mixes out of 5,000, matching the video. The on-screen counter in the mid-video animation reads 688 at the moment the sweep line crosses roughly 20% risk, which is consistent with a counter ticking up toward the final 825.
Worth being precise about what 825 means. A kept mix only has to beat everything safer than itself. It does not have to beat every mix at its own risk level, so the record filter is a necessary condition for efficiency and not a sufficient one. In principle that lets the staircase sit below the true frontier. I measured the gap by solving, for each of the 825 kept points, the exact maximum long-only return at that point's volatility. The average shortfall is 0.004 percentage points and the worst is 0.043 percentage points. At this sample density the approximation is tight enough that the distinction is academic, which supports the video's closing claim that more mixes bring the edge closer to the exact frontier.
Checking the stated numbers against an exact optimizer
I recomputed the two headline results two ways: by rerunning the shown code, and independently with a constrained optimizer on the same covariance matrix.
The minimum-risk point. The video says the lowest-risk mix in the simulation swings 5.7%, with the description adding a 4.4% return, and notes this is "a little less than asset A alone." Both check out. The sampled winner is 89.5% A, 7.5% B, 3.0% C, giving 5.68% volatility and 4.43% return. The exact global minimum-variance portfolio is 89.4% A, 8.5% B, 2.1% C at 5.674% volatility and 4.40% return. Both round to 5.7% and 4.4%. The claim that mixing lowers risk below A's standalone 6% is correct, and it follows from A being uncorrelated with the other two, which is exactly the diversification effect the series covered in Parts 10 and 11.
The 18% risk comparison. The video says that at B's own 18% risk the frontier earns 9.1% instead of B's 7%. The sampled frontier point at that risk is 17.5% A, 18.0% B, 64.5% C, returning 9.05% at 17.99% volatility. The exact optimum at a hard 18% volatility cap is 19.6% A, 14.2% B, 66.2% C, returning 9.06%. Both round to 9.1%.
The Sharpe ratios. The description states 0.34 for the frontier point and 0.22 for B alone, at a 3% safe rate. Using the standard definition of excess return over volatility: (9.1 − 3) / 18 = 0.339, and (7 − 3) / 18 = 0.222. Both round as stated.
For a sense of scale, an equal-weight third in each asset lands at 12.63% risk for 7.33% return, which sits inside the cloud and below the edge.
Where the framing is loose
The prize name. The video opens with "Harry Markowitz won a Nobel Prize for this curve," and the on-screen title is "The Nobel Prize Curve." Markowitz did receive the award in 1990, but its formal name is the Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel, established by Sweden's central bank in 1968 and not one of the five prizes named in Alfred Nobel's will. The video's own description is more careful, calling it "the 1990 Nobel prize in economics." The underlying facts are right: he shared it with Merton H. Miller and William F. Sharpe, the joint citation reads "for their pioneering work in the theory of financial economics," and Markowitz's individual share was awarded for having developed the theory of portfolio choice.
What the prize was actually for. The curve is the picture, not the award. Markowitz was recognized for the theory of portfolio choice as a whole, of which the frontier is the most reproducible visual. The video's description states this correctly. The voiceover's compression into "won a Nobel Prize for this curve" overstates how narrow the citation was.
I found no arithmetic errors. Every number the video states follows from the assumptions it states.
Markowitz 1952 and 1956, in the right order
The video's description gets the chronology right, which is worth confirming because it is commonly reversed. The concept came first: Harry Markowitz, "Portfolio Selection," The Journal of Finance, volume 7, number 1, March 1952, pages 77 to 91. The computational method came four years later: "The Optimization of a Quadratic Function Subject to Linear Constraints," Naval Research Logistics Quarterly, volume 3, 1956, pages 111 to 133. That second paper is the origin of the critical line algorithm, the direct quadratic-programming route to the frontier that makes random sampling unnecessary.
The pedagogical trade the video makes is deliberate. Random sampling is slower and only approximate, but it renders as a cloud with a visible upper edge, and it fits in sixteen lines a viewer can read in a vertical video. The exact method produces the same curve with no picture of why it is the boundary. For an explainer, the approximation earns its keep.
Key Takeaways
- All four stated figures reproduce exactly from the on-screen code with seed 13: 825 of 5,000 mixes kept, lowest risk 5.7% at 4.4% return, 9.1% return at B's 18% risk, and Sharpe ratios of 0.34 against B's 0.22 at a 3% safe rate.
- The minimum-variance mix is roughly 89% bonds, confirming that the left tip of the frontier is dominated by the low-volatility, uncorrelated asset rather than by any clever blend.
- The running-maximum filter is a necessary but not sufficient test for efficiency. At 5,000 samples the resulting staircase falls short of the exact frontier by an average of 0.004 percentage points and at most 0.043, so the approximation holds here.
- Uniform Dirichlet sampling almost never draws a portfolio corner. The sampled edge tops out at 10.97% return against C's 11%, slightly short of where the animation draws it.
- The 1990 award is the Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel, shared with Merton H. Miller and William F. Sharpe. Markowitz's share was for developing the theory of portfolio choice, which is broader than the frontier curve alone.
- The 1952 Journal of Finance paper introduced the idea and the 1956 Naval Research Logistics Quarterly paper supplied the quadratic-programming algorithm. The video states this order correctly.
Resources
- Original TikTok, Quant Finance from Scratch Part 13
- Markowitz, "Portfolio Selection," The Journal of Finance 7(1), 1952, pp. 77-91 (JSTOR)
- Markowitz, "The optimization of a quadratic function subject to linear constraints," Naval Research Logistics Quarterly 3(1-2), 1956, pp. 111-133 (EconPapers record)
- The Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel 1990, summary
- 1990 prize press release, with the individual citations for Markowitz, Miller and Sharpe
- Harry Markowitz, prize facts page
- NumPy documentation for
Generator.dirichlet, the sampler on line 7
Published October 4, 2026. Writeup generated from a favorited TikTok.