Problem statement
Price and quantity sold are the two determinants of business revenue/profit. At higher price the revenue is expected to be high. But this is not the case all the time. We know from our everyday experience, as price of something goes up, people have less tendency to buy it.
The reverse is also true, that is, as price is down, sales goes up (think what happens in a block buster sales event in a nearby shopping mall). But sales going up doesn’t always mean that the revenue will also go up, because of the trade-off created by price drop.
Setting a right price of products/services is one of the most important decisions a business can make. Under-pricing and over-pricing both can hurt a company’s bottom line. So where is the sweet spot, the right price, that maximizes revenue and profit?
With a simple example let’s examine how to optimization price to maximize revenue/profit.
Import libraries
import numpy as np
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
from statsmodels.compat import lzip
from statsmodels.formula.api import ols
Data
Data in this analysis came from here [Susan Li has a nice blog post about price elasticity of demand (i.e. sensitivity of demand to change in price) explained using the same dataset]. This is a time series, quarterly data of beef sales (i.e. quantity sold) and its corresponding price.
This data will be used first to find price elasticity of demand and then to use this information to find at what price the profit is maximized.
# Load data
data_source = https://raw.githubusercontent.com/susanli2016/Machine-Learning-with...
beef = pd.read_csv('data_source')
# View first few rows
beef.tail(5)
# demand curve estimation
sns.lmplot( x="Price", y="Quantity", data=beef, fit_reg=True, size=4)
# fit OLS model
model = ols("Quantity ~ Price", data=beef).fit()
# print model summary
print(model.summary())
Price = [320, 330,340,350, 360, 370, 380, 390] # a range of different prices to find the optimum one
Cost = 80 # a fixed cost in this case
Revenue = []
for i in Price:
quantity_demanded=30.05-0.0465*i
Revenue.append((i-cost)*quantity_demanded) # profit function
#create data frame of price and revenue
profit = pd.DataFrame({"Price": Price, "Revenue": Revenue})
#plot revenue against price
plt.plot(profit["Price"], profit["Revenue"])
# price at which the revenue is maximum
profit[profit['Revenue'] == profit['Revenue'].max()]
[Note: This is also posted in my personal blog here]