diff --git a/examples/Examples-1.ipynb b/examples/Examples-1.ipynb index 9ea00fb..b9c83db 100644 --- a/examples/Examples-1.ipynb +++ b/examples/Examples-1.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -470,7 +470,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -478,18 +478,17 @@ "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" ] }, { @@ -497,23 +496,23 @@ "text/html": [ "\n", "\n", - "
\n", + "\n", "" ], "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", + "\n", + "\n", + "" + ], + "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 } diff --git a/tests/data/cols_with_NaN.json b/tests/data/cols_with_NaN.json new file mode 100644 index 0000000..e5078a5 --- /dev/null +++ b/tests/data/cols_with_NaN.json @@ -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" + ] +} \ No newline at end of file diff --git a/tests/data/results_with_NaN_DOUBLE.json b/tests/data/results_with_NaN_DOUBLE.json new file mode 100644 index 0000000..c1fe5ed --- /dev/null +++ b/tests/data/results_with_NaN_DOUBLE.json @@ -0,0 +1,53 @@ +{ + "#rets": { + "name": "#rets", + "offsets": [ + 2 + ], + "namespace": "FUNCTION_DEFAULT", + "source": "BQLAnalyticsEngine", + "idColumn": { + "name": "ID", + "type": "STRING", + "rank": 0, + "values": [ + "YX231113 Corp", + "YX231113 Corp", + "YX231113 Corp" + ] + }, + "valuesColumn": { + "name": "VALUE", + "type": "DOUBLE", + "rank": 0, + "values": [ + "NaN", + 0.0002732545901463368, + -0.0008638730296779248 + ] + }, + "secondaryColumns": [ + { + "name": "DATE", + "type": "DATE", + "rank": 0, + "values": [ + "2024-12-07T00:00:00Z", + "2024-12-08T00:00:00Z", + "2024-12-09T00:00:00Z" + ], + "defaultDate": true + } + ], + "partialErrorMap": { + "errorIterator": null + }, + "responseExceptions": [], + "transparency": null, + "forUniverse": true, + "bqlResponseInfo": null, + "defaultDateColumnName": "DATE", + "itemPreviewStatistics": null, + "indexView": null + } +} \ No newline at end of file