# scripts/quick_test.py - Fixed import paths
import sys
import os
from pathlib import Path
# Add the project root to Python path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
def test_system_simple():
"""Simple test with proper type conversions."""
print("๐ QUICK SYSTEM TEST")
print("=" * 40)
try:
# Now imports should work
from models.arima_model import get_arima_forecast
from models.hybrid_model import train_xgboost_on_residuals
print("โ
Successfully imported models")
ticker = 'AAPL'
print(f"Testing {ticker}...")
# Get ARIMA forecast
arima_forecast, residuals, df = get_arima_forecast(ticker)
# Train XGBoost (will use fallback if enhanced fails)
xgb_model, latest_features = train_xgboost_on_residuals(residuals, df)
# Make prediction with proper type conversion
residual_correction = float(xgb_model.predict(latest_features)[0])
hybrid_forecast = float(arima_forecast) + residual_correction
last_price = float(df['Close'].iloc[-1])
change = (hybrid_forecast - last_price) / last_price
print(f"โ
Last price: ${last_price:.2f}")
print(f"โ
ARIMA forecast: ${float(arima_forecast):.2f}")
print(f"โ
Residual correction: {residual_correction:.4f}")
print(f"โ
Hybrid forecast: ${hybrid_forecast:.2f}")
print(f"โ
Expected change: {change:+.2%}")
# Signal
if change > 0.02:
signal = "๐ข BUY"
elif change < -0.02:
signal = "๐ด SELL"
else:
signal = "๐ก HOLD"
print(f"โ
Trading Signal: {signal}")
print(f"\n๐ SYSTEM WORKING!")
return True
except Exception as e:
print(f"โ Error: {e}")
import traceback
traceback.print_exc()
return False
def test_imports():
"""Test that all required modules can be imported."""
print("\n๐ TESTING IMPORTS")
print("-" * 30)
imports_to_test = [
('yfinance', 'yfinance'),
('pandas', 'pandas'),
('numpy', 'numpy'),
('sklearn', 'sklearn'),
('xgboost', 'xgboost'),
('statsmodels', 'statsmodels'),
('models.arima_model', 'models.arima_model'),
('models.hybrid_model', 'models.hybrid_model')
]
success_count = 0
for display_name, import_name in imports_to_test:
try:
__import__(import_name)
print(f"โ
{display_name}: Available")
success_count += 1
except ImportError as e:
print(f"โ {display_name}: Missing ({e})")
print(f"\n๐ Import Success: {success_count}/{len(imports_to_test)}")
return success_count == len(imports_to_test)
def test_project_structure():
"""Test that the project structure is correct."""
print("\n๐ TESTING PROJECT STRUCTURE")
print("-" * 30)
required_paths = [
'models/__init__.py',
'models/arima_model.py',
'models/hybrid_model.py',
'config',
'src',
'results',
'scripts'
]
missing_paths = []
for path in required_paths:
full_path = project_root / path
if full_path.exists():
print(f"โ
{path}: Found")
else:
print(f"โ {path}: Missing")
missing_paths.append(path)
if missing_paths:
print(f"\nโ ๏ธ Missing paths: {', '.join(missing_paths)}")
return False
else:
print(f"\nโ
All required paths found")
return True
def main():
"""Run comprehensive tests."""
print("๐งช COMPREHENSIVE SYSTEM TEST")
print("=" * 50)
print(f"๐ Project root: {project_root}")
print(f"๐ Current working directory: {os.getcwd()}")
# Test 1: Project structure
structure_ok = test_project_structure()
# Test 2: Imports
imports_ok = test_imports()
# Test 3: Core functionality (only if imports work)
if imports_ok:
functionality_ok = test_system_simple()
else:
print("\nโ ๏ธ Skipping functionality test due to import failures")
functionality_ok = False
# Summary
print("\n" + "=" * 50)
print("๐ TEST SUMMARY")
print("=" * 50)
if structure_ok and imports_ok and functionality_ok:
print("๐ ALL TESTS PASSED!")
print("โ
Project structure: OK")
print("โ
Module imports: OK")
print("โ
Core functionality: OK")
print("\n๐ Your enhanced trading system is ready!")
else:
print("โ ๏ธ SOME TESTS FAILED:")
print(f" Project structure: {'โ
' if structure_ok else 'โ'}")
print(f" Module imports: {'โ
' if imports_ok else 'โ'}")
print(f" Core functionality: {'โ
' if functionality_ok else 'โ'}")
if not structure_ok:
print("\n๐ง Fix: Run 'python scripts/setup_environment.py'")
if not imports_ok:
print("\n๐ง Fix: Check that model files exist in models/")
if not functionality_ok and imports_ok:
print("\n๐ง Fix: Check model implementation")
if __name__ == "__main__":
main()