Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions scripts/check_fee_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,21 +494,27 @@ def compare_sec(advisory: SecAdvisory, config: Mapping[str, Any], report: Report


def compare_taf_years(label: str, official: Mapping[int, Taf], config: Mapping[str, Any],
years: range, report: Report) -> None:
years: range, report: Report,
*, allow_missing_before_year: int | None = None) -> None:
mismatches = []
checked_years = []
for year in years:
if year not in official:
if allow_missing_before_year is not None and year < allow_missing_before_year:
continue
mismatches.append(f"{year}: missing in {label}")
continue
checked_years.append(year)
repo = repo_taf_on(config, date(year, 1, 1))
if repo != official[year]:
mismatches.append(f"{year}: {label} {official[year][0]} / {official[year][1]}, "
f"schedule {repo[0] if repo else None} / {repo[1] if repo else None}")
if mismatches:
report.findings.append(f"FINRA TAF ({label}) differs from the schedule: " + "; ".join(mismatches))
else:
span = f"{checked_years[0]}-{checked_years[-1]}" if checked_years else f"{years.start}-{years.stop - 1}"
report.notes.append(
f"FINRA TAF ({label}): covered-equity rate and cap for {years.start}-{years.stop - 1} "
f"FINRA TAF ({label}): covered-equity rate and cap for {span} "
"match the schedule.")


Expand Down Expand Up @@ -562,11 +568,14 @@ def sec(url: str) -> str:
else:
report.notes.append(f"SEC page for {filing}: no suspension mentioned.")

# FINRA: original schedule table, years up to 2026 (later years were deferred)
# FINRA: original schedule table, years up to 2026 (later years were deferred).
# FINRA's live webpage drops past calendar years once archived; tolerate absent
# prior-year columns while still checking any row that remains published.
report.source(FINRA_SCHEDULE_URL)
compare_taf_years("fee adjustment schedule SR-FINRA-2024-019",
parse_finra_schedule_table(fetch_html(FINRA_SCHEDULE_URL)),
config, range(2024, 2027), report)
config, range(2024, 2027), report,
allow_missing_before_year=date.today().year)

# FINRA: new TAF filings that have not been reviewed
report.source(FINRA_LISTING_URL)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_check_fee_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,45 @@ def test_compare_taf_years_reports_each_difference_and_missing_years():
assert "2027" in report.findings[0] and "2028: missing" in report.findings[0]


def test_compare_taf_years_allows_missing_archived_past_years():
official = {2026: TAF_2026}
report = cfs.Report()
cfs.compare_taf_years("test", official, config(), range(2024, 2027), report, allow_missing_before_year=2026)
assert report.findings == []
assert "2026-2026" in report.notes[0]

missing_current = cfs.Report()
cfs.compare_taf_years("test", {}, config(), range(2024, 2027), missing_current, allow_missing_before_year=2026)
assert len(missing_current.findings) == 1
assert "2026: missing" in missing_current.findings[0]
assert "2024: missing" not in missing_current.findings[0]


def test_full_run_tolerates_archived_past_years_removed_from_finra_schedule(monkeypatch):
# Keep 2026..2029 in the table while removing archived 2024 and 2025 columns.
schedule_html = fixture("finra_schedule.html")
for col in (
"<th>2024</th>",
"<th>2025 (no change)</th>",
"<td>$0.000166 per share (up to $8.30 max per trade)</td><td>$0.000166 per share (up to $8.30 max per trade)</td>",
"<td>$0.00279 per contract</td><td>$0.00279 per contract</td>",
"<td>$0.00011 per contract (with $0.014 minimum per round turn transaction)</td><td>$0.00011 per contract (with $0.014 minimum per round turn transaction)</td>",
"<td>$0.00105 per bond (up to $1.05 max per trade)</td><td>$0.00105 per bond (up to $1.05 max per trade)</td>",
"<td>$0.00000105 times reported value (up to $1.05 max per trade)</td><td>$0.00000105 times reported value (up to $1.05 max per trade)</td>",
):
assert col in schedule_html
schedule_html = schedule_html.replace(col, "", 1)

class FixedDate(date):
@classmethod
def today(cls) -> date:
return date(2026, 11, 28)

monkeypatch.setattr(cfs, "date", FixedDate)
report = offline_run(config(), {cfs.FINRA_SCHEDULE_URL: schedule_html})
assert report.findings == []


def test_compare_pause_checks_window_and_previous_rate():
cfg = config()
window = cfs.repo_pause(cfg)
Expand Down
Loading