analyser_hj3415 3.2.2__py3-none-any.whl → 3.3.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/__init__.py +30 -12
- analyser_hj3415/analyser/compile.py +222 -133
- 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 -1
- analyser_hj3415/analyser/tsa/common.py +33 -0
- analyser_hj3415/analyser/tsa/lstm.py +108 -133
- analyser_hj3415/analyser/tsa/prophet.py +261 -124
- analyser_hj3415/cli.py +12 -9
- {analyser_hj3415-3.2.2.dist-info → analyser_hj3415-3.3.1.dist-info}/METADATA +1 -1
- analyser_hj3415-3.3.1.dist-info/RECORD +23 -0
- analyser_hj3415-3.2.2.dist-info/RECORD +0 -22
- {analyser_hj3415-3.2.2.dist-info → analyser_hj3415-3.3.1.dist-info}/WHEEL +0 -0
- {analyser_hj3415-3.2.2.dist-info → analyser_hj3415-3.3.1.dist-info}/entry_points.txt +0 -0
@@ -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)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import os
|
2
|
-
from dataclasses import dataclass
|
2
|
+
from dataclasses import dataclass
|
3
3
|
|
4
4
|
from utils_hj3415 import tools, setup_logger
|
5
5
|
from db_hj3415 import myredis
|
@@ -13,6 +13,21 @@ expire_time = tools.to_int(os.getenv('DEFAULT_EXPIRE_TIME_H', 48)) * 3600
|
|
13
13
|
|
14
14
|
@dataclass()
|
15
15
|
class GrowthData:
|
16
|
+
"""
|
17
|
+
기업의 성장 데이터를 저장하는 데이터 클래스.
|
18
|
+
|
19
|
+
이 클래스는 기업의 성장 데이터를 관리하며, 매출액 증가율 및 영업이익률 데이터를 포함합니다.
|
20
|
+
또한, 평가 점수와 관련된 날짜 데이터를 관리합니다.
|
21
|
+
|
22
|
+
속성:
|
23
|
+
code (str): 기업의 종목 코드 (6자리 숫자 문자열).
|
24
|
+
name (str): 기업명.
|
25
|
+
매출액증가율_r (float): 최신 매출액 증가율.
|
26
|
+
매출액증가율_dict (dict): 매출액 증가율과 관련된 과거 데이터.
|
27
|
+
영업이익률_c106 (dict): c106 데이터를 기반으로 한 영업이익률 데이터.
|
28
|
+
score (list): 평가 점수.
|
29
|
+
date (list): 성장 데이터와 관련된 날짜 목록.
|
30
|
+
"""
|
16
31
|
code: str
|
17
32
|
name: str
|
18
33
|
|
@@ -26,6 +41,19 @@ class GrowthData:
|
|
26
41
|
|
27
42
|
|
28
43
|
class Growth:
|
44
|
+
"""
|
45
|
+
기업의 성장 데이터를 계산하고 관리하는 클래스.
|
46
|
+
|
47
|
+
이 클래스는 기업의 매출액 증가율, 영업이익률 등과 같은 성장 지표를 계산하며,
|
48
|
+
Redis 캐시를 통해 데이터를 저장하고 재사용할 수 있도록 지원합니다.
|
49
|
+
|
50
|
+
속성:
|
51
|
+
c101 (myredis.C101): 기업 정보와 데이터를 가져오기 위한 객체.
|
52
|
+
c104 (myredis.C104): 매출액 증가율 데이터를 관리하기 위한 객체.
|
53
|
+
c106 (myredis.C106): 영업이익률 데이터를 관리하기 위한 객체.
|
54
|
+
name (str): 기업명.
|
55
|
+
_code (str): 기업 종목 코드.
|
56
|
+
"""
|
29
57
|
def __init__(self, code: str):
|
30
58
|
assert tools.is_6digit(code), f'Invalid value : {code}'
|
31
59
|
mylogger.debug(f"Growth : 종목코드 ({code})")
|
@@ -42,10 +70,27 @@ class Growth:
|
|
42
70
|
|
43
71
|
@property
|
44
72
|
def code(self) -> str:
|
73
|
+
"""
|
74
|
+
현재 기업의 종목 코드를 반환합니다.
|
75
|
+
|
76
|
+
반환값:
|
77
|
+
str: 기업의 종목 코드 (6자리 숫자 문자열).
|
78
|
+
"""
|
45
79
|
return self._code
|
46
80
|
|
47
81
|
@code.setter
|
48
82
|
def code(self, code: str):
|
83
|
+
"""
|
84
|
+
기업의 종목 코드를 변경합니다.
|
85
|
+
|
86
|
+
종목 코드 변경 시 관련된 데이터 객체(c101, c104, c106)의 코드도 함께 변경됩니다.
|
87
|
+
|
88
|
+
매개변수:
|
89
|
+
code (str): 변경할 종목 코드 (6자리 숫자 문자열).
|
90
|
+
|
91
|
+
예외:
|
92
|
+
AssertionError: 종목 코드가 6자리 숫자 문자열이 아닐 경우 발생.
|
93
|
+
"""
|
49
94
|
assert tools.is_6digit(code), f'Invalid value : {code}'
|
50
95
|
mylogger.debug(f"Growth : 종목코드 변경({self.code} -> {code})")
|
51
96
|
|
@@ -60,6 +105,21 @@ class Growth:
|
|
60
105
|
return [0,]
|
61
106
|
|
62
107
|
def _generate_data(self, refresh=False) -> GrowthData:
|
108
|
+
"""
|
109
|
+
성장 데이터를 계산하여 GrowthData 객체를 생성합니다.
|
110
|
+
|
111
|
+
이 함수는 매출액 증가율, 영업이익률 등의 데이터를 계산하고,
|
112
|
+
이를 GrowthData 객체로 정리하여 반환합니다.
|
113
|
+
|
114
|
+
매개변수:
|
115
|
+
refresh (bool, optional): 데이터를 새로고침할지 여부. 기본값은 False.
|
116
|
+
|
117
|
+
반환값:
|
118
|
+
GrowthData: 계산된 성장 데이터를 포함하는 객체.
|
119
|
+
|
120
|
+
예외:
|
121
|
+
ValueError: 날짜 데이터가 없을 경우 기본값으로 빈 날짜 리스트를 설정.
|
122
|
+
"""
|
63
123
|
self.c104.page = 'c104y'
|
64
124
|
_, 매출액증가율_dict = self.c104.find('매출액증가율', remove_yoy=True, refresh=refresh)
|
65
125
|
|
@@ -95,9 +155,20 @@ class Growth:
|
|
95
155
|
|
96
156
|
def get(self, refresh = False, verbose = True) -> GrowthData:
|
97
157
|
"""
|
98
|
-
GrowthData
|
99
|
-
|
100
|
-
|
158
|
+
GrowthData 객체를 Redis 캐시에서 가져오거나 새로 생성하여 반환합니다.
|
159
|
+
|
160
|
+
캐시에서 데이터를 검색하고, 없을 경우 `_generate_data`를 호출하여 데이터를 생성합니다.
|
161
|
+
생성된 데이터는 Redis 캐시에 저장되어 재사용됩니다.
|
162
|
+
|
163
|
+
매개변수:
|
164
|
+
refresh (bool, optional): 캐시 데이터를 무시하고 새로 계산할지 여부. 기본값은 False.
|
165
|
+
verbose (bool, optional): 실행 중 상세 정보를 출력할지 여부. 기본값은 True.
|
166
|
+
|
167
|
+
반환값:
|
168
|
+
GrowthData: Redis 캐시에서 가져오거나 새로 생성된 GrowthData 객체.
|
169
|
+
|
170
|
+
로그:
|
171
|
+
- 캐시 검색 상태와 새로 생성된 데이터를 출력합니다.
|
101
172
|
"""
|
102
173
|
redis_name = f"{self.code}_growth"
|
103
174
|
mylogger.info(f"{self} GrowthData를 레디스캐시에서 가져오거나 새로 생성합니다.. refresh : {refresh}")
|
@@ -105,6 +176,6 @@ class Growth:
|
|
105
176
|
print(f"{self} redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time/3600}h")
|
106
177
|
|
107
178
|
def fetch_generate_data(refresh_in: bool) -> dict:
|
108
|
-
return
|
179
|
+
return self._generate_data(refresh_in) # type: ignore
|
109
180
|
|
110
|
-
return
|
181
|
+
return myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_generate_data, refresh, timer=expire_time)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import os
|
2
|
-
from dataclasses import dataclass
|
2
|
+
from dataclasses import dataclass
|
3
3
|
from typing import Tuple
|
4
4
|
import math
|
5
5
|
|
@@ -15,6 +15,32 @@ expire_time = tools.to_int(os.getenv('DEFAULT_EXPIRE_TIME_H', 48)) * 3600
|
|
15
15
|
|
16
16
|
@dataclass
|
17
17
|
class MilData:
|
18
|
+
"""
|
19
|
+
기업의 주요 재무 데이터를 나타내는 데이터 클래스.
|
20
|
+
|
21
|
+
이 클래스는 기업의 다양한 재무 데이터를 포함하며,
|
22
|
+
이를 통해 투자 수익률, 가치 지표, 현금 흐름 등을 분석할 수 있습니다.
|
23
|
+
|
24
|
+
속성:
|
25
|
+
code (str): 기업의 종목 코드 (6자리 숫자 문자열).
|
26
|
+
name (str): 기업명.
|
27
|
+
시가총액억 (float): 기업의 시가총액 (억 단위).
|
28
|
+
주주수익률 (float): 재무활동 현금흐름을 기반으로 계산된 주주 수익률.
|
29
|
+
재무활동현금흐름 (float): 재무활동으로 인한 현금흐름.
|
30
|
+
이익지표 (float): 기업의 이익지표.
|
31
|
+
영업활동현금흐름 (float): 영업활동으로 인한 현금흐름.
|
32
|
+
지배주주당기순이익 (float): 지배주주에게 귀속된 당기순이익.
|
33
|
+
roic_r (float): ROIC(투하자본이익률).
|
34
|
+
roic_dict (dict): ROIC와 관련된 데이터.
|
35
|
+
roe_r (float): ROE(자기자본이익률).
|
36
|
+
roe_106 (dict): ROE와 관련된 상세 데이터.
|
37
|
+
roa_r (float): ROA(총자산이익률).
|
38
|
+
fcf_dict (dict): FCF(자유 현금 흐름) 관련 데이터.
|
39
|
+
pfcf_dict (dict): PFCF(주가 대비 자유 현금 흐름 비율) 관련 데이터.
|
40
|
+
pcr_dict (dict): PCR(주가 대비 현금 흐름 비율) 관련 데이터.
|
41
|
+
score (list): 계산된 평가 점수.
|
42
|
+
date (list): 재무 데이터와 관련된 날짜 목록.
|
43
|
+
"""
|
18
44
|
code: str
|
19
45
|
name: str
|
20
46
|
|
@@ -44,6 +70,21 @@ class MilData:
|
|
44
70
|
|
45
71
|
|
46
72
|
class Mil:
|
73
|
+
"""
|
74
|
+
기업의 재무 데이터를 분석하고 계산하는 클래스.
|
75
|
+
|
76
|
+
이 클래스는 주어진 종목 코드에 대해 다양한 재무 데이터를 수집하고,
|
77
|
+
이를 기반으로 주요 재무 지표(예: ROIC, ROE, 이익지표 등)를 계산합니다.
|
78
|
+
또한 Redis 캐시를 활용하여 계산된 데이터를 저장하고 재사용할 수 있습니다.
|
79
|
+
|
80
|
+
속성:
|
81
|
+
c101 (myredis.C101): 기업 정보 및 최근 데이터 접근 객체.
|
82
|
+
c103 (myredis.C103): 재무 상태표 데이터 접근 객체.
|
83
|
+
c104 (myredis.C104): 투자 지표 데이터 접근 객체.
|
84
|
+
c106 (myredis.C106): ROE 관련 데이터 접근 객체.
|
85
|
+
name (str): 기업명.
|
86
|
+
_code (str): 기업 종목 코드.
|
87
|
+
"""
|
47
88
|
def __init__(self, code: str):
|
48
89
|
assert tools.is_6digit(code), f'Invalid value : {code}'
|
49
90
|
mylogger.debug(f"Mil : 종목코드 ({code})")
|
@@ -78,8 +119,16 @@ class Mil:
|
|
78
119
|
|
79
120
|
def get_marketcap억(self, refresh: bool) -> float:
|
80
121
|
"""
|
81
|
-
시가총액(
|
82
|
-
|
122
|
+
기업의 시가총액(억 단위)을 반환합니다.
|
123
|
+
|
124
|
+
매개변수:
|
125
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
126
|
+
|
127
|
+
반환값:
|
128
|
+
float: 기업의 시가총액 (억 단위).
|
129
|
+
|
130
|
+
로그:
|
131
|
+
- 계산된 시가총액 정보를 출력합니다.
|
83
132
|
"""
|
84
133
|
c101r = self.c101.get_recent(refresh)
|
85
134
|
시가총액 = tools.to_int(tools.to_float(c101r.get('시가총액', math.nan)) / 100000000)
|
@@ -87,6 +136,19 @@ class Mil:
|
|
87
136
|
return 시가총액
|
88
137
|
|
89
138
|
def _calc주주수익률(self, 시가총액_억: float, refresh: bool) -> Tuple[str, float, float]:
|
139
|
+
"""
|
140
|
+
주주수익률을 계산합니다.
|
141
|
+
|
142
|
+
매개변수:
|
143
|
+
시가총액_억 (float): 기업의 시가총액 (억 단위).
|
144
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
145
|
+
|
146
|
+
반환값:
|
147
|
+
Tuple[str, float, float]: 최근 날짜, 주주수익률, 재무활동 현금흐름.
|
148
|
+
|
149
|
+
예외:
|
150
|
+
ZeroDivisionError: 시가총액이 0일 경우 주주수익률을 계산하지 못합니다.
|
151
|
+
"""
|
90
152
|
self.c103.page = 'c103현금흐름표q'
|
91
153
|
d, 재무활동현금흐름 = self.c103.sum_recent_4q('재무활동으로인한현금흐름', refresh)
|
92
154
|
try:
|
@@ -97,6 +159,19 @@ class Mil:
|
|
97
159
|
return d, 주주수익률, 재무활동현금흐름
|
98
160
|
|
99
161
|
def _calc이익지표(self, 시가총액_억: float, refresh: bool) -> Tuple[str, float, float, float]:
|
162
|
+
"""
|
163
|
+
이익지표를 계산합니다.
|
164
|
+
|
165
|
+
매개변수:
|
166
|
+
시가총액_억 (float): 기업의 시가총액 (억 단위).
|
167
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
168
|
+
|
169
|
+
반환값:
|
170
|
+
Tuple[str, float, float, float]: 최근 날짜, 이익지표, 영업활동 현금흐름, 지배주주 당기순이익.
|
171
|
+
|
172
|
+
예외:
|
173
|
+
ZeroDivisionError: 시가총액이 0일 경우 이익지표를 계산하지 못합니다.
|
174
|
+
"""
|
100
175
|
d1, 지배주주당기순이익 = Tools.calc당기순이익(self.c103, refresh)
|
101
176
|
self.c103.page = 'c103현금흐름표q'
|
102
177
|
d2, 영업활동현금흐름 = self.c103.sum_recent_4q('영업활동으로인한현금흐름', refresh)
|
@@ -113,6 +188,15 @@ class Mil:
|
|
113
188
|
return date , 이익지표, 영업활동현금흐름, 지배주주당기순이익
|
114
189
|
|
115
190
|
def _calc투자수익률(self, refresh: bool) -> tuple:
|
191
|
+
"""
|
192
|
+
ROIC, ROE, ROA 등의 투자 수익률을 계산합니다.
|
193
|
+
|
194
|
+
매개변수:
|
195
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
196
|
+
|
197
|
+
반환값:
|
198
|
+
tuple: 계산된 ROIC, ROE, ROA 및 관련 데이터.
|
199
|
+
"""
|
116
200
|
self.c104.page = 'c104q'
|
117
201
|
self.c106.page = 'c106q'
|
118
202
|
d1, roic_r = self.c104.sum_recent_4q('ROIC', refresh)
|
@@ -131,13 +215,16 @@ class Mil:
|
|
131
215
|
|
132
216
|
def _calcFCF(self, refresh: bool) -> dict:
|
133
217
|
"""
|
134
|
-
FCF
|
135
|
-
|
136
|
-
|
218
|
+
자유 현금 흐름(FCF)을 계산합니다.
|
219
|
+
|
220
|
+
매개변수:
|
221
|
+
refresh (bool): 데이터를 새로고침할지 여부.
|
137
222
|
|
138
|
-
|
139
|
-
|
223
|
+
반환값:
|
224
|
+
dict: 계산된 FCF 딕셔너리. 영업활동 현금흐름 데이터가 없는 경우 빈 딕셔너리를 반환합니다.
|
140
225
|
|
226
|
+
참고:
|
227
|
+
- CAPEX가 없는 업종의 경우, 영업활동 현금흐름을 그대로 사용합니다.
|
141
228
|
"""
|
142
229
|
self.c103.page = 'c103현금흐름표y'
|
143
230
|
_, 영업활동현금흐름_dict = self.c103.find('영업활동으로인한현금흐름', remove_yoy=True, del_unnamed_key=True, refresh=refresh)
|
@@ -172,13 +259,16 @@ class Mil:
|
|
172
259
|
return dict(sorted(fcf_dict.items(), reverse=False))
|
173
260
|
|
174
261
|
def _calcPFCF(self, 시가총액_억: float, fcf_dict: dict) -> dict:
|
175
|
-
"""
|
262
|
+
"""
|
263
|
+
PFCF(Price to Free Cash Flow Ratio)를 계산합니다.
|
176
264
|
|
177
|
-
|
265
|
+
매개변수:
|
266
|
+
시가총액_억 (float): 기업의 시가총액 (억 단위).
|
267
|
+
fcf_dict (dict): 자유 현금 흐름(FCF) 데이터.
|
178
268
|
|
179
|
-
|
180
|
-
|
181
|
-
|
269
|
+
반환값:
|
270
|
+
dict: 계산된 PFCF 딕셔너리.
|
271
|
+
"""
|
182
272
|
if math.isnan(시가총액_억):
|
183
273
|
mylogger.warning(f"{self} - 시가총액이 nan으로 pFCF를 계산할수 없습니다.")
|
184
274
|
return {}
|
@@ -259,9 +349,20 @@ class Mil:
|
|
259
349
|
|
260
350
|
def get(self, refresh = False, verbose = True) -> MilData:
|
261
351
|
"""
|
262
|
-
MilData
|
263
|
-
|
264
|
-
|
352
|
+
MilData 객체를 Redis 캐시에서 가져오거나 새로 생성하여 반환합니다.
|
353
|
+
|
354
|
+
캐시에서 데이터를 검색하고, 없을 경우 `_generate_data`를 호출하여 데이터를 생성합니다.
|
355
|
+
생성된 데이터는 Redis 캐시에 저장되어 재사용됩니다.
|
356
|
+
|
357
|
+
매개변수:
|
358
|
+
refresh (bool): 캐시를 무시하고 새로 데이터를 계산할지 여부. 기본값은 False.
|
359
|
+
verbose (bool): 실행 중 상세 정보를 출력할지 여부. 기본값은 True.
|
360
|
+
|
361
|
+
반환값:
|
362
|
+
MilData: Redis 캐시에서 가져오거나 새로 생성된 MilData 객체.
|
363
|
+
|
364
|
+
로그:
|
365
|
+
- 캐시 검색 상태와 새로 생성된 데이터를 출력합니다.
|
265
366
|
"""
|
266
367
|
redis_name = f"{self.code}_mil"
|
267
368
|
mylogger.info(f"{self} MilData를 레디스캐시에서 가져오거나 새로 생성합니다.. refresh : {refresh}")
|
@@ -269,6 +370,6 @@ class Mil:
|
|
269
370
|
print(f"{self} redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time/3600}h")
|
270
371
|
|
271
372
|
def fetch_generate_data(refresh_in: bool) -> dict:
|
272
|
-
return
|
373
|
+
return self._generate_data(refresh_in) # type: ignore
|
273
374
|
|
274
|
-
return
|
375
|
+
return myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_generate_data, refresh, timer=expire_time)
|