<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/pricing-optimization-how-to-find-the-price-that-maximizes-your-profit/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://insightr.wordpress.com/2017/08/27/pricing-optimization-how-to-find-the-price-that-maximizes-your-profit/"> R – insightR</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div></div>
<p><strong>By Yuri Fonseca</strong></p>
<h2>Basic idea</h2>
<p>In this post we will discuss briefly about pricing optimization. The main idea behind this problem is the following question: As manager of a company/store, how much should I charge in order to maximize my revenue or profit?</p>
<p><span></span></p>
<p>Obviously, the answer isn’t as high as possible. If you charge one hundred dollars for a candy, probably only one or two people will accept to buy it. Although the profit per product is very high, you probably won’t even your fixed costs. Charge a very small is also not the best call.</p>
<p>Before showing an example for this problem, let us build some simple formulas.</p>
<p>Imagine a monopolist selling a specific product with demand curve <img alt="Q(p)" title="Q(p)" src="https://s0.wp.com/latex.php?latex=Q%28p%29&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">, where <img alt="Q(p)" title="Q(p)" src="https://s0.wp.com/latex.php?latex=Q%28p%29&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> is the quantity sold given a specific price <img alt="p" title="p" src="https://s0.wp.com/latex.php?latex=p&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">. To simplify things, let’s suppose that <img alt="Q(p)" title="Q(p)" src="https://s0.wp.com/latex.php?latex=Q%28p%29&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> is a linear function:</p>
<p><img alt="displaystyle Q(p) = alpha p + beta" title="displaystyle Q(p) = alpha p + beta" src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+Q%28p%29+%3D+%5Calpha+p+%2B+%5Cbeta&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"></p>
<p>The total revenue will be given by:</p>
<p><img alt="displaystyle R(p) = p Q(p) = alpha p^2 + pbeta" title="displaystyle R(p) = p Q(p) = alpha p^2 + pbeta" src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+R%28p%29+%3D+p+Q%28p%29+%3D+%5Calpha+p%5E2+%2B+p%5Cbeta&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"></p>
<p>And total profit will be given by:</p>
<p><img alt="displaystyle L(p) = (p - c)Q(p) = alpha p^2 - alpha pc + beta(p - c)" title="displaystyle L(p) = (p - c)Q(p) = alpha p^2 - alpha pc + beta(p - c)" src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+L%28p%29+%3D+%28p+-+c%29Q%28p%29+%3D+%5Calpha+p%5E2+-+%5Calpha+pc+%2B+%5Cbeta%28p+-+c%29&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"></p>
<p>Where <img alt="c" title="c" src="https://s0.wp.com/latex.php?latex=c&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> is the unity cost of the product. Adding fixed costs in the profit equation does not change the price police, so we will suppose it’s zero.</p>
<p>Next, we differentiate the equations for <img alt="R(p)" title="R(p)" src="https://s0.wp.com/latex.php?latex=R%28p%29&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> and <img alt="L(p)" title="L(p)" src="https://s0.wp.com/latex.php?latex=L%28p%29&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> to find the first order conditions, which allow us to find the optimal police under the hypothesis of a linear demand curve. <img alt="alpha" title="alpha" src="https://s0.wp.com/latex.php?latex=%5Calpha&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> is expected to be negative (demand decrease when prices increase) <img alt="R" title="R" src="https://s0.wp.com/latex.php?latex=R&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> and <img alt="L" title="L" src="https://s0.wp.com/latex.php?latex=L&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> are concave functions of <img alt="p" title="p" src="https://s0.wp.com/latex.php?latex=p&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">. As consequence, the critical point will be a maximum point. Therefore, the optimal police for revenue is given by:</p>
<p><img alt="displaystyle P_{textrm{max rev}}= frac{-beta}{2alpha}" title="displaystyle P_{textrm{max rev}}= frac{-beta}{2alpha}" src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+P_%7B%5Ctextrm%7Bmax+rev%7D%7D%3D+%5Cfrac%7B-%5Cbeta%7D%7B2%5Calpha%7D&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"></p>
<p>And for profit:</p>
<p><img alt="displaystyle P_{textrm{max prof}} = frac{-beta + alpha c}{2alpha}" title="displaystyle P_{textrm{max prof}} = frac{-beta + alpha c}{2alpha}" src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+P_%7B%5Ctextrm%7Bmax+prof%7D%7D+%3D+%5Cfrac%7B-%5Cbeta+%2B+%5Calpha+c%7D%7B2%5Calpha%7D&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"></p>
<p>Note that sometimes people write the linear demand curve as <img alt="Q(p) = -alpha p + beta" title="Q(p) = -alpha p + beta" src="https://s0.wp.com/latex.php?latex=Q%28p%29+%3D+-%5Calpha+p+%2B+%5Cbeta&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">, in this case <img alt="alpha" title="alpha" src="https://s0.wp.com/latex.php?latex=%5Calpha&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> should be positive, and the signs in equation 2 and equation 3 must change. Moreover, it is interesting to note that the price that maximizes profit is always bigger than the one that maximizes total revenue because <img alt="c" title="c" src="https://s0.wp.com/latex.php?latex=c&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> is always positive.</p>
<p>If taxes are calculated just on profit the price police remains the same. However, countries like Brazil usually charges a lot of taxes on total revenue. In this case, the price police for maximizing revenue doesn’t change, but the police for maximizing profit will change according to the following expression:</p>
<p><img alt="displaystyle P_{textrm{max prof}}^{(tax)} = frac{-beta(1-tax) + alpha c}{2alpha(1-tax)}" title="displaystyle P_{textrm{max prof}}^{(tax)} = frac{-beta(1-tax) + alpha c}{2alpha(1-tax)}" src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+P_%7B%5Ctextrm%7Bmax+prof%7D%7D%5E%7B%28tax%29%7D+%3D+%5Cfrac%7B-%5Cbeta%281-tax%29+%2B+%5Calpha+c%7D%7B2%5Calpha%281-tax%29%7D&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"></p>
<h2>Example and implementations:</h2>
<p>As an example of how to proceed with the estimation of the optimum price, let’s generate a linear demand curve with for daily selling of a product:</p>
<pre>library(ggplot2)

