Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
3053 lines (2553 loc) · 124 KB
/
Copy pathapp.py
File metadata and controls
3053 lines (2553 loc) · 124 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import streamlit as st
import plotly.graph_objects as go
import plotly.express as px
import pandas as pd
import json
from datetime import datetime
import time
import base64
import os
import config
from stock_data import StockDataFetcher
from ai_agents import StockAnalysisAgents
from pdf_generator import display_pdf_export_section
from database import db
from monitor_manager import display_monitor_manager, get_monitor_summary
from monitor_service import monitor_service
from notification_service import notification_service
from config_manager import config_manager
from main_force_ui import display_main_force_selector
from sector_strategy_ui import display_sector_strategy
from longhubang_ui import display_longhubang
from smart_monitor_ui import smart_monitor_ui
from news_flow_ui import display_news_flow_monitor
# 页面配置
st.set_page_config(
page_title="复合多AI智能体股票团队分析系统",
page_icon="📈",
layout="wide",
initial_sidebar_state="expanded"
)
# 在侧边栏显示当前模型信息(统一使用.env配置)
def show_current_model_info():
"""显示当前使用的AI模型信息"""
st.sidebar.markdown("---")
st.sidebar.subheader("🤖 AI模型")
st.sidebar.info(f"当前模型: **{config.DEFAULT_MODEL_NAME}**")
st.sidebar.caption("可在「环境配置」中修改模型名称")
# 自定义CSS样式 - 专业版
st.markdown("""
<style>
/* 全局样式 */
.main {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
background-attachment: fixed;
}
.stApp {
background: transparent;
}
/* 主容器 */
.block-container {
padding-top: 2rem;
padding-bottom: 2rem;
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
margin-top: 1rem;
}
/* 顶部导航栏 */
.top-nav {
background-color: #667eea;
background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 1.5rem 2rem;
border-radius: 15px;
margin-bottom: 2rem;
box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
}
.nav-title {
font-size: 2rem;
font-weight: 800;
color: white;
text-align: center;
margin: 0;
text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
letter-spacing: 1px;
}
.nav-subtitle {
text-align: center;
color: rgba(255, 255, 255, 0.9);
font-size: 0.95rem;
margin-top: 0.5rem;
font-weight: 300;
}
/* 标签页样式 */
.stTabs [data-baseweb="tab-list"] {
gap: 2rem;
background-color: #667eea;
background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 1rem 2rem;
border-radius: 15px;
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
}
.stTabs [data-baseweb="tab"] {
height: 60px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
color: white;
font-weight: 600;
font-size: 1.1rem;
padding: 0 2rem;
border: none;
transition: all 0.3s ease;
}
.stTabs [data-baseweb="tab"]:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
}
.stTabs [aria-selected="true"] {
background: white !important;
color: #667eea !important;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
/* 侧边栏美化(background-color 兜底,避免渐变失效时白底白字,issue #1) */
.css-1d391kg, [data-testid="stSidebar"] {
background-color: #667eea;
background-image: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
padding-top: 2rem;
}
.css-1d391kg h1, .css-1d391kg h2, .css-1d391kg h3,
[data-testid="stSidebar"] h1, [data-testid="stSidebar"] h2, [data-testid="stSidebar"] h3 {
color: white !important;
}
.css-1d391kg .stMarkdown, [data-testid="stSidebar"] .stMarkdown {
color: rgba(255, 255, 255, 0.95) !important;
}
/* 分析师卡片 */
.agent-card {
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
padding: 1.5rem;
border-radius: 15px;
margin: 1rem 0;
border-left: 5px solid #667eea;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
transition: transform 0.3s ease;
}
.agent-card:hover {
transform: translateX(5px);
}
/* 决策卡片 */
.decision-card {
background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
padding: 2rem;
border-radius: 15px;
border: 3px solid #4caf50;
margin: 1.5rem 0;
box-shadow: 0 8px 30px rgba(76, 175, 80, 0.2);
}
/* 警告卡片 */
.warning-card {
background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
padding: 1.5rem;
border-radius: 15px;
border-left: 5px solid #ff9800;
box-shadow: 0 4px 15px rgba(255, 152, 0, 0.2);
}
/* 指标卡片 */
.metric-card {
background-color: #ffffff;
color: #222222;
padding: 1.5rem;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
text-align: center;
transition: transform 0.3s ease, box-shadow 0.3s ease;
border-top: 4px solid #667eea;
}
.metric-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}
/* 按钮美化(必须有 background-color 兜底,否则渐变失效时白字白底) */
.stButton>button {
background-color: #667eea;
background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white !important;
border: none;
border-radius: 10px;
padding: 0.75rem 2rem;
font-weight: 600;
font-size: 1rem;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.stButton>button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 25px rgba(102, 126, 234, 0.4);
}
/* 输入框美化 */
.stTextInput>div>div>input {
border-radius: 10px;
border: 2px solid #e0e0e0;
padding: 0.75rem;
font-size: 1rem;
transition: border-color 0.3s ease;
}
.stTextInput>div>div>input:focus {
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
/* 进度条美化 */
.stProgress > div > div > div > div {
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
}
/* 成功/错误/警告/信息消息框 */
.stSuccess, .stError, .stWarning, .stInfo {
border-radius: 10px;
padding: 1rem;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
/* 图表容器 */
.js-plotly-plot {
border-radius: 15px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
/* Expander美化 */
.streamlit-expanderHeader {
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
border-radius: 10px;
font-weight: 600;
}
/* 数据框美化 */
.dataframe {
border-radius: 10px;
overflow: hidden;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
/* 隐藏Streamlit默认元素 */
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
/* 响应式设计 */
@media (max-width: 768px) {
.nav-title {
font-size: 1.5rem;
}
.stTabs [data-baseweb="tab"] {
font-size: 0.9rem;
padding: 0 1rem;
}
}
</style>
""", unsafe_allow_html=True)
def main():
# 顶部标题栏
st.markdown("""
<div class="top-nav">
<h1 class="nav-title">📈 复合多AI智能体股票团队分析系统</h1>
<p class="nav-subtitle">基于DeepSeek的专业量化投资分析平台 | Multi-Agent Stock Analysis System</p>
</div>
""", unsafe_allow_html=True)
# 学习资源展示
st.info("📺 **新手必看干货**:为了在股市长久生存,建议您观看 👉 [股票知识讲解合集](https://www.bilibili.com/video/BV1Y2FGzzEeS/) 和 [投资认知提升合集](https://www.bilibili.com/video/BV1ugBMBAEbW) 👈,相信会对您有很大帮助!")
# 侧边栏
with st.sidebar:
# 快捷导航 - 移到顶部
st.markdown("### 🔍 功能导航")
# 🏠 单股分析(首页)
if st.button("🏠 股票分析", width='stretch', key="nav_home", help="返回首页,进行单只股票的深度分析"):
# 清除所有功能页面标志
for key in ['show_history', 'show_monitor', 'show_config', 'show_main_force',
'show_sector_strategy', 'show_longhubang', 'show_portfolio', 'show_low_price_bull', 'show_news_flow', 'show_macro_cycle', 'show_macro_analysis', 'show_value_stock']:
if key in st.session_state:
del st.session_state[key]
st.markdown("---")
# 🎯 选股板块
with st.expander("🎯 选股板块", expanded=True):
st.markdown("**根据不同策略筛选优质股票**")
if st.button("💰 主力选股", width='stretch', key="nav_main_force", help="基于主力资金流向的选股策略"):
st.session_state.show_main_force = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_sector_strategy',
'show_longhubang', 'show_portfolio', 'show_low_price_bull', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
if st.button("🐂 低价擒牛", width='stretch', key="nav_low_price_bull", help="低价高成长股票筛选策略"):
st.session_state.show_low_price_bull = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_sector_strategy',
'show_longhubang', 'show_portfolio', 'show_main_force', 'show_small_cap', 'show_profit_growth', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
if st.button("📊 小市值策略", width='stretch', key="nav_small_cap", help="小盘高成长股票筛选策略"):
st.session_state.show_small_cap = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_sector_strategy',
'show_longhubang', 'show_portfolio', 'show_main_force', 'show_low_price_bull', 'show_profit_growth', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
if st.button("📈 净利增长", width='stretch', key="nav_profit_growth", help="净利润增长稳健股票筛选策略"):
st.session_state.show_profit_growth = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_sector_strategy',
'show_longhubang', 'show_portfolio', 'show_main_force', 'show_low_price_bull', 'show_small_cap', 'show_news_flow', 'show_value_stock', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
if st.button("💎 低估值策略", width='stretch', key="nav_value_stock", help="低PE+低PB+高股息+低负债 价值投资筛选"):
st.session_state.show_value_stock = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_sector_strategy',
'show_longhubang', 'show_portfolio', 'show_main_force', 'show_low_price_bull', 'show_small_cap', 'show_profit_growth', 'show_news_flow', 'show_macro_cycle', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
# 📊 策略分析
with st.expander("📊 策略分析", expanded=True):
st.markdown("**AI驱动的板块和龙虎榜策略**")
if st.button("🎯 智策板块", width='stretch', key="nav_sector_strategy", help="AI板块策略分析"):
st.session_state.show_sector_strategy = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_main_force',
'show_longhubang', 'show_portfolio', 'show_smart_monitor', 'show_low_price_bull', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
if st.button("🐉 智瞰龙虎", width='stretch', key="nav_longhubang", help="龙虎榜深度分析"):
st.session_state.show_longhubang = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_main_force',
'show_sector_strategy', 'show_portfolio', 'show_smart_monitor', 'show_low_price_bull', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
if st.button("📰 新闻流量", width='stretch', key="nav_news_flow", help="新闻流量监测与短线指导"):
st.session_state.show_news_flow = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_main_force',
'show_sector_strategy', 'show_portfolio', 'show_smart_monitor', 'show_low_price_bull', 'show_longhubang', 'show_macro_cycle', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
if st.button("🌏 宏观分析", width='stretch', key="nav_macro_analysis", help="国家统计局宏观数据 × A股行业映射 × 优质标的"):
st.session_state.show_macro_analysis = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_main_force',
'show_sector_strategy', 'show_portfolio', 'show_smart_monitor', 'show_low_price_bull', 'show_longhubang', 'show_news_flow', 'show_macro_cycle']:
if key in st.session_state:
del st.session_state[key]
if st.button("🧭 宏观周期", width='stretch', key="nav_macro_cycle", help="康波周期 × 美林投资时钟 × 政策分析"):
st.session_state.show_macro_cycle = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_main_force',
'show_sector_strategy', 'show_portfolio', 'show_smart_monitor', 'show_low_price_bull', 'show_longhubang', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
# 💼 投资管理
with st.expander("💼 投资管理", expanded=True):
st.markdown("**持仓跟踪与实时监测**")
if st.button("📊 持仓分析", width='stretch', key="nav_portfolio", help="投资组合分析与定时跟踪"):
st.session_state.show_portfolio = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_main_force',
'show_sector_strategy', 'show_longhubang', 'show_smart_monitor', 'show_low_price_bull', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
if st.button("🤖 AI盯盘", width='stretch', key="nav_smart_monitor", help="DeepSeek AI自动盯盘决策交易(支持A股T+1)"):
st.session_state.show_smart_monitor = True
for key in ['show_history', 'show_monitor', 'show_config', 'show_main_force',
'show_sector_strategy', 'show_longhubang', 'show_portfolio', 'show_low_price_bull', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
if st.button("📡 实时监测", width='stretch', key="nav_monitor", help="价格监控与预警提醒"):
st.session_state.show_monitor = True
for key in ['show_history', 'show_main_force', 'show_longhubang', 'show_portfolio',
'show_config', 'show_sector_strategy', 'show_smart_monitor', 'show_low_price_bull', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
st.markdown("---")
# 📖 历史记录
if st.button("📖 历史记录", width='stretch', key="nav_history", help="查看历史分析记录"):
st.session_state.show_history = True
for key in ['show_monitor', 'show_longhubang', 'show_portfolio', 'show_config',
'show_main_force', 'show_sector_strategy', 'show_low_price_bull', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
# ⚙️ 环境配置
if st.button("⚙️ 环境配置", width='stretch', key="nav_config", help="系统设置与API配置"):
st.session_state.show_config = True
for key in ['show_history', 'show_monitor', 'show_main_force', 'show_sector_strategy',
'show_longhubang', 'show_portfolio', 'show_low_price_bull', 'show_news_flow', 'show_macro_analysis']:
if key in st.session_state:
del st.session_state[key]
st.markdown("---")
# 系统配置
st.markdown("### ⚙️ 系统配置")
# API密钥检查
api_key_status = check_api_key()
if api_key_status:
st.success("✅ API已连接")
else:
st.error("❌ API未配置")
st.caption("请在.env中配置API密钥")
st.markdown("---")
# 显示当前模型信息 + 可切换模型(issue #43:选择需持久化,刷新不丢)
show_current_model_info()
try:
from model_config import model_options
_options = list(model_options.keys())
if not _options:
_options = [config.DEFAULT_MODEL_NAME]
_current = st.session_state.get('selected_model') or config.DEFAULT_MODEL_NAME
if _current not in _options:
_options = [_current] + _options
_idx = _options.index(_current)
_picked = st.selectbox(
"分析模型",
options=_options,
index=_idx,
format_func=lambda x: model_options.get(x, x),
key="sidebar_model_picker",
help="选择后自动写入 .env 的 DEFAULT_MODEL_NAME,刷新后仍生效",
)
if _picked and _picked != config.DEFAULT_MODEL_NAME:
st.session_state.selected_model = _picked
# 持久化到 .env,避免刷新后回退默认模型
try:
from config_manager import config_manager as _cm
_cm.write_env({"DEFAULT_MODEL_NAME": _picked})
_cm.reload_config()
except Exception as _e:
st.caption(f"⚠️ 保存模型选择失败: {_e}")
else:
st.session_state.selected_model = _picked or config.DEFAULT_MODEL_NAME
except Exception:
st.session_state.selected_model = st.session_state.get(
'selected_model', config.DEFAULT_MODEL_NAME
)
st.markdown("---")
# 系统状态面板
st.markdown("### 📊 系统状态")
monitor_status = "🟢 运行中" if monitor_service.running else "🔴 已停止"
st.markdown(f"**监测服务**: {monitor_status}")
try:
from monitor_db import monitor_db
stocks = monitor_db.get_monitored_stocks()
notifications = monitor_db.get_pending_notifications()
record_count = db.get_record_count()
st.markdown(f"**分析记录**: {record_count}条")
st.markdown(f"**监测股票**: {len(stocks)}只")
st.markdown(f"**待处理**: {len(notifications)}条")
except:
pass
st.markdown("---")
# 分析参数设置
st.markdown("### 📊 分析参数")
period = st.selectbox(
"数据周期",
["1y", "6mo", "3mo", "1mo"],
index=0,
help="选择历史数据的时间范围"
)
st.markdown("---")
# 帮助信息
with st.expander("💡 使用帮助"):
st.markdown("""
**股票代码格式**
- 🇨🇳 A股:6位数字(如600519)
- 🇭🇰 港股:1-5位数字(如700、00700)或HK前缀(如HK00700)
- 🇺🇸 美股:字母代码(如AAPL)
**功能说明**
- **股票分析**:AI团队深度分析个股
- **选股板块**:主力资金选股策略
- **策略分析**:智策板块、智瞰龙虎
- **投资管理**:持仓分析、实时监测
- **历史记录**:查看分析历史
**AI分析流程**
1. 数据获取 → 2. 技术分析
3. 基本面分析 → 4. 资金分析
5. 情绪数据(ARBR) → 6. 新闻(qstock)
7. AI分析 → 8. 团队讨论 → 9. 决策
""")
# 学习资源
with st.expander("📺 学习视频合集"):
st.markdown("""
**📢 B站干货合集**
如果你希望能在股市中长久生存下去,建议你能把下面的合集看完,会对你有很大帮助的!
- 📚 [股票知识讲解合集](https://www.bilibili.com/video/BV1Y2FGzzEeS/)
- 🧠 [投资认知提升合集](https://www.bilibili.com/video/BV1ugBMBAEbW)
""")
# 检查是否显示历史记录
if 'show_history' in st.session_state and st.session_state.show_history:
display_history_records()
return
# 检查是否显示监测面板
if 'show_monitor' in st.session_state and st.session_state.show_monitor:
display_monitor_manager()
return
# 检查是否显示主力选股
if 'show_main_force' in st.session_state and st.session_state.show_main_force:
display_main_force_selector()
return
# 检查是否显示低价擒牛
if 'show_low_price_bull' in st.session_state and st.session_state.show_low_price_bull:
from low_price_bull_ui import display_low_price_bull
display_low_price_bull()
return
# 检查是否显示小市值策略
if 'show_small_cap' in st.session_state and st.session_state.show_small_cap:
from small_cap_ui import display_small_cap
display_small_cap()
return
# 检查是否显示净利增长策略
if 'show_profit_growth' in st.session_state and st.session_state.show_profit_growth:
from profit_growth_ui import display_profit_growth
display_profit_growth()
return
# 检查是否显示低估值策略
if 'show_value_stock' in st.session_state and st.session_state.show_value_stock:
from value_stock_ui import display_value_stock
display_value_stock()
return
# 检查是否显示智策板块
if 'show_sector_strategy' in st.session_state and st.session_state.show_sector_strategy:
display_sector_strategy()
return
# 检查是否显示智瞰龙虎
if 'show_longhubang' in st.session_state and st.session_state.show_longhubang:
display_longhubang()
return
# 检查是否显示AI盯盘
if 'show_smart_monitor' in st.session_state and st.session_state.show_smart_monitor:
smart_monitor_ui()
return
# 检查是否显示持仓分析
if 'show_portfolio' in st.session_state and st.session_state.show_portfolio:
from portfolio_ui import display_portfolio_manager
display_portfolio_manager()
return
# 检查是否显示新闻流量监测
if 'show_news_flow' in st.session_state and st.session_state.show_news_flow:
display_news_flow_monitor()
return
# 检查是否显示宏观分析
if 'show_macro_analysis' in st.session_state and st.session_state.show_macro_analysis:
from macro_analysis_ui import display_macro_analysis
display_macro_analysis()
return
# 检查是否显示宏观周期分析
if 'show_macro_cycle' in st.session_state and st.session_state.show_macro_cycle:
from macro_cycle_ui import display_macro_cycle
display_macro_cycle()
return
# 检查是否显示环境配置
if 'show_config' in st.session_state and st.session_state.show_config:
display_config_manager()
return
# 主界面
# 添加单个/批量分析切换
col_mode1, col_mode2 = st.columns([1, 3])
with col_mode1:
analysis_mode = st.radio(
"分析模式",
["单个分析", "批量分析"],
horizontal=True,
help="单个分析:分析单只股票;批量分析:同时分析多只股票"
)
with col_mode2:
if analysis_mode == "批量分析":
batch_mode = st.radio(
"批量模式",
["顺序分析", "多线程并行"],
horizontal=True,
help="顺序分析:按次序分析,稳定但较慢;多线程并行:同时分析多只,快速但消耗资源"
)
st.session_state.batch_mode = batch_mode
st.markdown("---")
if analysis_mode == "单个分析":
# 单个股票分析界面
col1, col2, col3 = st.columns([2, 1, 1])
with col1:
stock_input = st.text_input(
"🔍 请输入股票代码或名称",
placeholder="例如: AAPL, 000001, 00700",
help="支持A股(如000001)、港股(如00700)和美股(如AAPL)"
)
with col2:
analyze_button = st.button("🚀 开始分析", type="primary", width='stretch')
with col3:
if st.button("🔄 清除缓存", width='stretch'):
st.cache_data.clear()
st.success("缓存已清除")
else:
# 批量股票分析界面
stock_input = st.text_area(
"🔍 请输入多个股票代码(每行一个或用逗号分隔)",
placeholder="例如:\n000001\n600036\n00700\n\n或者: 000001, 600036, 00700, AAPL",
height=120,
help="支持多种格式:每行一个代码或用逗号分隔。支持A股、港股、美股"
)
col1, col2, col3 = st.columns(3)
with col1:
analyze_button = st.button("🚀 开始批量分析", type="primary", width='stretch')
with col2:
if st.button("🔄 清除缓存", width='stretch'):
st.cache_data.clear()
st.success("缓存已清除")
with col3:
if st.button("🗑️ 清除结果", width='stretch'):
if 'batch_analysis_results' in st.session_state:
del st.session_state.batch_analysis_results
st.success("已清除批量分析结果")
# 分析师团队选择
st.markdown("---")
st.subheader("👥 选择分析师团队")
col1, col2, col3 = st.columns(3)
with col1:
enable_technical = st.checkbox("📊 技术分析师", value=True,
help="负责技术指标分析、图表形态识别、趋势判断")
enable_fundamental = st.checkbox("💼 基本面分析师", value=True,
help="负责公司财务分析、行业研究、估值分析")
with col2:
enable_fund_flow = st.checkbox("💰 资金面分析师", value=True,
help="负责资金流向分析、主力行为研究")
enable_risk = st.checkbox("⚠️ 风险管理师", value=True,
help="负责风险识别、风险评估、风险控制策略制定")
with col3:
enable_sentiment = st.checkbox("📈 市场情绪分析师", value=True,
help="负责市场情绪研究、ARBR指标分析(仅A股)")
enable_news = st.checkbox("📰 新闻分析师", value=True,
help="负责新闻事件分析、舆情研究(仅A股,qstock数据源)")
# 显示已选择的分析师
selected_analysts = []
if enable_technical:
selected_analysts.append("技术分析师")
if enable_fundamental:
selected_analysts.append("基本面分析师")
if enable_fund_flow:
selected_analysts.append("资金面分析师")
if enable_risk:
selected_analysts.append("风险管理师")
if enable_sentiment:
selected_analysts.append("市场情绪分析师")
if enable_news:
selected_analysts.append("新闻分析师")
if selected_analysts:
st.info(f"✅ 已选择 {len(selected_analysts)} 位分析师: {', '.join(selected_analysts)}")
else:
st.warning("⚠️ 请至少选择一位分析师")
# 保存选择到session_state
st.session_state.enable_technical = enable_technical
st.session_state.enable_fundamental = enable_fundamental
st.session_state.enable_fund_flow = enable_fund_flow
st.session_state.enable_risk = enable_risk
st.session_state.enable_sentiment = enable_sentiment
st.session_state.enable_news = enable_news
st.markdown("---")
if analyze_button and stock_input:
if not api_key_status:
st.error("❌ 请先配置 DeepSeek API Key")
return
# 检查是否至少选择了一位分析师
if not selected_analysts:
st.error("❌ 请至少选择一位分析师参与分析")
return
if analysis_mode == "单个分析":
# 单个股票分析
# 清除之前的分析结果
if 'analysis_completed' in st.session_state:
del st.session_state.analysis_completed
if 'stock_info' in st.session_state:
del st.session_state.stock_info
if 'agents_results' in st.session_state:
del st.session_state.agents_results
if 'discussion_result' in st.session_state:
del st.session_state.discussion_result
if 'final_decision' in st.session_state:
del st.session_state.final_decision
if 'just_completed' in st.session_state:
del st.session_state.just_completed
run_stock_analysis(stock_input, period)
else:
# 批量股票分析
# 解析股票代码列表
stock_list = parse_stock_list(stock_input)
if not stock_list:
st.error("❌ 请输入有效的股票代码")
return
if len(stock_list) > 20:
st.warning(f"⚠️ 检测到 {len(stock_list)} 只股票,建议一次分析不超过20只")
st.info(f"📊 准备分析 {len(stock_list)} 只股票: {', '.join(stock_list)}")
# 清除之前的分析结果(包括单个和批量)
if 'batch_analysis_results' in st.session_state:
del st.session_state.batch_analysis_results
if 'analysis_completed' in st.session_state:
del st.session_state.analysis_completed
if 'stock_info' in st.session_state:
del st.session_state.stock_info
if 'agents_results' in st.session_state:
del st.session_state.agents_results
if 'discussion_result' in st.session_state:
del st.session_state.discussion_result
if 'final_decision' in st.session_state:
del st.session_state.final_decision
if 'just_completed' in st.session_state:
del st.session_state.just_completed
# 获取批量模式
batch_mode = st.session_state.get('batch_mode', '顺序分析')
# 运行批量分析
run_batch_analysis(stock_list, period, batch_mode)
# 检查是否有已完成的批量分析结果(优先显示批量结果)
if 'batch_analysis_results' in st.session_state and st.session_state.batch_analysis_results:
display_batch_analysis_results(st.session_state.batch_analysis_results, period)
# 检查是否有已完成的单个分析结果(但不是刚刚完成的,避免重复显示)
elif 'analysis_completed' in st.session_state and st.session_state.analysis_completed:
# 如果是刚刚完成的分析,清除标志,避免重复显示
if st.session_state.get('just_completed', False):
st.session_state.just_completed = False
else:
# 重新显示之前的分析结果(页面刷新后)
stock_info = st.session_state.stock_info
agents_results = st.session_state.agents_results
discussion_result = st.session_state.discussion_result
final_decision = st.session_state.final_decision
# 重新获取股票数据用于显示图表
stock_info_current, stock_data, indicators = get_stock_data(stock_info['symbol'], period)
# 显示股票基本信息
display_stock_info(stock_info, indicators)
# 显示股票图表
if stock_data is not None:
display_stock_chart(stock_data, stock_info)
# 显示各分析师报告
display_agents_analysis(agents_results)
# 显示团队讨论
display_team_discussion(discussion_result)
# 显示最终决策
display_final_decision(final_decision, stock_info, agents_results, discussion_result)
# 示例和说明
elif not stock_input:
show_example_interface()
def check_api_key():
"""检查API密钥是否配置"""
try:
import config
return bool(config.DEEPSEEK_API_KEY and config.DEEPSEEK_API_KEY.strip())
except:
return False
@st.cache_data(ttl=300) # 缓存5分钟
def get_stock_data(symbol, period):
"""获取股票数据(带缓存)"""
fetcher = StockDataFetcher()
stock_info = fetcher.get_stock_info(symbol)
stock_data = fetcher.get_stock_data(symbol, period)
if isinstance(stock_data, dict) and "error" in stock_data:
return stock_info, None, None
stock_data_with_indicators = fetcher.calculate_technical_indicators(stock_data)
indicators = fetcher.get_latest_indicators(stock_data_with_indicators)
return stock_info, stock_data_with_indicators, indicators
def parse_stock_list(stock_input):
"""解析股票代码列表
支持的格式:
- 每行一个代码
- 逗号分隔
- 空格分隔
"""
if not stock_input or not stock_input.strip():
return []
# 先按换行符分割
lines = stock_input.strip().split('\n')
# 处理每一行
stock_list = []
for line in lines:
line = line.strip()
if not line:
continue
# 检查是否包含逗号
if ',' in line:
codes = [code.strip() for code in line.split(',')]
stock_list.extend([code for code in codes if code])
# 检查是否包含空格
elif ' ' in line:
codes = [code.strip() for code in line.split()]
stock_list.extend([code for code in codes if code])
else:
stock_list.append(line)
# 去重并保持顺序;统一去掉 .SH/.SZ 等市场后缀,避免批量分析识别失败(issue #16)
try:
from stock_data import StockDataFetcher
normalize = StockDataFetcher.normalize_symbol
except Exception:
normalize = lambda x: x
seen = set()
unique_list = []
for code in stock_list:
code = normalize(code)
if code and code not in seen:
seen.add(code)
unique_list.append(code)
return unique_list
def analyze_single_stock_for_batch(symbol, period, enabled_analysts_config=None, selected_model=None):
"""单个股票分析(用于批量分析)
Args:
symbol: 股票代码
period: 数据周期
enabled_analysts_config: 分析师配置字典
selected_model: 选择的AI模型,默认从 .env 的 DEFAULT_MODEL_NAME 读取
返回分析结果或错误信息
"""
try:
# 统一去掉市场后缀(600519.SH -> 600519),避免数据源识别失败(issue #16)
try:
from stock_data import StockDataFetcher as _SDF
symbol = _SDF.normalize_symbol(symbol)
except Exception:
pass
# 使用默认模型
if selected_model is None:
selected_model = config.DEFAULT_MODEL_NAME
# 使用默认配置
if enabled_analysts_config is None:
enabled_analysts_config = {
'technical': True,
'fundamental': True,
'fund_flow': True,
'risk': True,
'sentiment': False,
'news': False
}
# 1. 获取股票数据
stock_info, stock_data, indicators = get_stock_data(symbol, period)
if "error" in stock_info:
return {"symbol": symbol, "error": stock_info['error'], "success": False}
if stock_data is None:
return {"symbol": symbol, "error": "无法获取股票历史数据", "success": False}
# 2. 获取财务数据
fetcher = StockDataFetcher()
financial_data = fetcher.get_financial_data(symbol)
# 2.5 获取季报数据(仅A股)
quarterly_data = None
enable_fundamental = enabled_analysts_config.get('fundamental', True)
if enable_fundamental and fetcher._is_chinese_stock(symbol):
try:
from quarterly_report_data import QuarterlyReportDataFetcher
quarterly_fetcher = QuarterlyReportDataFetcher()
quarterly_data = quarterly_fetcher.get_quarterly_reports(symbol)
except:
pass
# 获取分析师选择状态(从参数而不是session_state)
enable_fund_flow = enabled_analysts_config.get('fund_flow', True)
enable_sentiment = enabled_analysts_config.get('sentiment', False)
enable_news = enabled_analysts_config.get('news', False)
# 3. 获取资金流向数据(akshare数据源,可选)
fund_flow_data = None
if enable_fund_flow and fetcher._is_chinese_stock(symbol):
try:
from fund_flow_akshare import FundFlowAkshareDataFetcher
fund_flow_fetcher = FundFlowAkshareDataFetcher()
fund_flow_data = fund_flow_fetcher.get_fund_flow_data(symbol)
except:
pass
# 4. 获取市场情绪数据(可选)
sentiment_data = None
if enable_sentiment and fetcher._is_chinese_stock(symbol):
try:
from market_sentiment_data import MarketSentimentDataFetcher
sentiment_fetcher = MarketSentimentDataFetcher()
sentiment_data = sentiment_fetcher.get_market_sentiment_data(symbol, stock_data)
except:
pass
# 5. 获取新闻数据(qstock数据源,可选)
news_data = None
if enable_news and fetcher._is_chinese_stock(symbol):
try: