首页 > 解决方案 > 在 Python 中使用 blpapiwrapper 通过 BDH() 检索日内数据

问题描述

我正在尝试使用 blpapiwrapper( https://github.com/alex314159/blpapiwrapper )在特定时间获取股票价格,并从中获得灵感(https://quant.stackexchange.com/questions/35126/price- at-specific-time-from-bloomberg ):

=BDH("EURGBP Curncy","Last Price","7/13/2017 3:00:00 PM","7/13/2017 3:00:01 PM","BarTp=T,BarSz=1,Fill=P")

如果我尝试重新创建它,我会得到 EOD 价格,而不是 15:40:00 到 15:40:01 之间的最后价格。在具有相同 SEDOL 和日期的 Excel 中使用相同的语法会在 15:40 给出正确的股票价格。

bloomberg = BLP()

startdate = datetime.datetime.strptime('2020-01-03 15:40:00', '%Y-%m-%d %H:%M:%S')
enddate = datetime.datetime.strptime('2020-01-03 15:40:01', '%Y-%m-%d %H:%M:%S')

bloomberg.bdh('/SEDOL1/B151P43 Equity', "Last price",startdate, enddate , "BarTp = T, BarSz = 1, Fill = P")

我试图修改 blpapiwrapper 中的 bdh() 函数,将周期更改为“INTRADAY”,并在“startDate”和“endDate”的定义中包含“%H:%M:%S”,但没有运气。

def bdh(self, strSecurity='SPX Index', strData='PX_LAST', startdate=datetime.date(2014, 1, 1),
        enddate=datetime.date(2014, 1, 9), adjustmentSplit=False, periodicity='DAILY'):
    request = self.refDataSvc.createRequest('HistoricalDataRequest')
    request.append('securities', strSecurity)
    if type(strData) == str:
        strData = [strData]

    for strD in strData:
        request.append('fields', strD)

    request.set('startDate', startdate.strftime('%Y%m%d'))
    request.set('endDate', enddate.strftime('%Y%m%d'))
    request.set('adjustmentSplit', 'TRUE' if adjustmentSplit else 'FALSE')
    request.set('periodicitySelection', periodicity)
    requestID = self.session.sendRequest(request)

对于使用 blpapiwrapper 的解决方案有什么建议吗?

标签: pythonblpapi

解决方案


推荐阅读