0

I have a dataframe which contains ticker name and currency in adjacent columns.

Now I want to extract data for a field which uses currency as an override (consider for e.g. the field CRNCY ADJ MKT CAP which has an override EQY_FUND_CRNCY).

To get the desired output I have to rely on apply function in python which will call a function

def adj_mcap(ticker, crncy):
    ...
    blp.bdp(tickers=ticker, flds=["CRNCY ADJ MKT CAP","EQY_FUND_CRNCY="crncy]).loc[:,"crncy_adj_mkt_cap"].values[0]
    ...

So basically using apply I call this function

df['AdjMcap'] = df.apply(lambda x: adj_mcap(x.ticker, x.crncy), axis=1)

Now the problem I am facing is that the apply function makes one bdp call per row at a time thus requiring way too much time and resulting in a lot of hits. I just wanted to check if there was a better way around.

The only other way that I can think of is to group tickers by currency, and then iterate through each currency and dump all the tickers per currency, keep on appending till the last currency. This would result in a fewer calls, but honestly I'm looking for a much elegant solution.

x0nar
  • 125
  • 2
  • 10
  • There is a similar question [here](https://stackoverflow.com/q/75979818/15239951). My answer: https://stackoverflow.com/a/75980183/15239951 – Corralien Apr 10 '23 at 21:24

0 Answers0