Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import statsmodels.tsa.stattools as ts
- import statsmodels.graphics.tsaplots
- import statsmodels.api as sm
- import matplotlib.pyplot as plt
- def data_reader(file):
- data = pd.read_excel(file, skiprows=10)
- return data
- def augdfuller():
- data = data_reader('CSUSHPISA.xls')
- print(ts.adfuller(data['CSUSHPISA'], maxlag=1))
- def arima():
- data = data_reader('CSUSHPISA.xls')
- diff = data['CSUSHPISA'] - data['CSUSHPISA'].shift()
- diff = data['CSUSHPISA']
- fig = plt.figure(figsize=(12, 8))
- ax1 = fig.add_subplot(311)
- fig = statsmodels.graphics.tsaplots.plot_acf(diff, lags=200, ax=ax1)
- ax2 = fig.add_subplot(312)
- fig = statsmodels.graphics.tsaplots.plot_pacf(diff, lags=200, ax=ax2)
- ax3 = fig.add_subplot(313)
- fig = plt.plot(diff)
- plt.show()
- def arma():
- from statsmodels.tsa.arima_model import _arma_predict_out_of_sample
- data = data_reader('CSUSHPISA.xls')
- diff = data['CSUSHPISA'] - data['CSUSHPISA'].shift()
- diff = data['CSUSHPISA']
- res = sm.tsa.ARMA(diff.values, (1, 0)).fit()
- params = res.params
- residuals = res.resid
- p = res.k_ar
- q = res.k_ma
- k_exog = res.k_exog
- k_trend = res.k_trend
- steps = 4
- print(_arma_predict_out_of_sample(params, steps, residuals, p, q, k_trend, k_exog, endog=diff.values, exog=None,
- start=len(diff.values)))
- def main():
- print('Adfuller tests : \n')
- augdfuller()
- print('Arima model : \n')
- arima()
- print('Arma model : \n')
- arma_x = arma()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement