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.
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
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
subs = [
['coefficient', (1,2)],
['exponent', (1,2)]
]
utility.marginal_utility(indx=0, subs=subs).simplify()
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$$
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
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)