Copula Simulation
Calibrate a bivariate copula (see get_copula_parameters) between ticker_a and ticker_b, and simulate joint scenarios from it.
When ticker_a/ticker_b are not given, every unique pair among the Toolkit’s tickers is calibrated and simulated instead, as columns grouped under a top-level (Ticker A, Ticker B) column per pair.
This is what a copula-based portfolio Monte Carlo simulation needs: draws that preserve the calibrated dependence structure – including tail dependence, for the “student-t”, “clayton” and “gumbel” families – rather than the (typically understated) joint crash risk a plain multivariate gaussian simulation would produce.
Also known as: copula Monte Carlo, dependence simulation, scenario generation.
Copula Simulation in Python
get_copula_simulation is part of the Risk module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_copula_simulation as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AMZN", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit.risk.get_copula_simulation(
"AAPL", "MSFT", copula="clayton", period="weekly", n_simulations=5000
).describe()
Which returns:
| AAPL | MSFT | |
|---|---|---|
| count | 5000 | 5000 |
| mean | 0.00357512 | 0.0028215 |
| std | 0.0371953 | 0.0365134 |
| min | -0.1316 | -0.0764 |
| 25% | -0.0196 | -0.0211 |
| 50% | 0.0019 | 0.00145 |
| 75% | 0.0261 | 0.0213 |
| max | 0.1315 | 0.2169 |
Parameters
get_copula_simulation accepts the following parameters:
- ticker_a (str, optional): The first asset. Defaults to None, meaning every unique pair of
tickers in the Toolkit instance is used (requires
ticker_bto also be None). - ticker_b (str, optional): The second asset. Defaults to None, see
ticker_a. - copula (str, optional): The copula family to fit and simulate from, one of “gaussian”, “student-t”, “clayton”, “gumbel” or “frank”. Defaults to “gaussian”.
- period (str, optional): The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”, since a dependence estimate needs far more observations than a lower frequency provides – at “yearly” a decade of history is only ten observations.
- column (str, optional): The historical data column to use. Defaults to “Return”.
- n_simulations (int, optional): The number of joint draws to simulate. Defaults to 10,000.
- random_state (int, optional): The seed for the random number generator. Defaults to 42.
- empirical_margins (bool, optional): Whether to map the simulated pseudo-observations back to realistic returns via each asset’s own empirical (historical) quantile function. Defaults to True. When False, the raw pseudo-observations (each in (0, 1)) are returned instead.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.