Commit
·
ff03388
1
Parent(s):
0091ee4
autogluon.timeseries
Browse files- app.py +21 -3
- requirements.txt +1 -1
app.py
CHANGED
@@ -12,18 +12,36 @@ def get_stock_data(ticker, period):
|
|
12 |
# Function to prepare the data for Chronos-Bolt
|
13 |
|
14 |
def prepare_data_chronos(data):
|
|
|
15 |
data = data.reset_index()
|
16 |
data = data.rename(columns={"Date": "timestamp", "Close": "target"})
|
|
|
|
|
17 |
data = data[["timestamp", "target"]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
data["item_id"] = "stock"
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
data,
|
23 |
id_column="item_id",
|
24 |
timestamp_column="timestamp",
|
25 |
target_column="target"
|
26 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Function to fetch stock indices (you already defined these)
|
28 |
def get_tw0050_stocks():
|
29 |
response = requests.get('https://answerbook.david888.com/TW0050')
|
|
|
12 |
# Function to prepare the data for Chronos-Bolt
|
13 |
|
14 |
def prepare_data_chronos(data):
|
15 |
+
# 確保索引重置並重命名欄位
|
16 |
data = data.reset_index()
|
17 |
data = data.rename(columns={"Date": "timestamp", "Close": "target"})
|
18 |
+
|
19 |
+
# 只保留需要的欄位
|
20 |
data = data[["timestamp", "target"]]
|
21 |
+
|
22 |
+
# 設定正確的資料類型
|
23 |
+
data = data.astype({
|
24 |
+
"timestamp": "datetime64[ns]",
|
25 |
+
"target": "float32"
|
26 |
+
})
|
27 |
+
|
28 |
+
# 添加 item_id
|
29 |
data["item_id"] = "stock"
|
30 |
+
|
31 |
+
# 建立 TimeSeriesDataFrame 並指定資料類型
|
32 |
+
ts_data = TimeSeriesDataFrame(
|
33 |
data,
|
34 |
id_column="item_id",
|
35 |
timestamp_column="timestamp",
|
36 |
target_column="target"
|
37 |
)
|
38 |
+
|
39 |
+
# 確保時間序列資料是按時間排序的
|
40 |
+
ts_data = ts_data.sort_index()
|
41 |
+
|
42 |
+
return ts_data
|
43 |
+
|
44 |
+
|
45 |
# Function to fetch stock indices (you already defined these)
|
46 |
def get_tw0050_stocks():
|
47 |
response = requests.get('https://answerbook.david888.com/TW0050')
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
autogluon.timeseries
|
2 |
pandas>=1.3.0
|
3 |
numpy>=1.19.5
|
4 |
yfinance
|
|
|
1 |
+
autogluon.timeseries==0.8.2
|
2 |
pandas>=1.3.0
|
3 |
numpy>=1.19.5
|
4 |
yfinance
|