How EvidInvest's Portfolio Optimizer Works: Markowitz, Max Sharpe, and Real Data
Everyone knows diversification is good. "Don't put all your eggs in one basket" has been investment advice for as long as there have been baskets. But here's the thing: not all diversification is equal. Owning five tech mega-caps is not the same as owning one tech stock, one bank, one pharmaceutical company, one utility, and one energy company — even if the dollar amounts are identical.
The difference comes down to correlation. And that's exactly what Modern Portfolio Theory, developed by Harry Markowitz in 1952, formalizes mathematically.
This post explains how Markowitz's framework works, how we implemented it in EvidInvest's portfolio optimizer, and — importantly — where it breaks down and why you shouldn't treat the output as gospel.
The Problem: Intuition Isn't Precise Enough
Suppose you hold AAPL and MSFT. When the "tech is overvalued" narrative takes hold, both fall together. Their returns move in the same direction, at roughly the same time. They are highly correlated. Owning both gives you only partial diversification.
Now suppose you add a utility like NextEra Energy to the mix. Utilities tend to hold up when growth stocks sell off — investors rotate to them for their steady dividends. The correlation between AAPL and NEE is much lower. That pairing gives you real diversification.
The key insight Markowitz formalized is this: what matters for portfolio risk is not just how risky each stock is individually, but how they move relative to each other. You can combine two moderately risky assets with low correlation and end up with a portfolio that's less volatile than either asset alone. That's not intuition — that's math.
The Math (We'll Keep It Human)
Three concepts are at the core of everything:
1. Expected Return. This is just the average return you'd expect from a stock or portfolio, annualized. We estimate it from historical log returns over a 365-day lookback window.
2. Volatility (Standard Deviation). How much do those returns swing around? A stock that's up 40% one year and down 30% the next is more volatile than one that consistently returns 8% — even if the average is similar. Measured in annualized percentage terms.
3. The Sharpe Ratio. The money metric. It answers: how much return am I getting per unit of risk?
Sharpe = (R_p - R_f) / sigma_p
Where R_p is the portfolio's expected return, R_f is the risk-free rate (e.g., US Treasury yield, ~4.5% today), and sigma_p is portfolio volatility. A Sharpe of 1.0 means you're earning 1 percentage point of excess return for every 1% of volatility. A Sharpe of 2.0 is exceptional. Below 0.5 is poor.
The Efficient Frontier is the set of all portfolios that maximize return for a given level of risk, or equivalently minimize risk for a given level of return. Every portfolio on the frontier is "efficient" — no wasted risk. The specific point that maximizes the Sharpe ratio is called the tangency portfolio, or Max Sharpe portfolio. That's the one we target.
How EvidInvest's Optimizer Actually Works
Here's what happens under the hood when you click "Optimize Portfolio."
Step 1: Pull Real Price History
We fetch adjusted close prices for every stock in your portfolio from our database, using a 365-day lookback. Adjusted prices account for dividends and splits — so the returns are apples-to-apples.
Step 2: Compute Log Returns and the Covariance Matrix
For each stock, we compute daily log returns: r_t = ln(P_t / P_{t-1}). We use log returns (not simple percentage returns) because they're mathematically cleaner when compounding and slightly more stable statistically.
From those return series, we build the covariance matrix — a grid showing how every pair of stocks in your portfolio moves together. The diagonal contains each stock's variance; the off-diagonal cells show the covariance between pairs.
Step 3: Covariance Shrinkage (This One Matters)
Here's where we depart from a textbook implementation — and why it matters.
The raw covariance matrix, computed from 365 days of data, is noisy. When you have a portfolio of 15–20 stocks and only 365 data points, the matrix can produce extreme estimates: two stocks that happened to move together for a few months get wildly overstated correlation, or vice versa. Feed a noisy covariance matrix into an optimizer and it will produce extreme, unstable portfolios — sometimes concentrating 80%+ into a single name because the model "thinks" everything else is perfectly correlated.
We solve this with Oracle Approximating Shrinkage (OAS) — a Ledoit-Wolf style covariance estimator. The idea is to "shrink" the sample covariance matrix toward a structured target (a scaled identity matrix), blending the noisy raw estimate with a clean prior. The amount of shrinkage is determined analytically rather than by guesswork.
The result is a smoother, more numerically stable covariance matrix that doesn't over-fit to short-term noise. Think of it as regularization for your risk model. It's the same class of technique used by large asset managers to stabilize their risk models — we just apply it at the retail scale.
Step 4: Solve the Max Sharpe Optimization
With the covariance matrix in hand, we maximize the Sharpe ratio subject to constraints:
- All weights
w_i >= 0(long-only — no shorting) - Weights sum to 1:
sum_i w_i = 1 - Optional user-defined minimum or maximum per-name weight
This is a quadratically-constrained optimization problem. We solve it using projected gradient descent — an iterative algorithm that moves in the direction of increasing Sharpe and projects back onto the constraint set (non-negative weights summing to 1) at each step.
We also compute the Minimum Variance portfolio as an alternative — the point on the efficient frontier with the lowest possible volatility, regardless of return. This is better suited for investors who care more about stability than maximizing risk-adjusted growth.
Finally, we render the full efficient frontier: a curve sweeping from minimum variance (bottom-left) to maximum return (top-right), so you can see where the Max Sharpe and Min Variance points sit relative to each other and to simply holding each stock individually.
A Concrete Example
Let's walk through a real-ish optimization: five large-cap tech names — AAPL, MSFT, GOOGL, AMZN, NVDA — using a recent 365-day lookback.
Individual stock stats (approximate, recent 1-year):
| Stock | Ann. Return | Ann. Volatility | Sharpe |
|---|---|---|---|
| AAPL | 22% | 24% | 0.74 |
| MSFT | 28% | 26% | 0.90 |
| GOOGL | 35% | 28% | 1.10 |
| AMZN | 42% | 33% | 1.14 |
| NVDA | 118% | 58% | 1.97 |
NVDA is a statistical outlier — extraordinary return, high volatility, but a Sharpe nearly 2× anyone else. AMZN and GOOGL are strong. AAPL and MSFT are solid but relatively modest on a risk-adjusted basis.
Correlation matrix (approximate):
| AAPL | MSFT | GOOGL | AMZN | NVDA | |
|---|---|---|---|---|---|
| AAPL | 1.00 | 0.73 | 0.69 | 0.65 | 0.54 |
| MSFT | — | 1.00 | 0.75 | 0.70 | 0.62 |
| GOOGL | — | — | 1.00 | 0.72 | 0.64 |
| AMZN | — | — | — | 1.00 | 0.60 |
| NVDA | — | — | — | — | 1.00 |
These correlations are high — they're all mega-cap tech, so they move together. NVDA has the lowest correlations to the others (0.54–0.64), which partially justifies a large allocation despite its volatility.
Optimizer output:
| Portfolio | AAPL | MSFT | GOOGL | AMZN | NVDA | Return | Volatility | Sharpe |
|---|---|---|---|---|---|---|---|---|
| Equal-weight | 20% | 20% | 20% | 20% | 20% | 49% | 31% | 1.44 |
| Max Sharpe | 5% | 11% | 21% | 25% | 38% | 71% | 43% | 1.55 |
| Min Variance | 34% | 29% | 20% | 13% | 4% | 29% | 21% | 1.16 |
A few things to note:
- The Max Sharpe portfolio leans heavily into NVDA and AMZN because they have the best individual Sharpe ratios and lower correlations to each other. AAPL gets only 5% — not because it's bad, but because for every unit of volatility it adds, the alternatives offer more return.
- The Min Variance portfolio flips the allocation: AAPL and MSFT dominate because their lower volatility makes the portfolio steadier, even at the cost of leaving return on the table.
- Equal-weight is surprisingly competitive — a Sharpe of 1.44 vs. 1.55 for Max Sharpe is not a dramatic gap. More on this in a moment.
The Honest Caveats
We built this optimizer because it's genuinely useful. But we'd be misleading you if we didn't flag where it struggles.
1. Past returns are noisy estimates of future returns. The optimizer uses historical returns to project forward. NVDA returning 118% in the last year is mostly a reflection of an extraordinary AI cycle — not a law of nature. The volatility estimate (based on price swings) tends to be more stable and meaningful than the return estimate. Most practitioners trust the covariance matrix more than the expected return vector.
2. Equal-weight beats MPT more often than you'd expect. This is an established empirical finding, not a gotcha. Markowitz optimization is sensitive to input assumptions. Small errors in the estimated returns compound into large errors in the final weights. Equal-weight is robust to these estimation errors — it makes no assumptions at all about relative returns. If you're not confident your return estimates are accurate, equal-weight is a serious alternative.
3. This is a rebalancing signal, not a set-and-forget strategy. The optimal weights change as correlations shift, as volatility regimes change, as individual stock trajectories diverge. The output is most useful as an answer to: given what the data says today, where should I be pointing my portfolio? — not as a permanent allocation you lock in for three years.
4. Constraints matter. An unconstrained optimizer on this five-stock set might put 60–70% in NVDA. Our long-only, sum-to-1 constraint prevents extreme concentration, but users should think about their own maximum position sizes for names they're uncomfortable concentrating into.
What This Means for How You Use It
The right mental model is this: use the Max Sharpe portfolio as a reference point and the Min Variance portfolio as a floor. The Max Sharpe tells you what the data supports given your risk-adjusted return objective. The Min Variance tells you what the lowest-volatility version of your portfolio looks like.
If you hold 40% NVDA and the optimizer suggests 38%, that's basically alignment — no action needed. If you hold 5% NVDA and the optimizer suggests 38%, that's a signal worth thinking about: are you underweighting the best risk-adjusted name because of unfamiliarity or inertia?
We don't expect you to slavishly follow the weights. We expect you to look at the result, understand why the optimizer is allocating the way it is, and use that as a structured prompt to revisit whether your current portfolio reflects your actual views — or just the order you happened to buy things in.
That's the real value of a quant tool for a human investor: not to replace judgment, but to surface the implicit bets you're already making, and ask whether you'd make them consciously.
EvidInvest's portfolio optimizer is available on Pro and Professional plans. See Pricing for details.
Fair Value Weekly
Get DCF breakdowns, fair value updates, and portfolio ideas for serious investors. No spam, no paywalled teasers.