'can only join iterable' 使用 tia.bbg.datamgr 获取数据时 (Python 2.7)
'can only join iterable' when fetching data using tia.bbg.datamgr (Python 2.7)
我正在编写一个脚本,使用 TIA 工具包从 Bloomberg 获取数据。我正在尝试将 start
日期中 stocks
中每个股票的 PX_VALUE
放在名为 dict1
的字典中,以便我以后可以操纵这些值。
到目前为止,这是我的脚本,没有计算:
from __future__ import division
import numpy as np
import pandas as pd
import datetime
import tia
import tia.bbg.datamgr as dm
from operator import itemgetter
start = datetime.date(2017, 1, 3)
end = datetime.date(2017, 7, 25)
diffdays = ((end - start).days)/365
resolution = 0.01
diff2dp = int(np.round(diffdays/resolution))*resolution
diff = 1/diff2dp
dict1 = {}
stocks = ('GOOGL US Equity','MSFT US Equity', 'IBM US Equity')
mgr = dm.BbgDataManager()
eqt = mgr[stocks]
for eq in eqt:
df = eq.get_historical(['PX_LAST'], start, end)
k = df.loc[start]['PX_LAST']
dict1 [stocks] = k
print dict1
这里是实际的输出:
Traceback (most recent call last):
File "C:\Users\bloomberg\Desktop\examples\CAGR by LouisV2 BROKEN.py", line 23, in <module>
for eq in eqt:
File "C:\Python27\lib\site-packages\tia\bbg\datamgr.py", line 94, in __getitem__
return self.get_attributes(flds, **self.overrides)
File "C:\Python27\lib\site-packages\tia\bbg\datamgr.py", line 90, in get_attributes
frame = self.mgr.get_attributes(self.sids, flds, **overrides)
File "C:\Python27\lib\site-packages\tia\bbg\datamgr.py", line 148, in get_attributes
return self.terminal.get_reference_data(sids, flds, **overrides).as_frame()
File "C:\Python27\lib\site-packages\tia\bbg\v3api.py", line 745, in get_reference_data
return self.execute(req)
File "C:\Python27\lib\site-packages\tia\bbg\v3api.py", line 711, in execute
self.logger.info('executing request: %s' % repr(request))
File "C:\Python27\lib\site-packages\tia\bbg\v3api.py", line 432, in __repr__
fields=','.join(self.fields),
TypeError: can only join an iterable
>>>
我还编写了一个计算 1 个权益的脚本:
from __future__ import division
import numpy as np
import pandas as pd
import datetime
import tia
import tia.bbg.datamgr as dm
start = datetime.date(2017, 1, 3)
end = datetime.date(2017, 7, 25)
diffdays = ((end - start).days)/365
resolution = 0.01
diff2dp = int(np.round(diffdays/resolution))*resolution
diff = 1/diff2dp
mgr = dm.BbgDataManager()
eqt = mgr['GOOGL US Equity']
datafetch = eqt.get_historical(['PX_LAST'], start, end)
calc1 = ((datafetch.loc[end]['PX_LAST'])/(datafetch.loc[start]['PX_LAST']))
calc2 = (pow(calc1,diff))-1
calc22dp = int(np.round(calc2/resolution))*resolution
print calc22dp
您的单一安全解决方案是这样做的:
eqt = mgr['GOOGL US Equity']
但您的多重安全解决方案(实际上)是这样做的:
eqt = mgr[('GOOGL US Equity','MSFT US Equity', 'IBM US Equity')]
现在,如果没有安装 Bloomberg,我显然无法对此进行测试,但从错误消息中可以清楚地看出您的问题出在 eqt
。您是否 100% 确定可以将 BBG id 的元组作为密钥传递给 dm.BbgDataManager()
?您得到的结果表明您不能。
按照您的单一安全解决方案行事,但循环浏览感兴趣的股票:
stocks = ('GOOGL US Equity','MSFT US Equity', 'IBM US Equity')
mgr = dm.BbgDataManager()
for stock in stocks:
eqt = mgr[stock]
datafetch = eqt.get_historical(['PX_LAST'], start, end)
calc1 = ((datafetch.loc[end]['PX_LAST'])/(datafetch.loc[start]['PX_LAST']))
calc2 = (pow(calc1,diff))-1
calc22dp = int(np.round(calc2/resolution))*resolution
print calc22dp
我正在编写一个脚本,使用 TIA 工具包从 Bloomberg 获取数据。我正在尝试将 start
日期中 stocks
中每个股票的 PX_VALUE
放在名为 dict1
的字典中,以便我以后可以操纵这些值。
到目前为止,这是我的脚本,没有计算:
from __future__ import division
import numpy as np
import pandas as pd
import datetime
import tia
import tia.bbg.datamgr as dm
from operator import itemgetter
start = datetime.date(2017, 1, 3)
end = datetime.date(2017, 7, 25)
diffdays = ((end - start).days)/365
resolution = 0.01
diff2dp = int(np.round(diffdays/resolution))*resolution
diff = 1/diff2dp
dict1 = {}
stocks = ('GOOGL US Equity','MSFT US Equity', 'IBM US Equity')
mgr = dm.BbgDataManager()
eqt = mgr[stocks]
for eq in eqt:
df = eq.get_historical(['PX_LAST'], start, end)
k = df.loc[start]['PX_LAST']
dict1 [stocks] = k
print dict1
这里是实际的输出:
Traceback (most recent call last):
File "C:\Users\bloomberg\Desktop\examples\CAGR by LouisV2 BROKEN.py", line 23, in <module>
for eq in eqt:
File "C:\Python27\lib\site-packages\tia\bbg\datamgr.py", line 94, in __getitem__
return self.get_attributes(flds, **self.overrides)
File "C:\Python27\lib\site-packages\tia\bbg\datamgr.py", line 90, in get_attributes
frame = self.mgr.get_attributes(self.sids, flds, **overrides)
File "C:\Python27\lib\site-packages\tia\bbg\datamgr.py", line 148, in get_attributes
return self.terminal.get_reference_data(sids, flds, **overrides).as_frame()
File "C:\Python27\lib\site-packages\tia\bbg\v3api.py", line 745, in get_reference_data
return self.execute(req)
File "C:\Python27\lib\site-packages\tia\bbg\v3api.py", line 711, in execute
self.logger.info('executing request: %s' % repr(request))
File "C:\Python27\lib\site-packages\tia\bbg\v3api.py", line 432, in __repr__
fields=','.join(self.fields),
TypeError: can only join an iterable
>>>
我还编写了一个计算 1 个权益的脚本:
from __future__ import division
import numpy as np
import pandas as pd
import datetime
import tia
import tia.bbg.datamgr as dm
start = datetime.date(2017, 1, 3)
end = datetime.date(2017, 7, 25)
diffdays = ((end - start).days)/365
resolution = 0.01
diff2dp = int(np.round(diffdays/resolution))*resolution
diff = 1/diff2dp
mgr = dm.BbgDataManager()
eqt = mgr['GOOGL US Equity']
datafetch = eqt.get_historical(['PX_LAST'], start, end)
calc1 = ((datafetch.loc[end]['PX_LAST'])/(datafetch.loc[start]['PX_LAST']))
calc2 = (pow(calc1,diff))-1
calc22dp = int(np.round(calc2/resolution))*resolution
print calc22dp
您的单一安全解决方案是这样做的:
eqt = mgr['GOOGL US Equity']
但您的多重安全解决方案(实际上)是这样做的:
eqt = mgr[('GOOGL US Equity','MSFT US Equity', 'IBM US Equity')]
现在,如果没有安装 Bloomberg,我显然无法对此进行测试,但从错误消息中可以清楚地看出您的问题出在 eqt
。您是否 100% 确定可以将 BBG id 的元组作为密钥传递给 dm.BbgDataManager()
?您得到的结果表明您不能。
按照您的单一安全解决方案行事,但循环浏览感兴趣的股票:
stocks = ('GOOGL US Equity','MSFT US Equity', 'IBM US Equity')
mgr = dm.BbgDataManager()
for stock in stocks:
eqt = mgr[stock]
datafetch = eqt.get_historical(['PX_LAST'], start, end)
calc1 = ((datafetch.loc[end]['PX_LAST'])/(datafetch.loc[start]['PX_LAST']))
calc2 = (pow(calc1,diff))-1
calc22dp = int(np.round(calc2/resolution))*resolution
print calc22dp