How to use the portfolio optimizer
- Add your stocks. Type a company name or ticker and pick it from the list. Two assets is the minimum; 5 to 15 gives more meaningful diversification.
- Choose the history. The analysis period sets how many years of prices are used to estimate returns, volatilities and correlations. The data frequency sets whether daily, weekly or monthly returns are used.
- Pick an optimization method. Maximize Sharpe ratio is the usual starting point. The table below explains when each method fits.
- Read the results. You get the optimal weights, the expected annual return and volatility, the Sharpe ratio, the efficient frontier chart and the past cumulative return of the portfolio against each stock. Export them to CSV if you want to keep them.
What a portfolio optimizer does
A portfolio optimizer chooses how much to put in each asset so that the mix has the best trade-off between return and risk. The idea comes from Harry Markowitz's 1952 paper Portfolio Selection, the basis of Modern Portfolio Theory: what matters is not the risk of each stock on its own but how the stocks move together. Two volatile stocks that are weakly correlated can form a portfolio that is less risky than either of them.
For weights w, expected annual returns μ and the covariance matrix Σ of the assets:
Portfolio return: μp = wTμ = Σ wi μi
Portfolio volatility: σp = √(wTΣw)
The two most common optimizations are:
Minimum variance: minimize wTΣw
Maximum Sharpe: maximize (wTμ − rf) / √(wTΣw)
Both are solved subject to Σ wi = 1 (fully invested) and wi ≥ 0 (no short selling), which is how this tool works. Expected returns and covariances are estimated from the price history you choose and annualized with 252 trading days; the risk-free rate rf is set at 2%. Repeating the minimum-variance problem for every target return traces the efficient frontier: the set of portfolios with the highest return for each level of risk. The maximum Sharpe portfolio is the point on that curve with the best return per unit of volatility (see the Sharpe ratio explained).
The six optimization methods compared
| Method | What it optimizes | Use it when | Watch out for |
|---|---|---|---|
| Maximize Sharpe ratio | Excess return per unit of volatility | You want the best risk-adjusted mix (the usual default) | Very sensitive to the estimated returns |
| Minimize risk | Lowest portfolio volatility | Capital preservation; you distrust return forecasts | Can load up on the calmest assets |
| Maximize return | Highest expected return | Seeing the return end of the frontier | Without shorting or leverage it puts 100% in the single best past performer |
| Minimize CVaR | Average loss in the worst days | You care about crashes more than day-to-day swings | Needs enough history to contain bad periods |
| Target return | Lowest volatility for a return you set | You have a required return, for example for a plan | The target must lie within the achievable range |
| Black-Litterman | Blends market-implied returns with your views | You have specific views and want stable weights | Results depend on your confidence levels |
Worked example: three asset classes
To show what the optimizer does, take three assets with these assumed annual figures (illustrative only, not forecasts): stocks with 8% expected return and 16% volatility, bonds with 4% and 6%, and gold with 5% and 15%. Correlations are 0 between stocks and bonds, 0.1 between stocks and gold, and 0.3 between bonds and gold. The risk-free rate is 2%.
| Portfolio | Stocks | Bonds | Gold | Return | Volatility | Sharpe |
|---|---|---|---|---|---|---|
| Equal weight | 33.3% | 33.3% | 33.3% | 5.67% | 8.29% | 0.44 |
| Minimum variance | 12.1% | 85.5% | 2.4% | 4.51% | 5.61% | 0.45 |
| Maximum Sharpe | 28.9% | 65.3% | 5.8% | 5.21% | 6.35% | 0.51 |
| 100% stocks | 100% | 0% | 0% | 8.00% | 16.00% | 0.38 |
The maximum Sharpe portfolio gives up less than half a point of return against the equal-weight mix (5.21% vs 5.67%) but cuts volatility by almost two points (6.35% vs 8.29%), so it earns more per unit of risk. Its large bond weight comes from the zero stock-bond correlation: bonds lower the portfolio's risk more than their own return costs.
Now raise gold's expected return from 5% to 6% and keep everything else the same. The optimal gold weight roughly doubles, from 5.8% to 11.9% (stocks 28.0%, bonds 60.1%). A one-point change in one input moved the allocation a lot, and that sensitivity is the main thing to understand before trusting any optimizer's output.
Limitations and good practice
- The past is only an estimate. The optimizer uses historical averages as expected returns. Returns are far harder to estimate than volatilities and correlations, and errors in them drive the weights. Richard Michaud called mean-variance optimizers "error maximizers" for this reason.
- Expect concentrated weights. With few assets or a short period, maximum Sharpe often puts most of the money in one or two recent winners. Use a longer period, more assets, minimum variance or Black-Litterman to get steadier weights.
- Volatility is not the only risk. Variance treats gains and losses alike and assumes well-behaved returns. If crashes worry you, compare with the CVaR method or check tail risk in our VaR and CVaR calculator.
- Rebalance on a rule. Optimal weights drift as prices move. Re-run the optimizer and rebalance on a schedule or with tolerance bands; the portfolio rebalancing calculator shows the trades.
- Check the factors. A portfolio of different stocks can still be one big bet on the market or on growth stocks. Our factor analysis tool shows those exposures.
Risk note: results are based on past prices and are for education and research only. They are not investment advice and do not predict future returns. See our terms of service.