diff --git a/gen.py b/gen.py
index d01e2fd..e4646c6 100644
--- a/gen.py
+++ b/gen.py
@@ -79,7 +79,7 @@ def isMACDCrossSignal(signal: pd.Series, macd: pd.Series, nday: int, order=1) ->
signal.iloc[nday+order] < macd.iloc[nday+order])
def isRelativeDiffLessThan(a:pd.Series,b:pd.Series, threshold: float,nday:int) -> bool:
- return (a.iloc[nday] - b.iloc[nday]) / b.iloc[nday] < threshold
+ return abs(a.iloc[nday] - b.iloc[nday]) / b.iloc[nday] < threshold
def isDiffGreaterThan(a:pd.Series,b:pd.Series, nday:int) -> bool:
"""a is bigger than b"""
@@ -90,22 +90,40 @@ def prepareCollector(collector: OutputCollector) -> None:
for item in pages.GenLists:
collector.addResult(item["name"], item["description"])
+def every(f, xs):
+ for x in xs:
+ if not f(x):
+ return False
+ return True
+
def collect(data: DataStore, collector: OutputCollector, corp: database.KRXCorp
, nday: int) -> None:
- stock = data.getStockPrice(corp.Code,70)
- if len(stock) < 70:
+ stock = data.getStockPrice(corp.Code,120)
+ if len(stock) < 120:
+ return
+ if (stock.iloc[nday]['VOLUME'] <= 0):
return
+ close = stock["CLOSE"]
d5 = stock["CLOSE"].loc[::-1].rolling(window=5
).mean().dropna().loc[::-1]
+ d10 = stock["CLOSE"].loc[::-1].rolling(window=10
+ ).mean().dropna().loc[::-1]
d20 = stock["CLOSE"].loc[::-1].rolling(window=20
).mean().dropna().loc[::-1]
+ d30 = stock["CLOSE"].loc[::-1].rolling(window=30
+ ).mean().dropna().loc[::-1]
d60 = stock["CLOSE"].loc[::-1].rolling(window=60
).mean().dropna().loc[::-1]
- if (d60.iloc[nday+2] > d60.iloc[nday+1] and d60.iloc[nday+1] < d60.iloc[nday]):
- collector.collect("60일선반등",corp, stock.index[nday])
-
+ a = [d5, d10, d20, d30, d60]
+ if every(lambda i: isRelativeDiffLessThan(i,close,0.05,nday), a):
+ collector.collect("뭉침", corp, stock.index[nday])
+ if every(lambda i: isRelativeDiffLessThan(i,close,0.01,nday), a):
+ collector.collect("뭉침01", corp, stock.index[nday])
+ if every(lambda i: isRelativeDiffLessThan(i,close,0.03,nday), a):
+ collector.collect("뭉침03", corp, stock.index[nday])
+
if (isRelativeDiffLessThan(d5, d20, 0.01, nday) and
isRelativeDiffLessThan(d5, d60, 0.01, nday)):
collector.collect("cross 2", corp, stock.index[nday])
diff --git a/pages.py b/pages.py
index 09aa02f..498a094 100644
--- a/pages.py
+++ b/pages.py
@@ -1,7 +1,8 @@
name = "name"
desc = "description"
-GenLists = [{name:"cross 2", desc:"""\
+GenLists = [
+ {name:"cross 2", desc:"""\
5일선과 20일선이 서로 만나는 시점 즉 상대 오차가 1% 이하이고
5일선과 60일선이 서로 만나는 시점을 찾습니다.
"""},
@@ -38,8 +39,10 @@ signal과 macd가 서로 교차한 시점을 찾습니다. 즉 signal이 올라
macd가 아래로 내려가는 시점을 찾습니다. macd 는 5일선과 10일선으로 이루어지고
시그널을 구하기 위한 이동 평균은 4일입니다.
"""},
- {
- name:"60일선반등",desc: """\
-60일선이 반등하는 시점을 찾습니다."""
- }
+ {name:"뭉침", desc: """\
+5 10 20 30 60 만난것""" },
+ {name:"뭉침01", desc: """\
+5 10 20 30 60 만난것""" },
+ {name:"뭉침03", desc: """\
+5 10 20 30 60 만난것""" }
]
\ No newline at end of file
diff --git a/test.ipynb b/test.ipynb
index 770b689..d91d4a3 100644
--- a/test.ipynb
+++ b/test.ipynb
@@ -52,6 +52,26 @@
"db = sqlite3.connect(\"stock.db\")\n"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "False"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "db.in_transaction"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 5,
@@ -72,16 +92,16 @@
},
{
"cell_type": "code",
- "execution_count": 27,
+ "execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
- "data = GetStockPriceFrom(db,\"294870\", 61)\n"
+ "data = GetStockPriceFrom(db,\"042670\", 61)\n"
]
},
{
"cell_type": "code",
- "execution_count": 28,
+ "execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
@@ -90,7 +110,7 @@
},
{
"cell_type": "code",
- "execution_count": 29,
+ "execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@@ -99,7 +119,7 @@
},
{
"cell_type": "code",
- "execution_count": 30,
+ "execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
@@ -108,7 +128,7 @@
},
{
"cell_type": "code",
- "execution_count": 31,
+ "execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -153,54 +173,54 @@
" \n",
"
\n",
" \n",
- " 2022-06-03 | \n",
- " 294870 | \n",
- " 13700 | \n",
- " 100 | \n",
- " 13700 | \n",
- " 13800 | \n",
- " 13600 | \n",
- " 175508 | \n",
+ " 2022-06-10 | \n",
+ " 042670 | \n",
+ " 6490 | \n",
+ " 210 | \n",
+ " 6670 | \n",
+ " 6680 | \n",
+ " 6470 | \n",
+ " 1817916 | \n",
"
\n",
" \n",
- " 2022-06-02 | \n",
- " 294870 | \n",
- " 13600 | \n",
- " 250 | \n",
- " 13850 | \n",
- " 13850 | \n",
- " 13550 | \n",
- " 350113 | \n",
+ " 2022-06-09 | \n",
+ " 042670 | \n",
+ " 6700 | \n",
+ " 110 | \n",
+ " 6620 | \n",
+ " 6750 | \n",
+ " 6440 | \n",
+ " 2623890 | \n",
"
\n",
" \n",
- " 2022-05-31 | \n",
- " 294870 | \n",
- " 13850 | \n",
- " 50 | \n",
- " 13850 | \n",
- " 13950 | \n",
- " 13800 | \n",
- " 276819 | \n",
+ " 2022-06-08 | \n",
+ " 042670 | \n",
+ " 6590 | \n",
+ " 160 | \n",
+ " 6820 | \n",
+ " 6860 | \n",
+ " 6580 | \n",
+ " 2026670 | \n",
"
\n",
" \n",
- " 2022-05-30 | \n",
- " 294870 | \n",
- " 13800 | \n",
- " 100 | \n",
- " 13850 | \n",
- " 13950 | \n",
- " 13750 | \n",
- " 191087 | \n",
- "
\n",
- " \n",
- " 2022-05-27 | \n",
- " 294870 | \n",
- " 13700 | \n",
+ " 2022-06-07 | \n",
+ " 042670 | \n",
+ " 6750 | \n",
" 150 | \n",
- " 14050 | \n",
- " 14100 | \n",
- " 13600 | \n",
- " 392051 | \n",
+ " 6870 | \n",
+ " 6990 | \n",
+ " 6720 | \n",
+ " 3234237 | \n",
+ "
\n",
+ " \n",
+ " 2022-06-03 | \n",
+ " 042670 | \n",
+ " 6900 | \n",
+ " 440 | \n",
+ " 6550 | \n",
+ " 6940 | \n",
+ " 6510 | \n",
+ " 9983571 | \n",
"
\n",
" \n",
" ... | \n",
@@ -213,54 +233,54 @@
" ... | \n",
"
\n",
" \n",
- " 2022-03-15 | \n",
- " 294870 | \n",
- " 16200 | \n",
+ " 2022-03-21 | \n",
+ " 042670 | \n",
+ " 6770 | \n",
+ " 120 | \n",
+ " 6910 | \n",
+ " 7030 | \n",
+ " 6770 | \n",
+ " 1314044 | \n",
+ "
\n",
+ " \n",
+ " 2022-03-18 | \n",
+ " 042670 | \n",
+ " 6890 | \n",
" 200 | \n",
- " 14800 | \n",
- " 16450 | \n",
- " 14750 | \n",
- " 2701677 | \n",
+ " 6750 | \n",
+ " 6890 | \n",
+ " 6650 | \n",
+ " 1207925 | \n",
"
\n",
" \n",
- " 2022-03-14 | \n",
- " 294870 | \n",
- " 16400 | \n",
- " 2050 | \n",
- " 18500 | \n",
- " 19250 | \n",
- " 16000 | \n",
- " 4436719 | \n",
+ " 2022-03-17 | \n",
+ " 042670 | \n",
+ " 6690 | \n",
+ " 50 | \n",
+ " 6790 | \n",
+ " 6790 | \n",
+ " 6670 | \n",
+ " 1003575 | \n",
"
\n",
" \n",
- " 2022-03-11 | \n",
- " 294870 | \n",
- " 18450 | \n",
- " 100 | \n",
- " 18450 | \n",
- " 18500 | \n",
- " 18000 | \n",
- " 997048 | \n",
+ " 2022-03-16 | \n",
+ " 042670 | \n",
+ " 6640 | \n",
+ " 60 | \n",
+ " 6610 | \n",
+ " 6680 | \n",
+ " 6570 | \n",
+ " 642939 | \n",
"
\n",
" \n",
- " 2022-03-10 | \n",
- " 294870 | \n",
- " 18350 | \n",
- " 1400 | \n",
- " 17450 | \n",
- " 18350 | \n",
- " 17400 | \n",
- " 1754702 | \n",
- "
\n",
- " \n",
- " 2022-03-08 | \n",
- " 294870 | \n",
- " 16950 | \n",
- " 450 | \n",
- " 17100 | \n",
- " 17500 | \n",
- " 16800 | \n",
- " 878964 | \n",
+ " 2022-03-15 | \n",
+ " 042670 | \n",
+ " 6580 | \n",
+ " 260 | \n",
+ " 6830 | \n",
+ " 6840 | \n",
+ " 6550 | \n",
+ " 1776057 | \n",
"
\n",
" \n",
"\n",
@@ -268,24 +288,24 @@
""
],
"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",
+ " CODE CLOSE DIFF OPEN HIGH LOW VOLUME\n",
+ "DATE \n",
+ "2022-06-10 042670 6490 210 6670 6680 6470 1817916\n",
+ "2022-06-09 042670 6700 110 6620 6750 6440 2623890\n",
+ "2022-06-08 042670 6590 160 6820 6860 6580 2026670\n",
+ "2022-06-07 042670 6750 150 6870 6990 6720 3234237\n",
+ "2022-06-03 042670 6900 440 6550 6940 6510 9983571\n",
+ "... ... ... ... ... ... ... ...\n",
+ "2022-03-21 042670 6770 120 6910 7030 6770 1314044\n",
+ "2022-03-18 042670 6890 200 6750 6890 6650 1207925\n",
+ "2022-03-17 042670 6690 50 6790 6790 6670 1003575\n",
+ "2022-03-16 042670 6640 60 6610 6680 6570 642939\n",
+ "2022-03-15 042670 6580 260 6830 6840 6550 1776057\n",
"\n",
"[61 rows x 7 columns]"
]
},
- "execution_count": 31,
+ "execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@@ -436,6 +456,25 @@
"obv"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "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]"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
@@ -443,6 +482,17 @@
"outputs": [],
"source": []
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "a = [d5, d10, d20, d30, d60]\n",
+ "if every(lambda i: isRelativeDiffLessThan(i,close,0.05,nday), a):\n",
+ " print(\"evert\")"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 73,