diff --git a/docs/examples/credits.ipynb b/docs/examples/credits.ipynb new file mode 100644 index 0000000..2f869c8 --- /dev/null +++ b/docs/examples/credits.ipynb @@ -0,0 +1,104 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Credit Fixed Income Examples\n", + "(c) 2024 Marek Ozana" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from polars_bloomberg import BQuery\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Monthly Spreads, Spread diff and Return for HY Index" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "shape: (3, 6)
ID#oas_sDATE#dOAS#dur#ret
strf64datef64f64f64
"LG30TRUU Index"363.03362024-10-31-19.67823.533628-0.630516
"LG30TRUU Index"347.15132024-11-29-15.88233.5347580.820944
"LG30TRUU Index"349.59592024-12-232.44463.614952-0.622827
" + ], + "text/plain": [ + "shape: (3, 6)\n", + "┌────────────────┬──────────┬────────────┬──────────┬──────────┬───────────┐\n", + "│ ID ┆ #oas_s ┆ DATE ┆ #dOAS ┆ #dur ┆ #ret │\n", + "│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n", + "│ str ┆ f64 ┆ date ┆ f64 ┆ f64 ┆ f64 │\n", + "╞════════════════╪══════════╪════════════╪══════════╪══════════╪═══════════╡\n", + "│ LG30TRUU Index ┆ 363.0336 ┆ 2024-10-31 ┆ -19.6782 ┆ 3.533628 ┆ -0.630516 │\n", + "│ LG30TRUU Index ┆ 347.1513 ┆ 2024-11-29 ┆ -15.8823 ┆ 3.534758 ┆ 0.820944 │\n", + "│ LG30TRUU Index ┆ 349.5959 ┆ 2024-12-23 ┆ 2.4446 ┆ 3.614952 ┆ -0.622827 │\n", + "└────────────────┴──────────┴────────────┴──────────┴──────────┴───────────┘" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get data\n", + "query = \"\"\"\n", + " let(\n", + " #oas_s=spread(spread_type=OAS_SWAP, universe_type=RETURNS);\n", + " #dOAS = diff(#oas_s);\n", + " #dur = duration(universe_type=RETURNS);\n", + " #ret = pct_diff(px_last());\n", + " )\n", + " get(#oas_s, #dOAS, #dur, #ret)\n", + " for('LG30TRUU Index')\n", + " with(dates=range(-3M, 0D), fill=PREV, per=M)\n", + "\"\"\"\n", + "\n", + "with BQuery() as bq:\n", + " df = bq.bql(query).combine().drop_nulls()\n", + "\n", + "df" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/mkdocs.yml b/mkdocs.yml index 9e7af54..f0b49bc 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -25,4 +25,5 @@ nav: - BQL: usage/bql.md - Examples: - Equity: examples/equity.ipynb + - Credits: examples/credits.ipynb - API Reference: api.md \ No newline at end of file