init repo
This commit is contained in:
182
run_analysis.py
Normal file
182
run_analysis.py
Normal file
@@ -0,0 +1,182 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
美股分析系统启动脚本
|
||||
提供交互式界面进行股票分析
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
from main import StockAnalysisSystem
|
||||
|
||||
def print_banner():
|
||||
"""打印系统横幅"""
|
||||
banner = """
|
||||
╔══════════════════════════════════════════════════════════════╗
|
||||
║ 美股低价值公司分析系统 ║
|
||||
║ US Stock Value Analysis ║
|
||||
╚══════════════════════════════════════════════════════════════╝
|
||||
"""
|
||||
print(banner)
|
||||
|
||||
def print_menu():
|
||||
"""打印主菜单"""
|
||||
menu = """
|
||||
请选择操作:
|
||||
|
||||
1. 分析单只股票 (完整分析)
|
||||
2. 快速筛选股票 (检查是否符合低价值标准)
|
||||
3. 批量分析多只股票
|
||||
4. 查看历史分析结果
|
||||
5. 系统测试
|
||||
6. 退出
|
||||
|
||||
请输入选项 (1-6): """
|
||||
return input(menu).strip()
|
||||
|
||||
def analyze_single_stock():
|
||||
"""分析单只股票"""
|
||||
symbol = input("请输入股票代码 (如: AAPL): ").strip().upper()
|
||||
if not symbol:
|
||||
print("❌ 股票代码不能为空")
|
||||
return
|
||||
|
||||
print(f"\n🔍 正在分析 {symbol}...")
|
||||
print("⏳ 这可能需要2-3分钟,请耐心等待...")
|
||||
|
||||
system = StockAnalysisSystem()
|
||||
result = system.analyze_stock(symbol)
|
||||
|
||||
if 'error' in result:
|
||||
print(f"❌ 分析失败: {result['error']}")
|
||||
else:
|
||||
print(f"\n✅ {symbol} 分析完成!")
|
||||
print(f"📊 投资建议: {result.get('recommendation', 'N/A')}")
|
||||
print(f"🎯 综合评分: {result.get('overall_score', 0):.1f}/100")
|
||||
|
||||
recommendation = result.get('investment_recommendation', {})
|
||||
if recommendation.get('key_strengths'):
|
||||
print("\n💪 关键优势:")
|
||||
for strength in recommendation['key_strengths']:
|
||||
print(f" • {strength}")
|
||||
|
||||
if recommendation.get('key_concerns'):
|
||||
print("\n⚠️ 关键担忧:")
|
||||
for concern in recommendation['key_concerns']:
|
||||
print(f" • {concern}")
|
||||
|
||||
if result.get('report_file'):
|
||||
print(f"\n📄 详细报告: {result['report_file']}")
|
||||
if result.get('summary_file'):
|
||||
print(f"📝 简要报告: {result['summary_file']}")
|
||||
|
||||
def quick_screen_stock():
|
||||
"""快速筛选股票"""
|
||||
symbol = input("请输入股票代码 (如: AAPL): ").strip().upper()
|
||||
if not symbol:
|
||||
print("❌ 股票代码不能为空")
|
||||
return
|
||||
|
||||
print(f"\n🔍 正在快速筛选 {symbol}...")
|
||||
|
||||
system = StockAnalysisSystem()
|
||||
result = system.quick_screening(symbol)
|
||||
|
||||
if 'error' in result:
|
||||
print(f"❌ 筛选失败: {result['error']}")
|
||||
else:
|
||||
print(f"\n📋 {symbol} 筛选结果:")
|
||||
print(f"🏢 公司名称: {result.get('company_name', 'N/A')}")
|
||||
print(f"💰 市值: ${result.get('market_cap', 0):,.0f}")
|
||||
|
||||
if result.get('passes_screening'):
|
||||
print("✅ 通过低价值投资筛选")
|
||||
else:
|
||||
print("❌ 未通过低价值投资筛选")
|
||||
|
||||
if result.get('criteria_met'):
|
||||
print("\n✅ 符合条件:")
|
||||
for criteria in result['criteria_met']:
|
||||
print(f" • {criteria}")
|
||||
|
||||
if result.get('criteria_failed'):
|
||||
print("\n❌ 不符合条件:")
|
||||
for criteria in result['criteria_failed']:
|
||||
print(f" • {criteria}")
|
||||
|
||||
def batch_analyze_stocks():
|
||||
"""批量分析股票"""
|
||||
symbols_input = input("请输入股票代码,用逗号分隔 (如: AAPL,MSFT,GOOGL): ").strip()
|
||||
if not symbols_input:
|
||||
print("❌ 股票代码不能为空")
|
||||
return
|
||||
|
||||
symbols = [s.strip().upper() for s in symbols_input.split(',')]
|
||||
print(f"\n🔍 正在批量分析 {len(symbols)} 只股票...")
|
||||
print("⏳ 这可能需要较长时间,请耐心等待...")
|
||||
|
||||
system = StockAnalysisSystem()
|
||||
results = system.batch_analysis(symbols)
|
||||
|
||||
print(f"\n📊 批量分析结果:")
|
||||
print("=" * 60)
|
||||
|
||||
for symbol, result in results.items():
|
||||
if 'error' in result:
|
||||
print(f"❌ {symbol}: {result['error']}")
|
||||
else:
|
||||
recommendation = result.get('recommendation', 'N/A')
|
||||
score = result.get('overall_score', 0)
|
||||
print(f"📈 {symbol}: {recommendation} (评分: {score:.1f})")
|
||||
|
||||
def view_history():
|
||||
"""查看历史分析结果"""
|
||||
print("\n📚 历史分析结果功能开发中...")
|
||||
print("💡 提示: 分析结果已保存在数据库中,详细报告在 reports/ 目录下")
|
||||
|
||||
def run_system_test():
|
||||
"""运行系统测试"""
|
||||
print("\n🧪 正在运行系统测试...")
|
||||
|
||||
try:
|
||||
from test_system import main as test_main
|
||||
test_main()
|
||||
except ImportError:
|
||||
print("❌ 测试模块未找到")
|
||||
except Exception as e:
|
||||
print(f"❌ 测试失败: {e}")
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
print_banner()
|
||||
|
||||
while True:
|
||||
try:
|
||||
choice = print_menu()
|
||||
|
||||
if choice == '1':
|
||||
analyze_single_stock()
|
||||
elif choice == '2':
|
||||
quick_screen_stock()
|
||||
elif choice == '3':
|
||||
batch_analyze_stocks()
|
||||
elif choice == '4':
|
||||
view_history()
|
||||
elif choice == '5':
|
||||
run_system_test()
|
||||
elif choice == '6':
|
||||
print("\n👋 感谢使用美股分析系统!")
|
||||
break
|
||||
else:
|
||||
print("❌ 无效选项,请重新选择")
|
||||
|
||||
input("\n按回车键继续...")
|
||||
print("\n" + "="*60)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n\n👋 程序已退出")
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"\n❌ 发生错误: {e}")
|
||||
input("按回车键继续...")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user