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

如何为彭博xbbg API的bdh接口添加交易日及排序参数

你传入的参数不生效是因为xbbg对接彭博API时对参数大小写敏感,且部分参数的命名规则和Excel BDH的简写习惯有差异,正确设置方式如下:

1. 交易日过滤(对应Excel days=a)

Excel里的days=a功能对应参数为Days='A',注意参数名首字母大写,参数值为大写A,小写写法无法被识别。

2. 日期降序排序(对应Excel Sort=D)

Excel里的Sort=D功能对应参数为sort='D',注意参数名全小写,参数值为大写D,首字母大写的Sort无法生效。

修改后可用代码

import pandas as pd
import arrow
from xbbg import blp

now = arrow.now()
today = str(now.format('YYYYMMDD'))
today_minus_one_year = str(now.shift(days=-365).format('YYYYMMDD'))
start_date = today_minus_one_year

Security = 'AAPL US Equity'
period = 90
Select_interval = 'D'
delta = 25

df_call = blp.bdh(
    [Security],
    ['PX_LAST','IVOL_Delta','VOLUME_TOTAL_CALL'],
    start_date=start_date,
    end_date=today,
    IVOL_DELTA_LEVEL='DELTA_LVL_'+str(delta),
    IVOL_MATURITY='MATURITY_'+str(period)+str(Select_interval),
    IVOL_DELTA_PUT_OR_CALL='IVOL_CALL',
    Days='A',
    sort='D'
)

兼容老版本xbbg的写法

如果你使用的是较早版本的xbbg,上述直接传参的方式不生效,可以将参数放到overrides字典中传入:

df_call = blp.bdh(
    [Security],
    ['PX_LAST','IVOL_Delta','VOLUME_TOTAL_CALL'],
    start_date=start_date,
    end_date=today,
    IVOL_DELTA_LEVEL='DELTA_LVL_'+str(delta),
    IVOL_MATURITY='MATURITY_'+str(period)+str(Select_interval),
    IVOL_DELTA_PUT_OR_CALL='IVOL_CALL',
    overrides={
        'Days': 'A',
        'Sort': 'D'
    }
)

内容的提问来源于stack exchange,提问作者Jørgen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 04:57:04