# example of linear demand curve (first equation) 

demand = function(p, alpha = -40, beta = 500, sd = 10) {

  error = rnorm(length(p), sd = sd)
  q = p*alpha + beta + error

  return(q)
}

set.seed(100)

prices = seq(from = 5, to = 10, by = 0.1)
q = demand(prices)

data = data.frame('prices' = prices,'quantity' = q)

ggplot(data, aes(prices, quantity)) +
  geom_point(shape=1) +
  geom_smooth(method='lm') +
  ggtitle('Demand Curve')
</pre>
<p><img alt="plot of chunk demand" src="https://i0.wp.com/i.imgur.com/pJkla0L.png"></p>
<p>Imagine a company that has been selling the product which follows the demand curve above for a while (one year changing prices daily), testing some prices over time. The following time-series is what we should expect for the historical revenue, profit and cost of the company:</p>
<pre>set.seed(10)

hist.prices = rnorm(252, mean = 6, sd = .5) # random prices defined by the company
hist.demand = demand(hist.prices) # demand curve defined in the chunck above
hist.revenue = hist.prices*hist.demand # From the revenue equation
unity.cost = 4 # production cost per unity
hist.cost = unity.cost*hist.demand
hist.profit = (hist.prices - unity.cost)*hist.demand # From the price equation

data = data.frame('Period' = seq(1,252),'Daily.Prices' = hist.prices,
                  'Daily.Demand' = hist.demand, 'Daily.Revenue' = hist.revenue,
                  'Daily.Cost' = hist.cost, 'Daily.Profit' = hist.profit)

ggplot(data, aes(Period, Daily.Prices)) +
  geom_line(color = 4) +
  ggtitle('Historical Prices used for explotation')
</pre>
<p><img alt="plot of chunk historical series" src="https://i1.wp.com/i.imgur.com/2sJjOyK.png"></p>
<pre>ggplot(data, aes(Period, Daily.Revenue, colour = 'Revenue')) +
  geom_line() +
  geom_line(aes(Period, Daily.Profit, colour = 'Profit')) +
  geom_line(aes(Period, Daily.Cost, colour = 'Cost')) +
  labs(title = 'Historical Performance', colour = '')
</pre>
<p><img alt="plot of chunk historical series" src="https://i2.wp.com/i.imgur.com/QtD2i6J.png"></p>
<p>We can recover the demand curve using the historical data (that is how it is done in the real world).</p>
<pre>library(stargazer)

