I have a script that keep messing up and I am not sure what the source is. It seems to work sometimes and not others. Here is an example.
In [29]: pricesEquities=financialMarketPrices['equities'].dropna(axis[0,1],how='all'))
In [30]: pricesEquities.head()
Out[30]:
aud cad chf eur gbp inr jpy sek \
date
2003-01-01 3007.1 6614.54 4630.8 2386.41 3940.4 1100.15 843.29 493.20
2003-01-02 3027.6 6740.05 4630.8 2522.24 4009.5 1093.05 843.29 514.79
2003-01-03 3055.5 6772.66 4899.5 2502.19 4004.9 1089.60 843.29 519.75
2003-01-06 3075.4 6837.27 4916.2 2529.86 4001.4 1084.35 860.07 519.75
2003-01-07 3074.5 6802.78 4887.0 2504.91 3957.4 1081.80 853.93 518.66
usd
date
2003-01-01 879.82
2003-01-02 909.03
2003-01-03 908.59
2003-01-06 929.01
2003-01-07 922.93
In [31]: returnsEquities = pricesEquities.pct_change().iloc[1:]
In [32]: returnsEquities.head()
Out [32]: aud cad chf eur gbp inr jpy sek usd
date
2003-01-02 -1 414.00 NaN 189.23 NaN 145.11 NaN 210.13 NaN
2003-01-03 NaN NaN NaN NaN 0 NaN NaN 217.26 NaN
2003-01-06 NaN NaN NaN NaN 0 NaN 0 NaN 65.33
2003-01-07 NaN 436.00 NaN 191.79 0 146.50 0 NaN 60.63
2003-01-08 NaN 452.67 NaN 188.93 0 147.43 0 214.14 59.13
This is very strange and I honestly have no idea what the source of error might be. The percent change function seems to be the source of it and it works sometimes and not others seemingly at random. Has anyone else dealt with something like this before? Is there anything under the hood or unstable about my code? It also messes up elsewhere in the code, but this is the most simple of returns calculations and it still messes up. Does anyone have any idea what is going on?