All articles →

100 Exercises / Marketing Science / Marketing Science 100 Exercises

Practicing Price Optimization in Manufacturing with Python | From Price Elasticity to Dynamic Pricing and Reinforcement Learning

Explore manufacturing pricing in Python through elasticity, profit optimization, coupons, bandits, price search, and inventory-based Q-learning.

This article focuses on a fictional manufacturing industry that handles industrial dust filters, covering price elasticity, customer preferences, profit maximization, dynamic pricing, promotions and coupons, online learning, Bayesian optimization, reinforcement learning, and practical implementation as a single decision-making process. The goal is not to consider prices solely by the “degree of increase,” but to simultaneously consider demand, gross profit, production capacity, customer relationships, and learning costs.

Note This article adapts a notebook used in corporate training by Surikobo or its representative, Hiroshi Wayama, and is published with the participating company’s permission. All data listed is fictional and has no relation whatsoever to real companies, factories, or figures.

Introduction: Practical Challenges in Manufacturing Covered in This Article

While raw material and logistics costs are rising, the sales department is worried about losing orders. Furthermore, there are months when production capacity is tight and months when there is margin, and simply quoting the same price for all customers and all periods misses profit opportunities. In this article, we will create a minimum structure where sales, production, and accounting can discuss prices using common values.

Common situations on site

  • Quantity decreases after price hikes are based solely on experience.
  • Policies that pursue sales and those that pursue marginal profit are mixed together.
  • The discount is ‘carried over from last year,’ and the incremental profit has not been verified.
  • Customer pricing becomes personalized and learning outcomes do not remain with the organization.
  • Even if demand is stimulated, factory supply capacity becomes a bottleneck.

Why is this issue so difficult to judge?

A price increase usually raises contribution per unit while reducing demand, so total profit need not increase. Customer mix, seasonality, and sales effort also affect observed data. Do not interpret the price–volume correlation as a causal effect without checking those factors and the pricing process.

Exercises in This Article

In No.051 to No.053, you will learn about price responses and static profit maximization, while in No.054 to No.056, you will handle differences in timing, promotions, and customers. No.057 to No.059 compare methods of learning during operations and integrate them into implementation plans including KPIs, approvals, and monitoring in No.060.

Preparing the Python environment

No external data is used. Fix the random number generator so you can reproduce the same results. Unless otherwise specified, amounts are in yen, and quantities are per piece per month.

Run the cells from top to bottom in Jupyter Notebook. Expand the preparation sections to view their code. Each article records the environment used for its outputs. Fixed random seeds do not prevent differences caused by library versions.

Preparation: libraries and display settings (expand)
[IN: 1]
import sys
import numpy as np
import pandas as pd
from IPython.display import display
import matplotlib
import matplotlib.pyplot as plt
import japanize_matplotlib
from scipy.optimize import minimize_scalar
from sklearn.linear_model import LinearRegression

SEED = 20260712
rng = np.random.default_rng(SEED)
pd.set_option("display.float_format", lambda x: f"{x:,.2f}")
print(
    f"Python {sys.version.split()[0]} / pandas {pd.__version__} / matplotlib {matplotlib.__version__}"
)
[OUT: 1]
Python 3.14.4 / pandas 3.0.3 / matplotlib 3.11.0

Creation of Fictional Data

Generate business negotiation data for 3 customer segments over 24 months. Prices fluctuate depending on market conditions and monthly, while demand is influenced by price, seasonality, and customer size. The true demand formula is used only for generating data for the teaching materials, while the analysis side estimates it from observational data.

Preparation: synthetic data generation (expand)
[IN: 2]
months = pd.date_range("2024-01-01", periods=24, freq="MS")
segments = {
    "Large accounts": (320, -1.15),
    "Mid-sized accounts": (190, -1.55),
    "Small accounts": (95, -2.05),
}
rows = []
for t, month in enumerate(months):
    season = 1 + 0.10 * np.sin(2 * np.pi * t / 12)
    market = 1 + 0.025 * t / 12
    for segment, (base_qty, elasticity) in segments.items():
        price = 10_000 * market * rng.uniform(0.92, 1.10)
        expected = base_qty * season * (price / 10_000) ** elasticity
        quantity = max(1, int(round(expected + rng.normal(0, base_qty * 0.045))))
        rows.append((month, segment, price, quantity, 6_200 + 18 * t))
