Escape from spreadsheet models!
18 February 2020: modelx v0.3.0 and spyder-modelx v0.2.0 are released. See modelx v0.3.0 (18 February 2020) release notes for details.
8 February 2020: spyder-modelx v0.1.1 is released. See Release Notes for details.
13 January 2020: modelx v0.2.0 is released. See modelx v0.2.0 (13 January 2020) release notes for details.
2 January 2020: spyder-modelx v0.1.0 is released. See spyder-modelx v0.1.0 (2 January 2020) release notes for details.
1 December 2019: modelx v0.1.0 is released. See modelx v0.1.0 (1 December 2019) release notes for details.
19 October 2019: modelx v0.0.25 is released. See modelx v0.0.25 (19 October 2019) release notes for details.
4 October 2019: modelx v0.0.24 is released. See modelx v0.0.24 (4 October 2019) release notes for details.
8 August 2019: modelx v0.0.23 is released. See modelx v0.0.23 (9 August 2019) release notes for details.
4 June 2019: modelx v0.0.22 is released. See modelx v0.0.22 (4 June 2019) release notes for details.
24 March 2019: spyder-modelx v0.0.9 is released. See Release Notes for details.
24 March 2019: modelx v0.0.21 is released. See Release Notes for details.
2 February 2019: modelx v0.0.20 is released. See Release Notes for details.
13 January 2019: spyder-modelx v0.0.8 is released. See Release Notes for details.
13 January 2019: modelx v0.0.19 is released. See Release Notes for details.
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!
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
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.
Copyright 2017-2020, 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
With the release of modelx version 0.1.0 in December 2019,
the author of modelx will try to consider maintaining
backward compatibility to a limited extent
in developing future releases of modelx.
Especially, he will try to make it possible to read
models written to files by one version’s
read_model of the next version of modelx.
However, models saved by
Model.save method may not be opened by
Overall, modelx is still in its early alpha-release stage,
and its specifications may change without consideration
on backward compatibility.
modelx was originally conceived and written by Fumito Hamamura and it was first released in October 2017.
- What’s New
- Spyder plugin
- User Guide