Valuation Adjustment API
This module provides functions for calculating various valuation adjustments in financial risk management.
Functions
- torchquantlib.core.risk.valuation_adjustment.valuation_adjustment.calculate_cva(exposure: Tensor, default_prob: Tensor, recovery_rate: Tensor) Tensor[source]
Calculate the Credit Valuation Adjustment (CVA).
CVA represents the market value of counterparty credit risk.
- Parameters:
exposure (Tensor) – Expected positive exposure to the counterparty.
default_prob (Tensor) – Probability of default of the counterparty.
recovery_rate (Tensor) – Expected recovery rate in case of default (between 0 and 1).
- Returns:
The calculated Credit Valuation Adjustment.
- Return type:
Tensor
- torchquantlib.core.risk.valuation_adjustment.valuation_adjustment.calculate_dva(exposure: Tensor, default_prob: Tensor, recovery_rate: Tensor) Tensor[source]
Calculate the Debit Valuation Adjustment (DVA).
DVA is similar to CVA but represents the credit risk of the entity itself.
- Parameters:
exposure (Tensor) – Expected negative exposure (i.e., liability) to the counterparty.
default_prob (Tensor) – Probability of default of the entity itself.
recovery_rate (Tensor) – Expected recovery rate in case of the entity’s default.
- Returns:
The calculated Debit Valuation Adjustment.
- Return type:
Tensor
- torchquantlib.core.risk.valuation_adjustment.valuation_adjustment.calculate_fva(exposure: Tensor, funding_spread: Tensor, maturity: Tensor) Tensor[source]
Calculate the Funding Valuation Adjustment (FVA).
FVA represents the cost of funding for uncollateralized derivatives.
- Parameters:
exposure (Tensor) – Expected exposure over the life of the derivative.
funding_spread (Tensor) – The entity’s funding spread above the risk-free rate.
maturity (Tensor) – Time to maturity of the derivative.
- Returns:
The calculated Funding Valuation Adjustment.
- Return type:
Tensor
- torchquantlib.core.risk.valuation_adjustment.valuation_adjustment.calculate_mva(exposure: Tensor, funding_cost: Tensor, maturity: Tensor) Tensor[source]
Calculate the Margin Valuation Adjustment (MVA).
MVA represents the cost of posting initial margin for cleared or non-cleared derivatives.
- Parameters:
exposure (Tensor) – Expected initial margin requirement.
funding_cost (Tensor) – The cost of funding the initial margin.
maturity (Tensor) – Time to maturity of the derivative.
- Returns:
The calculated Margin Valuation Adjustment.
- Return type:
Tensor
Detailed Description
The valuation adjustment module offers a set of functions to compute different types of valuation adjustments commonly used in financial risk management and derivatives pricing.
Credit Valuation Adjustment (CVA)
The calculate_cva function computes the Credit Valuation Adjustment, which represents the market value of counterparty credit risk.
Debit Valuation Adjustment (DVA)
The calculate_dva function calculates the Debit Valuation Adjustment, which is similar to CVA but represents the credit risk of the entity itself.
Funding Valuation Adjustment (FVA)
The calculate_fva function determines the Funding Valuation Adjustment, which represents the cost of funding for uncollateralized derivatives.
Margin Valuation Adjustment (MVA)
The calculate_mva function computes the Margin Valuation Adjustment, which represents the cost of posting initial margin for cleared or non-cleared derivatives.
Usage Example
Here’s a basic example of how to use the valuation adjustment functions:
import torch
from torchquantlib.core.risk.valuation_adjustment.valuation_adjustment import calculate_cva, calculate_dva, calculate_fva, calculate_mva
# Set up parameters
exposure = torch.tensor(1000000.0)
default_prob = torch.tensor(0.05)
recovery_rate = torch.tensor(0.4)
funding_spread = torch.tensor(0.02)
funding_cost = torch.tensor(0.03)
maturity = torch.tensor(5.0)
# Calculate adjustments
cva = calculate_cva(exposure, default_prob, recovery_rate)
dva = calculate_dva(exposure, default_prob, recovery_rate)
fva = calculate_fva(exposure, funding_spread, maturity)
mva = calculate_mva(exposure, funding_cost, maturity)
print(f"CVA: {cva.item():.2f}")
print(f"DVA: {dva.item():.2f}")
print(f"FVA: {fva.item():.2f}")
print(f"MVA: {mva.item():.2f}")
Note
All functions in this module use PyTorch tensors for input and output, allowing for efficient computation and automatic differentiation when needed.