Mastering the Artwork of Pricing Optimization — A Information Science Answer | by Rhydham Gupta | Aug, 2023

Unlocking Secrets and techniques of Actual-World Information Science Options for Pricing Optimization in Retail

Picture By Creator

Desk Of Contents:

1. Overview
2. Elasticity Modeling
3. Optimization

Pricing performs a really essential position on the planet of enterprise. Making a steadiness between gross sales and margins is essential for the success of any enterprise. How can we do it within the information science method? On this part, we’ll construct the instinct of an efficient information science answer for pricing optimization after which we’ll go into the small print and code of every part.

Notice — There are several types of pricing methods however on this article, we’ll give attention to constructing the pricing technique for standard companies/established manufacturers with sufficient information on value change historical past. Let’s have a look at the essential strategy that we try to observe earlier than going into particulars —

Picture by Creator

We now have plotted gross sales and costs for merchandise 1. Prior to now 9 months, there have been 2 value modifications and clearly, we will see the impression on the gross sales. When costs had been decrease gross sales had been larger. Now the query is find out how to quantify the impression on gross sales as a result of value modifications prior to now and predict the optimum value for the merchandise sooner or later.

An fascinating remark from Jan-Apr, the value has been fastened at $5 however we nonetheless observe gross sales fluctuations. It’s very regular as in a sensible world there are a whole lot of exterior elements that impression gross sales like seasonality, holidays, promotional occasions, advertising expenditure, and so on. Therefore, we don’t mannequin the precise gross sales however the baseline gross sales which we derive utilizing the totally different fashions.

Picture by Creator

You possibly can observe that we’re taking a look at a smoother pattern of gross sales within the baseline gross sales sequence. Is it 100% correct? Undoubtedly Not! Information science is all about how shut we will get to actuality. Let’s transfer to the method now —

Suppose, we’re employed and requested to offer the costs for 1000’s of things throughout shops for the Retailmart group. The costs of the identical merchandise might be totally different throughout totally different shops. The corporate has supplied us with information for the previous 5 years. What needs to be our strategy to fixing it?

Let’s perceive this with a value meter instance. Assume that we now have a value meter and we now have fastened the minimal and most values and the dial can transfer in between these two extremes. At the moment, the dial is pointing towards the present value. Our goal is to cease the dial at a degree the place we will maximize earnings.

Now as we transfer the dial towards the proper (i.e. we’re growing the value) the gross sales will begin to go down and margins will improve however

  1. Can we quantify this lower? sure, we will and it is named the value elasticity of an merchandise. In easy phrases, Value elasticity for an merchandise would imply the proportion change in gross sales for a 1% change within the value.
  2. In the actual world, gross sales are sometimes pushed by promotional occasions, holidays, additional reductions, and so on. however for optimizing the value we would wish to exclude the impact of all these exterior elements and compute baseline gross sales.
  3. As soon as we quantify the change in gross sales w.r.t the change in value, we want the reply, The place do I cease the dial? For that, we want an goal which usually is maximizing the earnings. Income = Gross sales * Margin so we have to cease on the place the place our earnings worth will get most. Mathematically, it is a idea of non-linear optimization the place worth can transfer inside bounds.
  4. Enterprise Guidelines are necessary, we now have to make it possible for the ultimate really helpful costs adhere to those guidelines.

So these are the most important steps that we are going to observe to derive the proper value for every merchandise in a given retailer. Let’s have a look at these steps in just a little extra element —

1. Baselines Gross sales/Base Items

This step is a pre-step for the following steps. As acknowledged, we wish to mannequin the impression on gross sales as a result of modifications within the costs. The best situation is to have gross sales which might be solely impacted as a result of costs however within the sensible world, it’s by no means the case —

So we wish to simulate the gross sales for our ideally suited situation and we do it utilizing a time sequence mannequin on the beneath equation —

Gross sales ~ operate[Baseline_sales + (promotional effect) + (holidays effect) + (any other effect) ]

Please word that generally we don’t have precise information on the exterior elements which might be impacting the gross sales. In such a situation, we will use dummy variables to account for all such elements. A easy instance might be if, in a sure month, we see a sudden improve in gross sales however the value stays fixed, we will introduce a easy dummy variable having 1s for that month and 0s for the remaining months.