sales = pd.DataFrame(
    rows, columns=["month", "segment", "price", "quantity", "unit_cost"]
)
sales["revenue"] = sales.price * sales.quantity
sales["gross_profit"] = (sales.price - sales.unit_cost) * sales.quantity
display(sales.head(6))
print(
    f"Number of lines: {len(sales):,}, Sales: {sales.revenue.sum()/1e6:,.1f}million yen"
)
[OUT: 2]
month segment price quantity unit_cost revenue gross_profit
0 2024-01-01 Large accounts 10,446.52 314 6200 3,280,205.73 1,333,405.73
1 2024-01-01 Mid-sized accounts 10,764.81 168 6200 1,808,488.43 766,888.43
2 2024-01-01 Small accounts 9,260.98 113 6200 1,046,490.19 345,890.19
3 2024-02-01 Large accounts 10,916.25 300 6218 3,274,875.57 1,409,475.57
4 2024-02-01 Mid-sized accounts 9,544.64 228 6218 2,176,176.96 758,472.96
5 2024-02-01 Small accounts 9,751.53 105 6218 1,023,911.01 371,021.01
Number of lines: 72, Sales: 144.8million yen

No.051: Price Elasticity

Meaning in Practice

Price elasticity represents how much demand changes when the price changes by 1%. In markets where the absolute value exceeds 1, demand reacts strongly to price changes. However, price increases are not determined solely by elasticity; costs and capability constraints are also considered.

Approach to Analysis and Modeling

Let the constant elasticity model be Q=APεQ=A P^{\varepsilon}, then take the logarithm and

log⁡Q=α+εlog⁡P\log Q=\alpha+\varepsilon\log P

The regression coefficient ε\varepsilon represents price elasticity. Here, a monthly dummy is also added to minimize the impact of seasonal fluctuations. Since endogeneity remains in observational studies, price experiments and instrumental variables are also considered in production.

Check with Python

[IN: 3]
elasticity_rows = []
for segment, g in sales.groupby("segment"):
    X = pd.concat(
        [
            np.log(g.price).rename("log_price"),
            pd.get_dummies(g.month.dt.month, prefix="m", drop_first=True),
        ],
        axis=1,
    )
    model = LinearRegression().fit(X, np.log(g.quantity))
    elasticity_rows.append(
        (segment, model.coef_[0], model.score(X, np.log(g.quantity)))
    )
elasticity_df = pd.DataFrame(
    elasticity_rows, columns=["segment", "estimated_elasticity", "R2"]
)
display(elasticity_df)

fig, ax = plt.subplots(figsize=(7, 4))
ax.bar(
    elasticity_df.segment,
    elasticity_df.estimated_elasticity,
    color=["#4472C4", "#70AD47", "#ED7D31"],
)
ax.axhline(-1, color="black", linestyle="--", label="Unit elasticity (-1)")
ax.set_title("Estimated Price Elasticity by Customer Segment")
ax.set_xlabel("Customer Segments")
ax.set_ylabel("price elasticity")
ax.grid(axis="y", alpha=0.3)
ax.legend()
plt.tight_layout()
plt.show()
[OUT: 3]
segment estimated_elasticity R2
0 Large accounts -1.15 0.98
1 Mid-sized accounts -2.07 0.96
2 Small accounts -2.09 0.93

No.051: Price Elasticity — output

Reading the results

The smaller the portion, the larger the absolute value, which makes price comparisons more likely to occur, which is also considered a regression setting. For large traders, value propositions including supply stability and technical support are important, rather than uniform discounts; for small traders, monitoring competitive prices is important. Estimates are used for decision-making after reviewing the target period, confidence intervals, and pricing process.

No.052: Conjoint Analysis

Meaning in Practice

For B2B products, not only unit price but also lifespan, delivery time, and maintenance contracts influence selection. Conjoint analysis is a method where customers estimate the relative value of each attribute from selection data comparing the entire product, and design specifications and pricing simultaneously.

Approach to Analysis and Modeling

Set utility to U=β0+βpP+∑kβkxkU=\beta_0+\beta_p P+\sum_k\beta_k x_k, and this time, we will check partial utility using linear regression from a hypothetical choice score. The willingness to pay for an attribute is calculated by dividing the attribute coefficient by the absolute value of the price coefficient. For discrete selection in production, the Logit model and hierarchical Bayes are suitable.

Check with Python

