Skip to main content

Build and run complex models composed of formulas and data

Project description

Use Python like a spreadsheet!

https://github.com/fumitoh/modelx/actions/workflows/python-package.yml/badge.svg 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 numerical computing tool that enables you to use Python like a spreadsheet and build object-oriented models by defining formulas. modelx is best suited for building models in such fields as actuarial science, quantitative finance and risk management.

modelx sites

Home page

https://modelx.io

Blog

https://modelx.io/allposts

Documentation site

https://docs.modelx.io

Development

https://github.com/fumitoh/modelx

Discussion Forum

https://github.com/fumitoh/modelx/discussions

modelx on PyPI

https://pypi.org/project/modelx/

Feature highlights

modelx enables you to interactively develop, run and scrutinize complex models in smart ways:

  • Only basic Python knowledge required

  • Formulas defined by Python functions

  • Object-oriented, supports composition and inheritance

  • Parameterization

  • Dependency tracing

  • Reading from Excel and CSV files

  • GUI as Spyder plugin (spyder-modelx)

  • Saving to text files, enabling use of version control systems

  • Document integration enabling use of document generators

  • Pandas interface

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-2022, 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

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 write_model, by read_model of the next version of modelx. However, models saved by Model.save method may not be opened by open_model method. Overall, modelx is still in its early alpha-release stage, and its specifications may change without consideration on backward compatibility.

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+

  • asttokens

  • 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.19.1.tar.gz (159.6 kB view details)

Uploaded Source

Built Distribution

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

modelx-0.19.1-py3-none-any.whl (176.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modelx-0.19.1.tar.gz
  • Upload date:
  • Size: 159.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for modelx-0.19.1.tar.gz
Algorithm Hash digest
SHA256 cb8871eb8e3f8782a899efa0f18312121d771d7c637ed68ab40718a7b6cd7020
MD5 1c1dfe92de79f404b561eb866d86520f
BLAKE2b-256 c6645fd51437c7e42db9e95cc93c24bce78f5b3cf8b114799c416df511d51996

See more details on using hashes here.

File details

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

File metadata

  • Download URL: modelx-0.19.1-py3-none-any.whl
  • Upload date:
  • Size: 176.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for modelx-0.19.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee4776e271282e33712186d2f51bd789405398fb555ec564570e9500bcbea008
MD5 029adb807e4e116ac5bb553d4587b59b
BLAKE2b-256 2e64269a3710c6b58d116cb0595e57679ceeab7626cb445793da1ef8708826cc

See more details on using hashes here.

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