Skip to main content

Build and run complex models composed of formulas and data

Project description

Escape from spreadsheet models!

https://travis-ci.org/fumitoh/modelx.svg?branch=master https://img.shields.io/pypi/pyversions/modelx https://img.shields.io/pypi/v/modelx https://img.shields.io/pypi/l/modelx

What is modelx?

modelx is a Python package to build object-oriented models containing formulas and values to carry out complex calculations. You can think of it as a hierarchical and multidimensional extension of spreadsheet, but there’s so much more to it!

Feature highlights

modelx comes with features that enable users to interactively develop, run and scrutinize complex models in smart ways:

  • Only little Python knowledge required

  • Model composed of a tree of Spaces containing Cells

  • Cells containing formulas and data

  • Dynamic name binding for evaluating formulas within a Space

  • Space inheritance

  • Dynamic parametrized spaces created interactively

  • GUI as Spyder plugin (spyder-modelx)

  • Cells graph to track cells interdependency (Under development)

  • Saving to / loading from files

  • Conversion to Pandas objects

  • Reading from Excel files

Who is modelx for?

modelx is designed to be domain agnostic.

The modelx was created by actuary, and its primary use is to develop actuarial projection models. lifelib (https://lifelib.io) is a library of actuarial models that are built on top of modelx.

However, modelx is intentionally designed to eliminate domain specific features so that potential audience for modelx can be wider than actuaries, whoever needs to develop complex models of any sorts that are too much to deal with by spreadsheets.

How modelx works

modelx exposes its API functions and classes such as Model, Space and Cells to its users, and the users build their models from those classes, by defining calculation formulas in the form of Python functions and associating those calculations with Cells objects.

Below is a very simple working example in which following operations are demonstrated:

  • a new model is created,

  • and in the model, a new space is created,

  • and in the space, a new cells is created , which is associated with the Fibonacci series.

from modelx import *

model, space = new_model(), new_space()

@defcells
def fibo(n):
    if n == 0 or n == 1:
        return n
    else:
        return fibo(n - 1) + fibo(n - 2)

To get a Fibonacci number for, say 10, you can do:

>>> fibo(10)
55
>>> fibo.series
n
0      0
1      1
2      1
3      2
4      3
5      5
6      8
7     13
8     21
9     34
10    55
Name: fibo, dtype: int64

Refer to lifelib (https://lifelib.io) fo more complex examples.

Python and modelx

Aside from modelx being a Python package and written entirely in Python, modelx utilizes Python in that it lets users define formulas by writing Python functions and converting it to modelx formulas. However, there is a critical difference between how Python functions are interpreted by Python and how modelx formulas are interpreted by modelx.

Python employs lexical scoping, i.e. the namespace in which function code is executed is determined by textual context. The global namespace of a function is the module that the function is defined in. In contrast, the evaluation of modelx formulas is based on dynamic scoping. Each Cells belongs to a space, and the space has associated namespace (a mapping of names to objects). The formula associated with the cells is evaluated in that namespace. So, what module a formula is defined (in the form of a Python function) does not affect the result of formula evaluation. It is what space the cells belongs to that affects the result.

License

Copyright 2017-2019, Fumito Hamamura

modelx is free software; you can redistribute it and/or modify it under the terms of GNU Lesser General Public License v3 (LGPLv3).

Contributions, productive comments, requests and feedback from the community are always welcome. Information on modelx development is found at Github https://github.com/fumitoh/modelx

Development State

modelx is in its early alpha-release stage, and its specifications are subject to changes without consideration on backward compatibility. The source files of you models may need to be modified manually, if there are updates that break backward compatibility in newer versions of modelx.

Likewise, model files saved with one version may not load with a newer version. When updating modelx to a newer version, make sure you rebuild model files saved using older versions of modelx from their source code.

History

modelx was originally conceived and written by Fumito Hamamura and it was first released in October 2017.

Requirements

  • Python 3.6+

  • NetwrkX 2.0+

  • Pandas

  • OpenPyXL

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

modelx-0.0.25.tar.gz (113.0 kB view details)

Uploaded Source

Built Distribution

modelx-0.0.25-py3-none-any.whl (150.1 kB view details)

Uploaded Python 3

File details

Details for the file modelx-0.0.25.tar.gz.

File metadata

  • Download URL: modelx-0.0.25.tar.gz
  • Upload date:
  • Size: 113.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for modelx-0.0.25.tar.gz
Algorithm Hash digest
SHA256 c597083b43f0242033f30d90013eafe73df1fc591af4b575de473e49994e0447
MD5 22924a2c931cf8e3eaa7f9275319e6ab
BLAKE2b-256 f8138160116eafad60ce1c32579aab242244f907e43ad2c17b17da704daa1d08

See more details on using hashes here.

File details

Details for the file modelx-0.0.25-py3-none-any.whl.

File metadata

  • Download URL: modelx-0.0.25-py3-none-any.whl
  • Upload date:
  • Size: 150.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for modelx-0.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 1dc954d94fb039fcb904da1f0616cc053f9a50d3fe4f7252a88a3493d25d51cb
MD5 edce913342228d2dd6aece41c79dd34a
BLAKE2b-256 a4868a1b4ca1870ab5318476e576ee0fdbaad1d8b0c78e1837cbd12d930aca59

See more details on using hashes here.

Supported by

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