2. Value Elasticity

Value Elasticity refers back to the % change in gross sales w.r.t the % change within the value of an merchandise for a given retailer.

For example, take into account two merchandise milk and ABC inexperienced tea. Which do you assume could have excessive value elasticity?

Milk, being an important on a regular basis merchandise with excessive competitors, displays excessive value elasticity. Even a slight change in value can considerably affect gross sales as a result of its widespread demand. Alternatively, ABC inexperienced tea, which is perhaps out there in a restricted variety of shops, experiences low value elasticity. A small value change for ABC inexperienced tea is unlikely to have a considerable impression on gross sales as a result of its area of interest market presence.

How will we mannequin this?

Baseline_Sales ~ operate[(price) + trend]

The coefficient of the value variable will probably be used as the value elasticity. Development variable is used to account for gross sales improve as a result of a long-term pattern and never essentially as a result of value modifications. We’ll focus on extra particulars on computing elasticities within the Value Elasticity part beneath.

3. Non-linear optimization inside bounds

On this step, we’ll get the reply to the place the dial needs to be stopped.

We first outline our goal operate — maximizing the earnings

Then we outline the beginning and finish level of the value meter that defines the LB and UB of the value

We now have already computed baseline gross sales and value elasticities which quantify the gross sales sensitivity to cost. We’ll put all these inputs into our non-linear optimization operate and we’ll get the optimized value.

In quite simple phrases, the algorithm will strive totally different value factors inside the bounds and examine the worth of the target operate which in our case is earnings. It’s going to return us to the value level the place it may get most worth for our goal operate. (In linear optimization, visualize how the gradient descent works). We’ll focus on extra particulars on computing the optimized costs within the Optimization part beneath.

4. Enterprise Guidelines

So can we straight implement the optimized costs in our shops?

No, however what’s left now? Adhering to enterprise guidelines is among the most necessary necessities for any enterprise.

However what sort of guidelines are we speaking about in pricing —

  1. Ending Quantity Guidelines — It’s a frequent follow to cost the product at $999 or $995 as an alternative of $1000. There are a number of psychological causes for doing so therefore we might want to make it possible for our closing really helpful costs adhere to any such guidelines if these are relevant.
  2. Product Hole Guidelines — Are you able to promote the one-pack Maggi priced dearer per unit than the 4-pack Maggi? No, Proper. Usually if the pack’s dimension will increase the per-unit value ought to go down or at the least keep the identical.

So, these are examples of among the enterprise guidelines that the enterprise desires to use. We’ll do some post-processing steps on the optimized costs to get to the ultimate really helpful costs.

Now that you’re conscious of the general course of, it’s time to dive into extra particulars and coding.

On this part, we’ll perceive how we will use this idea to derive optimized costs for 1000s of things throughout a number of shops. Let’s say we now have to find out value elasticity for a snack merchandise Yochips promoting in a California retailer for the previous 3 years. Let’s first see the definition of value elasticity:-

Value elasticity is outlined as the proportion change in gross sales with a 1% change within the value.

Now it’s possible you’ll be questioning, which algorithm can I take advantage of for computing the value elasticity of an merchandise like Yochips?

Allow us to look into some particulars from the financial e-book on the fixed value elasticity mannequin and see if we will relate it to some information science algorithm.

The multiplicative type of the demand operate will probably be:-

Yi = α*Xi (the place y will probably be gross sales/demand and x will probably be value)

Taking the go surfing either side

log(Yᵢ) = log(α*Xᵢ^β)

log(Yᵢ) = log(α) + β*log(Xᵢ) ……….Eq(1)

log(α) might be thought-about as an intercept as β₀

log(Yᵢ) = β₀ + β₁*log(Xᵢ) ………….Eq(2)

Now taking the differentiation on either side, we’ll get

δY/Y = β₁*δX/X

The time period on the left-hand facet represents the % change in Y which is the % change in gross sales whereas the time period on the proper facet represents the %change in value. Now when

%change in value = 1%; then δX/X = 1

δY/Y = β₁

This is able to imply the proportion change within the gross sales will probably be β₁ and that’s our elasticity.

Now when you would have seen, Equation 2 is a Regression Equation the place log(gross sales) are regressed towards log(value) and the coefficient of log(value) will probably be our value elasticity.

Hurray! Now we all know that computing elasticity is so simple as coaching a regression mannequin.

However there may be another catch. The demand operate equation has some assumptions and one of many assumptions is that gross sales are solely impacted by value however that’s usually by no means the case in the actual world as a result of there are usually a number of elements impacting the gross sales like promotions, holidays, occasions, and so on. So what’s the answer, we have to compute the gross sales part whereby we will take away the impression of all these extra occasions.

One factor to make clear is that base gross sales confer with unit gross sales and never greenback gross sales. So in equation 2, we have to regress the value towards base items as an alternative of precise unit gross sales. Now the query is how can we derive the bottom items from the precise gross sales items?

Let’s perceive it utilizing an instance. Under you may see the weekly plot of the time sequence for gross sales items and promote costs:-

Picture by Creator

Are you able to see any sample within the above plot, it’s tough to inform as a result of there are too many fluctuations within the gross sales items sequence. Now these fluctuations might be as a result of a number of elements like holidays, promotions, occasions, FIFA World Cup, and so on. To isolate the impact of value modifications, we have to compute gross sales that exclude the affect of those extra elements.

Utilizing the prophet mannequin, we will decompose the time sequence and extract the pattern part which represents the bottom gross sales. By making use of this method, we separate the long-term impression of value modifications from different short-term influences. Let’s see what we’re speaking about:-

Picture by Creator

Within the above plot, have decomposed the unique log gross sales items (grey) into log base items (yellow line plot)

Here’s a code utilizing which you’ll decompose the time sequence and fetch the pattern part which is able to turn into base gross sales:-

# Defining the inputs
timestamp_var = "week_ending_sunday"
baseline_dep_var = "ln_sales"
changepoint_prior_scale_value = 0.3
list_ind_vars_baseline = ['event_type_1_Cultural','event_type_1_National','event_type_1_Religious','event_type_1_Sporting']
# Making ready the datasecloset
df_item_store = df_item_store.rename(columns={timestamp_var: 'ds', baseline_dep_var: 'y'})
df_item_store['ds'] = pd.to_datetime(df_item_store['ds'])

# Initializing and becoming the mannequin
mannequin = Prophet(changepoint_prior_scale= changepoint_prior_scale_value) #Default changepoint_prior_scale = 0.05

# Add the regressor variables to the mannequin

for regressor in list_ind_vars_baseline:

# Since we're solely decomposing present time sequence, we'll use identical information is forecasting that was used for modelling
# Making predictions and extracting the extent part
forecast = mannequin.predict(df_item_store)
level_component = forecast['trend']

Under are the inputs that we have to outline:

  • changepoint_prior_scale_value — This controls the smoothness of the pattern. You possibly can learn extra about it within the prophet mannequin documentation.
  • list_ind_vars_baseline — These embody all the extra occasions which have impacted the gross sales like some festivals, sports activities occasions, cultural occasions, and so on.

Right here is how changepoint_prior_scale_value impacts the pattern. when the worth is small then it results in an virtually straight line and when the worth is excessive then the pattern is much less easy.

The code is straightforward, Initially, we rename the “ln_sales” variable as “y” and the “week” variable as “ds” to fulfill the conditions for using the Prophet mannequin. Subsequent, we initialize the Prophet mannequin, specifying the “changepoint_prior_scale” parameter. Subsequently, we incorporate extra occasion and vacation variables into the mannequin. Lastly, we generate forecasts utilizing the identical dataset on which we educated the mannequin and extracted the pattern part.

Nice. We now have the bottom items sequence and we will match a linear regression mannequin between base items (that are already at log scale as a result of we decomposed the log_base_units sequence) and log(value). Under is the equation:-

log(base items) = intercept + elasticity*log(value)

With the above equation, we will compute the elasticity worth. In follow, not all of the sequence are good to mannequin so it’s possible you’ll count on some sudden values of elasticity for varied objects. Then what’s the answer? If we will by some means carry out a regression with constraints on the elasticity worth. However how can we implement it? Utilizing Optimization operate.

