Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

Tax-Engine

A deterministic real-estate tax engine that refuses to recommend when a load-bearing input is nobody's.

Simulating a property portfolio forward is the easy half of this problem, and it is the half most tools stop at.

The hard part is not the simulation. An advisor sits down with a client and says what to do with the largest asset that client owns, and then defends the number out loud with their license behind it. The hard part is being able to defend the number — and the data it runs on doesn't exist anywhere yet. Purchase price is in a closing file. Basis and depreciation are on a tax return, often a different one each year. The land allocation is frequently in no system at all and has to be asked of the owner, because the owner is the only one who knows.

This engine treats where a number came from as a property of the number.

Cannot recommend. 1 input to the exit-tax calculation is not attested,
and the range between defensible readings is $17,836.51.

  What land/improvement split was used for 1247 Ocean Blvd?
  MOVES THE ANSWER BY: $17,836.51

  $224,000  from 2024-form-1040-schedule-e
    $32,581.82/yr of depreciation over 27.5 years implies $896,000
    of depreciable basis, leaving $224,000 as land (20% of basis)

  $336,000  from 2022-form-1040-schedule-e
    $28,509.09/yr of depreciation over 27.5 years implies $784,000
    of depreciable basis, leaving $336,000 as land (30% of basis)

Two tax years were filed with different land allocations. Neither document states the allocation directly — it has to be backed out. The engine does not average them, and does not return a number with an asterisk. It refuses, names the one question that would unblock it, and prices it. The advisor attests, and the recommendation unlocks with their name permanently in the provenance chain.


Run it

make demo        # the full walkthrough, in the terminal
make verify      # tests + determinism check + generated validation report
make web         # rebuild the single-file viewer, then open packages/web/index.html

No API key, no database, no network, no build step. Python 3.10+.

Open the visualization → — one self-contained HTML file, five views, charts drawn from the engine's own exported ledger.


What's actually in here

The engine is a household simulator, not a property calculator

This is the architectural bet. Every spreadsheet an advisor uses today models one property at a time, and a per-property model structurally cannot see the three effects that most often change the answer:

1. Passive losses are a shared pool. IRC §469 suspends rental losses. Selling one property in a fully taxable disposition releases that property's entire suspended stack at once — and once released those losses are no longer passive, so they shelter wage income and gain on other properties. In the demo household that is worth $78,915 on a single sale. The best year to sell property B is often the year you sold property A.

2. Brackets are shared. Capital gain stacks on top of ordinary income, so the rate on a sale depends on everything else the household did that year. Selling two properties in one tax year versus splitting them across two costs $7,528 more, on identical properties at identical prices.

3. The NIIT threshold is a cliff the household crosses, not the property. $250,000 of MAGI for a joint filer, and never indexed since 2013.

The math is exact

Money is an integer number of cents and refuses to be constructed from a float. Rates are Decimal. Money.apply_rate() is the only rounding point in the engine, so every rounding decision is greppable. Splitting is largest-remainder, so a land/improvement split never loses a cent — which matters when you then depreciate it for 27.5 years.

Straight-line depreciation uses cumulative differencing rather than rounding each year: the schedule sums to exactly the depreciable basis for every input, with no drift and no fudge in the final year.

The engine reproduces IRS Pub 946 Table A-6 exactly (all twelve mid-month first-year percentages) and Table A-1 to published precision for 5-, 7- and 15-year property — with the declining-balance-to-straight-line switch year computed rather than hardcoded. See docs/VALIDATION.md, which is generated by running the engine.

Tax rules are versioned data, not code

Rules live in YAML under packages/engine/taxengine/rules/, keyed by year and jurisdiction, each carrying its own citation and a per-field verified mapping naming the primary source. Every computed result records the rule version that produced it, so "why is this number different from last quarter" has an answer.

Projecting forward indexes only what statute actually indexes. The NIIT thresholds (frozen 2013), the §469(i) allowance (frozen 1986) and the §121 exclusion (frozen 1997) are held fixed, because they are. Inflating them is a real modelling bug that makes a household's tax picture look stable forever when in fact those thresholds fall in real terms every year.

Provenance is a type, and it propagates by weakest link

Provenance = Assumed | Extracted | Attested | Derived

The entire refusal mechanism is one rule:

@property
def standing(self) -> Standing:
    """A derived number is exactly as defensible as its weakest input."""
    return min(fact.standing for fact in self.inputs)

Nothing else in the engine needs to know about defensibility — it propagates from the leaves for free. Fact.require() is the gate: call it anywhere a number is about to become advice, and it either returns the value or raises Unattested carrying the blocking leaves, so a refusal turns into a ranked question list instead of an error message.

I broke it five times

docs/EDGE_CASES.md opens with five defects this engine shipped with, how each was caught, and the regression test for each — including a $0.01 stub balance on a $13,164.73 note that Hypothesis found and five hand-picked examples did not, and a §1031 mortgage-boot calculation that overstated recognised gain by $19,644 on every trade-down because it ignored cash the deal structure implied.

