<jupyter_start><jupyter_text>Reference Data `BDP` and `BDS`<jupyter_code>blp.__version__
blp.bdp('AAPL US Equity', flds=['Security_Name', 'Last_Price'])
blp.bdp('6758 JP Equity', flds='Crncy_Adj_Mkt_Cap', Eqy_Fund_Crncy='USD')
holders = blp.bds('AMZN US Equity', flds='All_Holders_Public_Filings', cache=True)
(
    holders
    .loc[:, ~holders.columns.str.contains(
        f'holder_id|portfolio_name|change|number|'
        f'metro|percent_of_portfolio|source'
    )]
    .rename(
        index=lambda tkr: tkr.replace(' Equity', ''),
        columns={
            'holder_name_': 'holder',
            'position_': 'position',
            'filing_date__': 'filing_dt',
            'percent_outstanding': 'pct_out',
            'insider_status_': 'insider',
        }
    )
).head()
blp.dividend('SPY US Equity', start_date='2019')
blp.earning('FB US Equity', Eqy_Fund_Year=2018, Number_Of_Periods=2)<jupyter_output><empty_output><jupyter_text>Historical Data Historical data with Excel compatible overrides<jupyter_code>blp.bdh(
    tickers='SHCOMP Index', flds=['high', 'low', 'last_price'],
    start_date='2019-11', end_date='2020', Per='W', Fill='P', Days='A',
)<jupyter_output><empty_output><jupyter_text>Dividend / split adjustments<jupyter_code>pd.concat([
    blp.bdh(
        'AAPL US Equity', 'Px_Last', '20140605', '20140610',
        CshAdjNormal=True, CshAdjAbnormal=True, CapChg=True
    ).rename(columns={'Px_Last': 'Px_Adj'}),
    blp.bdh(
        'AAPL US Equity', 'Px_Last', '20140605', '20140610',
        CshAdjNormal=False, CshAdjAbnormal=False, CapChg=False
    ).rename(columns={'Px_Last': 'Px_Raw'}),
], axis=1)<jupyter_output><empty_output><jupyter_text>Intraday Bars<jupyter_code>cur_dt = pd.Timestamp('today', tz='America/New_York').date()
recent = pd.bdate_range(end=cur_dt, periods=2, tz='America/New_York')
pre_dt = max(filter(lambda dd: dd < cur_dt, recent))
pre_dt.date()
blp.bdib('QQQ US Equity', dt=pre_dt, session='day').tail()
blp.bdib('388 HK Equity', dt=pre_dt, session='am_open_7')<jupyter_output><empty_output><jupyter_text>Intraday Tick Data<jupyter_code>blp.bdtick('QQQ US Equity', dt=pre_dt).tail(10)<jupyter_output><empty_output><jupyter_text>Equity Screen `BEQS`<jupyter_code>blp.beqs('Core Capital Ratios', typ='GLOBAL').iloc[:5, :6]<jupyter_output><empty_output><jupyter_text>Subscription `blp.live` will yield market data as `dict`<jupyter_code>async for snap in blp.live(['ESA Index', 'NQA Index'], info=const.LIVE_INFO, max_cnt=2):
    print(snap)<jupyter_output>{'TICKER': 'NQA Index', 'FIELD': 'LAST_PRICE', 'MKTDATA_EVENT_TYPE': 'SUMMARY', 'MKTDATA_EVENT_SUBTYPE': 'INITPAINT', 'BID': 12882.25, 'ASK': 12887.0, 'LAST_PRICE': 12885.5, 'VOLUME': 277076, 'MID': 12884.63, 'SPREAD_BA': 4.75, 'IS_DELAYED_STREAM': True, 'REALTIME_PERCENT_BID_ASK_SPREAD': 0.03690000000000282, 'RT_PX_CHG_PCT_1D': 0.3425999879837036}
{'TICKER': 'ESA Index', 'FIELD': 'LAST_PRICE', 'MKTDATA_EVENT_TYPE': 'SUMMARY', 'MKTDATA_EVENT_SUBTYPE': 'INITPAINT', 'BID': 3748.5, 'ASK': 3749.0, 'LAST_PRICE': 3748.75, 'VOLUME': 917212, 'MID': 3748.75, 'SPREAD_BA': 0.5, 'IS_DELAYED_STREAM': True, 'REALTIME_PERCENT_BID_ASK_SPREAD': 0.013300000000000978, 'RT_PX_CHG_PCT_1D': 0.6578999757766724}<jupyter_text>Pipelines<jupyter_code>fx = blp.bdib('JPY Curncy', dt=pre_dt)
jp = pd.concat([
    blp.bdib(ticker, dt=pre_dt, session='day')
    for ticker in ['7974 JP Equity', '9984 JP Equity']
], axis=1)
jp.tail()<jupyter_output><empty_output><jupyter_text>Get `close` prices and convert to USD<jupyter_code>prices = (
    jp
    .pipe(pipeline.get_series, col='close')
    .pipe(pipeline.apply_fx, fx=fx)
    .tz_convert('Asia/Tokyo')
)
prices.tail()<jupyter_output><empty_output><jupyter_text>Customized Pipelines VWAP for intraday bar data<jupyter_code>def vwap(data: pd.DataFrame, fx=None, name=None) -> pd.Series:
    return pd.Series({
        ticker: (
            data[ticker][['close', 'volume']].prod(axis=1).sum()
            if fx is None else (
                data[ticker].close
                .pipe(pipeline.apply_fx, fx)
                .close
                .mul(data[ticker].volume)
                .sum()
            )
        ) / data[ticker].volume.sum()
        for ticker in data.columns.get_level_values(0).unique()
    }, name=name)<jupyter_output><empty_output><jupyter_text>VWAP in local currency<jupyter_code>jp.pipe(vwap, name=jp.index[-1].date())<jupyter_output><empty_output><jupyter_text>VWAP in USD<jupyter_code>jp.pipe(vwap, fx=fx, name=jp.index[-1].date())<jupyter_output><empty_output><jupyter_text>Total traded volume as of time in day for past few days<jupyter_code>jp_hist = pd.concat([
    pd.concat([
        blp.bdib(ticker, dt=dt, session='day')
        for ticker in ['7974 JP Equity', '9984 JP Equity']
    ], axis=1)
    for dt in pd.bdate_range(end='today', periods=10)[:-1]
], sort=False)
unique(jp_hist.index.date)
def drop_zeros(data: pd.DataFrame) -> pd.DataFrame:
    return (
        data
        .replace(0, np.nan)
        .dropna(how='all')
        .replace(np.nan, 0)
    )
def traded_volume(data: pd.DataFrame, asof: str) -> pd.DataFrame:
    return (
        data
        .pipe(pipeline.get_series, col='volume')
        .between_time('0:00', asof)
        .resample('B')
        .sum()
        .pipe(drop_zeros)
    )
jp_hist.pipe(traded_volume, asof='10:00')
jp_hist.pipe(traded_volume, asof='11:00')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16438609467455623, 'fraction_numerical': 0.04474852071005917, 'mean_word_length': 4.616822429906542, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '145464', 'license': 'Apache-2.0', 'n_tokens_mistral': 2362, 'n_tokens_neox': 2163, 'n_words': 338, 'path': 'Examples.ipynb', 'repo_name': 'hceh/xbbg', 'size': '5408'}