EconStatsCraft rigorous, plain-spoken econometrics
Econometrics that explains itself.
Regression, panel data, time series and the whole battery of tests. Every result is followed by a verdict you can defend.
Load a dataset to see it here.
EconStatsCraft › Portfolio optimization
Takes the sample means and covariance of several return series and finds the minimum-variance and maximum-Sharpe portfolios, traces the efficient frontier, and shows how far inside it every single asset sits.
Portfolio optimization chooses the weights of assets to get the highest expected return for a given level of risk, or the lowest risk for a given return. In Markowitz mean-variance optimization, risk is the portfolio variance, which depends on every pair of assets' covariance, not just their individual volatilities.
The efficient frontier is the curve of portfolios that offer the best possible expected return at each level of volatility. Any portfolio below it is inefficient: another mix of the same assets gives more return for the same risk.
It is the portfolio on the efficient frontier with the highest excess return per unit of volatility. With a risk-free asset, every investor should hold this one risky portfolio and adjust risk by mixing it with cash or borrowing, which traces out the capital market line.
The minimum variance portfolio is the leftmost point of the efficient frontier: the lowest-volatility mix of the assets, chosen without using expected returns at all. Because expected returns are the hardest input to estimate, it is often more stable out of sample than the maximum-Sharpe portfolio.
Mean-variance optimization treats estimated returns as exact, so it piles into assets whose returns happen to be overestimated. Constraining weights (no short selling, position limits), using longer data or shrinking the inputs gives more sensible weights.
Given several assets, some combinations are simply better than others: same expected return for less risk. Plot every possible mix and the good ones trace out a curve, the efficient frontier. The mathematics is a constrained optimisation, but the economics is one idea - correlations below one mean a mix is less risky than its parts, and that free reduction in risk is the only free lunch in finance.
Asset allocation, constructing a benchmark-agnostic portfolio, teaching diversification, or showing why holding many imperfectly-correlated assets beats holding the best one.
Minimise portfolio variance w'\Sigma w subject to w'\mu=\mu_p and w'\mathbf{1}=1. The Lagrangian gives a closed form: with A=\mathbf{1}'\Sigma^{-1}\mathbf{1}, B=\mathbf{1}'\Sigma^{-1}\mu and C=\mu'\Sigma^{-1}\mu, the minimum-variance frontier is the parabola \sigma_p^2=(A\mu_p^2-2B\mu_p+C)/(AC-B^2). The global minimum-variance portfolio is w=\Sigma^{-1}\mathbf{1}/A and needs no expected returns at all, which is why it is far more stable in practice. Adding a risk-free asset gives the tangency portfolio w\propto\Sigma^{-1}(\mu-R_f\mathbf{1}), the mix with the highest Sharpe ratio.
\min_{w}\; w^{\top}\Sigma\,w \quad\text{s.t.}\quad w^{\top}\mathbf{1}=1,\; w^{\top}\mu = \bar{r};\qquad w_{\text{tan}} \propto \Sigma^{-1}(\mu - r_f\mathbf{1})
Five funds, and the global minimum-variance portfolio puts 100% of the money into one of them - the defensive fund, which happens to have the lowest volatility of the five (3.1691 against 5.17 to 6.47). That is the honest face of an unconstrained optimiser: nothing in the objective rewards diversification for its own sake, so if one asset dominates the covariance structure the solution is a corner. The resulting portfolio has an expected return of 0.5529 per period (6.635% annualised) at a volatility of 3.1691 (10.978% annualised). Notice what that means for the tangency portfolio further down, which adds expected RETURNS to the problem: minimum-variance uses only the covariance matrix, which is estimated reasonably well from 180 observations, while tangency also needs the means, which are not - the standard error on a mean return is roughly the volatility over the square root of the sample, and over any realistic sample that is large relative to the differences between assets. It is why minimum-variance weights are usually the ones worth taking to a client and tangency weights usually are not.
| If you see this | It means | Do this |
|---|---|---|
| Weights of +300% and -200% | Unconstrained optimiser on noisy means | Impose no-short, or use the minimum-variance portfolio |
| Weights change completely with one more month of data | Estimation error dominating | Shrink the covariance matrix; do not trust the point solution |
| One asset takes almost everything | Its sample mean is the highest, probably by luck | Check what happens with equal weights |
| Frontier is nearly a straight line | Assets are highly correlated | There is little diversification to be had here |
| Covariance matrix will not invert | More assets than periods | Shrinkage, or fewer assets |
| Tangency portfolio has a Sharpe ratio above 2 | In-sample overfitting | This will not survive out of sample |
Ridge / Lasso / Elastic Net, which is the same estimation-error problem in a regression - shrinking noisy estimates towards something stabler is exactly what a minimum-variance constraint does to weights. Value at Risk, for the tail rather than the variance.
Black–Scholes option pricing · Bond price, duration & convexity · Merton distance to default · EMI / home loan planner · CAPM / beta estimation · Multi-factor model · Value at Risk & Expected Shortfall · Performance & drawdown · Time value of money & NPV/IRR · Equity valuation (DDM, FCF, residual income) · Cost of capital (WACC) · Binomial option pricing · Option strategies (payoff & profit) · Forwards, futures & swaps · Credit risk & Basel capital · Extreme value theory (tail risk)
Line chart · Area chart · Bar chart · Stacked bar · Scatter plot · Bubble chart · Histogram · Box plot · Pie chart · Heat map · Rebased to 100 · Lorenz curve and Gini
World map · Bivariate map · Flow map · India - state map · India - district map
Descriptive statistics · Summary by group · Two-way table · Classical statistical tests
Multiple regression (OLS) · Logit / Probit · Tobit (censored) · Truncated regression · Multinomial logit · Ordered logit / probit · Quantile regression · Poisson / Negative binomial
Time-varying coefficients (Kalman) · Unit root tests · Correlogram (ACF / PACF) · ARIMA / SARIMA · Rolling-origin cross-validation · Theta method · Unobserved components · STL forecasting · Forecast combination · Markov regime switching · Change frequency (resample) · ARCH / GARCH volatility · Decompose & filter · Spectral analysis · Exponential smoothing · Forecast accuracy
Yield curve (Nelson–Siegel / Svensson) · Dynamic factor model · Dynamic regression (ARIMAX) · Structural VAR · VAR · Granger causality · Cointegration · VECM · ARDL & bounds test
Panel regression · Panel cointegration tests · Heterogeneous panel: Mean Group & PMG · Gravity model of trade · Dynamic panel GMM · Panel diagnostics · Panel unit-root tests
Principal components (PCA) · Factor analysis · Cluster analysis
Conjoint analysis · MaxDiff (best–worst scaling) · TURF - reach of a product line · Price sensitivity (Van Westendorp) · Market basket analysis · Perceptual map · Scale reliability (Cronbach’s alpha) · Key driver analysis
Spatial autocorrelation · Spatial regression · Heckman selection · Instrumental variables (2SLS) · Difference-in-differences · Staggered difference-in-differences · Regression discontinuity · Matching & weighting · Oaxaca–Blinder decomposition
Black–Scholes option pricing · Bond price, duration & convexity · Merton distance to default · EMI / home loan planner · CAPM / beta estimation · Multi-factor model · Portfolio optimization · Value at Risk & Expected Shortfall · Performance & drawdown · Time value of money & NPV/IRR · Equity valuation (DDM, FCF, residual income) · Cost of capital (WACC) · Binomial option pricing · Option strategies (payoff & profit) · Forwards, futures & swaps · Credit risk & Basel capital · Extreme value theory (tail risk)
Life table · Life annuity · Life insurance pricing · Chain ladder reserving · Buhlmann credibility · Survival analysis · Mortality graduation · Aggregate loss model · Ruin probability · Multi-state Markov model · Loss severity fitting
Monte Carlo experiment · F-test, Wald & Chow · Structural breaks & stability
Regression vs machine learning · Ridge / Lasso / Elastic Net · Random forest · Gradient boosting
EconStatsCraft rigorous, plain-spoken econometrics
Regression, panel data, time series and the whole battery of tests. Every result is followed by a verdict you can defend.
Load a dataset to see it here.
Pick the example closest to your question. You get a spreadsheet with the right columns and a few rows showing the expected format - replace the numbers with your own, then paste or upload it back.
Copy the header row from the table above (or from the downloaded template), put your own rows underneath, and paste the whole thing here. It is checked against the layout before anything is imported.
Or click a row in the preview below.
For a units or notes row.
Search every source at once. World Bank indicators need countries and years; everything else loads in one click.
Loading the catalogue…
The engine stays loaded, so this is quick - and it leaves your open tab and panel layout alone.
⌘/Ctrl+Enter runs the current analysis. ⌘/Ctrl+P exports the session as a PDF. Esc closes this.
In the Notebook: Enter starts a new block and
Shift+Enter a new line inside one; Backspace at the start
joins back into the paragraph above; / on an empty line inserts anything.
⌘/Ctrl+B, I, E, H and
M apply bold, italic, code, highlight and maths.
#, ##, -, 1., > and
``` at the start of a line convert it.
Sign in to run unlimited analyses.
Scroll to pan · Esc to close