yfinance 和 yahoo finance 数据差别很大
yfinance and yahoo finance data are very different
我在下面的 Python 代码中使用 yfinance 包来获取 LGEN.L 5 年的每日价格数据(Legal & General,一家在伦敦证券交易所上市超过 100 年的公司).结果就是下面第一张图
然后我去雅虎财经网站查找 LGEN.L 然后点击 5 年按钮:见下面第二张图(注意:如果你从其他资源查找股价,你会得到非常相似的个人资料)
虽然最近的数据(两个图的右侧)在 280 左右匹配,但较旧的数据(两个图的左侧)不匹配:yfinance 数据从 150 左右开始,而 yfinance 数据从 210 左右开始;巨大的差异
我做错了什么?
Python代码:
import yfinance as yf
import matplotlib.pyplot as plt
isin = "LGEN.L"
# Extract 5 years of daily data
df = yf.download(tickers=isin, period="5y", interval="1d", auto_adjust=True, prepost=False)
print(df)
#Extract time index
indx = df.index.to_numpy()
indx = indx.astype(str)
indx = [elem[:16] for elem in indx]
indx = [elem.replace(" ", "T") for elem in indx]
# Extract price (as average of openPrice, highPrice, lowPrice and closePrice
openPrice = df['Open'].to_numpy()
highPrice = df['High'].to_numpy()
lowPrice = df['Low'].to_numpy()
closePrice = df['Close'].to_numpy()
price = (openPrice + highPrice + lowPrice + closePrice) / 4.0
for i in range(len(openPrice)): print(indx[i] + ' / ' + str(price[i]))
# Plot
fig = plt.scatter(indx, price)
plt.title(isin)
plt.show()
这段代码给出了这个数字:
雅虎财经人物:
yahoo 网站显示的是严格的收盘价,而您绘制的是调整后的收盘价。所以时间越往后,它们的差异就越大。
使用
df = yf.download(tickers=isin, period="5y", interval="1d", auto_adjust=False, prepost=False)
我在下面的 Python 代码中使用 yfinance 包来获取 LGEN.L 5 年的每日价格数据(Legal & General,一家在伦敦证券交易所上市超过 100 年的公司).结果就是下面第一张图
然后我去雅虎财经网站查找 LGEN.L 然后点击 5 年按钮:见下面第二张图(注意:如果你从其他资源查找股价,你会得到非常相似的个人资料)
虽然最近的数据(两个图的右侧)在 280 左右匹配,但较旧的数据(两个图的左侧)不匹配:yfinance 数据从 150 左右开始,而 yfinance 数据从 210 左右开始;巨大的差异
我做错了什么?
Python代码:
import yfinance as yf
import matplotlib.pyplot as plt
isin = "LGEN.L"
# Extract 5 years of daily data
df = yf.download(tickers=isin, period="5y", interval="1d", auto_adjust=True, prepost=False)
print(df)
#Extract time index
indx = df.index.to_numpy()
indx = indx.astype(str)
indx = [elem[:16] for elem in indx]
indx = [elem.replace(" ", "T") for elem in indx]
# Extract price (as average of openPrice, highPrice, lowPrice and closePrice
openPrice = df['Open'].to_numpy()
highPrice = df['High'].to_numpy()
lowPrice = df['Low'].to_numpy()
closePrice = df['Close'].to_numpy()
price = (openPrice + highPrice + lowPrice + closePrice) / 4.0
for i in range(len(openPrice)): print(indx[i] + ' / ' + str(price[i]))
# Plot
fig = plt.scatter(indx, price)
plt.title(isin)
plt.show()
这段代码给出了这个数字:
雅虎财经人物:
yahoo 网站显示的是严格的收盘价,而您绘制的是调整后的收盘价。所以时间越往后,它们的差异就越大。
使用
df = yf.download(tickers=isin, period="5y", interval="1d", auto_adjust=False, prepost=False)