[IN: 4]
n = 240
profiles = pd.DataFrame(
    {
        "price_k": rng.choice([9.5, 10.5, 11.5, 12.5], n),
        "life_18m": rng.integers(0, 2, n),
        "delivery_3d": rng.integers(0, 2, n),
        "remote_support": rng.integers(0, 2, n),
    }
)
true_beta = np.array([-0.85, 1.50, 0.95, 0.65])
profiles["preference_score"] = profiles[
    ["price_k", "life_18m", "delivery_3d", "remote_support"]
].to_numpy() @ true_beta + rng.normal(0, 0.65, n)
conjoint = LinearRegression().fit(
    profiles.drop(columns="preference_score"), profiles.preference_score
)
coef = pd.Series(conjoint.coef_, index=profiles.columns[:-1], name="partial utility")
wtp = (coef.drop("price_k") / abs(coef["price_k"]) * 1000).rename(
    "amount_of_willing_to_pay_yen"
)
display(pd.concat([coef, wtp], axis=1))

fig, ax = plt.subplots(figsize=(7, 4))
wtp.sort_values().plot.barh(ax=ax, color="#5B9BD5")
ax.set_title("Estimated willingness to pay for additional attributes")
ax.set_xlabel("Willingness to pay (JPY/unit)")
ax.set_ylabel("Additional Attributes")
ax.grid(axis="x", alpha=0.3)
plt.tight_layout()
plt.show()
[OUT: 4]
partial utility amount_of_willing_to_pay_yen
price_k -0.81 NaN
life_18m 1.60 1,972.24
delivery_3d 0.87 1,074.14
remote_support 0.59 720.21

No.052: Conjoint Analysis — output

Reading the results

The largest willingness to pay for longevity is the most significant, followed by short delivery times and remote support. Attributes where the additional cost is less than the willingness to pay are candidates for the high value-added version. However, since average values alone can hide differences in customers, design and analyze by purchasing participants and specific use cases.

No.053: Maximizing Profit

Meaning in Practice

Maximizing sales and maximizing profits do not coincide. Lowering the price increases quantity, but the marginal profit per unit shrinks. By connecting demand forecasts by price with costs, we visualize sensitivity to operating profit.

Approach to Analysis and Modeling

If we Q(P)=A(P/P0)εQ(P)=A(P/P_0)^\varepsilon forecasted demand and unit variable cost cc, the marginal profit is

Π(P)=(P−c)Q(P)\Pi(P)=(P-c)Q(P)

Here, the cap is also included, and the available quantity is set at min⁡(Q(P),K)\min(Q(P),K).

Check with Python

[IN: 5]
price_grid = np.arange(7_500, 14_001, 100)
base_demand, base_price, eps, unit_cost, capacity = 620, 10_000, -1.55, 6_500, 700
demand = base_demand * (price_grid / base_price) ** eps
sold = np.minimum(demand, capacity)
profit = (price_grid - unit_cost) * sold
profit_table = pd.DataFrame(
    {"price": price_grid, "demand": demand, "sold": sold, "gross_profit": profit}
)
best = profit_table.loc[profit_table.gross_profit.idxmax()]
display(best.to_frame("optimal point"))

fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(price_grid, profit / 1e6, label="Contribution profit", color="#4472C4")
ax.axvline(
    best.price,
    color="#C00000",
    linestyle="--",
    label=f"Best Price {best.price:,.0f}jpy",
)
ax.set_title("Price and monthly contribution profit with a capacity limit")
ax.set_xlabel("Price (JPY/unit)")
ax.set_ylabel("Monthly Marginal Profit (million yen)")
ax.grid(alpha=0.3)
ax.legend()
plt.tight_layout()
plt.show()
[OUT: 5]
optimal point
price 14,000.00
demand 368.04
sold 368.04
gross_profit 2,760,288.64

No.053: Maximizing Profit — output

Reading the results

The best candidate is JPY 14,000, the upper bound of the search range; the search has not found an interior peak. Without a binding capacity constraint, the constant-elasticity model gives P∗=cε/(1+ε)P^*=c\varepsilon/(1+\varepsilon), about JPY 18,318 for these parameters. That extrapolates beyond the observed price range and requires validation of demand assumptions and contract limits.

No.054: Dynamic Pricing

Meaning in Practice

If demand and production capacity differ month by month, fixed prices cause missed opportunities. However, rather than arbitrarily changing existing contracts, design them as explainable pricing rules such as spot orders, short delivery fees, and off-peak discounts.

