From 6ea183419a3b0f37d4d9fe805a077ee6c61f3fef Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Mon, 18 Nov 2024 01:03:14 +0000 Subject: [PATCH] updated python ntoebook --- notebooks/python-notebook.ipynb | 134 ++++++++++++++++++++++---------- 1 file changed, 94 insertions(+), 40 deletions(-) diff --git a/notebooks/python-notebook.ipynb b/notebooks/python-notebook.ipynb index c70e3c3..fb445b8 100644 --- a/notebooks/python-notebook.ipynb +++ b/notebooks/python-notebook.ipynb @@ -12,55 +12,64 @@ "# source .venv/bin/activate\n", "./.venv/Scripts/activate\n", "\n", - "pip install maturin\n", + "pip install maturin ipywidgets\n", "\n", "maturin develop --release\n", - "```" + "```\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Import Python packages\n" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "e:\\Work\\ruzt\\msyrs\\.venv\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "import macrosynergy\n", "import pandas as pd\n", - "import numpy as np\n" + "import numpy as np\n", + "import polars as pl\n", + "import os" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Import Python bindings - `msyrs`\n" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "import msyrs\n", - "import polars as pl" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "DATA_FOLDER_PATH = \"E:/Work/jpmaqs-data\"" + "import msyrs" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, + "outputs": [], + "source": [ + "DATA_FOLDER_PATH = \"E:/Work/jpmaqs-data\"\n", + "\n", + "DQ_CLIENT_ID = os.getenv(\"DQ_CLIENT_ID\")\n", + "DQ_CLIENT_SECRET = os.getenv(\"DQ_CLIENT_SECRET\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, "outputs": [ { "data": { @@ -89,7 +98,7 @@ "└────────────┴─────┴────────────────────┴───────────┴─────────┴─────────┴─────────┘" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -104,7 +113,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -115,8 +124,7 @@ "ecos = \"CPIC_SA_P1M1ML12.CPIC_SJA_P3M3ML3AR.CPIC_SJA_P6M6ML6AR.CPIH_SA_P1M1ML12.CPIH_SJA_P3M3ML3AR.CPIH_SJA_P6M6ML6AR.INFTEFF_NSA.INTRGDP_NSA_P1M1ML12_3MMA.INTRGDPv5Y_NSA_P1M1ML12_3MMA.PCREDITGDP_SJA_D1M1ML12.RGDP_SA_P1Q1QL4_20QMA.RYLDIRS02Y_NSA.RYLDIRS05Y_NSA.PCREDITBN_SJA_P1M1ML12\".split(\n", " \".\"\n", ")\n", - "[\"CPIC\", \"CPIH\", \"INFTEFF\", \"INTRGDP\", \"INTRGDPv5Y\", \"PCREDITGDP\", \"RGDP\", \"RYLDIRS\", \"PCREDITBN\"]\n", - "[\"\"]\n", + "\n", "\n", "mkts = \"DU02YXR_NSA.DU05YXR_NSA.DU02YXR_VT10.DU05YXR_VT10.EQXR_NSA.EQXR_VT10.FXXR_NSA.FXXR_VT10.FXCRR_NSA.FXTARGETED_NSA.FXUNTRADABLE_NSA\".split(\n", " \".\"\n", @@ -128,7 +136,53 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "shape: (5, 7)
real_datecidxcatvaluegradingeop_lagmop_lag
datestrstrf64f64f64f64
1990-04-26"AUD""CPIC_SA_P1M1ML12"6.4345992.026.0223.0
1990-04-27"AUD""CPIC_SA_P1M1ML12"6.4345992.027.0224.0
1990-04-30"AUD""CPIC_SA_P1M1ML12"6.4345992.030.0227.0
1990-05-01"AUD""CPIC_SA_P1M1ML12"6.4345992.031.0228.0
1990-05-02"AUD""CPIC_SA_P1M1ML12"6.4345992.032.0229.0
" + ], + "text/plain": [ + "shape: (5, 7)\n", + "┌────────────┬─────┬──────────────────┬──────────┬─────────┬─────────┬─────────┐\n", + "│ real_date ┆ cid ┆ xcat ┆ value ┆ grading ┆ eop_lag ┆ mop_lag │\n", + "│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n", + "│ date ┆ str ┆ str ┆ f64 ┆ f64 ┆ f64 ┆ f64 │\n", + "╞════════════╪═════╪══════════════════╪══════════╪═════════╪═════════╪═════════╡\n", + "│ 1990-04-26 ┆ AUD ┆ CPIC_SA_P1M1ML12 ┆ 6.434599 ┆ 2.0 ┆ 26.0 ┆ 223.0 │\n", + "│ 1990-04-27 ┆ AUD ┆ CPIC_SA_P1M1ML12 ┆ 6.434599 ┆ 2.0 ┆ 27.0 ┆ 224.0 │\n", + "│ 1990-04-30 ┆ AUD ┆ CPIC_SA_P1M1ML12 ┆ 6.434599 ┆ 2.0 ┆ 30.0 ┆ 227.0 │\n", + "│ 1990-05-01 ┆ AUD ┆ CPIC_SA_P1M1ML12 ┆ 6.434599 ┆ 2.0 ┆ 31.0 ┆ 228.0 │\n", + "│ 1990-05-02 ┆ AUD ┆ CPIC_SA_P1M1ML12 ┆ 6.434599 ┆ 2.0 ┆ 32.0 ┆ 229.0 │\n", + "└────────────┴─────┴──────────────────┴──────────┴─────────┴─────────┴─────────┘" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "downloaded_df: pl.DataFrame = msyrs.download.download_jpmaqs_indicators_as_df(\n", + " client_id=DQ_CLIENT_ID,\n", + " client_secret=DQ_CLIENT_SECRET,\n", + " tickers=tickers,\n", + ")\n", + "downloaded_df.head(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -158,7 +212,7 @@ "└────────────┴─────┴──────────────────┴──────────┴─────────┴─────────┴─────────┘" ] }, - "execution_count": 6, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -172,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -182,7 +236,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -218,7 +272,7 @@ "└────────────┴─────┴───────────┴───────────┴─────────┴─────────┴─────────┘" ] }, - "execution_count": 8, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -235,7 +289,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -247,7 +301,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -282,7 +336,7 @@ "└────────────┴─────┴──────────┴───────────┴─────────┴─────────┴─────────┘" ] }, - "execution_count": 10, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -295,7 +349,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -330,7 +384,7 @@ "└────────────┴─────┴───────────┴───────────┴─────────┴─────────┴─────────┘" ] }, - "execution_count": 11, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" }