我使用下面Python代码中的yfinance包获取LGEN.L(Legal&;General,一家在伦敦证券交易所上市超过100年的公司)5年的每日价格数据。结果是下面的第一个图
然后我进入雅虎财经网站,查找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()
该代码给出了以下数字:
雅虎财经数据:
雅虎网站显示了严格的收盘价,而你已经绘制了调整后的收盘价。因此,时间越晚,它们的分歧就越大
使用
相关问题 更多 >
编程相关推荐