costs#

Cost curve utilities and classes.

class freeride.costs.Cost(*args: Any, **kwargs: Any)[source]#

Bases: PolyBase

Polynomial cost curve.

This class represents a polynomial cost curve and extends PolyBase. It provides methods for calculating costs, finding the efficient scale, breakeven price, shutdown price, and plotting various cost-related curves.

Parameters:

array-like) (*coef (float or)

coef(array-like)#
Type:

Coefficients of the polynomial cost curve.

__init__(self, \*coef):

Initialize a Cost object with coefficients.

_repr_latex_(self):

Generate a LaTeX representation of the cost curve.

cost(self, q):

Calculate the cost at a given quantity.

variable_cost(self):

Return a Cost object representing the variable cost.

marginal_cost(self):

Return a Cost object representing the marginal cost.

average_cost(self):

Return an AverageCost object representing the average cost.

efficient_scale(self):

Find the quantity that minimizes average cost.

breakeven_price(self):

Find the price such that economic profit is zero (perfect competition).

shutdown_price(self):

Find the price such that total revenue equals total variable cost (perfect competition).

long_run_plot(self, ax=None):

Plot the long-run average cost and marginal cost curves.

cost_profit_plot(self, p, ax=None, items=['tc', 'tr', 'profit']):

Plot cost, revenue, and profit curves at a given price.

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> cost_curve.cost(10)
__init__(*coef)[source]#

Initialize a Cost object with the specified coefficients.

This method creates an instance of the Cost class with the given coefficients.

Parameters:

array-like) (*coef (float or)

Returns:

Cost

Return type:

A Cost object representing the polynomial cost curve.

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
cost(q)[source]#

Calculate the cost at a given quantity.

Parameters:

(float) (q)

Returns:

float

Return type:

The cost at the specified quantity.

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> cost_curve.cost(10)
variable_cost()[source]#

Return a Cost object representing the variable cost.

Returns:

Cost

Return type:

A Cost object representing the variable cost.

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> variable_cost_curve = cost_curve.variable_cost()
marginal_cost()[source]#

Return a Cost object representing the marginal cost.

Returns:

Cost

Return type:

A Cost object representing the marginal cost.

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> marginal_cost_curve = cost_curve.marginal_cost()
average_cost()[source]#

Return an AverageCost object representing the average cost.

Returns:

AverageCost

Return type:

An AverageCost object representing the average cost.

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> average_cost_curve = cost_curve.average_cost()
efficient_scale()[source]#

Find the quantity that minimizes average cost.

Returns:

float or str

Return type:

The quantity that minimizes average cost or ‘in prog’ if it’s not finite.

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> efficient_quantity = cost_curve.efficient_scale()
breakeven_price()[source]#

Find the price such that economic profit is zero (perfect competition).

Returns:

float

Return type:

The price at which economic profit is zero.

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> breakeven_price = cost_curve.breakeven_price()
shutdown_price()[source]#

Assume perfect competition and find the price at which total revenue equals total variable cost.

This method calculates the price at which a firm should shut down in the short run to minimize losses, assuming perfect competition. It finds the price at which total revenue (TR) equals total variable cost (TVC).

Returns:

float

Return type:

The price at which total revenue equals total variable cost.

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> shutdown = cost_curve.shutdown_price()
long_run_plot(ax=None)[source]#

Plot the long-run average cost (LRAC) and marginal cost (MC) curves.

This method plots the long-run average cost (LRAC) curve and the marginal cost (MC) curve on the same graph. It also marks the efficient scale and the breakeven price.

Parameters:
  • (matplotlib.pyplot.axis (ax) – not provided, the current axis is used.

  • optional) (The axis on which to plot. If) – not provided, the current axis is used.

Return type:

None

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> cost_curve.long_run_plot()
cost_profit_plot(p, ax=None, items=['tc', 'tr', 'profit'])[source]#

Plot various cost and profit components at a given price.

This method plots the average total cost (ATC) and marginal cost (MC) curves, and it marks the given price and quantity on the graph. It can also shade areas to represent total cost (TC), total revenue (TR), and profit (π).

Parameters:
  • (float) (p)

  • (matplotlib.pyplot.axis (ax) – not provided, the current axis is used.

  • optional) (A list of items to include in the) – not provided, the current axis is used.

  • str (items (list of) – plot. Options are ‘tc’, ‘tr’, and ‘profit’.

  • optional) – plot. Options are ‘tc’, ‘tr’, and ‘profit’.

Return type:

None

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> cost_curve.cost_profit_plot(0.4, items=['tc', 'tr', 'profit'])
class freeride.costs.AverageCost(coef)[source]#

Bases: object

Class representing the average cost curve.

The average cost (AC) curve is derived from a given cost function’s coefficients. It calculates the cost per unit of output (average cost) for different levels of output (quantity).

Parameters:

(array-like) (coef)

poly_coef(array-like)#

polynomial excluding the constant term.

Type:

Coefficients of the underlying cost function

coef(array-like)#

polynomial, including the constant term.

Type:

Coefficients of the underlying cost function

Example

>>> cost_curve = Cost(0.5, 0.1, -0.02)
>>> ac_curve = AverageCost(cost_curve.coef)
__init__(coef)[source]#

Initialize the AverageCost object.

Parameters:

(array-like) (coef)

cost(q)[source]#

Calculate the average cost at a given quantity.

This method is equivalent to calling the object as a function with the quantity as the argument.

Parameters:

(float) (q)

Returns:

float

Return type:

The average cost at the given quantity.

Example

>>> ac_curve = AverageCost([0.5, 0.1, -0.02])
>>> avg_cost_at_10_units = ac_curve.cost(10)
plot(ax=None, max_q=10, label=None)[source]#

Plot the average cost curve.

This method generates a plot of the average cost (AC) curve over a range of output levels (quantity).

Parameters:
  • (matplotlib.pyplot.axis (ax) – not provided, the current axis is used.

  • optional) (Label for the curve on the plot.) – not provided, the current axis is used.

  • (float (max_q)

  • optional)

  • (str (label)

  • optional)

Return type:

None

Example

>>> ac_curve = AverageCost([0.5, 0.1, -0.02])
>>> ac_curve.plot(max_q=20, label='AC Curve')