Stock/test.ipynb

979 lines
63 KiB
Plaintext
Raw Permalink 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",
2023-07-24 09:10:32 +09:00
"execution_count": 2,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"db = sqlite3.connect(\"stock.db\")\n"
]
},
2022-06-19 17:58:08 +09:00
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 3,
2022-06-19 17:58:08 +09:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
2023-07-24 09:10:32 +09:00
"execution_count": 3,
2022-06-19 17:58:08 +09:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"db.in_transaction"
]
},
2022-05-25 03:16:39 +09:00
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 4,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"krx = database.GetAllKRXCorp(db)"
]
},
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 5,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"krxDf = pd.DataFrame([corp.toDict() for corp in krx])"
]
},
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 6,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
2023-07-24 09:10:32 +09:00
"data = GetStockPriceFrom(db,\"212310\", 61)\n"
2022-05-25 03:16:39 +09:00
]
},
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 7,
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",
2023-07-24 09:10:32 +09:00
"execution_count": 8,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"s.set_index(\"DATE\", inplace=True)"
]
},
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 9,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
"source": [
"stock = s"
]
},
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 10,
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",
2023-07-24 09:10:32 +09:00
" <th>2023-06-02</th>\n",
" <td>212310</td>\n",
" <td>2375</td>\n",
" <td>75</td>\n",
" <td>2205</td>\n",
" <td>2615</td>\n",
" <td>2205</td>\n",
" <td>19</td>\n",
2022-06-06 10:55:12 +09:00
" </tr>\n",
" <tr>\n",
2023-07-24 09:10:32 +09:00
" <th>2023-06-01</th>\n",
" <td>212310</td>\n",
" <td>2300</td>\n",
" <td>35</td>\n",
" <td>2335</td>\n",
" <td>2645</td>\n",
" <td>2215</td>\n",
" <td>16</td>\n",
2022-06-06 10:55:12 +09:00
" </tr>\n",
" <tr>\n",
2023-07-24 09:10:32 +09:00
" <th>2023-05-31</th>\n",
" <td>212310</td>\n",
" <td>2335</td>\n",
" <td>0</td>\n",
" <td>2340</td>\n",
" <td>2340</td>\n",
" <td>2335</td>\n",
" <td>145</td>\n",
2022-06-06 10:55:12 +09:00
" </tr>\n",
" <tr>\n",
2023-07-24 09:10:32 +09:00
" <th>2023-05-30</th>\n",
" <td>212310</td>\n",
" <td>2335</td>\n",
" <td>190</td>\n",
" <td>2275</td>\n",
" <td>2790</td>\n",
" <td>2275</td>\n",
" <td>6245</td>\n",
2022-06-06 10:55:12 +09:00
" </tr>\n",
" <tr>\n",
2023-07-24 09:10:32 +09:00
" <th>2023-05-26</th>\n",
" <td>212310</td>\n",
" <td>2525</td>\n",
" <td>30</td>\n",
" <td>2450</td>\n",
" <td>2780</td>\n",
" <td>2420</td>\n",
" <td>658</td>\n",
2022-06-06 10:55:12 +09:00
" </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",
2023-07-24 09:10:32 +09:00
" <th>2023-03-13</th>\n",
" <td>212310</td>\n",
" <td>3190</td>\n",
" <td>100</td>\n",
" <td>3695</td>\n",
" <td>3695</td>\n",
" <td>2805</td>\n",
" <td>2967</td>\n",
2022-06-06 10:55:12 +09:00
" </tr>\n",
" <tr>\n",
2023-07-24 09:10:32 +09:00
" <th>2023-03-10</th>\n",
" <td>212310</td>\n",
" <td>3290</td>\n",
" <td>15</td>\n",
" <td>3675</td>\n",
" <td>3675</td>\n",
" <td>3110</td>\n",
" <td>9</td>\n",
2022-06-06 10:55:12 +09:00
" </tr>\n",
" <tr>\n",
2023-07-24 09:10:32 +09:00
" <th>2023-03-09</th>\n",
" <td>212310</td>\n",
" <td>3275</td>\n",
" <td>205</td>\n",
" <td>3800</td>\n",
" <td>3800</td>\n",
" <td>3220</td>\n",
" <td>467</td>\n",
2022-06-06 10:55:12 +09:00
" </tr>\n",
" <tr>\n",
2023-07-24 09:10:32 +09:00
" <th>2023-03-08</th>\n",
" <td>212310</td>\n",
" <td>3480</td>\n",
" <td>15</td>\n",
" <td>3460</td>\n",
" <td>3480</td>\n",
" <td>3460</td>\n",
" <td>289</td>\n",
2022-06-06 10:55:12 +09:00
" </tr>\n",
" <tr>\n",
2023-07-24 09:10:32 +09:00
" <th>2023-03-07</th>\n",
" <td>212310</td>\n",
" <td>3495</td>\n",
" <td>235</td>\n",
" <td>3495</td>\n",
" <td>3500</td>\n",
" <td>3315</td>\n",
" <td>125</td>\n",
2022-06-06 10:55:12 +09:00
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>61 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
2023-07-24 09:10:32 +09:00
" CODE CLOSE DIFF OPEN HIGH LOW VOLUME\n",
"DATE \n",
"2023-06-02 212310 2375 75 2205 2615 2205 19\n",
"2023-06-01 212310 2300 35 2335 2645 2215 16\n",
"2023-05-31 212310 2335 0 2340 2340 2335 145\n",
"2023-05-30 212310 2335 190 2275 2790 2275 6245\n",
"2023-05-26 212310 2525 30 2450 2780 2420 658\n",
"... ... ... ... ... ... ... ...\n",
"2023-03-13 212310 3190 100 3695 3695 2805 2967\n",
"2023-03-10 212310 3290 15 3675 3675 3110 9\n",
"2023-03-09 212310 3275 205 3800 3800 3220 467\n",
"2023-03-08 212310 3480 15 3460 3480 3460 289\n",
"2023-03-07 212310 3495 235 3495 3500 3315 125\n",
2022-06-06 10:55:12 +09:00
"\n",
"[61 rows x 7 columns]"
]
},
2023-07-24 09:10:32 +09:00
"execution_count": 10,
2022-06-06 10:55:12 +09:00
"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",
2023-07-24 09:10:32 +09:00
"execution_count": 11,
2022-06-06 10:55:12 +09:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
2023-07-24 09:10:32 +09:00
"2023-06-02 2374.0\n",
"2023-06-01 2398.0\n",
"2023-05-31 2404.0\n",
"2023-05-30 2434.0\n",
"2023-05-26 2447.0\n",
"2023-05-25 2447.0\n",
"Name: CLOSE, dtype: float64"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"close = stock[\"CLOSE\"]\n",
"d5 = stock[\"CLOSE\"].iloc[:10].loc[::-1].rolling(window=5\n",
" ).mean().dropna().loc[::-1]\n",
"d5"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2023-06-02 88.487287\n",
"2023-06-01 103.778611\n",
"2023-05-31 97.365292\n",
"2023-05-30 93.834962\n",
"2023-05-26 80.202868\n",
"2023-05-25 80.202868\n",
"Name: CLOSE, dtype: float64"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dstd5 = close.iloc[:10].loc[::-1].rolling(window=5).std().dropna().loc[::-1]\n",
"dstd5"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2023-06-01 2398.0\n",
"2023-05-31 2404.0\n",
"Name: CLOSE, dtype: float64"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d5[[1,2]]"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(50.04, 0.2, 50.44, True)"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = 51\n",
"arr = np.array([50]* 24 + [a])\n",
"m = arr.mean()\n",
"std = arr.std(ddof=1)\n",
"m, std , m + 2*std, m+2*std < a"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10.0"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(a-50)/5"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"59.082092668956086"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"krx.__len__() * ((100-95.4499736104)/100)*0.5"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DATE\n",
"2023-05-22 27\n",
"2023-05-19 403\n",
"2023-05-18 1\n",
"2023-05-17 5\n",
"2023-05-16 3711\n",
" ... \n",
"2023-02-28 1017\n",
"2023-02-27 799\n",
"2023-02-24 12\n",
"2023-02-23 688\n",
"2023-02-22 4\n",
2022-06-06 10:55:12 +09:00
"Name: VOLUME, Length: 61, dtype: int64"
]
},
2023-07-24 09:10:32 +09:00
"execution_count": 12,
2022-06-06 10:55:12 +09:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"volume = stock[\"VOLUME\"]\n",
"volume"
2022-05-25 03:16:39 +09:00
]
},
2023-07-24 09:10:32 +09:00
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'2023-05-22'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock.index[0]"
]
},
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"
]
},
2022-06-19 17:58:08 +09:00
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 29,
2022-06-19 17:58:08 +09:00
"metadata": {},
"outputs": [],
"source": [
"close = stock[\"CLOSE\"]\n",
"d5 = stock[\"CLOSE\"].loc[::-1].rolling(window=5\n",
" ).mean().dropna().loc[::-1]\n",
"d10 = stock[\"CLOSE\"].loc[::-1].rolling(window=10\n",
" ).mean().dropna().loc[::-1]\n",
"d20 = stock[\"CLOSE\"].loc[::-1].rolling(window=20\n",
" ).mean().dropna().loc[::-1]\n",
"d30 = stock[\"CLOSE\"].loc[::-1].rolling(window=30\n",
" ).mean().dropna().loc[::-1]\n",
"d60 = stock[\"CLOSE\"].loc[::-1].rolling(window=60\n",
" ).mean().dropna().loc[::-1]"
]
},
2022-06-06 10:55:12 +09:00
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 30,
2022-05-25 03:16:39 +09:00
"metadata": {},
"outputs": [],
2023-07-24 09:10:32 +09:00
"source": [
"def isRelativeDiffLessThan(a:pd.Series,b:pd.Series, threshold: float,nday:int) -> bool:\n",
" return (a.iloc[nday] - b.iloc[nday]) / b.iloc[nday] < threshold"
]
2022-05-25 03:16:39 +09:00
},
2022-06-19 17:58:08 +09:00
{
"cell_type": "code",
2023-07-24 09:10:32 +09:00
"execution_count": 15,
2022-06-19 17:58:08 +09:00
"metadata": {},
"outputs": [],
2023-07-24 09:10:32 +09:00
"source": [
"def every(f, xs):\n",
" for x in xs:\n",
" if not f(x):\n",
" return False\n",
" return True"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"evert\n",
"6236.0 6290 -54.0\n"
]
},
{
"data": {
"text/plain": [
"-0.008585055643879173"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
2022-06-19 17:58:08 +09:00
"source": [
"a = [d5, d10, d20, d30, d60]\n",
2023-07-24 09:10:32 +09:00
"if every(lambda i: isRelativeDiffLessThan(i,close,0.05,0), a):\n",
" print(\"evert\")\n",
"print(d5.iloc[0] , close.iloc[0],d5.iloc[0] - close.iloc[0])\n",
"(d5.iloc[0] - close.iloc[0]) / close.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-0.1876921038685744"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(d60.iloc[0] - close.iloc[0])/close.iloc[0]"
2022-06-19 17:58:08 +09:00
]
},
2022-05-25 03:16:39 +09:00
{
"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/T7dAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAA9uElEQVR4nO3dd3gVZfbA8e9JJxASUikhBEINVQgdG0VBEETF3nXZ31rWtbe197V3Zde26tpQFAWlWECKSpEeepFO6B1S3t8fM8FruCk39+bOLefzPPPkljnzntwy587MO++IMQallFIKIMLpBJRSSgUOLQpKKaWO0aKglFLqGC0KSimljtGioJRS6hgtCkoppY4J+KIgIm+JyDYRWVTF+c8TkSUislhE/lfT+SmlVCiRQD9PQUROAvYD/zXGtKtk3hbAJ0BfY8wuEUk3xmzzR55KKRUKAn5LwRgzFdjp+piI5IjItyIyR0R+EpHW9lN/AV4xxuyyY7UgKKWUBwK+KJRjFHCDMaYLcCvwqv14S6CliEwXkZ9FZKBjGSqlVBCKcjoBT4lIHaAX8KmIlD4ca/+NAloApwCZwFQRaW+M2e3nNJVSKigFXVHA2rrZbYzp5Oa5DcAvxphCYI2ILMcqErP8mJ9SSgWtoNt9ZIzZi7XCHwEglo72019gbSUgIqlYu5NWO5CmUkoFpYAvCiLyITATaCUiG0TkauBi4GoRmQ8sBobZs08AdojIEuAH4DZjzA4n8lZKqWAU8F1SlVJK+U/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o91SlVHDTouAlEeHK3tmsKjjATyu3O52OUkp5RYuCDwxu35C
"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+gVEERti96rXjoqKvSD2huX6Q0EvIE0BCxaKBaT3EiFA6AmQkED6+f1xJrBgKCm7M5v9vp5nn2xmdjOfTDb73Tln5hyltUYIIYQ4k5/dAYQQQjiTFAghhBCFkgIhhBCiUFIghBBCFEoKhBBCiEIF2B3gQlWrVk1HR0fbHUMIIbzGihUrkrXWEcV9vtcUiOjoaJYvX253DCGE8BpKqZ0leb40MQkhhCiUFAghhBCFkgIhhBCiUF7TB1GYnJwckpKSyMzMtDuKLYKDg4mKiiIwMNDuKEKIMsirC0RSUhKVKlUiOjoapZTdcTxKa01KSgpJSUnExMTYHUcIUQZ5dRNTZmYm4eHhPlccAJRShIeH++zRkxDC/by6QAA+WRwK+PLvLoRwP68vEEKIsmPP0ROM/34LCQfT7Y4ikALhaL/++iv9+vWzO4YQbqe1Ztry3fR+fRHv/JJA7zcW8fzcjRzLzLE7mk+TAiGEsNXBY5ncMmkFD01fS+Oaocy6qzND20bx8ZIddBu/kOkrksjPl4nN7CAFogQSExOJi4vjxhtvJDY2lmuvvZYFCxbQuXNnGjZsyLJly1i2bBkXX3wxrVu3plOnTmzZsgWAvLw8HnzwQZo1a0aLFi14++23Afjuu++Ii4ujTZs2zJgxw85fTwi3m7duH71eX8SibYd4om9jvrq1I63qVOGlIS2YdWdn6oSV58Fpaxjywe+sTT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07NiRAQMGOPKFI3xD6okcxs3ZwIxVe2hWO5Qvr2pF7BnDcnuz4EB/7unekCFto3hh3iZeX7CVaSt280TfJvRqaq7GzsrNY/fh4yQmHz/taCAxJYM9R07gOpdRxaAAoqtVoGntyvRrUcscBVhHAxEVnVkEzqXsFAgbNG/enAceeIBHHnmEfv360aVLl5Prli1bRteuXQkLCwNg2LBhbN269eT6QYMG4efnR5MmTThw4ABg2ncfe+wxFi1ahJ+fH3v27OHAgQNERtp7yqDwTYu2HuLh6Ws5lJ7FPd0b8u/LGziuQ7e01K5SnndHtOHaDsmMm7OR279YQVxkJY5l5rI39QSuIxKFBgcQUy2E1nWqMrhVbS4KDyG6WgjR4RUICynndUXgXMpOgTjHJ313iY2NZeXKlcybN48nnniC7t27X/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
}