Giter VIP home page Giter VIP logo

xbbg's Introduction

xbbg

xbbg

An intuitive Bloomberg API

PyPI version PyPI version PyPI - Downloads Gitter

Coffee

Features

Below are main features. Jupyter notebook examples can be found here.

  • Excel compatible inputs
  • Straightforward intraday bar requests
  • Subscriptions

Requirements

  • Bloomberg C++ SDK version 3.12.1 or higher:

    • Visit Bloomberg API Library and download C++ Supported Release

    • In the bin folder of downloaded zip file, copy blpapi3_32.dll and blpapi3_64.dll to Bloomberg BLPAPI_ROOT folder (usually blp/DAPI)

  • Bloomberg official Python API:

pip install blpapi --index-url=https://bcms.bloomberg.com/pip/simple/
  • numpy, pandas, ruamel.yaml and pyarrow

Installation

pip install xbbg

What's New

0.7.7a2 - Custom config and etc. for reference exchange (author hceh)

0.7.6a2 - Use blp.connect for alternative Bloomberg connection (author anxl2008)

0.7.2 - Use async for live data feeds

0.7.0 - bdh preserves columns orders (both tickers and flds). timeout argument is available for all queries - bdtick usually takes longer to respond - can use timeout=1000 for example if keep getting empty DataFrame.

0.6.6 - Add flexibility to use reference exchange as market hour definition (so that it's not necessary to add .yml for new tickers, provided that the exchange was defined in /xbbg/markets/exch.yml). See example of bdib below for more details.

0.6.0 - Speed improvements and tick data availablity

0.5.0 - Rewritten library to add subscription, BEQS, simplify interface and remove dependency of pdblp

0.1.22 - Remove PyYAML dependency due to security vulnerability

0.1.17 - Add adjust argument in bdh for easier dividend / split adjustments

Tutorial

In [1]: from xbbg import blp

Basics

  • BDP example:
In [2]: blp.bdp(tickers='NVDA US Equity', flds=['Security_Name', 'GICS_Sector_Name'])
Out[2]:
               security_name        gics_sector_name
NVDA US Equity   NVIDIA Corp  Information Technology
  • BDP with overrides:
In [3]: blp.bdp('AAPL US Equity', 'Eqy_Weighted_Avg_Px', VWAP_Dt='20181224')
Out[3]:
                eqy_weighted_avg_px
AAPL US Equity               148.75
  • BDH example:
In [4]: blp.bdh(
   ...:     tickers='SPX Index', flds=['high', 'low', 'last_price'],
   ...:     start_date='2018-10-10', end_date='2018-10-20',
   ...: )
Out[4]:
           SPX Index
                high      low last_price
2018-10-10  2,874.02 2,784.86   2,785.68
2018-10-11  2,795.14 2,710.51   2,728.37
2018-10-12  2,775.77 2,729.44   2,767.13
2018-10-15  2,775.99 2,749.03   2,750.79
2018-10-16  2,813.46 2,766.91   2,809.92
2018-10-17  2,816.94 2,781.81   2,809.21
2018-10-18  2,806.04 2,755.18   2,768.78
2018-10-19  2,797.77 2,760.27   2,767.78
  • BDH example with Excel compatible inputs:
In [5]: blp.bdh(
   ...:     tickers='SHCOMP Index', flds=['high', 'low', 'last_price'],
   ...:     start_date='2018-09-26', end_date='2018-10-20',
   ...:     Per='W', Fill='P', Days='A',
   ...: )
Out[5]:
           SHCOMP Index
                   high      low last_price
2018-09-28     2,827.34 2,771.16   2,821.35
2018-10-05     2,827.34 2,771.16   2,821.35
2018-10-12     2,771.94 2,536.66   2,606.91
2018-10-19     2,611.97 2,449.20   2,550.47
  • BDH without adjustment for dividends and splits:
In [6]: blp.bdh(
   ...:     'AAPL US Equity', 'px_last', '20140605', '20140610',
   ...:     CshAdjNormal=False, CshAdjAbnormal=False, CapChg=False
   ...: )
Out[6]:
           AAPL US Equity
                  px_last
2014-06-05         647.35
2014-06-06         645.57
2014-06-09          93.70
2014-06-10          94.25
  • BDH adjusted for dividends and splits:
In [7]: blp.bdh(
   ...:     'AAPL US Equity', 'px_last', '20140605', '20140610',
   ...:     CshAdjNormal=True, CshAdjAbnormal=True, CapChg=True
   ...: )
Out[7]:
           AAPL US Equity
                  px_last
2014-06-05          85.45
2014-06-06          85.22
2014-06-09          86.58
2014-06-10          87.09
  • BDS example:
In [8]: blp.bds('AAPL US Equity', 'DVD_Hist_All', DVD_Start_Dt='20180101', DVD_End_Dt='20180531')
Out[8]:
               declared_date     ex_date record_date payable_date  dividend_amount dividend_frequency dividend_type
AAPL US Equity    2018-05-01  2018-05-11  2018-05-14   2018-05-17             0.73            Quarter  Regular Cash
AAPL US Equity    2018-02-01  2018-02-09  2018-02-12   2018-02-15             0.63            Quarter  Regular Cash
  • Intraday bars BDIB example:
In [9]: blp.bdib(ticker='BHP AU Equity', dt='2018-10-17').tail()
Out[9]:
                          BHP AU Equity
                                   open  high   low close   volume num_trds
2018-10-17 15:56:00+11:00         33.62 33.65 33.62 33.64    16660      126
2018-10-17 15:57:00+11:00         33.65 33.65 33.63 33.64    13875      156
2018-10-17 15:58:00+11:00         33.64 33.65 33.62 33.63    16244      159
2018-10-17 15:59:00+11:00         33.63 33.63 33.61 33.62    16507      167
2018-10-17 16:10:00+11:00         33.66 33.66 33.66 33.66  1115523      216

Above example works because 1) AU in equity ticker is mapped to EquityAustralia in markets/assets.yml, and 2) EquityAustralia is defined in markets/exch.yml. To add new mappings, define BBG_ROOT in sys path and add assets.yml and exch.yml under BBG_ROOT/markets.

