-
Notifications
You must be signed in to change notification settings - Fork 263
Query multiple PSE symbols with parallelization #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ajdajd
wants to merge
8
commits into
enzoampil:master
Choose a base branch
from
ajdajd:multiple-pse-query
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3123504
Merge enzoampil/fastquant to ajdajd/fastquant
ajdajd e9d96d9
Merge pull request #5 from enzoampil/master
ajdajd c63ac51
Implement get_pse_data_multiple
ajdajd d8d0353
Add demo notebook for get_pse_data_multiple
ajdajd ad65d62
Update example notebook
ajdajd 7adb58d
Add demo notebook
ajdajd d957f92
Add type checking for symbols
ajdajd 86fb42f
Update demo notebook
ajdajd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,378 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.8.5" | ||
}, | ||
"colab": { | ||
"name": "get_pse_data_multiple_demo.ipynb", | ||
"provenance": [], | ||
"toc_visible": true | ||
} | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "h-tZ3KhfPQW6" | ||
}, | ||
"source": [ | ||
"*This notebook was run with Google Colab.*" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "FcVD1bJrL_RG" | ||
}, | ||
"source": [ | ||
"from fastquant import get_pse_data, get_pse_data_multiple\r\n", | ||
"from datetime import datetime" | ||
], | ||
"execution_count": 1, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "obCQra9qL_RL" | ||
}, | ||
"source": [ | ||
"# Define variables" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "vqnwvVoAL_RL" | ||
}, | ||
"source": [ | ||
"# Define a list of stock symbols\n", | ||
"psei = [\n", | ||
" \"AEV\",\n", | ||
" \"AP\",\n", | ||
" \"AGI\",\n", | ||
" \"AC\",\n", | ||
" \"ALI\",\n", | ||
" \"BPI\",\n", | ||
" \"BDO\",\n", | ||
" \"BLOOM\",\n", | ||
" \"DMC\",\n", | ||
" \"EMP\",\n", | ||
" \"FGEN\",\n", | ||
" \"GLO\",\n", | ||
" \"GTCAP\",\n", | ||
" \"ICT\",\n", | ||
" \"JGS\",\n", | ||
" \"JFC\",\n", | ||
" \"LTG\",\n", | ||
" \"MER\",\n", | ||
" \"MEG\",\n", | ||
" \"MPI\",\n", | ||
" \"MBT\",\n", | ||
" \"TEL\",\n", | ||
" \"PGOLD\",\n", | ||
" \"RLC\",\n", | ||
" \"RRHI\",\n", | ||
" \"SMC\",\n", | ||
" \"SECB\",\n", | ||
" \"SM\",\n", | ||
" \"SMPH\",\n", | ||
" \"URC\",\n", | ||
"]\n", | ||
"\n", | ||
"# Define start and stop dates\n", | ||
"start_date = \"2021-01-01\"\n", | ||
"end_date = datetime.utcnow().strftime(\"%Y-%m-%d\")" | ||
], | ||
"execution_count": 2, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "nqLGsSenL_RM" | ||
}, | ||
"source": [ | ||
"# Method 1: Without parallelization" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "AOLREYbCL_RM", | ||
"outputId": "c27f80a7-2ff2-4bd4-89f9-c5925bb3898b", | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
} | ||
}, | ||
"source": [ | ||
"%%time\n", | ||
"\n", | ||
"for symbol in psei:\n", | ||
" get_pse_data(symbol, start_date, end_date)" | ||
], | ||
"execution_count": 3, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"text": [ | ||
"193it [00:24, 7.72it/s]\n", | ||
"193it [00:24, 8.54it/s]\n", | ||
"193it [00:25, 8.02it/s]\n", | ||
"193it [00:26, 8.21it/s]\n", | ||
"193it [00:25, 8.83it/s]\n", | ||
"193it [00:25, 8.30it/s]\n", | ||
"193it [00:24, 8.73it/s]\n", | ||
"193it [00:26, 8.22it/s]\n", | ||
"193it [00:24, 5.93it/s]\n", | ||
"193it [00:25, 6.94it/s]\n", | ||
"193it [00:29, 9.29it/s]\n", | ||
"193it [00:26, 8.26it/s]\n", | ||
"193it [00:26, 8.53it/s]\n", | ||
"193it [00:26, 7.34it/s]\n", | ||
"193it [00:26, 7.40it/s]\n", | ||
"193it [00:26, 6.06it/s]\n", | ||
"193it [00:27, 9.16it/s]\n", | ||
"193it [00:23, 8.38it/s]\n", | ||
"193it [00:24, 9.32it/s]\n", | ||
"193it [00:24, 7.80it/s]\n", | ||
"193it [00:25, 7.72it/s]\n", | ||
"193it [00:31, 6.21it/s]\n", | ||
"193it [00:25, 9.26it/s]\n", | ||
"193it [00:24, 7.66it/s]\n", | ||
"193it [00:25, 6.85it/s]\n", | ||
"193it [00:25, 7.69it/s]\n", | ||
"193it [00:26, 6.93it/s]\n", | ||
"193it [00:23, 9.43it/s]\n", | ||
"193it [00:26, 8.46it/s]\n", | ||
"193it [00:27, 8.13it/s]" | ||
], | ||
"name": "stderr" | ||
}, | ||
{ | ||
"output_type": "stream", | ||
"text": [ | ||
"CPU times: user 49 s, sys: 4.33 s, total: 53.3 s\n", | ||
"Wall time: 13min 14s\n" | ||
], | ||
"name": "stdout" | ||
}, | ||
{ | ||
"output_type": "stream", | ||
"text": [ | ||
"\n" | ||
], | ||
"name": "stderr" | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "3_nL-bnRL_RN" | ||
}, | ||
"source": [ | ||
"# Method 2: With parallelization" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "WtCjazDsL_RN", | ||
"outputId": "2dfbca92-ec17-411c-a15d-c64ddc5b45a4", | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
} | ||
}, | ||
"source": [ | ||
"%%time\n", | ||
"\n", | ||
"data = get_pse_data_multiple(\n", | ||
" psei, n_jobs=-1, start_date=start_date, end_date=end_date\n", | ||
")" | ||
], | ||
"execution_count": 4, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"text": [ | ||
"[Parallel(n_jobs=-1)]: Using backend LokyBackend with 2 concurrent workers.\n" | ||
], | ||
"name": "stderr" | ||
}, | ||
{ | ||
"output_type": "stream", | ||
"text": [ | ||
"CPU times: user 110 ms, sys: 44.4 ms, total: 155 ms\n", | ||
"Wall time: 8min 34s\n" | ||
], | ||
"name": "stdout" | ||
}, | ||
{ | ||
"output_type": "stream", | ||
"text": [ | ||
"[Parallel(n_jobs=-1)]: Done 30 out of 30 | elapsed: 8.6min finished\n" | ||
], | ||
"name": "stderr" | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "iDkkY5qSL_RO" | ||
}, | ||
"source": [ | ||
"## Accessing individual stock data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "ciFsQ4J1L_RO", | ||
"outputId": "20f4b574-697a-47c7-af2a-f89322941d3a", | ||
"colab": { | ||
"base_uri": "https://localhost:8080/", | ||
"height": 235 | ||
} | ||
}, | ||
"source": [ | ||
"data[\"JFC\"].head()" | ||
], | ||
"execution_count": 5, | ||
"outputs": [ | ||
{ | ||
"output_type": "execute_result", | ||
"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>open</th>\n", | ||
" <th>high</th>\n", | ||
" <th>low</th>\n", | ||
" <th>close</th>\n", | ||
" <th>value</th>\n", | ||
" <th>volume</th>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>dt</th>\n", | ||
" <th></th>\n", | ||
" <th></th>\n", | ||
" <th></th>\n", | ||
" <th></th>\n", | ||
" <th></th>\n", | ||
" <th></th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>2021-01-04</th>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>194.4</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>625440.0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2021-01-05</th>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>194.9</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>513300.0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2021-01-06</th>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>194.4</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>565340.0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2021-01-07</th>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>192.6</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>802590.0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2021-01-08</th>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>192.5</td>\n", | ||
" <td>NaN</td>\n", | ||
" <td>720470.0</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" open high low close value volume\n", | ||
"dt \n", | ||
"2021-01-04 NaN NaN NaN 194.4 NaN 625440.0\n", | ||
"2021-01-05 NaN NaN NaN 194.9 NaN 513300.0\n", | ||
"2021-01-06 NaN NaN NaN 194.4 NaN 565340.0\n", | ||
"2021-01-07 NaN NaN NaN 192.6 NaN 802590.0\n", | ||
"2021-01-08 NaN NaN NaN 192.5 NaN 720470.0" | ||
] | ||
}, | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"execution_count": 5 | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "9LT0bBAJPEVN" | ||
}, | ||
"source": [ | ||
"" | ||
], | ||
"execution_count": null, | ||
"outputs": [] | ||
} | ||
] | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.