Approach to Analysis and Modeling

Forecast demand coefficient AtA_t and capacity KtK_t at tt each month, and select max⁡p(p−ct)min⁡{Qt(p),Kt}\max_p (p-c_t)\min\{Q_t(p),K_t\} from the candidate price. If carrying over to the future or inventory is important, extend to multi-period optimization.

Check with Python

[IN: 6]
dynamic_rows = []
for t in range(12):
    season = 1 + 0.22 * np.sin(2 * np.pi * t / 12)
    cap = 650 + 70 * np.cos(2 * np.pi * t / 12)
    cost = 6_500 + 120 * np.sin(2 * np.pi * (t + 2) / 12)
    q = 620 * season * (price_grid / 10_000) ** -1.55
    gp = (price_grid - cost) * np.minimum(q, cap)
    i = np.argmax(gp)
    dynamic_rows.append((t + 1, season, cap, price_grid[i], gp[i]))
dynamic = pd.DataFrame(
    dynamic_rows,
    columns=["month", "demand_index", "capacity", "optimal_price", "gross_profit"],
)
display(dynamic.round(1))

fig, ax1 = plt.subplots(figsize=(8, 4))
ax1.plot(
    dynamic.month,
    dynamic.optimal_price,
    marker="o",
    color="#4472C4",
    label="Suggested Price",
)
ax1.set_xlabel("month")
ax1.set_ylabel("Recommended price (JPY/unit)")
ax2 = ax1.twinx()
ax2.plot(
    dynamic.month,
    dynamic.demand_index,
    marker="s",
    color="#ED7D31",
    label="Demand Index",
)
ax2.set_ylabel("Demand Index")
ax1.set_title("Seasonal demand and monthly recommended prices")
ax1.grid(alpha=0.3)
lines = ax1.lines + ax2.lines
ax1.legend(lines, [x.get_label() for x in lines], loc="best")
plt.tight_layout()
plt.show()
[OUT: 6]
month demand_index capacity optimal_price gross_profit
0 1 1.00 720.00 14000 2,722,041.00
1 2 1.10 710.60 14000 3,014,897.70
2 3 1.20 685.00 14000 3,240,659.40
3 4 1.20 650.00 14000 3,340,611.70
4 5 1.20 615.00 14000 3,286,194.30
5 6 1.10 589.40 14000 3,088,431.80
6 7 1.00 580.00 14000 2,798,536.30
7 8 0.90 589.40 14000 2,495,963.40
8 9 0.80 615.00 14000 2,265,343.50
9 10 0.80 650.00 14000 2,170,249.30
10 11 0.80 685.00 14000 2,234,383.00
11 12 0.90 710.60 14000 2,437,003.60

No.054: Dynamic Pricing — output

Reading the results

All 12 months select JPY 14,000, so the recommended price does not change. Although demand and costs vary by month, profit increases up to the candidate ceiling and capacity is not binding at the selected price. Optimizing each month does not necessarily produce different prices.

No.055: Campaign Optimization

Meaning in Practice

Exhibitions, technical seminars, and sample provision use not only budget but also the man-hours of sales and technical staff. Allocation to the channel is determined based on incremental marginal profit rather than response rate.

Approach to Analysis and Modeling

The gross contribution from block mm of campaign jj is aje−dj(m−1)a_j e^{-d_j(m-1)}. We allocate 18 blocks of JPY 100,000 each in descending order of marginal contribution. All selected blocks return more than their cost, so the full budget is used. ROI is calculated as (incremental contribution minus investment) divided by investment.

Check with Python

[IN: 7]
channels = {
    "Exhibition": (95, 0.16),
    "Technical Seminar": (72, 0.12),
    "Sample Provision": (58, 0.09),
}  # Initial incremental profit (10,000 yen), decay rate
budget_units = 18
allocation = {k: 0 for k in channels}
gain = {k: 0.0 for k in channels}
for _ in range(budget_units):
    marginal = {k: a * np.exp(-d * allocation[k]) for k, (a, d) in channels.items()}
    chosen = max(marginal, key=marginal.get)
    allocation[chosen] += 1
    gain[chosen] += marginal[chosen]
