Bloomberg VBA - BLPSubscribe 方法为 CUSIP 输入返回“#N/A Sec”
Bloomberg VBA - BLPSubscribe method returning "#N/A Sec" for CUSIP input
我正在尝试下拉未知固定收益类型(可能是公司、国库、抵押或资产支持等)的已知 CUSIP 的 SECURITY_DES 字段值。我正在使用 return Bloomberg 响应的声明变体,无论我如何构建我的请求,它一直显示“#N/A Sec”。
我在 Excel 中 运行 并添加了 "Bloomberg Data Type Library" 参考。我将粘贴下面的代码;我尝试将 CUSIP 格式化为 /CUSIP/xxxxxxxxx、xxxxxxxxx CUSIP、IDxxxxxxxxx,但都没有成功。我尝试使用谷歌搜索格式帮助,但无法找到适合我的匹配讨论。
Dim BloombergModule As BlpData
Set BloombergModule = New BlpData
Dim BloombergReturnData As Variant
Dim BloombergFields(0) As String
' Prepare request for the SECURITY_DES field, "Security Description"...
BloombergFields(0) = "SECURITY_DES"
BloombergReturnData = BloombergModule.BLPSubscribe([CUSIP], BloombergFields)
我在上面粘贴的最后一行之后放置了一个断点;当我查看 BloombergReturnData 变量时,我在 BloombergReturnData(0,0) 表达式中看到“#N/A Sec”,这正是我所期望的——仅使用证券的实际描述 returned 而不是“ #N/A秒".
如果您还没有了解,我不是专业的程序员,但最近一直在使用 Bloomberg 和 VBA 来填补办公室的一些空白。根据我读过的内容,我怀疑我必须传递固定收益类型(Corp、Govt、Mtge 等),但是我不知道在我当前的数据集中,我必须以某种方式追踪它.
使用 Bloomberg 的 GUI,我可以输入 "IDxxxxxxxxx"(x 代表 CUSIP)以到达证券主菜单。
以下是一些 CUSIP 示例:
428236BR3,
500255AV6,
912828UE8,
49126PET3,
912828SC5,
912828MS6,
02225AFW7
如何将我的 BLPSubscribe 请求格式化为 return Bloomberg 的安全说明?
编辑:已回答。我使用的是 Bloomberg 不再支持的旧参考和结构。使用 Mikael Katajamäki 撰写的博客 post 中的信息,我使用更新的参考 ("Bloomberg API COM 3.5 Type Library") 和安全名称格式“/cusip/xxxxxxxxx” 重组了我的调用。更新后的代码如下(请记住,如果您打算复制此结构,您将需要 Mikael Katajamäki 的博客 post 中的 class 模块):
' BCOM_wrapper is from Mikael Katajamäki's Bloomberg Class Module
Dim BloombergModule As BCOM_wrapper
Set BloombergModule = New BCOM_wrapper
Dim BloombergReturnData As Variant
Dim BloombergFields(0) As Variant
Dim BloombergSecurities(0) As Variant
Dim SecurityDescription As String
' Prepare request for the SECURITY_DES field, "Security Description"...
BloombergFields(0) = "SECURITY_DES"
BloombergSecurities(0) = ("/cusip/" & CStr(SQLResults![CUSIP]))
' getData() is from Mikael Katajamäki's Bloomberg Class Module
BloombergReturnData = BloombergModule.getData(REFERENCE_DATA, BloombergSecurities, BloombergFields)
' I used an absolute reference to the (0,0) slot since the nature of my use here is always just a single security
SecurityDescription = BloombergReturnData(0, 0)
Range("D" & CStr(Right(Target.Address, 2))).Value = SecurityDescription
Mikael Katajamäki 的博客 Post:http://mikejuniperhill.blogspot.com/2013/06/bloomberg-v3com-api-wrapper-update-for.html
Mikael Katajamäki 的 class 模块存档(如果违反规则请通知我,我将删除):
Option Explicit
'
' public enumerator for request type
Public Enum ENUM_REQUEST_TYPE
REFERENCE_DATA = 1
HISTORICAL_DATA = 2
BULK_REFERENCE_DATA = 3
End Enum
'
' constants
Private Const CONST_SERVICE_TYPE As String = "//blp/refdata"
Private Const CONST_REQUEST_TYPE_REFERENCE As String = "ReferenceDataRequest"
Private Const CONST_REQUEST_TYPE_BULK_REFERENCE As String = "ReferenceDataRequest"
Private Const CONST_REQUEST_TYPE_HISTORICAL As String = "HistoricalDataRequest"
'
' private data structures
Private bInputSecurityArray() As Variant
Private bInputFieldArray() As Variant
Private bOutputArray() As Variant
'
' BCOM objects
Private bSession As blpapicomLib2.Session
Private bService As blpapicomLib2.Service
Private bRequest As blpapicomLib2.REQUEST
Private bSecurityArray As blpapicomLib2.Element
Private bFieldArray As blpapicomLib2.Element
Private bEvent As blpapicomLib2.Event
Private bIterator As blpapicomLib2.MessageIterator
Private bIteratorData As blpapicomLib2.Message
Private bSecurities As blpapicomLib2.Element
Private bSecurity As blpapicomLib2.Element
Private bSecurityName As blpapicomLib2.Element
Private bSecurityField As blpapicomLib2.Element
Private bFieldValue As blpapicomLib2.Element
Private bSequenceNumber As blpapicomLib2.Element
Private bFields As blpapicomLib2.Element
Private bField As blpapicomLib2.Element
Private bDataPoint As blpapicomLib2.Element
'
' class non-object data members
Private bRequestType As ENUM_REQUEST_TYPE
Private bNumberOfDataPoints As Long
Private bCalendarType As String
Private bFrequency As String
Private bMaxDataPoints As Long
Private bStartDate As String
Private bEndDate As String
Private nSecurities As Long
Private nSecurity As Long
'
Public Function getData(ByVal requestType As ENUM_REQUEST_TYPE, _
ByRef securities() As Variant, ByRef fields() As Variant, _
Optional ByVal calendarType As String, Optional ByVal dataFrequency As String, _
Optional ByVal startDate As Date, Optional ByVal endDate As Date) As Variant()
'
bRequestType = requestType
bInputSecurityArray = securities
bInputFieldArray = fields
'
If (bRequestType = ENUM_REQUEST_TYPE.HISTORICAL_DATA) Then
'
bCalendarType = calendarType
bFrequency = dataFrequency
'
If ((startDate = CDate(0)) Or (endDate = CDate(0))) Then _
Err.Raise vbObjectError, "Bloomberg API", "Input parameters missing for historical data query"
bStartDate = convertDateToBloombergString(startDate)
bEndDate = convertDateToBloombergString(endDate)
End If
'
openSession
sendRequest
catchServerEvent
releaseObjects
getData = bOutputArray
End Function
'
Private Function openSession()
'
Set bSession = New blpapicomLib2.Session
bSession.Start
bSession.OpenService CONST_SERVICE_TYPE
Set bService = bSession.GetService(CONST_SERVICE_TYPE)
End Function
'
Private Function sendRequest()
'
Select Case bRequestType
Case ENUM_REQUEST_TYPE.HISTORICAL_DATA
ReDim bOutputArray(0 To UBound(bInputSecurityArray, 1), 0 To 0)
Set bRequest = bService.CreateRequest(CONST_REQUEST_TYPE_HISTORICAL)
bRequest.Set "periodicityAdjustment", bCalendarType
bRequest.Set "periodicitySelection", bFrequency
bRequest.Set "startDate", bStartDate
bRequest.Set "endDate", bEndDate
'
Case ENUM_REQUEST_TYPE.REFERENCE_DATA
Dim nSecurities As Long: nSecurities = UBound(bInputSecurityArray)
Dim nFields As Long: nFields = UBound(bInputFieldArray)
ReDim bOutputArray(0 To nSecurities, 0 To nFields)
'
Set bRequest = bService.CreateRequest(CONST_REQUEST_TYPE_REFERENCE)
'
Case ENUM_REQUEST_TYPE.BULK_REFERENCE_DATA
ReDim bOutputArray(0 To UBound(bInputSecurityArray, 1), 0 To 0)
Set bRequest = bService.CreateRequest(CONST_REQUEST_TYPE_BULK_REFERENCE)
'
End Select
'
Set bSecurityArray = bRequest.GetElement("securities")
Set bFieldArray = bRequest.GetElement("fields")
appendRequestItems
bSession.sendRequest bRequest
End Function
'
Private Function appendRequestItems()
'
Dim nSecurities As Long: nSecurities = UBound(bInputSecurityArray)
Dim nFields As Long: nFields = UBound(bInputFieldArray)
Dim i As Long
Dim nItems As Integer: nItems = getMax(nSecurities, nFields)
For i = 0 To nItems
If (i <= nSecurities) Then bSecurityArray.AppendValue CStr(bInputSecurityArray(i))
If (i <= nFields) Then bFieldArray.AppendValue CStr(bInputFieldArray(i))
Next i
End Function
'
Private Function catchServerEvent()
'
Dim bExit As Boolean
Do While (bExit = False)
Set bEvent = bSession.NextEvent
If (bEvent.EventType = PARTIAL_RESPONSE Or bEvent.EventType = RESPONSE) Then
'
Select Case bRequestType
Case ENUM_REQUEST_TYPE.REFERENCE_DATA: getServerData_reference
Case ENUM_REQUEST_TYPE.HISTORICAL_DATA: getServerData_historical
Case ENUM_REQUEST_TYPE.BULK_REFERENCE_DATA: getServerData_bulkReference
End Select
'
If (bEvent.EventType = RESPONSE) Then bExit = True
End If
Loop
End Function
'
Private Function getServerData_reference()
'
Set bIterator = bEvent.CreateMessageIterator
Do While (bIterator.Next)
Set bIteratorData = bIterator.Message
Set bSecurities = bIteratorData.GetElement("securityData")
Dim offsetNumber As Long, i As Long, j As Long
nSecurities = bSecurities.Count
'
For i = 0 To (nSecurities - 1)
Set bSecurity = bSecurities.GetValue(i)
Set bSecurityName = bSecurity.GetElement("security")
Set bSecurityField = bSecurity.GetElement("fieldData")
Set bSequenceNumber = bSecurity.GetElement("sequenceNumber")
offsetNumber = CInt(bSequenceNumber.Value)
'
For j = 0 To UBound(bInputFieldArray)
If (bSecurityField.HasElement(bInputFieldArray(j))) Then
Set bFieldValue = bSecurityField.GetElement(bInputFieldArray(j))
'
If (bFieldValue.DataType = BLPAPI_INT32) Then
bOutputArray(offsetNumber, j) = VBA.CLng(bFieldValue.Value)
Else
bOutputArray(offsetNumber, j) = bFieldValue.Value
End If
End If
Next j
Next i
Loop
End Function
'
Private Function getServerData_bulkReference()
'
Set bIterator = bEvent.CreateMessageIterator
nSecurity = nSecurity + 1
'
Do While (bIterator.Next)
Set bIteratorData = bIterator.Message
Set bSecurities = bIteratorData.GetElement("securityData")
Dim offsetNumber As Long, i As Long, j As Long
Dim nSecurities As Long: nSecurities = bSecurities.Count
'
Set bSecurity = bSecurities.GetValue(0)
Set bSecurityField = bSecurity.GetElement("fieldData")
'
If (bSecurityField.HasElement(bInputFieldArray(0))) Then
Set bFieldValue = bSecurityField.GetElement(bInputFieldArray(0))
'
If ((bFieldValue.NumValues - 1) > UBound(bOutputArray, 2)) Then _
ReDim Preserve bOutputArray(0 To UBound(bOutputArray, 1), 0 To bFieldValue.NumValues - 1)
'
For i = 0 To bFieldValue.NumValues - 1
Set bDataPoint = bFieldValue.GetValue(i)
bOutputArray(nSecurity - 1, i) = bDataPoint.GetElement(0).Value
Next i
End If
Loop
End Function
'
Private Function getServerData_historical()
'
Set bIterator = bEvent.CreateMessageIterator
Do While (bIterator.Next)
Set bIteratorData = bIterator.Message
Set bSecurities = bIteratorData.GetElement("securityData")
Dim nSecurities As Long: nSecurities = bSecurityArray.Count
Set bSecurityField = bSecurities.GetElement("fieldData")
Dim nItems As Long, offsetNumber As Long, nFields As Long, i As Long, j As Long
nItems = bSecurityField.NumValues
If (nItems = 0) Then Exit Function
If ((nItems > UBound(bOutputArray, 2))) Then _
ReDim Preserve bOutputArray(0 To nSecurities - 1, 0 To nItems - 1)
'
Set bSequenceNumber = bSecurities.GetElement("sequenceNumber")
offsetNumber = CInt(bSequenceNumber.Value)
'
If (bSecurityField.Count > 0) Then
For i = 0 To (nItems - 1)
'
If (bSecurityField.Count > i) Then
Set bFields = bSecurityField.GetValue(i)
If (bFields.HasElement(bFieldArray(0))) Then
'
Dim d(0 To 1) As Variant
d(0) = bFields.GetElement(0).GetValue(0)
d(1) = bFields.GetElement(1).GetValue(0)
bOutputArray(offsetNumber, i) = d
End If
End If
Next i
End If
Loop
End Function
'
Private Function releaseObjects()
'
Set bFieldValue = Nothing
Set bSequenceNumber = Nothing
Set bSecurityField = Nothing
Set bSecurityName = Nothing
Set bSecurity = Nothing
Set bSecurities = Nothing
Set bIteratorData = Nothing
Set bIterator = Nothing
Set bEvent = Nothing
Set bFieldArray = Nothing
Set bSecurityArray = Nothing
Set bRequest = Nothing
Set bService = Nothing
bSession.Stop
Set bSession = Nothing
End Function
'
Private Function convertDateToBloombergString(ByVal d As Date) As String
'
' convert date data type into string format YYYYMMDD
Dim dayString As String: dayString = VBA.CStr(VBA.Day(d)): If (VBA.Day(d) < 10) Then dayString = "0" + dayString
Dim MonthString As String: MonthString = VBA.CStr(VBA.Month(d)): If (VBA.Month(d) < 10) Then MonthString = "0" + MonthString
Dim yearString As String: yearString = VBA.Year(d)
convertDateToBloombergString = yearString + MonthString + dayString
End Function
'
Private Function getMax(ByVal a As Long, ByVal b As Long) As Long
'
getMax = a: If (b > a) Then getMax = b
End Function
您可以通过在 CUSIP 号码后放置 "Cusip" 来格式化它。
所以 BloombergReturnData = BloombergModule.BLPSubscribe("xxxxxxx Cusip", BloombergFields) 会 return 必填字段。
我使用您的 Cusip 列表进行了测试,它确实使用正确的字段数据填充了变体。
请注意,Bloomberg 不再支持您使用的 ActiveX 控件。有一个使用 "v3" 接口的 COM 数据控件。
我正在尝试下拉未知固定收益类型(可能是公司、国库、抵押或资产支持等)的已知 CUSIP 的 SECURITY_DES 字段值。我正在使用 return Bloomberg 响应的声明变体,无论我如何构建我的请求,它一直显示“#N/A Sec”。
我在 Excel 中 运行 并添加了 "Bloomberg Data Type Library" 参考。我将粘贴下面的代码;我尝试将 CUSIP 格式化为 /CUSIP/xxxxxxxxx、xxxxxxxxx CUSIP、IDxxxxxxxxx,但都没有成功。我尝试使用谷歌搜索格式帮助,但无法找到适合我的匹配讨论。
Dim BloombergModule As BlpData
Set BloombergModule = New BlpData
Dim BloombergReturnData As Variant
Dim BloombergFields(0) As String
' Prepare request for the SECURITY_DES field, "Security Description"...
BloombergFields(0) = "SECURITY_DES"
BloombergReturnData = BloombergModule.BLPSubscribe([CUSIP], BloombergFields)
我在上面粘贴的最后一行之后放置了一个断点;当我查看 BloombergReturnData 变量时,我在 BloombergReturnData(0,0) 表达式中看到“#N/A Sec”,这正是我所期望的——仅使用证券的实际描述 returned 而不是“ #N/A秒".
如果您还没有了解,我不是专业的程序员,但最近一直在使用 Bloomberg 和 VBA 来填补办公室的一些空白。根据我读过的内容,我怀疑我必须传递固定收益类型(Corp、Govt、Mtge 等),但是我不知道在我当前的数据集中,我必须以某种方式追踪它.
使用 Bloomberg 的 GUI,我可以输入 "IDxxxxxxxxx"(x 代表 CUSIP)以到达证券主菜单。
以下是一些 CUSIP 示例: 428236BR3, 500255AV6, 912828UE8, 49126PET3, 912828SC5, 912828MS6, 02225AFW7
如何将我的 BLPSubscribe 请求格式化为 return Bloomberg 的安全说明?
编辑:已回答。我使用的是 Bloomberg 不再支持的旧参考和结构。使用 Mikael Katajamäki 撰写的博客 post 中的信息,我使用更新的参考 ("Bloomberg API COM 3.5 Type Library") 和安全名称格式“/cusip/xxxxxxxxx” 重组了我的调用。更新后的代码如下(请记住,如果您打算复制此结构,您将需要 Mikael Katajamäki 的博客 post 中的 class 模块):
' BCOM_wrapper is from Mikael Katajamäki's Bloomberg Class Module
Dim BloombergModule As BCOM_wrapper
Set BloombergModule = New BCOM_wrapper
Dim BloombergReturnData As Variant
Dim BloombergFields(0) As Variant
Dim BloombergSecurities(0) As Variant
Dim SecurityDescription As String
' Prepare request for the SECURITY_DES field, "Security Description"...
BloombergFields(0) = "SECURITY_DES"
BloombergSecurities(0) = ("/cusip/" & CStr(SQLResults![CUSIP]))
' getData() is from Mikael Katajamäki's Bloomberg Class Module
BloombergReturnData = BloombergModule.getData(REFERENCE_DATA, BloombergSecurities, BloombergFields)
' I used an absolute reference to the (0,0) slot since the nature of my use here is always just a single security
SecurityDescription = BloombergReturnData(0, 0)
Range("D" & CStr(Right(Target.Address, 2))).Value = SecurityDescription
Mikael Katajamäki 的博客 Post:http://mikejuniperhill.blogspot.com/2013/06/bloomberg-v3com-api-wrapper-update-for.html
Mikael Katajamäki 的 class 模块存档(如果违反规则请通知我,我将删除):
Option Explicit
'
' public enumerator for request type
Public Enum ENUM_REQUEST_TYPE
REFERENCE_DATA = 1
HISTORICAL_DATA = 2
BULK_REFERENCE_DATA = 3
End Enum
'
' constants
Private Const CONST_SERVICE_TYPE As String = "//blp/refdata"
Private Const CONST_REQUEST_TYPE_REFERENCE As String = "ReferenceDataRequest"
Private Const CONST_REQUEST_TYPE_BULK_REFERENCE As String = "ReferenceDataRequest"
Private Const CONST_REQUEST_TYPE_HISTORICAL As String = "HistoricalDataRequest"
'
' private data structures
Private bInputSecurityArray() As Variant
Private bInputFieldArray() As Variant
Private bOutputArray() As Variant
'
' BCOM objects
Private bSession As blpapicomLib2.Session
Private bService As blpapicomLib2.Service
Private bRequest As blpapicomLib2.REQUEST
Private bSecurityArray As blpapicomLib2.Element
Private bFieldArray As blpapicomLib2.Element
Private bEvent As blpapicomLib2.Event
Private bIterator As blpapicomLib2.MessageIterator
Private bIteratorData As blpapicomLib2.Message
Private bSecurities As blpapicomLib2.Element
Private bSecurity As blpapicomLib2.Element
Private bSecurityName As blpapicomLib2.Element
Private bSecurityField As blpapicomLib2.Element
Private bFieldValue As blpapicomLib2.Element
Private bSequenceNumber As blpapicomLib2.Element
Private bFields As blpapicomLib2.Element
Private bField As blpapicomLib2.Element
Private bDataPoint As blpapicomLib2.Element
'
' class non-object data members
Private bRequestType As ENUM_REQUEST_TYPE
Private bNumberOfDataPoints As Long
Private bCalendarType As String
Private bFrequency As String
Private bMaxDataPoints As Long
Private bStartDate As String
Private bEndDate As String
Private nSecurities As Long
Private nSecurity As Long
'
Public Function getData(ByVal requestType As ENUM_REQUEST_TYPE, _
ByRef securities() As Variant, ByRef fields() As Variant, _
Optional ByVal calendarType As String, Optional ByVal dataFrequency As String, _
Optional ByVal startDate As Date, Optional ByVal endDate As Date) As Variant()
'
bRequestType = requestType
bInputSecurityArray = securities
bInputFieldArray = fields
'
If (bRequestType = ENUM_REQUEST_TYPE.HISTORICAL_DATA) Then
'
bCalendarType = calendarType
bFrequency = dataFrequency
'
If ((startDate = CDate(0)) Or (endDate = CDate(0))) Then _
Err.Raise vbObjectError, "Bloomberg API", "Input parameters missing for historical data query"
bStartDate = convertDateToBloombergString(startDate)
bEndDate = convertDateToBloombergString(endDate)
End If
'
openSession
sendRequest
catchServerEvent
releaseObjects
getData = bOutputArray
End Function
'
Private Function openSession()
'
Set bSession = New blpapicomLib2.Session
bSession.Start
bSession.OpenService CONST_SERVICE_TYPE
Set bService = bSession.GetService(CONST_SERVICE_TYPE)
End Function
'
Private Function sendRequest()
'
Select Case bRequestType
Case ENUM_REQUEST_TYPE.HISTORICAL_DATA
ReDim bOutputArray(0 To UBound(bInputSecurityArray, 1), 0 To 0)
Set bRequest = bService.CreateRequest(CONST_REQUEST_TYPE_HISTORICAL)
bRequest.Set "periodicityAdjustment", bCalendarType
bRequest.Set "periodicitySelection", bFrequency
bRequest.Set "startDate", bStartDate
bRequest.Set "endDate", bEndDate
'
Case ENUM_REQUEST_TYPE.REFERENCE_DATA
Dim nSecurities As Long: nSecurities = UBound(bInputSecurityArray)
Dim nFields As Long: nFields = UBound(bInputFieldArray)
ReDim bOutputArray(0 To nSecurities, 0 To nFields)
'
Set bRequest = bService.CreateRequest(CONST_REQUEST_TYPE_REFERENCE)
'
Case ENUM_REQUEST_TYPE.BULK_REFERENCE_DATA
ReDim bOutputArray(0 To UBound(bInputSecurityArray, 1), 0 To 0)
Set bRequest = bService.CreateRequest(CONST_REQUEST_TYPE_BULK_REFERENCE)
'
End Select
'
Set bSecurityArray = bRequest.GetElement("securities")
Set bFieldArray = bRequest.GetElement("fields")
appendRequestItems
bSession.sendRequest bRequest
End Function
'
Private Function appendRequestItems()
'
Dim nSecurities As Long: nSecurities = UBound(bInputSecurityArray)
Dim nFields As Long: nFields = UBound(bInputFieldArray)
Dim i As Long
Dim nItems As Integer: nItems = getMax(nSecurities, nFields)
For i = 0 To nItems
If (i <= nSecurities) Then bSecurityArray.AppendValue CStr(bInputSecurityArray(i))
If (i <= nFields) Then bFieldArray.AppendValue CStr(bInputFieldArray(i))
Next i
End Function
'
Private Function catchServerEvent()
'
Dim bExit As Boolean
Do While (bExit = False)
Set bEvent = bSession.NextEvent
If (bEvent.EventType = PARTIAL_RESPONSE Or bEvent.EventType = RESPONSE) Then
'
Select Case bRequestType
Case ENUM_REQUEST_TYPE.REFERENCE_DATA: getServerData_reference
Case ENUM_REQUEST_TYPE.HISTORICAL_DATA: getServerData_historical
Case ENUM_REQUEST_TYPE.BULK_REFERENCE_DATA: getServerData_bulkReference
End Select
'
If (bEvent.EventType = RESPONSE) Then bExit = True
End If
Loop
End Function
'
Private Function getServerData_reference()
'
Set bIterator = bEvent.CreateMessageIterator
Do While (bIterator.Next)
Set bIteratorData = bIterator.Message
Set bSecurities = bIteratorData.GetElement("securityData")
Dim offsetNumber As Long, i As Long, j As Long
nSecurities = bSecurities.Count
'
For i = 0 To (nSecurities - 1)
Set bSecurity = bSecurities.GetValue(i)
Set bSecurityName = bSecurity.GetElement("security")
Set bSecurityField = bSecurity.GetElement("fieldData")
Set bSequenceNumber = bSecurity.GetElement("sequenceNumber")
offsetNumber = CInt(bSequenceNumber.Value)
'
For j = 0 To UBound(bInputFieldArray)
If (bSecurityField.HasElement(bInputFieldArray(j))) Then
Set bFieldValue = bSecurityField.GetElement(bInputFieldArray(j))
'
If (bFieldValue.DataType = BLPAPI_INT32) Then
bOutputArray(offsetNumber, j) = VBA.CLng(bFieldValue.Value)
Else
bOutputArray(offsetNumber, j) = bFieldValue.Value
End If
End If
Next j
Next i
Loop
End Function
'
Private Function getServerData_bulkReference()
'
Set bIterator = bEvent.CreateMessageIterator
nSecurity = nSecurity + 1
'
Do While (bIterator.Next)
Set bIteratorData = bIterator.Message
Set bSecurities = bIteratorData.GetElement("securityData")
Dim offsetNumber As Long, i As Long, j As Long
Dim nSecurities As Long: nSecurities = bSecurities.Count
'
Set bSecurity = bSecurities.GetValue(0)
Set bSecurityField = bSecurity.GetElement("fieldData")
'
If (bSecurityField.HasElement(bInputFieldArray(0))) Then
Set bFieldValue = bSecurityField.GetElement(bInputFieldArray(0))
'
If ((bFieldValue.NumValues - 1) > UBound(bOutputArray, 2)) Then _
ReDim Preserve bOutputArray(0 To UBound(bOutputArray, 1), 0 To bFieldValue.NumValues - 1)
'
For i = 0 To bFieldValue.NumValues - 1
Set bDataPoint = bFieldValue.GetValue(i)
bOutputArray(nSecurity - 1, i) = bDataPoint.GetElement(0).Value
Next i
End If
Loop
End Function
'
Private Function getServerData_historical()
'
Set bIterator = bEvent.CreateMessageIterator
Do While (bIterator.Next)
Set bIteratorData = bIterator.Message
Set bSecurities = bIteratorData.GetElement("securityData")
Dim nSecurities As Long: nSecurities = bSecurityArray.Count
Set bSecurityField = bSecurities.GetElement("fieldData")
Dim nItems As Long, offsetNumber As Long, nFields As Long, i As Long, j As Long
nItems = bSecurityField.NumValues
If (nItems = 0) Then Exit Function
If ((nItems > UBound(bOutputArray, 2))) Then _
ReDim Preserve bOutputArray(0 To nSecurities - 1, 0 To nItems - 1)
'
Set bSequenceNumber = bSecurities.GetElement("sequenceNumber")
offsetNumber = CInt(bSequenceNumber.Value)
'
If (bSecurityField.Count > 0) Then
For i = 0 To (nItems - 1)
'
If (bSecurityField.Count > i) Then
Set bFields = bSecurityField.GetValue(i)
If (bFields.HasElement(bFieldArray(0))) Then
'
Dim d(0 To 1) As Variant
d(0) = bFields.GetElement(0).GetValue(0)
d(1) = bFields.GetElement(1).GetValue(0)
bOutputArray(offsetNumber, i) = d
End If
End If
Next i
End If
Loop
End Function
'
Private Function releaseObjects()
'
Set bFieldValue = Nothing
Set bSequenceNumber = Nothing
Set bSecurityField = Nothing
Set bSecurityName = Nothing
Set bSecurity = Nothing
Set bSecurities = Nothing
Set bIteratorData = Nothing
Set bIterator = Nothing
Set bEvent = Nothing
Set bFieldArray = Nothing
Set bSecurityArray = Nothing
Set bRequest = Nothing
Set bService = Nothing
bSession.Stop
Set bSession = Nothing
End Function
'
Private Function convertDateToBloombergString(ByVal d As Date) As String
'
' convert date data type into string format YYYYMMDD
Dim dayString As String: dayString = VBA.CStr(VBA.Day(d)): If (VBA.Day(d) < 10) Then dayString = "0" + dayString
Dim MonthString As String: MonthString = VBA.CStr(VBA.Month(d)): If (VBA.Month(d) < 10) Then MonthString = "0" + MonthString
Dim yearString As String: yearString = VBA.Year(d)
convertDateToBloombergString = yearString + MonthString + dayString
End Function
'
Private Function getMax(ByVal a As Long, ByVal b As Long) As Long
'
getMax = a: If (b > a) Then getMax = b
End Function
您可以通过在 CUSIP 号码后放置 "Cusip" 来格式化它。 所以 BloombergReturnData = BloombergModule.BLPSubscribe("xxxxxxx Cusip", BloombergFields) 会 return 必填字段。 我使用您的 Cusip 列表进行了测试,它确实使用正确的字段数据填充了变体。
请注意,Bloomberg 不再支持您使用的 ActiveX 控件。有一个使用 "v3" 接口的 COM 数据控件。