Compare commits

..

2 Commits

Author SHA1 Message Date
790052c2a2 fix macd signal 2022-06-12 18:13:54 +09:00
e86ada382c fix: ewm bug and new collector 2022-06-06 10:55:12 +09:00
5 changed files with 529 additions and 159 deletions

1
app.py
View File

@ -18,6 +18,7 @@ def index():
return flask.render_template("index.html", pages = pages.GenLists)
if __name__ == '__main__':
args = parser.parse_args()
app.run(host=args.host, port=args.port, debug=args.debug)

18
gen.py
View File

@ -75,8 +75,8 @@ def isVolumeMulPriceGreaterThan(stock: pd.DataFrame, threshold: int, nday: int)
return stock.iloc[nday]['VOLUME'] * stock.iloc[nday]['CLOSE'] > threshold
def isMACDCrossSignal(signal: pd.Series, macd: pd.Series, nday: int, order=1) -> bool:
return (signal.iloc[nday] < macd.iloc[nday] and
signal.iloc[nday+order] > macd.iloc[nday+order])
return (signal.iloc[nday] > macd.iloc[nday] and
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
@ -103,6 +103,9 @@ def collect(data: DataStore, collector: OutputCollector, corp: database.KRXCorp
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])
if (isRelativeDiffLessThan(d5, d20, 0.01, nday) and
isRelativeDiffLessThan(d5, d60, 0.01, nday)):
collector.collect("cross 2", corp, stock.index[nday])
@ -133,10 +136,10 @@ def collect(data: DataStore, collector: OutputCollector, corp: database.KRXCorp
if (isVolumeNTimes(stock, 5, nday)):
collector.collect("volumeX5", corp, stock.index[nday])
ewm12 = stock["CLOSE"].loc[::-1].ewm(span=12).mean().loc[::-1]
ewm26 = stock["CLOSE"].loc[::-1].ewm(span=26).mean().loc[::-1]
macd = (ewm12 - ewm26)
signal = macd.ewm(span=9).mean()
ewm5 = stock["CLOSE"].loc[::-1].ewm(span=5).mean().loc[::-1]
ewm10 = stock["CLOSE"].loc[::-1].ewm(span=10).mean().loc[::-1]
macd = (ewm5 - ewm10)
signal = macd.loc[::-1].ewm(span=4).mean().loc[::-1]
if (isMACDCrossSignal(macd, signal, nday)):
collector.collect("macd", corp, stock.index[nday])
@ -183,11 +186,10 @@ if __name__ == "__main__":
days = v.corpListByDate.keys()
days = list(days)
days.append(datetime.date.today().isoformat())
days.sort(reverse=True)
days = days[:5]
html = template.render(collected=v, title=k, days=days)
html = template.render(collected=v, title=k, days=days, lastUpdate=datetime.date.today().isoformat())
if args.printStdout:
print(html)
else:

View File

@ -34,7 +34,12 @@ d20d5의 조건에서 더해서 거래량이 이전 날짜보다 5배 증가한
거래량이 이전 날짜보다 5 증가한 시점을 찾습니다.
"""},
{name:"macd",desc: """\
signal과 macd가 서로 교차한 시점을 찾습니다. signal이 아래로 떨어지고
macd가 위로 올라가는 시점을 찾습니다.
signal과 macd가 서로 교차한 시점을 찾습니다. signal이 올라가고
macd가 아래로 내려가는 시점을 찾습니다. macd 5일선과 10일선으로 이루어지고
시그널을 구하기 위한 이동 평균은 4일입니다.
"""},
{
name:"60일선반등",desc: """\
60일선이 반등하는 시점을 찾습니다."""
}
]

View File

@ -40,6 +40,7 @@
<body>
<div style="margin: auto; max-width: 750px;">
<h1>{{title}} Stock List</h1>
<h3>{{lastUpdate}}</h3>
<section class="description">
{{collected.description}}
</section>

File diff suppressed because one or more lines are too long