Stock/test.ipynb

690 lines
58 KiB
Plaintext
Raw Normal View History

2022-05-25 03:16:39 +09:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sqlite3\n",
"from typing import Dict\n",
"from render import * \n",
"import db as database\n",
"from jinja2 import Environment, PackageLoader, select_autoescape\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 2,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"import importlib"
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 3,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2022-06-06 10:55:12 +09:00
"<module 'db' from '/data/sss/f/tt/Stock/db.py'>"
2022-05-25 03:16:39 +09:00
]
},
2022-06-06 10:55:12 +09:00
"execution_count": 3,
2022-05-25 03:16:39 +09:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"importlib.reload(database)"
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 4,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"db = sqlite3.connect(\"stock.db\")\n"
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 5,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"krx = database.GetAllKRXCorp(db)"
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 6,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"krxDf = pd.DataFrame([corp.toDict() for corp in krx])"
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 27,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
2022-06-06 10:55:12 +09:00
"data = GetStockPriceFrom(db,\"294870\", 61)\n"
2022-05-25 03:16:39 +09:00
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 28,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"s = pd.DataFrame(data, columns=[s for s in database.STOCK_INDEX.__members__.keys()])"
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 29,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"s.set_index(\"DATE\", inplace=True)"
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 30,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"stock = s"
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 31,
2022-05-25 03:16:39 +09:00
"metadata": {},
2022-06-06 10:55:12 +09:00
"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>CODE</th>\n",
" <th>CLOSE</th>\n",
" <th>DIFF</th>\n",
" <th>OPEN</th>\n",
" <th>HIGH</th>\n",
" <th>LOW</th>\n",
" <th>VOLUME</th>\n",
" </tr>\n",
" <tr>\n",
" <th>DATE</th>\n",
" <th></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>2022-06-03</th>\n",
" <td>294870</td>\n",
" <td>13700</td>\n",
" <td>100</td>\n",
" <td>13700</td>\n",
" <td>13800</td>\n",
" <td>13600</td>\n",
" <td>175508</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-06-02</th>\n",
" <td>294870</td>\n",
" <td>13600</td>\n",
" <td>250</td>\n",
" <td>13850</td>\n",
" <td>13850</td>\n",
" <td>13550</td>\n",
" <td>350113</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-05-31</th>\n",
" <td>294870</td>\n",
" <td>13850</td>\n",
" <td>50</td>\n",
" <td>13850</td>\n",
" <td>13950</td>\n",
" <td>13800</td>\n",
" <td>276819</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-05-30</th>\n",
" <td>294870</td>\n",
" <td>13800</td>\n",
" <td>100</td>\n",
" <td>13850</td>\n",
" <td>13950</td>\n",
" <td>13750</td>\n",
" <td>191087</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-05-27</th>\n",
" <td>294870</td>\n",
" <td>13700</td>\n",
" <td>150</td>\n",
" <td>14050</td>\n",
" <td>14100</td>\n",
" <td>13600</td>\n",
" <td>392051</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-15</th>\n",
" <td>294870</td>\n",
" <td>16200</td>\n",
" <td>200</td>\n",
" <td>14800</td>\n",
" <td>16450</td>\n",
" <td>14750</td>\n",
" <td>2701677</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-14</th>\n",
" <td>294870</td>\n",
" <td>16400</td>\n",
" <td>2050</td>\n",
" <td>18500</td>\n",
" <td>19250</td>\n",
" <td>16000</td>\n",
" <td>4436719</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-11</th>\n",
" <td>294870</td>\n",
" <td>18450</td>\n",
" <td>100</td>\n",
" <td>18450</td>\n",
" <td>18500</td>\n",
" <td>18000</td>\n",
" <td>997048</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-10</th>\n",
" <td>294870</td>\n",
" <td>18350</td>\n",
" <td>1400</td>\n",
" <td>17450</td>\n",
" <td>18350</td>\n",
" <td>17400</td>\n",
" <td>1754702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-08</th>\n",
" <td>294870</td>\n",
" <td>16950</td>\n",
" <td>450</td>\n",
" <td>17100</td>\n",
" <td>17500</td>\n",
" <td>16800</td>\n",
" <td>878964</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>61 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
" CODE CLOSE DIFF OPEN HIGH LOW VOLUME\n",
"DATE \n",
"2022-06-03 294870 13700 100 13700 13800 13600 175508\n",
"2022-06-02 294870 13600 250 13850 13850 13550 350113\n",
"2022-05-31 294870 13850 50 13850 13950 13800 276819\n",
"2022-05-30 294870 13800 100 13850 13950 13750 191087\n",
"2022-05-27 294870 13700 150 14050 14100 13600 392051\n",
"... ... ... ... ... ... ... ...\n",
"2022-03-15 294870 16200 200 14800 16450 14750 2701677\n",
"2022-03-14 294870 16400 2050 18500 19250 16000 4436719\n",
"2022-03-11 294870 18450 100 18450 18500 18000 997048\n",
"2022-03-10 294870 18350 1400 17450 18350 17400 1754702\n",
"2022-03-08 294870 16950 450 17100 17500 16800 878964\n",
"\n",
"[61 rows x 7 columns]"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
2022-05-25 03:16:39 +09:00
"source": [
2022-06-06 10:55:12 +09:00
"stock"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2022-06-03 175508\n",
"2022-06-02 350113\n",
"2022-05-31 276819\n",
"2022-05-30 191087\n",
"2022-05-27 392051\n",
" ... \n",
"2022-03-15 2701677\n",
"2022-03-14 4436719\n",
"2022-03-11 997048\n",
"2022-03-10 1754702\n",
"2022-03-08 878964\n",
"Name: VOLUME, Length: 61, dtype: int64"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"volume = stock[\"VOLUME\"]\n",
"volume"
2022-05-25 03:16:39 +09:00
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2022-06-03 True\n",
"2022-06-02 False\n",
"2022-05-31 True\n",
"2022-05-30 True\n",
"2022-05-27 False\n",
" ... \n",
"2022-03-15 False\n",
"2022-03-14 False\n",
"2022-03-11 True\n",
"2022-03-10 True\n",
"2022-03-08 False\n",
"Name: CLOSE, Length: 61, dtype: bool"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"biggerThanYesterday = stock[\"CLOSE\"].shift(-1) < stock[\"CLOSE\"]\n",
"biggerThanYesterday"
]
},
{
"cell_type": "code",
"execution_count": 63,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
2022-06-06 10:55:12 +09:00
"ObvWeight = biggerThanYesterday.map(lambda x: 1 if x else -1)\n",
"ObvWeight"
2022-05-25 03:16:39 +09:00
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 66,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
2022-06-06 10:55:12 +09:00
"2022-06-03 175508\n",
"2022-06-02 -350113\n",
"2022-05-31 276819\n",
"2022-05-30 191087\n",
"2022-05-27 -392051\n",
" ... \n",
"2022-03-15 -2701677\n",
"2022-03-14 -4436719\n",
"2022-03-11 997048\n",
"2022-03-10 1754702\n",
"2022-03-08 -878964\n",
"Length: 61, dtype: int64"
2022-05-25 03:16:39 +09:00
]
},
2022-06-06 10:55:12 +09:00
"execution_count": 66,
2022-05-25 03:16:39 +09:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2022-06-06 10:55:12 +09:00
"factor = volume * ObvWeight\n",
"factor"
2022-05-25 03:16:39 +09:00
]
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 71,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2022-06-03 -1804451\n",
"2022-06-02 -1979959\n",
"2022-05-31 -1629846\n",
"2022-05-30 -1906665\n",
"2022-05-27 -2097752\n",
" ... \n",
"2022-03-15 -5265610\n",
"2022-03-14 -2563933\n",
"2022-03-11 1872786\n",
"2022-03-10 875738\n",
"2022-03-08 -878964\n",
"Length: 61, dtype: int64"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"obv = factor.iloc[::-1].cumsum().iloc[::-1]\n",
"obv"
]
},
{
"cell_type": "code",
"execution_count": null,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 73,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2022-06-06 10:55:12 +09:00
"([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],\n",
" [Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, '')])"
2022-05-25 03:16:39 +09:00
]
},
2022-06-06 10:55:12 +09:00
"execution_count": 73,
2022-05-25 03:16:39 +09:00
"metadata": {},
"output_type": "execute_result"
2022-06-06 10:55:12 +09:00
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEpCAYAAAB8/T7dAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb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KVUjtCh44LyujakdE8lb07V7qlIqNGlR8EDduGjO7ZLJ1/M3s23fYafTUUopn/OqKIjICBFZLCIlIpJXwXwDRWSZiKwUkTu9adNpl/fK5mhxCR/8rN1TlVKhx9sthUXA2cDU8mYQkUjgFWAQkAtcKCK5XrbrmGZpdejbOp0PflnHkaJip9NRSimf8qooGGPyjTHLKpmtG7DSGLPaGHMU+AgY5k27Truydzbb9x/l6/mbnU5FKaV8yh/HFBoB613ub7Afc0tERorIbBGZXVAQmENW92meSov0Orw1fQ3G6LUWlFKho9KiICKTRWSRm6lGfu0bY0YZY/KMMXlpaWk10YTXRIQremezeNNeZq3d5XQ6SinlM1GVzWCM6e9lGxuBxi73M+3HgtrZJ2Tyr2+X8fb0NXRrmux0Okop5RP+2H00C2ghIk1FJAa4ABjrh3ZrVK2YSC7slsWExVvYsOug0+kopZRPeNsldbiIbAB6AuNEZIL9eEMRGQ9gjCkCrgcmAPnAJ8aYxd6lHRgu69kEEeG9meucTkUppXzC295HY4wxmcaYWGNMhjHmdPvxTcaYM1zmG2+MaWmMyTHGPOpt0oGiYVItBratz4e//s7Bo0VOp6OUUl7TM5q9dFWfbPYeLuKzuUF/mEQppbQoeKtzVj06ZCbyzvQ1lJRo91SlVHDTouAlEeHK3tmsKjjATyu3O52OUkp5RYuCDwxu35C
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
2022-05-25 03:16:39 +09:00
}
],
2022-06-06 10:55:12 +09:00
"source": [
"plt.plot(obv.iloc[:20].iloc[::-1])\n",
"plt.xticks(rotation = 45)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"d5 = stock[\"CLOSE\"].loc[::-1].rolling(window=5\n",
" ).mean().dropna().loc[::-1]\n",
"d20 = stock[\"CLOSE\"].loc[::-1].rolling(window=20\n",
" ).mean().dropna().loc[::-1]\n",
"d60 = stock[\"CLOSE\"].loc[::-1].rolling(window=60\n",
" ).mean().dropna().loc[::-1]"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"ewm5 = stock[\"CLOSE\"].loc[::-1].ewm(span=5).mean().loc[::-1]\n",
"ewm10 = stock[\"CLOSE\"].loc[::-1].ewm(span=10).mean().loc[::-1]\n",
"macd = (ewm5 - ewm10)\n",
"signal = macd.loc[::-1].ewm(span=4).mean().loc[::-1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
2022-05-25 03:16:39 +09:00
"source": []
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 51,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2022-06-06 10:55:12 +09:00
"([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n",
" [Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, ''),\n",
" Text(0, 0, '')])"
2022-05-25 03:16:39 +09:00
]
},
2022-06-06 10:55:12 +09:00
"execution_count": 51,
2022-05-25 03:16:39 +09:00
"metadata": {},
"output_type": "execute_result"
2022-06-06 10:55:12 +09:00
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEeCAYAAACQfIJ4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAA9eElEQVR4nO3dd3gU1f7H8fdJIYFAgIRAgIAJJYTeQhFEREBA+gVEERti96rXjoqKvSD2huX6Q0EvIE0BCxaKBaT3EiFA6AmQ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t27X/BzXYcJLxgPa/LkyRw6dIgVK1YQGBhIdHQ0mZmZpZ5biHPJyMrlxfmb+OLPXTSoXpGJ17elRVQVu2N5RKf61Zh7zyV8/udOvlu/n8Y1Q0/2BRR8rRpSzu6YHlN2CoQN9u7dS1hYGCNHjqRKlSqndVC3a9eO++67jyNHjlCpUiW+/vrrkxMLnU1qairVq1cnMDCQX375hZ07d7r7VxDiNH8lHubBaWvYdfg4oy+J4cFejUo08qo3CvD346bOMdzUOcbuKLaTAlEC69at46GHHsLPz4/AwEDef/99HnzwQQBq167NY489Rvv27QkLCyMuLo7Klc89/v21115L//79ad68OfHx8cTFxXni1xCC7Nx8XvtxCxMXbSeqanm+uqUjHeqF2x1L2EyG+3aj9PR0KlasSG5uLoMHD2bUqFEMHjy4VLfh9H0gnG/P0RPcNXklq3cf5Zr2dXi8bxMqumnkVXEBtIbUJDi4EQ5sgOx06P5ksX5USYf7dturQCn1NHALcMha9Jj
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
2022-05-25 03:16:39 +09:00
}
],
2022-06-06 10:55:12 +09:00
"source": [
"plt.plot(macd.iloc[0:10].iloc[::-1],label=\"macd\")\n",
"plt.legend()\n",
"plt.plot(signal.iloc[0:10].iloc[::-1],label=\"signal\")\n",
"plt.legend()\n",
"plt.xticks(rotation=45)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"from gen import *"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"dataStore = DataStore()\n",
"krx_corps = dataStore.getAllKRXCorp()"
]
2022-05-25 03:16:39 +09:00
},
{
"cell_type": "code",
2022-06-06 10:55:12 +09:00
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"collector = OutputCollector()\n",
"prepareCollector(collector)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 2564/2564 [01:10<00:00, 36.62it/s] \n"
]
}
],
"source": [
"for corp in tqdm.tqdm(krx_corps):\n",
" for nday in range(0, 5):\n",
" collect(dataStore, collector, corp, nday)\n",
" dataStore.clearCache()"
]
},
{
"cell_type": "code",
"execution_count": 26,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2022-06-06 10:55:12 +09:00
"['2022-05-27',\n",
" '2022-06-02',\n",
" '2022-05-31',\n",
" '2022-05-30',\n",
" '2021-04-14',\n",
" '2022-05-04',\n",
" '2022-01-28',\n",
" '2022-05-16',\n",
" '2021-07-05',\n",
" '2022-02-10']"
2022-05-25 03:16:39 +09:00
]
},
2022-06-06 10:55:12 +09:00
"execution_count": 26,
2022-05-25 03:16:39 +09:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
}
],
"metadata": {
"interpreter": {
2022-06-06 10:55:12 +09:00
"hash": "315ddbd22344660769d1dae43a6a5e914850a7ce75ac77a9d658327898fcf0d6"
2022-05-25 03:16:39 +09:00
},
"kernelspec": {
2022-06-06 10:55:12 +09:00
"display_name": "Python 3.9.2 ('stock': venv)",
2022-05-25 03:16:39 +09:00
"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",
2022-06-06 10:55:12 +09:00
"version": "3.9.2"
2022-05-25 03:16:39 +09:00
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}