An open source ETRM for commodity trading, built for traders, risk managers and AI agents.
LeanETRM books trades, builds curves and calculates P&L and risk on a standard, unmodified PostgreSQL database. Exact quantity and cash arithmetic, explicit numerical policies and retained source lineage make calculations auditable; corrections never overwrite history. It is aimed at shops that need trade capture and risk with explicit inputs and a retained calculation history.
Status: a foundation, not a finished product. Try it as a disposable local preview on synthetic data. Nothing here is production-qualified.
For a worked PPA example, follow the PPA tester guide for synthetic booking, graphical break-even pricing and settlement previews.
- Trade capture: futures, listed American options on futures, financial gas and power swaps, factor swaps and PPAs, with exact party references and retained history. New trade opens each product's booking workflow; supported amendments retain immutable revisions
- Physical gas: fixed-quantity delivery with independent fixed or daily indexed consideration and fixed fee sides in the deal ticket, explicit fuel links, multi-month booking and versioned delivery setup. Future compositions support amendments before operational/facility relationships exist. Contractual pre-delivery net MTM and interactive/queued scenario risk retain independent physical and payment forecasts; started-delivery indexed cash lifecycle remains work. Manual nominations, acknowledgments, schedule adoption and imbalance reconciliation reuse retained daily quantities. Final daily fixed-price cash determinations retain original and correcting contributions; gas invoices, payments and operational PV remain work. See delivery operations and billing
- Physical crude: fixed standard-volume booking, contractual pre-delivery PV and interactive/queued risk, plus bounded receipts, title transfer, inventory-lot allocation, dispatch, invoices, payments and cash-record corrections. See the contract and operations
- Physical LNG: future cargo booking with separate loading/discharge terms, explicit discharge-energy quantity or retained mass-to-energy conversion, Incoterms and fixed consideration. Retained trading views and interactive/queued risk support contractual PV before loading starts; cargo actuals and settlement remain work. See the bounded cargo contract
- Physical operations: gas and crude workflows have a dedicated Operations workspace. Gas, crude and LNG share a read-only delivery grid with native intervals, quantities and source status; LNG operational actions remain TBD. See the workspace and delivery view
- Curves: one Curves & prices workspace groups Contract prices, Curve builder and Hourly / sub-hourly prices under the shared context and edit guards. Futures, gas and power forwards, basis and interest rates are built from explicitly selected prices, with a diagram showing which inputs built each contract's price. The custom-curve workbench supports visual/formula recipes and explicit weighted contract baskets, reusable published curve outputs and guided combinations of computed curves with matching periods and units; all keep their upstream graph links; the swap editor selects compatible published outputs for monthly or exact daily projections. Effective-version timelines resolve under the selected business date and knowledge cutoff. Explicit delivery splices and whole-interval lookups retain selected source evidence; see curve evaluation
- P&L and risk: futures execution P&L and swap/PPA PV using pinned actuals and projections. Connected quote and computed-output scenarios calculate delta and gamma from shared scenario PV evaluations; generated-close jobs retain mixed futures-and-swaps reports. Interactive and queued portfolio risk also cover supported PPA, gas, crude and LNG bindings; generated gas, crude and LNG closes refuse. A delta ladder shows each shocked contract's totals by book and measure, see the delta ladder. Native one-session delta-normal VaR/ES uses retained complete held-factor history, with signed contributions and correlation diagnostics; see parametric risk
- Agent curve drafts: authorized agents can read curve ingredients, prepare a pinned preview and propose a bounded custom-curve draft. Saving uses the ordinary authorized operation after explicit human approval; publishing remains a person’s action
- Live corrections: push updates through the shared header context, with visible refresh/stale status; policy and limits
- Facility quantities: shared reported quantities, explicit trade/Side allocation plans, versioned operating maxima and historical views for retained gas days; see the implemented scope
- Risk jobs: temporary nested stresses, risk around the stressed market, and queued mixed-book runs pinned to the header's financial context, with retained results and cancellation; see the risk engine
- VaR / expected shortfall: guided portfolio/book/trade setup, visible editable defaults, automatic end-of-day history alignment, official-close priority with explicit approved price-type alternatives, aligned-factor coverage grids and correlation/covariance graphics; see how to run VaR and the parametric model. Full-PV Monte Carlo adds explicit seeded correlated Gaussian shocks, full PV and convergence/sampling diagnostics. Optional PCA / hybrid qualification adds loadings, residual diagnostics and every-path candidate comparisons with user-selected fallback and cost. Hybrid Monte Carlo valuation separately predicts the distribution with sampled full-PV validation and visible approximate/observed/fallback graphics. Fallback starts off and requires explicit opt-in. Full-PV historical simulation adds empirical loss distributions, signed book/trade allocations, sample PV drilldown and a matching normal comparison
- Scheduled swaps: persistent booking, amendments and inspection of up to 120 monthly periods per side, with explicit quantities, observations, payment rules and discounting; see quantity contracts
- Swap settlement: opt-in immutable determinations, corrections, gross/net allocations, manual cash recording, reversals and a closing-context P&L bridge; see the bounded lifecycle
- Blotter: filters, pivots, saved views, charts, exports, docked trade details, pop-out, maximize/restore for every pane, shared portfolio/book selectors, personal sidebar pins and backend-prepared close-out drafts. Shared lazy, paged Side inspection exposes pricing, source/calculation detail and native lifecycle state for swaps, PPAs, gas, crude and LNG; unsupported values retain explicit reasons. See the workbench and Side inspection limits
- Dashboard: account-owned layouts, curve levels/history and positions from saved risk run definitions; see implemented widgets and limits
- Interval series: audited per-interval values on any market clock (price shapes, capacity-factor forecasts, metered energy) with CSV import, corrections, a change log and reads at a chosen knowledge time. Shaped interval curves consume price shapes; PPA quantity/valuation consumes forecast and meter series. PPA settlement has a separate read-only monthly gross preview, without cash posting; see the implementation record
- Physical power: published daily/monthly product curves, curve-owned hourly LMP resolution, explicit DA availability replay, booked fixed physical Sides and shaped ATC quantities/prices. Close comparisons reconcile fixing, marks and captured corrections; see support and limits.
- Interval curves: hourly and sub-hourly prices marked directly or shaped exactly from monthly peak and off-peak marks, delivered hours resolved to collected actuals under an explicit due rule, with lineage for every price, see the implementation record
- Volatility surfaces: fitted expiry smiles, rich/cheap heat maps and a linked 3D view for listed futures options. These are analytical views; option valuation and risk retain each series' own settlement calibration. See the surface contract
- History: browse supported market and trade history at explicit business and knowledge times; trading-history cutover boundaries refuse earlier trade contexts. Close-based views use the latest close in force for the selected session and business day, including in historical views; saved calculation results retain their original pins. See regional closes
- Access control: roles enforced by PostgreSQL row-level security, with people and AI agents as separate principals; agent actions require an explicit delegation
- Private pilot mode: invited user accounts and scheduled PJM and ERCOT day-ahead and real-time price collection; see private pilot operations
- Page assistant: bounded delegated reads, human-approved business proposals, page guidance, selection questions and presentation walkthroughs, plus recorded conversations, provider configuration and usage accounting. Walkthroughs use supported native controls and stop at unsaved edits; see workspace operations and walkthrough limits
- Operating settings and profiles: versioned assistant/access policies under separate administration permissions, account-owned display preferences, explicit process/connection budgets, and server-supplied risk/request limits. Gas, crude and LNG execute retained instrument schedules under their exact commodity contracts; see implemented consumers and remaining work
Full futures settlement PV and variation margin, option products beyond the supported listed American futures options, EVT and operating backtests, broader physical settlement, power products outside the documented fixed hourly profile, inventory costing, post-delivery crude valuation, PPA accepted-cash accounting/payments, broader agent credential lifecycle and production qualification remain work. General swap/PPA portfolio execution directly from compact retained programs is still an integration task; the booking-storage checkpoint alone does not complete it. See the delivery plan. If you want to help with any of these, start with CONTRIBUTING.md.
You need the .NET SDK pinned in global.json, Node with npm (version in
.node-version), Python 3.12+ with assertions enabled and PostgreSQL 18.
CI runs on Ubuntu 24.04.
git clone https://github.com/zerodrift/leanetrm.git
cd leanetrm
python3 tools/run_preview.py --pg-bin /path/to/postgresql/bin --dotnet /path/to/dotnetOpen the http://127.0.0.1:PORT address it prints. You start as a read-only demo
user. Use Curves & prices and the header's close-session/date controls to
inspect the synthetic market. To book trades or correct prices, switch demo users
under Profile → Preview access; New trade opens the product booking workflows.
The preview builds the app, creates its own throwaway PostgreSQL cluster seeded with synthetic data, and deletes it when you stop it with Ctrl+C. It never connects to an existing database.
Design
- Architecture and domain contracts
- Delivery plan and acceptance criteria
- Decisions, proposals and unresolved choices
- Events and lifecycle
- Historical context and temporal data
- Market model proposal and key linkages
Implementation
- Current implementation and verification
- Blotter workbench
- Description-driven deal ticket (physical gas)
- Scheduled financial swaps
- Financial swap settlement and P&L
- PPA and heat-rate portfolio consumers
- Physical gas booking and quantities
- Physical crude booking and delivery-to-cash operations
- Physical LNG cargo booking and valuation
- Curve-definition preview and remaining publication work
- Market dashboard and saved risk runs
- Booked executable schedule storage and remaining cutover
- Business scenarios, settlement gaps and shared scenarios
- Market-data contracts
- Reference data and futures
- CME/ICE futures example
- Listed American options on futures
- Volatility surfaces
- Time, delivery calendars and TOU
- Schedules and contract sequences
- Physical power curves, hourly settlement and current limits
- Booked peak and shaped ATC close comparisons
- Power example and its limits
- Risk calculation benchmark
- Connected curve calculation, booked projections and scenarios
- Large dependency-graph benchmark
- Nested market scenarios and durable risk jobs
- Native one-session parametric VaR/ES
- Full-PV historical simulation VaR/ES
- Full-PV Monte Carlo VaR/ES
- PCA diagnostics and hybrid qualification
- Identity, agent login kinds and authorization
- Reference schema and disposable verification
Operations
- Physical operations workspace and common delivery view
- Manual gas delivery operations
- Final daily gas cash determinations and corrections
- Shared facility quantities, physical Side allocations and operating limits
- Regional close sessions and historical-view policy
- Workspace assistant operations and human approval
- Assistant digests and presentation walkthroughs
- Connected-curve cutover prerequisites
- Jobs, workers and infrastructure
- Private pilot operations
- Operating policies, user preferences and process configuration
- Local verification and CI
The wider documents specify the intended system; they are not claims of implemented functionality or production qualification. The intended hosted domain is leanetrm.com. No hosted service or deployment is implied by this repository's current status.
Read the project instructions, architecture and delivery plan before changing the application.
python3 tools/check_standalone.pychecks dependency boundaries.- Add
--checkto the preview command to run the HTTP integration checks, then clean up. npm test --prefix webruns presentation checks, including isolated browser-control checks whenCHROME_BINnames an installed browser. The complete verification command passes its explicit--browserselection to these checks.- Local verification and CI has the complete check command and hosted-runner boundaries.
Small fixes are welcome. Sign off contribution commits with git commit -s
under the Developer Certificate of Origin.
See the contribution guide; designated core contributors also
sign the Core Contributor Agreement.
Copyright (c) 2026 Trusty Genius LLC.
Licensed under the Apache License, Version 2.0.
The local frontend uses pinned public presentation dependencies for its trading
grid and analytical charts. The build serves their assets locally and includes
required license notices under web/dist/vendor. Business calculations remain
in the managed backend; see implemented capabilities.