gpt4 book ai didi

yql - 如何以编程方式获取 ETF 的持有量

转载 作者:行者123 更新时间:2023-12-05 06:45:06 25 4
gpt4 key购买 nike

我正在寻找一种方法来获取 ETF 的持有列表通过网络服务,如雅虎财经。到目前为止,YQL 还没有产生预期的结果。

例如,ZUB.TO 是一种持有股票的 ETF。这是 holdings 的列表通过查询 yahoo.finance.quotes 我们没有得到正确的 information . The result.

在某处是否有另一个表可以包含这些馆藏?

最佳答案

可能无法从 Yahoo Finance 下载和/或可能无法正常工作。

如何使用 ETF 提供商已有的各种 API 来下载持有的 Excel 或 CSV 文件?

使用“append_df_to_excel”文件作为导入文件,然后使用下面的代码为SSgA(State Street global Advisors)提供的所有11个Sector SPDR制作Excel文件。

我个人用它来做广度分析

import pandas as pd
import append_to_excel
# https://stackoverflow.com/questions/20219254/how-to-write-to-an-existing-excel-file-without-overwriting-data-using-pandas

##############################################################################
# Author: Salil Gangal
# Posted on: 08-JUL-2018
# Forum: Stack Overflow
##############################################################################

output_file = 'C:\my_python\SPDR_Holdings.xlsx'
base_url = "http://www.sectorspdr.com/sectorspdr/IDCO.Client.Spdrs.Holdings/Export/ExportExcel?symbol="

data = {
'Ticker' : [ 'XLC','XLY','XLP','XLE','XLF','XLV','XLI','XLB','XLRE','XLK','XLU' ]
, 'Name' : [ 'Communication Services','Consumer Discretionary','Consumer Staples','Energy','Financials','Health Care','Industrials','Materials','Real Estate','Technology','Utilities' ]
}

spdr_df = pd.DataFrame(data)

print(spdr_df)

for i, row in spdr_df.iterrows():
url = base_url + row['Ticker']
df_url = pd.read_excel(url)
header = df_url.iloc[0]
holdings_df = df_url[1:]
holdings_df.set_axis(header, axis='columns', inplace=True)
print("\n\n", row['Ticker'] , "\n")
print(holdings_df)
append_df_to_excel(output_file, holdings_df, sheet_name= row['Ticker'], index=False)

Image of Excel file generated for SPDRs

关于yql - 如何以编程方式获取 ETF 的持有量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26185884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com