AlanRex commited on
Commit
7470af8
·
verified ·
1 Parent(s): 4ecc851

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -7
app.py CHANGED
@@ -592,17 +592,45 @@ def update_taiex_prediction(predict_days):
592
  line=dict(color='#FFA726', width=2)
593
  ))
594
 
595
- # 預測點
596
- future_date = recent_data.index[-1] + timedelta(days=predict_days)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597
  fig.add_trace(go.Scatter(
598
- x=[recent_data.index[-1], future_date],
599
  y=[current_price, predicted_price],
600
- mode='lines+markers',
601
- name=f'{predict_days}日預測',
602
- line=dict(color=color, width=3, dash='dash'),
603
- marker=dict(size=8)
604
  ))
605
 
 
 
606
  fig.update_layout(
607
  title=f'台指期 {predict_days}日預測走勢',
608
  xaxis_title='日期',
 
592
  line=dict(color='#FFA726', width=2)
593
  ))
594
 
595
+ # --- 關鍵修正從這裡開始 ---
596
+ # 定義所有要顯示的預測天數點
597
+ all_predict_days = [1, 5, 10, 20, 60]
598
+
599
+ # 過濾出所有小於或等於使用者選擇的預測天數
600
+ points_to_show = [d for d in all_predict_days if d <= predict_days]
601
+
602
+ # 為每個要顯示的預測點創建圖表軌跡
603
+ for d in points_to_show:
604
+ # 重新計算每個點的預測值
605
+ point_prediction = simple_lstm_predict(data, d)
606
+ if point_prediction:
607
+ point_predicted_price = point_prediction['predicted_price']
608
+ point_future_date = recent_data.index[-1] + timedelta(days=d)
609
+
610
+ # 決定點的顏色
611
+ point_color = '#00C851' if point_predicted_price >= current_price else '#FF4444'
612
+
613
+ # 添加預測點
614
+ fig.add_trace(go.Scatter(
615
+ x=[point_future_date],
616
+ y=[point_predicted_price],
617
+ mode='markers',
618
+ name=f'{d}日預測點',
619
+ marker=dict(size=10, color=point_color)
620
+ ))
621
+
622
+ # 為使用者選擇的最終天數添加趨勢線
623
+ final_future_date = recent_data.index[-1] + timedelta(days=predict_days)
624
  fig.add_trace(go.Scatter(
625
+ x=[recent_data.index[-1], final_future_date],
626
  y=[current_price, predicted_price],
627
+ mode='lines',
628
+ name='最終預測線',
629
+ line=dict(color=color, width=3, dash='dash')
 
630
  ))
631
 
632
+ # --- 修正結束 ---
633
+
634
  fig.update_layout(
635
  title=f'台指期 {predict_days}日預測走勢',
636
  xaxis_title='日期',