1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Sub GetOptionsData()
Dim i As Long, j As Long, nTotCount As Long, iMax As Long, nCnt As Long, vChainResult As Variant
Dim objBloomberg As BlpData, strSec() As String
Const offset As Integer = 10
Dim vArrayFields(1 To 5) As String
vArrayFields(1) = "OPT_EXPIRE_DT"
vArrayFields(2) = "OPT_STRIKE_PX"
vArrayFields(3) = "OPT_PUT_CALL"
vArrayFields(4) = "BID"
vArrayFields(5) = "ASK"
Ticker = Range("Ticker")
Range("B" & offset & ":AA" & Rows.Count).ClearContents
Application.StatusBar = Ticker & " Subscription Status: Retrieving Option Chain Tickers"
Set objBloomberg = New BlpData
objBloomberg.Subscribe Ticker, 1, "OPT_CHAIN", Results:=vChainResult
If IsArray(vChainResult) Then
iMax = UBound(vChainResult, 1)
For i = 0 To iMax
ReDim Preserve strSec(UBound(vChainResult(i, 0), 1) + nTotCount)
For nCnt = 0 To UBound(vChainResult(i, 0), 1)
strSec(nTotCount) = vChainResult(i, 0)(nCnt, 0)
nTotCount = nTotCount + 1
Cells(i + offset, 1) = strSec(i)
Next nCnt
Next i
Cells(i + offset, 1) = strSec(i)
DoEvents
Application.StatusBar = Ticker & " Subscription Status: Retrieving Data for " & strSec(i) & " (" & i & _
" of " & UBound(strSec) - LBound(strSec) & ")"
objBloomberg.Subscribe strSec(i), i + 1, vArrayFields, monitor:=True, Results:=vbData
For j = 1 To UBound(vArrayFields)
Cells(i + offset, j + 1) = vbData(0, j - 1)
Next j
vbData = vbEmpty
Next i
End If
End Sub |
Partager