fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Logistic PD Model

Install and import#

bash
npm install fintech-algorithms
ts
import { logisticPdModel } from "fintech-algorithms/credit-risk-and-default/probability-of-default/logistic-pd-model";

Signature#

logisticPdModel(intercept, coefficients, features, alert_threshold)

Applies a logistic link to a supplied linear credit score and reports the resulting default probability alongside the per-feature contributions that produced it and its position relative to an alert threshold.

Parameters#

NameTypeNotes
interceptnumberThe constant term of the already-fitted linear score. This function does not fit anything; the intercept and coefficients come from the caller.
coefficientsnumber[]The fitted coefficient for each feature, in the same order as features. Must hold at least one finite number.
min_length: 1 · same_length_as: features
featuresnumber[]The borrower's feature values, aligned position by position with coefficients.
min_length: 1
alert_thresholdnumberThe probability at or above which the borrower is flagged. Compared with the computed probability using a greater-than-or-equal test.
exclusive_min: 0 · exclusive_max: 1

Returns#

{ linear_score: number; feature_contributions: number[]; probability_of_default: number; survival_probability: number; odds_of_default: number; alert_threshold: number; state: string; reason: string }

linear_score is the intercept plus the summed contributions, and feature_contributions holds each coefficient times its feature. probability_of_default is the logistic transform of the score, survival_probability its complement, and odds_of_default the ratio of the two. state is at-or-above-alert or below-alert, and reason records that the score was supplied rather than fitted here.

Errors#

  • When any argument is not a finite number — throws Error
  • When coefficients or features is not an array of at least one finite number — throws Error
  • When coefficients and features have different lengths — throws Error
  • When alert_threshold is not strictly between zero and one — throws Error

Complexity: time O(n), space O(n).

Worked example#

verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

Input#

intercept
-2.4
coefficients
[0.8, -0.6, 1.1]
features
[0.5, -0.4, 0.2]
alert_threshold
0.2

Call#

logisticPdModel(intercept, coefficients, features, alert_threshold)

Returns#

object with 8 fields: linear_score, feature_contributions, probability_of_default, survival_probability, odds_of_default, alert_threshold, state, reason

{
  "linear_score": -1.54,
  "feature_contributions": [0.4, 0.24, 0.22],
  "probability_of_default": 0.176535274779,
  "survival_probability": 0.823464725221,
  "odds_of_default": 0.214381101427,
  "alert_threshold": 0.2,
  "state": "below-alert",
  "reason": "supplied-logit-score-transformed"
}

Other exports#

This module also exports probitPdModel, throughTheCyclePd, pointInTimePd, mertonDistanceToDefault, campbellHilscherSzilagyiDistressProbability, bharathShumwayNaiveDistanceToDefault, calculate. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams#

Logistic PD Model — article hero
Logistic PD Model — evidence clock
Logistic PD Model — formula anatomy
Logistic PD Model — method comparison
Logistic PD Model — system map
Logistic PD Model — validation layers

Calculation flow#

Logistic PD Model calculation flow
flowchart LR
    S1["Validate feature identity order units availability tim"]
    S2["Multiply each feature by its matching coefficient"]
    S3["Add the intercept to obtain the linear logodds score"]
    S4["Apply a numerically stable sigmoid"]
    S5["Return probability survival odds contribution trace an"]
    S1 --> S2
    S2 --> S3
    S3 --> S4
    S4 --> S5
    S5 --> D{"PD  alertthreshold uses an inclusive comparison"}
    D --> O["probability_of_default + diagnostics"]
    O --> A["Audit: probabilityofdefault  survivalprobability  1 within tolera"]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Probability of Default family#