Mean-variance portfolios
Portfolio expected return and risk, the minimum-variance frontier with short sales, and the minimum-variance and tangency portfolios.
- Model id
portfolio.mean_variance, version 1- Domain
- Portfolio
- Evidence
- standard
- Cost class
- instant: A closed-form calculation; a hosted run may take up to 2 seconds.
Formula
Where
- The portfolio's expected return
expected_return - The portfolio's weights
weights - The assets' expected returns
expected_returns - The portfolio's variance
variance - Covariance matrix of the assets' returns
covariance - Weights of the global minimum-variance portfolio
weights - The sum of the elements of the inverse covariance matrix
- Variance of the global minimum-variance portfolio
- The smallest variance for the expected return m
variances - A target expected return on the frontier
target_returns - Expected return of the global minimum-variance portfolio
minimum_variance_return - How fast the frontier's variance rises away from the minimum- variance return
- The assets' expected returns less the minimum-variance return
- Weights of the tangency portfolio
weights - Risk-free rate
risk_free_rate - Slope of the capital market line: the tangency portfolio's Sharpe ratio
capital_market_line_slope
Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.
Variables
Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.
Inputs
Expected return and risk of given weights (portfolio): 6 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Expected returnsexpected_returnsreturn (array) · length min 1, max 100; each [-1, 100] | return (array) | length min 1, max 100; each [-1, 100] | Expected return of each asset per period |
Covariancecovarianceratio (array) (array) · each length min 1, max 100; each [-100, 100] | ratio (array) (array) | each length min 1, max 100; each [-100, 100] | Covariance matrix of the asset returns per period, as rows; or give volatilities and correlations |
Volatilitiesvolatilitiesvolatility (array) · each (0, 10] | volatility (array) | each (0, 10] | Volatility of each asset per period, with correlations |
Correlationscorrelationscorrelation (array) (array) · each length min 1, max 100; each [-1, 1] | correlation (array) (array) | each length min 1, max 100; each [-1, 1] | Correlation matrix of the asset returns, as rows, with volatilities |
Calculationcalculationtext | text | Expected return and risk of given weights | |
Weightsweightsratio (array) · length min 1, max 100; each [-100, 100] | ratio (array) | length min 1, max 100; each [-100, 100] | Weight of each asset; negative is short. They need not sum to 1 |
Minimum-variance frontier, short sales allowed (frontier): 8 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Expected returnsexpected_returnsreturn (array) · length min 1, max 100; each [-1, 100] | return (array) | length min 1, max 100; each [-1, 100] | Expected return of each asset per period |
Covariancecovarianceratio (array) (array) · each length min 1, max 100; each [-100, 100] | ratio (array) (array) | each length min 1, max 100; each [-100, 100] | Covariance matrix of the asset returns per period, as rows; or give volatilities and correlations |
Volatilitiesvolatilitiesvolatility (array) · each (0, 10] | volatility (array) | each (0, 10] | Volatility of each asset per period, with correlations |
Correlationscorrelationscorrelation (array) (array) · each length min 1, max 100; each [-1, 1] | correlation (array) (array) | each length min 1, max 100; each [-1, 1] | Correlation matrix of the asset returns, as rows, with volatilities |
Calculationcalculationtext | text | Minimum-variance frontier, short sales allowed | |
Pointspointscount · [2, 200] | count | [2, 200] | Number of target returns to trace |
Min returnmin_returnreturn · [-1, 100] | return | [-1, 100] | Lowest target return; by default the minimum-variance return |
Max returnmax_returnreturn · [-1, 100] | return | [-1, 100] | Highest target return; by default the highest expected return of an asset |
Global minimum-variance portfolio (minimum_variance): 5 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Expected returnsexpected_returnsreturn (array) · length min 1, max 100; each [-1, 100] | return (array) | length min 1, max 100; each [-1, 100] | Expected return of each asset per period |
Covariancecovarianceratio (array) (array) · each length min 1, max 100; each [-100, 100] | ratio (array) (array) | each length min 1, max 100; each [-100, 100] | Covariance matrix of the asset returns per period, as rows; or give volatilities and correlations |
Volatilitiesvolatilitiesvolatility (array) · each (0, 10] | volatility (array) | each (0, 10] | Volatility of each asset per period, with correlations |
Correlationscorrelationscorrelation (array) (array) · each length min 1, max 100; each [-1, 1] | correlation (array) (array) | each length min 1, max 100; each [-1, 1] | Correlation matrix of the asset returns, as rows, with volatilities |
Calculationcalculationtext | text | Global minimum-variance portfolio |
Tangency portfolio and the capital market line (tangency): 6 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Expected returnsexpected_returnsreturn (array) · length min 1, max 100; each [-1, 100] | return (array) | length min 1, max 100; each [-1, 100] | Expected return of each asset per period |
Covariancecovarianceratio (array) (array) · each length min 1, max 100; each [-100, 100] | ratio (array) (array) | each length min 1, max 100; each [-100, 100] | Covariance matrix of the asset returns per period, as rows; or give volatilities and correlations |
Volatilitiesvolatilitiesvolatility (array) · each (0, 10] | volatility (array) | each (0, 10] | Volatility of each asset per period, with correlations |
Correlationscorrelationscorrelation (array) (array) · each length min 1, max 100; each [-1, 1] | correlation (array) (array) | each length min 1, max 100; each [-1, 1] | Correlation matrix of the asset returns, as rows, with volatilities |
Calculationcalculationtext | text | Tangency portfolio and the capital market line | |
Risk free raterisk_free_raterate · [-0.99, 10] | rate | [-0.99, 10] | Risk-free rate per period |
Outputs
Expected return and risk of given weights (portfolio): 5 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Expected return and risk of given weights | |
Expected returnexpected_returnreturn · [-1e+06, 1e+06] | return | [-1e+06, 1e+06] | Expected return per period, w'mu |
Variancevarianceratio · [0, 1e+10] | ratio | [0, 1e+10] | Variance of the return, w' Sigma w |
Volatilityvolatilityvolatility · [0, 100000] | volatility | [0, 100000] | Standard deviation of the return |
Weight sumweight_sumratio · [-10000, 10000] | ratio | [-10000, 10000] | Sum of the weights |
Minimum-variance frontier, short sales allowed (frontier): 7 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Minimum-variance frontier, short sales allowed | |
Minimum variance returnminimum_variance_returnreturn · [-1e+06, 1e+06] | return | [-1e+06, 1e+06] | Expected return of the minimum-variance portfolio |
Minimum variance volatilityminimum_variance_volatilityvolatility · [0, 10] | volatility | [0, 10] | Volatility of the minimum-variance portfolio |
Target returnstarget_returnsreturn (array) · length max 200; each [-1e+06, 1e+06] | return (array) | length max 200; each [-1e+06, 1e+06] | Target expected returns, ascending |
Variancesvariancesratio (array) · length max 200; each [0, 1e+10] | ratio (array) | length max 200; each [0, 1e+10] | Lowest variance at each target return |
Volatilitiesvolatilitiesvolatility (array) · length max 200; each [0, 100000] | volatility (array) | length max 200; each [0, 100000] | Lowest volatility at each target return |
Weightsweightsratio (array) (array) · length max 200; each length max 100; each [-1e+06, 1e+06] | ratio (array) (array) | length max 200; each length max 100; each [-1e+06, 1e+06] | Weights of the frontier portfolio at each target, as rows |
Global minimum-variance portfolio (minimum_variance): 5 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Global minimum-variance portfolio | |
Weightsweightsratio (array) · length max 100; each [-1e+06, 1e+06] | ratio (array) | length max 100; each [-1e+06, 1e+06] | Weight of each asset; they sum to 1 |
Expected returnexpected_returnreturn · [-1e+06, 1e+06] | return | [-1e+06, 1e+06] | Expected return per period |
Variancevarianceratio · [0, 100] | ratio | [0, 100] | Variance, 1 / A; never above the least risky asset's |
Volatilityvolatilityvolatility · [0, 10] | volatility | [0, 10] | Standard deviation of the return |
Tangency portfolio and the capital market line (tangency): 6 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Tangency portfolio and the capital market line | |
Weightsweightsratio (array) · length max 100; each [-1e+06, 1e+06] | ratio (array) | length max 100; each [-1e+06, 1e+06] | Weight of each asset; they sum to 1 |
Expected returnexpected_returnreturn · [-1e+06, 1e+06] | return | [-1e+06, 1e+06] | Expected return per period |
Variancevarianceratio · [0, 1e+10] | ratio | [0, 1e+10] | Variance of the return |
Volatilityvolatilityvolatility · [0, 100000] | volatility | [0, 100000] | Standard deviation of the return |
Capital market line slopecapital_market_line_sloperatio · [0, 1e+06] | ratio | [0, 1e+06] | Slope of the capital market line: the tangency portfolio's Sharpe ratio per period, the highest of any portfolio of the assets |
Calculator
Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.
Loading the calculator…
Worked example
Example sixty_forty. Inputs:
{
"calculation": "portfolio",
"correlations": [
[1, 0.3],
[0.3, 1]
],
"covariance": null,
"expected_returns": [0.1, 0.06],
"volatilities": [0.2, 0.1],
"weights": [0.6, 0.4]
}Outputs:
{
"calculation": "portfolio",
"expected_return": 0.08399999999999999,
"variance": 0.01888,
"volatility": 0.13740451229854134,
"weight_sum": 1
}Assumptions
- Expected returns, volatilities and covariances are per period and given, not estimated here; the outputs are in the same period.
- Short sales are allowed and unlimited, there are no transaction costs or taxes, and the weights of an optimized portfolio sum to one.
- The outputs follow from the inputs the user supplies, the same for every user: they are formula results, not investment advice, and no portfolio here is advice to hold it.
Limitations
- A covariance (or correlation) matrix that is not symmetric and positive definite to working precision, or a correlation matrix without ones on its diagonal, raises DomainError.
- A frontier when every expected return is equal, or over an empty range of returns, raises DomainError; so does a tangency portfolio for a risk-free rate not below the minimum-variance return.
- A matrix so close to singular that a weight exceeds 1e6 in size, or another output its bounds, raises DomainError.
- Mean-variance weights are very sensitive to the expected returns; estimation error is not modelled. Long-only and other constraints are not supported.
Evidence
Status: standard. Textbook consensus, such as bond duration or the CAPM formula.
Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).
Syllabus
The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.
Citations
- Markowitz, H. (1952). Portfolio selection. The Journal of Finance, 7(1), 77-91. doi:10.1111/j.1540-6261.1952.tb01525.x (p. 81, the expected return E and variance V of a portfolio)
- Merton, R. C. (1972). An analytic derivation of the efficient portfolio frontier. Journal of Financial and Quantitative Analysis, 7(4), 1851-1872. doi:10.2307/2329621 (Eqs. (12)-(14), the frontier and its minimum-variance portfolio; Section IV, eq. (44), the tangency portfolio (numbered as in MIT Sloan working paper 493-70))
Changelog
- Version 1: First version.
Use it elsewhere
- Documentation
- The model's reference page
- REST API
GET or POST /v1/models/portfolio.mean_variance/run- MCP tool
portfolio_mean_variance, orrun_modelwith the model's id; both give the same result. Connect an assistant- Command line
pyeconomics models run portfolio.mean_variance --help
The worked example, from Python and from the command line:
import pyeconomics
inputs = {
"calculation": "portfolio",
"correlations": [
[1, 0.3],
[0.3, 1],
],
"covariance": None,
"expected_returns": [0.1, 0.06],
"volatilities": [0.2, 0.1],
"weights": [0.6, 0.4],
}
result = pyeconomics.run("portfolio.mean_variance", inputs)
print(result.to_json())
pyeconomics models run portfolio.mean_variance --inputs - <<'JSON'
{
"calculation": "portfolio",
"correlations": [
[1, 0.3],
[0.3, 1]
],
"covariance": null,
"expected_returns": [0.1, 0.06],
"volatilities": [0.2, 0.1],
"weights": [0.6, 0.4]
}
JSON