Skip to content

fix(reconciliation): explain broker-assisted fees and valuation basis - #495

Closed
Pigbibi wants to merge 3 commits into
mainfrom
feat/statement-fee-split-valuation-basis-20261101
Closed

Pigbibi wants to merge 3 commits into
mainfrom
feat/statement-fee-split-valuation-basis-20261101

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

AI assistance

Grok Bot (an AI agent working for the repository owner) wrote the code, tests and documentation in this PR. It was not merged or deployed by the agent; human review is pending.

What changed

Problem: two Firstrade reconciliation differences (August 19.96 and total assets 0.06) were reported as unexplained. They come from the broker-assisted order fee (19.95) plus SEC Section 31 / FINRA TAF regulatory fees on margin-sellout sells, and from a price-basis difference between the balance API long_stock_value and summed position market values.

Behaviour after this PR:

  • Sells whose description contains BROKER/DEALER ORDER (including MARGIN SELLOUT) are split into broker-assisted fee, SEC fee and TAF. Unrounded fees are summed and rounded up to the cent with a 0.01 minimum; a residual within +/-0.01 is explained.
  • Rates live in an effective-dated schedule. TAF follows SR-FINRA-2026-021 (zero 2026-10-01 to 2026-12-31) and SR-FINRA-2026-020 (2027-2028 stay 0.000195/share, max 9.79; 2029 0.000232 / 11.61; 2030 and 2031 rows).
  • verified_through (2026-11-01) makes any later trade date unsupported, because the SEC FY2027 Section 31 rate is not published.
  • The CSV Date column is treated as the trade date (checked against EXEC TIME and S/D; the 8/28 IBIT row settles 8/31). Non-positive quantity or price is unsupported.
  • The balance-vs-positions difference is a separate valuation_basis_difference with tolerance min(max(0.10, 0.1% of market value), 25.00), an optional position-quantity cross-check, and unexplained for an empty positions list with a non-zero balance.
  • The collector keeps long_stock_value as its own fact; a conflicting value is flagged (long_stock_value_ambiguous) instead of failing the whole collection. The snapshot persists it only behind an explicit opt-in.

How verified

  • pytest tests/test_statement_reconciliation.py tests/test_account_facts_readonly.py tests/test_account_facts_publisher.py: 122 passed. ruff check passes.
  • The full suite cannot run locally: 31 collection errors and 41 failures from a missing quant_platform_kit, identical on the base commit (checked with git stash).
  • Regulatory facts were checked against the FINRA/SEC filings (Release 34-106410, 34-106409) and the SEC FY2026 Section 31 advisory. SR-FINRA-2026-020 is immediately effective but the SEC may still suspend it.
  • Commit messages of the new commits pass commitlint 21.2.4 (config-conventional). The first commit on this branch (409120b) predates the convention and still fails it; fixing that needs a history rewrite, which is not done under the no-force-push rule.
  • Not done: no Firstrade confirmations requested; statement PDFs not read; nothing deployed.

…reconciliation

Add a pure statement reconciliation module with an effective-dated fee
schedule (broker-assisted fee, SEC Section 31, FINRA TAF) and a valuation
basis difference check (tolerance max($0.10, 0.1% of market value)).
Keep balance long_stock_value as a distinct collector fact and let the
snapshot builder persist it only behind an explicit opt-in, because the QRS
console schema rejects extra Firstrade balance keys today.
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 84574718-2978-4875-b49c-e79b82f79e7d
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…checks

- Correct the FINRA TAF schedule per SR-FINRA-2026-020: 2027 and 2028
  stay at 0.000195/share (max 9.79), 2029 is 0.000232 (max 11.61), then
  2030 and 2031 rows; cite SR-FINRA-2026-020 and -021 in the header.
- Add verified_through to the fee schedule; lookups after that date are
  unsupported because the SEC FY2027 Section 31 rate is not published.
- Treat the CSV Date column as the trade date (checked against EXEC TIME
  and S/D); a settlement-dated row is unsupported instead of misrated.
- Reject non-positive quantity or price with boundary tests.
- Cap the valuation tolerance at 25.00, cross-check position quantities
  and stop an empty positions list from passing as a basis difference.
A conflict between the top-level and result long_stock_value now withholds
that auxiliary value and sets coverage long_stock_value_ambiguous, so cash,
equity and positions are still collected. The opt-in snapshot option
reports long_stock_value_ambiguous distinctly. A cash_balance conflict
still fails closed.
@Pigbibi Pigbibi changed the title Reconciliation: explain broker-assisted sell fees and valuation basis differences fix(reconciliation): explain broker-assisted fees and valuation basis Nov 1, 2026
@Pigbibi

Pigbibi commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #496 (#496): the tree is identical to this PR head 2786474, rebuilt on a clean branch from main with Conventional Commits, because the first commit here fails commitlint and force-push is not allowed. This branch is kept.

@Pigbibi Pigbibi closed this Nov 1, 2026
@Pigbibi
Pigbibi deleted the feat/statement-fee-split-valuation-basis-20261101 branch November 18, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant