1

我有一份带有 ISIN 和 WKN-Number 的股票清单。我的目标是使用 pandas_datareader 现在从该股票中获取历史数据。我的问题是,功能例如

import pandas_datareader as web

stock = web.DataReader('ALB', data_source="yahoo", start="01.01.2021", end="30.10.2021")

只能使用股票代码。是否有某种方法(可能是其他库)来解决该问题或某种算法将数字转换为股票代码?

4

1 回答 1

1

至少对于ISIN,您可以使用函数,该函数返回一个pandas.DataFrame ,其中包含(以及其他信息)该ISIN 代码的符号investpy stocks.search_stocks

import investpy

df = investpy.stocks.search_stocks(by='isin', value='US0126531013')
print(df)
#          country       name              full_name          isin currency symbol
# 0         mexico  Albemarle         Albemarle Corp  US0126531013      MXN    ALB
# 1  united states  Albemarle         Albemarle Corp  US0126531013      USD    ALB
# 2        germany  Albemarle  Albemarle Corporation  US0126531013      EUR   ALLE
from pandas_datareader import data as pdr

symbol = df.loc[df['country']=='united states','symbol'].values[0]
print(symbol) # ALB

stock = pdr.DataReader(symbol, data_source="yahoo", start="2021-01-01", end="2021-10-30")
print(stock.head())
                  Open        High         Low       Close   Adj Close   Volume
Date
2021-01-04  152.899994  156.759995  150.289993  152.630005  151.645477  2898700
2021-01-05  152.669998  166.779999  152.669998  162.929993  161.879028  2628000
2021-01-06  165.500000  178.589996  165.500000  175.100006  173.970535  3335500
2021-01-07  183.479996  187.250000  180.550003  184.000000  182.813126  2947800
2021-01-08  184.490005  186.929993  178.660004  184.100006  182.912491  1659400
于 2021-12-05T15:53:57.700 回答