analyser_hj3415 3.1.2__py3-none-any.whl → 3.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- analyser_hj3415/analyser/compile.py +92 -38
- analyser_hj3415/analyser/tsa/prophet.py +5 -5
- analyser_hj3415/cli.py +6 -5
- {analyser_hj3415-3.1.2.dist-info → analyser_hj3415-3.2.1.dist-info}/METADATA +1 -1
- {analyser_hj3415-3.1.2.dist-info → analyser_hj3415-3.2.1.dist-info}/RECORD +7 -7
- {analyser_hj3415-3.1.2.dist-info → analyser_hj3415-3.2.1.dist-info}/WHEEL +0 -0
- {analyser_hj3415-3.1.2.dist-info → analyser_hj3415-3.2.1.dist-info}/entry_points.txt +0 -0
@@ -11,8 +11,60 @@ from analyser_hj3415.analyser import eval
|
|
11
11
|
mylogger = setup_logger(__name__,'WARNING')
|
12
12
|
expire_time = tools.to_int(os.getenv('DEFAULT_EXPIRE_TIME_H', 48)) * 3600
|
13
13
|
|
14
|
+
class MICompile:
|
15
|
+
def __init__(self, mi_type: str):
|
16
|
+
assert mi_type in tsa.MIs.keys(), f"Invalid MI type ({tsa.MIs.keys()})"
|
17
|
+
self._mi_type = mi_type
|
18
|
+
self.prophet = tsa.MIProphet(mi_type)
|
19
|
+
self.lstm = tsa.MILSTM(mi_type)
|
14
20
|
|
15
|
-
|
21
|
+
@property
|
22
|
+
def mi_type(self) -> str:
|
23
|
+
return self._mi_type
|
24
|
+
|
25
|
+
@mi_type.setter
|
26
|
+
def mi_type(self, mi_type: str):
|
27
|
+
assert mi_type in tsa.MIs.keys(), f"Invalid MI type ({tsa.MIs.keys()})"
|
28
|
+
self._mi_type = mi_type
|
29
|
+
self.prophet.mi_type = mi_type
|
30
|
+
self.lstm.mi_type = mi_type
|
31
|
+
|
32
|
+
def get(self, refresh=False) -> dict:
|
33
|
+
print(f"{self.mi_type}의 compiling을 시작합니다.")
|
34
|
+
redis_name = self.mi_type + '_mi_compile'
|
35
|
+
print(
|
36
|
+
f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time / 3600}h")
|
37
|
+
|
38
|
+
def fetch_mi_compile() -> dict:
|
39
|
+
trading_action, prophet_score = self.prophet.scoring()
|
40
|
+
print(f"{self.mi_type}")
|
41
|
+
self.lstm.initializing()
|
42
|
+
_, lstm_grade = self.lstm.get_final_predictions(refresh=refresh, num=5)
|
43
|
+
is_lstm_up = self.lstm.is_lstm_up()
|
44
|
+
|
45
|
+
return {
|
46
|
+
'name': self.mi_type,
|
47
|
+
'trading_action': trading_action,
|
48
|
+
'prophet_score': prophet_score,
|
49
|
+
'lstm_grade': lstm_grade,
|
50
|
+
'is_lstm_up': is_lstm_up
|
51
|
+
}
|
52
|
+
|
53
|
+
data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_mi_compile, timer=expire_time)
|
54
|
+
return data_dict
|
55
|
+
|
56
|
+
@staticmethod
|
57
|
+
def analyser_lstm_all_mi(refresh: bool):
|
58
|
+
mi_lstm = tsa.MILSTM('wti')
|
59
|
+
print(f"*** LSTM prediction redis cashing Market Index items ***")
|
60
|
+
for mi_type in tsa.MIs.keys():
|
61
|
+
mi_lstm.mi_type = mi_type
|
62
|
+
print(f"{mi_lstm.mi_type}")
|
63
|
+
mi_lstm.initializing()
|
64
|
+
mi_lstm.get_final_predictions(refresh=refresh, num=5)
|
65
|
+
|
66
|
+
|
67
|
+
class CorpCompile:
|
16
68
|
def __init__(self, code: str, expect_earn=0.06):
|
17
69
|
assert tools.is_6digit(code), f'Invalid value : {code}'
|
18
70
|
self._code = code
|
@@ -36,12 +88,13 @@ class Compile:
|
|
36
88
|
self.prophet.code = code
|
37
89
|
|
38
90
|
def get(self, refresh=False) -> dict:
|
91
|
+
|
39
92
|
print(f"{self.code}/{self.name}의 compiling을 시작합니다.")
|
40
|
-
redis_name = self.code + '
|
93
|
+
redis_name = self.code + '_corp_compile'
|
41
94
|
print(
|
42
95
|
f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time/3600}h")
|
43
96
|
|
44
|
-
def
|
97
|
+
def fetch_corp_compile() -> dict:
|
45
98
|
mylogger.info("Red score 계산중..")
|
46
99
|
red_score = self.red.get(verbose=False).score
|
47
100
|
|
@@ -59,9 +112,42 @@ class Compile:
|
|
59
112
|
'trading_action': trading_action,
|
60
113
|
'prophet_score': prophet_score,
|
61
114
|
}
|
62
|
-
data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh,
|
115
|
+
data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_corp_compile, timer=expire_time)
|
63
116
|
return data_dict
|
64
117
|
|
118
|
+
@staticmethod
|
119
|
+
def red_ranking(expect_earn: float = 0.06, refresh=False) -> OrderedDict:
|
120
|
+
# 이전 expect earn 과 비교하여 다르거나 없으면 강제 refresh 설정
|
121
|
+
redis_name = 'red_ranking_prev_expect_earn'
|
122
|
+
pee = tools.to_float(myredis.Base.get_value(redis_name))
|
123
|
+
if pee != expect_earn:
|
124
|
+
# expect earn의 이전 계산값이 없거나 이전 값과 다르면 새로 계산
|
125
|
+
mylogger.warning(
|
126
|
+
f"expect earn : {expect_earn} / prev expect earn : {pee} 두 값이 달라 refresh = True"
|
127
|
+
)
|
128
|
+
myredis.Base.set_value(redis_name, str(expect_earn))
|
129
|
+
refresh = True
|
130
|
+
|
131
|
+
print("**** Start red_ranking... ****")
|
132
|
+
redis_name = 'red_ranking'
|
133
|
+
print(
|
134
|
+
f"redisname: '{redis_name}' / expect_earn: {expect_earn} / refresh : {refresh} / expire_time : {expire_time / 3600}h")
|
135
|
+
|
136
|
+
def fetch_ranking(refresh_in: bool) -> dict:
|
137
|
+
data = {}
|
138
|
+
red = eval.Red(code='005930', expect_earn=expect_earn)
|
139
|
+
for i, code in enumerate(myredis.Corps.list_all_codes()):
|
140
|
+
red.code = code
|
141
|
+
red_score = red.get(refresh=refresh_in, verbose=False).score
|
142
|
+
if red_score > 0:
|
143
|
+
data[code] = red_score
|
144
|
+
print(f"{i}: {red} - {red_score}")
|
145
|
+
return data
|
146
|
+
|
147
|
+
data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_ranking, refresh, timer=expire_time)
|
148
|
+
|
149
|
+
return OrderedDict(sorted(data_dict.items(), key=lambda item: item[1], reverse=True))
|
150
|
+
|
65
151
|
@staticmethod
|
66
152
|
def prophet_ranking(refresh=False, top: Union[int, str]='all') -> OrderedDict:
|
67
153
|
|
@@ -73,7 +159,7 @@ class Compile:
|
|
73
159
|
|
74
160
|
def fetch_ranking() -> dict:
|
75
161
|
data = {}
|
76
|
-
c =
|
162
|
+
c = CorpCompile('005930')
|
77
163
|
for code in myredis.Corps.list_all_codes():
|
78
164
|
try:
|
79
165
|
c.code = code
|
@@ -100,7 +186,7 @@ class Compile:
|
|
100
186
|
|
101
187
|
@staticmethod
|
102
188
|
def analyse_lstm_topn(refresh: bool, top=40):
|
103
|
-
ranking_topn =
|
189
|
+
ranking_topn = CorpCompile.prophet_ranking(refresh=False, top=top)
|
104
190
|
mylogger.info(ranking_topn)
|
105
191
|
corp_lstm = tsa.CorpLSTM('005930')
|
106
192
|
print(f"*** LSTM prediction redis cashing top{top} items ***")
|
@@ -110,36 +196,4 @@ class Compile:
|
|
110
196
|
corp_lstm.initializing()
|
111
197
|
corp_lstm.get_final_predictions(refresh=refresh, num=5)
|
112
198
|
|
113
|
-
@staticmethod
|
114
|
-
def red_ranking(expect_earn: float = 0.06, refresh=False) -> OrderedDict:
|
115
|
-
# 이전 expect earn 과 비교하여 다르거나 없으면 강제 refresh 설정
|
116
|
-
redis_name = 'red_ranking_prev_expect_earn'
|
117
|
-
pee = tools.to_float(myredis.Base.get_value(redis_name))
|
118
|
-
if pee != expect_earn:
|
119
|
-
# expect earn의 이전 계산값이 없거나 이전 값과 다르면 새로 계산
|
120
|
-
mylogger.warning(
|
121
|
-
f"expect earn : {expect_earn} / prev expect earn : {pee} 두 값이 달라 refresh = True"
|
122
|
-
)
|
123
|
-
myredis.Base.set_value(redis_name, str(expect_earn))
|
124
|
-
refresh = True
|
125
|
-
|
126
|
-
print("**** Start red_ranking... ****")
|
127
|
-
redis_name = 'red_ranking'
|
128
|
-
print(
|
129
|
-
f"redisname: '{redis_name}' / expect_earn: {expect_earn} / refresh : {refresh} / expire_time : {expire_time / 3600}h")
|
130
|
-
|
131
|
-
def fetch_ranking(refresh_in: bool) -> dict:
|
132
|
-
data = {}
|
133
|
-
red = eval.Red(code='005930', expect_earn=expect_earn)
|
134
|
-
for i, code in enumerate(myredis.Corps.list_all_codes()):
|
135
|
-
red.code = code
|
136
|
-
red_score = red.get(refresh=refresh_in, verbose=False).score
|
137
|
-
if red_score > 0:
|
138
|
-
data[code] = red_score
|
139
|
-
print(f"{i}: {red} - {red_score}")
|
140
|
-
return data
|
141
|
-
|
142
|
-
data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_ranking, refresh, timer=expire_time)
|
143
|
-
|
144
|
-
return OrderedDict(sorted(data_dict.items(), key=lambda item: item[1], reverse=True))
|
145
199
|
|
@@ -128,10 +128,10 @@ class MyProphet:
|
|
128
128
|
fig2 = self.model.plot_components(self.df_forecast)
|
129
129
|
plt.show() # 시각화 창 띄우기
|
130
130
|
|
131
|
-
def export(self, to="
|
131
|
+
def export(self, to="html") -> Optional[str]:
|
132
132
|
"""
|
133
133
|
prophet과 plotly로 그래프를 그려서 html을 문자열로 반환
|
134
|
-
:param to:
|
134
|
+
:param to: html, png, file
|
135
135
|
:return:
|
136
136
|
"""
|
137
137
|
# Plotly를 사용한 시각화
|
@@ -161,7 +161,7 @@ class MyProphet:
|
|
161
161
|
showlegend=False,
|
162
162
|
)
|
163
163
|
|
164
|
-
if to == '
|
164
|
+
if to == 'html':
|
165
165
|
# 그래프 HTML로 변환 (string 형식으로 저장)
|
166
166
|
graph_html = plot(fig, output_type='div')
|
167
167
|
return graph_html
|
@@ -169,8 +169,8 @@ class MyProphet:
|
|
169
169
|
# 그래프를 PNG 파일로 저장
|
170
170
|
fig.write_image(f"myprophet_{self.ticker}.png")
|
171
171
|
return None
|
172
|
-
elif to == '
|
173
|
-
# 그래프를 HTML
|
172
|
+
elif to == 'file':
|
173
|
+
# 그래프를 HTML 파일로 저장
|
174
174
|
plot(fig, filename=f'myprophet_{self.ticker}.html', auto_open=False)
|
175
175
|
return None
|
176
176
|
else:
|
analyser_hj3415/cli.py
CHANGED
@@ -99,9 +99,9 @@ def analyser_manager():
|
|
99
99
|
mymongo.Logs.save('cli', 'INFO', 'run >> analyser red ranking')
|
100
100
|
try:
|
101
101
|
if args.expect_earn is None:
|
102
|
-
result = compile.
|
102
|
+
result = compile.CorpCompile.red_ranking(refresh=args.refresh)
|
103
103
|
else:
|
104
|
-
result = compile.
|
104
|
+
result = compile.CorpCompile.red_ranking(expect_earn=args.expect_earn, refresh=args.refresh)
|
105
105
|
print(result)
|
106
106
|
except Exception as e:
|
107
107
|
print(e)
|
@@ -171,7 +171,7 @@ def analyser_manager():
|
|
171
171
|
if args.command == 'ranking':
|
172
172
|
mymongo.Logs.save('cli', 'INFO', 'run >> analyser prophet ranking')
|
173
173
|
try:
|
174
|
-
result = compile.
|
174
|
+
result = compile.CorpCompile.prophet_ranking(refresh=args.refresh)
|
175
175
|
print(result)
|
176
176
|
except Exception as e:
|
177
177
|
print(e)
|
@@ -191,9 +191,10 @@ def analyser_manager():
|
|
191
191
|
mymongo.Logs.save('cli', 'INFO', f'run >> analyser lstm caching')
|
192
192
|
try:
|
193
193
|
if args.top:
|
194
|
-
compile.
|
194
|
+
compile.CorpCompile.analyse_lstm_topn(refresh=args.refresh, top=args.top)
|
195
195
|
else:
|
196
|
-
compile.
|
196
|
+
compile.CorpCompile.analyse_lstm_topn(refresh=args.refresh)
|
197
|
+
compile.MICompile.analyser_lstm_all_mi(refresh=args.refresh)
|
197
198
|
except Exception as e:
|
198
199
|
print(e)
|
199
200
|
mymongo.Logs.save('cli','ERROR', f'analyser lstm caching 실행중 에러 - {e}')
|
@@ -1,7 +1,7 @@
|
|
1
1
|
analyser_hj3415/__init__.py,sha256=f2E9Neh7Nzkhvdj7HWWlgxZK2sB95rBtaIgWEHzxK9E,450
|
2
|
-
analyser_hj3415/cli.py,sha256=
|
2
|
+
analyser_hj3415/cli.py,sha256=iNyZz77BNe_aPcqiJrhWhjvxJZJQfmWQev8dM9xu2H8,11824
|
3
3
|
analyser_hj3415/analyser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
analyser_hj3415/analyser/compile.py,sha256=
|
4
|
+
analyser_hj3415/analyser/compile.py,sha256=INd9XI-V21Q48HQkk8oUke7k_mE4kIbqorahiaPeKaQ,7720
|
5
5
|
analyser_hj3415/analyser/eval/__init__.py,sha256=IP1d0Q3nOCAD3zK1qxrC685MkJQfUh-qaXc7xptTxk8,80
|
6
6
|
analyser_hj3415/analyser/eval/blue.py,sha256=fq_eln7-EdwICNQ2sMXAfZKXGhQ29EaJwsGvn7xA29U,7632
|
7
7
|
analyser_hj3415/analyser/eval/common.py,sha256=wcWJg_jNgr02i1U62oZGgLt2iscdle9X-u4aMnZl89Q,14127
|
@@ -10,13 +10,13 @@ analyser_hj3415/analyser/eval/mil.py,sha256=wN1jPu5zLJjoDk3kL7piL-4jWhpsAMeQpsTZ
|
|
10
10
|
analyser_hj3415/analyser/eval/red.py,sha256=rJbidKlo2s2EJHBGn4HDbfCDcEGP5Rst8iQeJ6jlzNA,10988
|
11
11
|
analyser_hj3415/analyser/tsa/__init__.py,sha256=0XIpMgYIiyDrSE3sp9S0J0gXwW4cpk6nQmxSjC3KkY4,371
|
12
12
|
analyser_hj3415/analyser/tsa/lstm.py,sha256=22Rd1PTBeDAvITb1zw65Y51lLB76w6MyWXNKku6RzjM,29975
|
13
|
-
analyser_hj3415/analyser/tsa/prophet.py,sha256=
|
13
|
+
analyser_hj3415/analyser/tsa/prophet.py,sha256=jHaOufe7FAJanPXgPh0YxvQ4OiATJue_7cDyfHnq1hc,10156
|
14
14
|
analyser_hj3415/workroom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
15
|
analyser_hj3415/workroom/mysklearn.py,sha256=wJXKz5MqqTzADdG2mqRMMzc_G9RzwYjj5_j4gyOopxQ,2030
|
16
16
|
analyser_hj3415/workroom/mysklearn2.py,sha256=1lIy6EWEQHkOzDS-av8U0zQH6DuCLKWMI73dnJx5KRs,1495
|
17
17
|
analyser_hj3415/workroom/score.py,sha256=P6nHBJYmyhigGtT4qna4BmNtvt4B93b7SKyzdstJK24,17376
|
18
18
|
analyser_hj3415/workroom/trash.py,sha256=zF-W0piqkGr66UP6-iybo9EXh2gO0RP6R1FnIpsGkl8,12262
|
19
|
-
analyser_hj3415-3.1.
|
20
|
-
analyser_hj3415-3.1.
|
21
|
-
analyser_hj3415-3.1.
|
22
|
-
analyser_hj3415-3.1.
|
19
|
+
analyser_hj3415-3.2.1.dist-info/entry_points.txt,sha256=ZfjPnJuH8SzvhE9vftIPMBIofsc65IAWYOhqOC_L5ck,65
|
20
|
+
analyser_hj3415-3.2.1.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
21
|
+
analyser_hj3415-3.2.1.dist-info/METADATA,sha256=ysCQEllcgKTZjSHajJ6lx0iyGfS_DI5MUACiPRpnwew,6777
|
22
|
+
analyser_hj3415-3.2.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|