StockRecommander / test_probability.py
54justin's picture
Create test_probability.py
fb6193f verified
#!/usr/bin/env python3
# 由 Copilot 生成 - 機率預測測試腳本
import sys
import os
# 添加當前目錄到 Python 路徑
sys.path.append(os.path.dirname(__file__))
def test_probability_calculation():
"""測試機率計算功能"""
print("🧪 測試機率計算功能...")
try:
# 模擬技術指標信號
test_signals = [
"價格在20日均線之上(多頭信號)",
"RSI(45.2) 正常範圍",
"MACD 呈現多頭排列"
]
test_sentiment = "偏樂觀"
# 模擬最近數據
import pandas as pd
import numpy as np
dates = pd.date_range('2024-01-01', periods=20, freq='D')
test_data = pd.DataFrame({
'Close': np.random.randn(20).cumsum() + 100,
'RSI': [45.2] * 20,
'MACD': [0.5] * 20,
'MACD_signal': [0.3] * 20
}, index=dates)
print("✅ 測試數據準備完成")
print(f"📊 技術信號數量: {len(test_signals)}")
print(f"💭 市場情感: {test_sentiment}")
print(f"📈 最新價格: ${test_data['Close'].iloc[-1]:.2f}")
return True
except Exception as e:
print(f"❌ 測試失敗: {e}")
return False
if __name__ == "__main__":
print("🚀 開始測試 AI 股票分析師機率預測功能...")
print("-" * 50)
success = test_probability_calculation()
print("-" * 50)
if success:
print("✅ 機率預測功能測試通過!")
print("💡 新功能已就緒:")
print(" • 📈 上漲機率百分比")
print(" • 📉 下跌機率百分比")
print(" • ➡️ 盤整機率百分比")
print(" • 🎯 信心度評估")
print(" • 📋 個性化投資建議")
else:
print("❌ 測試失敗,請檢查代碼")
print("\n🔍 可以運行 app.py 查看完整功能!")