Calculate the Marginal Value at Risk (Marginal VaR) of each asset in a portfolio.

Ordinary VaR (see get_value_at_risk) treats each asset in isolation. Marginal VaR instead measures how much the portfolio’s VaR would change for an infinitesimal increase in a given asset’s portfolio weight - i.e. the sensitivity of portfolio risk to each holding, not the risk of the holding on its own.

The formula is as follows (with the default distribution=”historic”):

\[\text{Portfolio Return} = \operatorname{SUM}(\text{weight}_{i} \cdot \text{Return}_{i})\] \[\text{Beta}_{i} = \operatorname{Cov}(\text{Return}_{i},\; \text{Portfolio Return}) / \operatorname{Var}(\text{Portfolio Return})\] \[\text{Marginal VaR}_{i} = \text{Beta}_{i} \cdot \text{Portfolio VaR}\]

Where the weights are normalized to sum to 1, the covariance and variance are sample estimates (ddof=1) on the dates all assets have a return, and Portfolio VaR is the VaR of the portfolio return under distribution (see get_value_at_risk). The beta-based sensitivity is exact for a zero-mean elliptical distribution and an approximation otherwise; distribution=”gaussian” uses the exact derivative instead, with z_alpha the standard normal quantile at alpha:

\[\text{Gaussian Marginal VaR}_{i} = \text{Mean}_{i} + z_{\alpha} \cdot \operatorname{Cov}(\text{Return}_{i},\; \text{Portfolio Return}) / \operatorname{Std}(\text{Portfolio Return})\]

An asset with Beta_i > 1 contributes disproportionately to portfolio risk, while Beta_i < 1 (and especially Beta_i < 0) indicates a diversifying holding.

For more information about the method, see the following sources:

  • Garman, M.B. (1997). “Taking VaR to Pieces.” Risk, 10(10), 70-71.
  • Litterman, R. (1996). “Hot Spots and Hedges.” Goldman Sachs Risk Management Series.
  • Jorion, P. (2006). “Value at Risk: The New Benchmark for Managing Financial Risk.” 3rd ed., McGraw-Hill, Chapter 7.

Also known as: Marginal VaR, MVaR.

Marginal Value at Risk (mVaR) in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_marginal_value_at_risk as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["VTI", "TLT", "GLD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.risk.get_marginal_value_at_risk(weights={"VTI": 0.6, "TLT": 0.3, "GLD": 0.1})

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

What is the marginal Value at Risk of each holding in a portfolio of 60% VTI, 30% TLT and 10% GLD, based on returns from 2021 to 2025?

Which returns:

  Marginal VaR
VTI -0.0159
TLT -0.0078
GLD -0.0053

Parameters

get_marginal_value_at_risk accepts the following parameters.

ParameterTypeDescriptionExample
weightsdict[str, float] | NonePortfolio weights keyed by ticker. Normalized internally to sum to 1. Defaults to None, which uses equal weights across every ticker in the Toolkit instance (excluding the “Portfolio” and “Benchmark” pseudo-tickers, if present).{"AAPL": 0.6, "MSFT": 0.4}
periodstrThe data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”, since a whole-series estimate needs far more observations than a single quarter or year holds."weekly"
columnstrThe historical data column to use. Defaults to “Return”."Return"
alphafloatThe tail probability (e.g., 0.05 for the 95% confidence level). Defaults to 0.05.0.01
distributionstrThe distribution to use for the underlying portfolio VaR calculation (historic, gaussian, cornish-fisher or studentt). Defaults to “historic”."studentt"
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
Share