python - 从投资包中提取收益率数据
问题描述
我有兴趣使用investpy
python 包从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())
解决方案
要使用下载债券收益率数据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”。
推荐阅读
- elasticsearch - ElasticSearch Filebeat 输出到现有索引
- powershell - 我可以提取哪些 Active Directory 用户被手动禁用以及哪些用户的帐户过期的报告吗?
- javascript - 为什么在我的 javascript (Vue) 代码中将对象属性标记为只读?
- r - 您如何绘制仅部分按时间顺序排列的数据?
- php - 如何一次保存整个 XML 节点?
- react-native - 在 React Native 中检测 SvgText 的所有边框
- sql - 多列的 SQL MAX 并检索每一行
- python - 过滤列表的百分比 - Sqlalchemy
- r - 如何使用 R 根据 group_by cols 和时间戳计算平均响应时间和总响应时间?
- pine-script - 在不满足条件的情况下触发警报 - 你能帮忙吗?需要 pinescript 帮助