analyser_hj3415 2.5.0__py2.py3-none-any.whl → 2.5.1__py2.py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,182 +1,182 @@
1
- """다양한 문자열 출력 형식에 맞춘 함수들
2
- """
3
- from db_hj3415 import myredis
4
- from analyser_hj3415.analysers import eval
5
- from analyser_hj3415.analysers import score
6
- from utils_hj3415 import utils
7
- import textwrap
8
-
9
- import logging
10
- logger = logging.getLogger(__name__)
11
- formatter = logging.Formatter('%(levelname)s: [%(name)s] %(message)s')
12
- ch = logging.StreamHandler()
13
- ch.setFormatter(formatter)
14
- logger.addHandler(ch)
15
- logger.setLevel(logging.WARNING)
16
-
17
-
18
- class Report:
19
- separate_line = '\n' + ('-' * 65) + '\n'
20
-
21
- def __init__(self, client, code: str):
22
- self.client = client
23
- self.code = code
24
- self.name = myredis.Corps.get_name(code)
25
-
26
- def __str__(self):
27
- return (self.c101() + self.separate_line
28
- + self.red() + self.separate_line
29
- + self.mil() + self.separate_line
30
- + self.blue() + self.separate_line
31
- + self.growth())
32
- # + make_str.c108())
33
-
34
- def c101(self, full=True):
35
- c101 = myredis.C101(self.code).get_recent()
36
- logger.info(c101)
37
-
38
- title = '=' * 35 + f"\t{c101['코드']}\t\t{c101['종목명']}\t\t{c101['업종']}\t" + '=' * 35
39
- intro = textwrap.fill(f"{c101['intro']}", width=70)
40
-
41
- if full:
42
- price = (f"{c101['date']}\t\t"
43
- f"주가: {utils.deco_num(c101['주가'])}원\t\t"
44
- f"52주최고: {utils.deco_num(c101['최고52주'])}원\t"
45
- f"52주최저: {utils.deco_num(c101['최저52주'])}원")
46
- info = (f"PER: {c101['PER']}\t\t"
47
- f"PBR: {c101['PBR']}\t\t\t"
48
- f"배당수익률: {c101['배당수익률']}%\t\t"
49
- f"시가총액: {utils.get_kor_amount(utils.to_int(c101['시가총액']), omit='억')}\n"
50
- f"업종PER: {c101['업종PER']}\t"
51
- f"유통비율: {c101['유통비율']}%\t\t"
52
- f"거래대금: {utils.to_억(c101['거래대금'])}원\t\t"
53
- f"발행주식: {utils.to_만(c101['발행주식'])}주")
54
- else:
55
- price = (f"<< {c101['date']} >>\n"
56
- f"주가: {utils.deco_num(c101['주가'])}원")
57
- info = (f"PER: {c101['PER']}\n"
58
- f"업종PER: {c101['업종PER']}\n"
59
- f"PBR: {c101['PBR']}\n"
60
- f"배당수익률: {c101['배당수익률']}%\n"
61
- f"유통비율: {c101['유통비율']}%\n"
62
- f"발행주식: {utils.to_만(c101['발행주식'])}주\n"
63
- f"시가총액: {utils.get_kor_amount(utils.to_int(c101['시가총액']), omit='억')}")
64
-
65
- return title + '\n' + intro + self.separate_line + price + '\n' + info
66
-
67
- def red(self, full=True) -> str:
68
- red_dict = eval.red(self.code)
69
- 괴리율 = score.red(self.code)
70
- logger.info(red_dict)
71
-
72
- title = f"Red\t괴리율({괴리율}%)\t{red_dict['date']}\n"
73
- if full:
74
- contents = (f"사업가치({utils.deco_num(red_dict['사업가치'])}억) "
75
- f"+ 재산가치({utils.deco_num(red_dict['재산가치'])}억) "
76
- f"- 부채({utils.deco_num(red_dict['부채평가'])}억) "
77
- f"/ 발행주식({utils.to_만(red_dict['발행주식수'])}주) "
78
- f"= {utils.deco_num(red_dict['red_price'])}원")
79
- else:
80
- contents = f"{utils.deco_num(red_dict['red_price'])}원"
81
- return title + contents
82
-
83
- def mil(self, full=True) -> str:
84
- mil_dict = eval.mil(self.code)
85
- p1, p2, p3, p4 = score.mil(self.code)
86
- logger.info(mil_dict)
87
-
88
- title = f"Millenial\tPoint({p1+p2+p3+p4})\t{mil_dict['date']}\n"
89
- if full:
90
- contents = (f"1. 주주수익률({p1}): {mil_dict['주주수익률']} %\n"
91
- f"2. 이익지표({p2}): {mil_dict['이익지표']}\n"
92
- f"3. 투자수익률({p3}): ROIC 4분기합: {mil_dict['투자수익률']['ROIC']}%, "
93
- f"최근 ROE: {mil_dict['투자수익률']['ROE']}%\n"
94
- f"4. 가치지표\n"
95
- f"\tFCF: {mil_dict['가치지표']['FCF']}\n"
96
- f"\tPFCF({p4}) : {mil_dict['가치지표']['PFCF']}\n"
97
- f"\tPCR: {mil_dict['가치지표']['PCR']}")
98
- else:
99
- contents = (f"1. 주주수익률({p1}): {mil_dict['주주수익률']} %\n"
100
- f"2. 이익지표({p2}): {mil_dict['이익지표']}\n"
101
- f"3. 투자수익률({p3}): ROIC 4분기합: {mil_dict['투자수익률']['ROIC']}%, "
102
- f"최근 ROE: {mil_dict['투자수익률']['ROE']}%\n"
103
- f"4. 가치지표\tPFCF({p4}) : {mongo.EvalTools.get_recent(mil_dict['가치지표']['PFCF'])}")
104
- return title + contents
105
-
106
- def blue(self, full=True) -> str:
107
- blue_dict = eval.blue(self.code)
108
- p1, p2, p3, p4, p5 = score.blue(self.code)
109
- logger.info(blue_dict)
110
-
111
- title = f"Blue\tPoint({p1+p2+p3+p4+p5})\t{blue_dict['date']}\n"
112
- if full:
113
- contents = (f"1. 유동비율({p1}): {blue_dict['유동비율']}(100이하 위험)\n"
114
- f"2. 이자보상배율({p2}): {blue_dict['이자보상배율']}(1이하 위험 5이상 양호)\n"
115
- f"3. 순부채비율({p3}): {blue_dict['순부채비율']}(30이상 not good)\n"
116
- f"4. 순운전자본회전율({p4}): {blue_dict['순운전자본회전율']}\n"
117
- f"5. 재고자산회전율({p5}): {blue_dict['재고자산회전율']}")
118
-
119
- else:
120
- contents = ''
121
- return title + contents
122
-
123
- def growth(self, full=True) -> str:
124
- growth_dict = eval.growth(self.code)
125
- p1, p2 = score.growth(self.code)
126
- logger.info(growth_dict)
127
-
128
- title = f"Growth\tPoint({p1 + p2})\t{growth_dict['date']}\n"
129
- if full:
130
- contents = (f"1. 매출액증가율({p1}): {growth_dict['매출액증가율']}\n"
131
- f"2. 영업이익률({p2}): {growth_dict['영업이익률']}")
132
- else:
133
- contents = (f"1. 매출액증가율({p1}): {growth_dict['매출액증가율'][0]}\n"
134
- f"2. 영업이익률({p2}): {growth_dict['영업이익률'].get(self.name)}")
135
- return title + contents
136
-
137
- def for_django(self) -> dict:
138
- """
139
- 장고에서 report 페이지에서 사용될 eval & score data 를 반환
140
-
141
- 장고의 view context는 딕셔너리 형식이기 때문에 딕셔너리 모음으로 반환한다.
142
-
143
- 리턴값
144
- {'blue': {'date': ['2022/12'],
145
- '순부채비율': (-29.57, {'2018/12': -34.82,...'2023/12': -27.54}),
146
- '순운전자본회전율': (1.59, {'2018/12': 12.3,...'2023/12': nan}),
147
- '유동비율': 278.86,
148
- '이자보상배율': (15.7, {'2018/12': 87.29,...'2023/12': nan}),
149
- '재고자산회전율': (1.29, {'2018/12': 9.03,...'2023/12': nan})},
150
- 'blue_s': (0, 0, 0, -1, 0),
151
- 'c101': {'BPS': 50817.0, 'EPS': 8057.0, 'PBR': 1.28, 'PER': 8.08, 'date': '2023.04.14', 'intro': '...',
152
- '거래대금': '1062800000000', '거래량': '16176500', '발행주식': '5969782550', '배당수익률': '2.22', '베타52주': '0.95',
153
- '시가총액': '388632800000000', '업종': '반도체와반도체장비', '업종PER': '8.36', '유통비율': '75.82', '종목명': '삼성전자',
154
- '주가': '65100', '최고52주': '68800', '최저52주': '51800', '코드': '005930'},
155
- 'growth': {'date': ['2022/12'],
156
- '매출액증가율': (-8.23, {'2018/12': 1.75,...'2023/12': -10.5}),
157
- '영업이익률': {'LG디스플레이': '3.61', 'LG전자': '42.38', 'SK하이닉스': '15.26', '삼성전자': '14.35', '에스에프에이': '45.89'}},
158
- 'growth_s': (-2, 1),
159
- 'mil': {'date': ['2022/12'],
160
- '가치지표': {'FCF': {'2018/12': 374754.5,...'2023/12': 24605.8},
161
- 'PCR': {'2021/12': 8.17,...'2022/12': 6.04},
162
- 'PFCF': {'2018/12': 10.37,...'2023/12': 157.94}},
163
- '이익지표': -0.01917,
164
- '주주수익률': 4.99,
165
- '투자수익률': {'ROE': 17.07, 'ROIC': 13.41}},
166
- 'mil_s': (1, 10, 7, 0),
167
- 'red': {'date': ['2022/12'], 'red_price': 264881, '발행주식수': 6792669000.0, '부채평가': 1257599.6,
168
- '사업가치': 13682505.0, '재산가치': 5567563.52},
169
- 'red_s': (53, -75.42)}
170
- """
171
- return {
172
- 'c101': myredis.C101(self.code).get_recent(),
173
- 'red': eval.red(self.code),
174
- 'mil': eval.mil(self.code),
175
- 'blue': eval.blue(self.code),
176
- 'growth': eval.growth(self.code),
177
- 'red_s': score.red(self.code),
178
- 'mil_s': score.mil(self.code),
179
- 'blue_s': score.blue(self.code),
180
- 'growth_s': score.growth(self.code),
181
- }
182
-
1
+ """다양한 문자열 출력 형식에 맞춘 함수들
2
+ """
3
+ from db_hj3415 import myredis
4
+ from analyser_hj3415.analysers import eval
5
+ from analyser_hj3415.analysers import score
6
+ from utils_hj3415 import utils
7
+ import textwrap
8
+
9
+ import logging
10
+ logger = logging.getLogger(__name__)
11
+ formatter = logging.Formatter('%(levelname)s: [%(name)s] %(message)s')
12
+ ch = logging.StreamHandler()
13
+ ch.setFormatter(formatter)
14
+ logger.addHandler(ch)
15
+ logger.setLevel(logging.WARNING)
16
+
17
+
18
+ class Report:
19
+ separate_line = '\n' + ('-' * 65) + '\n'
20
+
21
+ def __init__(self, client, code: str):
22
+ self.client = client
23
+ self.code = code
24
+ self.name = myredis.Corps.get_name(code)
25
+
26
+ def __str__(self):
27
+ return (self.c101() + self.separate_line
28
+ + self.red() + self.separate_line
29
+ + self.mil() + self.separate_line
30
+ + self.blue() + self.separate_line
31
+ + self.growth())
32
+ # + make_str.c108())
33
+
34
+ def c101(self, full=True):
35
+ c101 = myredis.C101(self.code).get_recent()
36
+ logger.info(c101)
37
+
38
+ title = '=' * 35 + f"\t{c101['코드']}\t\t{c101['종목명']}\t\t{c101['업종']}\t" + '=' * 35
39
+ intro = textwrap.fill(f"{c101['intro']}", width=70)
40
+
41
+ if full:
42
+ price = (f"{c101['date']}\t\t"
43
+ f"주가: {utils.deco_num(c101['주가'])}원\t\t"
44
+ f"52주최고: {utils.deco_num(c101['최고52주'])}원\t"
45
+ f"52주최저: {utils.deco_num(c101['최저52주'])}원")
46
+ info = (f"PER: {c101['PER']}\t\t"
47
+ f"PBR: {c101['PBR']}\t\t\t"
48
+ f"배당수익률: {c101['배당수익률']}%\t\t"
49
+ f"시가총액: {utils.get_kor_amount(utils.to_int(c101['시가총액']), omit='억')}\n"
50
+ f"업종PER: {c101['업종PER']}\t"
51
+ f"유통비율: {c101['유통비율']}%\t\t"
52
+ f"거래대금: {utils.to_억(c101['거래대금'])}원\t\t"
53
+ f"발행주식: {utils.to_만(c101['발행주식'])}주")
54
+ else:
55
+ price = (f"<< {c101['date']} >>\n"
56
+ f"주가: {utils.deco_num(c101['주가'])}원")
57
+ info = (f"PER: {c101['PER']}\n"
58
+ f"업종PER: {c101['업종PER']}\n"
59
+ f"PBR: {c101['PBR']}\n"
60
+ f"배당수익률: {c101['배당수익률']}%\n"
61
+ f"유통비율: {c101['유통비율']}%\n"
62
+ f"발행주식: {utils.to_만(c101['발행주식'])}주\n"
63
+ f"시가총액: {utils.get_kor_amount(utils.to_int(c101['시가총액']), omit='억')}")
64
+
65
+ return title + '\n' + intro + self.separate_line + price + '\n' + info
66
+
67
+ def red(self, full=True) -> str:
68
+ red_dict = eval.red(self.code)
69
+ 괴리율 = score.red(self.code)
70
+ logger.info(red_dict)
71
+
72
+ title = f"Red\t괴리율({괴리율}%)\t{red_dict['date']}\n"
73
+ if full:
74
+ contents = (f"사업가치({utils.deco_num(red_dict['사업가치'])}억) "
75
+ f"+ 재산가치({utils.deco_num(red_dict['재산가치'])}억) "
76
+ f"- 부채({utils.deco_num(red_dict['부채평가'])}억) "
77
+ f"/ 발행주식({utils.to_만(red_dict['발행주식수'])}주) "
78
+ f"= {utils.deco_num(red_dict['red_price'])}원")
79
+ else:
80
+ contents = f"{utils.deco_num(red_dict['red_price'])}원"
81
+ return title + contents
82
+
83
+ def mil(self, full=True) -> str:
84
+ mil_dict = eval.mil(self.code)
85
+ p1, p2, p3, p4 = score.mil(self.code)
86
+ logger.info(mil_dict)
87
+
88
+ title = f"Millenial\tPoint({p1+p2+p3+p4})\t{mil_dict['date']}\n"
89
+ if full:
90
+ contents = (f"1. 주주수익률({p1}): {mil_dict['주주수익률']} %\n"
91
+ f"2. 이익지표({p2}): {mil_dict['이익지표']}\n"
92
+ f"3. 투자수익률({p3}): ROIC 4분기합: {mil_dict['투자수익률']['ROIC']}%, "
93
+ f"최근 ROE: {mil_dict['투자수익률']['ROE']}%\n"
94
+ f"4. 가치지표\n"
95
+ f"\tFCF: {mil_dict['가치지표']['FCF']}\n"
96
+ f"\tPFCF({p4}) : {mil_dict['가치지표']['PFCF']}\n"
97
+ f"\tPCR: {mil_dict['가치지표']['PCR']}")
98
+ else:
99
+ contents = (f"1. 주주수익률({p1}): {mil_dict['주주수익률']} %\n"
100
+ f"2. 이익지표({p2}): {mil_dict['이익지표']}\n"
101
+ f"3. 투자수익률({p3}): ROIC 4분기합: {mil_dict['투자수익률']['ROIC']}%, "
102
+ f"최근 ROE: {mil_dict['투자수익률']['ROE']}%\n"
103
+ f"4. 가치지표\tPFCF({p4}) : {mongo.EvalTools.get_recent(mil_dict['가치지표']['PFCF'])}")
104
+ return title + contents
105
+
106
+ def blue(self, full=True) -> str:
107
+ blue_dict = eval.blue(self.code)
108
+ p1, p2, p3, p4, p5 = score.blue(self.code)
109
+ logger.info(blue_dict)
110
+
111
+ title = f"Blue\tPoint({p1+p2+p3+p4+p5})\t{blue_dict['date']}\n"
112
+ if full:
113
+ contents = (f"1. 유동비율({p1}): {blue_dict['유동비율']}(100이하 위험)\n"
114
+ f"2. 이자보상배율({p2}): {blue_dict['이자보상배율']}(1이하 위험 5이상 양호)\n"
115
+ f"3. 순부채비율({p3}): {blue_dict['순부채비율']}(30이상 not good)\n"
116
+ f"4. 순운전자본회전율({p4}): {blue_dict['순운전자본회전율']}\n"
117
+ f"5. 재고자산회전율({p5}): {blue_dict['재고자산회전율']}")
118
+
119
+ else:
120
+ contents = ''
121
+ return title + contents
122
+
123
+ def growth(self, full=True) -> str:
124
+ growth_dict = eval.growth(self.code)
125
+ p1, p2 = score.growth(self.code)
126
+ logger.info(growth_dict)
127
+
128
+ title = f"Growth\tPoint({p1 + p2})\t{growth_dict['date']}\n"
129
+ if full:
130
+ contents = (f"1. 매출액증가율({p1}): {growth_dict['매출액증가율']}\n"
131
+ f"2. 영업이익률({p2}): {growth_dict['영업이익률']}")
132
+ else:
133
+ contents = (f"1. 매출액증가율({p1}): {growth_dict['매출액증가율'][0]}\n"
134
+ f"2. 영업이익률({p2}): {growth_dict['영업이익률'].get(self.name)}")
135
+ return title + contents
136
+
137
+ def for_django(self) -> dict:
138
+ """
139
+ 장고에서 report 페이지에서 사용될 eval & score data 를 반환
140
+
141
+ 장고의 view context는 딕셔너리 형식이기 때문에 딕셔너리 모음으로 반환한다.
142
+
143
+ 리턴값
144
+ {'blue': {'date': ['2022/12'],
145
+ '순부채비율': (-29.57, {'2018/12': -34.82,...'2023/12': -27.54}),
146
+ '순운전자본회전율': (1.59, {'2018/12': 12.3,...'2023/12': nan}),
147
+ '유동비율': 278.86,
148
+ '이자보상배율': (15.7, {'2018/12': 87.29,...'2023/12': nan}),
149
+ '재고자산회전율': (1.29, {'2018/12': 9.03,...'2023/12': nan})},
150
+ 'blue_s': (0, 0, 0, -1, 0),
151
+ 'c101': {'BPS': 50817.0, 'EPS': 8057.0, 'PBR': 1.28, 'PER': 8.08, 'date': '2023.04.14', 'intro': '...',
152
+ '거래대금': '1062800000000', '거래량': '16176500', '발행주식': '5969782550', '배당수익률': '2.22', '베타52주': '0.95',
153
+ '시가총액': '388632800000000', '업종': '반도체와반도체장비', '업종PER': '8.36', '유통비율': '75.82', '종목명': '삼성전자',
154
+ '주가': '65100', '최고52주': '68800', '최저52주': '51800', '코드': '005930'},
155
+ 'growth': {'date': ['2022/12'],
156
+ '매출액증가율': (-8.23, {'2018/12': 1.75,...'2023/12': -10.5}),
157
+ '영업이익률': {'LG디스플레이': '3.61', 'LG전자': '42.38', 'SK하이닉스': '15.26', '삼성전자': '14.35', '에스에프에이': '45.89'}},
158
+ 'growth_s': (-2, 1),
159
+ 'mil': {'date': ['2022/12'],
160
+ '가치지표': {'FCF': {'2018/12': 374754.5,...'2023/12': 24605.8},
161
+ 'PCR': {'2021/12': 8.17,...'2022/12': 6.04},
162
+ 'PFCF': {'2018/12': 10.37,...'2023/12': 157.94}},
163
+ '이익지표': -0.01917,
164
+ '주주수익률': 4.99,
165
+ '투자수익률': {'ROE': 17.07, 'ROIC': 13.41}},
166
+ 'mil_s': (1, 10, 7, 0),
167
+ 'red': {'date': ['2022/12'], 'red_price': 264881, '발행주식수': 6792669000.0, '부채평가': 1257599.6,
168
+ '사업가치': 13682505.0, '재산가치': 5567563.52},
169
+ 'red_s': (53, -75.42)}
170
+ """
171
+ return {
172
+ 'c101': myredis.C101(self.code).get_recent(),
173
+ 'red': eval.red(self.code),
174
+ 'mil': eval.mil(self.code),
175
+ 'blue': eval.blue(self.code),
176
+ 'growth': eval.growth(self.code),
177
+ 'red_s': score.red(self.code),
178
+ 'mil_s': score.mil(self.code),
179
+ 'blue_s': score.blue(self.code),
180
+ 'growth_s': score.growth(self.code),
181
+ }
182
+