Skip to content

API Reference

The public facade lives at the top level of the package.

wayfault.estimate_wwr

estimate_wwr(exposure: ExposureSource, credit: CreditCurveSource, model: DependenceModel, discount: ndarray | None = None, pfe_quantile: float = 0.95, sink: ResultSink | None = None) -> WWRResult

Estimate Wrong-Way Risk for one counterparty.

Parameters:

Name Type Description Default
exposure ExposureSource

The outbound-port collaborators.

required
credit ExposureSource

The outbound-port collaborators.

required
model ExposureSource

The outbound-port collaborators.

required
discount ndarray | None

Optional discount factors on the grid.

None
pfe_quantile float

Quantile for the PFE profile.

0.95
sink ResultSink | None

Optional result sink; if given, the result is also written to it.

None

Returns:

Type Description
WWRResult

The full result object.

Source code in src/wayfault/adapters/inbound/api.py
def estimate_wwr(
    exposure: ExposureSource,
    credit: CreditCurveSource,
    model: DependenceModel,
    discount: np.ndarray | None = None,
    pfe_quantile: float = 0.95,
    sink: ResultSink | None = None,
) -> WWRResult:
    """Estimate Wrong-Way Risk for one counterparty.

    Parameters
    ----------
    exposure, credit, model:
        The outbound-port collaborators.
    discount:
        Optional discount factors on the grid.
    pfe_quantile:
        Quantile for the PFE profile.
    sink:
        Optional result sink; if given, the result is also written to it.

    Returns
    -------
    WWRResult
        The full result object.
    """
    request = WWRRequest(
        exposure=exposure,
        credit=credit,
        model=model,
        discount=discount,
        pfe_quantile=pfe_quantile,
    )
    result = WrongWayRiskService().estimate(request)
    if sink is not None:
        sink.write(result)
    return result

wayfault.WWRResult dataclass

WWRResult(baseline_cva: float, wwr_cva: float, alpha: float, classification: WWRClass, tenors: ndarray, epe: ndarray, conditional_ee: ndarray, pfe: ndarray, eepe: float, ead: float, uplift_pct: float, ee_ratio: ndarray, ee_hazard_corr: float, model: str, params: dict[str, float] = dict())

Outputs of a WWR estimation.

Attributes:

Name Type Description
baseline_cva, wwr_cva, alpha

The independent CVA, the WWR-adjusted CVA, and their ratio.

classification WWRClass

WWR / RWR / NEUTRAL label.

tenors ndarray

The tenor grid year-fractions (x-axis for the per-tenor profiles).

epe, conditional_ee, pfe

Per-tenor profiles (numpy arrays).

eepe float

Effective EPE scalar.

ead float

alpha * eepe.

uplift_pct, ee_ratio, ee_hazard_corr

Diagnostics.

model, params

Metadata about the dependence model used.

to_dict

to_dict() -> dict[str, Any]

Return a JSON-serialisable dictionary representation.

Source code in src/wayfault/application/dto.py
def to_dict(self) -> dict[str, Any]:
    """Return a JSON-serialisable dictionary representation."""
    return {
        "baseline_cva": self.baseline_cva,
        "wwr_cva": self.wwr_cva,
        "alpha": self.alpha,
        "classification": self.classification.value,
        "tenors": self.tenors.tolist(),
        "epe": self.epe.tolist(),
        "conditional_ee": self.conditional_ee.tolist(),
        "pfe": self.pfe.tolist(),
        "eepe": self.eepe,
        "ead": self.ead,
        "uplift_pct": self.uplift_pct,
        "ee_ratio": self.ee_ratio.tolist(),
        "ee_hazard_corr": self.ee_hazard_corr,
        "model": self.model,
        "params": self.params,
    }

wayfault.WWRRequest dataclass

WWRRequest(exposure: ExposureSource, credit: CreditCurveSource, model: DependenceModel, discount: ndarray | None = None, pfe_quantile: float = 0.95)

Inputs for a WWR estimation.

Parameters:

Name Type Description Default
exposure ExposureSource

Port supplying the exposure cube.

required
credit CreditCurveSource

Port supplying the credit curve.

required
model DependenceModel

The dependence model to apply.

required
discount ndarray | None

Optional discount factors on the grid (defaults to 1.0).

None
pfe_quantile float

Quantile used for the PFE profile.

0.95

wayfault.WWRClass

Bases: StrEnum

Classification of the dependence direction.

Errors

wayfault.WayfaultError

Bases: Exception

Base class for all :mod:wayfault errors.

wayfault.ValidationError

Bases: WayfaultError

Raised when a value object fails its construction-time invariants.

wayfault.MissingDependencyError

MissingDependencyError(package: str, extra: str)

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. "pandas").

required
extra str

The :mod:wayfault extras group that provides it (e.g. "io").

required
Source code in src/wayfault/domain/errors.py
def __init__(self, package: str, extra: str) -> None:
    self.package = package
    self.extra = extra
    super().__init__(
        f"Optional dependency {package!r} is required for this feature. "
        f"Install it with: pip install 'wayfault[{extra}]'"
    )

Browse the layers:

  • Domain — pure value objects and functions.
  • Application — service and DTOs.
  • Ports — Protocol definitions.
  • Adapters — concrete implementations.