I am trying to extract data from Bloomberg. I need data for multiple fields with diferent currencies. I can’t get what I need from this answer https://github.com/alpha-xone/xbbg
Can anyone help, please?. for a “specifc time” and on a “period of time”?
I tried the following code but it didn’t work.
blp.bdh( tickers='TPXDDVD Index,SCTOGAA LN Equity,VAPEJSI ID Equity', flds=['PX_LAST', 'FUND_NET_ASSET_VAL', 'FUND_TOTAL_ASSETS'], start_date='2018-10-01', end_date='2019-11-01', FX=['JPY','GBp','USD'] )
Advertisement
Answer
It is best to group similar securities together when pulling in historic data. In the OP’s question, ‘TPXDDVD Index’ is a calculated total return index. Hence it will not have the same fields available as the other two, which as their tickers suggest are quoted funds.
Taking just the two quoted funds, SCTOGAA LN Equity
and VAPEJSI ID Equity
, we can determine the default currency in which each field is denominated. This being Bloomberg, naming conventions are organic and may not be obvious! The two value fields are FUND_NET_ASSET_VAL
and FUND_TOTAL_ASSETS
, and the default currency might be different for each.
We can use the bdp()
function to pull back these currencies as follows (NB tickers are in a python list:
from xbbg import blp tickers = ['SCTOGAA LN Equity','VAPEJSI ID Equity'] df = blp.bdp(tickers,['NAV_CRNCY','FUND_TOTAL_ASSETS_CRNCY']) print(df)
With the result:
nav_crncy fund_total_assets_crncy SCTOGAA LN Equity GBp GBP VAPEJSI ID Equity USD EUR
So for VAPEJSI the NAV and Total Assets are denominated in different currencies. And NB. GBp
is not a typo by the data entry clerk, it means GBP pence
.
You can override the currency with a single currency value applied to all fields in the function call.
from xbbg import blp fields = ['FUND_NET_ASSET_VAL','FUND_TOTAL_ASSETS'] df = blp.bdh('SCTOGAA LN Equity',fields, start_date='2018-10-01', end_date='2019-11-01') print(df.tail(2)) df = blp.bdh('SCTOGAA LN Equity',fields, start_date='2018-10-01', end_date='2019-11-01', Currency='USD') print(df.tail(2))
which returns:
SCTOGAA LN Equity FUND_NET_ASSET_VAL FUND_TOTAL_ASSETS 2019-10-31 70.81 1755.65 2019-11-01 70.99 1756.51 SCTOGAA LN Equity FUND_NET_ASSET_VAL FUND_TOTAL_ASSETS 2019-10-31 0.91607 2271.28527 2019-11-01 0.91840 2272.40325
The asset value in GBP pence, has been converted to USD dollars. As an aside if you had put Currency='USd'
instead you would have the price in US cents. You have to love case-sensitivity …