Zopra/Charts
Guide
Getting startedAll chartsWhich chart to use?Domain specific
Base charts7
XY ChartTrendCandlestickHeatmapState TimelineFlame GraphBar Gauge
Derived charts73
Time SeriesHistogramStatus HistoryStatGaugeHoneyCombTracesNode GraphHeikin-AshiRenkoKagiPoint & FigureParetoIshikawaControl ChartBland-AltmanLollipopDumbbellSlopeBumpBack-to-BackWaterfallBulletFunnelMekkoForestBarcodeBeeswarmRidgelineHorizonSpectrogramAttention MapWaffleVennUpSetWarped WaffleWord CloudGanttSankeySankey MatrixTreemap ForceChord DiagramCircosArc DiagramAlluvialSankey FunnelDendrogramIcicleSunburstSpiderNightingale RoseParallel CoordinatesOscilloscopeEfficient FrontierPhase PortraitPoincaré MapBifurcationH-R DiagramRamachandranHarkerRoot LocusRadiation PatternQuiverHodographSmith ChartEye DiagramSequence LogoTernaryTernary ContourPiperStüveTephigramChoropleth

Charts/Science charts

Efficient Frontier

<EfficientFrontier /> · 11 examples

Every portfolio you could build from your assets, with the best ones traced as a curve.

Overview

Ask three investors how to split money between stocks, bonds and gold and you will get four answers and one of them will mention a cousin. Harry Markowitz asked a sharper question in his 1952 paper on portfolio selection: for a given amount of risk you are willing to carry, what is the most return you can get? The answer is not a single portfolio. It is a curve, and everything below the curve is a portfolio that someone could have beaten without taking on any extra risk.

That curve is the efficient frontier. It works because assets do not move in lockstep: two risky things that zig and zag at different times make a combination steadier than either. The chart's job is to put that on one page. Each asset appears as a square, a cloud of random portfolios fills the space between and around them, and the frontier runs along the top-left edge of the cloud like a roof.

Markowitz shared the 1990 Nobel Prize in economics, partly for this picture. It is one of the rare charts where the single most valuable thing is an empty region: the area above and to the left of the curve, where nothing is available at any price.

Props

API

<EfficientFrontier returns={vec![0.08, 0.12, 0.05]} covariance={covariance} risk_free={0.03} />
PropTypeDefault
returnsVec<f64>: expected return per assetrequired
covarianceVec<Vec<f64>>: the assets' covariance matrixrequired
risk_freef64: the risk-free rate0.
portfoliosusize: random long-only portfolios to scatter2000
schemeScheme: colours the portfolios by Sharpe ratioBlueYellowRed
legend, tooltip, class

Draws the random portfolios, the frontier itself (solved exactly, short sales allowed), the capital market line from risk_free, and the maximum-Sharpe (tangency) portfolio. Returns and risk are shown as percentages.

Run them

11 examples

Press Run to load an example into the live render at the top of the page. Open one to read its code.

How to read it

  1. 01Find the leftmost point of the frontier: the global minimum-variance portfolio. Nothing has less risk than this, whatever the return.
  2. 02Look at the squares. A single asset far to the right of the frontier is paying for risk it does not need to carry.
  3. 03Follow the dashed capital market line to where it touches the curve: the red dot is the best return per unit of risk, given your risk-free rate.
  4. 04Hover a cloud point for its risk, return and Sharpe ratio. The colour gradient shows how the ratio climbs towards the upper left.

When to use it, and when not to

Reach for it when

  • You are choosing weights for three to a dozen assets and want to see how much diversification actually buys.
  • You want to show a client or a committee that their current mix sits well inside the curve: the same return was available for less risk.
  • You are comparing the effect of a changed assumption, such as a higher expected return for one asset, by watching the frontier move.
  • You want a feel for the shape of the opportunity, not a single recommended answer.

Skip it when

  • Your expected returns are guesses with false confidence. The frontier is extremely sensitive to μ\muμ, and the optimiser will happily load up on whichever asset you were optimistic about.
  • You need a long-only frontier. The curve here allows shorting, for constrained portfolios use the cloud's upper edge as a rough guide and solve the constraints elsewhere.
  • You have hundreds of assets. The closed form needs a clean inverse of Σ\SigmaΣ, and the picture stops being legible long before the algebra fails.
  • Risk to you is not variance. Downside, drawdown and tail risk are different questions with different charts.

The math behind it

Risk and return of a mix

Let μ\muμ be the vector of expected returns you pass in (returns) and Σ\SigmaΣ the covariance matrix (covariance). A portfolio is a weight vector www that sums to one. Its expected return is linear in the weights; its risk is the square root of a quadratic form, and the off-diagonal entries of Σ\SigmaΣ are where diversification lives.

μp=w⊤μ,σp=w⊤Σ w,∑iwi=1\mu_p = w^{\top}\mu, \qquad \sigma_p = \sqrt{w^{\top}\Sigma\,w}, \qquad \sum_i w_i = 1μp​=w⊤μ,σp​=w⊤Σw​,i∑​wi​=1
S=μp−rfσpS = \frac{\mu_p - r_f}{\sigma_p}S=σp​μp​−rf​​

The cloud of portfolios

The scatter is long-only. Each of the portfolios points (2000 by default) draws weights wi∝−ln⁡uiw_i \propto -\ln u_iwi​∝−lnui​ from a deterministic pseudo-random sequence, then divides by their sum. That is a uniform draw from the set of non-negative weights summing to one, so the cloud is not biased towards equal splits the way averaging uniform numbers would be. The points are coloured by the Sharpe ratio SSS above, with rfr_frf​ taken from risk_free (zero if absent). The sequence is fixed, so the same inputs always give the same cloud.

