import yfinance as yf
import pandas as pd
from statsmodels.tsa.arima.model import ARIMA
import matplotlib.pyplot as plt
apple_stock = yf.download('AAPL', start='2023-01-01', end='2024-01-01')
dates = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D')
apple_stock.index = pd.DatetimeIndex(apple_stock.index).normalize()
apple_stock = apple_stock.reindex(dates, method='ffill')
closing_prices = apple_stock['Close']
[*********************100%%**********************] 1 of 1 completed
"""
参数优化对于ARIMA模型的性能至关重要。
理想的参数(p, d, q)能够最准确地捕捉到时间序列数据的特性,从而提高预测的准确性。
一种自动化寻找最佳ARIMA模型参数的方法是使用pmdarima库中的auto_arima函数。
这个函数通过遍历不同的参数组合,选择出最佳的模型
"""
closing_prices = closing_prices.ffill()
closing_prices = closing_prices.bfill()