pyblp.Simulation.replace_endogenous

Simulation.replace_endogenous(costs=None, prices=None, iteration=None, constant_costs=True, compute_gradients=True, compute_hessians=True, error_behavior='raise')

Replace simulated prices and market shares with equilibrium values that are consistent with true parameters.

This method is the standard way of solving the simulation. Prices and market shares are computed in each market by iterating over the \(\zeta\)-markup contraction in (52):

(1)\[p \leftarrow c + \zeta(p).\]

Note

To not replace prices, pass the desired prices to prices and use an Iteration configuration with method='return'. This just uses the iteration “routine” that simply returns the the starting values, which are prices.

Using this same fake iteration routine and not setting prices will result in a simulation under perfect (instead of Bertrand) competition because the default starting values for the iteration routine are marginal costs.

Note

This method supports parallel() processing. If multiprocessing is used, market-by-market computation of prices and shares will be distributed among the processes.

Parameters
  • costs (array-like, optional) – Marginal costs, \(c\). By default, \(c = X_3\gamma + \omega\) if costs_type was 'linear' in Simulation (the default), and the exponential of this if it was 'log'. Marginal costs must be specified if \(X_3\) was not formulated in Simulation. If marginal costs depend on prices through market shares, they will be updated to reflect different prices during each iteration of the routine.

  • prices (array-like, optional) – Prices at which the fixed point iteration routine will start. By default, costs, are used as starting values.

  • iteration (Iteration, optional) – Iteration configuration for how to solve the fixed point problem. By default, Iteration('simple', {'atol': 1e-12}) is used.

  • constant_costs (bool, optional) – Whether to assume that marginal costs, \(c\), remain constant as equilibrium prices and shares change. By default this is True, which means that firms treat marginal costs as constant (equal to costs) when setting prices. If set to False, marginal costs will be allowed to adjust if shares was included in the formulation for \(X_3\). When simulating fake data, it likely makes more sense to set this to False since otherwise arbitrary shares simulated by Simulation will be used in marginal costs.

  • compute_gradients (bool, optional) – Whether to compute profit gradients to verify first order conditions. This is by default True. Setting it to False will slightly speed up computation, but first order conditions will not be reported.

  • compute_hessians (bool, optional) – Whether to compute profit Hessians to verify second order conditions. This is by default True. Setting it to False will slightly speed up computation, but second order conditions will not be reported.

  • error_behavior (str, optional) –

    How to handle errors when computing prices and shares. For example, the fixed point routine may not converge if the effects of nonlinear parameters on price overwhelm the linear parameter on price, which should be sufficiently negative. The following behaviors are supported:

    • 'raise' (default) - Raise an exception.

    • 'warn' - Use the last computed prices and shares. If the fixed point routine fails to converge, these are the last prices and shares computed by the routine. If there are other issues, these are the starting prices and their associated shares.

Returns

SimulationResults of the solved simulation.

Return type

SimulationResults

Examples