Skip to main content

Financial Model Engineering — Python code compiles to live Excel formulas

Project description

Modeleon

PyPI Python License

Write Python. Ship real Excel formulas.

Variable — a value.
MultiVariable — a concept, modeled as a set of Variables and sub-concepts.
Excel — one cell-traceable snapshot of a MultiVariable.

import modeleon as mo

forecast = mo.MultiVariable("Forecast")
forecast.pnl = mo.MultiVariable("P&L")
with forecast.pnl as pnl:
    pnl.revenue  = mo.Variable(1_000_000, unit="$")
    pnl.cogs_pct = mo.Variable(0.6, display_name="COGS %")
    pnl.cogs     = pnl.revenue * pnl.cogs_pct
    pnl.profit   = pnl.revenue - pnl.cogs

forecast.to_excel("forecast.xlsx")

The resulting forecast.xlsx:

A B
1 Revenue 1000000
2 COGS % 0.6
3 Cogs =B1*B2
4 Profit =B1-B3

B3 is =B1*B2 — a real Excel formula, not the baked value 600000.


Install

pip install modeleon

Python 3.12+.


Variable

A value or formula. Arithmetic tracks dependencies automatically.

revenue = mo.Variable(1_000_000)
cogs    = revenue * mo.Variable(0.6)
cogs.value         # 600_000.0
cogs.formula       # 'revenue * 0.6'
cogs.dependencies  # {'revenue'}

Scalar, list, or unit-bearing — all the same Variable.


MultiVariable

A concept. Variables are its attributes; sub-MultiVariables are its inner concepts.

forecast = mo.MultiVariable("Forecast")
forecast.assumptions = mo.MultiVariable("Assumptions", tax_rate=mo.Variable(0.25))
forecast.pnl = mo.MultiVariable("P&L")
forecast.pnl.revenue = mo.Variable(1_000_000)
forecast.pnl.taxes   = forecast.pnl.revenue * forecast.assumptions.tax_rate
#                                              ↑ cross-MV reference, fully resolved

Reusable concepts subclass MultiVariableClass:

class Cohort(mo.MultiVariableClass):
    def compute(self, start, churn, price):
        self.users   = mo.recurrence(start, "{prev} * (1 - {c})", c=churn)
        self.revenue = self.users * price

Excel as a snapshot

.to_excel() walks the MultiVariable tree and writes a workbook where every Variable is a cell, every formula is =A1*B2, every cross-sheet reference is =Sheet!Cell.

Standard library functions emit live formulas, not values:

mo.IRR(cf)       # =IRR(B2:F2, 0.1)
mo.NPV(0.1, cf)  # =NPV(0.1, B2:F2)
mo.IF(rev > 0, rev * 0.25, 0)   # =IF(B1>0, B1*0.25, 0)
mo.EOMONTH(start, 1)            # =EOMONTH(B1, 1)

License

Apache 2.0. See LICENSE and NOTICE.

modeleon.ai · PyPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modeleon-0.1.2.tar.gz (128.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modeleon-0.1.2-py3-none-any.whl (113.5 kB view details)

Uploaded Python 3

File details

Details for the file modeleon-0.1.2.tar.gz.

File metadata

  • Download URL: modeleon-0.1.2.tar.gz
  • Upload date:
  • Size: 128.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modeleon-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c2c1abfba8285f44a11d14d80e7cc062feef6825d885222889a799a2d78a42b1
MD5 2c0a4c034298d63bef980b8fc79699ac
BLAKE2b-256 57f5aba4bebde691939aa2a1563e52fcd25a8fd27874823a7aa8ae411d534c3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for modeleon-0.1.2.tar.gz:

Publisher: publish.yml on modeleonai/modeleon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modeleon-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: modeleon-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 113.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modeleon-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9ffadb61e357ce81ad0ab6140397e7ba8ac6552a05aabd6791285bb12fbfe0a8
MD5 a18e79ec12ddcfb9c2099f60555cc6e1
BLAKE2b-256 7f5327ff6ac3497d1503b55045ef7256bd92cca4aff9e1ee88cb20329e9ca87c

See more details on using hashes here.

Provenance

The following attestation bundles were made for modeleon-0.1.2-py3-none-any.whl:

Publisher: publish.yml on modeleonai/modeleon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page