model.fit = lm(hist.demand ~ hist.prices) # linear model for demand
stargazer(model.fit, type = 'html', header = FALSE) # output
</pre>
<table>
<tbody>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td></td>
<td><em>Dependent variable:</em></td>
</tr>
<tr>
<td></td>
<td colspan="1"></td>
</tr>
<tr>
<td></td>
<td>hist.demand</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>hist.prices</td>
<td>-38.822<sup>***</sup></td>
</tr>
<tr>
<td></td>
<td>(1.429)</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>Constant</td>
<td>493.588<sup>***</sup></td>
</tr>
<tr>
<td></td>
<td>(8.542)</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>Observations</td>
<td>252</td>
</tr>
<tr>
<td>R<sup>2</sup></td>
<td>0.747</td>
</tr>
<tr>
<td>Adjusted R<sup>2</sup></td>
<td>0.746</td>
</tr>
<tr>
<td>Residual Std. Error</td>
<td>10.731 (df = 250)</td>
</tr>
<tr>
<td>F Statistic</td>
<td>738.143<sup>***</sup> (df = 1; 250)</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td><em>Note:</em></td>
<td><sup>*</sup>p&lt;0.1; <sup>**</sup>p&lt;0.05; <sup>***</sup>p&lt;0.01</td>
</tr>
</tbody>
</table>
<p>And now we need to apply equation 2 and equation 3.</p>
<pre># estimated parameters
beta = model.fit$coefficients[1]
alpha = model.fit$coefficients[2]  

p.revenue = -beta/(2*alpha) # estimated price for revenue
p.profit = (alpha*unity.cost - beta)/(2*alpha) # estimated price for profit
</pre>
<p>The final plot with the estimated prices:</p>
<pre>true.revenue = function(p) p*(-40*p + 500) # Revenue with true parameters (chunck demand)
true.profit = function(p) (p - unity.cost)*(-40*p + 500) # price with true parameters

# estimated curves
estimated.revenue = function(p) p*(model.fit$coefficients[2]*p + model.fit$coefficients[1])
estimated.profit = function(p) (p - unity.cost)*(model.fit$coefficients[2]*p + model.fit$coefficients[1])

opt.revenue = true.revenue(p.revenue) # Revenue with estimated optimum price
opt.profit = true.profit(p.profit) # Profit with estimated optimum price

# plot
df = data.frame(x1 = p.revenue, x2 = p.profit,
                y1 = opt.revenue, y2 = opt.profit, y3 = 0)

ggplot(data = data.frame(Price = 0)) +
  stat_function(fun = true.revenue, mapping = aes(x = Price, color = 'True Revenue')) +
  stat_function(fun = true.profit, mapping = aes(x = Price, color = 'True Profit')) +
  stat_function(fun = estimated.revenue, mapping = aes(x = Price, color = 'Estimated Revenue')) +
  stat_function(fun = estimated.profit, mapping = aes(x = Price, color = 'Estimated Profit')) +
  scale_x_continuous(limits = c(4, 11)) +
  labs(title = 'True curves without noise') +
  ylab('Results') +
  scale_color_manual(name = &quot;&quot;, values = c(&quot;True Revenue&quot; = 2, &quot;True Profit&quot; = 3, &quot;Estimated Revenue&quot; = 4, &quot;Estimated Profit&quot; = 6)) +
  geom_segment(aes(x = x1, y = y1, xend = x1, yend = y3), data = df) +
  geom_segment(aes(x = x2, y = y2, xend = x2, yend = y3), data = df)
</pre>
<p><img alt="plot of chunk final plot" src="https://i1.wp.com/i.imgur.com/SLKLQ1c.png"></p>
<h2>Final observations</h2>
<p>As you can see, the estimated Revenue and estimated Profit curves are quite similar to the true ones without noise and the expected revenue for our estimated optimal policies looks very promising. Although the linear and monopolist assumption looks quite restrictive, this might not be the case, check Besbes and Zeevi (2015) and Cooper et al (2015).</p>
<p>If one expect a large variance for <img alt="alpha" title="alpha" src="https://s0.wp.com/latex.php?latex=%5Calpha&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">, it might be useful to simulate <img alt="alpha" title="alpha" src="https://s0.wp.com/latex.php?latex=%5Calpha&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">, <img alt="beta" title="beta" src="https://s0.wp.com/latex.php?latex=%5Cbeta&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> and then the optimal price using Jensen’s inequality.</p>
<h2>References</h2>
<p>Phillips, Robert Lewis. Pricing and revenue optimization. Stanford University Press, 2005.</p>
<p>Besbes, Omar, and Assaf Zeevi. “On the (surprising) sufficiency of linear models for dynamic pricing with demand learning.” Management Science 61.4 (2015): 723-739.</p>
<p>Cooper, William L., Tito Homem-de-Mello, and Anton J. Kleywegt. “Learning and pricing with models that do not explicitly incorporate competition.” Operations research 63.1 (2015): 86-103.</p>
<p>Talluri, Kalyan T., and Garrett J. Van Ryzin. The theory and practice of revenue management. Vol. 68. Springer Science &amp; Business Media, 2006.</p>
<p> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/insightr.wordpress.com/613/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/insightr.wordpress.com/613/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://insightr.wordpress.com/2017/08/27/pricing-optimization-how-to-find-the-price-that-maximizes-your-profit/"> R – insightR</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/nHzRH272d7g" height="1"></a></div>