analyser_hj3415 3.4.1__py3-none-any.whl → 3.4.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/prophet.py +53 -3
- {analyser_hj3415-3.4.1.dist-info → analyser_hj3415-3.4.2.dist-info}/METADATA +1 -1
- {analyser_hj3415-3.4.1.dist-info → analyser_hj3415-3.4.2.dist-info}/RECORD +5 -5
- {analyser_hj3415-3.4.1.dist-info → analyser_hj3415-3.4.2.dist-info}/WHEEL +0 -0
- {analyser_hj3415-3.4.1.dist-info → analyser_hj3415-3.4.2.dist-info}/entry_points.txt +0 -0
@@ -1,5 +1,7 @@
|
|
1
1
|
from datetime import datetime, timedelta
|
2
|
-
from typing import Optional, Tuple, List
|
2
|
+
from typing import Optional, Tuple, List, Dict
|
3
|
+
|
4
|
+
import pandas
|
3
5
|
import yfinance as yf
|
4
6
|
import pandas as pd
|
5
7
|
from prophet import Prophet
|
@@ -29,11 +31,20 @@ class ProphetData:
|
|
29
31
|
yhat: float
|
30
32
|
yhat_upper: float
|
31
33
|
yhat_lower: float
|
32
|
-
forecast_data: List[dict]
|
33
34
|
|
34
35
|
trading_action: str = ''
|
35
36
|
score: int = None
|
36
37
|
|
38
|
+
@dataclass
|
39
|
+
class ProphetChartData:
|
40
|
+
ticker: str
|
41
|
+
|
42
|
+
labels: List[pandas.Timestamp]
|
43
|
+
prices: List[Dict[pandas.Timestamp, float]]
|
44
|
+
yhats: List[Dict[pandas.Timestamp, float]]
|
45
|
+
yhat_uppers: List[Dict[pandas.Timestamp, float]]
|
46
|
+
yhat_lowers: List[Dict[pandas.Timestamp, float]]
|
47
|
+
|
37
48
|
|
38
49
|
class MyProphet:
|
39
50
|
def __init__(self, ticker: str):
|
@@ -233,7 +244,6 @@ class MyProphet:
|
|
233
244
|
yhat=latest_yhat['yhat'],
|
234
245
|
yhat_lower=latest_yhat['yhat_lower'],
|
235
246
|
yhat_upper=latest_yhat['yhat_upper'],
|
236
|
-
forecast_data=self.df_forecast.to_dict(orient='records'),
|
237
247
|
)
|
238
248
|
|
239
249
|
data.trading_action, data.score = scoring(data.price, data.yhat_lower, data.yhat_upper)
|
@@ -244,6 +254,46 @@ class MyProphet:
|
|
244
254
|
|
245
255
|
return prophet_data
|
246
256
|
|
257
|
+
def generate_chart_data(self, refresh: bool) -> ProphetChartData:
|
258
|
+
"""
|
259
|
+
1. 현재 주가 (실제 데이터)
|
260
|
+
• df_real['ds'] → x축 (날짜)
|
261
|
+
• df_real['y'] → y축 (실제 주가)
|
262
|
+
|
263
|
+
2. 예측 값 범위 (최소/최대)
|
264
|
+
• df_forecast['ds'] → x축 (날짜)
|
265
|
+
• df_forecast['yhat_lower'] → y축 (최소 예측값)
|
266
|
+
• df_forecast['yhat_upper'] → y축 (최대 예측값)
|
267
|
+
"""
|
268
|
+
print("**** Start generate_chart_data... ****")
|
269
|
+
redis_name = f'{self.ticker}_myprophet_chart_data'
|
270
|
+
|
271
|
+
print(
|
272
|
+
f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time / 3600}h")
|
273
|
+
|
274
|
+
def fetch_generate_prophet_chart_data() -> ProphetChartData:
|
275
|
+
self.initializing()
|
276
|
+
|
277
|
+
# 날짜를 기준으로 합치기 (outer join)
|
278
|
+
merged_df = pd.merge(self.df_real, self.df_forecast, on="ds", how="outer")
|
279
|
+
# 날짜 정렬
|
280
|
+
merged_df = merged_df.sort_values(by="ds").reset_index(drop=True)
|
281
|
+
|
282
|
+
data = ProphetChartData(
|
283
|
+
ticker=self.ticker,
|
284
|
+
labels=merged_df["ds"].tolist(),
|
285
|
+
prices=[{"x": ds, "y": y} for ds, y in zip(merged_df["ds"], merged_df["y"]) if pd.notna(y)], # type: ignore
|
286
|
+
yhats=[{"x": ds, "y": yhat} for ds, yhat in zip(merged_df["ds"], merged_df["yhat"])], # type: ignore
|
287
|
+
yhat_uppers=[{"x": ds, "y": yhat_upper} for ds, yhat_upper in zip(merged_df["ds"], merged_df["yhat_upper"])], # type: ignore
|
288
|
+
yhat_lowers=[{"x": ds, "y": yhat_lower} for ds, yhat_lower in zip(merged_df["ds"], merged_df["yhat_lower"])], # type: ignore
|
289
|
+
)
|
290
|
+
return data
|
291
|
+
|
292
|
+
prophet_chart_data = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_generate_prophet_chart_data,
|
293
|
+
timer=expire_time)
|
294
|
+
return prophet_chart_data
|
295
|
+
|
296
|
+
|
247
297
|
def visualization(self):
|
248
298
|
"""
|
249
299
|
Prophet 모델의 예측 결과를 시각화합니다.
|
@@ -11,13 +11,13 @@ analyser_hj3415/analyser/eval/red.py,sha256=8aJPpiVzLOZtt6kILCzqcfL8BrEVgIld1iI3
|
|
11
11
|
analyser_hj3415/analyser/tsa/__init__.py,sha256=pg20ZQRABedTdaIoOr5t043RNKtJ7ji_WmnZrD1IhPg,147
|
12
12
|
analyser_hj3415/analyser/tsa/common.py,sha256=OnsZ_cFYmNzmk0tV5qSqVW-5jJyrwMWHguWdS2Z6fvY,979
|
13
13
|
analyser_hj3415/analyser/tsa/lstm.py,sha256=P8peqg6ZUpCSNKupjFlyba3xbPZoYtpd2UihXib_4Do,28548
|
14
|
-
analyser_hj3415/analyser/tsa/prophet.py,sha256=
|
14
|
+
analyser_hj3415/analyser/tsa/prophet.py,sha256=AlDU6YmjSf094diTVpMe0w06Z-FZ_2KAsDm2rshzxpA,16957
|
15
15
|
analyser_hj3415/workroom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
16
|
analyser_hj3415/workroom/mysklearn.py,sha256=wJXKz5MqqTzADdG2mqRMMzc_G9RzwYjj5_j4gyOopxQ,2030
|
17
17
|
analyser_hj3415/workroom/mysklearn2.py,sha256=1lIy6EWEQHkOzDS-av8U0zQH6DuCLKWMI73dnJx5KRs,1495
|
18
18
|
analyser_hj3415/workroom/score.py,sha256=P6nHBJYmyhigGtT4qna4BmNtvt4B93b7SKyzdstJK24,17376
|
19
19
|
analyser_hj3415/workroom/trash.py,sha256=zF-W0piqkGr66UP6-iybo9EXh2gO0RP6R1FnIpsGkl8,12262
|
20
|
-
analyser_hj3415-3.4.
|
21
|
-
analyser_hj3415-3.4.
|
22
|
-
analyser_hj3415-3.4.
|
23
|
-
analyser_hj3415-3.4.
|
20
|
+
analyser_hj3415-3.4.2.dist-info/entry_points.txt,sha256=ZfjPnJuH8SzvhE9vftIPMBIofsc65IAWYOhqOC_L5ck,65
|
21
|
+
analyser_hj3415-3.4.2.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
22
|
+
analyser_hj3415-3.4.2.dist-info/METADATA,sha256=F3_EIBCZD-sDpwathQJp9cCa_yF46fgHDegSF_FPeB8,6777
|
23
|
+
analyser_hj3415-3.4.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|