AlanRex commited on
Commit
718357b
·
verified ·
1 Parent(s): 5c4d9c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -15
app.py CHANGED
@@ -619,12 +619,12 @@ def generate_gemini_analysis(stock_name, stock_symbol, period, data):
619
  **你的任務:**
620
  1. **基本面分析 (約 150 字):**
621
  - 評論這家公司的產業地位、近期營運亮點或挑戰。
622
- - 提及任何可能影響其基本面的關鍵因素 (例如:最近公告財報日期、法說會日期、最近一次的EPS、最近一個月的MOM是否增長、政策、供應鏈變化等)。
623
  - 請用專業、客觀的語氣撰寫。
624
 
625
  2. **市場展望與投資建議 (約 150 字):**
626
  - 基於上述所有資訊,提供對該股票的短期和中期市場展望。
627
- - 提出具體的投資建議,例如:適合何種類型的投資人(價值投資、波段投資、動能投資)、潛在的風險點。
628
  - 請直接提供分析內容,不要包含任何問候語。
629
 
630
  **輸出格式:**
@@ -953,25 +953,89 @@ def update_industry_analysis(selected_stock):
953
  '月報酬率(%)': return_pct,
954
  '絕對波動': abs(return_pct)
955
  })
 
956
  if not performance_data:
957
  fig = go.Figure().add_annotation(text="無法計算產業資料", showarrow=False)
958
- fig.update_layout(title="近一月市場波動最大標的", height=400)
959
  return fig
 
960
  df_performance = pd.DataFrame(performance_data)
961
- df_top_movers = df_performance.sort_values(by='絕對波動', ascending=False).head(10)
962
- fig = px.pie(
963
- df_top_movers,
964
- values='絕對波動',
965
- names='股票',
966
- title='近一月市場波動最大 Top 10 標的',
967
- hover_data={'月報酬率(%)': ':.2f'}
 
 
 
 
 
 
 
 
968
  )
969
- fig.update_traces(
970
- textposition='inside',
971
- textinfo='percent+label',
972
- hovertemplate="<b>%{label}</b><br>月報酬率: %{customdata[0]:.2f}%<extra></extra>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973
  )
974
- fig.update_layout(height=400, showlegend=False)
975
  return fig
976
 
977
  @app.callback(
 
619
  **你的任務:**
620
  1. **基本面分析 (約 150 字):**
621
  - 評論這家公司的產業地位、近期營運亮點或挑戰。
622
+ - 提及任何可能影響其基本面的關鍵因素 (例如:公告財報的最近日期、法說會最近日期、最近一次的EPS數值、最近一個月的MOM%的數值、政策、供應鏈變化等)。
623
  - 請用專業、客觀的語氣撰寫。
624
 
625
  2. **市場展望與投資建議 (約 150 字):**
626
  - 基於上述所有資訊,提供對該股票的短期和中期市場展望。
627
+ - 提出具體的投資建議,例如:適合何種類型的投資(價值投資、波段投資、動能投資)、潛在的風險點。
628
  - 請直接提供分析內容,不要包含任何問候語。
629
 
630
  **輸出格式:**
 
953
  '月報酬率(%)': return_pct,
954
  '絕對波動': abs(return_pct)
955
  })
956
+
957
  if not performance_data:
958
  fig = go.Figure().add_annotation(text="無法計算產業資料", showarrow=False)
959
+ fig.update_layout(title="近一月市場表現分析", height=400)
960
  return fig
961
+
962
  df_performance = pd.DataFrame(performance_data)
963
+
964
+ # 分離漲跌幅數據
965
+ gainers = df_performance[df_performance['月報酬率(%)'] > 0].copy()
966
+ losers = df_performance[df_performance['月報酬率(%)'] < 0].copy()
967
+
968
+ # 按報酬率排序並取前5名
969
+ top_gainers = gainers.sort_values(by='月報酬率(%)', ascending=False).head(5)
970
+ top_losers = losers.sort_values(by='月報酬率(%)', ascending=True).head(5)
971
+
972
+ # 創建子圖布局 - 1行2列
973
+ fig = make_subplots(
974
+ rows=1, cols=2,
975
+ specs=[[{"type": "pie"}, {"type": "pie"}]],
976
+ subplot_titles=('📈 近一月漲幅排行 Top 5', '📉 近一月跌幅排行 Top 5'),
977
+ horizontal_spacing=0.1
978
  )
979
+
980
+ # 如果有上漲的股票,添加漲幅圓餅圖
981
+ if not top_gainers.empty:
982
+ fig.add_trace(go.Pie(
983
+ labels=top_gainers['股票'],
984
+ values=top_gainers['月報酬率(%)'],
985
+ name="漲幅",
986
+ textinfo='label+percent',
987
+ textposition='inside',
988
+ marker=dict(colors=['#FF6B6B', '#FF8E53', '#FF6B9D', '#C44569', '#F8B500']),
989
+ hovertemplate="<b>%{label}</b><br>漲幅: +%{value:.1f}%<extra></extra>",
990
+ textfont=dict(size=12)
991
+ ), row=1, col=1)
992
+ else:
993
+ # 如果沒有上漲股票,顯示提示
994
+ fig.add_annotation(
995
+ text="本月無上漲股票",
996
+ x=0.25, y=0.5,
997
+ showarrow=False,
998
+ font=dict(size=16, color="gray")
999
+ )
1000
+
1001
+ # 如果有下跌的股票,添加跌幅圓餅圖(使用絕對值)
1002
+ if not top_losers.empty:
1003
+ fig.add_trace(go.Pie(
1004
+ labels=top_losers['股票'],
1005
+ values=abs(top_losers['月報酬率(%)']), # 使用絕對值讓圓餅圖正常顯示
1006
+ name="跌幅",
1007
+ textinfo='label+percent',
1008
+ textposition='inside',
1009
+ marker=dict(colors=['#20BF6B', '#26DE81', '#2BCBBA', '#45AAF2', '#4834D4']),
1010
+ hovertemplate="<b>%{label}</b><br>跌幅: %{customdata:.1f}%<extra></extra>",
1011
+ customdata=top_losers['月報酬率(%)'], # 顯示實際的負值
1012
+ textfont=dict(size=12)
1013
+ ), row=1, col=2)
1014
+ else:
1015
+ # 如果沒有下跌股票,顯示提示
1016
+ fig.add_annotation(
1017
+ text="本月無下跌股票",
1018
+ x=0.75, y=0.5,
1019
+ showarrow=False,
1020
+ font=dict(size=16, color="gray")
1021
+ )
1022
+
1023
+ # 更新布局
1024
+ fig.update_layout(
1025
+ title_text="近一月市場表現分析 - 漲跌分佈",
1026
+ height=500,
1027
+ showlegend=False,
1028
+ font=dict(size=11),
1029
+ title_font_size=16,
1030
+ annotations=[
1031
+ dict(text=f"統計範圍:{len(performance_data)}檔股票",
1032
+ x=0.5, y=-0.1,
1033
+ showarrow=False,
1034
+ xanchor="center",
1035
+ font=dict(size=12, color="gray"))
1036
+ ]
1037
  )
1038
+
1039
  return fig
1040
 
1041
  @app.callback(