In [1]:
import load_data, plots
import pandas as pd
from matplotlib import pyplot as plt
import statsmodels.api as sm
In [2]:
data= load_data.load_data()
plots.plot_data(data)
In [10]:
value = data['usd-blue-lanacion'].keys()[0]
In [11]:
value?
In [3]:
df = pd.DataFrame(data)
In [19]:
df['usd-bna/buy'].describe()
Out[19]:
In [20]:
df['usd-bna/buy'].plot()
Out[20]:
In [21]:
df['usd-bna/buy'].hist()
Out[21]:
In [22]:
df['usd-bna/buy'].apply(np.log10).hist()
Out[22]:
In [4]:
serie = df['usd-bna/buy']
In [31]:
pd.stats.moments.rolling_mean(serie, 1).plot()
Out[31]:
In [33]:
pd.stats.moments.rolling_mean(serie.apply(np.log10), 2).plot()
Out[33]:
In [35]:
(serie/serie.shift(1)).plot()
Out[35]:
In [50]:
(serie/serie.shift(1)).hist(bins=50)
Out[50]:
In [41]:
(serie/serie.shift(30)).plot()
Out[41]:
In [42]:
(serie/serie.shift(360)).plot()
Out[42]:
In [49]:
(serie/serie.shift(30)).hist(bins=50)
Out[49]:
In [46]:
(serie/serie.shift(5)).plot()
Out[46]:
In [54]:
fig = (serie/serie.shift(5)).hist(bins=50)
fig.set_title('a')
Out[54]:
In [64]:
for i in [5, 30, 360]:
f, (ax1, ax2) = plt.subplots(2)
ax1.hist((serie/serie.shift(i)).dropna(), bins=50)
ax1.set_title('cada %d dias' % i)
ax2.plot((serie/serie.shift(i)).dropna())
ax2.set_title('cada %d dias' % i)
f.savefig('plot-%d.pdf' % i, format = 'pdf')
In [57]:
plt.plot((serie/serie.shift(i)).dropna())
Out[57]:
In [67]:
for i in [5, 30, 360]:
f, (ax1, ax2) = plt.subplots(2)
ax1.hist((serie/serie.shift(i)).apply(np.log10).dropna(), bins=50)
ax1.set_title('cada %d dias' % i)
ax2.plot((serie/serie.shift(i)).apply(np.log10).dropna())
ax2.set_title('cada %d dias' % i)
In [5]:
def difference(serie, shift):
return serie/serie.shift(i)
In [69]:
for i in [5, 30, 360]:
f, (ax1, ax2) = plt.subplots(2)
ax1.hist(difference(serie, i).dropna(), bins=50)
ax1.set_title('cada %d dias' % i)
ax2.plot(difference(serie, i).dropna())
ax2.set_title('cada %d dias' % i)
In [70]:
for i in [5, 30, 360]:
f, (ax1, ax2) = plt.subplots(2)
ax1.hist(difference(difference(serie, i), i).dropna(), bins=50)
ax1.set_title('cada %d dias' % i)
ax2.plot(difference(difference(serie, i), i).dropna())
ax2.set_title('cada %d dias' % i)
In [7]:
logged = serie.apply(np.log10)
In [73]:
(logged - logged.shift(1)).plot()
Out[73]:
In [6]:
df1 = lambda x, t=1: x - x.shift(t)
In [82]:
df1(logged, 5).plot()
Out[82]:
In [84]:
df1(df1(logged, 5), 5).plot()
Out[84]:
In [79]:
df1(df1(df1(logged))).hist()
Out[79]:
In [29]:
log_diff = df1(df1(logged, 5), 5)
In [32]:
arma_mod = sm.tsa.ARMA(log_diff.dropna(),order=(2,2), freq='D')
In [33]:
arma_res = arma_mod.fit()
In [99]:
arma_res.fittedvalues.plot()
Out[99]:
In [104]:
forecast = arma_res.forecast(100)[0]
In [108]:
arima = sm.tsa.ARMA(logged.dropna(), order = (2,2,2), freq='D')
In [111]:
df1(df1(logged, 30), 30).plot()
Out[111]:
In [17]:
sm.graphics.tsa.plot_acf(df1(df1(logged, 5), 5).dropna(), lags=10)
Out[17]:
In [18]:
sm.graphics.tsa.plot_pacf(df1(df1(logged, 5), 5).dropna(), lags=10)
Out[18]:
In [22]:
sm.graphics.tsa.plot_acf(df1(df1(df1(logged, 5), 5), 5).dropna(), lags=20)
Out[22]:
In [26]:
sm.graphics.tsa.plot_acf(df1(logged, 5).dropna(), lags=20)
Out[26]:
In [27]:
sm.graphics.tsa.plot_pacf(df1(logged, 5).dropna(), lags=20)
Out[27]:
In [36]:
sm.graphics.tsa.plot_pacf(logged.dropna(), lags=20)
Out[36]:
In [38]:
sm.graphics.tsa.plot_acf(logged.dropna(), lags=100)
Out[38]:
In [46]:
sm.graphics.tsa.plot_acf(df1(df1(logged, 5), 5).dropna(), lags=30)
sm.graphics.tsa.plot_pacf(df1(df1(logged, 5), 5).dropna(), lags=30)
Out[46]:
In [47]:
sm.graphics.tsa.plot_acf(logged.dropna(), lags=100)
sm.graphics.tsa.plot_pacf(logged.dropna(), lags=100)
Out[47]:
In [51]:
df1(df1(logged, 5), 5).hist(bins=40)
Out[51]:
In [49]:
df1(df1(logged, 5), 5).plot()
Out[49]:
In [ ]: