5D Library › Cross-Border Payment Routing, Chargeback Defense Games and Treasury Ruin Bounds · 中文

Chapter 6. A Formula for the Minimum Safe Reserve, and Spreading over Gateways

A reserve formula you can work by hand

Putting the two parts of Chapter 5 together gives an approximate formula for the minimum safe reserve. Let VV be daily card sales, mm the daily net cash drift with no reserve held (net margin minus the mean outflow of shocks), rr and HH the reserve rate and holding days, and σ\sigma the standard deviation of the daily shocks. Then

umin≈G+max⁡{0,−(m−0.97rV)}H+2.326σH+P+(1+θ)μθln⁡1(1+θ)ε.u_{\min} \approx G + \max\{0,\,-(m – 0.97rV)\}\,H + 2.326\,\sigma\sqrt{H} + P + \frac{(1+\theta)\mu}{\theta}\ln\frac{1}{(1+\theta)\varepsilon}.

The first term GG is the start-up gap before the first settlement arrives; the second, the cash drained by negative drift during the holding period; the third, the 99% swing of the random shocks over that period (counted only when the drift is negative); PP is the extra refunds of a return season falling inside the negative-drift period; and the last, the Lundberg reserve needed, once the drift is positive, to push the ruin probability down to ε\varepsilon.

Calculation

# Chapter 6. p11: A formula for the minimum safe cash reserve, checked
# against the simulation of p10. Daily drift of cash once payouts flow
# and no reserve is held: m = (0.97 - 0.75 - 0.03) V minus the mean shock
# outflow 2/7 * 8,000. A rolling reserve r cuts the drift by r * 0.97 V
# for the first H days. Then
#   u = start gap + drain + swing + pulse + Lundberg,
# start gap = 2 days of costs and refunds before the first payout;
# drain = max(0, -(m - r*0.97*V)) * H; swing = 2.326 sd of the shocks
# over the H days when the drift there is negative (shock variance per
# day 2/7 * 2 * 8,000^2); pulse = the extra refunds of the return season
# if it falls inside that window; Lundberg = cash for a 1% ruin chance at
# the positive drift (p09 formula, theta = drift / mean shock outflow).
import importlib.util
from math import log, sqrt

def load(name):
    spec = importlib.util.spec_from_file_location(name, name + ".py")
    m = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(m)
    return m

p10 = load("p10_rolling_reserve")
V, MU, LAM = p10.V, 8000.0, 2 / 7

def formula(r, H, eps=0.01):
    shock = LAM * MU
    m = (p10.PAY - p10.COST - p10.REF) * V - shock
    ramp = m - r * p10.PAY * V
    start = 2 * (p10.COST + p10.REF) * V
    drain = max(0.0, -ramp) * H
    swing = 2.326 * sqrt(H * LAM * 2 * MU ** 2) if ramp < 0 else 0.0
    pulse = 2 * p10.REF * V * 14 if (ramp < 0 and H > 300) else 0.0
    theta = (ramp if ramp > 0 else m) / shock
    lund = (1 + theta) * MU / theta * log(1 / ((1 + theta) * eps))
    return start + drain + swing + pulse + lund, drain, swing, lund

if __name__ == "__main__":
    print("   r     H   drain     swing    Lundberg  formula  simulated")
    for r, H in ((0.0, 0), (0.10, 90), (0.10, 180), (0.20, 90),
                 (0.20, 180)):
        u, d, sw, lu = formula(r, H)
        print("   {:3.0%}  {:3d}  {:7,.0f}  {:7,.0f}  {:8,.0f}  {:7,.0f}"
              "  {:9,.0f}".format(r, H, d, sw, lu, u, p10.need(r, H)))
    print("   start gap in every row: RM {:,.0f}".format(
        2 * (p10.COST + p10.REF) * V))
#    r     H   drain     swing    Lundberg  formula  simulated
#     0%    0        0        0    38,941  101,341    109,668
#    10%   90        0        0    85,447  147,847    154,991
#    10%  180        0        0    85,447  147,847    157,884
#    20%   90  220,114  133,445    38,941  454,900    428,954
#    20%  180  440,229  188,720    38,941  730,289    706,439
#    start gap in every row: RM 62,400

The start-up gap is RM 62,400. With no reserve held the formula gives RM 101,341 and simulation RM 109,668; holding 10%, the formula gives RM 147,847 and simulation RM 154,991 and RM 157,884; holding 20% for 90 days, the formula gives RM 454,900 (of which drain RM 220,114 and swing RM 133,445) and simulation RM 428,954; holding 20% for 180 days, the formula gives RM 730,289 and simulation RM 706,439. Formula and simulation differ by less than a tenth: slightly low when the drift is positive, slightly high when it is negative.

Note

Use the formula for the order of magnitude, simulation for the number. The formula lets finance staff estimate the scale of the reserve without a simulation tool; when the reserve is actually decided, it should be simulated on the firm’s own cash-flow data.

One gateway frozen means the whole cash flow stops

The greatest risk is not the reserve but a gateway suddenly freezing all settlements. Below, the merchant of Chapter 5 (10% held for 90 days) splits its card sales evenly over kk gateways; each gateway independently freezes settlements at a rate of 0.3 times a year, paying out after 90 days, while costs and refunds go on.

Calculation

# Chapter 6. p12: Spreading volume over several gateways. The business of
# p10 (10% rolling reserve for 90 days) splits its card sales evenly over
# k gateways. Each gateway, independently, freezes all payouts at random
# times (0.3 freezes a year); a freeze lasts 90 days, after which the
# held money is paid out. Costs and refunds go on. Cash needed so that
# the balance stays above zero over two years in 99% of 1,000 paths.
# Seed 85.
import importlib.util
import random

def load(name):
    spec = importlib.util.spec_from_file_location(name, name + ".py")
    m = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(m)
    return m

p10 = load("p10_rolling_reserve")
V, PAY, R, H = p10.V, p10.PAY, 0.10, 90

def path(rng, k, days=730):
    frozen_until = [0] * k
    owed = [0.0] * k
    cash, low, froze = 0.0, 0.0, False
    for d in range(days):
        for g in range(k):
            if frozen_until[g] <= d and rng.random() < 0.3 / 365:
                frozen_until[g] = d + 90
                froze = True
            share = V / k
            due = 0.0
            if d >= 2:
                due += (1 - R) * PAY * share
            if d >= H:
                due += R * PAY * share
            if frozen_until[g] > d:
                owed[g] += due
            else:
                cash += due + owed[g]
                owed[g] = 0.0
        refunds = p10.REF * V * (3 if 300 <= d < 314 else 1)
        cash -= p10.COST * V + refunds
        for _ in range(p10.shocks(rng, 2 / 7)):
            cash -= rng.expovariate(1 / 8000.0)
        low = min(low, cash)
    return -low, froze

if __name__ == "__main__":
    rng = random.Random(85)
    print("   gateways  cash needed (99%) RM  share of paths with a freeze")
    for k in (1, 2, 3, 4):
        runs = [path(rng, k) for _ in range(1000)]
        s = sorted(x for x, _ in runs)
        print("   {:8d}  {:20,.0f}  {:.3f}".format(
            k, s[989], sum(1 for _, f in runs if f) / 1000))
#    gateways  cash needed (99%) RM  share of paths with a freeze
#           1             3,114,683  0.463
#           2             2,026,860  0.687
#           3             1,532,138  0.818
#           4             1,258,468  0.907

With one gateway, staying in cash in 99% of cases over two years needs RM 3,114,683: one freeze means 90 days without income. Split over two gateways, RM 2,026,860; three, RM 1,532,138; four, RM 1,258,468. The more gateways, the more paths meet a freeze (0.907 of paths with four gateways meet at least one), but each freeze holds up only part of the cash flow, so the reserve needed falls sharply.

Reserve needed to stay in cash in 99% of cases over two years, against the number of gateways (p12).

Hypothesis · not established

The author’s hypothesis (not yet tested): for cross-border merchants of digital products with card sales on the order of a million ringgit a month, spreading card sales over three or more acquiring channels rather than one at least halves the longest run of days without settlements in years when a freeze occurs. What would show it wrong: in many merchants’ records, the longest run without settlements in freeze years differs by less than half between the two practices.

Summary

The minimum safe reserve can be written approximately as the sum of the start-up gap, the drain of negative drift, the swing of the shocks, the extra refunds of a return season and the Lundberg reserve, and with illustrative parameters it is within a tenth of simulation. More dangerous than a reserve is a total freeze; spreading card sales over several gateways cuts the reserve needed from about RM 3,114,683 to RM 1,258,468 with four.

Fan, Y. (2026). Cross-Border Payment Routing, Chargeback Defense Games and Treasury Ruin Bounds: Multi-Acquirer Success Optimization, Dispute Evidence Scoring and Cramér-Lundberg Cash Reserves [跨境支付智能路由、拒付抗辩博弈与资金池破产边界] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090225 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).