Skip to content

Commit

Permalink
adding index spread, duration and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekOzana committed Dec 23, 2024
1 parent cada707 commit 112dfcf
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
104 changes: 104 additions & 0 deletions docs/examples/credits.ipynb
Original file line number Diff line number Diff line change
@@ -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": [
"<div><style>\n",
".dataframe > thead > tr,\n",
".dataframe > tbody > tr {\n",
" text-align: right;\n",
" white-space: pre-wrap;\n",
"}\n",
"</style>\n",
"<small>shape: (3, 6)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>ID</th><th>#oas_s</th><th>DATE</th><th>#dOAS</th><th>#dur</th><th>#ret</th></tr><tr><td>str</td><td>f64</td><td>date</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;LG30TRUU Index&quot;</td><td>363.0336</td><td>2024-10-31</td><td>-19.6782</td><td>3.533628</td><td>-0.630516</td></tr><tr><td>&quot;LG30TRUU Index&quot;</td><td>347.1513</td><td>2024-11-29</td><td>-15.8823</td><td>3.534758</td><td>0.820944</td></tr><tr><td>&quot;LG30TRUU Index&quot;</td><td>349.5959</td><td>2024-12-23</td><td>2.4446</td><td>3.614952</td><td>-0.622827</td></tr></tbody></table></div>"
],
"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
}
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ nav:
- BQL: usage/bql.md
- Examples:
- Equity: examples/equity.ipynb
- Credits: examples/credits.ipynb
- API Reference: api.md

0 comments on commit 112dfcf

Please sign in to comment.