fundlab: extract strategy sections from EDGAR docs; --strategy CLI mode
- extract_strategy(): finds the 'Principal Investment Strategies' / 'main investment strategies' section, scores candidates (strategy prose +3, Q&A heading +2, TOC -5, risk subheading -5, stop-heading -2), truncates at the next section heading; falls back to the prose after the objective sentence when no heading exists - fundinfo --strategy [--refresh]: populates the strategy field of funds.json from each fund's EDGAR document - funds.json now carries objective + strategy for 20 funds (the 9 curated index funds have no strategy: their objective is the strategy)
This commit is contained in:
@@ -158,6 +158,31 @@ def test_edgar_live() -> None:
|
||||
and res["form"], repr(res))
|
||||
|
||||
|
||||
def test_strategy() -> None:
|
||||
print("strategy extraction", flush=True)
|
||||
doc = ("Fund Cover\nThe Fund seeks total return.\nFees and Expenses "
|
||||
"of the Fund: see table.\nInvestment Strategies The Fund invests "
|
||||
"in a diversified portfolio of US and international equity "
|
||||
"securities and may use derivatives to manage risk. It also "
|
||||
"invests in fixed income of varying credit quality.\nPrincipal "
|
||||
"Risks Market Risk. Values may go down.\nMore text.")
|
||||
s = edgar.extract_strategy(doc)
|
||||
check("strategy section extracted",
|
||||
s is not None and "diversified portfolio" in s
|
||||
and "Market Risk" not in s, repr(s))
|
||||
check("no strategy section -> None",
|
||||
edgar.extract_strategy("Fund Cover\nThe Fund seeks X.\nFees.") is None)
|
||||
# supplement amendment: the REAL strategy follows a replaced-clause heading
|
||||
doc2 = ("Supplement\nInvestment Strategies of the section of the "
|
||||
"Prospectus entitled X is deleted and replaced with the "
|
||||
"following: Under normal circumstances, the Fund invests in "
|
||||
"investment grade bonds with maturities under one year and "
|
||||
"cash equivalents.\nFund Management\nPortfolio Manager: Bob.")
|
||||
s2 = edgar.extract_strategy(doc2)
|
||||
check("amendment clause strategy extracted",
|
||||
s2 is not None and "investment grade bonds" in s2, repr(s2))
|
||||
|
||||
|
||||
def test_curated() -> None:
|
||||
print("curated", flush=True)
|
||||
import fundlab.fundinfo as fi
|
||||
@@ -176,6 +201,7 @@ def main() -> int:
|
||||
test_pool()
|
||||
test_text_and_objective()
|
||||
test_classify()
|
||||
test_strategy()
|
||||
test_curated()
|
||||
test_edgar_live()
|
||||
print(f"\n{PASS} passed, {FAIL} failed")
|
||||
|
||||
Reference in New Issue
Block a user