Feb-21-2020, 11:23 PM
(This post was last modified: Feb-21-2020, 11:24 PM by new_to_python.)
Hi, somebody mentioned that one could use ts/ts.shift(1)-1 to calculate the percent changes in a time series. I tried to understand this by hand calculating the percent changes on 2000-04-30. I got -3.1619163378849615 instead of -1.462553 using the formula. Have I done something wrong? I though percent changes is (new value - old value)/old value *100%.
In [91]: ts Out[91]: 2000-01-31 -0.047169 2000-02-29 0.636350 2000-03-31 1.207707 2000-04-30 -0.558628 Freq: M, dtype: float64 In [92]: ts.shift(1) Out[92]: 2000-01-31 NaN 2000-02-29 -0.047169 2000-03-31 0.636350 2000-04-30 1.207707 Freq: M, dtype: float64 In [93]: ts/ts.shift(1)-1 Out[93]: 2000-01-31 NaN 2000-02-29 -14.490780 2000-03-31 0.897866 2000-04-30 -1.462553 Freq: M, dtype: float64 In [94]: In [94]: (1.207707+0.558628)/(-0.558628) Out[94]: -3.1619163378849615