Domain¶
Pure value objects and functions — stdlib + numpy only.
Tenors¶
wayfault.domain.tenors ¶
The :class:TenorGrid value object.
TenorGrid
dataclass
¶
A strictly increasing grid of positive year-fractions t_1 < ... < t_n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
ndarray
|
One-dimensional array of strictly increasing, strictly positive year-fractions. |
required |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the grid is empty, not one-dimensional, contains non-positive values, or is not strictly increasing. |
Exposure¶
wayfault.domain.exposure ¶
Exposure value objects: :class:ExposureCube and :class:EEProfile.
EEProfile
dataclass
¶
An expected-exposure curve over a tenor grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
TenorGrid
|
The tenor grid the profile is defined on. |
required |
values
|
ndarray
|
Expected positive exposure |
required |
ExposureCube
dataclass
¶
A Monte-Carlo exposure cube of netting-set mark-to-market values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
TenorGrid
|
The tenor grid the columns are defined on. |
required |
values
|
ndarray
|
Array of shape |
required |
tenor_slice ¶
from_ee_profile
classmethod
¶
Build a degenerate single-scenario cube from an :class:EEProfile.
This lets users with only a precomputed EE profile still run the independent metrics. The single row reproduces the profile exactly for the positive-exposure expectation.
Source code in src/wayfault/domain/exposure.py
Credit¶
wayfault.domain.credit ¶
Credit term-structure value objects.
Provides :class:CreditCurve with interchangeable hazard / survival / marginal
PD representations, and a :class:RecoveryRate value object. Two concrete hazard
shapes are supported: flat and piecewise-constant.
RecoveryRate
dataclass
¶
A recovery rate R in [0, 1).
CreditCurve
dataclass
¶
A piecewise-constant hazard credit curve.
A flat curve is the degenerate single-segment case. Internally the curve is
represented by piecewise-constant hazard rates over the segments defined by
knots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
knots
|
ndarray
|
Strictly increasing positive segment end-times. Hazard |
required |
hazards
|
ndarray
|
Non-negative piecewise-constant hazard rates, same length as |
required |
recovery
|
RecoveryRate
|
The :class: |
required |
flat
classmethod
¶
Construct a flat-hazard curve.
piecewise
classmethod
¶
Construct a piecewise-constant hazard curve.
Source code in src/wayfault/domain/credit.py
hazard ¶
Instantaneous hazard lambda(t) at each time in t.
Source code in src/wayfault/domain/credit.py
cumulative_hazard ¶
Integrated hazard :math:\int_0^t \lambda(u)\,du at each time.
Source code in src/wayfault/domain/credit.py
survival ¶
marginal_pd ¶
Marginal default probabilities PD(t_{i-1}, t_i) on the grid.
Returns the probability of default in each interval, length grid.n,
with the first interval measured from time 0.
Source code in src/wayfault/domain/credit.py
Portfolio¶
wayfault.domain.portfolio ¶
Counterparty / netting-set aggregation.
NettingSet
dataclass
¶
A named netting set holding an exposure cube.
Counterparty
dataclass
¶
A counterparty aggregating one or more netting sets.
aggregate ¶
Aggregate netting-set cubes to a single counterparty-level cube.
Netting applies within a set; across sets values are summed scenario-by-scenario (no further netting benefit across sets).
Source code in src/wayfault/domain/portfolio.py
Metrics¶
wayfault.domain.metrics ¶
Baseline exposure metrics: EPE, ENE, PFE, EEPE.
epe ¶
Expected positive exposure EPE(t) = E[V(t)+] per tenor.
ene ¶
Expected negative exposure ENE(t) = E[(-V(t))+] per tenor.
pfe ¶
Potential future exposure: the q-quantile of V(t)+ per tenor.
Source code in src/wayfault/domain/metrics.py
eepe ¶
Effective expected positive exposure (time-weighted running-max EE).
EEE(t) is the running maximum of EPE up to t; EEPE is the
time-weighted average of EEE over the grid (Basel definition), using the
grid interval lengths as weights.
Source code in src/wayfault/domain/metrics.py
CVA¶
wayfault.domain.cva ¶
Unilateral CVA integral (independent and conditional).
discounted_cva ¶
discounted_cva(ee: EEProfile, curve: CreditCurve, grid: TenorGrid, discount: ndarray | None = None) -> float
Unilateral CVA over the grid.
Computes
.. math::
CVA = (1 - R) \sum_i DF(t_i)\, EE(t_i)\, PD(t_{i-1}, t_i)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ee
|
EEProfile
|
The (independent or conditional) expected-exposure profile. |
required |
curve
|
CreditCurve
|
The counterparty credit curve (supplies marginal PDs and recovery). |
required |
grid
|
TenorGrid
|
The tenor grid. |
required |
discount
|
ndarray | None
|
Optional discount factors on the grid (length |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The CVA value. |
Source code in src/wayfault/domain/cva.py
Wrong-Way Risk¶
wayfault.domain.wwr ¶
Wrong-Way / Right-Way Risk: alpha multiplier, classification, diagnostics.
WWRClass ¶
Bases: StrEnum
Classification of the dependence direction.
Diagnostics
dataclass
¶
Diagnostic summary of the WWR adjustment.
alpha_multiplier ¶
Empirical alpha multiplier alpha = WWR-CVA / independent-CVA.
Returns 1.0 if the baseline CVA is (near) zero, since there is no
exposure to amplify.
Source code in src/wayfault/domain/wwr.py
ead ¶
classify ¶
Label the dependence from the parameter sign and CVA uplift.
A positive parameter together with alpha > 1 is wrong-way; a negative
parameter with alpha < 1 is right-way; otherwise neutral.
Source code in src/wayfault/domain/wwr.py
diagnostics ¶
diagnostics(unconditional: EEProfile, conditional: EEProfile, hazard: ndarray, baseline_cva: float, wwr_cva: float) -> Diagnostics
Compute per-tenor diagnostics for the WWR adjustment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unconditional
|
EEProfile
|
Unconditional EPE profile. |
required |
conditional
|
EEProfile
|
Conditional-on-default EE profile. |
required |
hazard
|
ndarray
|
Per-tenor hazard rates (length |
required |
baseline_cva
|
float
|
The two CVA figures, for the uplift percentage. |
required |
wwr_cva
|
float
|
The two CVA figures, for the uplift percentage. |
required |
Source code in src/wayfault/domain/wwr.py
Errors¶
wayfault.domain.errors ¶
Domain exceptions for :mod:wayfault.
These exceptions are part of the pure domain layer and depend only on the standard library.
WayfaultError ¶
Bases: Exception
Base class for all :mod:wayfault errors.
ValidationError ¶
Bases: WayfaultError
Raised when a value object fails its construction-time invariants.
MissingDependencyError ¶
Bases: WayfaultError
Raised when an optional adapter is used without its extra installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
str
|
The importable package that was missing (e.g. |
required |
extra
|
str
|
The :mod: |
required |