You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Python重写Bloomberg blp.bdp获取YAS_BOND_PX(利差调整)

使用Bloomberg YAS_BOND_PX字段时覆盖参数返回无数据的问题

尝试通过Bloomberg的YAS_BOND_PX字段计算利差调整为75bps后的债券价格,复现YAS界面功能。无覆盖参数时可正常获取基础数据,但使用{'YAS_YLD_SPREAD': '75'}等覆盖参数调用blp.bdp获取YAS_BOND_PX时,均返回无数据错误。

测试代码

from xbbg import blp

# Define the bond ticker and desired spread
ticker = 'BH922181 Corp'

# Fetch basic price data without overrides
base_data = blp.bdp(tickers=ticker, flds='PX_LAST')
base_data2 = blp.bdp(tickers=ticker, flds='YAS_BOND_PX')
print("Base Data:")
print(base_data)
print(base_data2)

# Try other similar overrides or fields related to yield spread
overrides_list = [
    {'YAS_YLD_SPREAD': '75'},  # Original attempt
    {'YAS_O_SPREAD': '75'},    # Trying an OAS override for price impact
    {'YAS_BNCHMRK_YLD_PREC': '75'},  # Changing yield precision
]

# Test fetching data with different overrides
for overrides in overrides_list:
    try:
        print(f"\nAttempting fetch with overrides: {overrides}")
        
        # Fetch bond price with override
        data = blp.bdp(tickers=ticker, flds='YAS_BOND_PX', overrides=overrides)

        # Check and print result
        if data.empty:
            raise ValueError(f"No data returned for the given ticker with overrides: {overrides}. Please check your Bloomberg connection.")

        print(f"Price with Override {overrides}:")
        print(data)

    except Exception as e:
        print(f"Error fetching bond price with override {overrides}: {e}")

错误信息

Base Data:
px_last BH922181 Corp 86.36
yas_bond_px BH922181 Corp 86.3595

Attempting fetch with overrides: {'YAS_YLD_SPREAD': '75'} Error fetching bond price with override {'YAS_YLD_SPREAD': '75'}: No data returned for the given ticker with overrides: {'YAS_YLD_SPREAD': '75'}.

Attempting fetch with overrides: {'YAS_O_SPREAD': '75'} Error fetching bond price with override {'YAS_O_SPREAD': '75'}: No data returned for the given ticker with overrides: {'YAS_O_SPREAD': '75'}.

Attempting fetch with overrides: {'YAS_BNCHMRK_YLD_PREC': '75'} Error fetching bond price with override {'YAS_BNCHMRK_YLD_PREC': '75'}: No data returned for the given ticker with overrides: {'YAS_BNCHMRK_YLD_PREC': '75'}.


排查方向与解决方法

1. 验证覆盖参数的正确性

  • 字段名确认:在Bloomberg终端输入FLDS YAS_BOND_PX,查看该字段支持的官方覆盖参数名称,避免使用错误字段(比如确认YAS_YLD_SPREAD是否为合法参数)。
  • 参数格式调整:将参数值从字符串'75'改为数字75,Bloomberg API部分覆盖参数要求传入数值类型而非字符串。修改后的测试列表示例:
    overrides_list = [
        {'YAS_YLD_SPREAD': 75},
        {'YAS_O_SPREAD': 75},
    ]
    

2. 检查权限与模型兼容性

  • 权限验证:联系Bloomberg客服确认账号是否拥有YAS模块的自定义利差计算权限,部分高级YAS功能需要额外授权。
  • 债券兼容性:换用流动性较好、明确支持YAS模型的活跃债券(如US03076KAA06 Corp)测试,排除目标债券不支持YAS利差调整的可能性。

3. 排查xbbg封装问题

  • 原生API测试:尝试使用原生blpapi直接调用,确认是否为xbbg的参数传递逻辑导致问题。示例代码片段:
    import blpapi
    
    session = blpapi.Session()
    session.start()
    session.openService('//blp/refdata')
    
    request = session.createRequest('ReferenceDataRequest')
    request.append('securities', 'BH922181 Corp')
    request.append('fields', 'YAS_BOND_PX')
    override = request.getElement('overrides').appendElement()
    override.setElement('fieldId', 'YAS_YLD_SPREAD')
    override.setElement('value', 75)
    
    session.sendRequest(request)
    # 处理响应逻辑...
    
  • 版本更新:确保使用最新版本的xbbg,旧版本可能存在覆盖参数传递的bug。

内容的提问来源于stack exchange,提问作者BlueElement

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 02:50:00