Portfolio Risk Metrics
Calculate the return and risk of a portfolio with given weights over the Toolkit’s date range, next to the benchmark. The portfolio’s return in each period is the weighted return of its assets, r_p,t = Σ w_i r_i,t, which holds the weights constant by rebalancing to them every period. The measures use the formulas of the Performance and Risk modules:
\[\text{Annualized Return:}\;\; \text{the geometric average},\;\; \operatorname{Π}(1 + r_{t}) ^{P / T} - 1,\;\; \text{with P the periods per year and T the number of periods}\]-
Annualized Volatility: the standard deviation (ddof=1) times √P.
-
Sharpe Ratio: the average return above the risk free rate over its standard deviation, annualized with √P (Sharpe, 1966).
-
Sortino Ratio: the average return above the risk free rate over its downside deviation below zero, annualized with √P (Sortino and Price, 1994).
-
Maximum Drawdown: the largest fall of the compounded value from its peak.
-
Value at Risk: the 1 - α quantile of the returns per period (historical).
-
Conditional Value at Risk: the average return at or below the Value at Risk per period (historical).
Losses, drawdowns, the Value at Risk and the Conditional Value at Risk are negative returns, as in the Risk module.
For more information, see the following papers:
- Sharpe, W. F. (1966). “Mutual Fund Performance.” The Journal of Business, 39(1), 119-138.
- Sortino, F. A. and Price, L. N. (1994). “Performance Measurement in a Downside Risk Framework.” The Journal of Investing, 3(3), 59-64.
- Rockafellar, R. T. and Uryasev, S. (2002). “Conditional Value-at-Risk for General Loss Distributions.” Journal of Banking & Finance, 26(7), 1443-1471.
Also known as: portfolio risk report, risk summary, risk metrics of weights.
Portfolio Risk Metrics in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_portfolio_risk_metrics 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_portfolio_risk_metrics(
weights={"AAPL": 0.4, "MSFT": 0.3, "JNJ": 0.2, "XOM": 0.1}
)
Or, after setting up the Finance Toolkit MCP, ask:
What return, volatility, Sharpe ratio, maximum drawdown and value at risk did a portfolio of 40% Apple, 30% Microsoft, 20% Johnson & Johnson and 10% ExxonMobil have from 2021 to 2025, against the S&P 500?
Which returns:
| Portfolio | Benchmark | |
|---|---|---|
| Annualized Return | 0.1847 | 0.1472 |
| Annualized Volatility | 0.1855 | 0.1711 |
| Sharpe Ratio | 0.8247 | 0.6912 |
| Sortino Ratio | 1.211 | 0.996 |
| Maximum Drawdown | -0.1977 | -0.245 |
| Value at Risk | -0.0185 | -0.0166 |
| Conditional Value at Risk | -0.0263 | -0.0248 |
Parameters
get_portfolio_risk_metrics accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
weights | dict[str, float] | None | The weight per asset. Defaults to None, which uses the latest weights of the Portfolio the Toolkit came from, or equal weights. | None, which uses the latest weights of the Portfolio the Toolkit came from, or equal weights |
confidence_level | float | The confidence level of the Value at Risk and the Conditional Value at Risk, e.g. 0.95 for the worst 5% of periods. Defaults to 0.95. | 0.95 |
period | str | The frequency of the returns (daily, weekly, monthly, quarterly or yearly). Defaults to “daily”. | "weekly" |
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 |