Estimate Price Elasticity

easy
Unit 7 · Economics0/3 to milestone

Price elasticity is the percentage change in quantity sold for a 1% change in price. With a constant-elasticity demand curve q=Apeq = A p^{e}, taking logs gives a straight line: log⁡q=log⁡A+elog⁡p\log q = \log A + e \log p.

Implement:

  • fit_elasticity(prices, quantities): the least-squares slope and intercept of log q on log p, returned as (e, log_A)
  • predict_quantity(p, e, log_A)
  • revenue_effect(e): "increase" if raising prices would increase revenue (inelastic, e > -1), "decrease" if e < -1, and "flat" if e == -1
  • optimal_price(e, unit_cost): the profit-maximising price for constant elasticity, p∗=c e1+ep^* = c\,\frac{e}{1 + e}. Raise ValueError if e >= -1 (no finite optimum).
#economics#regression#pricing2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Estimate Price Elasticity · TechGradify