# test_working_system.py - Test your working models
def test_working_models():
"""Test the working models without pmdarima."""
print("π Testing Working Trading Models")
print("=" * 50)
try:
# Test imports
from models.arima_model import get_arima_forecast, get_enhanced_arima_forecast
from models.hybrid_model import train_xgboost_on_residuals
print("β
Model imports successful")
# Test basic functionality
ticker = 'AAPL'
print(f"\nπ Testing with {ticker}...")
# Get ARIMA forecast
arima_forecast, residuals, df = get_arima_forecast(ticker)
print(f"β
ARIMA forecast: ${arima_forecast:.2f}")
# Train XGBoost on residuals
xgb_model, latest_features = train_xgboost_on_residuals(residuals, df)
# Make hybrid prediction
residual_correction = xgb_model.predict(latest_features)[0]
hybrid_forecast = arima_forecast + residual_correction
last_price = df['Close'].iloc[-1]
change = (hybrid_forecast - last_price) / last_price
print(f"\nπ RESULTS:")
print(f"β
Last price: ${last_price:.2f}")
print(f"β
ARIMA forecast: ${arima_forecast:.2f}")
print(f"β
Residual correction: {residual_correction:.4f}")
print(f"β
Hybrid forecast: ${hybrid_forecast:.2f}")
print(f"β
Expected change: {change:+.2%}")
# Generate signal
if change > 0.02:
signal = "π’ BUY"
elif change < -0.02:
signal = "π΄ SELL"
else:
signal = "π‘ HOLD"
print(f"β
Trading Signal: {signal}")
# Test enhanced version
print(f"\n㪠Testing Enhanced ARIMA...")
enhanced_results = get_enhanced_arima_forecast(ticker, n_periods=1)
if enhanced_results:
enhanced_forecast = enhanced_results['forecast_results']['forecasts'].iloc[0]
print(f"β
Enhanced ARIMA forecast: ${enhanced_forecast:.2f}")
print(f"β
Model diagnostics: RMSE={enhanced_results['diagnostics']['rmse']:.4f}")
print(f"\nπ ALL TESTS PASSED! Your trading system is ready.")
return True
except Exception as e:
print(f"β Test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_multiple_tickers():
"""Test with multiple tickers."""
print("\nπ Testing Multiple Tickers...")
print("-" * 40)
tickers = ['AAPL', 'MSFT', 'GOOGL']
results = []
for ticker in tickers:
try:
from models.arima_model import get_arima_forecast
from models.hybrid_model import train_xgboost_on_residuals
print(f"\nπ Analyzing {ticker}...")
arima_forecast, residuals, df = get_arima_forecast(ticker)
xgb_model, latest_features = train_xgboost_on_residuals(residuals, df)
residual_correction = xgb_model.predict(latest_features)[0]
hybrid_forecast = arima_forecast + residual_correction
last_price = df['Close'].iloc[-1]
change = (hybrid_forecast - last_price) / last_price
if change > 0.02:
signal = "BUY"
elif change < -0.02:
signal = "SELL"
else:
signal = "HOLD"
results.append({
'ticker': ticker,
'last_price': last_price,
'forecast': hybrid_forecast,
'change': change,
'signal': signal
})
print(f"β
{ticker}: {signal} ({change:+.2%})")
except Exception as e:
print(f"β {ticker} failed: {e}")
print(f"\nπ SUMMARY:")
print("-" * 40)
for result in results:
emoji = "π’" if result['signal'] == "BUY" else "π΄" if result['signal'] == "SELL" else "π‘"
print(f"{emoji} {result['ticker']}: ${result['last_price']:.2f} β ${result['forecast']:.2f} ({result['change']:+.2%})")
return len(results) == len(tickers)
if __name__ == "__main__":
print("π WORKING TRADING SYSTEM TEST")
print("=" * 60)
# Test single ticker
success1 = test_working_models()
if success1:
# Test multiple tickers
success2 = test_multiple_tickers()
if success2:
print(f"\nπ COMPLETE SUCCESS!")
print("Your trading system is fully operational.")
print("\nNext: Run the full enhanced main.py for comprehensive analysis!")
else:
print(f"\nβ οΈ Basic functionality works, some tickers had issues.")
else:
print(f"\nβ System needs debugging.")
print("Check that you've copied the model files correctly.")