Serving the Quantitative Finance Community

 
User avatar
DReiner
Posts: 0
Joined: October 9th, 2002, 9:16 pm

Bloomberg BLPB function in VBA

January 4th, 2008, 8:56 pm

Well, this is not very timely, but having it archived here may help someone in future.This is a code fragment; you will need to declare some variables before this and fill in the ticker array.Quote ' Get accrued interest as of delivery date (calculation overrides) Set bbObj = New BlpData f = "INT_ACC" fo = "SETTLE_DT" Set r = Range("delivList").Offset(1, 14) ReDim fv(nBonds - 1) For i = 0 To nBonds - 1 fv(i) = Application.WorksheetFunction.Text(r.Offset(i, 0).Value, "YYYYMMDD") Next i v = bbObj.BLPSubscribe(ticker, f, fo, fv) For i = 0 To nBonds - 1 r.Offset(i, 1).Value = v(i, 0) Next i
 
User avatar
Moriaben
Posts: 0
Joined: November 23rd, 2009, 1:55 pm

Bloomberg BLPB function in VBA

March 8th, 2010, 7:27 pm

Dear all,I have an issue with bbg/vba. I can download any data i want, using the functions above, but it is a lot slower than using "BDP" fonctions in worksheets (which are, unfortunately, asynchronous)what I want to download is:opt_chain for 1 underlying (let's say: sx5e index)and then, for all option tickers: px_bid, px_ask, px_mid etc...I simply wanted to know if it was possible to do a "one shot" request using the bbg api, to accelerate the process (instead of iterating the bbg function for every option ticker)Thank you. NB: problem solved! using the following code: bbg_Ticker2 = Array("APV US 03/20/10 C125 Equity", "APV US 03/20/10 C130 Equity", "APV US 03/20/10 C135 Equity") bbg_Fields2 = Array("OPT_EXPIRE_DT", "OPT_PUT_CALL", "OPT_STRIKE_PX", "PX_BID", "PX_ASK", "PX_MID") bbg_Result2 = vbEmpty bbg_Result2 = bbControl.SynchReq(bbg_Ticker2, bbg_Fields2)Public Function SynchReq(vtSecurity As Variant, vtFields As Variant) As Variant SynchReq = objBloomberg.BLPSubscribe(vtSecurity, vtFields)End Functionedit 2: actually, it is still not very efficient. for a reason that i ignore, if the "bbg_Ticker2" is composed of opt_chain (ie: 2000 options on sx5e), it takes about 3 minutes to download everything! i'll ask bloomberg help during lunch time, but right now, i don't have access to bbg anymoredid you ever notice this problem ?thank you
Last edited by Moriaben on March 8th, 2010, 11:00 pm, edited 1 time in total.
 
User avatar
xlDominik
Posts: 0
Joined: March 10th, 2010, 7:44 am

Bloomberg BLPB function in VBA

March 10th, 2010, 8:33 am

Hi Moriaben,it looks like you use Bloomberg's "old" ActiveX Data Control. They recently published a new version (v3) and recommend that you migrate ASAP. Quote from the WAPI Insider (Feb. 2010):[quote]Limited Support for Pre-v3 APIAs of February, 2010, you should have already converted your Pre-v3 Desktop and Server API applications to now use the Bloomberg v3 API libraries. Bloomberg will continue to offer limited support of the pre-v3 API for the foreseeable future in order to provide Bloomberg users possessing larger systems additional time to migrate.Limited support means that you will continue to receive data via your pre-v3 API application as before. However, these API interfaces will no longer receive bug fixes, feature enhancements or software and programming support.If you have not yet migrated your application(s) to use the v3 API, in order to continue receiving full support, we ask that you do so immediately.Migration guides are available for the following pre-v3 API programming interfaces:C API Migration GuideAPI for .NET Migration Guide ActiveX/COM Data Control Migration Guide [/quote]If you log on to Bloomberg, goto WAPI<Go> and go to the SDK Download Center. If you download and install the COM v3 Data Control, there will be some VBA Examples under C:\blp\api\APIv3\COM Data Control\Examples\VBA on your hard drive.On WAPI homepage you'll also find links to Developer and Installation Guides, Migration Guides and Best Practices. IMHO, some of the VBA code seems to be "translated" row by row from C# (e.g. in VBA you don't Dim a variable within a For-Next-Loop!). Therefore, you might want to fine-tune the VBA code...There is also an API Developer's Forum - but it's not very active (yet).I am currently migrating to the new COM v3 Data Control and synchronously learning how to request data using C#. If you have any questions about the VBA part, feel free to ask.Regards,Dominik.
 
User avatar
Moriaben
Posts: 0
Joined: November 23rd, 2009, 1:55 pm

Bloomberg BLPB function in VBA

March 10th, 2010, 10:50 am

hello dominik,indeed the bloomberg help told me to upgrade to the new version. I have to deal with my IT support to do that (i don't have the privileges)I'll probably come back as soon as it's done!thank you for your help
 
User avatar
Moriaben
Posts: 0
Joined: November 23rd, 2009, 1:55 pm

Bloomberg BLPB function in VBA

March 22nd, 2010, 11:52 am

Dominik,now that the new api is installed on my computer ("mieux vaut tard que jamais"...), i'm trying to download historical datas in vba (using the "HistoryExample.xls" file installed in C:\blp\api\APIv3\COM Data Control\Examples\VBA)with the old api, i was using 2 options: .DisplayNonTradingDays = AllCalendar .NonTradingDayValue = PreviousDaysdo you know how can i use these options with the new api? I've tried: req.Set "DisplayNonTradingDays", "AllCalendar" req.Set "NonTradingDayValue", "PreviousDays"but as you can imagine, it doesn't work (i wouldn't be asking otherwise )thank you for your help!benjamin
 
User avatar
xlDominik
Posts: 0
Joined: March 10th, 2010, 7:44 am

Bloomberg BLPB function in VBA

March 22nd, 2010, 12:30 pm

Hi Benjamin,thanks to google, I translated your proverb What you are looking for isreq.Set "nonTradingDayFillOption", "ALL_CALENDAR_DAYS"req.Set "nonTradingDayFillMethod", "PREVIOUS_VALUE"If I remember correctly, the strings are case-sensitive! (at least the "nonTradingDayFillxxx"-strings).If you want to set more/other options, download the current version (2.17) of the API Developer's Guide and have a look on pages 98ff.To find the guide, type DOCS 2041121<Go>It might look funny that the strings don't start with capital letters, but that's called "camel-casing" and is used (e.g.) in C#Looks to me that Bloomberg adopted (part of) the C# syntax in the COM v3 Data Type Library. Some of the code they post as examples seems to be translated from their C# examples line by line in VBA. Maybe they used google for translation as well? For example, in VBA you don't Dim a variable within a For-Next-Loop, but in C# that's what you do to restrict the scope of the variable to the loop. Once the loop exits, the variable is no longer accessible... Hope this helps!Regards,Dominik.
 
User avatar
Moriaben
Posts: 0
Joined: November 23rd, 2009, 1:55 pm

Bloomberg BLPB function in VBA

March 22nd, 2010, 12:44 pm

works like a charm, thank you very much !
 
User avatar
Moriaben
Posts: 0
Joined: November 23rd, 2009, 1:55 pm

Bloomberg BLPB function in VBA

March 23rd, 2010, 7:37 am

does anyone know how to make a synchronous request ?with the example given in the file "historyexample.xls" that comes with the new api, it's only an async request and what i want (what i was doing with the old api) is:use a bbg function that returns an array (in vba, not in a worksheet) of historical datas (when everything is downloaded) to do so calculations with the datasthank you
 
User avatar
xlDominik
Posts: 0
Joined: March 10th, 2010, 7:44 am

Bloomberg BLPB function in VBA

March 23rd, 2010, 8:20 am

Hi Benjamin,have a look at the COM migration guide under WAPI<Go>This piece of code is NOT tested. It's taken out of context but it will hopefully give you an idea...Regards,Dominik.
Last edited by xlDominik on March 22nd, 2010, 11:00 pm, edited 1 time in total.