-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from dalenguyen/dev
Added sample & disclaimer
- Loading branch information
Showing
2 changed files
with
248 additions
and
3 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
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,231 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 26, | ||
"id": "incorporate-benefit", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd \n", | ||
"import datetime" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 25, | ||
"id": "fancy-problem", | ||
"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>low</th>\n", | ||
" <th>open</th>\n", | ||
" <th>volume</th>\n", | ||
" <th>high</th>\n", | ||
" <th>close</th>\n", | ||
" <th>date</th>\n", | ||
" <th>adjclose</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>0</th>\n", | ||
" <td>214.809998</td>\n", | ||
" <td>222.529999</td>\n", | ||
" <td>37130100</td>\n", | ||
" <td>223.000000</td>\n", | ||
" <td>217.690002</td>\n", | ||
" <td>1609770600</td>\n", | ||
" <td>217.189774</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>1</th>\n", | ||
" <td>215.699997</td>\n", | ||
" <td>217.259995</td>\n", | ||
" <td>23823000</td>\n", | ||
" <td>218.520004</td>\n", | ||
" <td>217.899994</td>\n", | ||
" <td>1609857000</td>\n", | ||
" <td>217.399292</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2</th>\n", | ||
" <td>211.940002</td>\n", | ||
" <td>212.169998</td>\n", | ||
" <td>35930700</td>\n", | ||
" <td>216.490005</td>\n", | ||
" <td>212.250000</td>\n", | ||
" <td>1609943400</td>\n", | ||
" <td>211.762268</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3</th>\n", | ||
" <td>213.710007</td>\n", | ||
" <td>214.039993</td>\n", | ||
" <td>27694500</td>\n", | ||
" <td>219.339996</td>\n", | ||
" <td>218.289993</td>\n", | ||
" <td>1610029800</td>\n", | ||
" <td>217.788391</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>4</th>\n", | ||
" <td>217.029999</td>\n", | ||
" <td>218.679993</td>\n", | ||
" <td>22956200</td>\n", | ||
" <td>220.580002</td>\n", | ||
" <td>219.619995</td>\n", | ||
" <td>1610116200</td>\n", | ||
" <td>219.115341</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" low open volume high close date \\\n", | ||
"0 214.809998 222.529999 37130100 223.000000 217.690002 1609770600 \n", | ||
"1 215.699997 217.259995 23823000 218.520004 217.899994 1609857000 \n", | ||
"2 211.940002 212.169998 35930700 216.490005 212.250000 1609943400 \n", | ||
"3 213.710007 214.039993 27694500 219.339996 218.289993 1610029800 \n", | ||
"4 217.029999 218.679993 22956200 220.580002 219.619995 1610116200 \n", | ||
"\n", | ||
" adjclose \n", | ||
"0 217.189774 \n", | ||
"1 217.399292 \n", | ||
"2 211.762268 \n", | ||
"3 217.788391 \n", | ||
"4 219.115341 " | ||
] | ||
}, | ||
"execution_count": 25, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from stockai import Stock\n", | ||
"\n", | ||
"td = Stock('MSFT')\n", | ||
"prices_list = td.get_historical_prices('2021-01-01', '2021-01-30')\n", | ||
"\n", | ||
"# Delete meta key\n", | ||
"del(prices_list['meta'])\n", | ||
"\n", | ||
"# print(prices_list)\n", | ||
"\n", | ||
"df = pd.DataFrame.from_dict(prices_list)\n", | ||
"df.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 45, | ||
"id": "refined-attendance", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
" AMZN MSFT INTC GOOG\n", | ||
"0 3206.199951 231.426987 55.175091 1835.739990\n", | ||
"1 3342.879883 239.099304 56.347969 1901.349976\n", | ||
"2 3380.000000 238.959625 57.650070 1927.510010\n", | ||
"3 3312.530029 242.441620 57.332001 2070.070068\n", | ||
"4 3331.000000 241.453888 58.790001 2062.370117\n", | ||
"5 3352.149902 241.643448 58.180000 2098.000000\n", | ||
"6 3322.939941 241.912842 59.160000 2092.909912\n", | ||
"7 3305.000000 243.209854 58.779999 2083.510010\n", | ||
"8 3286.580078 242.262039 58.860001 2095.379883\n", | ||
"9 3262.129883 243.928192 60.660000 2095.889893\n", | ||
"10 3277.709961 244.427048 61.810001 2104.110107\n", | ||
"11 3268.949951 243.139999 62.470001 2121.899902\n", | ||
"12 3308.639893 244.199997 61.849998 2128.310059\n", | ||
"13 3328.229980 243.789993 61.610001 2117.199951\n", | ||
"14 3249.899902 240.970001 63.009998 2101.139893\n", | ||
"15 3180.739990 234.509995 60.709999 2064.879883\n", | ||
"16 3194.500000 233.270004 61.119999 2070.860107\n", | ||
"17 3159.530029 234.550003 63.189999 2095.169922\n", | ||
"18 3057.159912 228.990005 60.400002 2031.359985\n", | ||
"19 3092.929932 232.380005 60.779999 2036.859985\n", | ||
"\n", | ||
"Open Price for Mircrosoft \n", | ||
"\n", | ||
"[235.99000549316406, 235.05999755859375, 241.3000030517578, 239.57000732421875, 242.66000366210938, 242.22999572753906, 243.14999389648438, 241.8699951171875, 245.0, 244.77999877929688, 243.92999267578125, 245.02999877929688, 241.32000732421875, 241.8000030517578, 243.75, 237.4199981689453, 230.3300018310547, 230.00999450683594, 232.0800018310547, 231.52999877929688]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"stocks = ['AMZN', 'MSFT', 'INTC', 'GOOG']\n", | ||
"\n", | ||
"start = (datetime.datetime.today() - datetime.timedelta(30)).strftime('%Y-%m-%d')\n", | ||
"end = datetime.datetime.today().strftime('%Y-%m-%d')\n", | ||
"\n", | ||
"# print(start)\n", | ||
"# print(end)\n", | ||
"\n", | ||
"cl_price = pd.DataFrame()\n", | ||
"ohlcv_data = {}\n", | ||
"\n", | ||
"# Loop through stock\n", | ||
"for ticker in stocks:\n", | ||
" sk = Stock(ticker)\n", | ||
" data = sk.get_historical_prices(start, end)\n", | ||
" del(data['meta'])\n", | ||
"\n", | ||
" ohlcv_data[ticker] = data\n", | ||
"\n", | ||
"# print(len(data['open']))\n", | ||
" cl_price[ticker] = data['adjclose']\n", | ||
" \n", | ||
"print(cl_price)\n", | ||
"\n", | ||
"print('\\nOpen Price for Mircrosoft \\n')\n", | ||
"\n", | ||
"print(ohlcv_data['MSFT']['open'])" | ||
] | ||
} | ||
], | ||
"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.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |