Calculate the efficient frontier: the portfolios with the lowest volatility for each level of expected return, from the minimum variance portfolio up to the highest return the weight bounds allow. Every portfolio below the frontier takes more risk than needed for its return.

For more information, see the following paper:

  • Markowitz, H. (1952). “Portfolio Selection.” The Journal of Finance, 7(1), 77-91.

Also known as: Markowitz frontier, mean-variance frontier, risk-return frontier.

Efficient Frontier in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_efficient_frontier 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_efficient_frontier(points=5)

Or, after setting up the Finance Toolkit MCP, ask:

What does the efficient frontier of Apple, Microsoft, Johnson & Johnson and ExxonMobil look like in five portfolios, from the lowest risk to the highest return, based on 2021 to 2025?

Which returns:

Portfolio Expected Return Volatility Sharpe Ratio AAPL MSFT JNJ XOM
1 0.1575 0.135 0.9166 0.0212 0.2166 0.5821 0.1801
2 0.1909 0.1439 1.0917 0.0178 0.265 0.388 0.3292
3 0.2243 0.1679 1.1349 0.0145 0.3133 0.194 0.4782
4 0.2576 0.2016 1.111 0.0111 0.3616 0 0.6274
5 0.291 0.2702 0.9522 0 0 0 1

Parameters

get_efficient_frontier accepts the following parameters.

ParameterTypeDescriptionExample
pointsintThe number of portfolios on the frontier. Defaults to 20.20
periodstrThe frequency of the returns (daily, weekly, monthly, quarterly or yearly). Defaults to “daily”."weekly"
minimum_weightfloatThe lowest weight an asset may have. Defaults to 0.0
maximum_weightfloatThe highest weight an asset may have. Defaults to 1.1
include_benchmarkboolWhether to include the benchmark as an asset. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding.2
Share