For any optimization, beneath are the essential necessities:-

  1. An goal operate — That is the equation that we attempt to decrease/maximize. In our case, it will likely be the loss operate that we use in linear regression MSE (pred-actual => [intercept + elasticity*ln_price — actual]²)
  2. The preliminary values of the parameter that we try to optimize, in our case it’s intercept and elasticity. These might be any random values initially.
  3. Bounds for the parameters, These are min and max bounds for each intercept & elasticity
  4. Optimization algorithm — That is depending on the library however you need to use the defaults and that ought to provide the proper outcomes

Let’s now see the code:-

# Making ready the matrix to feed into optimization algorithm
x = df_item_store_model
x["intercept"] = 1
x = x[["intercept","ln_sell_price","ln_base_sales"]].values.T
# x_t = x.T

actuals = x[2]

from scipy.optimize import decrease

# Outline the target operate to be minimized
def goal(x0):
return sum(((x[0]*x0[0] + x[1]*x0[1]) - actuals)**2) # (intercept*1 + elasticity*(ln_sell_price) -ln_base_sales)^2

# Outline the preliminary guess
x0 = [1, -1]

# Outline the bounds for the variables
bounds = ((None, None), (-3,-0.5))

# Use the SLSQP optimization algorithm to reduce the target operate
end result = decrease(goal, x0, bounds=bounds, methodology='L-BFGS-B')

# Print the optimization end result
print(end result)

# Saving the value elastitcity of an merchandise within the dataframe
price_elasticity = end result.x[1]
df_item_store_model["price_elasticity"] = end result.x[1]

Discover that we now have outlined the preliminary parameter worth for intercept as 1 and elasticity as -1. There aren’t any bounds outlined for intercept whereas bounds of (-3,-0.5) are outlined for elasticity. That is the principle motive why we’re performing the regression by means of the optimization operate. After operating the optimization, we save the optimized parameter worth of the value elasticity. Hurray! we now have computed the value elasticity!

So our Yochips on the California retailer have a value elasticity of -1.28.

Let’s have a look at the value elasticity for another sequence as effectively:-

Low Value Elasticity: No vital change in gross sales with a rise in value. Under is a plot for an merchandise having a value elasticity of -0.5

Picture by Creator

Medium Value Elasticity: There’s a average drop in gross sales with a rise in value. Under is a plot for an merchandise having a value elasticity of -1.28

Picture by Creator

Excessive Value Elasticity: There’s a excessive drop in gross sales with a rise in value. Under is a plot for an merchandise having a value elasticity of -2.5

Picture by Creator

Utilizing the identical strategy, we will compute the value elasticity for all of the objects. Within the subsequent article, we’ll discover how we will make the most of these elasticity values to find out the optimized costs for every merchandise.

Within the earlier part, we had already decided the value elasticity of Yochips for our California retailer. However that doesn’t assist the shop supervisor, he desires to understand how he ought to change the value of Yochips to maximise income. On this article, we’ll perceive the methodology to optimize costs.

However earlier than that, there are a number of questions, we should ask the shop supervisor.

Q: Is there some restrict on the minimal and most value change that needs to be thought-about whereas optimizing costs?

Primarily based on the discussions with the shop supervisor, we established that the value lower mustn’t exceed 20% and value will increase must also be restricted to twenty%.

The present value for the Yochips is $3.23 and now we all know that the optimized value needs to be between $2.58 — $3.876. However how can we derive an optimized value?

However how can we derive an optimized value that maximizes income? Let’s do some maths:-

Optimized Income = Complete items bought * (Optimized Value)

We have to optimize the value in order that we will maximize income. However the whole items bought may even change with a change in value. Let’s re-write the above equation and we will name the whole items bought at an optimized value as optimized items:-

Optimized Income = Optimized items* (Optimized Value)……………(eq1)

We already know that —

Elasticity = %change within the items bought/ %change within the value


Optimized items = Base items + change in items at an optimized value

Right here, Base items confer with whole unit gross sales on the present value which is $2.58

