Spaces:
Sleeping
Sleeping
Update model_predictor.py
Browse files- model_predictor.py +3 -4
model_predictor.py
CHANGED
|
@@ -64,7 +64,7 @@ class StockPredictor:
|
|
| 64 |
taiwan_stock = yf.Ticker('2330.TW')
|
| 65 |
taiwan_data = taiwan_stock.history(start=start_date, end=end_date)
|
| 66 |
|
| 67 |
-
#
|
| 68 |
taiwan_data.index = taiwan_data.index.tz_localize(None)
|
| 69 |
|
| 70 |
if taiwan_data.empty:
|
|
@@ -86,7 +86,7 @@ class StockPredictor:
|
|
| 86 |
ticker = yf.Ticker(symbol)
|
| 87 |
data = ticker.history(start=start_date, end=end_date)
|
| 88 |
|
| 89 |
-
#
|
| 90 |
data.index = data.index.tz_localize(None)
|
| 91 |
|
| 92 |
if not data.empty:
|
|
@@ -97,7 +97,7 @@ class StockPredictor:
|
|
| 97 |
print(f"獲取 {name} 數據時發生錯誤: {e}")
|
| 98 |
|
| 99 |
# 合併數據
|
| 100 |
-
main_df = pd.DataFrame(index=taiwan_data.index)
|
| 101 |
main_df['close'] = taiwan_data['Close']
|
| 102 |
main_df['volume'] = taiwan_data['Volume']
|
| 103 |
|
|
@@ -106,7 +106,6 @@ class StockPredictor:
|
|
| 106 |
|
| 107 |
# 添加美國市場數據
|
| 108 |
for name, data in us_data.items():
|
| 109 |
-
# 重新索引以匹配台灣股市交易日
|
| 110 |
main_df[name] = data.reindex(main_df.index, method='ffill')
|
| 111 |
|
| 112 |
return main_df
|
|
|
|
| 64 |
taiwan_stock = yf.Ticker('2330.TW')
|
| 65 |
taiwan_data = taiwan_stock.history(start=start_date, end=end_date)
|
| 66 |
|
| 67 |
+
# 移除時區,使索引為 tz-naive
|
| 68 |
taiwan_data.index = taiwan_data.index.tz_localize(None)
|
| 69 |
|
| 70 |
if taiwan_data.empty:
|
|
|
|
| 86 |
ticker = yf.Ticker(symbol)
|
| 87 |
data = ticker.history(start=start_date, end=end_date)
|
| 88 |
|
| 89 |
+
# 移除時區,使索引為 tz-naive
|
| 90 |
data.index = data.index.tz_localize(None)
|
| 91 |
|
| 92 |
if not data.empty:
|
|
|
|
| 97 |
print(f"獲取 {name} 數據時發生錯誤: {e}")
|
| 98 |
|
| 99 |
# 合併數據
|
| 100 |
+
main_df = pd.DataFrame(index=taiwan_data.index)
|
| 101 |
main_df['close'] = taiwan_data['Close']
|
| 102 |
main_df['volume'] = taiwan_data['Volume']
|
| 103 |
|
|
|
|
| 106 |
|
| 107 |
# 添加美國市場數據
|
| 108 |
for name, data in us_data.items():
|
|
|
|
| 109 |
main_df[name] = data.reindex(main_df.index, method='ffill')
|
| 110 |
|
| 111 |
return main_df
|