AFAIK,您无法更改yfinance 设置以获得每周数据,该数据的范围是周五到周五。
但是,您可以下载每日数据并手动重新采样以满足您的需要。
如果您只对调整后的收盘价感兴趣,则可以使用 Pandas 的 resample 函数。
df=yf.download("^NSEI", start="2020-11-30", end="2022-02-27")
df_daily_close = df.loc[:, "Adj Close"]
df_weekly_close = df_daily_close.resample("W-FRI").last()
如果您想对 OHLCV 价格重新采样,您可以使用 aggregate 函数和 resample 函数。聚合函数允许您将不同的函数应用于数据框中的不同列。
# Remove the `Close` column as we are using `Adj Close`
df_daily_ohlcv = df.drop("Close", axis=1)
# Define a dictionary with the functions to apply to each column
functions = {"Open": "first", "High": "max", "Low": "min", "Adj Close": "last", "Volume": "sum"}
# Resample
df_weekly_ohlcv = df.resample('W-FRI').aggregate(functions)