[英]How to get data from Bloomberg Python API?
如何通过Python获得特别现金? 在 BLQ 中,它适用于
=BQL("6592 JP Equity","dropna(CASH_DIVS(DIVIDEND_TYPE=SPECIAL))","dates=range(1y,0d)","showdates=y")
目前 Excel 中的 BQL 接口无法直接通过 Python 获得。 There are clunky workarounds (driving Excel from Python and running the function in a spreadsheet), but in this case the information is accessible via the 'old school' data API, using Bulk Data (in the same way as the =BDS(...)
Excel 中的 function)。
DAPI 的第一个障碍是确定您想要的字段的名称(因为它们不一定与 BQL 使用的那些匹配),以及任何覆盖的名称。 在彭博终端 window 中键入6592 JP Equity FLDS Go
以查看所有可用数据字段,然后可以对其进行搜索:
股息历史 - 现金的字段是DVD_HIST
如果单击 DVD_HIST,您将获得该字段的完整描述以及可以应用的任何覆盖。 在这种情况下,需要的覆盖是DVD_START_DT
。
有了这些信息,您可以使用任何您喜欢的 Python package 来访问彭博数据。 我的偏好是xbbg
,但也可以使用其他软件包。 如果您还没有安装 Bloomberg API,您需要先从这里安装它。
Bloomberg DAPI 不提供对dividend_type
类型的覆盖,因此您必须拉回所有行并自己过滤它们:
from xbbg import blp
from datetime import datetime,timedelta
#Find start date
dt = datetime.today() - timedelta(days=365)
#Get all cash dividends after DVD_START_DT in a DataFrame
dfAll = blp.bds('6592 JP Equity','DVD_HIST',DVD_START_DT=dt.strftime('%Y%m%d'))
#Filter DataFrame for rows with dividend_type=='Special Cash'
dfSpecial = dfAll[dfAll['dividend_type'] == 'Special Cash']
print(dfSpecial)
返回:
declared_date ex_date record_date payable_date dividend_amount dividend_frequency dividend_type
6592 JP Equity 2021-02-12 2021-12-29 2021-12-31 None 43.0 Semi-Anl Special Cash
6592 JP Equity 2021-02-12 2021-06-29 2021-06-30 2021-09-13 42.0 Semi-Anl Special Cash
6592 JP Equity 2020-02-13 2020-12-29 2020-12-31 2021-03-31 53.0 Semi-Anl Special Cash
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.