Fund Lab: N-PORT holdings page for the 16-fund shortlist

- fundlab/nport.py: parse the fund's own category/percentage lines,
  as-of date, net assets and dollar-valued positions from N-PORT
  schedules of investments (handles per-fund and combined multi-fund
  family filings; conservative keyword bucketing of positions)
- fundlab/nport_cache/<sym>.json: parsed snapshots for 15 of 16 funds
  (raw SOI HTML kept locally, gitignored; source URLs + filing dates in
  nport_manifest.json, md5-verified against EDGAR)
- atesx: no current SOI found (Anchor's recent filings cover the Income
  fund) - listed with an honest note
- app.py: new 'Fund Lab' tab - pick a fund, see objective, reported
  composition (bar + table), rough keyword buckets, top positions, and
  the prospectus strategy excerpt
- tests: parser unit tests (section finding, category regex, buckets)
This commit is contained in:
gmp
2026-08-26 09:59:24 -04:00
parent 7b27920a77
commit 54d26939dc
20 changed files with 4893 additions and 2 deletions
+57
View File
@@ -183,6 +183,62 @@ def test_strategy() -> None:
s2 is not None and "investment grade bonds" in s2, repr(s2))
def test_nport() -> None:
print("nport parser", flush=True)
import fundlab.nport as np
# _CAT: dash / paren / bare-space separators, one & two decimals
check("cat dash sep", np._CAT.search("CORPORATE BONDS - 53.9%")
is not None, "")
m = np._CAT.search("Asset-Backed Securities 7.2%")
check("cat bare-space sep", bool(m) and m.group(2) == "7.2", repr(m))
m = np._CAT.search("LONG-TERM INVESTMENTS 98.70%")
check("cat two decimals", bool(m) and m.group(2) == "98.70", repr(m))
# _trim_name: strip a mixed-case table-header run-on, keep title case
check("trim caps tail", np._trim_name("Maturity Fair Value CORPORATE BONDS")
== "CORPORATE BONDS", np._trim_name("Maturity Fair Value CORPORATE BONDS"))
check("trim keeps title-case", np._trim_name("Asset-Backed Securities - Non-Agency")
== "Asset-Backed Securities - Non-Agency", "")
# classify: first-match keyword bucketing
check("classify us equity", np.classify("Apple Inc. 100 $5,000", "")
== "Equity (US)", np.classify("Apple Inc. 100 $5,000", ""))
check("classify mbs", np.classify("GNMA 5.10 03/15/28", "")
== "Agency MBS", "")
check("classify fund", np.classify("Vanguard Total Bond ETF 1,000 $20,000", "")
== "Fund holdings", "")
# find_section: multi-fund stream, pick the right fund's block
filler = ("Alpha Inc. $ 1,000 Beta Corp. $ 2,000 Gamma Ltd. $ 3,000 " * 8)
stream = ("Cover Page. Alpha Fund Schedule of Investments as of January 1, 2026 "
f"COMMON STOCKS - 40.0% Apple Inc. $ 1,000 {filler}"
"Beta Mortgage Opportunities Fund Schedule of Investments as of "
"February 2, 2026 Asset-Backed Securities 7.2% Some Bond $ 4,000 "
f"{filler}Notes to Schedule of Investments.")
sec = np.find_section(stream, ["mortgage", "opportunities"])
check("find_section locates fund", sec is not None, "")
if sec:
seg = stream[sec[0]:sec[1]]
check("find_section excludes other fund", "Apple Inc." not in seg,
seg)
check("find_section excludes notes", "Notes to" not in seg, seg)
# parse_section end-to-end on a synthetic block
rs = ["Beta Mortgage Opportunities Fund",
"Schedule of Investments as of February 2, 2026",
"Asset-Backed Securities 7.2%", "Some Bond $ 2,000", "Net assets $ 50,000"]
st_ = " ".join(rs)
starts = []
p = 0
for r in rs:
starts.append(p)
p += len(r) + 1
out = np.parse_section(st_, 0, len(st_), rs, starts)
check("parse as_of", out["as_of"] == "February 2, 2026", repr(out["as_of"]))
check("parse category", any(c["name"] == "Asset-Backed Securities" and
c["pct"] == 7.2 for c in out["categories"]),
repr(out["categories"]))
check("parse position", any(p["value"] == 2000 for p in out["positions"]),
repr(out["positions"]))
check("parse net assets", out["net_assets"] == 50000, repr(out["net_assets"]))
def test_curated() -> None:
print("curated", flush=True)
import fundlab.fundinfo as fi
@@ -202,6 +258,7 @@ def main() -> int:
test_text_and_objective()
test_classify()
test_strategy()
test_nport()
test_curated()
test_edgar_live()
print(f"\n{PASS} passed, {FAIL} failed")