analyser_hj3415 4.0.0__py3-none-any.whl → 4.0.2__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/tsa/lstm.py +25 -33
- analyser_hj3415/analyser/tsa/prophet.py +12 -0
- {analyser_hj3415-4.0.0.dist-info → analyser_hj3415-4.0.2.dist-info}/METADATA +2 -2
- {analyser_hj3415-4.0.0.dist-info → analyser_hj3415-4.0.2.dist-info}/RECORD +6 -6
- {analyser_hj3415-4.0.0.dist-info → analyser_hj3415-4.0.2.dist-info}/WHEEL +0 -0
- {analyser_hj3415-4.0.0.dist-info → analyser_hj3415-4.0.2.dist-info}/entry_points.txt +0 -0
@@ -4,7 +4,7 @@ import pandas
|
|
4
4
|
import yfinance as yf
|
5
5
|
from datetime import datetime, timedelta
|
6
6
|
import pandas as pd
|
7
|
-
from typing import Tuple, Dict, List
|
7
|
+
from typing import Tuple, Dict, List, Optional
|
8
8
|
from sklearn.preprocessing import MinMaxScaler
|
9
9
|
from tensorflow.keras.models import Sequential # type: ignore
|
10
10
|
from tensorflow.keras.layers import LSTM, Dense, Dropout # type: ignore
|
@@ -432,23 +432,6 @@ class MyLSTM:
|
|
432
432
|
mylogger.info(
|
433
433
|
f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time/3600}h")
|
434
434
|
|
435
|
-
def caching_is_lstm_up(future_data_in: dict):
|
436
|
-
"""
|
437
|
-
날짜(str)를 키, 수치(float)를 값으로 갖는 딕셔너리를
|
438
|
-
선형회귀분석(최소제곱법)을 통해 추세가 우상향인지 판별.
|
439
|
-
|
440
|
-
Returns:
|
441
|
-
bool: 기울기가 양수이면 True, 아니면 False
|
442
|
-
"""
|
443
|
-
|
444
|
-
mylogger.debug("**** Caching is_lstm_up ... ****")
|
445
|
-
redis_name = f'{self.ticker}_is_lstm_up'
|
446
|
-
mylogger.debug(f"redisname: '{redis_name}' / expire_time : {expire_time / 3600}h")
|
447
|
-
|
448
|
-
is_up = tsa.common.is_up_by_OLS(future_data_in)
|
449
|
-
mylogger.debug(f"is_up: {is_up}")
|
450
|
-
myredis.Base.set_value(redis_name, is_up, expire_time)
|
451
|
-
|
452
435
|
def fetch_final_predictions(num_in) -> tuple:
|
453
436
|
"""
|
454
437
|
앙상블법으로 딥러닝을 모델을 반복해서 평균을 내서 미래를 예측한다. 평가는 래시스 캐시로 반환하기 어려워 일단 디버그 용도로만 사용하기로
|
@@ -490,9 +473,6 @@ class MyLSTM:
|
|
490
473
|
|
491
474
|
future_data, lstm_grade = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_final_predictions, num, timer=expire_time)
|
492
475
|
|
493
|
-
# 증가 추세인지 아닌지 레디스 캐시에 저장
|
494
|
-
caching_is_lstm_up(future_data)
|
495
|
-
|
496
476
|
return future_data, lstm_grade
|
497
477
|
|
498
478
|
def generate_chart_data(self, refresh:bool, num=5) -> LSTMChartData:
|
@@ -521,7 +501,7 @@ class MyLSTM:
|
|
521
501
|
past_prices = past_prices.astype(float)
|
522
502
|
return past_dates, past_prices
|
523
503
|
|
524
|
-
def prepare_future_data(refresh_in, num_in) -> tuple:
|
504
|
+
def prepare_future_data(refresh_in, num_in) -> tuple[pd.Series, pd.Series, LSTMGrade, bool]:
|
525
505
|
mylogger.info("*** prepare future data ... ****")
|
526
506
|
future_data, lstm_grade = self.get_final_predictions(refresh=refresh_in, num=num_in)
|
527
507
|
|
@@ -529,12 +509,12 @@ class MyLSTM:
|
|
529
509
|
future_dates = pd.to_datetime(list(future_data.keys()))
|
530
510
|
|
531
511
|
future_prices = pd.Series(future_data.values(), index=range(len(future_data.values()))).astype(float)
|
532
|
-
return future_dates, future_prices, lstm_grade
|
512
|
+
return future_dates, future_prices, lstm_grade, tsa.common.is_up_by_OLS(future_data)
|
533
513
|
|
534
514
|
if not self.initialized:
|
535
515
|
self.initializing()
|
536
516
|
past_dates, past_prices = prepare_past_data(past_days=120)
|
537
|
-
future_dates, future_prices, lstm_grade = prepare_future_data(refresh_in=refresh, num_in=num)
|
517
|
+
future_dates, future_prices, lstm_grade, is_lstm_up = prepare_future_data(refresh_in=refresh, num_in=num)
|
538
518
|
past_df = pd.DataFrame({"ds": past_dates, "y": past_prices})
|
539
519
|
future_df = pd.DataFrame({"ds": future_dates, "future_price": future_prices})
|
540
520
|
|
@@ -550,7 +530,7 @@ class MyLSTM:
|
|
550
530
|
future_prices=[{"x": ds, "y": future_price} for ds, future_price in zip(merged_df["ds"], merged_df["future_price"])], # type: ignore
|
551
531
|
grade=lstm_grade,
|
552
532
|
num=num_in,
|
553
|
-
is_lstm_up=
|
533
|
+
is_lstm_up=is_lstm_up,
|
554
534
|
)
|
555
535
|
#import pprint
|
556
536
|
#pprint.pprint(data.prices[-10:], compact=True)
|
@@ -562,14 +542,14 @@ class MyLSTM:
|
|
562
542
|
num, timer=expire_time)
|
563
543
|
return lstm_chart_data
|
564
544
|
|
565
|
-
def
|
566
|
-
""
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
545
|
+
def get_chart_data(self) -> Optional[LSTMChartData]:
|
546
|
+
mylogger.info("**** Start get_lstm_chart_data... ****")
|
547
|
+
redis_name = f'{self.ticker}_lstm_chart_data'
|
548
|
+
if myredis.Base.exists(redis_name):
|
549
|
+
mylogger.info(myredis.Base.get_ttl(redis_name))
|
550
|
+
return myredis.Base.get_value(redis_name)
|
551
|
+
else:
|
552
|
+
return None
|
573
553
|
|
574
554
|
@staticmethod
|
575
555
|
def caching_chart_data(tickers:list, num:int):
|
@@ -634,6 +614,18 @@ class MILSTM(MyLSTM):
|
|
634
614
|
|
635
615
|
속성:
|
636
616
|
mi_type (str): MI 타입.
|
617
|
+
|
618
|
+
MI 타입:
|
619
|
+
WTI (str): 서부 텍사스 중질유(WTI) 선물 지수 (심볼: "CL=F").
|
620
|
+
GOLD (str): 금 선물 지수 (심볼: "GC=F").
|
621
|
+
SILVER (str): 은 선물 지수 (심볼: "SI=F").
|
622
|
+
USD_IDX (str): 미국 달러 인덱스 (심볼: "DX-Y.NYB").
|
623
|
+
USD_KRW (str): 달러-원 환율 (심볼: "KRW=X").
|
624
|
+
SP500 (str): S&P 500 주가지수 (심볼: "^GSPC").
|
625
|
+
KOSPI (str): 코스피 지수 (심볼: "^KS11").
|
626
|
+
NIKKEI (str): 닛케이 225 지수 (일본) (심볼: "^N225").
|
627
|
+
CHINA (str): 항셍 지수 (홍콩) (심볼: "^HSI").
|
628
|
+
IRX (str): 미국 단기 국채 금리 지수 (13주 T-빌 금리) (심볼: "^IRX").
|
637
629
|
"""
|
638
630
|
def __init__(self, mi_type: str):
|
639
631
|
assert mi_type in MIs._fields, f"Invalid MI type ({MIs._fields})"
|
@@ -456,6 +456,18 @@ class MIProphet(MyProphet):
|
|
456
456
|
|
457
457
|
속성:
|
458
458
|
mi_type (str): MI 타입.
|
459
|
+
|
460
|
+
MI 타입:
|
461
|
+
WTI (str): 서부 텍사스 중질유(WTI) 선물 지수 (심볼: "CL=F").
|
462
|
+
GOLD (str): 금 선물 지수 (심볼: "GC=F").
|
463
|
+
SILVER (str): 은 선물 지수 (심볼: "SI=F").
|
464
|
+
USD_IDX (str): 미국 달러 인덱스 (심볼: "DX-Y.NYB").
|
465
|
+
USD_KRW (str): 달러-원 환율 (심볼: "KRW=X").
|
466
|
+
SP500 (str): S&P 500 주가지수 (심볼: "^GSPC").
|
467
|
+
KOSPI (str): 코스피 지수 (심볼: "^KS11").
|
468
|
+
NIKKEI (str): 닛케이 225 지수 (일본) (심볼: "^N225").
|
469
|
+
CHINA (str): 항셍 지수 (홍콩) (심볼: "^HSI").
|
470
|
+
IRX (str): 미국 단기 국채 금리 지수 (13주 T-빌 금리) (심볼: "^IRX").
|
459
471
|
"""
|
460
472
|
def __init__(self, mi_type: str):
|
461
473
|
assert mi_type in MIs._fields, f"Invalid MI type ({MIs._fields})"
|
@@ -1,11 +1,11 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: analyser_hj3415
|
3
|
-
Version: 4.0.
|
3
|
+
Version: 4.0.2
|
4
4
|
Summary: Stock analyser and database processing programs
|
5
5
|
Requires-Python: >=3.6
|
6
6
|
Description-Content-Type: text/markdown
|
7
7
|
Requires-Dist: utils-hj3415>=3.0.10
|
8
|
-
Requires-Dist: db-hj3415>=4.3.
|
8
|
+
Requires-Dist: db-hj3415>=4.3.5
|
9
9
|
Requires-Dist: scikit-learn>=1.5.2
|
10
10
|
Requires-Dist: plotly>=5.24.1
|
11
11
|
Requires-Dist: yfinance>=0.2.44
|
@@ -9,9 +9,9 @@ analyser_hj3415/analyser/eval/mil.py,sha256=mFMiFCuCBvlQrhQcM5hMg8U4zF32TS1GnUmk
|
|
9
9
|
analyser_hj3415/analyser/eval/red.py,sha256=b-Odud8pxQIO2NjI7m3HbK4FOND5WhaoYV94mCHqDPo,13907
|
10
10
|
analyser_hj3415/analyser/tsa/__init__.py,sha256=pg20ZQRABedTdaIoOr5t043RNKtJ7ji_WmnZrD1IhPg,147
|
11
11
|
analyser_hj3415/analyser/tsa/common.py,sha256=OnsZ_cFYmNzmk0tV5qSqVW-5jJyrwMWHguWdS2Z6fvY,979
|
12
|
-
analyser_hj3415/analyser/tsa/lstm.py,sha256=
|
13
|
-
analyser_hj3415/analyser/tsa/prophet.py,sha256=
|
14
|
-
analyser_hj3415-4.0.
|
15
|
-
analyser_hj3415-4.0.
|
16
|
-
analyser_hj3415-4.0.
|
17
|
-
analyser_hj3415-4.0.
|
12
|
+
analyser_hj3415/analyser/tsa/lstm.py,sha256=55MV62jSPqdOw1zAk1zB7LacNDesPsrmcUwHqaCz6Gs,27974
|
13
|
+
analyser_hj3415/analyser/tsa/prophet.py,sha256=dQ0g1pEv-ELugsg586w2yH0WJQQqr1zV_Wo7UXG_3WE,18337
|
14
|
+
analyser_hj3415-4.0.2.dist-info/entry_points.txt,sha256=ZfjPnJuH8SzvhE9vftIPMBIofsc65IAWYOhqOC_L5ck,65
|
15
|
+
analyser_hj3415-4.0.2.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
16
|
+
analyser_hj3415-4.0.2.dist-info/METADATA,sha256=Fk1VW_PXcF-9FA5YFahSiHC0164i0o0ExB5zrF19des,6777
|
17
|
+
analyser_hj3415-4.0.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|