-2

Can someone please help. I have a list of dataframe that i am trying to download duration data for. Unfortunately the historical data is not avalable, so i have to resort to using the bdp function. However, this is super slow, and very inefficient. How can i make the code faster? I have tried every known method i could use

for(i in 1:length(AA_securites)){
  AA_securites[[i]] <- AA_securites[[i]] %>%
    mutate(DUR_MID = map_df(SETTLE_DT, ~ bdp(names(AA_securites)[i], "DUR_MID", overrides = c("SETTLE_DT" = gsub("-", "", .x)))))
}

Kelvin
  • 19
  • 4
  • 1
    you should be able to request the data for several securities at once – assylias Aug 17 '23 at 12:10
  • Agreed. Is there a reason you cannot do `bdp(names(securites), "DUR_MID", overrides = ...)`? (I don't know exactly how to adapt your `overrides=` argument, not sure exactly how your list of frames is structured.) The first argument of `bdp` is *"securities: A character vector with security symbols in Bloomberg notation"*, which to me means it can except a vector of length 1 _or more_, and it should work. (Though I'm stuck on overrides.) – r2evans Aug 17 '23 at 12:40
  • Depending on the type of the bonds (eg bullet) and how accurate you want to be, you could try getting the history of prices and yields, and then approximate the duration by (change in price)/(change in yield) from day to day. This is PV01 rather than Macaulay duration. – DS_London Aug 17 '23 at 16:03

0 Answers0