New in 0.6.6 - if exchange is defined in /xbbg/markets/exch.yml, can use ref to look for relevant exchange market hours. Both ref='ES1 Index' and ref='CME' work for this example:

In [10]: blp.bdib(ticker='ESM0 Index', dt='2020-03-20', ref='ES1 Index').tail()
out[10]:
                          ESM0 Index
                                open     high      low    close volume num_trds        value
2020-03-20 16:55:00-04:00   2,260.75 2,262.25 2,260.50 2,262.00    412      157   931,767.00
2020-03-20 16:56:00-04:00   2,262.25 2,267.00 2,261.50 2,266.75    812      209 1,838,823.50
2020-03-20 16:57:00-04:00   2,266.75 2,270.00 2,264.50 2,269.00   1136      340 2,576,590.25
2020-03-20 16:58:00-04:00   2,269.25 2,269.50 2,261.25 2,265.75   1077      408 2,439,276.00
2020-03-20 16:59:00-04:00   2,265.25 2,272.00 2,265.00 2,266.50   1271      378 2,882,978.25
  • Intraday bars within market session:
In [11]: blp.bdib(ticker='7974 JT Equity', dt='2018-10-17', session='am_open_30').tail()
Out[11]:
                          7974 JT Equity
                                    open      high       low     close volume num_trds
2018-10-17 09:27:00+09:00      39,970.00 40,020.00 39,970.00 39,990.00  10800       44
2018-10-17 09:28:00+09:00      39,990.00 40,020.00 39,980.00 39,980.00   6300       33
2018-10-17 09:29:00+09:00      39,970.00 40,000.00 39,960.00 39,970.00   3300       21
2018-10-17 09:30:00+09:00      39,960.00 40,010.00 39,950.00 40,000.00   3100       19
2018-10-17 09:31:00+09:00      39,990.00 40,000.00 39,980.00 39,990.00   2000       15
  • Corporate earnings:
In [12]: blp.earning('AMD US Equity', by='Geo', Eqy_Fund_Year=2017, Number_Of_Periods=1)
Out[12]:
                 level    fy2017  fy2017_pct
Asia-Pacific      1.00  3,540.00       66.43
    China         2.00  1,747.00       49.35
    Japan         2.00  1,242.00       35.08
    Singapore     2.00    551.00       15.56
United States     1.00  1,364.00       25.60
Europe            1.00    263.00        4.94
Other Countries   1.00    162.00        3.04
  • Dividends:
In [13]: blp.dividend(['C US Equity', 'MS US Equity'], start_date='2018-01-01', end_date='2018-05-01')
Out[13]:
                dec_date     ex_date    rec_date    pay_date  dvd_amt dvd_freq      dvd_type
C US Equity   2018-01-18  2018-02-02  2018-02-05  2018-02-23     0.32  Quarter  Regular Cash
MS US Equity  2018-04-18  2018-04-27  2018-04-30  2018-05-15     0.25  Quarter  Regular Cash
MS US Equity  2018-01-18  2018-01-30  2018-01-31  2018-02-15     0.25  Quarter  Regular Cash

