Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -325,7 +325,10 @@ def advanced_xgboost_predict(predict_days=5):
|
|
| 325 |
# 準備特徵數據 (使用最新的數據點)
|
| 326 |
latest_data = taiex_data.iloc[-1]
|
| 327 |
|
| 328 |
-
#
|
|
|
|
|
|
|
|
|
|
| 329 |
new_feature_columns = [
|
| 330 |
'return_t-1', # 前一日報酬率
|
| 331 |
'return_t-5', # 過去 5 日累積報酬率
|
|
@@ -390,6 +393,21 @@ def advanced_xgboost_predict(predict_days=5):
|
|
| 390 |
|
| 391 |
feature_names.append(feature)
|
| 392 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
# 添加美股指標
|
| 394 |
features_list.extend([dji_return, sox_return])
|
| 395 |
feature_names.extend(['dji_return_t-1', 'sox_return_t-1'])
|
|
|
|
| 325 |
# 準備特徵數據 (使用最新的數據點)
|
| 326 |
latest_data = taiex_data.iloc[-1]
|
| 327 |
|
| 328 |
+
# 【【【新增功能】】】 取得昨日收盤價
|
| 329 |
+
yesterday_close = latest_data['Close']
|
| 330 |
+
|
| 331 |
+
# 新特徵列表 - 按照您指定的8個技術指標特徵
|
| 332 |
new_feature_columns = [
|
| 333 |
'return_t-1', # 前一日報酬率
|
| 334 |
'return_t-5', # 過去 5 日累積報酬率
|
|
|
|
| 393 |
|
| 394 |
feature_names.append(feature)
|
| 395 |
|
| 396 |
+
# 【【【新增功能】】】 添加 'close' 和 'NEWS' 特徵
|
| 397 |
+
# 1. 添加昨日收盤價 ('close')
|
| 398 |
+
if not pd.isna(yesterday_close):
|
| 399 |
+
features_list.append(yesterday_close)
|
| 400 |
+
feature_status['close'] = {'value': yesterday_close, 'is_real': True, 'source': 'calculated'}
|
| 401 |
+
else:
|
| 402 |
+
features_list.append(10000) # Fallback value for price
|
| 403 |
+
feature_status['close'] = {'value': 10000, 'is_real': False, 'source': 'default'}
|
| 404 |
+
feature_names.append('close')
|
| 405 |
+
|
| 406 |
+
# 2. 添加新聞情緒分數 ('NEWS')
|
| 407 |
+
features_list.append(sentiment_score_raw)
|
| 408 |
+
feature_status['NEWS'] = {'value': sentiment_score_raw, 'is_real': True, 'source': 'calculated'}
|
| 409 |
+
feature_names.append('NEWS')
|
| 410 |
+
|
| 411 |
# 添加美股指標
|
| 412 |
features_list.extend([dji_return, sox_return])
|
| 413 |
feature_names.extend(['dji_return_t-1', 'sox_return_t-1'])
|