analyser_hj3415 3.2.1__py3-none-any.whl → 3.3.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/__init__.py +0 -5
- analyser_hj3415/analyser/__init__.py +30 -0
- analyser_hj3415/analyser/compile.py +84 -65
- analyser_hj3415/analyser/eval/blue.py +78 -9
- analyser_hj3415/analyser/eval/common.py +72 -110
- analyser_hj3415/analyser/eval/growth.py +77 -6
- analyser_hj3415/analyser/eval/mil.py +119 -18
- analyser_hj3415/analyser/eval/red.py +95 -66
- analyser_hj3415/analyser/tsa/__init__.py +1 -13
- analyser_hj3415/analyser/tsa/common.py +33 -0
- analyser_hj3415/analyser/tsa/lstm.py +108 -137
- analyser_hj3415/analyser/tsa/prophet.py +262 -126
- analyser_hj3415/cli.py +13 -11
- {analyser_hj3415-3.2.1.dist-info → analyser_hj3415-3.3.0.dist-info}/METADATA +1 -1
- analyser_hj3415-3.3.0.dist-info/RECORD +23 -0
- analyser_hj3415-3.2.1.dist-info/RECORD +0 -22
- {analyser_hj3415-3.2.1.dist-info → analyser_hj3415-3.3.0.dist-info}/WHEEL +0 -0
- {analyser_hj3415-3.2.1.dist-info → analyser_hj3415-3.3.0.dist-info}/entry_points.txt +0 -0
analyser_hj3415/__init__.py
CHANGED
@@ -6,8 +6,3 @@ env_path = get_env_path()
|
|
6
6
|
if env_path is None:
|
7
7
|
mylogger.warning(f"환경변수 파일(.env)를 찾을수 없습니다. 기본 설정값으로 프로그램을 실행합니다.")
|
8
8
|
load_dotenv(env_path)
|
9
|
-
|
10
|
-
from analyser_hj3415.analyser import eval
|
11
|
-
from analyser_hj3415.analyser import compile
|
12
|
-
from analyser_hj3415.analyser import tsa
|
13
|
-
|
@@ -0,0 +1,30 @@
|
|
1
|
+
from typing import NamedTuple
|
2
|
+
|
3
|
+
class MarketIndices(NamedTuple):
|
4
|
+
"""
|
5
|
+
주요 시장 지수를 나타내는 NamedTuple입니다.
|
6
|
+
|
7
|
+
속성:
|
8
|
+
WTI (str): 서부 텍사스 중질유(WTI) 선물 지수 (심볼: "CL=F").
|
9
|
+
GOLD (str): 금 선물 지수 (심볼: "GC=F").
|
10
|
+
SILVER (str): 은 선물 지수 (심볼: "SI=F").
|
11
|
+
USD_IDX (str): 미국 달러 인덱스 (심볼: "DX-Y.NYB").
|
12
|
+
USD_KRW (str): 달러-원 환율 (심볼: "KRW=X").
|
13
|
+
SP500 (str): S&P 500 주가지수 (심볼: "^GSPC").
|
14
|
+
KOSPI (str): 코스피 지수 (심볼: "^KS11").
|
15
|
+
NIKKEI (str): 닛케이 225 지수 (일본) (심볼: "^N225").
|
16
|
+
CHINA (str): 항셍 지수 (홍콩) (심볼: "^HSI").
|
17
|
+
IRX (str): 미국 단기 국채 금리 지수 (13주 T-빌 금리) (심볼: "^IRX").
|
18
|
+
"""
|
19
|
+
WTI: str = "CL=F"
|
20
|
+
GOLD: str = "GC=F"
|
21
|
+
SILVER: str = "SI=F"
|
22
|
+
USD_IDX: str = "DX-Y.NYB"
|
23
|
+
USD_KRW: str = "KRW=X"
|
24
|
+
SP500: str = "^GSPC"
|
25
|
+
KOSPI: str = "^KS11"
|
26
|
+
NIKKEI: str = "^N225"
|
27
|
+
CHINA: str = "^HSI"
|
28
|
+
IRX: str = "^IRX"
|
29
|
+
|
30
|
+
MIs = MarketIndices()
|
@@ -1,22 +1,35 @@
|
|
1
1
|
import os
|
2
2
|
from collections import OrderedDict
|
3
3
|
from typing import Union
|
4
|
+
from dataclasses import dataclass
|
4
5
|
|
5
|
-
from db_hj3415 import myredis
|
6
|
+
from db_hj3415 import myredis
|
6
7
|
from utils_hj3415 import tools, setup_logger
|
7
8
|
|
8
|
-
from analyser_hj3415.analyser import tsa
|
9
|
-
from analyser_hj3415.analyser import eval
|
9
|
+
from analyser_hj3415.analyser import tsa, eval, MIs
|
10
10
|
|
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
|
+
@dataclass
|
16
|
+
class MICompileData:
|
17
|
+
mi_type: str
|
18
|
+
|
19
|
+
prophet_data: tsa.ProphetData
|
20
|
+
lstm_grade: tsa.LSTMGrade
|
21
|
+
|
22
|
+
is_lstm_up: bool = False
|
23
|
+
is_prophet_up: bool = False
|
24
|
+
|
25
|
+
lstm_html: str = ''
|
26
|
+
prophet_html: str = ''
|
27
|
+
|
28
|
+
|
14
29
|
class MICompile:
|
15
30
|
def __init__(self, mi_type: str):
|
16
|
-
assert mi_type in
|
31
|
+
assert mi_type in MIs._fields, f"Invalid MI type ({MIs._fields})"
|
17
32
|
self._mi_type = mi_type
|
18
|
-
self.prophet = tsa.MIProphet(mi_type)
|
19
|
-
self.lstm = tsa.MILSTM(mi_type)
|
20
33
|
|
21
34
|
@property
|
22
35
|
def mi_type(self) -> str:
|
@@ -24,54 +37,67 @@ class MICompile:
|
|
24
37
|
|
25
38
|
@mi_type.setter
|
26
39
|
def mi_type(self, mi_type: str):
|
27
|
-
assert mi_type in
|
40
|
+
assert mi_type in MIs._fields, f"Invalid MI type ({MIs._fields})"
|
28
41
|
self._mi_type = mi_type
|
29
|
-
self.prophet.mi_type = mi_type
|
30
|
-
self.lstm.mi_type = mi_type
|
31
42
|
|
32
|
-
def get(self, refresh=False) ->
|
43
|
+
def get(self, refresh=False) -> MICompileData:
|
33
44
|
print(f"{self.mi_type}의 compiling을 시작합니다.")
|
34
45
|
redis_name = self.mi_type + '_mi_compile'
|
35
46
|
print(
|
36
47
|
f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time / 3600}h")
|
37
48
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
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()
|
49
|
+
def fetch_mi_compile_data() -> MICompileData:
|
50
|
+
prophet = tsa.MIProphet(self.mi_type)
|
51
|
+
lstm = tsa.MILSTM(self.mi_type)
|
44
52
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
data = MICompileData(
|
54
|
+
mi_type=self.mi_type,
|
55
|
+
prophet_data=prophet.generate_data(refresh=refresh),
|
56
|
+
lstm_grade=lstm.get_final_predictions(refresh=refresh)[1],
|
57
|
+
)
|
58
|
+
data.is_lstm_up = lstm.is_lstm_up()
|
59
|
+
data.is_prophet_up = prophet.is_prophet_up(refresh=False)
|
60
|
+
data.lstm_html = lstm.export(refresh=False)
|
61
|
+
data.prophet_html = prophet.export()
|
62
|
+
return data
|
52
63
|
|
53
|
-
|
54
|
-
return
|
64
|
+
mi_compile_data = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_mi_compile_data, timer=expire_time)
|
65
|
+
return mi_compile_data
|
55
66
|
|
56
67
|
@staticmethod
|
57
68
|
def analyser_lstm_all_mi(refresh: bool):
|
58
|
-
mi_lstm = tsa.MILSTM('
|
69
|
+
mi_lstm = tsa.MILSTM('WTI')
|
59
70
|
print(f"*** LSTM prediction redis cashing Market Index items ***")
|
60
|
-
for mi_type in
|
71
|
+
for mi_type in MIs._fields:
|
61
72
|
mi_lstm.mi_type = mi_type
|
62
73
|
print(f"{mi_lstm.mi_type}")
|
63
74
|
mi_lstm.initializing()
|
64
75
|
mi_lstm.get_final_predictions(refresh=refresh, num=5)
|
65
76
|
|
66
77
|
|
78
|
+
@dataclass
|
79
|
+
class CorpCompileData:
|
80
|
+
code: str
|
81
|
+
name: str
|
82
|
+
|
83
|
+
red_data: eval.RedData
|
84
|
+
mil_data: eval.MilData
|
85
|
+
|
86
|
+
prophet_data: tsa.ProphetData
|
87
|
+
lstm_grade: tsa.LSTMGrade
|
88
|
+
|
89
|
+
is_lstm_up: bool = False
|
90
|
+
is_prophet_up: bool = False
|
91
|
+
|
92
|
+
lstm_html: str = ''
|
93
|
+
prophet_html: str = ''
|
94
|
+
|
95
|
+
|
67
96
|
class CorpCompile:
|
68
97
|
def __init__(self, code: str, expect_earn=0.06):
|
69
98
|
assert tools.is_6digit(code), f'Invalid value : {code}'
|
70
99
|
self._code = code
|
71
|
-
self.
|
72
|
-
self.red = eval.Red(code, expect_earn)
|
73
|
-
self.mil = eval.Mil(code)
|
74
|
-
self.prophet = tsa.CorpProphet(code)
|
100
|
+
self.expect_earn = expect_earn
|
75
101
|
|
76
102
|
@property
|
77
103
|
def code(self) -> str:
|
@@ -82,38 +108,34 @@ class CorpCompile:
|
|
82
108
|
assert tools.is_6digit(code), f'Invalid value : {code}'
|
83
109
|
mylogger.info(f'change code : {self.code} -> {code}')
|
84
110
|
self._code = code
|
85
|
-
self.name = mymongo.Corps.get_name(code)
|
86
|
-
self.red.code = code
|
87
|
-
self.mil.code = code
|
88
|
-
self.prophet.code = code
|
89
111
|
|
90
112
|
def get(self, refresh=False) -> dict:
|
91
|
-
|
92
|
-
print(f"{self.code}/{self.name}의 compiling을 시작합니다.")
|
113
|
+
print(f"{self.code}의 compiling을 시작합니다.")
|
93
114
|
redis_name = self.code + '_corp_compile'
|
94
115
|
print(
|
95
116
|
f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time/3600}h")
|
96
117
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
118
|
+
def fetch_corp_compile_data() -> CorpCompileData:
|
119
|
+
prophet = tsa.CorpProphet(self.code)
|
120
|
+
lstm = tsa.CorpLSTM(self.code)
|
121
|
+
|
122
|
+
data = CorpCompileData(
|
123
|
+
code=self.code,
|
124
|
+
name=myredis.Corps(self.code,'c101').get_name(data_from='mongo'),
|
125
|
+
red_data=eval.Red(self.code, self.expect_earn).get(refresh=refresh, verbose=False),
|
126
|
+
mil_data=eval.Mil(self.code).get(refresh=refresh, verbose=False),
|
127
|
+
prophet_data=prophet.generate_data(refresh=refresh),
|
128
|
+
lstm_grade=lstm.get_final_predictions(refresh=refresh)[1],
|
129
|
+
)
|
103
130
|
|
104
|
-
|
105
|
-
|
131
|
+
data.is_lstm_up = lstm.is_lstm_up()
|
132
|
+
data.is_prophet_up = prophet.is_prophet_up(refresh=False)
|
133
|
+
data.lstm_html = lstm.export(refresh=False)
|
134
|
+
data.prophet_html = prophet.export()
|
135
|
+
return data
|
106
136
|
|
107
|
-
|
108
|
-
|
109
|
-
'red_score': red_score,
|
110
|
-
'이익지표': mil_data.이익지표,
|
111
|
-
'주주수익률': mil_data.주주수익률,
|
112
|
-
'trading_action': trading_action,
|
113
|
-
'prophet_score': prophet_score,
|
114
|
-
}
|
115
|
-
data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_corp_compile, timer=expire_time)
|
116
|
-
return data_dict
|
137
|
+
corp_compile_data = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_corp_compile_data, timer=expire_time)
|
138
|
+
return corp_compile_data
|
117
139
|
|
118
140
|
@staticmethod
|
119
141
|
def red_ranking(expect_earn: float = 0.06, refresh=False) -> OrderedDict:
|
@@ -157,24 +179,24 @@ class CorpCompile:
|
|
157
179
|
print(
|
158
180
|
f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time/3600}h")
|
159
181
|
|
160
|
-
def
|
182
|
+
def fetch_prophet_ranking() -> dict:
|
161
183
|
data = {}
|
162
|
-
c =
|
184
|
+
c = tsa.CorpProphet('005930')
|
163
185
|
for code in myredis.Corps.list_all_codes():
|
164
186
|
try:
|
165
187
|
c.code = code
|
166
188
|
except ValueError:
|
167
189
|
mylogger.error(f'prophet ranking error : {code}')
|
168
190
|
continue
|
169
|
-
|
170
|
-
print(f'{code} compiled : {
|
171
|
-
data[code] =
|
191
|
+
score= c.generate_data(refresh=refresh).score
|
192
|
+
print(f'{code} compiled : {score}')
|
193
|
+
data[code] = score
|
172
194
|
return data
|
173
195
|
|
174
|
-
data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh,
|
196
|
+
data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_prophet_ranking, timer=expire_time)
|
175
197
|
|
176
198
|
# prophet_score를 기준으로 정렬
|
177
|
-
ranking = OrderedDict(sorted(data_dict.items(), key=lambda x: x[1]
|
199
|
+
ranking = OrderedDict(sorted(data_dict.items(), key=lambda x: x[1], reverse=True))
|
178
200
|
|
179
201
|
if top == 'all':
|
180
202
|
return ranking
|
@@ -193,7 +215,4 @@ class CorpCompile:
|
|
193
215
|
for i, (code, _) in enumerate(ranking_topn.items()):
|
194
216
|
corp_lstm.code = code
|
195
217
|
print(f"{i + 1}. {corp_lstm.code}/{corp_lstm.name}")
|
196
|
-
corp_lstm.initializing()
|
197
218
|
corp_lstm.get_final_predictions(refresh=refresh, num=5)
|
198
|
-
|
199
|
-
|
@@ -15,6 +15,28 @@ expire_time = tools.to_int(os.getenv('DEFAULT_EXPIRE_TIME_H', 48)) * 3600
|
|
15
15
|
|
16
16
|
@dataclass()
|
17
17
|
class BlueData:
|
18
|
+
"""
|
19
|
+
기업의 주요 안정성 지표와 관련된 데이터를 저장하는 데이터 클래스.
|
20
|
+
|
21
|
+
이 클래스는 기업의 유동성, 부채 비율, 자산 회전율 등을 포함하며,
|
22
|
+
이를 활용하여 기업의 안정성을 평가할 수 있습니다.
|
23
|
+
|
24
|
+
속성:
|
25
|
+
code (str): 기업의 종목 코드 (6자리 숫자 문자열).
|
26
|
+
name (str): 기업명.
|
27
|
+
유동비율 (float): 유동 자산 대비 유동 부채 비율.
|
28
|
+
이자보상배율_r (float): 최근 이자보상배율 값.
|
29
|
+
이자보상배율_dict (dict): 이자보상배율 데이터.
|
30
|
+
순운전자본회전율_r (float): 최근 순운전자본회전율 값.
|
31
|
+
순운전자본회전율_dict (dict): 순운전자본회전율 데이터.
|
32
|
+
재고자산회전율_r (float): 최근 재고자산회전율 값.
|
33
|
+
재고자산회전율_dict (dict): 재고자산회전율 데이터.
|
34
|
+
재고자산회전율_c106 (dict): C106 기준 재고자산회전율 데이터.
|
35
|
+
순부채비율_r (float): 최근 순부채비율 값.
|
36
|
+
순부채비율_dict (dict): 순부채비율 데이터.
|
37
|
+
score (list): 평가 점수.
|
38
|
+
date (list): 데이터와 관련된 날짜 목록.
|
39
|
+
"""
|
18
40
|
code: str
|
19
41
|
name: str
|
20
42
|
|
@@ -38,6 +60,20 @@ class BlueData:
|
|
38
60
|
|
39
61
|
|
40
62
|
class Blue:
|
63
|
+
"""
|
64
|
+
기업의 안정성 지표를 분석하고 계산하는 클래스.
|
65
|
+
|
66
|
+
이 클래스는 주어진 기업 코드에 대해 주요 안정성 지표(예: 유동비율, 이자보상배율 등)를 수집하고,
|
67
|
+
이를 기반으로 기업의 안정성을 평가합니다. Redis 캐시를 활용하여 계산된 데이터를 저장하고
|
68
|
+
재사용할 수 있습니다.
|
69
|
+
|
70
|
+
속성:
|
71
|
+
c101 (myredis.C101): 기업 정보 및 최근 데이터 접근 객체.
|
72
|
+
c103 (myredis.C103): 재무 상태표 데이터 접근 객체.
|
73
|
+
c104 (myredis.C104): 투자 지표 데이터 접근 객체.
|
74
|
+
name (str): 기업명.
|
75
|
+
_code (str): 기업 종목 코드.
|
76
|
+
"""
|
41
77
|
def __init__(self, code: str):
|
42
78
|
assert tools.is_6digit(code), f'Invalid value : {code}'
|
43
79
|
mylogger.debug(f"Blue : 종목코드 ({code})")
|
@@ -69,10 +105,22 @@ class Blue:
|
|
69
105
|
self._code = code
|
70
106
|
|
71
107
|
def _calc유동비율(self, pop_count: int, refresh: bool) -> Tuple[str, float]:
|
72
|
-
"""
|
108
|
+
"""
|
109
|
+
기업의 유동비율을 계산합니다.
|
110
|
+
|
111
|
+
유동비율 데이터가 유효하지 않거나 100 이하일 경우,
|
112
|
+
유동자산과 유동부채를 기반으로 계산을 수행합니다.
|
113
|
+
|
114
|
+
매개변수:
|
115
|
+
pop_count (int): 데이터 검색 시 사용할 값의 개수.
|
116
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
117
|
+
|
118
|
+
반환값:
|
119
|
+
Tuple[str, float]: 날짜와 계산된 유동비율.
|
73
120
|
|
74
|
-
|
75
|
-
|
121
|
+
로그:
|
122
|
+
- 유동비율 계산 과정과 결과를 출력합니다.
|
123
|
+
- 계산 중 유효하지 않은 데이터가 있으면 경고를 출력합니다.
|
76
124
|
"""
|
77
125
|
mylogger.info(f'In the calc유동비율... refresh : {refresh}')
|
78
126
|
self.c104.page = 'c104q'
|
@@ -111,6 +159,17 @@ class Blue:
|
|
111
159
|
return [0 ,]
|
112
160
|
|
113
161
|
def _generate_data(self, refresh: bool) -> BlueData:
|
162
|
+
"""
|
163
|
+
BlueData 형식의 데이터를 생성합니다.
|
164
|
+
|
165
|
+
각종 안정성 지표를 계산하고 데이터를 정리하여 BlueData 객체로 반환합니다.
|
166
|
+
|
167
|
+
매개변수:
|
168
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
169
|
+
|
170
|
+
반환값:
|
171
|
+
BlueData: 계산된 안정성 지표 데이터.
|
172
|
+
"""
|
114
173
|
d1, 유동비율 = self._calc유동비율(pop_count=3, refresh=refresh)
|
115
174
|
mylogger.info(f'유동비율 {유동비율} / [{d1}]')
|
116
175
|
|
@@ -171,9 +230,20 @@ class Blue:
|
|
171
230
|
|
172
231
|
def get(self, refresh = False, verbose = True) -> BlueData:
|
173
232
|
"""
|
174
|
-
BlueData
|
175
|
-
|
176
|
-
|
233
|
+
BlueData 객체를 Redis 캐시에서 가져오거나 새로 생성하여 반환합니다.
|
234
|
+
|
235
|
+
캐시에서 데이터를 검색하고, 없을 경우 `_generate_data`를 호출하여 데이터를 생성합니다.
|
236
|
+
생성된 데이터는 Redis 캐시에 저장되어 재사용됩니다.
|
237
|
+
|
238
|
+
매개변수:
|
239
|
+
refresh (bool): 캐시를 무시하고 새로 데이터를 계산할지 여부. 기본값은 False.
|
240
|
+
verbose (bool): 실행 중 상세 정보를 출력할지 여부. 기본값은 True.
|
241
|
+
|
242
|
+
반환값:
|
243
|
+
BlueData: Redis 캐시에서 가져오거나 새로 생성된 BlueData 객체.
|
244
|
+
|
245
|
+
로그:
|
246
|
+
- 캐시 검색 상태와 새로 생성된 데이터를 출력합니다.
|
177
247
|
"""
|
178
248
|
redis_name = f"{self.code}_blue"
|
179
249
|
mylogger.info(f"{self} BlueData를 레디스캐시에서 가져오거나 새로 생성합니다.. refresh : {refresh}")
|
@@ -181,7 +251,6 @@ class Blue:
|
|
181
251
|
print(f"{self} redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time /3600}h")
|
182
252
|
|
183
253
|
def fetch_generate_data(refresh_in: bool) -> dict:
|
184
|
-
return
|
254
|
+
return self._generate_data(refresh_in) # type: ignore
|
185
255
|
|
186
|
-
return
|
187
|
-
(**myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_generate_data, refresh, timer=expire_time))
|
256
|
+
return myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_generate_data, refresh, timer=expire_time)
|
@@ -9,22 +9,34 @@ mylogger = setup_logger(__name__,'WARNING')
|
|
9
9
|
|
10
10
|
|
11
11
|
class Tools:
|
12
|
+
"""
|
13
|
+
재무 데이터 분석 및 계산에 필요한 유틸리티 메서드를 제공하는 클래스.
|
14
|
+
|
15
|
+
이 클래스는 주어진 재무 데이터를 기반으로 다양한 계산을 수행하며,
|
16
|
+
로그를 통해 계산 과정 및 결과를 디버깅할 수 있도록 지원합니다.
|
17
|
+
|
18
|
+
주요 기능:
|
19
|
+
- Sigmoid 및 로그 점수 계산.
|
20
|
+
- 두 값 간의 괴리율(Deviation) 계산.
|
21
|
+
- 유효하지 않은 값(NaN, None 등) 필터링.
|
22
|
+
- 당기순이익, 유동자산, 유동부채 계산 등.
|
23
|
+
"""
|
12
24
|
@staticmethod
|
13
25
|
def sigmoid_score(deviation, a=1.0, b=2.0):
|
14
|
-
"""
|
15
|
-
|
26
|
+
""""
|
27
|
+
주어진 괴리율(Deviation)에 대해 Sigmoid 함수를 적용하여 점수를 계산합니다.
|
16
28
|
|
17
|
-
|
18
|
-
|
19
|
-
|
29
|
+
이 함수는 Sigmoid 함수에 로그 변환된 괴리율을 입력으로 사용하며,
|
30
|
+
결과를 0에서 100 사이의 점수로 변환합니다. `a`와 `b` 매개변수를 사용하여
|
31
|
+
Sigmoid 곡선의 기울기와 x-축 오프셋을 조정할 수 있습니다.
|
20
32
|
|
21
|
-
|
22
|
-
deviation (float):
|
23
|
-
a (float):
|
24
|
-
b (float):
|
33
|
+
매개변수:
|
34
|
+
deviation (float): 계산할 괴리율 값 (0 이상의 값이어야 함).
|
35
|
+
a (float): Sigmoid 곡선의 기울기 조정값. 기본값은 1.0.
|
36
|
+
b (float): Sigmoid 곡선의 x-축 오프셋. 기본값은 2.0.
|
25
37
|
|
26
|
-
|
27
|
-
float:
|
38
|
+
반환값:
|
39
|
+
float: Sigmoid 함수로 변환된 0~100 사이의 점수.
|
28
40
|
"""
|
29
41
|
# 예: x = log10(deviation + 1)
|
30
42
|
x = math.log10(deviation + 1)
|
@@ -34,40 +46,33 @@ class Tools:
|
|
34
46
|
@staticmethod
|
35
47
|
def log_score(deviation):
|
36
48
|
"""
|
37
|
-
|
49
|
+
주어진 괴리율(Deviation)에 대해 로그 점수를 계산합니다.
|
38
50
|
|
39
|
-
|
40
|
-
|
41
|
-
to scale the resulting logarithmic score.
|
51
|
+
괴리율 값에 1을 더한 뒤, 로그 변환(Base-10)을 수행하고
|
52
|
+
결과를 상수(33)로 곱하여 점수를 계산합니다.
|
42
53
|
|
43
|
-
|
44
|
-
|
45
|
-
logarithmic score for. Should be a non-negative number.
|
54
|
+
매개변수:
|
55
|
+
deviation (float): 계산할 괴리율 값.
|
46
56
|
|
47
|
-
|
48
|
-
|
57
|
+
반환값:
|
58
|
+
float: 계산된 로그 점수.
|
49
59
|
"""
|
50
60
|
return math.log10(deviation + 1) * 33
|
51
61
|
|
52
62
|
@staticmethod
|
53
63
|
def cal_deviation(v1: float, v2: float) -> float:
|
54
64
|
"""
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
v2 (float): The value to compare against the reference.
|
67
|
-
|
68
|
-
Returns:
|
69
|
-
float: The computed percentage deviation. Returns NaN if the reference
|
70
|
-
value (v1) is zero.
|
65
|
+
두 값 간의 퍼센트 괴리율(Deviation)을 계산합니다.
|
66
|
+
|
67
|
+
주어진 두 값 간의 상대적 차이를 백분율로 반환합니다.
|
68
|
+
기준값(v1)이 0인 경우, 계산은 NaN을 반환합니다.
|
69
|
+
|
70
|
+
매개변수:
|
71
|
+
v1 (float): 기준값.
|
72
|
+
v2 (float): 비교할 값.
|
73
|
+
|
74
|
+
반환값:
|
75
|
+
float: 두 값 간의 퍼센트 괴리율. 기준값이 0인 경우 NaN.
|
71
76
|
"""
|
72
77
|
try:
|
73
78
|
deviation = abs((v1 - v2) / v1) * 100
|
@@ -78,50 +83,33 @@ class Tools:
|
|
78
83
|
@staticmethod
|
79
84
|
def date_set(*args) -> list:
|
80
85
|
"""
|
81
|
-
|
86
|
+
주어진 값들에서 유효하지 않은 값을 제거하고 중복 없이 리스트로 반환합니다.
|
82
87
|
|
83
|
-
|
88
|
+
NaN, None, 빈 문자열 등 유효하지 않은 값을 필터링한 뒤,
|
89
|
+
고유한 값만 포함하는 리스트를 생성합니다.
|
84
90
|
|
85
|
-
|
86
|
-
|
91
|
+
매개변수:
|
92
|
+
*args: 필터링할 값들.
|
87
93
|
|
88
|
-
|
89
|
-
|
90
|
-
returned as a list.
|
91
|
-
|
92
|
-
Args:
|
93
|
-
*args: Arbitrary positional arguments to be filtered.
|
94
|
-
|
95
|
-
Returns:
|
96
|
-
list: A list of unique values after filtering out invalid entries.
|
94
|
+
반환값:
|
95
|
+
list: 유효한 값만 포함하는 고유 리스트.
|
97
96
|
"""
|
98
97
|
return [i for i in {*args} if i != "" and i is not math.nan and i is not None]
|
99
98
|
|
100
99
|
@staticmethod
|
101
100
|
def calc당기순이익(c103: myredis.C103, refresh: bool) -> Tuple[str, float]:
|
102
101
|
"""
|
103
|
-
|
104
|
-
|
105
|
-
일반적인 경우로는 직전 지배주주지분 당기순이익을 찾아서 반환한다.
|
106
|
-
|
107
|
-
금융기관의 경우는 지배당기순이익이 없기 때문에 계산을 통해서 간접적으로 구한다.
|
102
|
+
지배주주지분 당기순이익을 계산하여 반환합니다.
|
108
103
|
|
109
|
-
|
110
|
-
|
111
|
-
the `myredis.C103` class. It handles missing or 'Not-a-Number' conditions by
|
112
|
-
manually calculating from quarterly and annual financial figures. Logs the process
|
113
|
-
at various stages for debugging and auditing.
|
104
|
+
기본적으로 재무 데이터에서 지배주주지분 당기순이익을 검색하며,
|
105
|
+
데이터가 없거나 유효하지 않은 경우 간접적으로 계산합니다.
|
114
106
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
refresh (bool): A flag to determine whether or not to refresh the data
|
119
|
-
while accessing or computing financial values.
|
107
|
+
매개변수:
|
108
|
+
c103 (myredis.C103): 재무 데이터에 접근하기 위한 객체.
|
109
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
120
110
|
|
121
|
-
|
122
|
-
|
123
|
-
the calculated or retrieved value, and the second item is the calculated
|
124
|
-
or retrieved "지배당기순이익" (Controlling Comprehensive Income).
|
111
|
+
반환값:
|
112
|
+
Tuple[str, float]: 날짜와 계산된 지배주주지분 당기순이익.
|
125
113
|
"""
|
126
114
|
name = myredis.Corps(c103.code, 'c101').get_name(refresh=refresh)
|
127
115
|
|
@@ -156,35 +144,17 @@ class Tools:
|
|
156
144
|
@staticmethod
|
157
145
|
def calc유동자산(c103: myredis.C103, refresh: bool) -> Tuple[str, float]:
|
158
146
|
"""
|
159
|
-
|
147
|
+
기업의 유동자산을 계산하여 반환합니다.
|
160
148
|
|
161
|
-
|
149
|
+
최근 4분기의 데이터를 기반으로 유동자산을 계산하며,
|
150
|
+
데이터가 없거나 유효하지 않을 경우 간접적으로 계산합니다.
|
162
151
|
|
163
|
-
|
152
|
+
매개변수:
|
153
|
+
c103 (myredis.C103): 재무 데이터에 접근하기 위한 객체.
|
154
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
164
155
|
|
165
|
-
|
166
|
-
|
167
|
-
For a specified company, the function calculates the recent 4-quarter
|
168
|
-
sum of current assets if available. If the data is not available or
|
169
|
-
contains invalid values, it attempts to calculate the current assets
|
170
|
-
manually using financial asset data such as cash equivalents, trading
|
171
|
-
securities, available-for-sale securities, and held-to-maturity securities.
|
172
|
-
|
173
|
-
Logs relevant information and warnings during the calculation process,
|
174
|
-
including any cases where data is unavailable or a manual calculation
|
175
|
-
is required.
|
176
|
-
|
177
|
-
Parameters:
|
178
|
-
c103 (myredis.C103): The instance representing financial data of a
|
179
|
-
specific company. This includes methods to extract and calculate
|
180
|
-
various data points.
|
181
|
-
refresh (bool): Indicator flag to determine whether to refresh the
|
182
|
-
underlying data before performing calculations.
|
183
|
-
|
184
|
-
Returns:
|
185
|
-
Tuple[str, float]: A tuple containing the date associated with the
|
186
|
-
financial data and the calculated or retrieved value of current
|
187
|
-
assets. If dates are not available, the date field may be empty.
|
156
|
+
반환값:
|
157
|
+
Tuple[str, float]: 날짜와 계산된 유동자산.
|
188
158
|
"""
|
189
159
|
|
190
160
|
name = myredis.Corps(c103.code, 'c101').get_name(refresh=refresh)
|
@@ -220,25 +190,17 @@ class Tools:
|
|
220
190
|
@staticmethod
|
221
191
|
def calc유동부채(c103: myredis.C103, refresh: bool) -> Tuple[str, float]:
|
222
192
|
"""
|
223
|
-
|
224
|
-
|
225
|
-
일반적인 경우로 유동부채를 찾아서 반환한다.
|
226
|
-
|
227
|
-
금융기관의 경우는 간접적으로 계산한다.
|
228
|
-
|
229
|
-
Calculate '유동부채' (Current Liabilities) based on financial data of a specific entity.
|
193
|
+
기업의 유동부채를 계산하여 반환합니다.
|
230
194
|
|
231
|
-
|
232
|
-
|
233
|
-
It includes logging for intermediate steps and supports handling missing values by logging
|
234
|
-
warnings and attempting a composed manual computation using alternative financial terms.
|
195
|
+
최근 4분기의 데이터를 기반으로 유동부채를 계산하며,
|
196
|
+
데이터가 없거나 유효하지 않을 경우 간접적으로 계산합니다.
|
235
197
|
|
236
|
-
|
237
|
-
|
238
|
-
|
198
|
+
매개변수:
|
199
|
+
c103 (myredis.C103): 재무 데이터에 접근하기 위한 객체.
|
200
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
239
201
|
|
240
|
-
|
241
|
-
|
202
|
+
반환값:
|
203
|
+
Tuple[str, float]: 날짜와 계산된 유동부채.
|
242
204
|
"""
|
243
205
|
|
244
206
|
name = myredis.Corps(c103.code, 'c101').get_name(refresh=refresh)
|