{ "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", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "import importlib" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "importlib.reload(database)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "db = sqlite3.connect(\"stock.db\")\n" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "krx = database.GetAllKRXCorp(db)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "krxDf = pd.DataFrame([corp.toDict() for corp in krx])" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "data = GetStockPriceFrom(db,\"155660\", 61)\n" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "s = pd.DataFrame(data, columns=[s for s in database.STOCK_INDEX.__members__.keys()])" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [], "source": [ "s.set_index(\"DATE\", inplace=True)" ] }, { "cell_type": "code", "execution_count": 91, "metadata": {}, "outputs": [], "source": [ "stock = s" ] }, { "cell_type": "code", "execution_count": 92, "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": 100, "metadata": {}, "outputs": [], "source": [ "ewm12 = stock[\"CLOSE\"].loc[::-1].ewm(span=12).mean().loc[::-1]\n", "ewm26 = stock[\"CLOSE\"].loc[::-1].ewm(span=26).mean().loc[::-1]\n", "macd = (ewm12 - ewm26)\n", "signal = macd.ewm(span=9).mean()" ] }, { "cell_type": "code", "execution_count": 101, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "DATE\n", "2022-05-20 148.895069\n", "2022-05-19 152.584580\n", "2022-05-18 122.762721\n", "2022-05-17 97.031260\n", "2022-05-16 50.671176\n", " ... \n", "2022-02-28 7.956286\n", "2022-02-25 1.291958\n", "2022-02-24 -0.770309\n", "2022-02-23 4.262821\n", "2022-02-22 0.000000\n", "Name: CLOSE, Length: 61, dtype: float64" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "macd" ] }, { "cell_type": "code", "execution_count": 105, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 115, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['2022-05-16', '2022-05-15']" ] }, "execution_count": 115, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": 142, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
abc
0123
1456
\n", "
" ], "text/plain": [ " a b c\n", "0 1 2 3\n", "1 4 5 6" ] }, "execution_count": 142, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": 132, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
abc
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [a, b, c]\n", "Index: []" ] }, "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [] } ], "metadata": { "interpreter": { "hash": "4958a03c5ef93b3c628112f436609f44fba8a7f6eb1fb9f266a15f7204ae796a" }, "kernelspec": { "display_name": "Python 3.10.2 ('stock': venv)", "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.10.2" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }