Calculator
Efficient Frontier Calculator
Plot the Markowitz efficient frontier with minimum-variance and tangency (max-Sharpe) portfolios and per-asset weights. Closed-form, free, in your browser.
Runs in your browser. Nothing you enter is uploaded, and no account or API key is needed.
Upload a multi-asset returns CSV
Wide format: date,asset_1,asset_2,…. Each column is a series of simple periodic returns as decimals. Minimum 60 observations and 2 assets; maximum 20 assets. Computation is entirely client-side.
Used for Sharpe ratios and the tangency portfolio.
Annualizes means and covariances.
Max-Sharpe portfolio
-2.12
Annualized Sharpe of the tangency portfolio: -4.8% expected return at 4.1% volatility, gross exposure 201% (weights can be negative). In-sample estimate: historical means make this optimistic out of sample.
The risk-free rate is at or above the minimum-variance portfolio's return, so no portfolio on the efficient branch beats cash; the closed-form "tangency" weights shown are not a max-Sharpe portfolio.
4 assets · 504 observations (~2.0 yrs) · rf = 4.0% · min-var vol 1.5%
Efficient frontier (shorting allowed)
Solid curve: efficient frontier (upper branch). Dashed curve: the inefficient lower branch. Hollow dot: tangency (max-Sharpe) portfolio. Amber dot: minimum-variance portfolio. Gray dots: individual assets.
Key portfolios
Tangency (max Sharpe)
Return
-4.8%
Vol
4.1%
Sharpe
-2.12
| Asset | Weight |
|---|---|
| equity | -12.5% |
| bonds | 150.6% |
| commodities | -33.4% |
| crypto | -4.7% |
Minimum variance
Return
2.9%
Vol
1.5%
Sharpe
-0.76
| Asset | Weight |
|---|---|
| equity | 19.5% |
| bonds | 74.5% |
| commodities | 5.9% |
| crypto | 0.1% |
Formulas
min-var: w* = Σ⁻¹·1 / (1ᵀ·Σ⁻¹·1) tangency: w* = Σ⁻¹·(μ − rf·1) / (1ᵀ·Σ⁻¹·(μ − rf·1)) frontier: w(μ_t) = λ·Σ⁻¹·μ + γ·Σ⁻¹·1 λ = (C·μ_t − A) / D, γ = (B − A·μ_t) / D A = μᵀΣ⁻¹1, B = μᵀΣ⁻¹μ, C = 1ᵀΣ⁻¹1, D = B·C − A²
Shorting is allowed and there are no position limits: these are the unconstrained closed-form solutions. Long-only or capped weights (w ≥ 0, w ≤ cap) need a quadratic-program solver, which this tool does not include.
How to use it
- Upload a wide-format CSV of simple returns (an optional date column, then one column per asset, at least 60 rows and 2 to 20 assets), or load the four-asset demo.
- Set the yearly risk-free rate and the return frequency (daily, weekly or monthly) so means and covariances are annualized correctly.
- Read the tangency portfolio's Sharpe ratio, return, volatility and gross exposure, and check the chart: the solid curve is the efficient frontier, the hollow dot the tangency portfolio, the amber dot the minimum-variance portfolio.
- Read the weights of both portfolios. Weights can be negative because shorting is allowed and there are no position limits.
- Re-run on a different date range or frequency. Weights that swing a lot between samples mean the estimates are too noisy to use as is.
The method, step by step
Build an efficient frontier by estimating each asset's expected return and the covariance matrix of returns, then solving for the minimum-variance portfolio at each target return level and plotting risk against return. The mechanics are straightforward; the hard part is estimation error, because mean-variance optimization is exquisitely sensitive to noisy expected-return inputs and will over-concentrate in whatever it overestimates.
-
Estimate expected returns and covariances
The optimization needs two inputs: a vector of expected returns and a covariance matrix capturing how assets move together. Historical averages are the naive estimate, but expected returns from history are notoriously unreliable, while the covariance matrix is more stable. Recognize up front that the expected-return estimates are the weak link, because the frontier will lean hardest on whichever assets you assign the highest expected return, error included.
The covariance matrix is far more estimable than expected returns. Many practitioners trust the risk structure and treat the return inputs with deep suspicion.
Portfolio Correlation Matrix -
Solve for minimum variance at each return level
For a grid of target return levels, find the portfolio weights that minimize variance subject to achieving that return and to your constraints. This is a quadratic optimization with a clean solution in the unconstrained case and a numerical one with constraints like no shorting. Each solved portfolio is one point on the frontier: the lowest-risk way to achieve that return given your inputs. Sweeping the target return traces the whole curve.
Impose realistic constraints from the start, such as no short selling and position caps. Unconstrained optimization often produces extreme long-short weights no one would actually hold.
-
Plot the frontier and locate key portfolios
Plot the solved portfolios with risk on the horizontal axis and expected return on the vertical, and the efficient frontier is the upper edge of the feasible region. Two portfolios on it are especially useful: the global minimum-variance portfolio at the leftmost point, and the tangency portfolio that maximizes the Sharpe ratio given a risk-free rate. These anchor the practical choices, since most investors pick a point between minimum variance and the tangency portfolio.
The minimum-variance portfolio relies only on the covariance matrix, not on expected returns. That makes it more robust than the tangency portfolio, which depends on the noisy return estimates.
-
Confront estimation error
A frontier built on raw historical estimates is overconfident: the optimizer treats noisy inputs as certain and concentrates in whatever it overestimated. Counter this by shrinking the expected-return estimates toward a common prior, regularizing the covariance matrix, or using resampling to average frontiers across many bootstrapped inputs. These methods trade a little in-sample optimality for portfolios that hold up out of sample, which is the only optimality that matters.
An optimizer fed noisy estimates is an error maximizer: it bets hardest on whatever it got most wrong. Shrinkage and resampling are how you tame that behavior.
-
Validate out of sample
Test the chosen portfolio on data after the period you estimated it on, exactly as you would validate any other strategy. An in-sample frontier always looks excellent because it was optimized to. The out-of-sample test reveals whether the diversification and the weights actually deliver, or whether estimation error produced a portfolio that concentrates and underperforms once the future stops matching the past it was fit on.
Compare your optimized portfolio against a simple equal-weight benchmark out of sample. If sophisticated optimization cannot beat equal weighting, estimation error has eaten the benefit.
Sources: Portfolio Selection (Harry Markowitz, Journal of Finance (1952)) ; Optimal Versus Naive Diversification: How Inefficient is the 1/N Portfolio Strategy? (DeMiguel, Garlappi, Uppal, Review of Financial Studies (2009))
Mistakes that undo the result
Trusting historical expected returns as inputs
Expected returns estimated from history are extremely noisy, and the optimizer concentrates in whichever assets it overestimates. This produces an in-sample frontier that looks great and an out-of-sample portfolio that is dangerously concentrated.
Running unconstrained optimization
Without constraints like no shorting and position caps, the optimizer produces extreme long-short weights driven by estimation noise. Realistic constraints are necessary for the frontier to yield portfolios anyone would actually hold.
Skipping out-of-sample validation
The in-sample frontier is optimized to look perfect, so it always does. Only out-of-sample testing reveals whether the weights deliver real diversification or just fit the noise of the estimation period.
Questions people ask
How is the frontier constructed?
With Markowitz's (1952) mean-variance model solved in closed form. The tool estimates annualized means and the covariance matrix from your return series, then uses the two-fund theorem: the minimum-variance portfolio is Σ⁻¹1 / (1ᵀΣ⁻¹1), the tangency portfolio is Σ⁻¹(μ − rf) normalized to sum to 1, and every frontier point is a combination of Σ⁻¹μ and Σ⁻¹1. Sweeping the target return traces the frontier; the upper branch is the efficient set.
Why do the inputs need so many observations?
Covariance estimation is data-hungry: 10 assets have 55 variances and covariances to estimate, so 60 monthly observations leave very few degrees of freedom. The tool requires 60 rows per asset and at most 20 assets, but it does not warn beyond that or shrink the matrix. Aim for many more observations than assets (ten times is a common rule of thumb), and treat weights from short samples as unstable.
Does the tool support constraints?
No. It computes the unconstrained closed-form solution, so weights can be negative (short positions) and there are no caps or minimum positions; weights always sum to 100%. Long-only or capped portfolios need a quadratic-program solver. Constraints shrink the feasible set, so a constrained frontier lies at or below this one at every volatility.
What's wrong with mean-variance optimization?
Two well-known issues: small changes in the expected-return estimates swing the weights a lot, and variance treats upside and downside alike, ignoring skew and fat tails. The tool has no alternative objective such as CVaR; for robust allocations look at shrinkage estimators, Black-Litterman, or risk parity, and read in-sample max-Sharpe weights as an upper bound on what is achievable.
How are expected returns estimated?
From the historical mean of each series, compounded to a year: (1 + mean periodic return)^periods − 1, with periods set by the return frequency you choose. There is no way to enter your own expected-return vector. Historical means are a noisy estimate of future returns, which is the main reason in-sample tangency weights rarely survive out of sample.
Related tools
- Calculators Portfolio Correlation Matrix
Paste a multi-asset returns CSV. See the Pearson correlation heatmap, condition number, average absolute correlation, and eigenvalue concentration — the diagnostics for detecting redundant strategies before you allocate capital.
- Calculators Risk-Adjusted Returns Calculator
Paste a returns CSV. Sharpe, Sortino, Calmar, Omega, alpha, beta, tracking error, information ratio, max drawdown, and tail moments — plus a benchmark-relative block when you include one.
- Calculators Kelly Criterion Calculator
Size positions with full, half, quarter, or eighth Kelly and stress-test the choice with a drawdown Monte Carlo simulator. Client-side. Private by default.
Articles
- 7 min read Markowitz 1952 Portfolio Selection: A Worked Example
Markowitz 1952 Portfolio Selection on a real stocks/bonds/gold tape: the E-V rule, why variance holds diversification, and a live efficient frontier.
- 7 min read Almgren-Chriss Optimal Execution: A Worked Example
Almgren-Chriss optimal execution on a 250k-share sell: permanent and temporary impact, the mean-variance frontier and the cost at the 2005 calibration.
Use it from code
The same calculation as a JavaScript module you can import. It runs where you import it, with no request, key or rate limit.
import { compute } from "https://aifinhub.io/engines/efficient-frontier-builder.js";