# Counterparty credit product examples

Run `examples/counterparty_credit_products.py`, or the packaged R `run_counterparty_credit_products()` example. Complete JSON inputs describe signed trade values, legal netting evidence, collateral ownership and dated margin calls, market prices, default/closeout dates, a frozen PD model and separate synthetic holdout observations. The four variants are netting set, collateralized, uncollateralized and wrong-way exposure. They are small analytical references, not empirical validation or a claim of regulatory capital/CVA compliance.

Each variant routes the counterparty profile, predicts a two-day physical PD of 0.5 from a frozen logit reference, aggregates signed values within the legal set, runs the margin ledger and freezes collateral at default. It then computes expected loss from joint default/exposure scenarios, validates exposures against a separately constructed synthetic observed-path artifact and composes a transaction-level assessment. PD, scenario default frequency and horizon match; the coupling of defaults and exposures is an explicit supplied assumption.

At inception trades +100 and -60 yield exposure 40 in the same enforceable set, but total exposure 100 in separate sets. Uncollateralized paths end at net value 90. With equal scenario weights, only scenario h defaults and LGD is 0.6: EL = 0.5 × 90 × 0.6 = 27. In the wrong-way case the surviving scenario exposure is only 10, so the independence benchmark is 0.5 × mean(90,10) × 0.6 = 15. The joint path calculation preserves the dependence contribution 12.

The collateralized example defaults January 2 before that day's margin events. It therefore freezes 40 opening units from January 1, not the subsequent 60 or 180 units. At January 3 closeout, price 0.5 leaves recognized collateral 20. Net market value 90 plus the expressly excluded unpaid January 3 cashflow 10 gives closeout exposure 80 and EL24. Ordinary January 3 margin would produce market exposure zero. The validator reports ordinary exposure and the conditional-on-default closeout subset separately, reproducing zero and 80 respectively. Its one synthetic observation provides a reconciliation oracle, not statistical power; no sampling confidence interval or LGD/loss performance verdict is inferred.

Counterfactual closeouts for both scenario paths allow a defined unconditional exposure comparator; only h is included in the actual default-conditioned forecast/observation subset. Zero-collateral variants use explicit nonbinding margin thresholds. Each variant has its own controlled invalid-contract check: unenforceable multitrade netting, missing closeout grid extension, overlapping legal sets or duplicate scenario identifiers.

The assessment binds the scenario artifacts and keeps exposure-loss estimates at transaction level. These examples execute all counterparty recipe methods and four variants. Full lifecycle acceptance additionally requires separate dated governance and workout journeys.
