import yfinance as yf
import pandas as pd
from datetime import datetime, timedelta

# 获取当前日期
end_date = datetime.today().strftime('%Y-%m-%d')

# 获取十年前的日期
start_date = (datetime.today() - timedelta(days=365*10)).strftime('%Y-%m-%d')

# 下载 AAPL 股票数据
data = yf.download('AAPL', start=start_date, end=end_date)

# 将数据保存为 CSV 文件
data.to_csv('AAPL.csv')

print(f"Downloaded AAPL stock data from {start_date} to {end_date} and saved to AAPL.csv")