Commit
·
3c0fe99
1
Parent(s):
47cec11
test6
Browse files
app.py
CHANGED
@@ -115,12 +115,10 @@ def get_top_10_potential_stocks(period, selected_indices):
|
|
115 |
continue
|
116 |
|
117 |
ts_data = prepare_data_chronos(data)
|
118 |
-
|
119 |
-
# 創建預測器,使用 'target' 作為目標列名
|
120 |
predictor = TimeSeriesPredictor(
|
121 |
prediction_length=prediction_length,
|
122 |
-
freq="D",
|
123 |
-
target="target"
|
124 |
)
|
125 |
|
126 |
predictor.fit(
|
@@ -131,14 +129,25 @@ def get_top_10_potential_stocks(period, selected_indices):
|
|
131 |
)
|
132 |
|
133 |
predictions = predictor.predict(ts_data)
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
except Exception as e:
|
138 |
print(f"Stock {ticker} error: {str(e)}")
|
139 |
continue
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
return top_10_stocks
|
143 |
|
144 |
# Gradio interface function
|
|
|
115 |
continue
|
116 |
|
117 |
ts_data = prepare_data_chronos(data)
|
|
|
|
|
118 |
predictor = TimeSeriesPredictor(
|
119 |
prediction_length=prediction_length,
|
120 |
+
freq="D",
|
121 |
+
target="target"
|
122 |
)
|
123 |
|
124 |
predictor.fit(
|
|
|
129 |
)
|
130 |
|
131 |
predictions = predictor.predict(ts_data)
|
132 |
+
|
133 |
+
# 修改這部分以正確處理預測結果
|
134 |
+
last_actual = float(data['Close'].iloc[-1])
|
135 |
+
last_pred = float(predictions.iloc[-1].values[0]) # 確保取得數值
|
136 |
+
potential = (last_pred - last_actual) / last_actual
|
137 |
+
|
138 |
+
stock_predictions.append((ticker, potential, last_actual, last_pred))
|
139 |
|
140 |
except Exception as e:
|
141 |
print(f"Stock {ticker} error: {str(e)}")
|
142 |
continue
|
143 |
+
|
144 |
+
# 確保所有值都是基本數據類型
|
145 |
+
top_10_stocks = sorted(
|
146 |
+
[(str(t), float(p), float(c), float(pred)) for t, p, c, pred in stock_predictions],
|
147 |
+
key=lambda x: x[1],
|
148 |
+
reverse=True
|
149 |
+
)[:10]
|
150 |
+
|
151 |
return top_10_stocks
|
152 |
|
153 |
# Gradio interface function
|