campaign = pd.DataFrame(
    {
        "investment_amount_ten_thousand_yen": {
            k: v * 10 for k, v in allocation.items()
        },
        "incremental_marginal_profit_ten_thousand_yen": gain,
    }
)
campaign["ROI"] = (
    campaign.incremental_marginal_profit_ten_thousand_yen
    - campaign.investment_amount_ten_thousand_yen
) / campaign.investment_amount_ten_thousand_yen
display(campaign)

fig, ax = plt.subplots(figsize=(7, 4))
campaign.investment_amount_ten_thousand_yen.plot.bar(ax=ax, color="#70AD47")
ax.set_title("Campaign budget allocation after optimization")
ax.set_xlabel("Campaign")
ax.set_ylabel("Investment Amount (10,000 yen)")
ax.grid(axis="y", alpha=0.3)
plt.xticks(rotation=0)
plt.tight_layout()
plt.show()
[OUT: 7]
investment_amount_ten_thousand_yen incremental_marginal_profit_ten_thousand_yen ROI
Exhibition 60 396.50 5.61
Technical Seminar 60 326.80 4.45
Sample Provision 60 281.18 3.69

No.055: Campaign Optimization — output

Reading the results

Rather than allocating the entire amount to a single measure based solely on initial efficiency, the marginal effects after diminishing are allocated to balance out. It is important that the coefficients are updated as incremental effects through experiments divided by region or customer group, rather than past correlations.

No.056: Coupon Design

Meaning in Practice

B2B coupons can be used for initial orders for maintenance parts, resuming dormant customers, transitioning to online ordering, and more. Incremental profit is evaluated including discounted existing demand (cannibalization).

Approach to Analysis and Modeling

Incremental profit from issuing coupons to customer ii

ΔΠi=(p−d−c)Pr⁡(Yi(1)=1)−(p−c)Pr⁡(Yi(0)=1)\Delta\Pi_i=(p-d-c)\Pr(Y_i(1)=1)-(p-c)\Pr(Y_i(0)=1)

After deducting distribution costs, only positive customers are targeted. In practice, we estimate two probability differences using the uplift model and randomized controlled trials.

Check with Python

[IN: 8]
coupon = pd.DataFrame(
    {
        "segment": [
            "High probability, low response",
            "Medium probability, high response",
            "Dormancy and Intermediate Reactions",
            "low gross margin",
        ],
        "p_without": [0.72, 0.35, 0.08, 0.28],
        "p_with": [0.76, 0.58, 0.22, 0.50],
        "price": [10_500, 10_500, 10_500, 8_000],
        "cost": [6_200, 6_200, 6_200, 6_900],
        "discount": [500, 500, 700, 500],
        "contact_cost": [80, 80, 120, 80],
    }
)
coupon["incremental_profit"] = (
    (coupon.price - coupon.discount - coupon.cost) * coupon.p_with
    - (coupon.price - coupon.cost) * coupon.p_without
    - coupon.contact_cost
)
coupon["send"] = coupon.incremental_profit > 0
display(coupon[["segment", "p_without", "p_with", "incremental_profit", "send"]])

fig, ax = plt.subplots(figsize=(8, 4))
colors = np.where(coupon.send, "#70AD47", "#C00000")
ax.bar(coupon.segment, coupon.incremental_profit, color=colors)
ax.axhline(0, color="black", linewidth=1)
ax.set_title("Incremental profit from segment-specific coupons")
ax.set_xlabel("Customer Segments")
ax.set_ylabel("Expected incremental profit per offer (JPY)")
ax.grid(axis="y", alpha=0.3)
plt.xticks(rotation=15)
plt.tight_layout()
plt.show()
[OUT: 8]
segment p_without p_with incremental_profit send
0 High probability, low response 0.72 0.76 -288.00 False
1 Medium probability, high response 0.35 0.58 619.00 True
2 Dormancy and Intermediate Reactions 0.08 0.22 328.00 True
3 low gross margin 0.28 0.50 -88.00 False

No.056: Coupon Design — output

Reading the results

Customers with a high purchase probability may receive a large discount on existing sales even if they respond, and may not be eligible for distribution. The key is to choose those whose coupons change behavior and generate profit, rather than those with high response rates.

No.057: Bandit Algorithm

Meaning in Practice

When trying multiple prices, fixed A/B testing will continue to deliver inefficient prices until the end. Multi-armed bandits sequentially adjust their search for learning and the use of good ideas at the moment.

Approach to Analysis and Modeling

