Skip to content

v0.2.0: lambda formulas, tracing, versions and review

Choose a tag to compare

@zalmane zalmane released this 07 Nov 13:39
· 70 commits to main since this release
187ea53

tracemodel builds financial models in Python where every number has a fixed address, a source you can open, and rules that check it.

pip install pytracemodel

Highlights

  • One kind of formula. Every formula and check is a lambda of x. tracemodel checks it against an allow-list and compiles it with RestrictedPython. It saves the lambda as source text, so a model file runs no other code.
  • Tracing. model.precedents(...) and model.dependents(...) trace a cell, as Excel's Trace Precedents and Trace Dependents do. report.explain() lists each cell a check read.
  • Versions, branches and review. tm.Repo.open(path, author) keeps a model in an append-only, hash-chained log. An agent drafts on a branch. A person reads repo.review(branch), accepts or rejects each change, and repo.approve(branch) lands only what was accepted. repo.diff(...) shows the calculated cells that moved.
  • Sources are plain data. set_value(..., source={...}) takes any keys (document, page, bbox, sha256, ...). The Excel Values sheet gets a column for each key.
  • Text and dates. Items can hold sourced text (dtype=str) and dates, with pandas-named .str and .dt methods.
  • Labels are objects. dim["Q1"].description and dim["Q1"].attrs. Dimensions have their own description and attrs.
  • Undo verbs. remove_item, set_formula, update_item, remove_check, clear_value and remove_coords. Each one refuses while a formula or a check still reads what it would remove.

Breaking changes from 0.1

  • Arithmetic on model["item"] raises DefinitionError. Write formula=lambda x: x["revenue"] * 0.6.
  • Checks are lambdas of the run x. Use and, or, not in place of &, |, ~.
  • dim.description(label) and dim.attrs(label) are replaced by dim[label].description and dim[label].attrs.
  • A source no longer requires document, url or section.
  • Definition files are tracemodel/2. Files from 0.1 still load.

See CHANGELOG.md for the full list.

Try it: apple.ipynb, a model of Apple's FY2024–FY2025 10-K.