python - YFINANCE:检索更多ETF数据
问题描述
我正在使用yfinance API,并希望从 ETF 中检索更多数据,特别是特定 ETF 的行业权重 (%) ,可在 Yahoo 网站上的“ Holdings ”选项卡中找到: https ://finance.yahoo.com/quote /IWDA.AS/holdings?p=IWDA.AS
这在当前的 API 中可行吗?如果没有,有人知道我如何将其添加到 API 中吗?我猜它会在base.py
,但我不确定在哪里。欢迎所有帮助!
解决方案
虽然我没有与 yfinance 相关的答案,但您可以使用名为yahooquery的包来检索该数据。免责声明:我是包的作者。
from yahooquery import Ticker
t = Ticker('IWDA.AS')
# sector weightings, returns pandas DataFrame
t.fund_sector_weightings
IWDA.AS
0
realestate 0.0303
consumer_cyclical 0.1036
basic_materials 0.0411
consumer_defensive 0.0857
technology 0.1920
communication_services 0.0917
financial_services 0.1453
utilities 0.0329
industrials 0.1013
energy 0.0331
healthcare 0.1430
t.fund_holding_info
或者从整个页面中检索大部分数据:
t.fund_holding_info
{
'IWDA.AS': {
'maxAge': 1,
'stockPosition': 0.9959,
'bondPosition': 0.0,
'holdings': [{
'symbol': 'AAPL',
'holdingName': 'Apple Inc',
'holdingPercent': 0.038
}, {
'symbol': 'MSFT',
'holdingName': 'Microsoft Corp',
'holdingPercent': 0.035099998
}, {
'symbol': 'AMZN',
'holdingName': 'Amazon.com Inc',
'holdingPercent': 0.0278
}, {
'symbol': 'FB',
'holdingName': 'Facebook Inc A',
'holdingPercent': 0.012999999
}, {
'symbol': 'GOOG',
'holdingName': 'Alphabet Inc Class C',
'holdingPercent': 0.010299999
}, {
'symbol': 'GOOGL',
'holdingName': 'Alphabet Inc A',
'holdingPercent': 0.0101
}, {
'symbol': 'JNJ',
'holdingName': 'Johnson & Johnson',
'holdingPercent': 0.0088
}, {
'symbol': 'V',
'holdingName': 'Visa Inc Class A',
'holdingPercent': 0.007900001
}, {
'symbol': 'NESN',
'holdingName': 'Nestle SA',
'holdingPercent': 0.0078
}, {
'symbol': 'PG',
'holdingName': 'Procter & Gamble Co',
'holdingPercent': 0.0070999996
}],
'equityHoldings': {
'priceToEarnings': 20.47,
'priceToBook': 2.34,
'priceToSales': 1.62,
'priceToCashflow': 11.82
},
'bondHoldings': {},
'bondRatings': [{
'bb': 0.0
}, {
'aa': 0.0
}, {
'aaa': 0.0
}, {
'a': 0.0
}, {
'other': 0.0
}, {
'b': 0.0
}, {
'bbb': 0.0
}, {
'below_b': 0.0
}, {
'us_government': 0.0
}],
'sectorWeightings': [{
'realestate': 0.030299999
}, {
'consumer_cyclical': 0.103599995
}, {
'basic_materials': 0.041100003
}, {
'consumer_defensive': 0.0857
}, {
'technology': 0.192
}, {
'communication_services': 0.0917
}, {
'financial_services': 0.1453
}, {
'utilities': 0.032899998
}, {
'industrials': 0.1013
}, {
'energy': 0.033099998
}, {
'healthcare': 0.143
}]
}
}
您可以通过文档找到其他数据访问器。
推荐阅读
- design-patterns - 物理对象双缓冲
- python - Python - 如何填写网络表单然后下载生成的文件
- sql - 错误:18456,严重性:14,状态:38 原因:无法打开明确指定的数据库“ReportServer”。[客户:
] - html - HTMLElement.offsetTop 与静态父元素一起使用
- swift - 将 detailView 交换为不同的视图时,tableView 中的错误
- docker - 使用 docker-compose 为 AWS CodeBuild 创建自定义构建映像
- ruby-on-rails - Rails 中的多级数据库检索
- service - 当我已经用 Junit 测试了 Facade 时,是否有必要测试 DAO 类?
- python - 如何在 python 中解压使用 Swift 保存的二进制数据?
- javascript - 在 Reactjs 中管理状态时遇到问题