在我使用InvestPy包时,我可以使用内置的函数' get _ stock _historical_ data‘轻松地获取股票报价器数据。但在试图获取Nifty50索引数据时却没有同样的运气,例如。快速查看函数)中所有可用的印度代码,就会发现与索引无关.
他们有办法用这个包裹吗?我的选择是为索引做网络抓取。在官方文档这里中找不到任何相关的东西。
发布于 2020-12-16 13:56:17
investpy实现了几种方法来收集有关索引的信息。不幸的是,我找不到任何函数来返回索引的每个成员的性能,但是您可以,例如,获取有关索引的历史数据:
df = investpy.get_index_historical_data(index="Nifty 50",
country="India",
from_date='01/01/2018',
to_date='01/01/2019') Open High Low Close Volume Currency
Date
2018-01-01 10531.70 10537.85 10423.10 10435.55 134532000 INR
2018-01-02 10477.55 10495.20 10404.65 10442.20 158092000 INR
2018-01-03 10482.65 10503.60 10429.55 10443.20 172516992 INR
2018-01-04 10469.40 10513.00 10441.45 10504.80 180256992 INR
2018-01-05 10534.25 10566.10 10520.10 10558.85 186470000 INR
... ... ... ... ... ... ...
2018-12-26 10635.45 10747.50 10534.55 10729.85 271943 INR
2018-12-27 10817.90 10834.20 10764.45 10779.80 470160 INR
2018-12-28 10820.95 10893.60 10817.15 10859.90 253087 INR
2018-12-31 10913.20 10923.55 10853.20 10862.55 186495 INR
2019-01-01 10881.70 10923.60 10807.10 10910.10 159405 INR
[247 rows x 6 columns]关于Index Data Retrieval的更多信息可以在文档这里中找到。
您还可以检索某一国家所有股票的列表:
df = investpy.get_stocks_list(country="india") # returns 'list'
df = investpy.get_stocks(country="india") # returns 'pandas.DataFrame' (shown below) country name ... currency symbol
0 india Aditya Birla Capital ... INR ADTB
1 india Hubtown ... INR HUBT
2 india 3i Infotech ... INR TIIN
3 india 3M India ... INR TMIN
4 india ABB India ... INR ABB
... ... ... ... ... ...
1706 india G K P Printing ... INR GKPP
1707 india Vivid Mercantile ... INR VIVD
1708 india White Organic ... INR WHIE
1709 india Parshva Enterprises ... INR PAHV
1710 india SK International Export ... INR SKIN
[1711 rows x 6 columns]因为investpy没有提供某种东西来获取某一指数的所有股票,所以你必须自己整理它们。幸运的是,investpy确实为您提供了一些函数,这些函数允许您获取有关特定索引的最近、历史等数据(上面提到过)。如果您正在寻找每种股票的数据,您可以:
编辑
您提到了无法找到MSCI Emerging Markets的数据,这是一个world索引。不幸的是,我无法将world指定为一个国家。我不知道这背后的原因是什么,但我确实深入到源代码中去找出发生了什么:
结果表明,world索引确实存在于investpy/resources/indices.csv中,但它们在index_countries_as_list()中被过滤掉,因为world country不存在于investpy/utils/constants.py中的变量INDEX_COUNTRIES中。您可能希望提交一个问题这里。下面是我能够验证MSCIEF是否存在的几件事,但我不确定是否有办法获取有关该索引的数据。
investpy.indices.get_indices_dict(country=None, columns=None, as_json=False){'country': 'world', 'name': 'MSCI Emerging Markets', 'full_name': 'MSCI Emerging Markets', 'symbol': 'MSCIEF', 'currency': 'USD', 'class': 'other_indices', 'market': 'global_indices'}以及:
investpy.indices.search_indices(by="name", value="MSCI Emerging Markets") country name ... class market
0 world MSCI Emerging Markets ... other_indices global_indices
[1 rows x 7 columns]发布于 2022-04-30 08:51:09
关于摩根士丹利资本国际新兴市场(MSCIEF)未被发现的部分:
它可以通过投资公司的SearchObj界面找到。下面是如何使用包装包泰莎
from tessa import search, price_history
r = search("MSCIEF")
# Find the object that fits what you're looking for
prices, currency = price_history('{"id_": 101764, "name": "MSCI Emerging Markets", "symbol": "MSCIEF", "country": "worldFlag", "tag": "/indices/msci-emerging-markets", "pair_type": "indices", "exchange": "Global Indexes"}', "searchobj")https://stackoverflow.com/questions/65323421
复制相似问题