Price optimization with Python (Part 2: Elasticities)

Anna Kozina
2 min readSep 11, 2020

--

This is a follow-up to the article on price optimization, which focuses on the price elasticity of demand.

Let me recap what we are doing at this workflow step. As we have already predicted what would be the demand for deliveries at current prices, we can assess how it will change if we vary the prices. Let’s assume, that our demand looks like that:

This equation works, because it approximates functional dependency D vs P, and doesn’t break the basic logic, i.e. when P = P0, D = D0. Apparently e has to be a negative number.

Now let’s use the historic data and approximate elasticity coefficients. I wouldn’t recommend fitting the Price vs Demand curve straight away. Consider predictive modeling first. And that is why — if your regression gets two dimensions (Price and Demand), it can’t take other features into account. Meanwhile, Demand does not depend on Price exclusively, but on seasonality and some other factors as well. Let me illustrate.

The idea is to fix all parameters and vary only the price to get changes in demand. Than utilize scipy.optimize.curve_fit to get e.

scipy.optimize.curve_fit(lambda t,e: demand_0*(t/price_0)**e,  x,  y)

Great job!

Next time we’ll make use of elasticity coefficients to implement a Profit function and optimize it.

--

--