The frontier and the tangent portfolio

The curve is not read off the cloud. It is solved in closed form. With 1\mathbf 11 a vector of ones, define three scalars, and the minimum variance for a target return mmm follows. The chart evaluates it at 101 evenly spaced targets, from the return of the global minimum-variance portfolio, A/CA/CA/C, up to 1.2 times the best single-asset return.

A=1⊤Σ−1μ,B=μ⊤Σ−1μ,C=1⊤Σ−11,D=BC−A2A = \mathbf 1^{\top}\Sigma^{-1}\mu,\quad B = \mu^{\top}\Sigma^{-1}\mu,\quad C = \mathbf 1^{\top}\Sigma^{-1}\mathbf 1,\quad D = BC - A^{2}A=1⊤Σ−1μ,B=μ⊤Σ−1μ,C=1⊤Σ−11,D=BC−A2
σ2(m)=C m2−2A m+BD\sigma^{2}(m) = \frac{C\,m^{2} - 2A\,m + B}{D}σ2(m)=DCm2−2Am+B​
wtan=Σ−1(μ−rf1)1⊤Σ−1(μ−rf1)w_{\text{tan}} = \frac{\Sigma^{-1}(\mu - r_f\mathbf 1)}{\mathbf 1^{\top}\Sigma^{-1}(\mu - r_f\mathbf 1)}wtan​=1⊤Σ−1(μ−rf​1)Σ−1(μ−rf​1)​

What the closed form assumes

The frontier allows negative weights (short positions) because that is where the algebra is clean, while the random cloud does not. So the cloud sits inside the curve and touches it only when the best long-only portfolio happens to be the unconstrained one. The red dot is wtanw_{\text{tan}}wtan​, the portfolio with the highest Sharpe ratio, and the dashed capital market line runs from (0,rf)(0, r_f)(0,rf​) through it, extended to 1.4 times its risk. If Σ\SigmaΣ is singular, or D≤0D \le 0D≤0, the frontier is skipped and only the cloud and the assets are drawn. Risk is shown on the x axis, return on y, both as percentages.

Real life usage

The pension that was already on the roof

Ines chaired the investment committee of a small teachers' pension fund, which is a job with all of the responsibility of a bank and none of the staff. The fund held three things: a domestic equity index, a global bond fund and a slice of infrastructure. It had held them in the same proportions since a trustee named Gerald had written them on a napkin in 2011. The napkin was treated with a respect usually reserved for tablets.

A new actuary asked a quiet question at the March meeting: was the napkin portfolio any good? Nobody knew how to answer. The fund's consultant said the mix was reasonable, which is what consultants say about mixes, and Gerald said it had always been fine, which is what everyone says about a napkin.

What Ines needed was a way to see the napkin portfolio against everything else that three assets can produce, using the fund's own estimates of return and its own covariance matrix, and a picture the trustees could read without a course.

She gave <EfficientFrontier> the three expected returns, the covariance matrix from ten years of monthly data and a risk-free rate of 2.5 percent. Two thousand grey-to-yellow portfolios filled the screen, and the frontier arched above them. She added the napkin mix as a point and it sat in the middle of the cloud, a good way inside the curve.

The same 6.1 percent expected return was available at 8.9 percent risk, and the napkin was carrying 11.4. Alternatively, holding the napkin's risk could have earned almost a point more. Put that way, the trustees stopped defending it. Gerald asked, with real dignity, whether the napkin could keep a smaller share. It could not.

The fund moved towards the tangent portfolio over three quarters, trimming domestic equity and raising infrastructure. In the next year it delivered the same return with measured volatility about a quarter lower, and the pension committee's longest meeting of the year was cut to one hour because there was nothing left to argue about.

The napkin now hangs framed in the boardroom, not as a guide but as a before picture.

Pitfalls

  • Garbage in, optimiser out. Small changes in expected returns move the frontier a lot. Treat the tangent portfolio as a thought experiment, not a trade list.
  • Units must match. Returns, covariance and the risk-free rate must all be per the same period, for example annual. Mixing monthly covariances with annual returns shrinks the risk axis by 12\sqrt{12}12​ and flatters everything.
  • Shorting is allowed on the curve. The cloud is long-only. If the curve rises far above the cloud's edge, the extra return comes from negative weights you may not be allowed to hold.
  • A bad covariance matrix. It must be symmetric and positive definite. A matrix assembled by hand from rounded correlations often is not, and the frontier will quietly vanish.

From around the web

Watch and read

YouTubeEfficient Frontier and Portfolio Optimization Explained | The Ultimate GuideRyan O'Connell, CFA, FRMIn-depth explanation of the efficient frontier and how it is computed.
YouTubeInvestopedia Video: Efficient FroniterInvestopediaShort, plain-language overview of the concept.

Keep going

Related charts

XY ChartWhen you only want a scatter of risk against return without the frontier and tangent portfolio.Control ChartWhen risk is about a process drifting out of limits rather than a mix of assets.WaterfallWhen you want to explain how a portfolio's return was built up, contribution by contribution.
PreviousOscilloscopeNextPhase Portrait

On this page

  • Live
  • Overview
  • API
  • Examples
  • How to read it
  • When to use it
  • The math
  • Story
  • Pitfalls
  • Watch and read
  • Related