-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreport_generator.py
More file actions
630 lines (547 loc) · 22.8 KB
/
report_generator.py
File metadata and controls
630 lines (547 loc) · 22.8 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
from datetime import datetime
def generate_html_report(recommendations, short_term_stocks):
"""生成HTML报告"""
html_content = f"""
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>智能选股系统 - 分析报告</title>
<style>
* {{
margin: 0;
padding: 0;
box-sizing: border-box;
}}
body {{
font-family: 'Microsoft YaHei', sans-serif;
line-height: 1.6;
color: #333;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}}
.container {{
max-width: 1400px;
margin: 0 auto;
background: white;
border-radius: 15px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
overflow: hidden;
}}
.header {{
background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
color: white;
padding: 30px;
text-align: center;
}}
.header h1 {{
font-size: 2.5em;
margin-bottom: 10px;
font-weight: 300;
}}
.header p {{
font-size: 1.1em;
opacity: 0.9;
}}
.stats {{
display: flex;
justify-content: space-around;
padding: 20px;
background: #f8f9fa;
border-bottom: 1px solid #eee;
}}
.stat-item {{
text-align: center;
flex: 1;
}}
.stat-number {{
font-size: 2em;
font-weight: bold;
color: #3498db;
display: block;
}}
.stat-label {{
color: #666;
font-size: 0.9em;
margin-top: 5px;
}}
.content {{
padding: 30px;
}}
.section-title {{
font-size: 1.8em;
color: #2c3e50;
margin-bottom: 20px;
text-align: center;
position: relative;
}}
.section-title::after {{
content: '';
position: absolute;
bottom: -10px;
left: 50%;
transform: translateX(-50%);
width: 80px;
height: 3px;
background: linear-gradient(90deg, #3498db, #2ecc71);
border-radius: 2px;
}}
.stock-grid {{
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
gap: 25px;
margin-top: 30px;
}}
.stock-card {{
background: white;
border-radius: 12px;
padding: 25px;
box-shadow: 0 8px 25px rgba(0,0,0,0.1);
transition: all 0.3s ease;
cursor: pointer;
border: 2px solid transparent;
position: relative;
overflow: hidden;
}}
.stock-card:hover {{
transform: translateY(-5px);
box-shadow: 0 15px 35px rgba(0,0,0,0.15);
border-color: #3498db;
}}
.stock-card::before {{
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
background: linear-gradient(90deg, #3498db, #2ecc71);
}}
.stock-header {{
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}}
.stock-name {{
font-size: 1.3em;
font-weight: bold;
color: #2c3e50;
}}
.stock-code {{
font-size: 0.9em;
color: #7f8c8d;
background: #ecf0f1;
padding: 4px 8px;
border-radius: 6px;
}}
.score-badge {{
background: linear-gradient(135deg, #e74c3c, #c0392b);
color: white;
padding: 8px 12px;
border-radius: 20px;
font-weight: bold;
font-size: 1.1em;
position: absolute;
top: 15px;
right: 15px;
}}
.score-badge.high {{
background: linear-gradient(135deg, #2ecc71, #27ae60);
}}
.score-badge.medium {{
background: linear-gradient(135deg, #f39c12, #e67e22);
}}
.stock-info {{
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
margin: 20px 0;
}}
.info-item {{
background: #f8f9fa;
padding: 10px;
border-radius: 8px;
text-align: center;
}}
.info-label {{
font-size: 0.8em;
color: #666;
margin-bottom: 5px;
}}
.info-value {{
font-weight: bold;
color: #2c3e50;
}}
.signals {{
margin: 15px 0;
}}
.signal-tag {{
display: inline-block;
background: #3498db;
color: white;
padding: 4px 10px;
border-radius: 15px;
font-size: 0.8em;
margin: 2px;
}}
.prediction {{
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
padding: 15px;
border-radius: 10px;
margin: 15px 0;
}}
.prediction-item {{
display: flex;
justify-content: space-between;
margin: 5px 0;
}}
.advice {{
text-align: center;
padding: 10px;
border-radius: 8px;
font-weight: bold;
color: white;
margin-top: 15px;
}}
.advice.strong {{
background: linear-gradient(135deg, #2ecc71, #27ae60);
}}
.advice.recommend {{
background: linear-gradient(135deg, #3498db, #2980b9);
}}
.advice.watch {{
background: linear-gradient(135deg, #f39c12, #e67e22);
}}
.advice.hold {{
background: linear-gradient(135deg, #95a5a6, #7f8c8d);
}}
.chart-modal {{
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.8);
z-index: 1000;
justify-content: center;
align-items: center;
}}
.chart-content {{
background: white;
padding: 20px;
border-radius: 10px;
max-width: 90%;
max-height: 90%;
overflow: auto;
position: relative;
}}
.close-btn {{
position: absolute;
top: 10px;
right: 15px;
font-size: 24px;
cursor: pointer;
color: #999;
z-index: 1001;
}}
.close-btn:hover {{
color: #333;
}}
.chart-image {{
max-width: 100%;
height: auto;
border-radius: 8px;
}}
.footer {{
text-align: center;
padding: 20px;
background: #2c3e50;
color: white;
font-size: 0.9em;
}}
@media (max-width: 768px) {{
.stock-grid {{
grid-template-columns: 1fr;
}}
.stock-info {{
grid-template-columns: 1fr;
}}
.stats {{
flex-direction: column;
gap: 15px;
}}
}}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🎯 智能选股分析系统</h1>
<p>基于多因子模型的股票投资建议 | 生成时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>
</div>
<div class="stats">
<div class="stat-item">
<span class="stat-number">{len(recommendations)}</span>
<div class="stat-label">综合推荐股票数</div>
</div>
<div class="stat-item">
<span class="stat-number">{len(short_term_stocks)}</span>
<div class="stat-label">短线推荐股票数</div>
</div>
<div class="stat-item">
<span class="stat-number">{len([r for r in recommendations if r['综合得分'] >= 70])}</span>
<div class="stat-label">强烈推荐</div>
</div>
<div class="stat-item">
<span class="stat-number">{len([r for r in recommendations if r['预测信息'] and r['预测信息']['置信度'] >= 70]) + len([r for r in short_term_stocks if r['预测信息'] and r['预测信息']['置信度'] >= 70])}</span>
<div class="stat-label">高置信度</div>
</div>
<div class="stat-item">
<span class="stat-number">{len([r for r in recommendations if '低风险' in r['投资建议']]) + len([r for r in short_term_stocks if '低风险' in r['投资建议']])}</span>
<div class="stat-label">低风险标的</div>
</div>
</div>
<div class="content">
<h2 class="section-title">📊 综合推荐股票列表(Top 15)</h2>
<div class="stock-grid">
"""
# 综合推荐循环
for i, stock in enumerate(recommendations):
score = stock['综合得分']
if score >= 70:
score_class = "high"
elif score >= 50:
score_class = "medium"
else:
score_class = "low"
advice = stock['投资建议']
if "强烈推荐" in advice:
advice_class = "strong"
elif "推荐" in advice:
advice_class = "recommend"
elif "关注" in advice:
advice_class = "watch"
else:
advice_class = "hold"
market_cap = stock['市值']
if market_cap >= 1e12:
market_cap_str = f"{market_cap/1e12:.1f}万亿"
elif market_cap >= 1e8:
market_cap_str = f"{market_cap/1e8:.1f}亿"
else:
market_cap_str = f"{market_cap/1e4:.1f}万"
prediction = stock.get('预测信息', {})
pred_5d = prediction.get('5日预测涨幅', 0)
pred_15d = prediction.get('15日预测涨幅', 0)
confidence = prediction.get('置信度', 0)
signals = stock.get('主要信号', [])
signals_html = ''.join([f'<span class="signal-tag">{signal}</span>' for signal in signals])
html_content += f"""
<div class="stock-card" onclick="showChart('{stock['股票代码']}')">
<div class="score-badge {score_class}">{score}分</div>
<div class="stock-header">
<div>
<div class="stock-name">{stock['股票名称']}</div>
<div class="stock-code">{stock['股票代码']}</div>
</div>
</div>
<div class="stock-info">
<div class="info-item">
<div class="info-label">当前价格</div>
<div class="info-value">¥{stock['当前价格']:.2f}</div>
</div>
<div class="info-item">
<div class="info-label">市值</div>
<div class="info-value">{market_cap_str}</div>
</div>
<div class="info-item">
<div class="info-label">换手率</div>
<div class="info-value">{stock['换手率']}%</div>
</div>
<div class="info-item">
<div class="info-label">波动率</div>
<div class="info-value">{stock['波动率']}%</div>
</div>
</div>
<div class="signals">
<div class="info-label">主要信号:</div>
{signals_html}
</div>
<div class="prediction">
<div class="prediction-item">
<span>5日预测:</span>
<span>{pred_5d:+.1f}%</span>
</div>
<div class="prediction-item">
<span>15日预测:</span>
<span>{pred_15d:+.1f}%</span>
</div>
<div class="prediction-item">
<span>置信度:</span>
<span>{confidence:.1f}%</span>
</div>
</div>
<div class="advice {advice_class}">
{advice}
</div>
</div>
"""
html_content += """
</div>
<h2 class="section-title">🚀 短线技术信号股票(Top 10-20)</h2>
<div class="stock-grid">
"""
# 短线推荐循环
for i, stock in enumerate(short_term_stocks):
score = stock['综合得分']
if score >= 70:
score_class = "high"
elif score >= 50:
score_class = "medium"
else:
score_class = "low"
advice = stock['投资建议']
if "强烈推荐" in advice:
advice_class = "strong"
elif "推荐" in advice:
advice_class = "recommend"
elif "关注" in advice:
advice_class = "watch"
else:
advice_class = "hold"
market_cap = stock['市值']
if market_cap >= 1e12:
market_cap_str = f"{market_cap/1e12:.1f}万亿"
elif market_cap >= 1e8:
market_cap_str = f"{market_cap/1e8:.1f}亿"
else:
market_cap_str = f"{market_cap/1e4:.1f}万"
prediction = stock.get('预测信息', {})
pred_5d = prediction.get('5日预测涨幅', 0)
pred_15d = prediction.get('15日预测涨幅', 0)
confidence = prediction.get('置信度', 0)
signals = stock.get('主要信号', [])
signals_html = ''.join([f'<span class="signal-tag">{signal}</span>' for signal in signals])
html_content += f"""
<div class="stock-card" onclick="showChart('{stock['股票代码']}')">
<div class="score-badge {score_class}">{score}分</div>
<div class="stock-header">
<div>
<div class="stock-name">{stock['股票名称']}</div>
<div class="stock-code">{stock['股票代码']}</div>
</div>
</div>
<div class="stock-info">
<div class="info-item">
<div class="info-label">当前价格</div>
<div class="info-value">¥{stock['当前价格']:.2f}</div>
</div>
<div class="info-item">
<div class="info-label">市值</div>
<div class="info-value">{market_cap_str}</div>
</div>
<div class="info-item">
<div class="info-label">换手率</div>
<div class="info-value">{stock['换手率']}%</div>
</div>
<div class="info-item">
<div class="info-label">波动率</div>
<div class="info-value">{stock['波动率']}%</div>
</div>
</div>
<div class="signals">
<div class="info-label">主要信号:</div>
{signals_html}
</div>
<div class="prediction">
<div class="prediction-item">
<span>5日预测:</span>
<span>{pred_5d:+.1f}%</span>
</div>
<div class="prediction-item">
<span>15日预测:</span>
<span>{pred_15d:+.1f}%</span>
</div>
<div class="prediction-item">
<span>置信度:</span>
<span>{confidence:.1f}%</span>
</div>
</div>
<div class="advice {advice_class}">
{advice}
</div>
</div>
"""
html_content += """
</div>
</div>
<div class="chart-modal" id="chartModal">
<div class="chart-content">
<span class="close-btn" onclick="closeChart()">×</span>
<div id="chartContainer"></div>
</div>
</div>
<div class="footer">
<p>⚠️ 投资有风险,入市需谨慎。本系统仅供参考,不构成投资建议。</p>
<p>数据来源:股票历史数据 | 技术支持:Python量化分析</p>
</div>
<script>
function showChart(stockCode) {
const modal = document.getElementById('chartModal');
const container = document.getElementById('chartContainer');
container.innerHTML = `
<div style="text-align: center; padding: 50px;">
<h2>${stockCode} K线图</h2>
<p>正在加载K线图数据...</p>
<div style="margin-top: 20px;">
<div style="width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; animation: spin 2s linear infinite; margin: 0 auto;"></div>
</div>
</div>
<style>
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
`;
modal.style.display = 'flex';
setTimeout(() => {
loadKLineChart(stockCode);
}, 1000);
}
function loadKLineChart(stockCode) {
const container = document.getElementById('chartContainer');
container.innerHTML = `
<h2 style="text-align: center; margin-bottom: 20px;">${stockCode} K线图</h2>
<div style="text-align: center; padding: 20px; background: #f8f9fa; border-radius: 8px;">
<p>📈 K线图功能需要与后端API集成</p>
<p>点击下方按钮查看详细分析</p>
<button onclick="alert('功能开发中...')" style="margin-top: 15px; padding: 10px 20px; background: #3498db; color: white; border: none; border-radius: 5px; cursor: pointer;">
查看详细分析
</button>
</div>
`;
}
function closeChart() {
document.getElementById('chartModal').style.display = 'none';
}
document.getElementById('chartModal').onclick = function(e) {
if (e.target === this) {
closeChart();
}
}
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeChart();
}
});
</script>
</body>
</html>
"""
return html_content