Home > Enterprise >  Calculate year-over-year growth rate based on month-over-month's
Calculate year-over-year growth rate based on month-over-month's

Time:09-29

Given a dataset as follows:

[{'date': '2017-01', 'CPI': 242.839, 'MoM%': nan, 'YoY%': nan},
 {'date': '2017-02', 'CPI': 243.603, 'MoM%': 0.0031, 'YoY%': nan},
 {'date': '2017-03', 'CPI': 243.801, 'MoM%': 0.0008, 'YoY%': nan},
 {'date': '2017-04', 'CPI': 244.524, 'MoM%': 0.003, 'YoY%': nan},
 {'date': '2017-05', 'CPI': 244.733, 'MoM%': 0.0009, 'YoY%': nan},
 {'date': '2017-06', 'CPI': 244.955, 'MoM%': 0.0009, 'YoY%': nan},
 {'date': '2017-07', 'CPI': 244.786, 'MoM%': -0.0007, 'YoY%': nan},
 {'date': '2017-08', 'CPI': 245.519, 'MoM%': 0.003, 'YoY%': nan},
 {'date': '2017-09', 'CPI': 246.819, 'MoM%': 0.0053, 'YoY%': nan},
 {'date': '2017-10', 'CPI': 246.663, 'MoM%': -0.0006, 'YoY%': nan},
 {'date': '2017-11', 'CPI': 246.669, 'MoM%': 0.0, 'YoY%': nan},
 {'date': '2017-12', 'CPI': 246.524, 'MoM%': -0.0006, 'YoY%': nan},
 {'date': '2018-01', 'CPI': 247.867, 'MoM%': 0.0054, 'YoY%': 0.0207},
 {'date': '2018-02', 'CPI': 248.991, 'MoM%': 0.0045, 'YoY%': 0.0221},
 {'date': '2018-03', 'CPI': 249.554, 'MoM%': 0.0023, 'YoY%': 0.0236},
 {'date': '2018-04', 'CPI': 250.546, 'MoM%': 0.004, 'YoY%': 0.0246},
 {'date': '2018-05', 'CPI': 251.588, 'MoM%': 0.0042, 'YoY%': 0.028},
 {'date': '2018-06', 'CPI': 251.989, 'MoM%': 0.0016, 'YoY%': 0.0287},
 {'date': '2018-07', 'CPI': 252.006, 'MoM%': 0.0001, 'YoY%': 0.0295},
 {'date': '2018-08', 'CPI': 252.146, 'MoM%': 0.0006, 'YoY%': 0.027},
 {'date': '2018-09', 'CPI': 252.439, 'MoM%': 0.0012, 'YoY%': 0.0228},
 {'date': '2018-10', 'CPI': 252.885, 'MoM%': 0.0018, 'YoY%': 0.0252},
 {'date': '2018-11', 'CPI': 252.038, 'MoM%': -0.0033, 'YoY%': 0.0218},
 {'date': '2018-12', 'CPI': 251.233, 'MoM%': -0.0032, 'YoY%': 0.0191},
 {'date': '2019-01', 'CPI': 251.712, 'MoM%': 0.0019, 'YoY%': 0.0155}]

Let's say CPI column is unknown to us, is it possible to calculate year-over-year growth rate based on month-over-month's, and vice versa in Python?

Reference:

https://www.econ.iastate.edu/ask-an-economist/cpi-and-inflation-relationship-between-mom-and-yoy-values

CodePudding user response:

Yes, you can calculate YoY growth from MoM growth by a rolling (12 periods) product assuming you have no months missing in your data. But it's likely you will accumulate some error due to the rounding you already have in MoM calculation:

df['MoM%'].add(1).rolling(12).apply(lambda x: x.prod()) - 1

0          NaN
1          NaN
2          NaN
3          NaN
4          NaN
5          NaN
6          NaN
7          NaN
8          NaN
9          NaN
10         NaN
11         NaN
12    0.020667
13    0.022091
14    0.023623
15    0.024644
16    0.028022
17    0.028741
18    0.029564
19    0.027101
20    0.022912
21    0.025368
22    0.021985
23    0.019326
24    0.015777
Name: MoM%, dtype: float64

It will be more accurate if MoM was not rounded:

mom_no_rounding = df['CPI'] / df['CPI'].shift() - 1
mom_no_rounding.add(1).rolling(12).apply(lambda x: x.prod()) - 1

0          NaN
1          NaN
2          NaN
3          NaN
4          NaN
5          NaN
6          NaN
7          NaN
8          NaN
9          NaN
10         NaN
11         NaN
12    0.020705
13    0.022118
14    0.023597
15    0.024627
16    0.028010
17    0.028715
18    0.029495
19    0.026992
20    0.022770
21    0.025225
22    0.021766
23    0.019102
24    0.015512
Name: CPI, dtype: float64
  • Related