Spaces:
Runtime error
Runtime error
File size: 2,580 Bytes
d5b7ee9 | 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 | #!/usr/bin/env python
"""Quick test to verify signal generation works without errors."""
import pandas as pd
import numpy as np
from trading_cli.strategy.signals import (
volume_score,
calculate_atr,
sma_crossover_score,
rsi_score,
bollinger_score,
ema_score,
technical_score,
generate_signal,
)
# Create sample OHLCV data
np.random.seed(42)
dates = pd.date_range('2024-01-01', periods=100, freq='D')
ohlcv = pd.DataFrame({
'Date': dates,
'Open': np.random.uniform(100, 200, 100),
'High': np.random.uniform(150, 250, 100),
'Low': np.random.uniform(90, 190, 100),
'Close': np.random.uniform(100, 200, 100),
'Volume': np.random.randint(1000000, 10000000, 100),
})
print("Testing individual score functions...")
# Test volume_score
try:
vol = volume_score(ohlcv)
print(f"β volume_score: {vol:.3f}")
except Exception as e:
print(f"β volume_score FAILED: {e}")
# Test calculate_atr
try:
atr = calculate_atr(ohlcv)
print(f"β calculate_atr: {atr.iloc[-1]:.3f}")
except Exception as e:
print(f"β calculate_atr FAILED: {e}")
# Test sma_crossover_score
try:
sma = sma_crossover_score(ohlcv)
print(f"β sma_crossover_score: {sma:.3f}")
except Exception as e:
print(f"β sma_crossover_score FAILED: {e}")
# Test rsi_score
try:
rsi = rsi_score(ohlcv)
print(f"β rsi_score: {rsi:.3f}")
except Exception as e:
print(f"β rsi_score FAILED: {e}")
# Test bollinger_score
try:
bb = bollinger_score(ohlcv)
print(f"β bollinger_score: {bb:.3f}")
except Exception as e:
print(f"β bollinger_score FAILED: {e}")
# Test ema_score
try:
ema = ema_score(ohlcv)
print(f"β ema_score: {ema:.3f}")
except Exception as e:
print(f"β ema_score FAILED: {e}")
# Test technical_score
try:
tech = technical_score(ohlcv)
print(f"β technical_score: {tech:.3f}")
except Exception as e:
print(f"β technical_score FAILED: {e}")
# Test generate_signal
try:
signal = generate_signal(
symbol="AAPL",
ohlcv=ohlcv,
sentiment_score=0.5,
tech_weight=0.6,
sent_weight=0.4,
)
print(f"\nβ generate_signal:")
print(f" Symbol: {signal['symbol']}")
print(f" Action: {signal['action']}")
print(f" Confidence: {signal['confidence']:.3f}")
print(f" Hybrid Score: {signal['hybrid_score']:.3f}")
print(f" Reason: {signal['reason']}")
except Exception as e:
print(f"\nβ generate_signal FAILED: {e}")
import traceback
traceback.print_exc()
print("\nβ
All tests completed!")
|