Minimum Variance
Calculate the weights of the minimum variance portfolio: the fully invested portfolio of the Toolkit’s assets with the lowest volatility. It uses only the covariance matrix, not the expected returns, which makes it the most robust of the mean-variance portfolios to estimation error.
The weights minimize w’Σw subject to the weights summing to one and lying between the minimum and maximum weight, where Σ is the annualized covariance matrix of the returns.
For more information, see the following paper:
- Markowitz, H. (1952). “Portfolio Selection.” The Journal of Finance, 7(1), 77-91.
Also known as: global minimum variance portfolio, GMV, lowest risk portfolio.
Minimum Variance in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_minimum_variance_weights as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "MSFT", "JNJ", "XOM"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.portfolio.get_minimum_variance_weights()
Or, after setting up the Finance Toolkit MCP, ask:
Which weights in Apple, Microsoft, Johnson & Johnson and ExxonMobil gave the lowest-volatility portfolio based on 2021 to 2025?
Which returns:
| Weight | Expected Return | Volatility | Sharpe Ratio | Risk Contribution | |
|---|---|---|---|---|---|
| AAPL | 0.0212 | 0.1933 | 0.2786 | 0.5727 | 0.0212 |
| MSFT | 0.2166 | 0.2017 | 0.2572 | 0.6532 | 0.2166 |
| JNJ | 0.5821 | 0.0984 | 0.1673 | 0.3867 | 0.5821 |
| XOM | 0.1801 | 0.291 | 0.2702 | 0.9522 | 0.1801 |
| Portfolio | 1 | 0.1575 | 0.135 | 0.9166 | 1 |
Parameters
get_minimum_variance_weights accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The frequency of the returns the covariance matrix is estimated from (daily, weekly, monthly, quarterly or yearly). Defaults to “daily”. | "weekly" |
minimum_weight | float | The lowest weight an asset may have; a negative value allows short positions. Defaults to 0. | 0 |
maximum_weight | float | The highest weight an asset may have. Defaults to 1. | 1 |
include_benchmark | bool | Whether to include the benchmark as an asset. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding. | 2 |