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 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 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]

© 2021 TechTarget, Inc. Powered by

Badges | Report an Issue | Privacy Policy | Terms of Service

**Most Popular Content on DSC**

To not miss this type of content in the future, subscribe to our newsletter.

- Book: Applied Stochastic Processes
- Long-range Correlations in Time Series: Modeling, Testing, Case Study
- How to Automatically Determine the Number of Clusters in your Data
- New Machine Learning Cheat Sheet | Old one
- Confidence Intervals Without Pain - With Resampling
- Advanced Machine Learning with Basic Excel
- New Perspectives on Statistical Distributions and Deep Learning
- Fascinating New Results in the Theory of Randomness
- Fast Combinatorial Feature Selection

**Other popular resources**

- Comprehensive Repository of Data Science and ML Resources
- Statistical Concepts Explained in Simple English
- Machine Learning Concepts Explained in One Picture
- 100 Data Science Interview Questions and Answers
- Cheat Sheets | Curated Articles | Search | Jobs | Courses
- Post a Blog | Forum Questions | Books | Salaries | News

**Archives:** 2008-2014 |
2015-2016 |
2017-2019 |
Book 1 |
Book 2 |
More

**Most popular articles**

- Free Book and Resources for DSC Members
- New Perspectives on Statistical Distributions and Deep Learning
- Time series, Growth Modeling and Data Science Wizardy
- Statistical Concepts Explained in Simple English
- Machine Learning Concepts Explained in One Picture
- Comprehensive Repository of Data Science and ML Resources
- Advanced Machine Learning with Basic Excel
- Difference between ML, Data Science, AI, Deep Learning, and Statistics
- Selected Business Analytics, Data Science and ML articles
- How to Automatically Determine the Number of Clusters in your Data
- Fascinating New Results in the Theory of Randomness
- Hire a Data Scientist | Search DSC | Find a Job
- Post a Blog | Forum Questions

## You need to be a member of Data Science Central to add comments!

Join Data Science Central