New in 0.1.17 - Dividend adjustment can be simplified to one parameter adjust:

  • BDH without adjustment for dividends and splits:
In [14]: blp.bdh('AAPL US Equity', 'px_last', '20140606', '20140609', adjust='-')
Out[14]:
           AAPL US Equity
                  px_last
2014-06-06         645.57
2014-06-09          93.70
  • BDH adjusted for dividends and splits:
In [15]: blp.bdh('AAPL US Equity', 'px_last', '20140606', '20140609', adjust='all')
Out[15]:
           AAPL US Equity
                  px_last
2014-06-06          85.22
2014-06-09          86.58

Data Storage

If BBG_ROOT is provided in os.environ, data can be saved locally. By default, local storage is preferred than Bloomberg for all queries.

Noted that local data usage must be compliant with Bloomberg Datafeed Addendum (full description in DAPI<GO>):

To access Bloomberg data via the API (and use that data in Microsoft Excel), your company must sign the 'Datafeed Addendum' to the Bloomberg Agreement. This legally binding contract describes the terms and conditions of your use of the data and information available via the API (the "Data"). The most fundamental requirement regarding your use of Data is that it cannot leave the local PC you use to access the BLOOMBERG PROFESSIONAL service.

Star History

Star History Chart

Docs Documentation Status
Build Actions Status
Azure
Coverage codecov
Quality Codacy Badge
CodeFactor
codebeat badge
License GitHub license

xbbg's People

Contributors

alpha-xone avatar anxl2008 avatar azure-pipelines[bot] avatar cxong avatar hceh avatar jkassies avatar nano112 avatar rchiorean avatar swiecki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xbbg's Issues

regression BDP

When upgrading from 0.5.0 to 0.6.0 noticed a regression in BDP when requesting the open price and the current bid for a product: the open price is identical to the bid even when they are not.

AttributeError

Since the new update is being released I have this Error message when I try to use the xbbg-module.
index

SEDOL and ISIN compatability

Currently, the package doesn't appear to have SEDOL and ISIN compatibility, as the below call returns an empty value:

price = blp.bdp(tickers="B725S29 SEDOL", flds="CRNCY_ADJ_PX_LAST", EQY_FUND_CRNCY="USD")

If the package is compatible with SEDOLs and ISINs, please can you add documentation detailing the correct call. If not, please can we add this compatibility?

Issue when calling "CRNCY_ADJ_PX_LAST" whilst using the "EQY_FUND_CRNCY" argument.

Hi,

Thanks for creating and maintaining such a useful package. I noticed that when making the below call, an empty pd.DataFrame is returned. However, when making the call to "PX_LAST" and removing the kwargs, the data is returned as expected. Is it possible to return data within a specified currency as below, or is the workaround based on "PX_LAST" for the relevant currency pair?

Thanks

from xbbg import blp

for index, row in dataset.iterrows():
        if verbose:
            print("Ticker: {}".format(row[key]))
        value = blp.bdp(row[key] + " Equity", "CRNCY_ADJ_PX_LAST", kwargs="EQY_FUND_CRNCY=USD")

BDS with custom portfolio returns nothing

Hello, I am able to pull portfolio information for a custom portfolio in Excel and in xbbg using BDP only. When I try to pull data using BDS nothing is returned.

The code I am using is:
blp.bds('<PORT ID> Client','PORTFOLIO_DATA')

And the results is just "__". If I use the same formula in Excel it works fine.

Anyone having the same issue?

blp.bds is not working

Hi - thanks for the package - I am having an issue in that bds is not working at all I get the following when i try to run a BDS query. I run a bulk ref query in pdblp and I get results?

blp.bds('XS1577949149 corp','TOP_20_HOLDERS_PUBLIC_FILINGS')
AttributeError: module 'xbbg' has no attribute 'bds'

I installed with pip.

Please can you let me know if the bds call has been deprecated or has been amended and what i should do to fix the issue.

Thanks

bdp error when result involves arrays

Hi,

I'm trying to use bdp to retrieve fields that typically return arrays (on the Terminal, under FLDS, such fields can be identified by the "Show Bulk Data" mention in the "Value" column.

Windows 10
Python 3.8.6
blpapi 3.15.2
xbbg 0.7.0

