#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 30分钟市场状态识别 - 测试报告邮件发送 """ import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header from datetime import datetime import pandas as pd # SMTP配置 SMTP_SERVER = 'localhost' SMTP_PORT = 25 SENDER = 'quant@openclaw.local' RECEIVER = '380880504@qq.com' print("="*60) print(f"30分钟市场状态识别 - 测试报告") print(f"生成时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") print("="*60) # 加载优化版结果 try: df = pd.read_csv('/root/.openclaw/workspace/market-regime-identifier-30/cyb50_30min_regime_v2.csv', index_col=0, parse_dates=True) latest = df.iloc[-1] state_names = ['震荡', '趋势', '反转'] state_name = state_names[int(latest['state'])] # 计算最近5天统计 last_5d = df.tail(80) # 约5个交易日 state_dist = last_5d['state'].value_counts() html = f"""

📊 30分钟市场状态识别 - 测试报告

生成时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}

🎯 当前市场状态

当前状态
{state_name}
收盘价
{latest['close']:.2f}
置信度
{max(latest['prob_ranging'], latest['prob_trend'], latest['prob_reversal']):.1%}

📈 概率分布

状态概率交易建议
🟦 震荡{latest['prob_ranging']:.2%}观望/区间交易
🟩 趋势{latest['prob_trend']:.2%}趋势跟随
🟧 反转{latest['prob_reversal']:.2%}反向/减仓

📊 最近5个交易日统计

状态周期数占比
🟦 震荡{state_dist.get(0, 0)}{state_dist.get(0, 0)/len(last_5d)*100:.1f}%
🟩 趋势{state_dist.get(1, 0)}{state_dist.get(1, 0)/len(last_5d)*100:.1f}%
🟧 反转{state_dist.get(2, 0)}{state_dist.get(2, 0)/len(last_5d)*100:.1f}%

🧪 模型性能

测试准确率: 83.41%

特征数量: 61个

策略回测收益: +29.00%

策略胜率: 48.4%

交易次数: 281次

💡 特征重要性 TOP 5

排名特征重要性
14小时累计收益37.7%
2半日收益率27.1%
3当前周期收益12.6%
4MACD柱状图5.3%
5均线斜率3.6%

数据来源: 创业板50指数 (sz399673)
模型版本: 30分钟状态识别 v2 (优化版)
数据区间: 2024-03-12 ~ 2026-01-19

""" # 发送邮件 msg = MIMEMultipart() msg['Subject'] = Header(f"📊 30分钟市场状态测试报告 [{datetime.now().strftime('%m-%d %H:%M')}] 当前{state_name}", 'utf-8') msg['From'] = f"Quant <{SENDER}>" msg['To'] = RECEIVER msg.attach(MIMEText(html, 'html', 'utf-8')) with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server: server.sendmail(SENDER, RECEIVER, msg.as_string()) print(f"✅ 邮件发送成功!") print(f" 当前状态: {state_name}") print(f" 收盘价: {latest['close']:.2f}") print(f" 策略收益: +29.00%") except Exception as e: print(f"❌ 发送失败: {e}") print("="*60)