Giter Site home page Giter Site logo

econmodels's Introduction

Overview

Econmodels is an open source library for exploring the core concepts of economics. The framework integrates a market structure with market actors and their decision functions. The module is built on top of Sympy, allowing symbolic logic for generalized examples as well as numeric examples.

Example Using Functional Forms

Functional forms of common mathematical functions used in economics are avaialble, including Cobb-Douglas and CES functions. There is no particular limit on what other functional forms can be added to the list.

Import Utility which gives you access to several fucntional forms of utility functions, including Cobb-Douglas, substitutes, complements, CES, and quasi-linear.

from econmodels.functional_forms.utility import Utility

Instantiate the Utility class with the functional form of a Cobb-Douglas function.

utility = Utility(func_form='cobb-douglas')

Print the utility function.

utility.function

$$C - U + {\beta}{0} {\beta}{1} {x}{0}^{{\alpha}{0}} {x}{1}^{{\alpha}{1}}$$

Print the symbols available.

utility.symboldict
{'coefficient': beta,
 'constant': C,
 'dependent': U,
 'exponent': alpha,
 'i': i,
 'input': x}

Print marginal utility of $x_0$, $\frac{\partial U}{\partial x_0}$.

utility.marginal_utility(indx=0).simplify()

$${\alpha}{0} {\beta}{0} {\beta}{1} {x}{0}^{{\alpha}{0} - 1} {x}{1}^{{\alpha}_{1}}$$

Print marginal utility of $x_0$ with substitutions.

subs = [
    ['coefficient', (1,2)],
    ['exponent', (1,2)]
]

utility.marginal_utility(indx=0, subs=subs).simplify()

$$2 {x}_{1}^{2}$$

Get total utility by substituting values for the goods.

utility.get_utility(input_values=[1,4], constant=None)

$$4^{{\alpha}{1}} {\beta}{0} {\beta}_{1} + 1$$

Example using Agents

Agents are usually a combination of a objective function and a constriant function. Agents are also usually given additional methods to maximize the objective given constraints.

Import the agent Consumer, which is a combination of a utility function and a budget constraint.

from econmodels.agents.consumer import Consumer

Instantiate the Consumer class.

consumer = Consumer()

Print the consumers property utility. The default utility function is a Cobb-Douglas utility with two goods.

consumer.utility.function

$$C - U + {\beta}{0} {\beta}{1} {x}{0}^{{\alpha}{0}} {x}{1}^{{\alpha}{1}}$$

Print the consumers property budget_constraint.

consumer.constraint.function

$$B - M + {p_{}}{0} {x}{0} + {p_{}}{1} {x}{1}$$

Maximize utility given the budget constraint. The result populates the property opt_values_dict.

consumer.maximize_utility()

Print optimal values dictionary.

consumer.opt_values_dict
{x[0]: (-B + M)*alpha[0]/((alpha[0] + alpha[1])*p_[0]),
 lambda: ((-B + M)*alpha[0]/((alpha[0] + alpha[1])*p_[0]))**alpha[0]*((-B + M)*alpha[1]/((alpha[0] + alpha[1])*p_[1]))**alpha[1]*(alpha[0] + alpha[1])*beta[0]*beta[1]/(B - M),
 x[1]: (-B + M)*alpha[1]/((alpha[0] + alpha[1])*p_[1])}

Show the demand for input $x_0$ as a homogenous equation.

consumer.get_demand(indx=0)

$$\frac{\left(- B + M\right) {\alpha}{0}}{\left({\alpha}{0} + {\alpha}{1}\right) {p{}}{0}} - {x}{0}$$

Calculate price elasticity of quantity demanded for good 0.

consumer.get_elasticity(input_indx=0, var='p_', var_indx=0)

$$- \frac{\left(- B + M\right) {\alpha}{0} p{}}{\left({\alpha}{0} + {\alpha}{1}\right) {p_{}}{0}^{2} {x}{0}}$$

Calculate income elasticity of quantity demanded for good 0.

consumer.get_elasticity(input_indx=0, var='M', var_indx=0)

$$\frac{M {\alpha}{0}}{\left({\alpha}{0} + {\alpha}{1}\right) {p{}}{0} {x}{0}}$$

Calculate price elasticity of quantity demanded for good 0 at a point where the price of good 0 is equal to quantity demanded.

consumer.get_elasticity(input_indx=0, var='p_', var_indx=0, point=(1,1))

$$- \frac{\left(- B + M\right) {\alpha}{0}}{\left({\alpha}{0} + {\alpha}{1}\right) {p{}}_{0}^{2}}$$

Calculate cross-price elasticity of quantity demanded for good 0 with respect to the price of good 1.

consumer.get_elasticity(input_indx=0, var='p_', var_indx=1)

$$0$$

econmodels's People

Contributors

gfbarbieri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.