Optimized items = (Base items + (Base items * value elasticity * (% change within the optimized value vs common value) ………. (eq2)

Let’s impute the eq2 in eq1

Optimized Income = (Base items + (Base items * value elasticity * (% change within the optimized value vs common value) * (Optimized Value) …….. (eq3)

Optimized Income = (Base items + (Base items * value elasticity * [(Optimized Price — Current Price)/ Current Price]* (Optimized Value)…………..eq(4)

Under are the important thing parameters within the optimization equation (eq4):

Base items = Common unit gross sales on the present value.

Value elasticity = computed worth for the merchandise’s value elasticity

Present value = Newest promoting value

Nice! In our equation, aside from the optimized value, we now have information for all different variables. So which algorithm can we use to compute an optimized value that maximizes income? We are able to merely use the optimization algorithm.

What are the important elements wanted for optimization:-

  1. The target operate that must be minimized/maximized:- We now have already outlined the target operate which is maximizing the optimized income as outlined in eq(4).
  2. Bounds: As outlined by the shop supervisor, we want the optimized value to not change by greater than 20%. So the Decrease Sure = Present Value (1–0.2) & Higher Sure = Present Value (1+0.2)
  3. Optimization Algorithm: We’ll use Scipy.optimize library from Python to implement the optimization.

Let’s have a look at the code:-

# Taking newest 6 weeks common of the bottom gross sales

# Rating the date colume
df_item_store_optimization["rank"] = df_item_store_optimization["ds"].rank(ascending=False)

# Subset newest 6 weeks of information
base_sales_df = df_item_store_optimization.loc[df_item_store_optimization["rank"] <= 6].groupby("id")["base_sales"].imply().reset_index()

df_item_store_optimization_input.rename(columns = {"base_sales":"base_units"}, inplace=True)

# Deriving the min and max sure for the sell_price

# Creating UB and LB as with the vary of 20%
df_item_store_optimization_input["LB_price"] = df_item_store_optimization_input["sell_price"] - (0.2*df_item_store_optimization_input["sell_price"])
df_item_store_optimization_input["UB_price"] = df_item_store_optimization_input["sell_price"] + (0.2*df_item_store_optimization_input["sell_price"])

The above code helps us in information prep for optimization. Firstly, we’re computing the bottom items as the common of base_sales (pattern part of the decomposed sequence) for the most recent 6 weeks. We now have already mentioned the methodology to compute the base_sales in the above part.

Subsequent, we’re defining the LB_price & UB_price by lowering and growing 20% from the present promote value respectively.

Let’s outline the code to hold out optimization.

from scipy.optimize import decrease

# Outline the target operate to be minimized
def goal(opti_price):

df_item_store_optimization_input["opti_price"] = opti_price
df_item_store_optimization_input["optimized_units"] = df_item_store_optimization_input["base_units"] + (df_item_store_optimization_input["base_units"]*
((df_item_store_optimization_input["opti_price"]/df_item_store_optimization_input["sell_price"]) - 1)*

df_item_store_optimization_input["optimized_revenue"] = df_item_store_optimization_input["optimized_units"]*df_item_store_optimization_input["opti_price"]

return -sum(df_item_store_optimization_input["optimized_revenue"])

# Outline the preliminary guess
opti_price = df_item_store_optimization_input["sell_price"][0]

# Outline the bounds for the variables
bounds = ((df_item_store_optimization_input["LB_price"][0], df_item_store_optimization_input["UB_price"][0]),)

# # Use the optimization algorithm to reduce the target operate
end result = decrease(goal, opti_price, bounds=bounds)

# Print the optimization end result
print(end result)

The above code will give us the optimized value. Are you able to guess that within the goal operate why are we defining unfavourable optimized income? What’s -(-1), it’s 1. We’re minimizing the target operate and utilizing the unfavourable signal for the optimized income will result in maximizing the optimized income.

Furthermore, we will initialize the opti_price variable with any random worth, simply to facilitate quick convergence, we’re initializing it with the present sell_price. Within the bounds, we’re defining the LB & UB that we now have created within the above code.

Hurray! We now have came upon the optimized value for Yochips and we’re able to suggest it to the California retailer supervisor.

Picture by Creator

Our suggestion will probably be to drop the Yochips costs by 10.2% to $2.9. It will end in most income.

That is the final step within the value optimization strategy and the general strategy is so highly effective that it may possibly assist us to return optimized costs for every merchandise at each retailer.

One of many limitations of the above strategy is for the objects the place we don’t have adequate value change historical past. In that situation, we use different methods but when that fraction of things is much less, then the common value elasticity at class degree can be utilized for such objects.

Hope you loved this text!

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button