Thompson sampling represents each price’s win probability with a Beta posterior, θk∼Beta(ak,bk)\theta_k\sim\mathrm{Beta}(a_k,b_k). Each round samples these probabilities and selects the price with the largest sampled probability times contribution per win. Apply this to comparable deals under consistent contract conditions.

Check with Python

[IN: 9]
prices = np.array([9_500, 10_500, 11_500])
cost = 6_200
true_conv = np.array([0.46, 0.39, 0.30])
a = np.ones(3)
b = np.ones(3)
counts = np.zeros(3, dtype=int)
rewards = np.zeros(3)
for _ in range(600):
    sampled_value = rng.beta(a, b) * (prices - cost)
    arm = int(np.argmax(sampled_value))
    won = rng.random() < true_conv[arm]
    a[arm] += won
    b[arm] += 1 - won
    counts[arm] += 1
    rewards[arm] += won * (prices[arm] - cost)
bandit = pd.DataFrame(
    {
        "price": prices,
        "trials": counts,
        "posterior_conversion": a / (a + b),
        "gross_profit": rewards,
    }
)
display(bandit)

fig, ax = plt.subplots(figsize=(7, 4))
ax.bar(bandit.price.astype(str), bandit.trials, color="#4472C4")
ax.set_title("Number of offers by price under Thompson sampling")
ax.set_xlabel("Suggested Price (yen)")
ax.set_ylabel("Number of offers")
ax.grid(axis="y", alpha=0.3)
plt.tight_layout()
plt.show()
[OUT: 9]
price trials posterior_conversion gross_profit
0 9500 153 0.47 237,600.00
1 10500 109 0.40 184,900.00
2 11500 338 0.31 545,900.00

No.057: Bandit Algorithm — output

Reading the results

In this run, JPY 11,500 receives the most offers: 338. However, the true expected contributions per offer are JPY 1,518, 1,677, and 1,590 at prices of JPY 9,500, 10,500, and 11,500, respectively. The algorithm therefore did not allocate most offers to the true best price. Finite samples and exploration can leave substantial allocation error.

No.058: Bayesian Optimization Concepts and a Simple Search Example

Meaning in Practice

Exhaustive price testing is impractical when each trial is expensive or slow. Bayesian optimization uses a probabilistic model of observed outcomes to select promising new prices with relatively few evaluations.

Approach to Analysis and Modeling

Bayesian optimization selects evaluations using a probabilistic model’s posterior mean and uncertainty. The following heuristic instead uses an RBF-weighted mean and distance from observed points. It does not compute a posterior distribution and is not Bayesian optimization itself. uncertainty is a distance-based exploration bonus, not a posterior standard deviation or credible interval.

Check with Python

[IN: 10]
grid = np.linspace(8_000, 14_000, 121)


def objective(p):
    q = 620 * (p / 10_000) ** -1.55
    return (p - 6_500) * q + rng.normal(0, 55_000)


observed_x = [8_000.0, 11_000.0, 14_000.0]
observed_y = [objective(x) for x in observed_x]
for _ in range(7):
    dist = (grid[:, None] - np.array(observed_x)[None, :]) / 900
    w = np.exp(-0.5 * dist**2) + 1e-9
    mean = (w @ np.array(observed_y)) / w.sum(axis=1)
    nearest = np.min(np.abs(grid[:, None] - np.array(observed_x)[None, :]), axis=1)
    uncertainty = 80_000 * (1 - np.exp(-nearest / 700))
    next_x = grid[np.argmax(mean + 1.4 * uncertainty)]
    observed_x.append(float(next_x))
    observed_y.append(objective(next_x))
bo = pd.DataFrame({"price": observed_x, "observed_profit": observed_y})
display(bo.round(0))

true_curve = (grid - 6_500) * 620 * (grid / 10_000) ** -1.55
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(grid, true_curve / 1e6, label="Underlying expected profit", color="#4472C4")
ax.scatter(
    bo.price,
    bo.observed_profit / 1e6,
    color="#C00000",
    label="Trial observations",
    zorder=3,
)
ax.set_title("Price Exploration Through Small-Scale Trials")
ax.set_xlabel("Price (JPY/unit)")
ax.set_ylabel("Monthly Marginal Profit (million yen)")
ax.grid(alpha=0.3)
ax.legend()
plt.tight_layout()
plt.show()
[OUT: 10]
price observed_profit
0 8,000.00 1,271,091.00
1 11,000.00 2,397,138.00
2 14,000.00 2,760,474.00
3 13,300.00 2,685,233.00
4 13,650.00 2,755,292.00
5 12,800.00 2,738,434.00
6 13,850.00 2,691,381.00
7 13,050.00 2,720,481.00
8 13,500.00 2,587,793.00
9 12,250.00 2,549,503.00

