-
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.
Loading status checks…
bug: NaN in double field
- Loading branch information
Marek Ozana
committed
Dec 10, 2024
1 parent
e189f96
commit 3711fd3
Showing
3 changed files
with
236 additions
and
24 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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
|
@@ -470,50 +470,49 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"shape: (5, 5)\n", | ||
"┌───────────┬─────────────────┬──────────────────────┬──────────────────────┬──────────────────────┐\n", | ||
"│ ID ┆ #average_spread ┆ #average_spread.DATE ┆ #average_spread.ORIG ┆ #average_spread.#BIN │\n", | ||
"│ --- ┆ --- ┆ --- ┆ _IDS ┆ S │\n", | ||
"│ str ┆ f64 ┆ date ┆ --- ┆ --- │\n", | ||
"│ ┆ ┆ ┆ str ┆ str │\n", | ||
"╞═══════════╪═════════════════╪══════════════════════╪══════════════════════╪══════════════════════╡\n", | ||
"│ (1) 0-3 ┆ 30.743399 ┆ 2024-12-08 ┆ QZ552396 Corp ┆ (1) 0-3 │\n", | ||
"│ (2) 3-9 ┆ 59.796562 ┆ 2024-12-08 ┆ null ┆ (2) 3-9 │\n", | ||
"│ (3) 9-18 ┆ 105.39336 ┆ 2024-12-08 ┆ BH393780 Corp ┆ (3) 9-18 │\n", | ||
"│ (4) 18-30 ┆ 131.727938 ┆ 2024-12-08 ┆ BH393781 Corp ┆ (4) 18-30 │\n", | ||
"│ (5) 30+ ┆ 150.336053 ┆ 2024-12-08 ┆ BH393782 Corp ┆ (5) 30+ │\n", | ||
"└───────────┴─────────────────┴──────────────────────┴──────────────────────┴──────────────────────┘\n" | ||
"┌───────────┬─────────────────┬──────────────────────┬──────────────────────────┬───────────────────────┐\n", | ||
"│ ID ┆ #average_spread ┆ #average_spread.DATE ┆ #average_spread.ORIG_IDS ┆ #average_spread.#BINS │\n", | ||
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n", | ||
"│ str ┆ f64 ┆ date ┆ str ┆ str │\n", | ||
"╞═══════════╪═════════════════╪══════════════════════╪══════════════════════════╪═══════════════════════╡\n", | ||
"│ (1) 0-3 ┆ 30.638311 ┆ 2024-12-10 ┆ QZ552396 Corp ┆ (1) 0-3 │\n", | ||
"│ (2) 3-9 ┆ 59.772151 ┆ 2024-12-10 ┆ null ┆ (2) 3-9 │\n", | ||
"│ (3) 9-18 ┆ 106.722341 ┆ 2024-12-10 ┆ BH393780 Corp ┆ (3) 9-18 │\n", | ||
"│ (4) 18-30 ┆ 129.945414 ┆ 2024-12-10 ┆ BH393781 Corp ┆ (4) 18-30 │\n", | ||
"│ (5) 30+ ┆ 151.318634 ┆ 2024-12-10 ┆ BH393782 Corp ┆ (5) 30+ │\n", | ||
"└───────────┴─────────────────┴──────────────────────┴──────────────────────────┴───────────────────────┘\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
"<style>\n", | ||
" #altair-viz-eee9b98f80954792b72a8d22008d95b7.vega-embed {\n", | ||
" #altair-viz-1b0f7623e39a4b14896b2d98d90b428a.vega-embed {\n", | ||
" width: 100%;\n", | ||
" display: flex;\n", | ||
" }\n", | ||
"\n", | ||
" #altair-viz-eee9b98f80954792b72a8d22008d95b7.vega-embed details,\n", | ||
" #altair-viz-eee9b98f80954792b72a8d22008d95b7.vega-embed details summary {\n", | ||
" #altair-viz-1b0f7623e39a4b14896b2d98d90b428a.vega-embed details,\n", | ||
" #altair-viz-1b0f7623e39a4b14896b2d98d90b428a.vega-embed details summary {\n", | ||
" position: relative;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<div id=\"altair-viz-eee9b98f80954792b72a8d22008d95b7\"></div>\n", | ||
"<div id=\"altair-viz-1b0f7623e39a4b14896b2d98d90b428a\"></div>\n", | ||
"<script type=\"text/javascript\">\n", | ||
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n", | ||
" (function(spec, embedOpt){\n", | ||
" let outputDiv = document.currentScript.previousElementSibling;\n", | ||
" if (outputDiv.id !== \"altair-viz-eee9b98f80954792b72a8d22008d95b7\") {\n", | ||
" outputDiv = document.getElementById(\"altair-viz-eee9b98f80954792b72a8d22008d95b7\");\n", | ||
" if (outputDiv.id !== \"altair-viz-1b0f7623e39a4b14896b2d98d90b428a\") {\n", | ||
" outputDiv = document.getElementById(\"altair-viz-1b0f7623e39a4b14896b2d98d90b428a\");\n", | ||
" }\n", | ||
" const paths = {\n", | ||
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n", | ||
|
@@ -559,7 +558,7 @@ | |
" .catch(showError)\n", | ||
" .then(() => displayChart(vegaEmbed));\n", | ||
" }\n", | ||
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-0dcd9683990143b20e589a04f1e0f661\"}, \"mark\": {\"type\": \"bar\"}, \"encoding\": {\"tooltip\": [{\"field\": \"ID\", \"type\": \"nominal\"}, {\"field\": \"#average_spread\", \"type\": \"quantitative\"}], \"x\": {\"field\": \"ID\", \"type\": \"nominal\"}, \"y\": {\"field\": \"#average_spread\", \"type\": \"quantitative\"}}, \"params\": [{\"name\": \"param_1\", \"select\": {\"type\": \"interval\", \"encodings\": [\"x\", \"y\"]}, \"bind\": \"scales\"}], \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"datasets\": {\"data-0dcd9683990143b20e589a04f1e0f661\": [{\"ID\": \"(1) 0-3\", \"#average_spread\": 30.74339924, \"#average_spread.DATE\": \"2024-12-08T00:00:00\", \"#average_spread.ORIG_IDS\": \"QZ552396 Corp\", \"#average_spread.#BINS\": \"(1) 0-3\"}, {\"ID\": \"(2) 3-9\", \"#average_spread\": 59.796561739999994, \"#average_spread.DATE\": \"2024-12-08T00:00:00\", \"#average_spread.ORIG_IDS\": null, \"#average_spread.#BINS\": \"(2) 3-9\"}, {\"ID\": \"(3) 9-18\", \"#average_spread\": 105.39336041, \"#average_spread.DATE\": \"2024-12-08T00:00:00\", \"#average_spread.ORIG_IDS\": \"BH393780 Corp\", \"#average_spread.#BINS\": \"(3) 9-18\"}, {\"ID\": \"(4) 18-30\", \"#average_spread\": 131.72793756, \"#average_spread.DATE\": \"2024-12-08T00:00:00\", \"#average_spread.ORIG_IDS\": \"BH393781 Corp\", \"#average_spread.#BINS\": \"(4) 18-30\"}, {\"ID\": \"(5) 30+\", \"#average_spread\": 150.33605297, \"#average_spread.DATE\": \"2024-12-08T00:00:00\", \"#average_spread.ORIG_IDS\": \"BH393782 Corp\", \"#average_spread.#BINS\": \"(5) 30+\"}]}}, {\"mode\": \"vega-lite\"});\n", | ||
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-801f0105c2f137aacf83e68239930d6c\"}, \"mark\": {\"type\": \"bar\"}, \"encoding\": {\"tooltip\": [{\"field\": \"ID\", \"type\": \"nominal\"}, {\"field\": \"#average_spread\", \"type\": \"quantitative\"}], \"x\": {\"field\": \"ID\", \"type\": \"nominal\"}, \"y\": {\"field\": \"#average_spread\", \"type\": \"quantitative\"}}, \"params\": [{\"name\": \"param_1\", \"select\": {\"type\": \"interval\", \"encodings\": [\"x\", \"y\"]}, \"bind\": \"scales\"}], \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"datasets\": {\"data-801f0105c2f137aacf83e68239930d6c\": [{\"ID\": \"(1) 0-3\", \"#average_spread\": 30.6383108, \"#average_spread.DATE\": \"2024-12-10T00:00:00\", \"#average_spread.ORIG_IDS\": \"QZ552396 Corp\", \"#average_spread.#BINS\": \"(1) 0-3\"}, {\"ID\": \"(2) 3-9\", \"#average_spread\": 59.772150996666674, \"#average_spread.DATE\": \"2024-12-10T00:00:00\", \"#average_spread.ORIG_IDS\": null, \"#average_spread.#BINS\": \"(2) 3-9\"}, {\"ID\": \"(3) 9-18\", \"#average_spread\": 106.72234053, \"#average_spread.DATE\": \"2024-12-10T00:00:00\", \"#average_spread.ORIG_IDS\": \"BH393780 Corp\", \"#average_spread.#BINS\": \"(3) 9-18\"}, {\"ID\": \"(4) 18-30\", \"#average_spread\": 129.94541384, \"#average_spread.DATE\": \"2024-12-10T00:00:00\", \"#average_spread.ORIG_IDS\": \"BH393781 Corp\", \"#average_spread.#BINS\": \"(4) 18-30\"}, {\"ID\": \"(5) 30+\", \"#average_spread\": 151.31863442, \"#average_spread.DATE\": \"2024-12-10T00:00:00\", \"#average_spread.ORIG_IDS\": \"BH393782 Corp\", \"#average_spread.#BINS\": \"(5) 30+\"}]}}, {\"mode\": \"vega-lite\"});\n", | ||
"</script>" | ||
], | ||
"text/plain": [ | ||
|
@@ -709,6 +708,149 @@ | |
"df" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"shape: (5, 6)\n", | ||
"┌───────────────┬───────────────────┬──────────────────┬────────────┬─────────────┬────────────┐\n", | ||
"│ ID ┆ name() ┆ #rank ┆ #nxt_call ┆ #oas ┆ #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 ┆ 615.798149 ┆ 2024-12-10 │\n", | ||
"│ BS116983 Corp ┆ GTN 5 ⅜ 11/15/31 ┆ Sr Unsecured ┆ 2026-11-15 ┆ 1144.393892 ┆ 2024-12-10 │\n", | ||
"│ AV438089 Corp ┆ GTN 7 05/15/27 ┆ Sr Unsecured ┆ 2024-12-17 ┆ 389.022271 ┆ 2024-12-10 │\n", | ||
"│ ZO860846 Corp ┆ GTN 4 ¾ 10/15/30 ┆ Sr Unsecured ┆ 2025-10-15 ┆ 1184.969597 ┆ 2024-12-10 │\n", | ||
"│ LW375188 Corp ┆ GTN 5 ⅞ 07/15/26 ┆ Sr Unsecured ┆ 2025-01-06 ┆ 185.544312 ┆ 2024-12-10 │\n", | ||
"└───────────────┴───────────────────┴──────────────────┴────────────┴─────────────┴────────────┘\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
"<style>\n", | ||
" #altair-viz-34062ea51e914bc9915a2dbd62677983.vega-embed {\n", | ||
" width: 100%;\n", | ||
" display: flex;\n", | ||
" }\n", | ||
"\n", | ||
" #altair-viz-34062ea51e914bc9915a2dbd62677983.vega-embed details,\n", | ||
" #altair-viz-34062ea51e914bc9915a2dbd62677983.vega-embed details summary {\n", | ||
" position: relative;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<div id=\"altair-viz-34062ea51e914bc9915a2dbd62677983\"></div>\n", | ||
"<script type=\"text/javascript\">\n", | ||
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n", | ||
" (function(spec, embedOpt){\n", | ||
" let outputDiv = document.currentScript.previousElementSibling;\n", | ||
" if (outputDiv.id !== \"altair-viz-34062ea51e914bc9915a2dbd62677983\") {\n", | ||
" outputDiv = document.getElementById(\"altair-viz-34062ea51e914bc9915a2dbd62677983\");\n", | ||
" }\n", | ||
" const paths = {\n", | ||
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n", | ||
" \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n", | ||
" \"vega-lite\": \"https://cdn.jsdelivr.net/npm/[email protected]?noext\",\n", | ||
" \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n", | ||
" };\n", | ||
"\n", | ||
" function maybeLoadScript(lib, version) {\n", | ||
" var key = `${lib.replace(\"-\", \"\")}_version`;\n", | ||
" return (VEGA_DEBUG[key] == version) ?\n", | ||
" Promise.resolve(paths[lib]) :\n", | ||
" new Promise(function(resolve, reject) {\n", | ||
" var s = document.createElement('script');\n", | ||
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n", | ||
" s.async = true;\n", | ||
" s.onload = () => {\n", | ||
" VEGA_DEBUG[key] = version;\n", | ||
" return resolve(paths[lib]);\n", | ||
" };\n", | ||
" s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", | ||
" s.src = paths[lib];\n", | ||
" });\n", | ||
" }\n", | ||
"\n", | ||
" function showError(err) {\n", | ||
" outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", | ||
" throw err;\n", | ||
" }\n", | ||
"\n", | ||
" function displayChart(vegaEmbed) {\n", | ||
" vegaEmbed(outputDiv, spec, embedOpt)\n", | ||
" .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", | ||
" }\n", | ||
"\n", | ||
" if(typeof define === \"function\" && define.amd) {\n", | ||
" requirejs.config({paths});\n", | ||
" require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", | ||
" } else {\n", | ||
" maybeLoadScript(\"vega\", \"5\")\n", | ||
" .then(() => maybeLoadScript(\"vega-lite\", \"5.20.1\"))\n", | ||
" .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n", | ||
" .catch(showError)\n", | ||
" .then(() => displayChart(vegaEmbed));\n", | ||
" }\n", | ||
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"layer\": [{\"mark\": {\"type\": \"point\"}, \"encoding\": {\"shape\": {\"field\": \"#rank\", \"type\": \"nominal\"}, \"tooltip\": [{\"field\": \"#nxt_call\", \"type\": \"temporal\"}, {\"field\": \"#oas\", \"type\": \"quantitative\"}, {\"field\": \"#rank\", \"type\": \"nominal\"}], \"x\": {\"field\": \"#nxt_call\", \"type\": \"temporal\"}, \"y\": {\"field\": \"#oas\", \"type\": \"quantitative\"}}, \"name\": \"view_4\"}, {\"mark\": {\"type\": \"text\", \"baseline\": \"bottom\"}, \"encoding\": {\"shape\": {\"field\": \"#rank\", \"type\": \"nominal\"}, \"text\": {\"field\": \"name()\", \"type\": \"nominal\"}, \"tooltip\": [{\"field\": \"#nxt_call\", \"type\": \"temporal\"}, {\"field\": \"#oas\", \"type\": \"quantitative\"}, {\"field\": \"#rank\", \"type\": \"nominal\"}], \"x\": {\"field\": \"#nxt_call\", \"type\": \"temporal\"}, \"y\": {\"field\": \"#oas\", \"type\": \"quantitative\"}}}], \"data\": {\"name\": \"data-140d99037d9a15bfdfefea22638b9309\"}, \"params\": [{\"name\": \"param_10\", \"select\": {\"type\": \"interval\", \"encodings\": [\"x\", \"y\"]}, \"bind\": \"scales\", \"views\": [\"view_4\"]}], \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"datasets\": {\"data-140d99037d9a15bfdfefea22638b9309\": [{\"ID\": \"YX231113 Corp\", \"name()\": \"GTN 10 \\u00bd 07/15/29\", \"#rank\": \"1st Lien Secured\", \"#nxt_call\": \"2026-07-15T00:00:00\", \"#oas\": 615.7981494, \"#oas.DATE\": \"2024-12-10T00:00:00\"}, {\"ID\": \"BS116983 Corp\", \"name()\": \"GTN 5 \\u215c 11/15/31\", \"#rank\": \"Sr Unsecured\", \"#nxt_call\": \"2026-11-15T00:00:00\", \"#oas\": 1144.39389241, \"#oas.DATE\": \"2024-12-10T00:00:00\"}, {\"ID\": \"AV438089 Corp\", \"name()\": \"GTN 7 05/15/27\", \"#rank\": \"Sr Unsecured\", \"#nxt_call\": \"2024-12-17T00:00:00\", \"#oas\": 389.02227142, \"#oas.DATE\": \"2024-12-10T00:00:00\"}, {\"ID\": \"ZO860846 Corp\", \"name()\": \"GTN 4 \\u00be 10/15/30\", \"#rank\": \"Sr Unsecured\", \"#nxt_call\": \"2025-10-15T00:00:00\", \"#oas\": 1184.96959681, \"#oas.DATE\": \"2024-12-10T00:00:00\"}, {\"ID\": \"LW375188 Corp\", \"name()\": \"GTN 5 \\u215e 07/15/26\", \"#rank\": \"Sr Unsecured\", \"#nxt_call\": \"2025-01-06T00:00:00\", \"#oas\": 185.54431211, \"#oas.DATE\": \"2024-12-10T00:00:00\"}]}}, {\"mode\": \"vega-lite\"});\n", | ||
"</script>" | ||
], | ||
"text/plain": [ | ||
"alt.LayerChart(...)" | ||
] | ||
}, | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Get Bond Universe from Equity Ticker\n", | ||
"query=\"\"\"\n", | ||
"let(#rank=normalized_payment_rank();\n", | ||
" #oas=spread(st=oas);\n", | ||
" #nxt_call=nxt_call_dt();\n", | ||
" )\n", | ||
"get(name(), #rank, #nxt_call, #oas)\n", | ||
"for(filter(bonds('GTN US Equity'), series() == '144A'))\n", | ||
"\"\"\"\n", | ||
"\n", | ||
"with BQuery() as bq:\n", | ||
" df = bq.bql(query)\n", | ||
"print(df)\n", | ||
"fig = df.plot.scatter(x=\"#nxt_call:T\",y=\"#oas:Q\", shape=\"#rank:N\")\n", | ||
"fig + fig.mark_text(baseline='bottom').encode(text=\"name()\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Total Return of GTN Bonds\n", | ||
"# TODO: FIX NaN\n", | ||
"\n", | ||
"# Get Bond Universe from Equity Ticker\n", | ||
"query=\"\"\"\n", | ||
"let(#rng = range(-3M, -1D);\n", | ||
" #rets = return_series(calc_interval=#rng,per=D);\n", | ||
" )\n", | ||
"get(#rets)\n", | ||
"for(filter(bonds('GTN US Equity'), series() == '144A'))\n", | ||
"\"\"\"\n", | ||
"\n", | ||
"with BQuery() as bq:\n", | ||
" df = bq.bql(query)\n", | ||
"print(df)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
|
@@ -719,7 +861,7 @@ | |
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
|
@@ -733,9 +875,9 @@ | |
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.8" | ||
"version": "3.12.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
"nbformat_minor": 4 | ||
} |
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,17 @@ | ||
{ | ||
"ID": [ | ||
"YX231113 Corp", | ||
"YX231113 Corp", | ||
"YX231113 Corp" | ||
], | ||
"#rets": [ | ||
"NaN", | ||
0.0002732545901463368, | ||
-0.0008638730296779248 | ||
], | ||
"#rets.DATE": [ | ||
"2024-12-07T00:00:00Z", | ||
"2024-12-08T00:00:00Z", | ||
"2024-12-09T00:00:00Z" | ||
] | ||
} |
Oops, something went wrong.