pdblp.BCon.bdh 用法。插入一个数组作为 "list" 参数
pdblp.BCon.bdh usage. inserting an array as the "list" argument
con.bdh
的用法是 con.bdh('SPY US Equity', ['PX_LAST', 'VOLUME'],
'20150629', '20150630', longdata=True)
我想获取 PX_LAST
和 VOLUME
数组中的证券列表(带代码的字符串)。当我尝试用数组 "arrtickers" 或 [list(arrtickers)] 替换 SPY US Equity 时,出现以下错误:
...eidData[] = {
}
sequenceNumber = 0
securityError = {
source = "3920::bbdbh4"
code = 15
category = "BAD_SEC"
message = "Security key is too longInvalid Security [nid:3920] "
subcategory = "INVALID_SECURITY"
}
fieldExceptions[] = {
}
fieldData[] = {
}}}
我使用的语法正确吗?
没有发布 reproducible example 这只是一个猜测,但正如您代码段中的错误消息所暗示的那样,这可能是因为您正在查询无效的证券。数组语法应该有效。例如以下工作正常
In [1]: import pdblp
...: con = pdblp.BCon().start()
...: con.bdh(['SPY US Equity', 'IBM US Equity'], ['PX_LAST', 'VOLUME'],
'20150629', '20150630', longdata=True)
Out[1]
date ticker field value
0 2015-06-29 SPY US Equity PX_LAST 2.054200e+02
1 2015-06-29 SPY US Equity VOLUME 2.026213e+08
2 2015-06-30 SPY US Equity PX_LAST 2.058500e+02
3 2015-06-30 SPY US Equity VOLUME 1.829251e+08
4 2015-06-29 IBM US Equity PX_LAST 1.629700e+02
5 2015-06-29 IBM US Equity VOLUME 3.314684e+06
6 2015-06-30 IBM US Equity PX_LAST 1.626600e+02
7 2015-06-30 IBM US Equity VOLUME 3.597288e+06
而这不会
In [2]: con.bdh(['SPY US Equity', 'NOT_A_SECURITY Equity'], ['PX_LAST', 'VOLUME'],
'20150629', '20150630', longdata=True)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-f23344f8a6b3> in <module>()
----> 1 con.bdh(['SPY US Equity', 'NOT_A_SECURITY Equity'], ['PX_LAST', 'VOLUME'], '20150629', '20150630', longdata=True)
~/Projects/pdblp/pdblp/pdblp.py in bdh(self, tickers, flds, start_date, end_date, elms, ovrds, longdata)
268
269 data = self._bdh_list(tickers, flds, start_date, end_date,
--> 270 elms, ovrds)
271
272 df = pd.DataFrame(data, columns=["date", "ticker", "field", "value"])
~/Projects/pdblp/pdblp/pdblp.py in _bdh_list(self, tickers, flds, start_date, end_date, elms, ovrds)
305 .numValues() > 0)
306 if has_security_error or has_field_exception:
--> 307 raise ValueError(msg)
308 ticker = (msg.getElement('securityData')
309 .getElement('security').getValue())
ValueError: HistoricalDataResponse = {
securityData = {
security = "NOT_A_SECURITY Equity"
eidData[] = {
}
sequenceNumber = 1
securityError = {
source = "139::bbdbh3"
code = 15
category = "BAD_SEC"
message = "Unknown/Invalid securityInvalid Security [nid:139] "
subcategory = "INVALID_SECURITY"
}
fieldExceptions[] = {
}
fieldData[] = {
}
}
}
感谢@mgilbert。我最终创建了一个列表并将所有代码添加到该列表中。
con.bdh
的用法是 con.bdh('SPY US Equity', ['PX_LAST', 'VOLUME'],
'20150629', '20150630', longdata=True)
我想获取 PX_LAST
和 VOLUME
数组中的证券列表(带代码的字符串)。当我尝试用数组 "arrtickers" 或 [list(arrtickers)] 替换 SPY US Equity 时,出现以下错误:
...eidData[] = {
}
sequenceNumber = 0
securityError = {
source = "3920::bbdbh4"
code = 15
category = "BAD_SEC"
message = "Security key is too longInvalid Security [nid:3920] "
subcategory = "INVALID_SECURITY"
}
fieldExceptions[] = {
}
fieldData[] = {
}}}
我使用的语法正确吗?
没有发布 reproducible example 这只是一个猜测,但正如您代码段中的错误消息所暗示的那样,这可能是因为您正在查询无效的证券。数组语法应该有效。例如以下工作正常
In [1]: import pdblp
...: con = pdblp.BCon().start()
...: con.bdh(['SPY US Equity', 'IBM US Equity'], ['PX_LAST', 'VOLUME'],
'20150629', '20150630', longdata=True)
Out[1]
date ticker field value
0 2015-06-29 SPY US Equity PX_LAST 2.054200e+02
1 2015-06-29 SPY US Equity VOLUME 2.026213e+08
2 2015-06-30 SPY US Equity PX_LAST 2.058500e+02
3 2015-06-30 SPY US Equity VOLUME 1.829251e+08
4 2015-06-29 IBM US Equity PX_LAST 1.629700e+02
5 2015-06-29 IBM US Equity VOLUME 3.314684e+06
6 2015-06-30 IBM US Equity PX_LAST 1.626600e+02
7 2015-06-30 IBM US Equity VOLUME 3.597288e+06
而这不会
In [2]: con.bdh(['SPY US Equity', 'NOT_A_SECURITY Equity'], ['PX_LAST', 'VOLUME'],
'20150629', '20150630', longdata=True)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-f23344f8a6b3> in <module>()
----> 1 con.bdh(['SPY US Equity', 'NOT_A_SECURITY Equity'], ['PX_LAST', 'VOLUME'], '20150629', '20150630', longdata=True)
~/Projects/pdblp/pdblp/pdblp.py in bdh(self, tickers, flds, start_date, end_date, elms, ovrds, longdata)
268
269 data = self._bdh_list(tickers, flds, start_date, end_date,
--> 270 elms, ovrds)
271
272 df = pd.DataFrame(data, columns=["date", "ticker", "field", "value"])
~/Projects/pdblp/pdblp/pdblp.py in _bdh_list(self, tickers, flds, start_date, end_date, elms, ovrds)
305 .numValues() > 0)
306 if has_security_error or has_field_exception:
--> 307 raise ValueError(msg)
308 ticker = (msg.getElement('securityData')
309 .getElement('security').getValue())
ValueError: HistoricalDataResponse = {
securityData = {
security = "NOT_A_SECURITY Equity"
eidData[] = {
}
sequenceNumber = 1
securityError = {
source = "139::bbdbh3"
code = 15
category = "BAD_SEC"
message = "Unknown/Invalid securityInvalid Security [nid:139] "
subcategory = "INVALID_SECURITY"
}
fieldExceptions[] = {
}
fieldData[] = {
}
}
}
感谢@mgilbert。我最终创建了一个列表并将所有代码添加到该列表中。