Skip to content
svgefficient-frontier

Efficient frontier

Which portfolios give the most return for each level of risk, and where does the chosen one sit?

Demo data · seed 20261101 · 31 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read x as risk and y as return.
  2. The curve is the best return at each risk.
  3. Points below it are beatable; the marker is the chosen portfolio.
  1. Callout 1: The chosen portfolio.
  2. Callout 2: A frontier point: more return, more risk.
  3. Callout 3: An asset below the frontier: beatable.

Watch out

  • It's very sensitive to estimated returns, so small estimation errors move the frontier a lot.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Frontier rows are joined in order of risk; values within ±2 on both axes are shown as percentages.
# Efficient frontier — Codesplash Chart Lab (recipe "efficient-frontier")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("efficient-frontier-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["frontier", "asset"])

R = "volatility"
RET = "expected return"
LABEL = "label"
CH = "chosen"
KIND = "kind"
d = df.dropna(subset=[R, RET])
asset = d[KIND].astype(str) == "asset" if KIND else pd.Series(False, index=d.index)
f, a = d[~asset].sort_values(R), d[asset]
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.plot(f[R], f[RET], marker="o", ms=3, color=PALETTE[0], linewidth=2, label="efficient frontier")
ax.scatter(a[R], a[RET], facecolors="none", edgecolors="grey", s=36, label="assets")
if LABEL:
    for _, r in a.iterrows():
        ax.annotate(str(r[LABEL]), (r[R], r[RET]), xytext=(6, 0), textcoords="offset points", va="center", fontsize=8)
if CH:
    ch = d[d[CH].astype(bool)]
    ax.scatter(ch[R], ch[RET], color=PALETTE[1], s=80, zorder=3, label="chosen")
ax.set_xlabel(R)
ax.set_ylabel(RET)
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads efficient-frontier-demo.csv · app theme from the optional codesplash helper