explaingit

tripp-smith/lean-lfse

Analysis updated 2026-05-18

0LeanAudience · developerComplexity · 4/5Setup · moderate

TLDR

A Lean 4 library and CLI for building auditable financial pricing scenarios as lazy, cached, traceable computation graphs.

Mindmap

mindmap
  root((lean-lfse))
    What it does
      Lazy financial scenarios
      Memoized computation graph
      Auditable traces
    Tech stack
      Lean 4
      Lake build system
      CLI tool
    Use cases
      Option and swap pricing
      Stress test regimes
      Monte Carlo risk
    Audience
      Quant developers
      Lean programmers
    Setup
      Needs Lean toolchain
      lake build and test

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Model option, forward, and swap pricing as a reusable, cached computation graph.

USE CASE 2

Run macro stress tests across multiple market regimes on the same portfolio definition.

USE CASE 3

Trace and export a financial scenario's computation graph as a DOT diagram for review.

USE CASE 4

Generate reproducible Monte Carlo risk estimates using a fixed seed.

What is it built with?

Lean 4CLI

How does it compare?

tripp-smith/lean-lfsecajal-technologies/talosmathtensor/ai4math-putnam2025
Stars01113
LanguageLeanLeanLean
Setup difficultymoderatehardmoderate
Complexity4/55/54/5
Audiencedeveloperresearcherresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 1h+

Requires the Lean 4 toolchain and lake build system, plus familiarity with functional programming.

In plain English

Lean-lfse is the Lazy Financial Scenario Engine, a library and command line tool written in Lean 4, a functional programming language with built in support for formal verification, for describing and evaluating financial scenarios in a way that is auditable and reproducible. The core idea is that financial calculations, such as pricing options, running stress tests, modeling interest rate swaps, and allocating cash through structured tranches, are represented as a graph of lazy computations rather than a flat sequence of function calls. Lazy means a calculation is only actually performed when its result is needed, and once computed, the result is cached and reused everywhere it is referenced. This avoids doing the same expensive calculation twice when many reports share inputs, and it makes it possible to trace exactly which parts of a scenario were evaluated and why. The engine includes a domain specific language, or DSL, for writing financial scenarios directly in Lean code, covering instruments like call and put options, forwards, and swaps. Scenarios can be evaluated from the command line with output in JSON or YAML format, traced to show which nodes were forced, or exported as DOT graph files for visual inspection. A synthetic scenario suite is included to demonstrate realistic workflows: multi asset portfolios evaluated across macro stress regimes, Monte Carlo risk reports with a fixed seed for reproducibility, and asset backed security waterfall allocations. The project also notes several correctness fixes it has hardened against, such as making sure Monte Carlo returns explicit errors instead of silently returning zero for unsupported cases. The README does not state a license for this project.

Copy-paste prompts

Prompt 1
Help me build and run the lean-lfse example scenarios with lake build and lake test.
Prompt 2
Explain how the memoized lazy DAG in lean-lfse avoids recomputing shared subgraphs.
Prompt 3
Walk me through writing a new financial scenario using the lean-lfse DSL.
Prompt 4
Show me how to export a lean-lfse scenario's computation graph to a DOT file.
Prompt 5
Explain the ABS waterfall example in this repo and how tranche allocation works.

Frequently asked questions

What is lean-lfse?

A Lean 4 library and CLI for building auditable financial pricing scenarios as lazy, cached, traceable computation graphs.

What language is lean-lfse written in?

Mainly Lean. The stack also includes Lean 4, CLI.

How hard is lean-lfse to set up?

Setup difficulty is rated moderate, with roughly 1h+ to a first successful run.

Who is lean-lfse for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.