What does FX Spreads, DCC Traps and Residency Days conclude, in numbers, about “Planning a Year as a Knapsack”?
Answer: Chapter 6 writes a year as a knapsack: the day limits cost 16.5, a day more in Taipei has a shadow price of 0.508, and four entries a year call for a 5-day buffer.
Scope of the numbers: Its exchange rates, fees and itineraries are illustrative models; all calculations are generated by its programs; the book is not tax, immigration, legal or investment advice. Marked boxes separate published evidence, runnable Python calculations (16 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. printed values that match the answer: 0.508, 16.5
| place free plan capped plan | |
| Taipei | 238 182 |
| Ho Chi Minh | 83 90 |
| Shenzhen | 36 50 |
| Tokyo | 8 14 |
| home | 0 29 |
| value | 934.0 free, 917.5 capped, cost of caps 16.5 |
| shadow price of one more day in Taipei | 0.508 |
| shadow price of one more day in Ho Chi Minh | 0.100 |
| shadow price of one more day in Shenzhen | 0.000 |
| shadow price of one more day in Tokyo | 0.000 |
Show the full program
# Chapter 6. p11: Planning a year as a knapsack. A founder divides 365
# days among home and four other places. A day in place j is worth
# a_j - b_j d (falling as d days are spent there), so d days are worth
# a_j d - b_j d (d - 1) / 2. Caps: no more than 182 days in a place
# where 183 would make the founder tax-resident, and a short-stay limit
# of 90 days a year where only visa-free entry is planned. Exact
# dynamic programming over whole days; no sampling. The shadow price is
# what one more allowed day would add.
HOME = ("home", 1.8, 0.0, 365)
PLACES = (("Taipei", 3.4, 0.006, 182), ("Ho Chi Minh", 2.8, 0.01, 90),
("Shenzhen", 2.4, 0.012, 90), ("Tokyo", 2.2, 0.03, 90))
def value(a, b, d):
return a * d - b * d * (d - 1) / 2
def solve(caps):
best = {0: (0.0, ())}
for (name, a, b, _), cap in zip(PLACES, caps):
nxt = {}
for used, (v, alloc) in best.items():
for d in range(0, min(cap, 365 - used) + 1):
key = used + d
cand = v + value(a, b, d)
if key not in nxt or cand > nxt[key][0]:
nxt[key] = (cand, alloc + (d,))
best = nxt
out = max(((v + HOME[1] * (365 - u), alloc + (365 - u,))
for u, (v, alloc) in best.items()), key=lambda t: t[0])
return out
if __name__ == "__main__":
free = solve([365] * 4)
capped = solve([p[3] for p in PLACES])
names = [p[0] for p in PLACES] + ["home"]
print(" place free plan capped plan")
for i, n in enumerate(names):
print(" {:12s} {:9d} {:11d}".format(n, free[1][i],
capped[1][i]))
print(" value: {:.1f} free, {:.1f} capped, cost of caps {:.1f}"
.format(free[0], capped[0], free[0] - capped[0]))
caps = [p[3] for p in PLACES]
for i in range(4):
up = list(caps)
up[i] += 1
print(" shadow price of one more day in {}: {:.3f}".format(
names[i], solve(up)[0] - capped[0]))Single source and citation
Fan, Y. (2026). Multicurrency FX Spread Microstructure, Dynamic Currency Conversion Traps and Tax-Residency Day-Counting Thresholds (Version 1.0.0), Chapter 6: Planning a Year as a Knapsack. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 5DL-B-108 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026108,
author = {Fan, Yafu},
title = {Multicurrency FX Spread Microstructure, Dynamic Currency Conversion Traps and Tax-Residency Day-Counting Thresholds},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}Other chapter answers in this book
- Chapter 1 · Why the Airport Booth's Spread Is So Wide
- Chapter 2 · The Weekend Markup on Multicurrency Cards
- Chapter 3 · How Much to Take Out of the ATM: The Economic Order Quantity
- Chapter 4 · Dynamic Currency Conversion at the Till
- Chapter 5 · Counting Days: 183, Rolling Windows and a Weighted Formula
- Chapter 7 · The Rites of Zhou on Contracts and the Money Office, Tang Flying Cash and the Forward Discount
- Chapter 8 · Practice: A Year's Friction Budget and a Day Ledger