analyser_hj3415 2.9.4__py3-none-any.whl → 2.9.6__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/cli.py +10 -0
- analyser_hj3415/tsa.py +65 -10
- {analyser_hj3415-2.9.4.dist-info → analyser_hj3415-2.9.6.dist-info}/METADATA +3 -2
- {analyser_hj3415-2.9.4.dist-info → analyser_hj3415-2.9.6.dist-info}/RECORD +6 -6
- {analyser_hj3415-2.9.4.dist-info → analyser_hj3415-2.9.6.dist-info}/WHEEL +1 -1
- {analyser_hj3415-2.9.4.dist-info → analyser_hj3415-2.9.6.dist-info}/entry_points.txt +0 -0
analyser_hj3415/cli.py
CHANGED
@@ -56,6 +56,11 @@ def analyser_manager():
|
|
56
56
|
caching_parser = lstm_subparser.add_parser('caching', help='lstm 랭킹 책정 및 레디스 저장')
|
57
57
|
caching_parser.add_argument('-r', '--refresh', action='store_true', help='래디스 캐시를 사용하지 않고 강제로 재계산 할지')
|
58
58
|
caching_parser.add_argument('-n', '--noti', action='store_true', help='작업 완료 후 메시지 전송 여부')
|
59
|
+
# red - get 파서
|
60
|
+
lstm_get_parser = lstm_subparser.add_parser('get', help='lstm get 책정 및 레디스 저장')
|
61
|
+
lstm_get_parser.add_argument('code', type=str, help='종목코드')
|
62
|
+
lstm_get_parser.add_argument('-r', '--refresh', action='store_true', help='래디스 캐시를 사용하지 않고 강제로 재계산 할지')
|
63
|
+
lstm_get_parser.add_argument('-n', '--noti', action='store_true', help='작업 완료 후 메시지 전송 여부')
|
59
64
|
|
60
65
|
# red 명령어 서브파서
|
61
66
|
red_parser = type_subparsers.add_parser('red', help='red 타입')
|
@@ -222,6 +227,11 @@ def analyser_manager():
|
|
222
227
|
result = tsa.MyLSTM('005930').caching_based_on_prophet_ranking(refresh=args.refresh)
|
223
228
|
if args.noti:
|
224
229
|
noti.telegram_to('manager', "오늘의 lstm caching을 레디스캐시에 저장했습니다.(유효 24시간)")
|
230
|
+
elif args.command == 'get':
|
231
|
+
assert utils.is_6digit(args.code), "code 인자는 6자리 숫자이어야 합니다."
|
232
|
+
result = tsa.MyLSTM(args.code).get_final_predictions(refresh=args.refresh)
|
233
|
+
if args.noti:
|
234
|
+
noti.telegram_to('manager', f"LSTM 분석을({args.code})를 레디스 캐시에 저장했습니다.(유효 12시간)")
|
225
235
|
elif args.type == 'setting':
|
226
236
|
if args.command == 'set':
|
227
237
|
settings_manager.set_value(args.title, args.value)
|
analyser_hj3415/tsa.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
"""
|
2
2
|
Time Series Analysis
|
3
3
|
"""
|
4
|
+
from pprint import pprint
|
5
|
+
|
4
6
|
import numpy as np
|
5
7
|
import yfinance as yf
|
6
8
|
from datetime import datetime, timedelta
|
@@ -98,6 +100,8 @@ class MyProphet:
|
|
98
100
|
|
99
101
|
# 추가 변수를 정규화
|
100
102
|
df['volume_scaled'] = self.scaler.fit_transform(df[['volume']])
|
103
|
+
tsa_logger.debug('_preprocessing_for_prophet')
|
104
|
+
tsa_logger.debug(df)
|
101
105
|
return df
|
102
106
|
|
103
107
|
def _make_forecast(self) -> pd.DataFrame:
|
@@ -108,12 +112,16 @@ class MyProphet:
|
|
108
112
|
|
109
113
|
# 향후 180일 동안의 주가 예측
|
110
114
|
future = self.model.make_future_dataframe(periods=180)
|
115
|
+
tsa_logger.debug('_make_forecast_future')
|
116
|
+
tsa_logger.debug(future)
|
111
117
|
|
112
118
|
# 미래 데이터에 거래량 추가 (평균 거래량을 사용해 정규화)
|
113
119
|
future_volume = pd.DataFrame({'volume': [self.raw_data['Volume'].mean()] * len(future)})
|
114
120
|
future['volume_scaled'] = self.scaler.transform(future_volume[['volume']])
|
115
121
|
|
116
122
|
forecast = self.model.predict(future)
|
123
|
+
tsa_logger.debug('_make_forecast')
|
124
|
+
tsa_logger.debug(forecast)
|
117
125
|
return forecast
|
118
126
|
|
119
127
|
def get_yhat(self) -> dict:
|
@@ -292,11 +300,14 @@ class MyLSTM:
|
|
292
300
|
four_years_ago = today - timedelta(days=365 * 4)
|
293
301
|
tsa_logger.info(f"start: {four_years_ago.strftime('%Y-%m-%d')}, end: {today.strftime('%Y-%m-%d')}")
|
294
302
|
|
295
|
-
|
303
|
+
df = yf.download(
|
296
304
|
self.code + '.KS',
|
297
305
|
start=four_years_ago.strftime('%Y-%m-%d'),
|
298
306
|
end=today.strftime('%Y-%m-%d')
|
299
307
|
)
|
308
|
+
df.index = df.index.tz_localize(None)
|
309
|
+
tsa_logger.debug(df)
|
310
|
+
return df
|
300
311
|
|
301
312
|
def _preprocessing_for_lstm(self) -> LSTMData:
|
302
313
|
"""
|
@@ -538,17 +549,61 @@ class MyLSTM:
|
|
538
549
|
future_dates, final_future_predictions = self.get_final_predictions(refresh=refresh)
|
539
550
|
final_future_predictions = final_future_predictions.reshape(-1) # 차원을 하나 줄인다.
|
540
551
|
|
541
|
-
#
|
552
|
+
# 데이터 준비
|
553
|
+
self.raw_data = self.raw_data.reset_index()
|
554
|
+
data = self.raw_data[['Date', 'Close']][-120:].reset_index(drop=True)
|
555
|
+
|
556
|
+
# 'Date'와 'Close' 열 추출
|
557
|
+
actual_dates = pd.to_datetime(data['Date'])
|
558
|
+
actual_close = data['Close']
|
559
|
+
|
560
|
+
# 'actual_close'가 Series인지 확인
|
561
|
+
if isinstance(actual_close, pd.DataFrame):
|
562
|
+
actual_close = actual_close.squeeze()
|
563
|
+
|
564
|
+
# 'Close' 열의 데이터 타입 확인
|
565
|
+
actual_close = actual_close.astype(float)
|
566
|
+
|
567
|
+
# 예측 데이터 준비
|
568
|
+
predicted_dates = pd.to_datetime(future_dates)
|
569
|
+
predicted_close = pd.Series(final_future_predictions, index=range(len(final_future_predictions))).astype(float)
|
570
|
+
|
571
|
+
# 그래프 생성
|
542
572
|
fig = go.Figure()
|
543
573
|
|
544
|
-
# 실제 데이터
|
545
|
-
fig.add_trace(go.Scatter(
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
574
|
+
# 실제 데이터 추가
|
575
|
+
fig.add_trace(go.Scatter(
|
576
|
+
x=actual_dates,
|
577
|
+
y=actual_close,
|
578
|
+
mode='markers',
|
579
|
+
name='실제주가'
|
580
|
+
))
|
581
|
+
|
582
|
+
# 예측 데이터 추가
|
583
|
+
fig.add_trace(go.Scatter(
|
584
|
+
x=predicted_dates,
|
585
|
+
y=predicted_close,
|
586
|
+
mode='lines+markers',
|
587
|
+
name='예측치(30일)'
|
588
|
+
))
|
589
|
+
|
590
|
+
# 레이아웃 업데이트
|
591
|
+
fig.update_layout(
|
592
|
+
xaxis_title='일자',
|
593
|
+
yaxis_title='주가(원)',
|
594
|
+
xaxis=dict(
|
595
|
+
tickformat='%Y/%m',
|
596
|
+
),
|
597
|
+
yaxis=dict(
|
598
|
+
tickformat=".0f",
|
599
|
+
),
|
600
|
+
showlegend=True,
|
601
|
+
)
|
602
|
+
|
603
|
+
tsa_logger.debug(f"actual_dates({len(actual_dates)}) - {actual_dates}")
|
604
|
+
tsa_logger.debug(f"actual_close({len(actual_close)} - {actual_close}")
|
605
|
+
tsa_logger.debug(f"predicted_dates({len(future_dates)}) - {future_dates}")
|
606
|
+
tsa_logger.debug(f"predicted_close({len(predicted_close)}) - {predicted_close}")
|
552
607
|
|
553
608
|
fig.update_layout(
|
554
609
|
# title=f'{self.code} {self.name} 주가 예측 그래프(prophet)',
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: analyser_hj3415
|
3
|
-
Version: 2.9.
|
3
|
+
Version: 2.9.6
|
4
4
|
Summary: Stock analyser and database processing programs
|
5
5
|
Requires-Python: >=3.6
|
6
6
|
Description-Content-Type: text/markdown
|
@@ -12,6 +12,7 @@ Requires-Dist: yfinance>=0.2.44
|
|
12
12
|
Requires-Dist: prophet>=1.1.6
|
13
13
|
Requires-Dist: kaleido>=0.2.1
|
14
14
|
Requires-Dist: matplotlib>=3.9.2
|
15
|
+
Requires-Dist: tensorflow>=2.18.0
|
15
16
|
|
16
17
|
### analyser-hj3415
|
17
18
|
|
@@ -1,14 +1,14 @@
|
|
1
1
|
analyser_hj3415/.DS_Store,sha256=S5yjTP1issWmV5kF2CFjGHm5OJHgkuTaZHuxjIwSkfc,6148
|
2
2
|
analyser_hj3415/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
analyser_hj3415/cli.py,sha256=
|
3
|
+
analyser_hj3415/cli.py,sha256=NZ5guApdRCWqpW0f_ECwSpGCccdja011wWsUYkccvbY,13717
|
4
4
|
analyser_hj3415/eval.py,sha256=WWIvB4BebjW9GNGcF8rMd-MLL-lPXUBOH01_FpSq95I,38811
|
5
|
-
analyser_hj3415/tsa.py,sha256=
|
5
|
+
analyser_hj3415/tsa.py,sha256=BsuyLZQcQE_VV7xOlw6_xpRAhwfY5FU_J-jBWTai7lg,26774
|
6
6
|
analyser_hj3415/workroom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
analyser_hj3415/workroom/mysklearn.py,sha256=wJXKz5MqqTzADdG2mqRMMzc_G9RzwYjj5_j4gyOopxQ,2030
|
8
8
|
analyser_hj3415/workroom/mysklearn2.py,sha256=1lIy6EWEQHkOzDS-av8U0zQH6DuCLKWMI73dnJx5KRs,1495
|
9
9
|
analyser_hj3415/workroom/score.py,sha256=P6nHBJYmyhigGtT4qna4BmNtvt4B93b7SKyzdstJK24,17376
|
10
10
|
analyser_hj3415/workroom/trash.py,sha256=zF-W0piqkGr66UP6-iybo9EXh2gO0RP6R1FnIpsGkl8,12262
|
11
|
-
analyser_hj3415-2.9.
|
12
|
-
analyser_hj3415-2.9.
|
13
|
-
analyser_hj3415-2.9.
|
14
|
-
analyser_hj3415-2.9.
|
11
|
+
analyser_hj3415-2.9.6.dist-info/entry_points.txt,sha256=ZfjPnJuH8SzvhE9vftIPMBIofsc65IAWYOhqOC_L5ck,65
|
12
|
+
analyser_hj3415-2.9.6.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
13
|
+
analyser_hj3415-2.9.6.dist-info/METADATA,sha256=E9NDlUi2M4vi7-RnFJTK-6w754uZHCnbVY7ZoaCqK20,6524
|
14
|
+
analyser_hj3415-2.9.6.dist-info/RECORD,,
|
File without changes
|