analyser_hj3415 3.3.0__py3-none-any.whl → 3.4.0__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 +155 -18
- analyser_hj3415/cli.py +18 -11
- {analyser_hj3415-3.3.0.dist-info → analyser_hj3415-3.4.0.dist-info}/METADATA +1 -1
- {analyser_hj3415-3.3.0.dist-info → analyser_hj3415-3.4.0.dist-info}/RECORD +6 -6
- {analyser_hj3415-3.3.0.dist-info → analyser_hj3415-3.4.0.dist-info}/WHEEL +0 -0
- {analyser_hj3415-3.3.0.dist-info → analyser_hj3415-3.4.0.dist-info}/entry_points.txt +0 -0
@@ -11,9 +11,20 @@ from analyser_hj3415.analyser import tsa, eval, MIs
|
|
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
|
-
|
15
14
|
@dataclass
|
16
15
|
class MICompileData:
|
16
|
+
"""
|
17
|
+
MI(Market Index) 데이터를 컴파일하여 저장하는 데이터 클래스.
|
18
|
+
|
19
|
+
속성:
|
20
|
+
mi_type (str): 시장 지수 유형.
|
21
|
+
prophet_data (tsa.ProphetData): Prophet 예측 데이터.
|
22
|
+
lstm_grade (tsa.LSTMGrade): LSTM 등급 데이터.
|
23
|
+
is_lstm_up (bool): LSTM 상승 여부.
|
24
|
+
is_prophet_up (bool): Prophet 상승 여부.
|
25
|
+
lstm_html (str): LSTM 시각화 HTML.
|
26
|
+
prophet_html (str): Prophet 시각화 HTML.
|
27
|
+
"""
|
17
28
|
mi_type: str
|
18
29
|
|
19
30
|
prophet_data: tsa.ProphetData
|
@@ -27,20 +38,57 @@ class MICompileData:
|
|
27
38
|
|
28
39
|
|
29
40
|
class MICompile:
|
41
|
+
"""
|
42
|
+
MI(Market Index) 데이터를 컴파일하는 클래스.
|
43
|
+
|
44
|
+
메서드:
|
45
|
+
get(refresh=False) -> MICompileData:
|
46
|
+
MI 데이터를 컴파일하거나 캐시에서 가져옵니다.
|
47
|
+
|
48
|
+
analyser_lstm_all_mi(refresh: bool):
|
49
|
+
모든 MI에 대해 LSTM 예측 및 초기화 수행.
|
50
|
+
"""
|
30
51
|
def __init__(self, mi_type: str):
|
52
|
+
"""
|
53
|
+
MICompile 객체를 초기화합니다.
|
54
|
+
|
55
|
+
매개변수:
|
56
|
+
mi_type (str): 시장 지수 유형.
|
57
|
+
"""
|
31
58
|
assert mi_type in MIs._fields, f"Invalid MI type ({MIs._fields})"
|
32
59
|
self._mi_type = mi_type
|
33
60
|
|
34
61
|
@property
|
35
62
|
def mi_type(self) -> str:
|
63
|
+
"""
|
64
|
+
MI 유형을 반환합니다.
|
65
|
+
|
66
|
+
반환값:
|
67
|
+
str: MI 유형.
|
68
|
+
"""
|
36
69
|
return self._mi_type
|
37
70
|
|
38
71
|
@mi_type.setter
|
39
72
|
def mi_type(self, mi_type: str):
|
73
|
+
"""
|
74
|
+
MI 유형을 변경합니다.
|
75
|
+
|
76
|
+
매개변수:
|
77
|
+
mi_type (str): 새로 설정할 MI 유형.
|
78
|
+
"""
|
40
79
|
assert mi_type in MIs._fields, f"Invalid MI type ({MIs._fields})"
|
41
80
|
self._mi_type = mi_type
|
42
81
|
|
43
82
|
def get(self, refresh=False) -> MICompileData:
|
83
|
+
"""
|
84
|
+
MI 데이터를 컴파일하거나 캐시에서 가져옵니다.
|
85
|
+
|
86
|
+
매개변수:
|
87
|
+
refresh (bool): 데이터를 새로 가져올지 여부.
|
88
|
+
|
89
|
+
반환값:
|
90
|
+
MICompileData: 컴파일된 MI 데이터.
|
91
|
+
"""
|
44
92
|
print(f"{self.mi_type}의 compiling을 시작합니다.")
|
45
93
|
redis_name = self.mi_type + '_mi_compile'
|
46
94
|
print(
|
@@ -65,18 +113,39 @@ class MICompile:
|
|
65
113
|
return mi_compile_data
|
66
114
|
|
67
115
|
@staticmethod
|
68
|
-
def
|
69
|
-
|
70
|
-
|
116
|
+
def caching_mi_compile_all(refresh: bool):
|
117
|
+
"""
|
118
|
+
모든 MI(Market Index)에 대해 MICompileData를 캐싱합니다..
|
119
|
+
|
120
|
+
매개변수:
|
121
|
+
refresh (bool): 데이터를 새로 가져올지 여부.
|
122
|
+
"""
|
123
|
+
mi_compile = MICompile('WTI')
|
124
|
+
print(f"*** MICompileData caching Market Index items ***")
|
71
125
|
for mi_type in MIs._fields:
|
72
|
-
|
73
|
-
print(f"{
|
74
|
-
|
75
|
-
|
126
|
+
mi_compile.mi_type = mi_type
|
127
|
+
print(f"{mi_type}")
|
128
|
+
mi_compile_data = mi_compile.get(refresh=refresh)
|
129
|
+
print(mi_compile_data)
|
76
130
|
|
77
131
|
|
78
132
|
@dataclass
|
79
133
|
class CorpCompileData:
|
134
|
+
"""
|
135
|
+
기업 데이터를 컴파일하여 저장하는 데이터 클래스.
|
136
|
+
|
137
|
+
속성:
|
138
|
+
code (str): 기업 코드.
|
139
|
+
name (str): 기업 이름.
|
140
|
+
red_data (eval.RedData): RED 분석 데이터.
|
141
|
+
mil_data (eval.MilData): MIL 분석 데이터.
|
142
|
+
prophet_data (tsa.ProphetData): Prophet 예측 데이터.
|
143
|
+
lstm_grade (tsa.LSTMGrade): LSTM 등급 데이터.
|
144
|
+
is_lstm_up (bool): LSTM 상승 여부.
|
145
|
+
is_prophet_up (bool): Prophet 상승 여부.
|
146
|
+
lstm_html (str): LSTM 시각화 HTML.
|
147
|
+
prophet_html (str): Prophet 시각화 HTML.
|
148
|
+
"""
|
80
149
|
code: str
|
81
150
|
name: str
|
82
151
|
|
@@ -94,22 +163,66 @@ class CorpCompileData:
|
|
94
163
|
|
95
164
|
|
96
165
|
class CorpCompile:
|
166
|
+
"""
|
167
|
+
기업 데이터를 컴파일하는 클래스.
|
168
|
+
|
169
|
+
메서드:
|
170
|
+
get(refresh=False) -> CorpCompileData:
|
171
|
+
기업 데이터를 컴파일하거나 캐시에서 가져옵니다.
|
172
|
+
|
173
|
+
red_ranking(expect_earn: float = 0.06, refresh=False) -> OrderedDict:
|
174
|
+
RED 데이터를 기반으로 기업 순위를 계산합니다.
|
175
|
+
|
176
|
+
prophet_ranking(refresh=False, top: Union[int, str]='all') -> OrderedDict:
|
177
|
+
Prophet 데이터를 기반으로 기업 순위를 계산합니다.
|
178
|
+
|
179
|
+
analyse_lstm_topn(refresh: bool, top=40):
|
180
|
+
상위 N개의 기업에 대해 LSTM 예측 수행.
|
181
|
+
"""
|
97
182
|
def __init__(self, code: str, expect_earn=0.06):
|
183
|
+
"""
|
184
|
+
CorpCompile 객체를 초기화합니다.
|
185
|
+
|
186
|
+
매개변수:
|
187
|
+
code (str): 기업 코드.
|
188
|
+
expect_earn (float, optional): 예상 수익률. 기본값은 0.06.
|
189
|
+
"""
|
98
190
|
assert tools.is_6digit(code), f'Invalid value : {code}'
|
99
191
|
self._code = code
|
100
192
|
self.expect_earn = expect_earn
|
101
193
|
|
102
194
|
@property
|
103
195
|
def code(self) -> str:
|
196
|
+
"""
|
197
|
+
기업 코드를 반환합니다.
|
198
|
+
|
199
|
+
반환값:
|
200
|
+
str: 기업 코드.
|
201
|
+
"""
|
104
202
|
return self._code
|
105
203
|
|
106
204
|
@code.setter
|
107
205
|
def code(self, code: str):
|
206
|
+
"""
|
207
|
+
기업 코드를 변경합니다.
|
208
|
+
|
209
|
+
매개변수:
|
210
|
+
code (str): 새로 설정할 기업 코드.
|
211
|
+
"""
|
108
212
|
assert tools.is_6digit(code), f'Invalid value : {code}'
|
109
213
|
mylogger.info(f'change code : {self.code} -> {code}')
|
110
214
|
self._code = code
|
111
215
|
|
112
|
-
def get(self, refresh=False) ->
|
216
|
+
def get(self, refresh=False) -> CorpCompileData:
|
217
|
+
"""
|
218
|
+
기업 데이터를 컴파일하여 캐시에 저장하거나 캐시에서 가져옵니다.
|
219
|
+
|
220
|
+
매개변수:
|
221
|
+
refresh (bool): 데이터를 새로 가져올지 여부.
|
222
|
+
|
223
|
+
반환값:
|
224
|
+
CorpCompileData: 컴파일된 기업 데이터.
|
225
|
+
"""
|
113
226
|
print(f"{self.code}의 compiling을 시작합니다.")
|
114
227
|
redis_name = self.code + '_corp_compile'
|
115
228
|
print(
|
@@ -139,11 +252,19 @@ class CorpCompile:
|
|
139
252
|
|
140
253
|
@staticmethod
|
141
254
|
def red_ranking(expect_earn: float = 0.06, refresh=False) -> OrderedDict:
|
142
|
-
|
255
|
+
"""
|
256
|
+
RED 데이터를 기반으로 기업 순위를 계산합니다.
|
257
|
+
|
258
|
+
매개변수:
|
259
|
+
expect_earn (float, optional): 예상 수익률. 기본값은 0.06.
|
260
|
+
refresh (bool): 데이터를 새로 가져올지 여부.
|
261
|
+
|
262
|
+
반환값:
|
263
|
+
OrderedDict: RED 점수를 기준으로 정렬된 기업 순위.
|
264
|
+
"""
|
143
265
|
redis_name = 'red_ranking_prev_expect_earn'
|
144
266
|
pee = tools.to_float(myredis.Base.get_value(redis_name))
|
145
267
|
if pee != expect_earn:
|
146
|
-
# expect earn의 이전 계산값이 없거나 이전 값과 다르면 새로 계산
|
147
268
|
mylogger.warning(
|
148
269
|
f"expect earn : {expect_earn} / prev expect earn : {pee} 두 값이 달라 refresh = True"
|
149
270
|
)
|
@@ -172,7 +293,16 @@ class CorpCompile:
|
|
172
293
|
|
173
294
|
@staticmethod
|
174
295
|
def prophet_ranking(refresh=False, top: Union[int, str]='all') -> OrderedDict:
|
296
|
+
"""
|
297
|
+
Prophet 데이터를 기반으로 기업 순위를 계산합니다.
|
298
|
+
|
299
|
+
매개변수:
|
300
|
+
refresh (bool): 데이터를 새로 가져올지 여부.
|
301
|
+
top (Union[int, str], optional): 상위 기업 개수. 'all'이면 전체 반환. 기본값은 'all'.
|
175
302
|
|
303
|
+
반환값:
|
304
|
+
OrderedDict: Prophet 점수를 기준으로 정렬된 기업 순위.
|
305
|
+
"""
|
176
306
|
print("**** Start Compiling scores and sorting... ****")
|
177
307
|
redis_name = 'prophet_ranking'
|
178
308
|
|
@@ -195,7 +325,6 @@ class CorpCompile:
|
|
195
325
|
|
196
326
|
data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_prophet_ranking, timer=expire_time)
|
197
327
|
|
198
|
-
# prophet_score를 기준으로 정렬
|
199
328
|
ranking = OrderedDict(sorted(data_dict.items(), key=lambda x: x[1], reverse=True))
|
200
329
|
|
201
330
|
if top == 'all':
|
@@ -207,12 +336,20 @@ class CorpCompile:
|
|
207
336
|
raise ValueError("top 인자는 'all' 이나 int형 이어야 합니다.")
|
208
337
|
|
209
338
|
@staticmethod
|
210
|
-
def
|
339
|
+
def caching_corp_compile_topn(refresh: bool, top=40):
|
340
|
+
"""
|
341
|
+
상위 N개의 기업에 대해 CorpCompileData를 수집합니다..
|
342
|
+
|
343
|
+
매개변수:
|
344
|
+
refresh (bool): 데이터를 새로 가져올지 여부.
|
345
|
+
top (int, optional): 상위 기업 개수. 기본값은 40.
|
346
|
+
"""
|
211
347
|
ranking_topn = CorpCompile.prophet_ranking(refresh=False, top=top)
|
212
348
|
mylogger.info(ranking_topn)
|
213
|
-
|
214
|
-
print(f"***
|
349
|
+
corp_compile = CorpCompile('005930')
|
350
|
+
print(f"*** CorpCompile redis cashing top{top} items ***")
|
215
351
|
for i, (code, _) in enumerate(ranking_topn.items()):
|
216
|
-
|
217
|
-
print(f"{i + 1}. {
|
218
|
-
|
352
|
+
corp_compile.code = code
|
353
|
+
print(f"{i + 1}. {code}")
|
354
|
+
corp_compile_data = corp_compile.get(refresh=refresh)
|
355
|
+
print(corp_compile_data)
|
analyser_hj3415/cli.py
CHANGED
@@ -10,6 +10,16 @@ def analyser_manager():
|
|
10
10
|
parser = argparse.ArgumentParser(description="Analyser Commands")
|
11
11
|
type_subparsers = parser.add_subparsers(dest='type', help='분석 타입')
|
12
12
|
|
13
|
+
# compile 명령어 서브파서
|
14
|
+
compile_parser = type_subparsers.add_parser('compile', help='Compile 타입')
|
15
|
+
compile_subparser = compile_parser.add_subparsers(dest='command', help='Compile 관련된 명령')
|
16
|
+
# compile - caching 파서
|
17
|
+
caching_parser = compile_subparser.add_parser('caching', help='lstm 랭킹 책정 및 레디스 저장')
|
18
|
+
caching_parser.add_argument('-r', '--refresh', action='store_true', help='래디스 캐시를 사용하지 않고 강제로 재계산 할지')
|
19
|
+
caching_parser.add_argument('-mi', '--market_index', action='store_true', help='Market index도 캐싱할지')
|
20
|
+
caching_parser.add_argument('-t', '--top', type=int, help='prophet ranking 몇위까지 작업을 할지')
|
21
|
+
|
22
|
+
|
13
23
|
# prophet 명령어 서브파서
|
14
24
|
prophet_parser = type_subparsers.add_parser('prophet', help='MyProphet 타입')
|
15
25
|
prophet_subparser = prophet_parser.add_subparsers(dest='command', help='prophet 관련된 명령')
|
@@ -24,11 +34,6 @@ def analyser_manager():
|
|
24
34
|
# lstm 명령어 서브파서
|
25
35
|
lstm_parser = type_subparsers.add_parser('lstm', help='MyLSTM 타입')
|
26
36
|
lstm_subparser = lstm_parser.add_subparsers(dest='command', help='lstm 관련된 명령')
|
27
|
-
# lstm - caching 파서
|
28
|
-
caching_parser = lstm_subparser.add_parser('caching', help='lstm 랭킹 책정 및 레디스 저장')
|
29
|
-
caching_parser.add_argument('-r', '--refresh', action='store_true', help='래디스 캐시를 사용하지 않고 강제로 재계산 할지')
|
30
|
-
caching_parser.add_argument('-mi', '--market_index', action='store_true', help='Market index도 캐싱할지')
|
31
|
-
caching_parser.add_argument('-t', '--top', type=int, help='prophet ranking 몇위까지 작업을 할지')
|
32
37
|
# lstm - predict 파서
|
33
38
|
lstm_get_parser = lstm_subparser.add_parser('predict', help='lstm get final prediction 시행')
|
34
39
|
lstm_get_parser.add_argument('target', type=str, help=f'종목코드 or {list(MIs._fields)}')
|
@@ -187,20 +192,22 @@ def analyser_manager():
|
|
187
192
|
print(myprophet.generate_data(refresh=args.refresh).score)
|
188
193
|
# mymongo.Logs.save('cli','INFO', f'run >> analyser prophet get {args.target}')
|
189
194
|
|
190
|
-
elif args.type == '
|
195
|
+
elif args.type == 'compile':
|
191
196
|
if args.command == 'caching':
|
192
|
-
mymongo.Logs.save('cli', 'INFO', f'run >> analyser
|
197
|
+
mymongo.Logs.save('cli', 'INFO', f'run >> analyser compile caching')
|
193
198
|
try:
|
194
199
|
if args.top:
|
195
|
-
compile.CorpCompile.
|
200
|
+
compile.CorpCompile.caching_corp_compile_topn(refresh=args.refresh, top=args.top)
|
196
201
|
else:
|
197
|
-
compile.CorpCompile.
|
202
|
+
compile.CorpCompile.caching_corp_compile_topn(refresh=args.refresh)
|
198
203
|
if args.market_index:
|
199
|
-
compile.MICompile.
|
204
|
+
compile.MICompile.caching_mi_compile_all(refresh=args.refresh)
|
200
205
|
except Exception as e:
|
201
206
|
print(e)
|
202
207
|
mymongo.Logs.save('cli','ERROR', f'analyser lstm caching 실행중 에러 - {e}')
|
203
|
-
|
208
|
+
|
209
|
+
elif args.type == 'lstm':
|
210
|
+
if args.command == 'predict':
|
204
211
|
mi_type = str(args.target).upper()
|
205
212
|
if mi_type in MIs._fields:
|
206
213
|
mylstm = tsa.MILSTM(mi_type)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
analyser_hj3415/__init__.py,sha256=jqHEUoBeihYOMaS0bPOe3nRVXBufZ0clxc6M6jxPY0o,320
|
2
|
-
analyser_hj3415/cli.py,sha256=
|
2
|
+
analyser_hj3415/cli.py,sha256=dnmhYBucWWNYsnyf0xVHcx87j7rciG7T2omD3_oGiYk,12300
|
3
3
|
analyser_hj3415/analyser/__init__.py,sha256=N0XyBfWJNpDS_6JYziKETWePO_jtFB1m7E8Qbwt1w0Q,1096
|
4
|
-
analyser_hj3415/analyser/compile.py,sha256=
|
4
|
+
analyser_hj3415/analyser/compile.py,sha256=wMTuVadcSODHjjTP5ma_GuygujqCeYDQkad2rAsCprw,12535
|
5
5
|
analyser_hj3415/analyser/eval/__init__.py,sha256=IP1d0Q3nOCAD3zK1qxrC685MkJQfUh-qaXc7xptTxk8,80
|
6
6
|
analyser_hj3415/analyser/eval/blue.py,sha256=p9_ddqLMJGq5HSn6NApuLhrX29qD--AASig9F71eb8I,10952
|
7
7
|
analyser_hj3415/analyser/eval/common.py,sha256=sNXapoofShA43ww_SLjXmIjkrAr1AhAcezdaN_X_3Us,11443
|
@@ -17,7 +17,7 @@ analyser_hj3415/workroom/mysklearn.py,sha256=wJXKz5MqqTzADdG2mqRMMzc_G9RzwYjj5_j
|
|
17
17
|
analyser_hj3415/workroom/mysklearn2.py,sha256=1lIy6EWEQHkOzDS-av8U0zQH6DuCLKWMI73dnJx5KRs,1495
|
18
18
|
analyser_hj3415/workroom/score.py,sha256=P6nHBJYmyhigGtT4qna4BmNtvt4B93b7SKyzdstJK24,17376
|
19
19
|
analyser_hj3415/workroom/trash.py,sha256=zF-W0piqkGr66UP6-iybo9EXh2gO0RP6R1FnIpsGkl8,12262
|
20
|
-
analyser_hj3415-3.
|
21
|
-
analyser_hj3415-3.
|
22
|
-
analyser_hj3415-3.
|
23
|
-
analyser_hj3415-3.
|
20
|
+
analyser_hj3415-3.4.0.dist-info/entry_points.txt,sha256=ZfjPnJuH8SzvhE9vftIPMBIofsc65IAWYOhqOC_L5ck,65
|
21
|
+
analyser_hj3415-3.4.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
22
|
+
analyser_hj3415-3.4.0.dist-info/METADATA,sha256=NNilJQn-1nlk0lwDdKM7tlntRtg6c9Yk65iVPyofVHg,6777
|
23
|
+
analyser_hj3415-3.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|