add 뭉침

This commit is contained in:
monoid 2022-06-19 17:58:08 +09:00
parent 790052c2a2
commit a20aba2f0c
3 changed files with 184 additions and 113 deletions

28
gen.py
View File

@ -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,21 +90,39 @@ 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)):

View File

@ -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 만난것""" }
]

View File

@ -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 @@
" </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",
" <th>2022-06-10</th>\n",
" <td>042670</td>\n",
" <td>6490</td>\n",
" <td>210</td>\n",
" <td>6670</td>\n",
" <td>6680</td>\n",
" <td>6470</td>\n",
" <td>1817916</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",
" <th>2022-06-09</th>\n",
" <td>042670</td>\n",
" <td>6700</td>\n",
" <td>110</td>\n",
" <td>6620</td>\n",
" <td>6750</td>\n",
" <td>6440</td>\n",
" <td>2623890</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",
" <th>2022-06-08</th>\n",
" <td>042670</td>\n",
" <td>6590</td>\n",
" <td>160</td>\n",
" <td>6820</td>\n",
" <td>6860</td>\n",
" <td>6580</td>\n",
" <td>2026670</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",
" <th>2022-06-07</th>\n",
" <td>042670</td>\n",
" <td>6750</td>\n",
" <td>150</td>\n",
" <td>14050</td>\n",
" <td>14100</td>\n",
" <td>13600</td>\n",
" <td>392051</td>\n",
" <td>6870</td>\n",
" <td>6990</td>\n",
" <td>6720</td>\n",
" <td>3234237</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-06-03</th>\n",
" <td>042670</td>\n",
" <td>6900</td>\n",
" <td>440</td>\n",
" <td>6550</td>\n",
" <td>6940</td>\n",
" <td>6510</td>\n",
" <td>9983571</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
@ -213,54 +233,54 @@
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-15</th>\n",
" <td>294870</td>\n",
" <td>16200</td>\n",
" <th>2022-03-21</th>\n",
" <td>042670</td>\n",
" <td>6770</td>\n",
" <td>120</td>\n",
" <td>6910</td>\n",
" <td>7030</td>\n",
" <td>6770</td>\n",
" <td>1314044</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2022-03-18</th>\n",
" <td>042670</td>\n",
" <td>6890</td>\n",
" <td>200</td>\n",
" <td>14800</td>\n",
" <td>16450</td>\n",
" <td>14750</td>\n",
" <td>2701677</td>\n",
" <td>6750</td>\n",
" <td>6890</td>\n",
" <td>6650</td>\n",
" <td>1207925</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",
" <th>2022-03-17</th>\n",
" <td>042670</td>\n",
" <td>6690</td>\n",
" <td>50</td>\n",
" <td>6790</td>\n",
" <td>6790</td>\n",
" <td>6670</td>\n",
" <td>1003575</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",
" <th>2022-03-16</th>\n",
" <td>042670</td>\n",
" <td>6640</td>\n",
" <td>60</td>\n",
" <td>6610</td>\n",
" <td>6680</td>\n",
" <td>6570</td>\n",
" <td>642939</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",
" <th>2022-03-15</th>\n",
" <td>042670</td>\n",
" <td>6580</td>\n",
" <td>260</td>\n",
" <td>6830</td>\n",
" <td>6840</td>\n",
" <td>6550</td>\n",
" <td>1776057</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
@ -268,24 +288,24 @@
"</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",
" 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,