No.058: Bayesian Optimization Concepts and a Simple Search Example — output

Reading the results

From the initial point, attempts are tested in uncertain areas, gradually concentrating toward higher-profit price ranges. Since fewer trial points are influenced by model assumptions, price upper and lower limits, minimum order rates, and customer protection are defined as constraints in advance.

No.059: Reinforcement Learning

Meaning in Practice

If current prices affect future inventory, customer relationships, and learning, single-month optimization is insufficient. Reinforcement learning learns strategies that include future rewards, choosing actions based on the state.

Approach to Analysis and Modeling

The state is inventory, the action is price, and the reward is contribution minus holding and shortage penalties. Q-learning updates values as follows:

Q(s,a)←Q(s,a)+α[r+γmax⁡a′Q(s′,a′)−Q(s,a)]Q(s,a)\leftarrow Q(s,a)+\alpha[r+\gamma\max_{a'}Q(s',a')-Q(s,a)]

This update targets a continuing discounted task. The example resets the starting state after six training steps but still bootstraps at the last step; it is not a six-period finite-horizon problem. For a finite horizon, include time remaining in the state and set terminal continuation value to zero.

Check with Python

[IN: 11]
inventory_levels = np.arange(0, 701, 100)
rl_prices = np.array([9_000, 10_500, 12_000])
Q = np.zeros((len(inventory_levels), len(rl_prices)))
visits = np.zeros_like(Q, dtype=int)
alpha, gamma, epsilon = 0.12, 0.92, 0.15
for episode in range(5000):
    inv = 500
    for t in range(6):
        s = int(np.argmin(abs(inventory_levels - inv)))
        arm = rng.integers(3) if rng.random() < epsilon else int(np.argmax(Q[s]))
        p = rl_prices[arm]
        demand = max(0, int(rng.normal(110 * (p / 10_000) ** -1.6, 12)))
        sold = min(inv, demand)
        next_inv = min(700, inv - sold + 100)
        reward = (p - 6_200) * sold - 250 * next_inv - 1_500 * max(demand - inv, 0)
        ns = int(np.argmin(abs(inventory_levels - next_inv)))
        visits[s, arm] += 1
        Q[s, arm] += alpha * (reward + gamma * Q[ns].max() - Q[s, arm])
        inv = next_inv
policy = pd.DataFrame(
    {
        "inventory": inventory_levels,
        "recommended_price": rl_prices[np.argmax(Q, axis=1)],
    }
)
# An unvisited state has no learned recommendation.
policy["training_visits"] = visits.sum(axis=1)
policy.loc[policy.training_visits == 0, "recommended_price"] = np.nan
display(policy)

fig, ax = plt.subplots(figsize=(7, 4))
ax.step(policy.inventory, policy.recommended_price, where="mid", color="#7030A0")
ax.set_title("Recommended pricing strategies by learned inventory level")
ax.set_xlabel("Beginning inventory (units)")
ax.set_ylabel("Recommended price (JPY/unit)")
ax.grid(alpha=0.3)
plt.tight_layout()
plt.show()
[OUT: 11]
inventory recommended_price training_visits
0 0 NaN 0
1 100 NaN 0
2 200 NaN 0
3 300 9,000.00 58
4 400 12,000.00 2204
5 500 12,000.00 24177
6 600 10,500.00 3558
7 700 9,000.00 3

No.059: Reinforcement Learning — output

Reading the results

Training restarts from inventory 500 after every six steps, leaving some inventory states rarely or never visited. An all-zero Q row must not be interpreted as recommending the first price. We show visit counts and leave unvisited states without a recommendation. Even visited states require policy evaluation; this table does not establish that lower inventory implies a higher price.

No.060: Practical Application

Meaning in Practice

A pricing system also needs cost data, contract limits, sales exceptions, capacity plans, approval responsibilities, and outcome measurement. These determine how recommended prices can be used in daily operations.

Approach to Analysis and Modeling

In practice, we separate the group who set the suggested price and the group who verify based on operational constraints. It stores differences between recommended and adopted values, exception reasons, and track records, monitoring not only profits but also order rates, retention rates, supply compliance, and fairness. Start with decision support and gradually expand the scope of automation.

Check with Python

[IN: 12]
recommendations = pd.DataFrame(
    {
        "customer": [
            "AIndustry",
            "BWorkshop",
            "Cchemistry",
            "DPrecision machinery",
            "EMaterial",
        ],
        "segment": [
            "Large accounts",
            "Mid-sized accounts",
            "Small accounts",
            "Mid-sized accounts",
            "Large accounts",
        ],
        "model_price": [11_800, 11_200, 10_100, 11_500, 12_100],
        "contract_floor": [10_800, 10_500, 9_800, 10_700, 11_000],
        "contract_ceiling": [11_500, 11_400, 10_600, 11_300, 11_900],
        "capacity_risk": ["high", "low", "low", "middle", "high"],
    }
)
recommendations["guardrailed_price"] = recommendations.model_price.clip(
    lower=recommendations.contract_floor, upper=recommendations.contract_ceiling
)
recommendations["needs_approval"] = (
    recommendations.model_price != recommendations.guardrailed_price
) | recommendations.capacity_risk.eq("high")
display(recommendations)

kpi = pd.DataFrame(
    {
        "KPI": [
            "Contribution profit / capacity hour",
            "Order rate",
            "Recommended Adoption Rate",
            "price exception rate",
            "90-day retention rate",
        ],
        "Monitoring frequency": ["weekly", "weekly", "monthly", "monthly", "quarter"],
        "main person in charge": [
            "Accounting and Production",
            "Sales",
            "Sales Planning",
            "Sales Planning",
            "Sales",
        ],
    }
)
display(kpi)
[OUT: 12]
customer segment model_price contract_floor contract_ceiling capacity_risk guardrailed_price needs_approval
0 AIndustry Large accounts 11800 10800 11500 high 11500 True
1 BWorkshop Mid-sized accounts 11200 10500 11400 low 11200 False
2 Cchemistry Small accounts 10100 9800 10600 low 10100 False
3 DPrecision machinery Mid-sized accounts 11500 10700 11300 middle 11300 True
4 EMaterial Large accounts 12100 11000 11900 high 11900 True
KPI Monitoring frequency main person in charge
0 Contribution profit / capacity hour weekly Accounting and Production
1 Order rate weekly Sales
2 Recommended Adoption Rate monthly Sales Planning
3 price exception rate monthly Sales Planning
4 90-day retention rate quarter Sales

Reading the results

Model prices are adjusted at the upper and lower limits of the contract, and projects with high capability risk or those subject to adjustments are subject to approval. By starting from a model that “the model gathers the basis and people control the exception,” rather than “the model decides,” auditability and on-site acceptance can be achieved.

Practical Lessons

  1. It is necessary to connect price reaction estimations, customer value, cost, and capability to the same profit indicator.
  2. Static optimization is based on base pricing, Bandit and Bayesian optimization require limited learning, and reinforcement learning requires multi-period problems; this is important.
  3. Practical value lies in price ranges and guardrail designs that can withstand estimation errors rather than optimal values.
  4. Price is a promise to customers. Explainability, fairness, and contract compliance are treated alongside objective functions.

Implementation Requirements

  • Data: Quotation presentation, order receipt and cancellation, quantity, cost, customer attributes, contract, delivery date, and capability are connected by case ID.
  • verification: Create a price experiment with a limited target and a preliminary evaluation plan for incremental profit and retention rate
  • Business Design: Define upper and lower limits, change frequency, exemptions, approvers, and customer descriptions
  • System: Save recommended values, adoption values, reasons for overwriting, and achievements as a history
  • surveillance: Regularly monitor demand drift, profits, lost orders, unfair practices between segments, and complaints

Conclusion

Price optimization is not just a calculation of price increases. It is a decision-making system that measures demand, designs customer value, converts profits including supply constraints, and continues to learn safely. As a first step, it is practical to introduce static profit curves and price guardrails into sales meetings targeting one major product and one region.

Consultations for Corporations

At Surikobo, we support companies tailored to their data maturity, from estimating price elasticity, designing price and promotional experiments, optimizing profits, implementing them into sales processes, to training for personnel. You can consult with us from the stage of what can be verified with existing data.

📩 Contact Us: www.surikobo.co.jp/contact Please feel free to consult us first.