blp.bdp('TYA Index','FUT_CHAIN')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\S\PycharmProjects\test_bbg\venv\lib\site-packages\xbbg\blp.py", line 46, in bdp
    res
  File "C:\Users\S\PycharmProjects\test_bbg\venv\lib\site-packages\pandas\core\frame.py", line 7142, in unstack
    return unstack(self, level, fill_value)
  File "C:\Users\S\PycharmProjects\test_bbg\venv\lib\site-packages\pandas\core\reshape\reshape.py", line 418, in unstack
    return _unstack_frame(obj, level, fill_value=fill_value)
  File "C:\Users\S\PycharmProjects\test_bbg\venv\lib\site-packages\pandas\core\reshape\reshape.py", line 438, in _unstack_frame
    return _Unstacker(
  File "C:\Users\S\PycharmProjects\test_bbg\venv\lib\site-packages\pandas\core\reshape\reshape.py", line 120, in __init__
    self._make_selectors()
  File "C:\Users\S\PycharmProjects\test_bbg\venv\lib\site-packages\pandas\core\reshape\reshape.py", line 169, in _make_selectors
    raise ValueError("Index contains duplicate entries, cannot reshape")

The returned value doesn't sit well with the unstack function from pandas. Let me know if there's more info I can provide.

I am getting a failed error...

My folder structure is as follows.... The problem seems to be caused by the dll location... I'm not sure.

error

My code is simple.

from xbbg import blp


blp.bdp(tickers='NVDA US Equity', flds=['Security_Name', 'GICS_Sector_Name'])

My operating system is ubuntu 20.04.
As for other information, I do not use anaconda, and I installed all necessary libraries using the pip install command without using the sudo command. (xbbg was also installed with pip install.)

Below is the error log.

20DEC2021_20:35:27.697 9050:139884534699776 WARN apicm_apiconnector.cpp:395 ApiConnector::socketConnectorCallback localhost: Failed to connect to 127.0.0.1:8194, status=1, error 8 connect event failed 

20DEC2021_20:35:27.697 9050:139884534699776 WARN blpapi_platformtransporttcp.cpp:151 blpapi.session.transporttcp.{1}.<localhost:8194> { platformId=0 } 127.0.0.1, session pool state=Failed 

20DEC2021_20:35:30.698 9050:139884534699776 WARN apicm_apiconnector.cpp:395 ApiConnector::socketConnectorCallback localhost: Failed to connect to 127.0.0.1:8194, status=1, error 8 connect event failed 

20DEC2021_20:35:30.698 9050:139884534699776 WARN blpapi_platformtransporttcp.cpp:151 blpapi.session.transporttcp.{1}.<localhost:8194> { platformId=0 } 127.0.0.1, session pool state=Failed 

20DEC2021_20:35:33.699 9050:139884534699776 WARN apicm_apiconnector.cpp:395 ApiConnector::socketConnectorCallback localhost: Failed to connect to 127.0.0.1:8194, status=1, error 8 connect event failed 

20DEC2021_20:35:33.699 9050:139884534699776 WARN blpapi_platformtransporttcp.cpp:151 blpapi.session.transporttcp.{1}.<localhost:8194> { platformId=0 } 127.0.0.1, session pool state=Failed 

20DEC2021_20:35:33.699 9050:139884534699776 WARN blpapi_platformcontroller.cpp:634 blpapi.session.platformcontroller.{1} Platform failed 3 consecutive connect attempts, stopped trying to reconnect. { PlatformId=0 }  

20DEC2021_20:35:33.699 9050:139884516685568 ERROR blpapi_sessionimpl.cpp:2445 blpapi.session.{1} Failed to start session: Failed to connect 

KeyError: 'Cannot find exchange info ...' while using blp.bdib

I am getting an error while trying to retrieve intra-day data as below:
I have set BBG_ROOT in my user environment to point to the folder with the /markets folder containing the yaml files.
xbbg version is 0.7.5

blp.bdib(ticker='ES1 Index', dt='2021-02-19').tail()

2021-02-21 20:47:26,647:xbbg.const.exch_info:ERROR:required info (allday + tz) cannot be found in ES1 Index ...
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-36-48f07c9cf297> in <module>
----> 1 blp.bdib(ticker='ES1 Index', dt='2021-02-19').tail()

~\miniconda3\envs\py3.8\lib\site-packages\xbbg\blp.py in bdib(ticker, dt, session, typ, **kwargs)
    217     ex_info = const.exch_info(ticker=ticker, **kwargs)
    218     if ex_info.empty:
--> 219         raise KeyError(f'Cannot find exchange info for {ticker}')
    220 
    221     ss_rng = process.time_range(

KeyError: 'Cannot find exchange info for ES1 Index'

BUG: Unable to pull index members field

Hello!

I am trying to pull a list of index members but some of the Dataframe standardization operations in the bdp function do not function correctly when there are duplicate entries in the index:

blp.bdp('RAY Index', 'INDX_MEMBERS')

Result (when trying to unstack): ValueError: Index contains duplicate entries, cannot reshape

res.head() at error:

      ticker         field Member Ticker and Exchange Code
0  RAY Index  INDX_MEMBERS                            A UN
1  RAY Index  INDX_MEMBERS                           AA UN
2  RAY Index  INDX_MEMBERS                          AAL UW
3  RAY Index  INDX_MEMBERS                          AAN UN
4  RAY Index  INDX_MEMBERS                         AAON UW

A50 Future trading in Singapore exchange day session is not returning anything

Hi,
Thanks for your effort in maintaining this great library. When I was trying to do some intraday analysis for the A50 Future (XU1 Index).
I am retriving data in the following way:

blp.bdib("XU1 Index", dt="2021-03-24", session="day", ref="FuturesSingapore")

Where the day session trading hour is supposed to be between 9am-16:35pm as it's defined in exch.yml.

FuturesSingapore:
  tz: Asia/Singapore
  allday: [1700, 445]
  day: [900, 1635]
  night: [1700, 445]

Nothing is returned, however, for the day session. Even when I set the session to be 'allday', it only returns the night session starting from 1700.

Thanks!

interval for subscription [Solved by modifying blp.py]

refer to the blpapi guide,
I can set the interval for subscription.
but xbbg does not pass the interval or any option argument to blpapi.

For example, If you want to set the interval 10 seconds,
You have to modify subscribe function of blp.py in xbbg
line# 532
sub_list.add(topic, flds, correlationId=cid) ---> sub_list.add(topic, flds, correlationId=cid, options='interval=10')

Can't get Pre and Post market data for US stocks

Hi,

I am using the following code to get the Pre-market data for QQQ (4am -9:30am EST):

tmp_df = blp.bdib('QQQ US Equity', dt=date, session='pre')
However, the above statement returns a blank dataframe. Same problem when i change the session to 'allday' or 'post'.

The statement however works correctly if i change the session to 'day' and gets the regular market session data (9:30am - 4pm EST).

Does anyone know how to get Trade/Bid/Ask data for US stocks in the Pre-market session?

Usage of BBG_ROOT to cache data

Can you please explain how the caching is supposed to work?

I set up BBG_ROOT as environment variable. However, when using bdh("SPX Index", "px_last"), nothing will be cached. There are no files in my BBG-ROOT folder.

Is BQR MSG1 supported?

Hi,
Congrats and thanks for the amazing work put so far! I'm wondering if the actual library would support the BQR excel function?

I've looked into WAPI and it seems to suggest that you can build a proxy using the intraday tick data.

Here is the snippet:

How do I emulate the BQR() Bloomberg formula in Microsoft Excel via the API interfaces?

To emulate the BQR formulas using the Desktop or Server API is a two step process. Under the hood of the formula in Microsoft Excel, these are the requests being made:

An Intraday Tick Request, which is using the //blp/refdata service and the "IntradayTickRequest" operation (i.e. request type).
A subscription to BID, ASK, BEST_BID and BEST_ASK for that same instrument. This uses the //blp/mktdata service.

For example, if you have the Microsoft Excel formula:

=BQR("IBM/ MSG1 Corp","-2D","","query=time,broker,bid,ask")

Under the hood, we are calculating 2 days back and determining the absolution startdate/time and setting the enddate/time to now. We are then setting the EventTypes property (i.e. element) to BID and also to ASK. For the "Broker", we are setting the "includeBrokerCodes" property to "true". Along with the security ("IBM/ MSG1 Corp"), this makes up our intraday tick request.

Once you get this data back, you will then subscribe to this security, along with BEST_BID, BEST_ASK, BID and ASK. Unfortunately, we do not provide an example of this, so it will be up to you to develop this. You can obtain most of the information you need from the IntradayTickExample and the SimpleSubscriptionExample examples in the Desktop API or the Server API SDK.

I was wondering if I could try it on with your blp.bdib using the /MSG1 source, but not sure if I need to modify anything on the root files. Any idea?

Thank you!

logging

Hi,

How can we access the log functionality and put everything in a file.

I know that i can use , log='debug' but how can i access the details and log it to a file?

thanks

Extending the list of overrides for BDH

Hi,

I am attempting to use the xbbg package to draw historic data with overrides. The below is retuning an empty df. (adjusting the timeout parameter does not change the result either)

-> blp.bdh(tickers="SPX Index",flds='BID',start_date="2021-03-30",end_date="2021-03-31",IntrRw=True)

I believe this is because the override IntrRw is not not added to the supported Elements. I have tried adding "IntrRw='IntrRw' , " to the ELEM_KEYS dict and "'IntrRw'," to the ELEMENTS array in overrides.py but then get the following error:

blpapi.exception.NotFoundException: Sub-element '(null)' does not exist. (0x0006000d)

Is there a way to add more overrides to the existing supported list?

[side note: The results of the above query can be achieved with blp.dbid() but that also appears not to accept overrides for querying other data]

Tick data from bdtick starts 1 minute late

I am in London (unsurprisingly) so GMT+1 at the time of writing. So NYC is GMT - 4.

Running this command (xbbg 7.5 on Python 3.7):

df = blp.bdtick('ESZ1 Index',datetime(2021,8,17),session='day',types=['BID','ASK'],ref='CME')
print(df.head())

And this is the output:

                          ESZ1 Index
                                 typ    value volume exch cond
2021-08-17 08:01:00-04:00        BID  4443.50      1    M  NaN
2021-08-17 08:01:00-04:00        BID  4443.75      1    M  NaN
2021-08-17 08:01:00-04:00        BID  4443.50      1    M  NaN
2021-08-17 08:01:00-04:00        BID  4443.75      1    M  NaN
2021-08-17 08:01:00-04:00        BID  4443.50      1    M  NaN

My exch.yml has:

CME:
  tz: America/New_York
  allday: [1800, 1700]
  day: [800, 1700]

So why does the tick data start a minute late?

"CUR_MARKET_CAP" currency override not implemented for none US stocks.

Good Morning,

Whilst working with the "CUR_MARKET_CAP" field in bds. When running the code:

for index, row in dataset.iterrows():
  row['Mkt Cap'] = blp.bds((row[key_column] + " Equity"), flds=["CUR_MKT_CAP", "CRNCY=USD"])

the market cap is returned in it's local currency, as opposed to standardised in USD. For context, the functionality which I am trying to emulate from the Excel Add-In is:

=@BDP($B7&" Equity", "INTERNAL_END_VALUE", "MARKET_DATA_OVERRIDE", "CUR_MKT_CAP", "CRNCY", "USD", "END_DATE_OVERRIDE", $I$1)

where B7 contains the ticker of interest and $I$1 contains date at which updates should stop.

bds produce duplicated results

Sample call:
'blp.bds(['AAPL US Equity', 'IBM US Equity', 'T US Equity', 'F US Equity'], flds = ['EQY_DVD_ADJUST_FACT'])'

This will produce duplicated output for same ticker. This bug can be fixed by altering blp.bds() and blp._bds_().

In bds():
request was created and passed to map(part, tickers). The map function will keep appending to request until all tickers are iterated.

As a consequence, in _bds_():

  • map for AAPL: request = ['AAPL']
  • map for IBM: request = ['AAPL', 'IBM']
  • map for T: request = ['AAPL', 'IBM', 'T'}
    ...

This can be fixed by moving process.create_request() call from bds() to inside the _bds_() function.

support for different authentication method

In core/conn.py, can the connect_bbg() method be modified to allow different connection method? I am connecting with bloomberg server api and I will need to manually modify the function to make it work. I think this can simply be done by allowing user to declare and pass a blpapi.session.Session object into the function.

blp.bdh returning different results with and without end_date (Solved)

fut_sym = "HC1 Index"
df_tmp = blp.bdh(fut_sym, "PX_LAST", start_date="2019-01-01", end_date="2019-12-31")
df_tmp.head()

yields

HC1 Index
--

9710.851
9739.567
9909.881
10030.685
10042.567

But when I ran this without the end date

df_tmp = blp.bdh(fut_sym, "PX_LAST", start_date="2019-01-01")
df_tmp.head()

yields

HC1 Index
--

9410.969
9438.798
9603.853
9720.926
9732.441


issue with generic commodity tickers >9th future

hi there.
i think there may be a bug for generic commodity ticker greater than the 9th future;

the following code will not work;
data=blp.bdtick('SB11 Comdty' , '2020-12-04')

workaround as follows DOES work;
data=blp.bdtick('SB11 Comdty' , '2020-12-04', ref='SB1 Comdty')

(same workaround as you suggested for 'C 1 Comdty', 'W 1 Comdty')

will use workaround for now, but wanted to bring to your attention...

many thanks

Traceback (most recent call last):

File "", line 1, in
bbg()

ERROR MESSAGE:
File "C:\m_PyFolioProject\Bloomberg_Intraday_data.py", line 118, in bbg
b=blp.bdtick(ticker, date,) # ref='SB1 Comdty')

File "c:\mypythonvenv\lib\site-packages\xbbg\blp.py", line 306, in bdtick
dt=dt, ticker=ticker, session=session, tz=exch.tz, **kwargs

File "c:\mypythonvenv\lib\site-packages\pandas\core\generic.py", line 5139, in getattr
return object.getattribute(self, name)

AttributeError: 'Series' object has no attribute 'tz'

BDS not downloading sometimes

Hi,

When I run the following command:

blp.bds(ISIN + " Corp", "ASW_CASHFLOWS")

In most cases it works properly (a bit slow), however in some specific cases (some custom bonds) I get empty dataframes:

Empty DataFrame
Columns: []
Index: []

These custom bonds work properly on excel.

I have tried with multiple fields as well as bds/bdp and although they work on excel they do not when using the library. Also I have tested multiple custom bonds and they all work perfectly fine. Is it possible that it needs some specific fields to be informed?

Requesting intradate in 5min,10min,30min etc

Good afternoon,

I've been working on the following code which give me 1 minute data in London hours between an interval:

df = blp.bdib('EURUSD Curncy', dt =('2021-08-10'),ref='CurrencyGeneric',typ ='TRADE')
df = df.tz_convert('Europe/London')
df = df.between_time('7:00:00', '10:00:00')

How can I request 5min data, or 10 min data or 30 min?

I much appreciate your help

Kind regards
Fredy

Will you implement CDR for bdh ?

Hi,

Are you considering adding CDR on bdh ? specifying CDR=5 forces bdh to return a 5 day a week dataset.
I know we can specify Days='W' but for certain chinese/taiwanese govies, bloomberg still returns previous-filled datasets unless we specify CDR=5D.

Thank you.

blp.bdh exit before fetching all the data

Hi,

Thank you for your package, Excellent work!!

I use your blp.bdh to fetch the data from bloomberg. I use it in the middle of a loop because i want to get data for more that the bloomberg limit per ticker so i split the data into chunks and run bdh in a loop.

It does end the loop before the program finish getting all the data.

can you please help?

xbbg requesting intraday interval

Hi,

I have 2 questions:

  1. Does anyone know if it is possible to request time intervals on intraday data in xbbg?

The following code gives me the whole day 1-minute intervals and I want to request, for instance, only from 7 am to 10 am.

df= blp.bdib(ticker='EURUSD Curncy', dt='2021-07-28',ref = 'CurrencyGeneric')

  1. I am in London, but the data I get, has the time from NY, how can I get data with London hours?

thanks

Unable to get Tick data for Commodity Securities

For example:

`from xbbg import blp
import pandas as pd
import numpy as np
import datetime

cur_dt = pd.Timestamp('today', tz='America/New_York')
recent = pd.bdate_range(end='today', periods=2, tz='America/New_York')
pre_dt = max(filter(lambda dd: dd < cur_dt, recent))
pre_dt.date()

blp.bdtick('NGQ20 Comdty', dt=pre_dt).tail()`

returns error: 'Unknown string format: 2020-08-03 None'

connecting error

Hi,
This is a very helpful package with clear instructions.

I received connecting error message with bloomberg api. Do you know what caused this issue?

XBBG: Adding New Mappings

I’ve been reading through your documentation for xbbg on https://pypi.org/project/xbbg/.

I’m confused following these instructions to add new mappings for more securities when pulling intraday data.

“To add new mappings, define BBG_ROOT in sys path and add assets.yml and exch.yml under BBG_ROOT/markets”.

When I open the .yml files for assets, exchanges and currencies in notepad the following instructions are also given:

“Override or expand this list by providing

os.environ['BBG_ROOT']/markets/assets.yml

os.environ['BBG_ROOT']/markets/ccy.yml

os.environ['BBG_ROOT']/markets/exch.yml “

Would you mind providing example code to show how exactly I’m supposed to do the above?

Many thanks,

Does xbbg cache each request?

Hi,
I am trying to understand when I make repeated calls like this:

blp.bdib("ESA Index", dt="2020-01-25", session="allday", ref="CME", cache=True)

vs

blp.bdib("ESA Index", dt="2020-01-25", session="allday", ref="CME")

Does it cache the result of these calls? Does the cache argument doing anything?

Thanks!

blp.bds is doing a weird rounding

If you try this:
blp.bds('ADP CHNG Index', "ECO_RELEASE_DT_LIST")

You will get some weird values that don't match what is showed in bloomberg's terminal.

The library pdblp seems to get right; the output of the next code matches bloomberg's terminal:
con.bulkref('ADP CHNG Index', 'ECO_RELEASE_DT_LIST')

The output should be a list of dates. The output of xbbg will contain '20180132', while the correct value is '20180131' as showed in bloomberg's terminal and by the pdblp library.

I was using xbbg v0.1.24; when I encountered this error I upgraded to v0.3.0 but the error persists.

XBBG mapping new tickers

hi there,
great package for simple access to BBG, many thanks!

i've adding many new commodity tickers to the assets/exch.yml files successfully.

e.g.
assets:

tickers: [SM] exch: CBT freq: Q is_fut: True
for SM1 Comdty

however, i have a number of tickers with a slightly "strange" format: W 1 Comdty, C 1 Comdty etc

if i try the below, mapping, it doesnt work. I've also tried [W ] (with a space after), which doesnt work either.

tickers: [W] exch: CBT freq: Q is_fut: True
i think its because of the space "W 1 Comdty", whereas the normal format for generic tickers seems to be "W1 Comdty"

any ideas would be much appreciated!!!

thanks

blp.bdib doesn't work for commodity futures

Tried to put "GC"/"GC1"/"GCZ" to assets.yml in Comdty, and used the following code to retrieve intraday bar data:

blp.bdib('GCZ1 Comdty', dt='2021-02-19', typ='TRADE')

But just returned empty data. Any advice?

Exist the Excel BPGE function in xbbg?

Congratulations on what a great job this library is.

I use the BPGE function in Excel and I would like to take the same information using xbbg. But I couldn't find the way to do it. Is it possible?

BPGE (Page Based Data) : Imports data from pages contributed to the Bloomberg by outside sources.

Thanks in advance.

async with blp.live

Trying to set up a live feed as shown in the Jupyter example unsuccessfully:

async for snap in blp.live(['ESA Index', 'NQA Index'], max_cnt=2):
    print(snap)

Tried to define an async function like this:

async def live_data():
    async for snap in blp.live(['ESA Index', 'NQA Index'], max_cnt=2):
        print(snap)

def run_data():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(live_data())
    loop.close()

run_data()

Still doesn't work for me. any help appreciated.

Null service handle error

Hi, thanks for the package.

I'm sure it's my fault but I've tried everything I can think of but I'm unable to get it working.

I couldn't find anyone with the same issue or anything related to blpapi that helped

I've installed according to instruction, matched the versions of the C++ SDK (3.14.1xx) to the python version 3.14 and moved the blpapi ddls to the correct place

When I try to run the examples I think xbbg.blp isnt able to establish a connection properly

67BCF766-BED3-45B3-8E5C-1898052E9EAA

I tried manually using blpapi to establish a connection which appears to work (despite the error returned, session.start() returns true)

77FC4667-AC9B-458D-9CD3-89AE1E66B1C5

I tried looking through conn.py but wasn't able to resolve it myself

Interestingly the live function appears to work

9275B359-6D95-4564-A434-BBB0D282A17D

Not sure what to try next, I've tried reinstalling from scratch but no luck

Thank you for any help, much appreciated

cannot specify server ip, only the port

You can specify the server port in kwargs but no the server ip, it s always localhost by default

in line 91 of conn.py if
sess_opts.setServerHost('localhost')

was replaced by
sess_opts.setServerHost(kwargs.get('server', SERVER))

and defining
SERVER= 'localhost'

we could pass the server in kwargs
with these changes the script below runs ok

from xbbg import blp
kwargs = {'server': 192.168.1.100', "port": 18194} # , "port" : 8194
print(blp.bdp(tickers='NVDA US Equity', flds=['Security_Name', 'GICS_Sector_Name'], **kwargs))
print('finished')

How to connect to Bloomberg

I need the script to run on an isolated server. It doesn't have Bloomberg installed. Is there a way to do it like that?

Multi Day Intraday bar data

Hi - Great library. thank you enormously.

currently blp.bdib() will only return intraday data for one date. it would be very useful to allow a dtFrom & dtTo and return data across multiple sessions.

i've hacked a suggestion via time_range() and blp.bdib(). see attached.

xbbg_idbib_multidayExample.txt

Close of the day

Hi, is there a way to obtain the correct close value of the day?
Indeed, the "last price" value does not really match with the close.
Thanks

BBG Tickers with whitespaces properly not working with blp.bdib

There are some instruments whose BBG ticker has one or more white spaces within the name of tickers, such as Corn futures("C 1 Comdty") or Soybean Futures("S 1 Comdty"). If I add those kind of instrument's ticker into markets/assets.yml, simply blp.bdib function doesn't recognize them. I need to put trailing whitespace at the end of list items but when reading yml files, the function seem to ignores the trailing whitespace. In case of "S 1 Comdty", I tried putting "S " or S\ or S"\ " as below but any of those are not working. How can I insert tickers with whitespaces into markets/assets.yml?

Comdty:
  - tickers: [CL, "S ", XB, GC, PL, HO, NG, PA]
    exch: NYME
    freq: M
    is_fut: True

Error Messages are like this: 2019-11-25 15:44:24,982:xbbg.const.exch_info:ERROR:required exchange info cannot be found in S 1 Comdty ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.