Table of Contents
Introduction
What is Paasche’s Index Number?
Real-World Scenario: Online Grocery Basket Inflation
Time and Space Complexity Analysis
Complete Implementation with Test Cases
Best Practices and Insights
Conclusion
Introduction
In a world where prices are changing rapidly, economists, data scientists, and even everyday consumers often need to measure how much more (or less) it costs to buy the same set of goods over time.
One of the most widely used tools for this is the Paasche’s Price Index Number. In this article, we’ll learn how to calculate it in Python, apply it to a real-time scenario, and verify our implementation with test cases.
What is Paasche’s Index Number?
Paasche’s Index measures the relative cost of a basket of goods, using current-period quantities as weights.
![c]()
Where:
p0p_0p0 = base period prices
p1p_1p1 = current period prices
q1q_1q1 = current period quantities
Unlike Laspeyres’ index, which fixes weights at the base year, Paasche’s reflects current consumer behavior, making it more realistic for modern markets.
Real-World Scenario: Online Grocery Basket Inflation
Imagine you regularly order groceries online. Your current basket includes different quantities of milk, rice, fruits, and vegetables compared to last year.
Last year’s prices (base) are p0p_0p0.
Today’s prices (current) are p1p_1p1.
The number of items you’re actually buying today are q1q_1q1.
Paasche’s Index will tell you how much more expensive your current basket is compared to last year’s basket prices.
Time and Space Complexity Analysis
Time Complexity: O(n), where n = number of goods
Space Complexity: O(1), since we only keep track of sums
Efficient for both small and large datasets.
Complete Implementation with Test Cases
from typing import List
import unittest
def paasche_index(
base_prices: List[float],
current_prices: List[float],
current_quantities: List[float]
) -> float:
"""
Calculate Paasche’s Price Index Number.
Formula:
P = (Σ p1*q1) / (Σ p0*q1) * 100
"""
if not (base_prices and current_prices and current_quantities):
raise ValueError("All input lists must be non-empty")
if not (len(base_prices) == len(current_prices) == len(current_quantities)):
raise ValueError("All lists must have the same length")
numerator = sum(p1 * q1 for p1, q1 in zip(current_prices, current_quantities))
denominator = sum(p0 * q1 for p0, q1 in zip(base_prices, current_quantities))
if denominator == 0:
raise ValueError("Denominator (Σ p0*q1) cannot be zero")
return round((numerator / denominator) * 100, 2)
class TestPaascheIndex(unittest.TestCase):
def test_grocery_example(self):
base_p = [50, 40, 30, 60] # last year prices
curr_p = [55, 42, 35, 70] # today prices
curr_q = [2, 5, 3, 1] # today quantities
index = paasche_index(base_p, curr_p, curr_q)
# Expected value corrected to 110.0 (495 / 450 * 100)
self.assertAlmostEqual(index, 110.0, places=2)
def test_no_change(self):
prices = [10, 20, 30]
qty = [2, 3, 1]
self.assertEqual(paasche_index(prices, prices, qty), 100.0)
def test_error_cases(self):
with self.assertRaises(ValueError):
paasche_index([], [1], [1])
with self.assertRaises(ValueError):
paasche_index([1, 2], [2, 3], [1])
with self.assertRaises(ValueError):
# Denominator: (0*5) = 0
paasche_index([0], [1], [5])
if __name__ == "__main__":
# Example usage: Online Grocery Basket
base_prices = [50, 40, 30, 60] # last year
current_prices = [55, 42, 35, 70] # today
current_quantities = [2, 5, 3, 1] # today’s basket
index = paasche_index(base_prices, current_prices, current_quantities)
print("=== Online Grocery Basket Inflation Tracker ===")
print(f"Paasche’s Index: {index}")
if index > 100:
print(f"→ Your basket costs {index - 100:.2f}% more today compared to last year!")
elif index < 100:
print(f"→ Your basket costs {100 - index:.2f}% less today compared to last year!")
else:
print("→ No change in overall cost.")
unittest.main(argv=[''], exit=False, verbosity=2)
![qw]()
Best Practices and Insights
Always check input lengths before computation to avoid mismatched errors.
Interpret results carefully: Paasche’s Index reflects current consumption patterns, so it adapts well to real-life consumer behavior.
Use unit tests to ensure accuracy across different scenarios.
Conclusion
Paasche’s Index is a powerful tool to measure how current consumption costs compare to the base period. In our online grocery example, it shows how much more we’re paying for the same basket today compared to last year. Whether you’re analyzing inflation, energy costs, or even subscription services, Paasche’s Index helps bring realistic and practical insights into how price changes impact daily life.