Search code examples
rbloomberg

Importing option chain data from Bloomberg


I would like to import from Bloomberg into R for a specified day the entire option chain for a particular stock, i.e. all expiries and strikes for the exchange traded options. I am able to import the option chain for a non-specified day (today):

bbgData <- bds(connection,sec,"OPT_CHAIN")

Where connection is a valid Bloomberg connection and sec is a Bloomberg security ticker such as "TLS AU Equity"

However, if I add extra fields it doesn't work, i.e.

bbgData <- bds(connection, sec,"OPT_CHAIN", testDate, "OPT_STRIKE_PX", "MATURITY", "PX_BID", "PX_ASK")
bbgData <- bds(connection, sec,"OPT_CHAIN", "OPT_STRIKE_PX", "MATURITY", "PX_BID", "PX_ASK")

Similarly, if I switch to using the historical data function it doesn't work

bbgData <- dateDataHist <- bdh(connection,sec,"OPT_CHAIN","20160201")

I just need the data for one day, but for a specified day, and including the additional fields

Hint: I think the issue is that every field following "OPT_CHAIN" is dependent on the result of "OPT_CHAIN", so for example it is the strike price given the code in "OPT_CHAIN", but I am unsure how to introduce this conditionality into the R Bloomberg query.


Solution

  • It's better to use the field CHAIN_TICKERS and related overrides when retrieving option data for a given underlying from Bloomberg. You can, for example, request points for a given moneyness by getting CHAIN_TICKERS with an override of CHAIN_STRIKE_PX_OVRD equal to 90%-110%.

    In either case you need to use the tickers that are the result of your first request in a second request if you want to retrieve additional data. So:

    option_tickers <- bds("TLS AU Equity","CHAIN_TICKERS", 
                          overrides=c(CHAIN_STRIKE_PX_OVRD="90%-110%"))
    
    option_prices <- bdp(sapply(option_tickers, paste, "equity"), c("PX_BID","PX_ASK"))