Skip to main content

Class to define, block analyse and solve dynamic and algebraic models numerically

Project description

SSB Model Solver

PyPI Status Python Version License

Documentation Tests Coverage Quality Gate Status

pre-commit Black Ruff Poetry

ModelSolver is a class that defines, block analyses and solves dynamic and algebraic models numerically. See documentation for detailed information about theory and implementation of the class.

Opprettet av: Magnus Kvåle Helliesen mkh@ssb.no

Features

ModelSolver is a Python class. It defines, analyses and solves dynamic algebraic model with lots of equations.

The package is imported using

import model_solver as ms

Usage is

model = ms.ModelSolver(equations, endogenous)

where equations are equations and endogenous are endogenous variables, both stored as strings in lists.

Built with

ModelSolver uses the following packages

Example of use

Let equations = ['x+y = 1', 'x-y = 2'] and endogenous = ['x', 'y'], then the model class is instatiatied by

model = ms.ModelSolver(equations, endogenous)

When instatiatied, the class reads in the equations, analyzes them for any lags, before it block analyzes it to find the smallest model blocks that must be solved simultaneously. Note that ModelSolver is not case sensitive, such that 'x' and 'X' are the same, both in equations, lists and dataframe (below).

When the class is finished instatiating, the user can call the following methods:

  • solution = model.solve(dataframe) where dataframe is a Pandas dataframe containing initial values for the endogenous variables and values for the exogenous variables. solution is a dataframe with same dimensions as dataframe containing the solutions for the endogenous variables.
  • model.switch_endo_vars(old_endo_var, new_endo_var) switches the endogenous variables old_endo_var for new_endo_var.
  • model.describe() writes out information about the model: the number of blocks, the size of the blocks etc.
  • model.find_endo_var('var') returns the block number in which var is solved for.
  • model.show_block(block_number) returns information about the block: endogenous variables, predetermined variables and equations.
  • model.show_blocks() returns information about all blocks.
  • model.trace_to_exog_vars(block_nunber) traces back to the exogenous variables that may affect the block.
  • model.trace_to_exog_vals(block_nunber, period_index) traces back to the exogenous variable values for the period.
  • model.draw_blockwise_graph(variable, maximum_ancestor_generations, maximum_decendants_generations) where variable is a variable of interest, and maximum_ancestor_generations and maximum_decendants_generationsare non-negative integers that governs the number of generations before and after the variable to be graphed. The output is a HTML-file with a relational graph.
  • model.sensitivity(block_nunber, period_index[, method='std', exog_subset=None]) analyses the sensitivity of the endogenous variable in the block with respect to the exogenous variabels that determine the solution for the period.

Installation

You can install SSB Model Solver via pip from PyPI:

pip install ssb-model-solver

Usage

Please see the Reference Guide for details.

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license, SSB Model Solver is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from Statistics Norway's SSB PyPI Template.

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

ssb_model_solver-1.4.4.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

ssb_model_solver-1.4.4-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file ssb_model_solver-1.4.4.tar.gz.

File metadata

  • Download URL: ssb_model_solver-1.4.4.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ssb_model_solver-1.4.4.tar.gz
Algorithm Hash digest
SHA256 7cb933e3c55604507e0bfbac2e6691449681f855863f75c563dadb3b18b95838
MD5 010265d69c096cbfe469400498eee7e2
BLAKE2b-256 f4c5f414d2fdae8c4e326e9a56d524af4d97b83c36e5d7a39a15eb1ac81a67bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for ssb_model_solver-1.4.4.tar.gz:

Publisher: release.yml on statisticsnorway/ssb-model-solver

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

File details

Details for the file ssb_model_solver-1.4.4-py3-none-any.whl.

File metadata

File hashes

Hashes for ssb_model_solver-1.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a6978f9f84a263a225818dae3cd1d142fbf4fbd445902ef1ee3685b87f5b3f58
MD5 17d4adfbb4644da59d6963e650c9064e
BLAKE2b-256 5ed0c5a05446ceef6dd4c833461ce93f5c6f8cf1b82587b6337104659cd421ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for ssb_model_solver-1.4.4-py3-none-any.whl:

Publisher: release.yml on statisticsnorway/ssb-model-solver

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