1

I am trying to get "CHF1M Curncy" as Forward Rates and not as points from Bloomberg API BLPAPI in Python. The Code itself works fine for the Forward Points, but as soon as I use the override to switch from Points to Rates, I get an error "No value for []" for the line with the first override. This is my code:

import blpapi
import json

HISTORICAL_DATA_RESPONSE = blpapi.Name("HistoricalDataResponse")

def historical_bloomberg_data(securities, fields, periodicity="DAILY", start_date="20190101", end_date="20190105"):

    # Create and start a session
    print("Creating session ...")

    sessionOptions = blpapi.SessionOptions()
    sessionOptions.setServerHost('localhost')
    sessionOptions.setServerPort(8194)

    session = blpapi.Session(sessionOptions)

    if not session.start():
        print("Failed to start session")
        return
   

    try:
        # Create and open a service
        print("Creating historical data service")

        if not session.openService("//blp/refdata"):
            print("Failed to create service")
            return
  
        refDataService = session.getService("//blp/refdata")
        request = refDataService.createRequest("HistoricalDataRequest")

   
        # Add all securities
        for security in securities:
            request.getElement("securities").appendValue(security)

        

        # Add all fields
        for field in fields:
            request.getElement("fields").appendValue(field)

            

        # Further settings
        request.set("periodicitySelection", periodicity)
        request.set("startDate", start_date)

 
        

        request.set("endDate", end_date)
        request.set("maxDataPoints", 2000)

 

        #Override code
        overrides = request.getElement('overrides')
        override1 = overrides.appendElement()
        override1.setElement('fieldID', 'FWD_CURVE_FORMAT')
        override1.setElement('value', 'RATES')
        #request.setOverride("FWD_CURVE_FORMAT", "RATES")

 

        # Send and process request
        print("Sending request...")
        session.sendRequest(request)

        results = {}
     

        while True:
            ev = session.nextEvent(500)
            for msg in ev:
                if msg.messageType() == HISTORICAL_DATA_RESPONSE:
                    #response = msg.getElement()
                    response = msg.getElement("securityData")
                    _sec = response.getElementAsString("security")
                    _data = [[fd.getElementAsString("date")] + [fd.getElementAsString(_) for _ in fields] for fd in response.getElement("fieldData").values()]
                 
                    results[_sec] = results.get(_sec, []) + _data
        

            if ev.eventType() == blpapi.Event.RESPONSE:
                break
       

        print("Results retrieved")
        return results
Dharman
  • 30,962
  • 25
  • 85
  • 135
peter113
  • 11
  • 3

1 Answers1

1

The correct override is FWD_CURVE_QUOTE_FORMAT. The values can be:

  • POINTS
  • RATES
  • OUTRIGHT

(I suspect OUTRIGHT and RATES do the same thing)

EDIT

And the correct way to override a field is by using fieldId (ending with a small cap d) and not fieldID.

assylias
  • 321,522
  • 82
  • 660
  • 783
  • Hi, thanks for your input. Unfortunately, it doesn't work with FWD_CURVE_QUOTE_FORMAT either. :/ – peter113 Sep 13 '21 at 09:59
  • 1
    What ticker and field are you using? I've just tried with CHF1M Curncy and PX_LAST from september 1st 2021 to today and it works as expected. I also note that for the override you are supposed to use `fieldId` not `fieldID` - not sure if it makes a difference. – assylias Sep 13 '21 at 13:14
  • 1
    It makes all the difference!. You need `override1.setElement('fieldId', 'FWD_CURVE_QUOTE_FORMAT')` with the lower-case 'd' or it doesn't work. – DS_London Sep 13 '21 at 14:11