{"id":37072000,"url":"https://github.com/marekozana/polars-bloomberg","last_synced_at":"2026-01-14T08:27:11.346Z","repository":{"id":267165190,"uuid":"896758112","full_name":"MarekOzana/polars-bloomberg","owner":"MarekOzana","description":"Python library providing a Polars DataFrame interface for easy and intuitive access to the Bloomberg API","archived":false,"fork":false,"pushed_at":"2025-12-21T16:12:46.000Z","size":9443,"stargazers_count":11,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-12-29T18:17:49.188Z","etag":null,"topics":["bloomberg-api","bql","finance","polars-dataframe","python","quantitative-finance"],"latest_commit_sha":null,"homepage":"https://marekozana.github.io/polars-bloomberg/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarekOzana.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-01T08:17:01.000Z","updated_at":"2025-12-21T16:12:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"bf9a67a1-518e-4878-8655-cca42483b37b","html_url":"https://github.com/MarekOzana/polars-bloomberg","commit_stats":null,"previous_names":["marekozana/polars-bloomberg"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/MarekOzana/polars-bloomberg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarekOzana%2Fpolars-bloomberg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarekOzana%2Fpolars-bloomberg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarekOzana%2Fpolars-bloomberg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarekOzana%2Fpolars-bloomberg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarekOzana","download_url":"https://codeload.github.com/MarekOzana/polars-bloomberg/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarekOzana%2Fpolars-bloomberg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28413966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:16:59.381Z","status":"ssl_error","status_checked_at":"2026-01-14T08:13:45.490Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bloomberg-api","bql","finance","polars-dataframe","python","quantitative-finance"],"created_at":"2026-01-14T08:27:10.721Z","updated_at":"2026-01-14T08:27:11.332Z","avatar_url":"https://github.com/MarekOzana.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD033 MD041 --\u003e\n\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"https://raw.githubusercontent.com/MarekOzana/polars-bloomberg/main/assets/polars-bloomberg-logo.jpg\" alt=\"Polars Bloomberg Logo\"\u003e\n\n# Polars + Bloomberg Open API\n\n[![PyPI version](https://img.shields.io/pypi/v/polars-bloomberg.svg?color=5FA8FF)](https://pypi.org/project/polars-bloomberg/)\n[![Python versions](https://img.shields.io/pypi/pyversions/polars-bloomberg.svg)](https://pypi.org/project/polars-bloomberg/)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/polars-bloomberg?color=4c1)](https://pypistats.org/packages/polars-bloomberg)\n[![Docs](https://img.shields.io/badge/docs-site-1E3A8A?logo=readthedocs\u0026logoColor=white)](https://marekozana.github.io/polars-bloomberg/)\n\u003cbr\u003e\n[![Tests](https://github.com/MarekOzana/polars-bloomberg/actions/workflows/python-package.yml/badge.svg)](https://github.com/MarekOzana/polars-bloomberg/actions/workflows/python-package.yml)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)\n\n\u003c/div\u003e\n\u003c!-- markdownlint-enable MD033 MD041 --\u003e\n\n**polars-bloomberg** is a Python library that extracts Bloomberg's financial data directly into [Polars](https://www.pola.rs/) DataFrames.\nIf you’re a quant financial analyst, data scientist, or quant developer working in capital markets, this library makes it easy to fetch, transform, and analyze Bloomberg data right in Polars—offering speed, efficient memory usage, and a lot of fun to use!\n\n**Why use polars-bloomberg?**\n\n- **User-Friendly Functions:** Shortcuts like `bdp()`, `bdh()`, and `bql()` (inspired by Excel-like Bloomberg calls) let you pull data with minimal boilerplate.\n- **High-Performance Analytics:** Polars is a lightning-fast DataFrame library. Combined with Bloomberg’s rich dataset, you get efficient data retrieval and minimal memory footprint\n- **No Pandas Dependency:** Enjoy a clean integration that relies solely on Polars for speed and simplicity.\n\n---\n\n## Table of Contents\n\n1. [Introduction](#introduction)\n2. [Prerequisites](#prerequisites)\n3. [Installation](#installation)\n4. [Quick Start](#quick-start)\n5. [Core Methods](#core-methods)\n    - [BDP (Bloomberg Data Point)](#bdp)\n    - [BDH (Bloomberg Data History)](#bdh)\n    - [BDIB (Bloomberg Data Intraday Bar)](#bdib)\n    - [BSRCH (Bloomberg Search)](#bsrch)\n    - [BQL (Bloomberg Query Language)](#bql) \u003cdetails\u003e\u003csummary\u003eBQL Examples\u003c/summary\u003e\n        - [Single Item and Single Security](#1-basic-example-single-item-and-single-security)\n        - [Multiple Securities with Single Item](#2-multiple-securities-with-a-single-item)\n        - [Multiple Items](#3-multiple-items)\n        - [SRCH](#4-advanced-example-screening-securities)\n        - [Aggregation (AVG)](#average-pe-per-sector)\n        - [Axes](#axes)\n        - [Axes with All Columns](#axes-with-all-columns)\n        - [Segments](#segments)\n        - [Average Spread per Bucket](#average-issuer-oas-spread-per-maturity-bucket)\n        - [Technical Analysis Screening](#technical-analysis-stocks-with-20d-ema--200d-ema-and-rsi--53)\n        - [Bonds Universe from Equity](#bond-universe-from-equity-ticker)\n        - [Bonds Total Return](#bonds-total-returns)\n        - [Maturity Wall for US HY](#maturity-wall-for-us-hy-bonds)\n        \u003c/details\u003e\n6. [Additional Documentation and Resources](#additional-documentation--resources)\n\n## Introduction\nWorking with Bloomberg data in Python often feels more complicated than using their well-known Excel interface.\nGreat projects like [blp](https://github.com/matthewgilbert/blp), [xbbg](https://github.com/alpha-xone/xbbg), and [pdblp](https://github.com/matthewgilbert/pdblp) have made this easier by pulling data directly into pandas.\n\nWith polars-bloomberg, you can enjoy the speed and simplicity of [Polars](https://www.pola.rs/) DataFrames—accessing both familiar Excel-style calls (`bdp`, `bdh` ,`bdip`, `bsrch`) and advanced `bql` queries—without extra pandas conversions.\n\nFor detailed documentation and function references, visit the documentation site [https://marekozana.github.io/polars-bloomberg](https://marekozana.github.io/polars-bloomberg/).\n\nI hope you enjoy using it as much as I had fun building it!\n\n\n## Prerequisites\n\n- **Bloomberg Access:** A valid Bloomberg terminal license.\n- **Bloomberg Python API:** The `blpapi` library must be installed. See the [Bloomberg API Library](https://www.bloomberg.com/professional/support/api-library/) for guidance.\n- **Python Version:** Python 3.12+ recommended.\n\n## Installation\n\n```bash\npip install polars-bloomberg\n```\n\n# Quick Start\n\"Hello World\" Example (under 1 minute):\n```python\nfrom polars_bloomberg import BQuery\n\n# Fetch the latest price for Apple (AAPL US Equity)\nwith BQuery() as bq:\n    df = bq.bdp([\"AAPL US Equity\"], [\"PX_LAST\"])\n    print(df)\n\n┌────────────────┬─────────┐\n│ security       ┆ PX_LAST │\n│ ---            ┆ ---     │\n│ str            ┆ f64     │\n╞════════════════╪═════════╡\n│ AAPL US Equity ┆ 248.13  │\n└────────────────┴─────────┘\n```\nWhat this does:\n- Establishes a Bloomberg connection using the context manager.\n- Retrieves the last price of Apple shares.\n- Returns the result as a Polars DataFrame.\n\nIf you see a price in `df`, your setup is working 🤩!!!\n\n## Core Methods\n`BQuery` is your main interface. Using a context manager ensures the connection opens and closes cleanly. Within this session, you can use:\n- `bq.bdp()` for Bloomberg Data Points (single-value fields).\n- `bq.bdh()` for Historical Data (time series).\n- `bq.bql()` for complex Bloomberg Query Language requests.\n- `bq.bsrch()` for saved custom SRCH searches and BI templates.\n- `bq.bdip()` for intraday bars\n\n## BDP\nUse Case: Fetch the latest single-value data points (like last price, currency, or descriptive fields).\n\n### Example: Fetching the Last Price \u0026 Currency of Apple and SEB\n```python\nwith BQuery() as bq:\n    df = bq.bdp([\"AAPL US Equity\", \"SEBA SS Equity\"], [\"PX_LAST\", \"CRNCY\"])\n    print(df)\n\n┌────────────────┬─────────┬───────┐\n│ security       ┆ PX_LAST ┆ CRNCY │\n│ ---            ┆ ---     ┆ ---   │\n│ str            ┆ f64     ┆ str   │\n╞════════════════╪═════════╪═══════╡\n│ AAPL US Equity ┆ 248.13  ┆ USD   │\n│ SEBA SS Equity ┆ 155.2   ┆ SEK   │\n└────────────────┴─────────┴───────┘\n```\n\n\u003cdetails\u003e\u003csummary\u003eExpand for more BDP Examples\u003c/summary\u003e\n\n### BDP with different column types\n\n`polars-bloomberg` correctly infers column type as shown in this example:\n\n```python\nwith BQuery() as bq:\n    df = bq.bdp([\"XS2930103580 Corp\", \"USX60003AC87 Corp\"],\n                [\"SECURITY_DES\", \"YAS_ZSPREAD\", \"CRNCY\", \"NXT_CALL_DT\"])\n\n┌───────────────────┬────────────────┬─────────────┬───────┬─────────────┐\n│ security          ┆ SECURITY_DES   ┆ YAS_ZSPREAD ┆ CRNCY ┆ NXT_CALL_DT │\n│ ---               ┆ ---            ┆ ---         ┆ ---   ┆ ---         │\n│ str               ┆ str            ┆ f64         ┆ str   ┆ date        │\n╞═══════════════════╪════════════════╪═════════════╪═══════╪═════════════╡\n│ XS2930103580 Corp ┆ SEB 6 3/4 PERP ┆ 304.676112  ┆ USD   ┆ 2031-11-04  │\n│ USX60003AC87 Corp ┆ NDAFH 6.3 PERP ┆ 292.477506  ┆ USD   ┆ 2031-09-25  │\n└───────────────────┴────────────────┴─────────────┴───────┴─────────────┘\n```\n\n### BDP with overrides\nUser can submit list of tuples with overrides\n```python\nwith BQuery() as bq:\n    df = bq.bdp(\n        [\"IBM US Equity\"],\n        [\"PX_LAST\", \"CRNCY_ADJ_PX_LAST\"],\n        overrides=[(\"EQY_FUND_CRNCY\", \"SEK\")],\n    )\n\n┌───────────────┬─────────┬───────────────────┐\n│ security      ┆ PX_LAST ┆ CRNCY_ADJ_PX_LAST │\n│ ---           ┆ ---     ┆ ---               │\n│ str           ┆ f64     ┆ f64               │\n╞═══════════════╪═════════╪═══════════════════╡\n│ IBM US Equity ┆ 230.82  ┆ 2535.174          │\n└───────────────┴─────────┴───────────────────┘\n```\n\n### BDP with date overrides\nOverrides for dates has to be in format YYYYMMDD\n```python\nwith BQuery() as bq:\n    df = bq.bdp([\"USX60003AC87 Corp\"], [\"SETTLE_DT\"],\n                overrides=[(\"USER_LOCAL_TRADE_DATE\", \"20241014\")])\n\n┌───────────────────┬────────────┐\n│ security          ┆ SETTLE_DT  │\n│ ---               ┆ ---        │\n│ str               ┆ date       │\n╞═══════════════════╪════════════╡\n│ USX60003AC87 Corp ┆ 2024-10-15 │\n└───────────────────┴────────────┘\n```\n\n```python\nwith BQuery() as bq:\n    df = bq.bdp(['USDSEK Curncy', 'SEKCZK Curncy'],\n                ['SETTLE_DT', 'PX_LAST'],\n                overrides=[('REFERENCE_DATE', '20200715')]\n               )\n\n┌───────────────┬────────────┬─────────┐\n│ security      ┆ SETTLE_DT  ┆ PX_LAST │\n│ ---           ┆ ---        ┆ ---     │\n│ str           ┆ date       ┆ f64     │\n╞═══════════════╪════════════╪═════════╡\n│ USDSEK Curncy ┆ 2020-07-17 ┆ 10.9778 │\n│ SEKCZK Curncy ┆ 2020-07-17 ┆ 2.1698  │\n└───────────────┴────────────┴─────────┘\n```\n\n\u003c/details\u003e\n\n## BDH\nUse Case: Retrieve historical data over a date range, such as daily closing prices or volumes.\n```python\nwith BQuery() as bq:\n    df = bq.bdh(\n        [\"TLT US Equity\"],\n        [\"PX_LAST\"],\n        start_date=date(2019, 1, 1),\n        end_date=date(2019, 1, 7),\n    )\n    print(df)\n\n┌───────────────┬────────────┬─────────┐\n│ security      ┆ date       ┆ PX_LAST │\n│ ---           ┆ ---        ┆ ---     │\n│ str           ┆ date       ┆ f64     │\n╞═══════════════╪════════════╪═════════╡\n│ TLT US Equity ┆ 2019-01-02 ┆ 122.15  │\n│ TLT US Equity ┆ 2019-01-03 ┆ 123.54  │\n│ TLT US Equity ┆ 2019-01-04 ┆ 122.11  │\n│ TLT US Equity ┆ 2019-01-07 ┆ 121.75  │\n└───────────────┴────────────┴─────────┘\n```\n\n\u003cdetails\u003e\u003csummary\u003eExpand for more BDH examples\u003c/summary\u003e\n\n### BDH with multiple securities / fields\n```python\nwith BQuery() as bq:\n    df = bq.bdh(\n        securities=[\"SPY US Equity\", \"TLT US Equity\"],\n        fields=[\"PX_LAST\", \"VOLUME\"],\n        start_date=date(2019, 1, 1),\n        end_date=date(2019, 1, 10),\n        options={\"adjustmentSplit\": True},\n    )\n    print(df)\n\nshape: (14, 4)\n┌───────────────┬────────────┬─────────┬──────────────┐\n│ security      ┆ date       ┆ PX_LAST ┆ VOLUME       │\n│ ---           ┆ ---        ┆ ---     ┆ ---          │\n│ str           ┆ date       ┆ f64     ┆ f64          │\n╞═══════════════╪════════════╪═════════╪══════════════╡\n│ SPY US Equity ┆ 2019-01-02 ┆ 250.18  ┆ 1.26925199e8 │\n│ SPY US Equity ┆ 2019-01-03 ┆ 244.21  ┆ 1.44140692e8 │\n│ SPY US Equity ┆ 2019-01-04 ┆ 252.39  ┆ 1.42628834e8 │\n│ SPY US Equity ┆ 2019-01-07 ┆ 254.38  ┆ 1.031391e8   │\n│ SPY US Equity ┆ 2019-01-08 ┆ 256.77  ┆ 1.02512587e8 │\n│ …             ┆ …          ┆ …       ┆ …            │\n│ TLT US Equity ┆ 2019-01-04 ┆ 122.11  ┆ 1.2970226e7  │\n│ TLT US Equity ┆ 2019-01-07 ┆ 121.75  ┆ 8.498104e6   │\n│ TLT US Equity ┆ 2019-01-08 ┆ 121.43  ┆ 7.737103e6   │\n│ TLT US Equity ┆ 2019-01-09 ┆ 121.24  ┆ 9.349245e6   │\n│ TLT US Equity ┆ 2019-01-10 ┆ 120.46  ┆ 8.22286e6    │\n└───────────────┴────────────┴─────────┴──────────────┘\n```\n\n### BDH with options - periodicitySelection: Monthly\n```python\nwith BQuery() as bq:\n    df = bq.bdh(['AAPL US Equity'],\n                ['PX_LAST'],\n                start_date=date(2019, 1, 1),\n                end_date=date(2019, 3, 29),\n                options={\"periodicitySelection\": \"MONTHLY\"})\n\n┌────────────────┬────────────┬─────────┐\n│ security       ┆ date       ┆ PX_LAST │\n│ ---            ┆ ---        ┆ ---     │\n│ str            ┆ date       ┆ f64     │\n╞════════════════╪════════════╪═════════╡\n│ AAPL US Equity ┆ 2019-01-31 ┆ 41.61   │\n│ AAPL US Equity ┆ 2019-02-28 ┆ 43.288  │\n│ AAPL US Equity ┆ 2019-03-29 ┆ 47.488  │\n└────────────────┴────────────┴─────────┘\n```\n\u003c/details\u003e\n\n\n## BDIB\nUse Case: Retrieve intraday bars (1- to 1440-minute intervals) over a precise intraday\nwindow without managing tick aggregation yourself.\n\n```python\nwith BQuery() as bq:  # set debug=False for normal usage\n    df = bq.bdib(\n        \"OMX Index\",\n        event_type=\"TRADE\",\n        interval=60,\n        start_datetime=datetime(2025, 11, 5),\n        end_datetime=datetime(2025, 11, 5, 12),\n    )\n    print(df)\n```\n\nOutput:\n```\nshape: (4, 9)\n┌───────────┬──────────────┬──────────┬──────────┬───┬──────────┬────────┬───────────┬───────┐\n│ security  ┆ time         ┆ open     ┆ high     ┆ … ┆ close    ┆ volume ┆ numEvents ┆ value │\n│ ---       ┆ ---          ┆ ---      ┆ ---      ┆   ┆ ---      ┆ ---    ┆ ---       ┆ ---   │\n│ str       ┆ datetime[μs] ┆ f64      ┆ f64      ┆   ┆ f64      ┆ i64    ┆ i64       ┆ f64   │\n╞═══════════╪══════════════╪══════════╪══════════╪═══╪══════════╪════════╪═══════════╪═══════╡\n│ OMX Index ┆ 2025-11-05   ┆ 2726.603 ┆ 2742.014 ┆ … ┆ 2739.321 ┆ 0      ┆ 3591      ┆ 0.0   │\n│           ┆ 08:00:00     ┆          ┆          ┆   ┆          ┆        ┆           ┆       │\n│ OMX Index ┆ 2025-11-05   ┆ 2739.466 ┆ 2739.706 ┆ … ┆ 2733.836 ┆ 0      ┆ 3600      ┆ 0.0   │\n│           ┆ 09:00:00     ┆          ┆          ┆   ┆          ┆        ┆           ┆       │\n│ OMX Index ┆ 2025-11-05   ┆ 2733.747 ┆ 2734.827 ┆ … ┆ 2731.724 ┆ 0      ┆ 3600      ┆ 0.0   │\n│           ┆ 10:00:00     ┆          ┆          ┆   ┆          ┆        ┆           ┆       │\n│ OMX Index ┆ 2025-11-05   ┆ 2731.721 ┆ 2742.015 ┆ … ┆ 2741.185 ┆ 0      ┆ 3600      ┆ 0.0   │\n│           ┆ 11:00:00     ┆          ┆          ┆   ┆          ┆        ┆           ┆       │\n└───────────┴──────────────┴──────────┴──────────┴───┴──────────┴────────┴───────────┴───────┘\n```\n\nEach row is a 60-minute bar built from TRADE events, and the `time` column is returned\nin UTC (matching Bloomberg's wide format).\n\n## BSRCH\nUse Case: Excel-style searches (SRCH/BI domains). Supports overrides such as `LIMIT` and custom keys (e.g., `BIKEY`).\n\n### Small example: two COCO bonds (limit = 2)\n```python\nwith BQuery() as bq:\n    df = bq.bsrch(\"FI:SRCHEX.@COCO\", overrides={\"LIMIT\": 2})\n    print(df)\n```\nExample output:\n```\nshape: (2, 1)\n┌──────────────┐\n│ id           │\n│ ---          │\n│ str          │\n╞══════════════╡\n│ DA785784 Corp│\n│ DA773901 Corp│\n└──────────────┘\n```\n\n### Larger example: BI template (BI:TPD) with BIKEY and LIMIT\n```python\nwith BQuery() as bq:\n    df = bq.bsrch(\n        \"BI:TPD\",\n        overrides={\n            \"BIKEY\": \"DKOCVGXJVU8II8M90W8JSQEKR\",\n            \"LIMIT\": 20000,  # avoid ReachMax warning\n        },\n    )\n    print(df.head())\n```\nExample output (truncated):\n```\nshape: (16, 6)\n┌──────────┬──────────┬─────────┬──────────┬──────────┬─────────┐\n│ Main_Cat ┆ Bclass3_ ┆ Category┆ 06/30/20 ┆ 03/31/20 ┆ 12/31/20│\n│ ...      ┆ ...      ┆ ...     ┆ 25       ┆ 25       ┆ 24      │\n│ str      ┆ str      ┆ str     ┆ f64      ┆ f64      ┆ f64     │\n╞══════════╪══════════╪═════════╪══════════╪══════════╪═════════╡\n│ Leverage ┆ Non-Fin… ┆ B       ┆ 3.956051 ┆ 4.118212 ┆ 4.269732│\n│ …        ┆ …        ┆ …       ┆ …        ┆ …        ┆ …       │\n└──────────┴──────────┴─────────┴──────────┴──────────┴─────────┘\n```\n\n## BQL\n*Use Case*: Run more advanced queries to screen securities, calculate analytics (like moving averages), or pull fundamental data with complex conditions.\n\n*Returns*: The `bql()` method returns a `BqlResult` object, which:\n- Acts like a list of Polars DataFrames (one for each item in BQL `get` statement).\n- Provides a `.combine()` method to merge DataFrames on common columns.\n\n### 1. Basic Example: Single Item and Single Security\n```python\n# Fetch the last price of IBM stock\nwith BQuery() as bq:\n    results = bq.bql(\"get(px_last) for(['IBM US Equity'])\")\n    print(results[0])  # Access the first DataFrame\n```\nOutput:\n```python\n┌───────────────┬─────────┬────────────┬──────────┐\n│ ID            ┆ px_last ┆ DATE       ┆ CURRENCY │\n│ ---           ┆ ---     ┆ ---        ┆ ---      │\n│ str           ┆ f64     ┆ date       ┆ str      │\n╞═══════════════╪═════════╪════════════╪══════════╡\n│ IBM US Equity ┆ 230.82  ┆ 2024-12-14 ┆ USD      │\n└───────────────┴─────────┴────────────┴──────────┘\n```\n\n### 2. Multiple Securities with a Single Item\n```python\n# Fetch the last price for IBM and SEB\nwith BQuery() as bq:\n    results = bq.bql(\"get(px_last) for(['IBM US Equity', 'SEBA SS Equity'])\")\n    print(results[0])\n```\nOutput:\n```python\n┌────────────────┬─────────┬────────────┬──────────┐\n│ ID             ┆ px_last ┆ DATE       ┆ CURRENCY │\n│ ---            ┆ ---     ┆ ---        ┆ ---      │\n│ str            ┆ f64     ┆ date       ┆ str      │\n╞════════════════╪═════════╪════════════╪══════════╡\n│ IBM US Equity  ┆ 230.82  ┆ 2024-12-14 ┆ USD      │\n│ SEBA SS Equity ┆ 155.2   ┆ 2024-12-14 ┆ SEK      │\n└────────────────┴─────────┴────────────┴──────────┘\n```\n\n### 3. Multiple Items\nWhen querying for multiple items, `bql()` returns a list of DataFrames\n```python\n# Fetch name and last price of IBM (two items)\nwith BQuery() as bq:\n    results = bq.bql(\"get(name, px_last) for(['IBM US Equity'])\")\n```\nOutput:\n```python\n\u003e\u003e\u003e print(len(results))  # 2 DataFrames\nn=2\n\n\u003e\u003e\u003e print(results[0])    # First DataFrame: 'name'\n┌───────────────┬────────────────────────────────┐\n│ ID            ┆ name                           │\n│ ---           ┆ ---                            │\n│ str           ┆ str                            │\n╞═══════════════╪════════════════════════════════╡\n│ IBM US Equity ┆ International Business Machine │\n└───────────────┴────────────────────────────────┘\n\n\u003e\u003e\u003e print(results[1])    # Second DataFrame: 'px_last'\n┌───────────────┬─────────┬────────────┬──────────┐\n│ ID            ┆ px_last ┆ DATE       ┆ CURRENCY │\n│ ---           ┆ ---     ┆ ---        ┆ ---      │\n│ str           ┆ f64     ┆ date       ┆ str      │\n╞═══════════════╪═════════╪════════════╪══════════╡\n│ IBM US Equity ┆ 230.82  ┆ 2024-12-14 ┆ USD      │\n└───────────────┴─────────┴────────────┴──────────┘\n```\n\n#### Combining Results\n```python\n\u003e\u003e\u003e combined_df = results.combine()\n\u003e\u003e\u003e print(combined_df)\n```\nOutput:\n```python\n┌───────────────┬────────────────────────────────┬─────────┬────────────┬──────────┐\n│ ID            ┆ name                           ┆ px_last ┆ DATE       ┆ CURRENCY │\n│ ---           ┆ ---                            ┆ ---     ┆ ---        ┆ ---      │\n│ str           ┆ str                            ┆ f64     ┆ date       ┆ str      │\n╞═══════════════╪════════════════════════════════╪═════════╪════════════╪══════════╡\n│ IBM US Equity ┆ International Business Machine ┆ 230.82  ┆ 2024-12-14 ┆ USD      │\n└───────────────┴────────────────────────────────┴─────────┴────────────┴──────────┘\n```\n\n### 4. Advanced Example: Screening Securities\nFind list of SEB and Handelsbanken's AT1 bonds and print their names, duration and Z-Spread.\n```python\nquery=\"\"\"\n    let(#dur=duration(duration_type=MODIFIED);\n        #zsprd=spread(spread_type=Z);)\n    get(name(), #dur, #zsprd)\n    for(filter(screenresults(type=SRCH, screen_name='@COCO'),\n            ticker in ['SEB', 'SHBASS']))\n\"\"\"\n\nwith BQuery() as bq:\n    results = bq.bql(query)\n    combined_df = results.combine()\n    print(combined_df)\n```\nOutput:\n```python\n┌───────────────┬─────────────────┬──────┬────────────┬────────┐\n│ ID            ┆ name()          ┆ #dur ┆ DATE       ┆ #zsprd │\n│ ---           ┆ ---             ┆ ---  ┆ ---        ┆ ---    │\n│ str           ┆ str             ┆ f64  ┆ date       ┆ f64    │\n╞═══════════════╪═════════════════╪══════╪════════════╪════════╡\n│ BW924993 Corp ┆ SEB 6 ⅞ PERP    ┆ 2.23 ┆ 2024-12-16 ┆ 212.0  │\n│ YV402592 Corp ┆ SEB Float PERP  ┆ 0.21 ┆ 2024-12-16 ┆ 233.0  │\n│ ZQ349286 Corp ┆ SEB 5 ⅛ PERP    ┆ 0.39 ┆ 2024-12-16 ┆ 186.0  │\n│ ZO703315 Corp ┆ SHBASS 4 ⅜ PERP ┆ 1.95 ┆ 2024-12-16 ┆ 213.0  │\n│ ZO703956 Corp ┆ SHBASS 4 ¾ PERP ┆ 4.94 ┆ 2024-12-16 ┆ 256.0  │\n│ YU819930 Corp ┆ SEB 6 ¾ PERP    ┆ 5.37 ┆ 2024-12-16 ┆ 309.0  │\n└───────────────┴─────────────────┴──────┴────────────┴────────┘\n```\n\n### Average PE per Sector\nThis example shows aggregation (average) per group (sector) for members of an index.\nThe resulting list has only one element since there is only one data-item in `get`\n```python\nquery = \"\"\"\n    let(#avg_pe=avg(group(pe_ratio(), gics_sector_name()));)\n    get(#avg_pe)\n    for(members('OMX Index'))\n\"\"\"\nwith BQuery() as bq:\n    results = bq.bql(query)\n    print(results[0].head(5))\n```\nOutput:\n```python\n┌──────────────┬───────────┬──────────────┬────────────┬──────────────┬──────────────┬─────────────┐\n│ ID           ┆ #avg_pe   ┆ REVISION_DAT ┆ AS_OF_DATE ┆ PERIOD_END_D ┆ ORIG_IDS     ┆ GICS_SECTOR │\n│ ---          ┆ ---       ┆ E            ┆ ---        ┆ ATE          ┆ ---          ┆ _NAME()     │\n│ str          ┆ f64       ┆ ---          ┆ date       ┆ ---          ┆ str          ┆ ---         │\n│              ┆           ┆ date         ┆            ┆ date         ┆              ┆ str         │\n╞══════════════╪═══════════╪══════════════╪════════════╪══════════════╪══════════════╪═════════════╡\n│ Communicatio ┆ 19.561754 ┆ 2024-10-24   ┆ 2024-12-14 ┆ 2024-09-30   ┆ null         ┆ Communicati │\n│ n Services   ┆           ┆              ┆            ┆              ┆              ┆ on Services │\n│ Consumer Dis ┆ 19.117295 ┆ 2024-10-24   ┆ 2024-12-14 ┆ 2024-09-30   ┆ null         ┆ Consumer    │\n│ cretionary   ┆           ┆              ┆            ┆              ┆              ┆ Discretiona │\n│              ┆           ┆              ┆            ┆              ┆              ┆ ry          │\n│ Consumer     ┆ 15.984743 ┆ 2024-10-24   ┆ 2024-12-14 ┆ 2024-09-30   ┆ ESSITYB SS   ┆ Consumer    │\n│ Staples      ┆           ┆              ┆            ┆              ┆ Equity       ┆ Staples     │\n│ Financials   ┆ 6.815895  ┆ 2024-10-24   ┆ 2024-12-14 ┆ 2024-09-30   ┆ null         ┆ Financials  │\n│ Health Care  ┆ 22.00628  ┆ 2024-11-12   ┆ 2024-12-14 ┆ 2024-09-30   ┆ null         ┆ Health Care │\n└──────────────┴───────────┴──────────────┴────────────┴──────────────┴──────────────┴─────────────┘\n```\n\n### Axes\nGet current axes of all Swedish USD AT1 bonds\n```python\n# Get current axes for Swedish AT1 bonds in USD\nquery=\"\"\"\n    let(#ax=axes();)\n    get(security_des, #ax)\n    for(filter(bondsuniv(ACTIVE),\n        crncy()=='USD' and\n        basel_iii_designation() == 'Additional Tier 1' and\n        country_iso() == 'SE'))\n\"\"\"\n\nwith BQuery() as bq:\n    results = bq.bql(query)\n    print(results.combine())\n\n┌───────────────┬─────────────────┬─────┬───────────┬───────────┬────────────────┬────────────────┐\n│ ID            ┆ security_des    ┆ #ax ┆ ASK_DEPTH ┆ BID_DEPTH ┆ ASK_TOTAL_SIZE ┆ BID_TOTAL_SIZE │\n│ ---           ┆ ---             ┆ --- ┆ ---       ┆ ---       ┆ ---            ┆ ---            │\n│ str           ┆ str             ┆ str ┆ i64       ┆ i64       ┆ f64            ┆ f64            │\n╞═══════════════╪═════════════════╪═════╪═══════════╪═══════════╪════════════════╪════════════════╡\n│ YU819930 Corp ┆ SEB 6 ¾ PERP    ┆ Y   ┆ 2         ┆ null      ┆ 5.6e6          ┆ null           │\n│ ZO703315 Corp ┆ SHBASS 4 ⅜ PERP ┆ Y   ┆ 1         ┆ 2         ┆ 5e6            ┆ 6e6            │\n│ BR069680 Corp ┆ SWEDA 4 PERP    ┆ Y   ┆ null      ┆ 1         ┆ null           ┆ 3e6            │\n│ ZL122341 Corp ┆ SWEDA 7 ⅝ PERP  ┆ Y   ┆ null      ┆ 6         ┆ null           ┆ 2.04e7         │\n│ ZQ349286 Corp ┆ SEB 5 ⅛ PERP    ┆ Y   ┆ 2         ┆ 4         ┆ 5.5e6          ┆ 3e7            │\n│ ZF859199 Corp ┆ SWEDA 7 ¾ PERP  ┆ Y   ┆ 1         ┆ 1         ┆ 2e6            ┆ 2e6            │\n│ ZO703956 Corp ┆ SHBASS 4 ¾ PERP ┆ Y   ┆ 1         ┆ 3         ┆ 1.2e6          ┆ 1.1e7          │\n│ BW924993 Corp ┆ SEB 6 ⅞ PERP    ┆ Y   ┆ 1         ┆ 3         ┆ 5e6            ┆ 1.1e7          │\n└───────────────┴─────────────────┴─────┴───────────┴───────────┴────────────────┴────────────────┘\n```\n\n### Axes with all columns\n```python\n# RT1 Axes with all columns\nquery = \"\"\"\nlet(#ax=axes();)\nget(name, #ax, amt_outstanding)\nfor(filter(bondsuniv(ACTIVE),\n    crncy() in ['USD', 'EUR'] and\n    solvency_ii_designation() == 'Restricted Tier 1' and\n    amt_outstanding() \u003e 7.5e8 and\n    is_axed('Bid') == True))\npreferences(addcols=all)\n\"\"\"\n\nwith BQuery() as bq:\n    results = bq.bql(query)\n    print(results.combine())\n```\nOutput:\n\u003cdiv\u003e\n\u003csmall\u003eshape: (3, 33)\u003c/small\u003e\u003ctable border=\"1\" class=\"dataframe\"\u003e\u003cthead\u003e\u003ctr\u003e\u003cth\u003eID\u003c/th\u003e\u003cth\u003ename\u003c/th\u003e\u003cth\u003e#ax\u003c/th\u003e\u003cth\u003eASK_PRICE\u003c/th\u003e\u003cth\u003eBID_PRICE\u003c/th\u003e\u003cth\u003eASK_DEPTH\u003c/th\u003e\u003cth\u003eBID_DEPTH\u003c/th\u003e\u003cth\u003eASK_DEALER\u003c/th\u003e\u003cth\u003eBID_DEALER\u003c/th\u003e\u003cth\u003eASK_SIZE\u003c/th\u003e\u003cth\u003eBID_SIZE\u003c/th\u003e\u003cth\u003eASK_TOTAL_SIZE\u003c/th\u003e\u003cth\u003eBID_TOTAL_SIZE\u003c/th\u003e\u003cth\u003eASK_PRICE_IS_DERIVED\u003c/th\u003e\u003cth\u003eBID_PRICE_IS_DERIVED\u003c/th\u003e\u003cth\u003eASK_SPREAD\u003c/th\u003e\u003cth\u003eBID_SPREAD\u003c/th\u003e\u003cth\u003eASK_SPREAD_IS_DERIVED\u003c/th\u003e\u003cth\u003eBID_SPREAD_IS_DERIVED\u003c/th\u003e\u003cth\u003eASK_YIELD\u003c/th\u003e\u003cth\u003eBID_YIELD\u003c/th\u003e\u003cth\u003eASK_YIELD_IS_DERIVED\u003c/th\u003e\u003cth\u003eBID_YIELD_IS_DERIVED\u003c/th\u003e\u003cth\u003eASK_AXE_SOURCE\u003c/th\u003e\u003cth\u003eBID_AXE_SOURCE\u003c/th\u003e\u003cth\u003eASK_BROKER\u003c/th\u003e\u003cth\u003eBID_BROKER\u003c/th\u003e\u003cth\u003eASK_HIST_AGG_SIZE\u003c/th\u003e\u003cth\u003eBID_HIST_AGG_SIZE\u003c/th\u003e\u003cth\u003eamt_outstanding\u003c/th\u003e\u003cth\u003eCURRENCY_OF_ISSUE\u003c/th\u003e\u003cth\u003eMULTIPLIER\u003c/th\u003e\u003cth\u003eCURRENCY\u003c/th\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ei64\u003c/td\u003e\u003ctd\u003ei64\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ebool\u003c/td\u003e\u003ctd\u003ebool\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ebool\u003c/td\u003e\u003ctd\u003ebool\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ebool\u003c/td\u003e\u003ctd\u003ebool\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003ctd\u003ef64\u003c/td\u003e\u003ctd\u003estr\u003c/td\u003e\u003c/tr\u003e\u003c/thead\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e\u0026quot;BM368057 Corp\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;ALVGR 2 ⅝ PERP\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;Y\u0026quot;\u003c/td\u003e\u003ctd\u003e88.034\u003c/td\u003e\u003ctd\u003e87.427\u003c/td\u003e\u003ctd\u003e5\u003c/td\u003e\u003ctd\u003e1\u003c/td\u003e\u003ctd\u003e\u0026quot;BARC\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;IMI\u0026quot;\u003c/td\u003e\u003ctd\u003e1.2e6\u003c/td\u003e\u003ctd\u003e1e6\u003c/td\u003e\u003ctd\u003e7.2e6\u003c/td\u003e\u003ctd\u003e1e6\u003c/td\u003e\u003ctd\u003enull\u003c/td\u003e\u003ctd\u003enull\u003c/td\u003e\u003ctd\u003e287.031\u003c/td\u003e\u003ctd\u003e300.046\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003e4.854\u003c/td\u003e\u003ctd\u003e4.976\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003e\u0026quot;ERUN\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;ERUN\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;BXOL\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;IMIC\u0026quot;\u003c/td\u003e\u003ctd\u003e6.68e6\u003c/td\u003e\u003ctd\u003e8.92e6\u003c/td\u003e\u003ctd\u003e1.2500e9\u003c/td\u003e\u003ctd\u003e\u0026quot;EUR\u0026quot;\u003c/td\u003e\u003ctd\u003e1.0\u003c/td\u003e\u003ctd\u003e\u0026quot;EUR\u0026quot;\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026quot;EK588238 Corp\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;ASSGEN 4.596 PERP\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;Y\u0026quot;\u003c/td\u003e\u003ctd\u003e101.0\u003c/td\u003e\u003ctd\u003e100.13\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003ctd\u003e6\u003c/td\u003e\u003ctd\u003e\u0026quot;MSAX\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;A2A\u0026quot;\u003c/td\u003e\u003ctd\u003e500000.0\u003c/td\u003e\u003ctd\u003e100000.0\u003c/td\u003e\u003ctd\u003e1.556e7\u003c/td\u003e\u003ctd\u003e3.83e7\u003c/td\u003e\u003ctd\u003enull\u003c/td\u003e\u003ctd\u003enull\u003c/td\u003e\u003ctd\u003e108.9\u003c/td\u003e\u003ctd\u003e207.889\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003e3.466\u003c/td\u003e\u003ctd\u003e4.434\u003c/td\u003e\u003ctd\u003enull\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003e\u0026quot;ERUN\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;BBX\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;MSAX\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;A2A\u0026quot;\u003c/td\u003e\u003ctd\u003e1.70424e7\u003c/td\u003e\u003ctd\u003e3.17e7\u003c/td\u003e\u003ctd\u003e1.0004e9\u003c/td\u003e\u003ctd\u003e\u0026quot;EUR\u0026quot;\u003c/td\u003e\u003ctd\u003e1.0\u003c/td\u003e\u003ctd\u003e\u0026quot;EUR\u0026quot;\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026quot;BR244025 Corp\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;ALVGR 3.2 PERP\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;Y\u0026quot;\u003c/td\u003e\u003ctd\u003e88.0\u003c/td\u003e\u003ctd\u003e86.875\u003c/td\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e4\u003c/td\u003e\u003ctd\u003e\u0026quot;UBS\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;DB\u0026quot;\u003c/td\u003e\u003ctd\u003e5e6\u003c/td\u003e\u003ctd\u003e1e6\u003c/td\u003e\u003ctd\u003e1.1e7\u003c/td\u003e\u003ctd\u003e1.4e7\u003c/td\u003e\u003ctd\u003enull\u003c/td\u003e\u003ctd\u003enull\u003c/td\u003e\u003ctd\u003e49.33\u003c/td\u003e\u003ctd\u003e414.602\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003e7.34258\u003c/td\u003e\u003ctd\u003e8.553\u003c/td\u003e\u003ctd\u003enull\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003e\u0026quot;ERUN\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;ERUN\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;UBSW\u0026quot;\u003c/td\u003e\u003ctd\u003e\u0026quot;DABC\u0026quot;\u003c/td\u003e\u003ctd\u003e1.6876e6\u003c/td\u003e\u003ctd\u003e3.6e7\u003c/td\u003e\u003ctd\u003e1.2500e9\u003c/td\u003e\u003ctd\u003e\u0026quot;USD\u0026quot;\u003c/td\u003e\u003ctd\u003e1.0\u003c/td\u003e\u003ctd\u003e\u0026quot;USD\u0026quot;\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\u003c/div\u003e\n\n\n### Segments\nThe following example shows handling of two data-items with different length. The first dataframe\ndescribes the segments (and has length 5 in this case), while the second dataframe contains time series.\nOne can join the dataframes on common columns and pivot the segments into columns as shown below:\n```python\n# revenue per segment\nquery = \"\"\"\n    let(#segment=segment_name();\n        #revenue=sales_Rev_turn(fpt=q, fpr=range(2023Q3, 2024Q3));\n        )\n    get(#segment, #revenue)\n    for(segments('GTN US Equity',type=reported,hierarchy=PRODUCT, level=1))\n\"\"\"\nwith BQuery() as bq:\n    results = bq.bql(query)\n    df = results.combine().pivot(\n        index=\"PERIOD_END_DATE\", on=\"#segment\", values=\"#revenue\"\n    )\n    print(df)\n```\nOutput:\n```python\n┌─────────────────┬──────────────┬──────────────────────┬────────┬────────────┐\n│ PERIOD_END_DATE ┆ Broadcasting ┆ Production Companies ┆ Other  ┆ Adjustment │\n│ ---             ┆ ---          ┆ ---                  ┆ ---    ┆ ---        │\n│ date            ┆ f64          ┆ f64                  ┆ f64    ┆ f64        │\n╞═════════════════╪══════════════╪══════════════════════╪════════╪════════════╡\n│ 2023-09-30      ┆ 7.83e8       ┆ 2e7                  ┆ 1.6e7  ┆ null       │\n│ 2023-12-31      ┆ 8.13e8       ┆ 3.2e7                ┆ 1.9e7  ┆ null       │\n│ 2024-03-31      ┆ 7.8e8        ┆ 2.4e7                ┆ 1.9e7  ┆ null       │\n│ 2024-06-30      ┆ 8.08e8       ┆ 1.8e7                ┆ 0.0    ┆ null       │\n│ 2024-09-30      ┆ 9.24e8       ┆ 2.6e7                ┆ 1.7e7  ┆ null       │\n└─────────────────┴──────────────┴──────────────────────┴────────┴────────────┘\n```\n\n### Actual and Forward EPS Estimates\n```python\nwith BQuery() as bq:\n    results = bq.bql(\"\"\"\n        let(#eps=is_eps(fa_period_type='A',\n                        fa_period_offset=range(-4,2));)\n        get(#eps)\n        for(['IBM US Equity'])\n    \"\"\")\n    print(results[0])\n\n┌───────────────┬───────┬───────────────┬────────────┬─────────────────┬──────────┐\n│ ID            ┆ #eps  ┆ REVISION_DATE ┆ AS_OF_DATE ┆ PERIOD_END_DATE ┆ CURRENCY │\n│ ---           ┆ ---   ┆ ---           ┆ ---        ┆ ---             ┆ ---      │\n│ str           ┆ f64   ┆ date          ┆ date       ┆ date            ┆ str      │\n╞═══════════════╪═══════╪═══════════════╪════════════╪═════════════════╪══════════╡\n│ IBM US Equity ┆ 10.63 ┆ 2022-02-22    ┆ 2024-12-14 ┆ 2019-12-31      ┆ USD      │\n│ IBM US Equity ┆ 6.28  ┆ 2023-02-28    ┆ 2024-12-14 ┆ 2020-12-31      ┆ USD      │\n│ IBM US Equity ┆ 6.41  ┆ 2023-02-28    ┆ 2024-12-14 ┆ 2021-12-31      ┆ USD      │\n│ IBM US Equity ┆ 1.82  ┆ 2024-03-18    ┆ 2024-12-14 ┆ 2022-12-31      ┆ USD      │\n│ IBM US Equity ┆ 8.23  ┆ 2024-03-18    ┆ 2024-12-14 ┆ 2023-12-31      ┆ USD      │\n│ IBM US Equity ┆ 7.891 ┆ 2024-12-13    ┆ 2024-12-14 ┆ 2024-12-31      ┆ USD      │\n│ IBM US Equity ┆ 9.236 ┆ 2024-12-13    ┆ 2024-12-14 ┆ 2025-12-31      ┆ USD      │\n└───────────────┴───────┴───────────────┴────────────┴─────────────────┴──────────┘\n```\n\n### Average issuer OAS spread per maturity bucket\n```python\n# Example: Average OAS-spread per maturity bucket\nquery = \"\"\"\nlet(\n    #bins = bins(maturity_years,\n                 [3,9,18,30],\n                 ['(1) 0-3','(2) 3-9','(3) 9-18','(4) 18-30','(5) 30+']);\n    #average_spread = avg(group(spread(st=oas),#bins));\n)\nget(#average_spread)\nfor(filter(bonds('NVDA US Equity', issuedby = 'ENTITY'),\n           maturity_years != NA))\n\"\"\"\n\nwith BQuery() as bq:\n    results = bq.bql(query)\n    print(results[0])\n```\nOutput:\n```python\n┌───────────┬─────────────────┬────────────┬───────────────┬───────────┐\n│ ID        ┆ #average_spread ┆ DATE       ┆ ORIG_IDS      ┆ #BINS     │\n│ ---       ┆ ---             ┆ ---        ┆ ---           ┆ ---       │\n│ str       ┆ f64             ┆ date       ┆ str           ┆ str       │\n╞═══════════╪═════════════════╪════════════╪═══════════════╪═══════════╡\n│ (1) 0-3   ┆ 31.195689       ┆ 2024-12-14 ┆ QZ552396 Corp ┆ (1) 0-3   │\n│ (2) 3-9   ┆ 59.580383       ┆ 2024-12-14 ┆ null          ┆ (2) 3-9   │\n│ (3) 9-18  ┆ 110.614416      ┆ 2024-12-14 ┆ BH393780 Corp ┆ (3) 9-18  │\n│ (4) 18-30 ┆ 135.160279      ┆ 2024-12-14 ┆ BH393781 Corp ┆ (4) 18-30 │\n│ (5) 30+   ┆ 150.713405      ┆ 2024-12-14 ┆ BH393782 Corp ┆ (5) 30+   │\n└───────────┴─────────────────┴────────────┴───────────────┴───────────┘\n```\n\n### Technical Analysis: stocks with 20d EMA \u003e 200d EMA and RSI \u003e 53\n```python\nwith BQuery() as bq:\n    results = bq.bql(\n        \"\"\"\n        let(#ema20=emavg(period=20);\n            #ema200=emavg(period=200);\n            #rsi=rsi(close=px_last());)\n        get(name(), #ema20, #ema200, #rsi)\n        for(filter(members('OMX Index'),\n                    and(#ema20 \u003e #ema200, #rsi \u003e 53)))\n        with(fill=PREV)\n        \"\"\"\n    )\n    print(results.combine())\n```\nOutput:\n```python\n┌─────────────────┬──────────────────┬────────────┬────────────┬──────────┬────────────┬───────────┐\n│ ID              ┆ name()           ┆ #ema20     ┆ DATE       ┆ CURRENCY ┆ #ema200    ┆ #rsi      │\n│ ---             ┆ ---              ┆ ---        ┆ ---        ┆ ---      ┆ ---        ┆ ---       │\n│ str             ┆ str              ┆ f64        ┆ date       ┆ str      ┆ f64        ┆ f64       │\n╞═════════════════╪══════════════════╪════════════╪════════════╪══════════╪════════════╪═══════════╡\n│ ERICB SS Equity ┆ Telefonaktiebola ┆ 90.152604  ┆ 2024-12-16 ┆ SEK      ┆ 75.072151  ┆ 56.010028 │\n│                 ┆ get LM Ericsso   ┆            ┆            ┆          ┆            ┆           │\n│ ABB SS Equity   ┆ ABB Ltd          ┆ 630.622469 ┆ 2024-12-16 ┆ SEK      ┆ 566.571183 ┆ 53.763102 │\n│ SEBA SS Equity  ┆ Skandinaviska    ┆ 153.80595  ┆ 2024-12-16 ┆ SEK      ┆ 150.742394 ┆ 56.460733 │\n│                 ┆ Enskilda Banken  ┆            ┆            ┆          ┆            ┆           │\n│ ASSAB SS Equity ┆ Assa Abloy AB    ┆ 339.017591 ┆ 2024-12-16 ┆ SEK      ┆ 317.057573 ┆ 53.351619 │\n└─────────────────┴──────────────────┴────────────┴────────────┴──────────┴────────────┴───────────┘\n```\n\n### Bond Universe from Equity Ticker\n```python\n# Get Bond Universe from Equity Ticker\nquery = \"\"\"\nlet(#rank=normalized_payment_rank();\n    #oas=spread(st=oas);\n    #nxt_call=nxt_call_dt();\n    )\nget(name(), #rank, #nxt_call, #oas)\nfor(filter(bonds('GTN US Equity'), series() == '144A'))\n\"\"\"\n\nwith BQuery() as bq:\n    results = bq.bql(query)\n    df = results.combine()\n    print(df)\n```\nOutput:\n```\n┌───────────────┬───────────────────┬──────────────────┬────────────┬────────────┬────────────┐\n│ ID            ┆ name()            ┆ #rank            ┆ #nxt_call  ┆ #oas       ┆ DATE       │\n│ ---           ┆ ---               ┆ ---              ┆ ---        ┆ ---        ┆ ---        │\n│ str           ┆ str               ┆ str              ┆ date       ┆ f64        ┆ date       │\n╞═══════════════╪═══════════════════╪══════════════════╪════════════╪════════════╪════════════╡\n│ YX231113 Corp ┆ GTN 10 ½ 07/15/29 ┆ 1st Lien Secured ┆ 2026-07-15 ┆ 598.66491  ┆ 2024-12-17 │\n│ BS116983 Corp ┆ GTN 5 ⅜ 11/15/31  ┆ Sr Unsecured     ┆ 2026-11-15 ┆ 1193.17529 ┆ 2024-12-17 │\n│ AV438089 Corp ┆ GTN 7 05/15/27    ┆ Sr Unsecured     ┆ 2024-12-24 ┆ 400.340456 ┆ 2024-12-17 │\n│ ZO860846 Corp ┆ GTN 4 ¾ 10/15/30  ┆ Sr Unsecured     ┆ 2025-10-15 ┆ 1249.34346 ┆ 2024-12-17 │\n│ LW375188 Corp ┆ GTN 5 ⅞ 07/15/26  ┆ Sr Unsecured     ┆ 2025-01-13 ┆ 173.761744 ┆ 2024-12-17 │\n└───────────────┴───────────────────┴──────────────────┴────────────┴────────────┴────────────┘\n```\n\n### Bonds Total Returns\nThis is example of a single-item query returning total return for all GTN bonds in a long dataframe.\nWe can easily pivot it into wide format, as in the example below\n```python\n# Total Return of GTN Bonds\nquery = \"\"\"\nlet(#rng = range(-1M, 0D);\n    #rets = return_series(calc_interval=#rng,per=W);)\nget(#rets)\nfor(filter(bonds('GTN US Equity'), series() == '144A'))\n\"\"\"\n\nwith BQuery() as bq:\n    results = bq.bql(query)\n    df = results[0].pivot(on=\"ID\", index=\"DATE\", values=\"#rets\")\n    print(df)\n```\nOutput:\n```python\nshape: (6, 6)\n┌────────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────┐\n│ DATE       ┆ YX231113 Corp ┆ BS116983 Corp ┆ AV438089 Corp ┆ ZO860846 Corp ┆ LW375188 Corp │\n│ ---        ┆ ---           ┆ ---           ┆ ---           ┆ ---           ┆ ---           │\n│ date       ┆ f64           ┆ f64           ┆ f64           ┆ f64           ┆ f64           │\n╞════════════╪═══════════════╪═══════════════╪═══════════════╪═══════════════╪═══════════════╡\n│ 2024-11-17 ┆ null          ┆ null          ┆ null          ┆ null          ┆ null          │\n│ 2024-11-24 ┆ 0.001653      ┆ 0.051179      ┆ 0.020363      ┆ 0.001371      ┆ -0.002939     │\n│ 2024-12-01 ┆ 0.002837      ┆ 0.010405      ┆ -0.001466     ┆ 0.007275      ┆ 0.000581      │\n│ 2024-12-08 ┆ -0.000041     ┆ 0.016145      ┆ 0.000766      ┆ 0.024984      ┆ 0.000936      │\n│ 2024-12-15 ┆ 0.001495      ┆ -0.047        ┆ -0.000233     ┆ -0.043509     ┆ 0.002241      │\n│ 2024-12-17 ┆ 0.00008       ┆ -0.000004     ┆ -0.0035       ┆ -0.007937     ┆ 0.000064      │\n└────────────┴───────────────┴───────────────┴───────────────┴───────────────┴───────────────┘\n```\n\n### Maturity Wall for US HY Bonds\n```python\nquery = \"\"\"\nlet(#mv=sum(group(amt_outstanding(currency=USD),\n                  by=[year(maturity()), industry_sector()]));)\nget(#mv)\nfor(members('LF98TRUU Index'))\n\"\"\"\nwith BQuery() as bq:\n    results = bq.bql(query)\ndf = results.combine().rename(\n    {\"YEAR(MATURITY())\": \"maturity\", \"INDUSTRY_SECTOR()\": \"sector\", \"#mv\": \"mv\"}\n)\n\nprint(df.pivot(index=\"maturity\", on=\"sector\", values=\"mv\").head())\n```\nOutput:\n```python\nshape: (5, 11)\n┌──────────┬───────────┬───────────┬───────────┬───┬───────────┬───────────┬───────────┬───────────┐\n│ maturity ┆ Basic     ┆ Consumer, ┆ Energy    ┆ … ┆ Financial ┆ Technolog ┆ Utilities ┆ Diversifi │\n│ ---      ┆ Materials ┆ Non-cycli ┆ ---       ┆   ┆ ---       ┆ y         ┆ ---       ┆ ed        │\n│ i64      ┆ ---       ┆ cal       ┆ f64       ┆   ┆ f64       ┆ ---       ┆ f64       ┆ ---       │\n│          ┆ f64       ┆ ---       ┆           ┆   ┆           ┆ f64       ┆           ┆ f64       │\n│          ┆           ┆ f64       ┆           ┆   ┆           ┆           ┆           ┆           │\n╞══════════╪═══════════╪═══════════╪═══════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡\n│ 2025     ┆ 1.5e8     ┆ 5.34916e8 ┆ 5e8       ┆ … ┆ null      ┆ null      ┆ null      ┆ null      │\n│ 2026     ┆ 4.4013e9  ┆ 9.3293e9  ┆ 8.2931e9  ┆ … ┆ 1.3524e10 ┆ 4.0608e9  ┆ 2.5202e9  ┆ null      │\n│ 2027     ┆ 8.3921e9  ┆ 2.3409e10 ┆ 1.2427e10 ┆ … ┆ 1.9430e10 ┆ 4.3367e9  ┆ 3.6620e9  ┆ null      │\n│ 2028     ┆ 1.4701e10 ┆ 3.7457e10 ┆ 2.2442e10 ┆ … ┆ 2.3341e10 ┆ 9.9143e9  ┆ 7.6388e9  ┆ 5e8       │\n│ 2029     ┆ 1.6512e10 ┆ 5.7381e10 ┆ 3.9286e10 ┆ … ┆ 4.2337e10 ┆ 2.2660e10 ┆ 5.8558e9  ┆ null      │\n└──────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴───────────┘\n```\n\n\n## Additional Documentation \u0026 Resources\n\n- *API Documentation*: Detailed documentation and function references are available in https://marekozana.github.io/polars-bloomberg\n\n- *Additional Examples*: Check out [examples/](examples/) for hands-on notebooks demonstrating a variety of use cases.\n    - BQL examples and use cases: [examples/Examples-BQL.ipynb](https://github.com/MarekOzana/polars-bloomberg/blob/main/examples/Examples-BQL.ipynb)\n\n- *Bloomberg Developer Resources*: For more details on the Bloomberg API itself, visit the [Bloomberg Developer's page](https://developer.bloomberg.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarekozana%2Fpolars-bloomberg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarekozana%2Fpolars-bloomberg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarekozana%2Fpolars-bloomberg/lists"}