tia bbg python - 覆盖“#N / A字段不适用”

问题描述 投票:1回答:2

我正在尝试使用get_attributes请求字段,但它会为不适用的任何内容返回FieldError(例如,请求非股息支付股票的除息日期)。

FieldError: (BRK/B US Equity, DVD_EX_DT, BAD_FLD, Field not applicable to security) 

是否已经覆盖了这种情况,或者我必须迭代每个股票代码然后合并?

import tia.bbg.datamgr as dm
mgr = dm.BbgDataManager()
sids_index = mgr[TICKERS]
bloomberg_fields =  ['BEST_DIV_YLD',  # Forward Dividend Yield
                     'DVD_EX_DT',  # Ex-Dividend Date
                     'EXPECTED_REPORT_DT',  # Next Earnings Call Date
                     'GROSS_MARGIN',  # Gross Margin
                     'OPER_MARGIN',  # Operating Margin
                     'PROF_MARGIN']  # Profit Margin
df_data = sids_index.get_attributes(bloomberg_fields, OVERRIDE)
python bloomberg
2个回答
1
投票

您可以尝试使用以下几行的xbbg包:

from xbbg import blp

blp.bdp(
    tickers=[
        'BRK/B US Equity', 'C US Equity'
    ],
    flds=[
        'Best_Div_Yld', 'DVD_Ex_Dt', 'Expected_Report_Dt',
        'Gross_Margin', 'Oper_Margin', 'Prof_Margin',
    ]
)

输出:

             ticker               field       value
0   BRK/B US Equity        Best_Div_Yld         -  
1   BRK/B US Equity           DVD_Ex_Dt         NaN
2   BRK/B US Equity  Expected_Report_Dt  2019-02-25
3   BRK/B US Equity        Gross_Margin       18.37
4   BRK/B US Equity         Oper_Margin       10.86
5   BRK/B US Equity         Prof_Margin       18.56
6       C US Equity        Best_Div_Yld        2.96
7       C US Equity           DVD_Ex_Dt  2018-11-02
8       C US Equity  Expected_Report_Dt  2019-01-14
9       C US Equity        Gross_Margin         NaN
10      C US Equity         Oper_Margin       31.86
11      C US Equity         Prof_Margin       -7.73

1
投票

我发现以下覆盖:

LocalTerminal.get_reference_data(tk, flds, ignore_field_error=1, ignore_security_error=1)

然后输出生成为nan或nat

© www.soinside.com 2019 - 2024. All rights reserved.