Risk
Classes
RiskInputs
Bases: BaseModel
Validated input parameters for VaR and CVaR calculations.
Attributes:
| Name | Type | Description |
|---|---|---|
confidence_level |
float
|
Confidence level for VaR (e.g. 0.95 for 95%). Must be in [0.90, 1.0]. |
num_simulations |
(int, optional)
|
Number of Monte Carlo simulations. Must be in [1000, 100000]. Default 10000. |
portfolio_weights |
list of float, optional
|
Asset weights in the portfolio. Each weight must be in [0, 1].
Pass |
portfolio_returns |
DataFrame
|
Historical log-returns. Columns are assets; rows are dates. |
is_single_stock |
(bool, optional)
|
Set to |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If any parameter fails its constraint. |
VaRAnalyzer
Class to perform a backtest for Value at Risk (VaR) calculations with non-overlapping windows
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
RiskInputs
|
Object containing the following option parameters: - confidence_level : float The confidence level for the VaR calculation. - num_simulations : int The number of Monte Carlo simulations. - portfolio_returns : pd.DataFrame Historical returns of portfolio assets or single stock. - is_single_stock : bool Flag to indicate single stock calculation. - portfolio_weights : list of float, optional Weights of assets in the portfolio (None for single stock). |
required |
window_volatility
|
int
|
The window size for the rolling volatility calculation, by default 21 |
21
|
window_forward
|
int
|
The window size for the rolling forward calculation, by default 10 |
10
|
Attributes:
| Name | Type | Description |
|---|---|---|
run |
str
|
The run attribute contains the results of the VaR backtest. |
VaRMetrics
Class to calculate various Value at Risk (VaR) metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
RiskInputs
|
Object containing the following option parameters: - confidence_level : float The confidence level for the VaR calculation. - num_simulations : int The number of Monte Carlo simulations. - portfolio_returns : pd.DataFrame Historical returns of portfolio assets or single stock. - is_single_stock : bool Flag to indicate single stock calculation. - portfolio_weights : list of float, optional Weights of assets in the portfolio (None for single stock). |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
parametric_var |
float
|
The parametric VaR value. |
historical_var |
float
|
The historical VaR value. |
monte_carlo_var |
float
|
The Monte Carlo VaR value. |
expected_shortfall |
float
|
The expected shortfall value. |