Skip to content

Commit

Permalink
analysis notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
amor71 committed Jun 26, 2022
1 parent 408328c commit 6d46a97
Showing 1 changed file with 262 additions and 28 deletions.
290 changes: 262 additions & 28 deletions notebooks/recent_short_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,289 @@
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"id": "dfc6b7d0",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"sys.path.append('..')\n",
"import pandas as pd\n",
"from finrashortdata import auth, get_chunk_and_size, process"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "91613a9a",
"metadata": {},
"outputs": [],
"source": [
"client_id = os.getenv(\"TEST_API_CLIENT_ID\", None)\n",
"secret = os.getenv(\"TEST_API_SECRET\", None)\n",
"\n",
"if not client_id or not secret:\n",
" raise AssertionError(\n",
" \"tests require env variables TEST_API_CLIENT_ID, TEST_API_SECRET\"\n",
" )\n",
"token = auth(client_id, secret)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1e1b3d13",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: finrashortdata in /Users/amichayoren/venv/finra/lib/python3.10/site-packages (0.0.1)\n",
"Collecting finrashortdata\n",
" Downloading finrashortdata-0.0.11-py3-none-any.whl (17 kB)\n",
"Requirement already satisfied: requests in /Users/amichayoren/venv/finra/lib/python3.10/site-packages (from finrashortdata) (2.28.0)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /Users/amichayoren/venv/finra/lib/python3.10/site-packages (from requests->finrashortdata) (2022.6.15)\n",
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/amichayoren/venv/finra/lib/python3.10/site-packages (from requests->finrashortdata) (1.26.9)\n",
"Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/amichayoren/venv/finra/lib/python3.10/site-packages (from requests->finrashortdata) (2.0.12)\n",
"Requirement already satisfied: idna<4,>=2.5 in /Users/amichayoren/venv/finra/lib/python3.10/site-packages (from requests->finrashortdata) (3.3)\n",
"Installing collected packages: finrashortdata\n",
" Attempting uninstall: finrashortdata\n",
" Found existing installation: finrashortdata 0.0.1\n",
" Uninstalling finrashortdata-0.0.1:\n",
" Successfully uninstalled finrashortdata-0.0.1\n",
"Successfully installed finrashortdata-0.0.11\n"
"loading data (chunk_size=5000, max_records=50000)...\n",
"process() >>> took 5.21 seconds\n"
]
}
],
"source": [
"!pip install --no-cache-dir --upgrade finrashortdata"
"chunk, max_data = get_chunk_and_size(token)\n",
"df: pd.DataFrame = await process(\n",
" token=token, offset=max_data - 10 * chunk\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "91613a9a",
"execution_count": 4,
"id": "f3bc9924",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'finrashortdata'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [5]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mfinrashortdata\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m auth, get_chunk_and_size, process\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'finrashortdata'"
]
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>volume</th>\n",
" <th>shorts</th>\n",
" <th>exempt</th>\n",
" <th>short_percent</th>\n",
" </tr>\n",
" <tr>\n",
" <th>tradeReportDate</th>\n",
" <th>symbol</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"5\" valign=\"top\">2022-06-22</th>\n",
" <th>WAT</th>\n",
" <td>68250</td>\n",
" <td>31043</td>\n",
" <td>23</td>\n",
" <td>45.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>WATT</th>\n",
" <td>74573</td>\n",
" <td>42238</td>\n",
" <td>90</td>\n",
" <td>56.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>WAVD</th>\n",
" <td>10897</td>\n",
" <td>1605</td>\n",
" <td>0</td>\n",
" <td>14.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>WAVE</th>\n",
" <td>2625</td>\n",
" <td>2045</td>\n",
" <td>0</td>\n",
" <td>77.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>WB</th>\n",
" <td>209831</td>\n",
" <td>54776</td>\n",
" <td>1257</td>\n",
" <td>26.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"5\" valign=\"top\">2022-06-24</th>\n",
" <th>ZWS</th>\n",
" <td>327092</td>\n",
" <td>108253</td>\n",
" <td>0</td>\n",
" <td>33.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ZY</th>\n",
" <td>564340</td>\n",
" <td>305461</td>\n",
" <td>1700</td>\n",
" <td>54.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ZYME</th>\n",
" <td>264434</td>\n",
" <td>170109</td>\n",
" <td>1</td>\n",
" <td>64.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ZYNE</th>\n",
" <td>214174</td>\n",
" <td>106467</td>\n",
" <td>41</td>\n",
" <td>49.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ZYXI</th>\n",
" <td>134683</td>\n",
" <td>80457</td>\n",
" <td>0</td>\n",
" <td>59.7</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>26752 rows × 4 columns</p>\n",
"</div>"
],
"text/plain": [
" volume shorts exempt short_percent\n",
"tradeReportDate symbol \n",
"2022-06-22 WAT 68250 31043 23 45.5\n",
" WATT 74573 42238 90 56.6\n",
" WAVD 10897 1605 0 14.7\n",
" WAVE 2625 2045 0 77.9\n",
" WB 209831 54776 1257 26.1\n",
"... ... ... ... ...\n",
"2022-06-24 ZWS 327092 108253 0 33.1\n",
" ZY 564340 305461 1700 54.1\n",
" ZYME 264434 170109 1 64.3\n",
" ZYNE 214174 106467 41 49.7\n",
" ZYXI 134683 80457 0 59.7\n",
"\n",
"[26752 rows x 4 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from finrashortdata import auth, get_chunk_and_size, process"
"df"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b121d1a7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>volume</th>\n",
" <th>shorts</th>\n",
" <th>exempt</th>\n",
" <th>short_percent</th>\n",
" </tr>\n",
" <tr>\n",
" <th>tradeReportDate</th>\n",
" <th>symbol</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2022-06-23</th>\n",
" <th>AAPL</th>\n",
" <td>30331923</td>\n",
" <td>17265498</td>\n",
" <td>59683</td>\n",
" <td>56.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-06-24</th>\n",
" <th>AAPL</th>\n",
" <td>29744419</td>\n",
" <td>16765515</td>\n",
" <td>87007</td>\n",
" <td>56.4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" volume shorts exempt short_percent\n",
"tradeReportDate symbol \n",
"2022-06-23 AAPL 30331923 17265498 59683 56.9\n",
"2022-06-24 AAPL 29744419 16765515 87007 56.4"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[df.index.isin([\"AAPL\"], level=\"symbol\")]"
]
}
],
Expand Down

0 comments on commit 6d46a97

Please sign in to comment.