One of them is a classification error worth calling out: 15-year land improvements are §1250 property, not §1245. Reg. §1.48-1(c) excludes "land and improvements thereto" from personal property. That matters because §1250 recaptures only additional depreciation — the excess over straight line — and land improvements run on 150% declining balance and are bonus-eligible. Sell a cost-segregated property five years after claiming 100% bonus and 63% of that bucket comes back as ordinary income, not as 25% gain. On the demo property it moves $31,333 from the 25% bucket to ordinary rates.

Part 2 of that document is the register of ~35 more cases that are handled, each with a named test — including the four instruments that most reliably break a naive implementation: interest-only conversions, ARM cap structures, HELOCs, and a property carrying four paid-off liens.

The document pipeline, and measuring whether it works

packages/pipeline/ turns tax returns into attested facts. Two passes, and the split was forced by a real API constraint that turned out to point at the better design: Anthropic's citations feature returns a 400 alongside output_config.format, so you cannot get grounded page-anchored quotes and a schema-validated object from one call.

Pass A takes the document with citations: {enabled: true} — one content block per page, so a citation's block index is the page number — and does nothing but find and quote. Pass B runs messages.parse() over only those quotes and never sees the document. It cannot invent a value because it has nothing to invent from. Grounding stops being something the prompt asks for and becomes a property of the pipeline's shape.

The corpus is generated, which is what makes the eval honest: ground-truth labels are exact by construction, and the mess can be deliberate — a missing 2023 return, the same property named three ways across years, a depreciation figure that disagrees between 2022 and 2024 because the preparer changed the land allocation and wrote that down nowhere, and one document with OCR-style scanner confusions.

That last one is the demo's blocked recommendation, arriving through the pipeline rather than hand-authored.

Reconciliation resolves the three aliases to one property, reports 2023 as missing, and surfaces the disagreement as a Conflict. There is no averaging code path, and a test asserts there isn't one — two filed returns implying 30% and 20% land do not average to 25%.

docs/EVALS.md reports per-field precision and recall (weighted, because date_placed_in_service breaks the whole schedule and insurance moves cash flow slightly), a confidence calibration table with expected calibration error, cost and latency, and an operating point chosen from the precision/review-burden curve rather than picked.

make eval runs it offline from committed cassettes — no key, no network.

The visualization

Five views over the engine's exported ledger: the portfolio, the gate (the refusal, the priced questions, and the attestation that unlocks it), the exit-tax waterfall, the strategy comparison, and a watchtower of dated triggers the engine can already see coming.

The page never does tax arithmetic. It renders a bundle the engine exported, so the number on screen and the number in the ledger cannot drift apart. The gain waterfall is coloured by a sequential ramp ordered by what each slice costs rather than by category, because the four slices have a real ordering: §1245 ordinary → §1250(a) ordinary → unrecaptured §1250 at 25% → capital gain at 20%.


Layout

packages/engine/taxengine/
  money.py            integer cents; the only rounding point in the engine
  provenance.py       Assumed | Extracted | Attested | Derived, weakest-link
  depreciation.py     MACRS, mid-month/half-year/mid-quarter, §1250(b)(1)
  loans.py            fixed · interest-only · ARM · HELOC · balloon · neg-am · liens
  property.py         acquisition → basis → schedules, incl. §1014 and carryover
  household.py        §469 · §1411 · bracket stacking — the coupling layer
  character.py        how a dollar of gain is characterised
  dispositions/       sale · exchange_1031 · death
  recommend.py        the gate: refuse, and price the questions
  simulate.py         event-sourced ledger, hashable and replayable
  rules/              versioned tax data with citations
  fixtures.py         the demo household
tests/                105 tests, property-based where invariants exist
docs/                 EDGE_CASES · VALIDATION · ROADMAP · ADRs
packages/pipeline/taxpipeline/
  corpus/             generated tax documents, ground truth for free
  extract.py          two-pass: cite-and-quote, then structure the quotes
  reconcile.py        entity resolution + conflicts, never averaging
  cassettes/          recorded API responses; the eval runs with no key
  evals/run.py        per-field P/R, calibration, operating points
packages/web/         the single-file viewer + its build step
scripts/              demo · validate · export_bundle · build_web · report_evals

Where it stops

Stated plainly, because a README that only lists wins is marketing.

  • Sale proceeds are held as cash and do not appreciate, which flatters holding and exchanging in the net-worth chart. The present-value ranking is the fair comparison; modelling reinvestment is the right fix and is not done.
  • C corporations are not modelled (§291(a)(1) changes recapture entirely).
  • §199A is in the rule data but not applied.
  • State coverage is California and Texas.
  • The extraction eval numbers in docs/EVALS.md come from recorded cassettes. Run make eval-live with an ANTHROPIC_API_KEY to re-record them against the API.

The full list is at the end of docs/EDGE_CASES.md.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages