""" Personal interest to see if bitcoin has seasonality. """ import os from statsmodels.graphics.tsaplots import plot_acf import pandas as pd import matplotlib.pyplot as plt from statsmodels.tsa.seasonal import STL # Chart config plt.rcParams["figure.figsize"] = (12, 6) # Ensure assets directory os.makedirs("assets", exist_ok=True) # Load solar data data = pd.read_csv( "../assets/btc_yearly.csv", parse_dates=["Date"], index_col="Date", thousands=",", converters={ "Change %": lambda x: float(x.rstrip("%")) / 100, "Vol.": lambda x: pd.to_numeric(x.replace("K", "000").replace("M", "000000").replace('B', '000000000') if x != '' else pd.NA), }, ) # cutoff = data.index.max() - pd.DateOffset(years=5) # pyright: ignore[reportOperatorIssue] # series = data["Price"] series = data["Price"].iloc[:365*8] # print(data['vol']) # Resample to daily series_daily = series.resample("D").sum() # Compute autocorrelation, acf = Auto Correlation Function # Compares against lags up to a year away # acf_scores = acf(x=series_daily, nlags=365) # Compute partial autocorrelation # pacf_scores = pacf(x=series_daily, nlags=365) # Convience functions to do math and plot plot_acf(series_daily, lags=365) plt.savefig("assets/btc_autocorrelation.png") result = STL(endog=series_daily, period=365).fit() result.plot() plt.savefig("assets/btc_stl_decomposition.png") # plot_pacf(series_daily, lags=365) # plt.savefig("assets/partion_autocorrelation.png")