首页 > 解决方案 > 从投资包中提取收益率数据

问题描述

我有兴趣使用investpypython 包从investing.com 网站提取收益率曲线数据(特别对南非的收益率感兴趣,网址为https://za.investing.com/rates-bonds/south-africa-government-bonds为了手动构建收益率曲线)。

该软件包的文档提供了一些如何提取指数或股票数据的示例,如下所示,但是没有关于通过哪些参数来提取利率/收益率数据的信息。寻找有关如何调整以下代码的解决方案,以便将每个收益率到期的历史系列提取到数据框中

import investpy

df = investpy.get_stock_historical_data(stock='AAPL',
                                        country='United States',
                                        from_date='01/01/2010',
                                        to_date='01/01/2020')
print(df.head())

标签: python

解决方案


要使用下载债券收益率数据investpy,请尝试以下代码,该代码专门针对您的需要进行了调整

import investpy
data = investpy.bonds.get_bond_historical_data(bond='South Africa 2Y',
                                               from_date='01/01/2019',
                                               to_date='31/12/2019')
data[:10]

请注意,与美国和英国相关的债券的国家代码分别为“US”和“UK”。


推荐阅读