-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding index spread, duration and changes
- Loading branch information
1 parent
cada707
commit 112dfcf
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>"LG30TRUU Index"</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>"LG30TRUU Index"</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>"LG30TRUU Index"</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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters