analyser_hj3415 3.2.0__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.
@@ -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
- class Compile:
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
@@ -38,11 +90,11 @@ class Compile:
38
90
  def get(self, refresh=False) -> dict:
39
91
 
40
92
  print(f"{self.code}/{self.name}의 compiling을 시작합니다.")
41
- redis_name = self.code + '_compile_scores'
93
+ redis_name = self.code + '_corp_compile'
42
94
  print(
43
95
  f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time/3600}h")
44
96
 
45
- def fetch_compile_scores() -> dict:
97
+ def fetch_corp_compile() -> dict:
46
98
  mylogger.info("Red score 계산중..")
47
99
  red_score = self.red.get(verbose=False).score
48
100
 
@@ -60,9 +112,42 @@ class Compile:
60
112
  'trading_action': trading_action,
61
113
  'prophet_score': prophet_score,
62
114
  }
63
- data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_compile_scores, timer=expire_time)
115
+ data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_corp_compile, timer=expire_time)
64
116
  return data_dict
65
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
+
66
151
  @staticmethod
67
152
  def prophet_ranking(refresh=False, top: Union[int, str]='all') -> OrderedDict:
68
153
 
@@ -74,7 +159,7 @@ class Compile:
74
159
 
75
160
  def fetch_ranking() -> dict:
76
161
  data = {}
77
- c = Compile('005930')
162
+ c = CorpCompile('005930')
78
163
  for code in myredis.Corps.list_all_codes():
79
164
  try:
80
165
  c.code = code
@@ -101,7 +186,7 @@ class Compile:
101
186
 
102
187
  @staticmethod
103
188
  def analyse_lstm_topn(refresh: bool, top=40):
104
- ranking_topn = Compile.prophet_ranking(refresh=False, top=top)
189
+ ranking_topn = CorpCompile.prophet_ranking(refresh=False, top=top)
105
190
  mylogger.info(ranking_topn)
106
191
  corp_lstm = tsa.CorpLSTM('005930')
107
192
  print(f"*** LSTM prediction redis cashing top{top} items ***")
@@ -111,46 +196,4 @@ class Compile:
111
196
  corp_lstm.initializing()
112
197
  corp_lstm.get_final_predictions(refresh=refresh, num=5)
113
198
 
114
- @staticmethod
115
- def analyse_lstm_mis(refresh: bool):
116
- mi_lstm = tsa.MILSTM('wti')
117
- print(f"*** LSTM prediction redis cashing Market Index items ***")
118
- for mi_type in tsa.MIs.keys():
119
- mi_lstm.mi_type = mi_type
120
- print(f"{mi_lstm.mi_type}")
121
- mi_lstm.initializing()
122
- mi_lstm.get_final_predictions(refresh=refresh, num=5)
123
-
124
- @staticmethod
125
- def red_ranking(expect_earn: float = 0.06, refresh=False) -> OrderedDict:
126
- # 이전 expect earn 과 비교하여 다르거나 없으면 강제 refresh 설정
127
- redis_name = 'red_ranking_prev_expect_earn'
128
- pee = tools.to_float(myredis.Base.get_value(redis_name))
129
- if pee != expect_earn:
130
- # expect earn의 이전 계산값이 없거나 이전 값과 다르면 새로 계산
131
- mylogger.warning(
132
- f"expect earn : {expect_earn} / prev expect earn : {pee} 두 값이 달라 refresh = True"
133
- )
134
- myredis.Base.set_value(redis_name, str(expect_earn))
135
- refresh = True
136
-
137
- print("**** Start red_ranking... ****")
138
- redis_name = 'red_ranking'
139
- print(
140
- f"redisname: '{redis_name}' / expect_earn: {expect_earn} / refresh : {refresh} / expire_time : {expire_time / 3600}h")
141
-
142
- def fetch_ranking(refresh_in: bool) -> dict:
143
- data = {}
144
- red = eval.Red(code='005930', expect_earn=expect_earn)
145
- for i, code in enumerate(myredis.Corps.list_all_codes()):
146
- red.code = code
147
- red_score = red.get(refresh=refresh_in, verbose=False).score
148
- if red_score > 0:
149
- data[code] = red_score
150
- print(f"{i}: {red} - {red_score}")
151
- return data
152
-
153
- data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_ranking, refresh, timer=expire_time)
154
-
155
- return OrderedDict(sorted(data_dict.items(), key=lambda item: item[1], reverse=True))
156
199
 
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.Compile.red_ranking(refresh=args.refresh)
102
+ result = compile.CorpCompile.red_ranking(refresh=args.refresh)
103
103
  else:
104
- result = compile.Compile.red_ranking(expect_earn=args.expect_earn, refresh=args.refresh)
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.Compile.prophet_ranking(refresh=args.refresh)
174
+ result = compile.CorpCompile.prophet_ranking(refresh=args.refresh)
175
175
  print(result)
176
176
  except Exception as e:
177
177
  print(e)
@@ -191,10 +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.Compile.analyse_lstm_topn(refresh=args.refresh, top=args.top)
194
+ compile.CorpCompile.analyse_lstm_topn(refresh=args.refresh, top=args.top)
195
195
  else:
196
- compile.Compile.analyse_lstm_topn(refresh=args.refresh)
197
- compile.Compile.analyse_lstm_mis(refresh=args.refresh)
196
+ compile.CorpCompile.analyse_lstm_topn(refresh=args.refresh)
197
+ compile.MICompile.analyser_lstm_all_mi(refresh=args.refresh)
198
198
  except Exception as e:
199
199
  print(e)
200
200
  mymongo.Logs.save('cli','ERROR', f'analyser lstm caching 실행중 에러 - {e}')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: analyser_hj3415
3
- Version: 3.2.0
3
+ Version: 3.2.1
4
4
  Summary: Stock analyser and database processing programs
5
5
  Requires-Python: >=3.6
6
6
  Description-Content-Type: text/markdown
@@ -1,7 +1,7 @@
1
1
  analyser_hj3415/__init__.py,sha256=f2E9Neh7Nzkhvdj7HWWlgxZK2sB95rBtaIgWEHzxK9E,450
2
- analyser_hj3415/cli.py,sha256=MIdk_0JVnx4M1la-2ifF09JLMXsZzS0mrvsPMQ1C-1g,11798
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=J2kSNC9xCWJ0l0A-nV6eUnBULP77xwdlaerVhXqDGvc,6153
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
@@ -16,7 +16,7 @@ analyser_hj3415/workroom/mysklearn.py,sha256=wJXKz5MqqTzADdG2mqRMMzc_G9RzwYjj5_j
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.2.0.dist-info/entry_points.txt,sha256=ZfjPnJuH8SzvhE9vftIPMBIofsc65IAWYOhqOC_L5ck,65
20
- analyser_hj3415-3.2.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
21
- analyser_hj3415-3.2.0.dist-info/METADATA,sha256=rByJ0JDeAVZprcztSyaBD9cM-Qupq4hhdltooDtbSmY,6777
22
- analyser_hj3415-3.2.0.dist-info/RECORD,,
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,,