Utility is a parent class for a variety of utility functions. Its various functions (
mrs) are marked with
@abstractmethod, and so must be overridden by any subclass. It cannot be instantiated directly.
This class should not be invoked from user code except as a base class for custom utility functions. Actual utility classes include
Leontief. Subclasses are required to implement the
Click a method name for more detailed documentation.
calculate( quantities )
Calculates the agent's utility on the basis of the quantities entered. Subclasses are required to implement this method and should call the parent function
super().calculate()at the beginning. The
agent.stocksdict can be passed directly to this function.
Utility.calculate()only returns the values, and is thus useful for counterfactual calculations. To actually realize utility from consumption, use
consume( quantities )
demand( income, prices )
Calculates the total demand for the various goods given some income. Subclasses are required to implement this method.
mrs( good1, q1, good2, … )
Calculates the marginal rate of substitution between two goods. Subclasses are required to implement this method.
mu( quantities )
Calculates the marginal utilities of the goods in question on the basis of the entered quantities. Many utility functions, including the CES function, are such that the quantities of all goods are necessary to calculate the marginal utility of any good. Subclasses are required to implement this method.
utility — num
The agent's current level of utility, updated whenever
Initial value: 0