Pandas Pct_change Gives Slightly Different Answers To Manual
Can anyone explain why the pct_change function gives slightly different numbers when using the more manual calculation: pct_change function: print(prices) 0
Solution 1:
Problem is second formula is wrong:
prices = pd.DataFrame({0:[1035.23,1032.47]})
print (prices)
print(prices.pct_change(1))
0
0 NaN
1 -0.002666
print(prices/(prices.shift())-1)
0
0 NaN
1 -0.002666
As pointed Andrew L in comment:
print((prices - prices.shift(1))/prices.shift(1))
0
0 NaN
1 -0.002666
Post a Comment for "Pandas Pct_change Gives Slightly Different Answers To Manual"