What the Deflator Says

GDP deflator · inflation rate · nominal GDP · real GDP · base year

The GDP deflator measures the price level of everything an economy produces. For year t and base year b:

\text{nominal}_t = \sum p_t q_t \qquad \text{real}_t = \sum p_b \, q_t \qquad \text{deflator}_t = 100 \cdot \frac{\text{nominal}_t}{\text{real}_t}

(the sums run over all goods). It is 100 in the base year, and the inflation rate it implies for year t is \text{deflator}_t / \text{deflator}_{t-1} - 1, as a fraction (0.05 means 5 %).

years lists consecutive calendar years in increasing order. data[good] is a list with one pair (price, quantity) per year, in the same order as years. base_year is one of the years (a calendar year, not a position).

Write deflator(years, data, base_year) that returns a pair (deflators, inflation): the deflator for every year, and the inflation rate for every year except the first.

Examples

Input:  years = [2040, 2041, 2042], base_year = 2041
        data = {"tea":   [(4, 50), (5, 60), (5, 80)],
                "cloth": [(20, 10), (22, 10), (25, 12)]}
Output: ([85.1063829787234, 100.0, 105.42168674698796],
         [0.17500000000000004, 0.054216867469879526])
Explanation: nominal GDP is 400, 520, 700. At 2041 prices the quantities are worth
470, 520, 664. So in 2040 the deflator is 100 * 400 / 470 = 85.1, and prices
rose 17.5 % into 2041.

Input:  years = [2050], data = {"salt": [(3, 7)]}, base_year = 2050
Output: ([100.0], [])

Constraints

  • every year at least one good has a positive quantity, so real GDP is never 0
  • floats are compared with a tolerance of 1e-6

Goals

  • Compute the GDP deflator as 100 times nominal over real GDP
  • Find the base year's position from its calendar year
  • Measure inflation as the growth rate of the deflator
Starting Python…