Repair Yahoo adj-close/event-date misalignment (JLPSX, JLPYX)

JLPSX showed a bogus +29.3%/-22.9% 3-day wiggle in Dec 2020: Yahoo dated
the 6.824 year-end cap-gain distribution on the 12-11 record date but the
market went ex-div on 12-14 (close 30.10 -> 23.22), so the raw Adj Close
column pre-applied the adjustment 3 days before the price actually fell.

New 'history' correction op ({date: {col: value}}) patches individual OHLC
cells at bundle assembly (full build, incremental, and correction-changed
recompute paths); check_corrections validates dates/columns; 4 new tests.

scripts/scan_adj_misalign.py finds the artifact set-wide: 481 hits on 278
symbols, overwhelmingly December year-end distributions of value funds
(JLPSX's class of fund). scripts/fix_adj_misalign.py repairs it
arithmetic-only (rescale adj in [event, ex-div) by (1-f); cumulative
returns unchanged, cross-checked implied dist vs the price drop). Applied
to the only curated-fund hit (JLPSX) and its sister class JLPYX (implied
dist 6.824 both = official amount; ex-div 2020-12-14). The remaining ~276
symbols are reported in reports/adj_misalign/scan.md for a bulk run.
This commit is contained in:
gmp
2026-08-31 23:08:42 -04:00
parent 3c5bee96ce
commit 43ddd3ec7f
8 changed files with 826 additions and 10 deletions
+31
View File
@@ -189,6 +189,37 @@ def main() -> int:
D.CORRECTIONS_DIR = real_corr
finally:
shutil.rmtree(tmp, ignore_errors=True)
# --- history cell corrections (misaligned Yahoo adj-close spike) ---
tmp = pathlib.Path(tempfile.mkdtemp(prefix="fd-"))
try:
root = tmp / "data"; cache = tmp / "cache"; corrdir = tmp / "corr"
root.mkdir(parents=True); cache.mkdir(); corrdir.mkdir()
(root / "ghh-history.csv").write_text(
"Date,Open,High,Low,Close,Adj Close,Volume\n"
"2020-12-10,30.10,30.10,30.10,30.10,11.247889,1000\n"
"2020-12-11,30.10,30.10,30.10,30.10,14.545517,1000\n"
"2020-12-14,23.22,23.22,23.22,23.22,11.220826,1000\n")
(corrdir / "GHH.json").write_text(json.dumps(
{"history": {"2020-12-11": {"Adj Close": 11.247889}}}))
real_corr = D.CORRECTIONS_DIR
D.CORRECTIONS_DIR = corrdir
try:
b = D.load_bundle(root=root, cache=cache)
t10, t11, t14 = (pd.Timestamp(x) for x in
("2020-12-10", "2020-12-11", "2020-12-14"))
check("history: adj cell patched",
b.adj["ghh"][t11] == 11.247889)
check("history: other adj cells untouched",
b.adj["ghh"][t10] == 11.247889 and b.adj["ghh"][t14] == 11.220826)
check("history: raw close untouched",
b.close["ghh"][t11] == 30.10 and b.close["ghh"][t14] == 23.22)
b2 = D.load_bundle(root=root, cache=cache)
check("history: idempotent on reload", b2.adj["ghh"][t11] == 11.247889)
finally:
D.CORRECTIONS_DIR = real_corr
finally:
shutil.rmtree(tmp, ignore_errors=True)
print(f"\n{PASS} passed, {FAIL} failed")
return 1 if FAIL else 0