<jupyter_start><jupyter_text>Stationarity Test<jupyter_code>import pandas as pd
from pandas import read_csv
import numpy as np
from datetime import datetime
import matplotlib.pylab as plt
from statsmodels.tsa.stattools import adfuller
from pandas.plotting import autocorrelation_plot
from statsmodels.tsa.stattools import acf, pacf
import yfinance as yf
#tick = 'BVSP'
#stock = pd.read_html('https://br.financas.yahoo.com/quote/^%s/history?p=^%s' % (tick, tick))
#stock[0].head()
#BVSP = pd.DataFrame({'indice': stock[0]['Fechamento*'], 'day': stock[0]['Data']})
#BVSP.head()
#plt.figure(figsize=(15,9))
#plt.plot(BVSP['indice'].astype(float))
#plt.show()
DJI = yf.Ticker("DJI")
hist = DJI.history(period="5y")
hist.head()
plt.figure(figsize=(16,9))
plt.plot(hist['Close'])
plt.show()
def stationarity_test(timeseries):
    #Determing rolling statistics
    rolmean = timeseries.rolling(window=12).mean()
    rolstd = timeseries.rolling(window=12).std()

    #Plot rolling statistics:
    plt.figure(figsize=(16,9))
    orig = plt.plot(timeseries, color='blue',label='Original')
    mean = plt.plot(rolmean, color='red', label='Rolling Mean')
    std = plt.plot(rolstd, color='black', label = 'Rolling Std')
    plt.legend(loc='best')
    plt.title('Rolling Mean & Standard Deviation')
    plt.show(block=False)
stationarity_test(hist['Close'])
def difference(dataset, interval=1):
    index = list(dataset.index)
    diff = list()
    for i in range(interval, len(dataset)):
        value = dataset["Close"][i] - dataset["Close"][i - interval]
        diff.append(value)
    return (diff)
diff = difference(hist)
plt.figure(figsize=(16,9))
plt.plot(diff)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16568396226415094, 'fraction_numerical': 0.012382075471698114, 'mean_word_length': 5.477099236641221, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '567714', 'license': 'MIT', 'n_tokens_mistral': 624, 'n_tokens_neox': 596, 'n_words': 120, 'path': 'code/stationary_time-series_models/stationarity_test.ipynb', 'repo_name': 'danilodsp/econometric', 'size': '1696'}