What does Knapsacks, Inspection Games and the Customs Reversal Point conclude, in numbers, about “Tail Risk in a Year of Cash Flow and the Landed-Cost Calculator”?
Answer: Chapter 6 simulates a year of cash flow by Monte Carlo with a fixed seed, finds a conditional value at risk of 146183 yuan for carrying at 20 units a month, and presents the landed-cost calculator.
Scope of the numbers: Its parameters are illustrative and laws differ from place to place; all calculations are generated by its programs; the book is not individual legal or tax advice. Marked boxes separate published evidence, runnable Python calculations (19 programs), classical sources and the author's hypotheses.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 146183, 20
| Q/mo channel | mean | sd | P(loss) | VaR95 | CVaR95 | CVaR99 |
| 20 carry | 43284 | 55390 | 0.1004 | 119360 | 146183 | 168762 |
| 20 general | -35756 | 2552 | 1.0000 | 39954 | 41038 | 42672 |
| 38 carry | 4173 | 109675 | 0.5187 | 150684 | 158806 | 174003 |
| 38 general | 9770 | 4915 | 0.0232 | -1674 | 353 | 3362 |
| 60 carry | -106332 | 27979 | 0.9988 | 146530 | 158982 | 171448 |
| 60 general | 65573 | 7706 | 0.0000 | -52905 | -49547 | -44630 |
| 100 carry | -84021 | 99360 | 0.9828 | 113700 | 482484 | 544592 |
| 100 general | 166632 | 12803 | 0.0000 -145382 -139931 -132287 |
Show the full program
# Chapter 6. p61: one year of cash flow by Monte Carlo, seed 20261112.
# A shop sells 12 Q units a year at 950 yuan. Carrying: trips of 50
# units, 4500 yuan travel, goods 600 a unit, profiled inspection rate
# of p41, sensitivity 0.9; at a finding the goods (30000) are lost, a
# fine of T = 6000 and a credit loss of 60000 are paid, each of the
# other n - 1 trips of the year is traced with probability 0.5 at 12000
# each, a severe tier of 400000 applies once traced tax reaches 100000,
# and the rest of the year is bought through general trade. General
# trade: 739 yuan a unit plus 7200 a month, each month's unit cost
# scaled by 1 + 0.05 Z for freight and exchange noise. 20000 years per
# volume. VaR and CVaR are losses measured from zero profit. All
# parameters are illustrative.
import math
import random
rng = random.Random(20261112)
YEARS, PRICE, UNIT, PER, TRAVEL = 20000, 950, 600, 50, 4500
def p_insp(n):
k = n / 4
a = 0.02 * math.exp(-5.0 + k * math.log(5.0) - math.lgamma(k + 1))
b = 0.98 * math.exp(-0.4 + k * math.log(0.4) - math.lgamma(k + 1))
return 0.02 + 0.58 * a / (a + b)
def general_year(q, months=12):
out = []
for _ in range(months):
out.append(q * 739 * (1 + 0.05 * rng.gauss(0, 1)) + 7200)
return math.fsum(out)
def carry_year(q):
n = math.ceil(12 * q / PER)
h = p_insp(n) * 0.9
units, cost = 12 * q, []
for j in range(1, n + 1):
cost.append(TRAVEL)
if rng.random() < h:
x = 0
for _ in range(n - 1):
if rng.random() < 0.5:
x += 1
cost += [UNIT * PER, 6000, 60000, x * 12000]
if (x + 1) * 6000 >= 100000:
cost.append(400000)
done = PER * (j - 1)
left = max(units - done, 0)
cost.append(UNIT * min(done, units))
months = left / q
cost.append(months * (q * 739 + 7200))
return PRICE * units - math.fsum(cost)
cost.append(UNIT * min(PER * n, units))
return PRICE * units - math.fsum(cost)
def stats(xs):
xs = sorted(xs)
n = len(xs)
mean = math.fsum(xs) / n
sd = math.sqrt(math.fsum((x - mean) ** 2 for x in xs) / (n - 1))
ploss = len([x for x in xs if x < 0]) / n
k5, k1 = n // 20, n // 100
var95 = -xs[k5]
cvar95 = -math.fsum(xs[:k5]) / k5
cvar99 = -math.fsum(xs[:k1]) / k1
return mean, sd, ploss, var95, cvar95, cvar99
print("Q/mo channel mean sd P(loss) VaR95 CVaR95 CVaR99")
for q in (20, 38, 60, 100):
for lab, f in (("carry", carry_year),
("general", lambda q: PRICE * 12 * q - general_year(q))):
m, sd, pl, v95, c95, c99 = stats([f(q) for _ in range(YEARS)])
print("{:4d} {:8s}{:8.0f}{:8.0f}{:9.4f}{:8.0f}{:8.0f}{:8.0f}"
.format(q, lab, m, sd, pl, v95, c95, c99))Single source and citation
Fan, Y. (2026). Two-Dimensional Volume-Weight Knapsacks for Cross-Border Buyers, Port Risk-Profiling Inspection Games and the Scale Reversal Point to Formal Customs Clearance (Version 1.0.0), Chapter 6: Tail Risk in a Year of Cash Flow and the Landed-Cost Calculator. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 5DL-B-174 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026174,
author = {Fan, Yafu},
title = {Two-Dimensional Volume-Weight Knapsacks for Cross-Border Buyers, Port Risk-Profiling Inspection Games and the Scale Reversal Point to Formal Customs Clearance},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}Other chapter answers in this book
- Chapter 1 · One Suitcase as a Two-Dimensional Knapsack: Weight, Volume and the Price of Greedy Density
- Chapter 2 · The Larger of Actual and Volumetric Weight: Break-Even Density, Mixed Loads and Vacuum Packing
- Chapter 3 · The Border as an Inspection Game: Mixed Equilibria of Declaring and Risk Profiling
- Chapter 4 · The Nonlinearity of Hidden Penalties: Back Taxes, Confiscation, Tracing and Credit
- Chapter 5 · The Scale Reversal Point: Landed Cost of Carrying, Cross-Border E-Commerce and General Trade
- Chapter 7 · Classical Sources: the Salt Policy of the Guanzi "Hai Wang" and Smith's Smuggler
- Chapter 8 · Practice and Falsification: Checklists for Buyers and Owners, the Calculator and a Pre-Registered Protocol