Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Profit-Aware Price Optimization with Demand Modeling

This project turns historical product sales data into pricing recommendations by combining demand diagnostics, model validation, constrained price optimization, and experiment rollout planning.

The goal is not only to predict demand, but to translate demand patterns into profit-aware pricing decisions that can be tested under realistic business guardrails.

Business question

What price should each product use to maximize expected profit while avoiding unrealistic extrapolation outside the observed product-level pricing range?

Project value

This project is designed as an end-to-end pricing analytics workflow:

  • Diagnoses product-level price sensitivity before optimization.
  • Compares baseline and nonlinear demand models before using predictions for decisions.
  • Converts predicted demand into expected profit instead of optimizing quantity or revenue alone.
  • Uses price guardrails to avoid unrealistic model extrapolation.
  • Extends the core workflow with segment-specific pricing, discount strategy simulation, robust optimization, and A/B test rollout planning.

Key results

  • Analyzed 2,800 historical sales records across 6 products, 5 customer segments, and 4 discount bands.

  • Identified strong profit concentration, with products such as Paseo and Velo contributing the largest profit pools.

  • Found that aggressive discounting can increase volume but damage profitability. Several high-discount groups generated negative profit, showing that discount strategy should be evaluated by margin and expected profit rather than quantity alone.

  • Compared Ridge Regression, Random Forest, and Gradient Boosting demand models. Random Forest was selected for the optimization layer with the lowest SMAPE of approximately 25.60%.

  • Built a constrained product-level price optimization framework using a ±15% price-change guardrail and observed product-level price ranges.

  • Identified high-value pricing opportunities, including:

    • Carretera: recommended price 18.36 vs current median 15.96, expected profit uplift around 102.07%.
    • Paseo: recommended price 48.28 vs current median 41.98, expected profit uplift around 75.79%.
    • Velo: recommended price 31.46 vs current median 27.36, expected profit uplift around 74.73%.
  • Added bootstrap-based robust optimization to reduce overconfidence from a single fitted model.

  • Designed an A/B test rollout plan using smaller first-step price increases, limited treatment exposure, profit-per-order as the primary metric, and quantity, revenue, and margin rate as guardrail metrics.

Methodology

1. Data preparation

  • Standardized column names.
  • Filled missing discount values as No Discount.
  • Derived revenue, unit cost, estimated profit, unit profit, margin rate, and log-transformed price and quantity fields.
  • Excluded raw data from GitHub to keep the repository reproducible without exposing the dataset.

2. Exploratory analysis

The analysis starts with business-oriented diagnostics:

  • Product-level profit concentration.
  • Price vs. quantity patterns by product.
  • Discount-level profit behavior.
  • Product-level price elasticity using log-log regression.

These steps help identify whether the pricing problem should be modeled globally or with product-specific behavior.

3. Demand modeling

The notebook compares three demand models:

  • Ridge Regression baseline
  • Random Forest
  • Gradient Boosting

The final optimization uses the best-performing model based on SMAPE and other prediction metrics.

4. Profit-aware price optimization

For each product, the project searches over a constrained price grid and calculates:

Expected Profit = (Recommended Price - Estimated Unit Cost) × Predicted Quantity

The optimization is constrained by:

  • observed product-level price ranges
  • a ±15% price-change guardrail from the current median price

This prevents the model from recommending unrealistic prices outside the historical pricing context.

5. Extensions

The project includes four practical extensions:

Extension A: Segment-specific pricing

Tests whether the same product should have different pricing recommendations across customer segments.

Extension B: Discount strategy simulation

Evaluates discount bands by predicted profit instead of volume uplift alone.

Extension C: Robust optimization

Uses bootstrap modelling to identify price recommendations that remain stable across repeated model samples.

Extension D: A/B test rollout plan

Translates model recommendations into a controlled pricing experiment with smaller first-step price changes, limited treatment exposure, and business guardrails.

Project structure

pricing-profit-optimization/
├── data/
│   ├── raw/                  # put financial_sample2.xlsx here; do not commit data
│   └── processed/
├── notebooks/
│   └── 01_pricing_optimization_storytelling.ipynb
├── src/
│   ├── config.py
│   ├── data_prep.py
│   ├── extensions.py
│   ├── modeling.py
│   ├── optimization.py
│   └── visualization.py
├── reports/
│   ├── figures/
│   └── tables/
├── requirements.txt
├── .gitignore
└── README.md

Setup

python -m venv .venv

# Windows PowerShell
.\.venv\Scripts\Activate.ps1

# macOS/Linux
source .venv/bin/activate

pip install -r requirements.txt
python -m ipykernel install --user --name pricing-profit-optimization --display-name "pricing-profit-optimization"

Place the dataset here:

data/raw/financial_sample2.xlsx

Then open and run:

notebooks/01_pricing_optimization_storytelling.ipynb

Outputs

The notebook generates:

reports/
├── figures/
│   ├── total_profit_by_product.png
│   ├── price_vs_quantity_by_product.png
│   ├── elasticity_by_product.png
│   ├── model_comparison_smape.png
│   ├── profit_curve_<product>.png
│   └── extension_C_robust_profit_curve_<product>.png
└── tables/
    ├── data_quality_summary.csv
    ├── product_summary.csv
    ├── discount_summary.csv
    ├── elasticity_by_product.csv
    ├── model_comparison.csv
    ├── price_optimization_recommendations.csv
    ├── extension_A_segment_specific_pricing.csv
    ├── extension_B_discount_strategy_simulation.csv
    ├── extension_C_robust_price_recommendations.csv
    └── extension_D_ab_test_rollout_plan.csv

Notes on data and GitHub

The raw dataset is excluded from GitHub via .gitignore.

Do not commit:

data/raw/
data/processed/
.venv/
__pycache__/
.ipynb_checkpoints/

Commit only code, notebooks, generated figures, tables, and documentation.

About

Profit-aware pricing optimization with demand modeling, price elasticity analysis, constrained price search, and A/B test rollout planning.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

Contributors

Languages