def demand_shares(price, theta):
delta = theta["beta"] _ x - theta["alpha"] _ price + xi
exp_delta = np.exp(delta)
return exp_delta / (1 + exp_delta.sum())
def pricing_residual(price, mc, ownership, theta):
s = demand_shares(price, theta)
deriv = demand_derivative(price, theta)
Delta = ownership * deriv.T
return s + Delta @ (price - mc)
price_new = solve_root(
lambda p: pricing_residual(p, mc_hat, ownership_after, theta_hat),
price_before
)