Skip to main content

Financial Model Engineering — Python code compiles to live Excel formulas

Project description

Modeleon

PyPI Python License Open in Colab

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.3.tar.gz (129.0 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.3-py3-none-any.whl (113.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modeleon-0.1.3.tar.gz
  • Upload date:
  • Size: 129.0 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.3.tar.gz
Algorithm Hash digest
SHA256 26656ce001f4f363c5356c33a0e7e87f096b7ba736526a1bee8b287ef723be68
MD5 4504280ab1eaa374b6c624627a4ed9cc
BLAKE2b-256 507508e30b2de9eca009595476b7a0152661d94b088feb0f1f5d7cb34d05b0ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for modeleon-0.1.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: modeleon-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 113.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bde81f02a341913523d90b51993d8db03cacaab15b9fc696799a24d5e4303d38
MD5 7303f79635ee8ca7e139b8a91fc48ce2
BLAKE2b-256 15c07e5516df76c97b868d338535aed61ffe3c046f161e6bb755a5ab0651b314

See more details on using hashes here.

Provenance

The following attestation bundles were made for modeleon-0.1.3-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