191 lines
5.9 KiB
Python
191 lines
5.9 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
Phase 3 Test Runner
|
||
|
|
|
||
|
|
This script runs all Phase 3 testing and validation tests and provides
|
||
|
|
a comprehensive summary report.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
import time
|
||
|
|
from typing import Dict, Any
|
||
|
|
|
||
|
|
# Add the project root to Python path
|
||
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
|
|
||
|
|
# Import test modules
|
||
|
|
from test_strategy_timeframes import run_integration_tests
|
||
|
|
from test_backtest_validation import run_backtest_validation
|
||
|
|
from test_realtime_simulation import run_realtime_simulation
|
||
|
|
|
||
|
|
|
||
|
|
def run_all_phase3_tests() -> Dict[str, Any]:
|
||
|
|
"""Run all Phase 3 tests and return results."""
|
||
|
|
print("🚀 PHASE 3: TESTING AND VALIDATION")
|
||
|
|
print("=" * 80)
|
||
|
|
print("Running comprehensive tests for timeframe aggregation fix...")
|
||
|
|
print()
|
||
|
|
|
||
|
|
results = {}
|
||
|
|
start_time = time.time()
|
||
|
|
|
||
|
|
# Task 3.1: Integration Tests
|
||
|
|
print("📋 Task 3.1: Integration Tests")
|
||
|
|
print("-" * 50)
|
||
|
|
task1_start = time.time()
|
||
|
|
try:
|
||
|
|
task1_success = run_integration_tests()
|
||
|
|
task1_time = time.time() - task1_start
|
||
|
|
results['task_3_1'] = {
|
||
|
|
'name': 'Integration Tests',
|
||
|
|
'success': task1_success,
|
||
|
|
'duration': task1_time,
|
||
|
|
'error': None
|
||
|
|
}
|
||
|
|
except Exception as e:
|
||
|
|
task1_time = time.time() - task1_start
|
||
|
|
results['task_3_1'] = {
|
||
|
|
'name': 'Integration Tests',
|
||
|
|
'success': False,
|
||
|
|
'duration': task1_time,
|
||
|
|
'error': str(e)
|
||
|
|
}
|
||
|
|
print(f"❌ Task 3.1 failed with error: {e}")
|
||
|
|
|
||
|
|
print("\n" + "="*80 + "\n")
|
||
|
|
|
||
|
|
# Task 3.2: Backtest Validation
|
||
|
|
print("📋 Task 3.2: Backtest Validation")
|
||
|
|
print("-" * 50)
|
||
|
|
task2_start = time.time()
|
||
|
|
try:
|
||
|
|
task2_success = run_backtest_validation()
|
||
|
|
task2_time = time.time() - task2_start
|
||
|
|
results['task_3_2'] = {
|
||
|
|
'name': 'Backtest Validation',
|
||
|
|
'success': task2_success,
|
||
|
|
'duration': task2_time,
|
||
|
|
'error': None
|
||
|
|
}
|
||
|
|
except Exception as e:
|
||
|
|
task2_time = time.time() - task2_start
|
||
|
|
results['task_3_2'] = {
|
||
|
|
'name': 'Backtest Validation',
|
||
|
|
'success': False,
|
||
|
|
'duration': task2_time,
|
||
|
|
'error': str(e)
|
||
|
|
}
|
||
|
|
print(f"❌ Task 3.2 failed with error: {e}")
|
||
|
|
|
||
|
|
print("\n" + "="*80 + "\n")
|
||
|
|
|
||
|
|
# Task 3.3: Real-Time Simulation
|
||
|
|
print("📋 Task 3.3: Real-Time Simulation")
|
||
|
|
print("-" * 50)
|
||
|
|
task3_start = time.time()
|
||
|
|
try:
|
||
|
|
task3_success = run_realtime_simulation()
|
||
|
|
task3_time = time.time() - task3_start
|
||
|
|
results['task_3_3'] = {
|
||
|
|
'name': 'Real-Time Simulation',
|
||
|
|
'success': task3_success,
|
||
|
|
'duration': task3_time,
|
||
|
|
'error': None
|
||
|
|
}
|
||
|
|
except Exception as e:
|
||
|
|
task3_time = time.time() - task3_start
|
||
|
|
results['task_3_3'] = {
|
||
|
|
'name': 'Real-Time Simulation',
|
||
|
|
'success': False,
|
||
|
|
'duration': task3_time,
|
||
|
|
'error': str(e)
|
||
|
|
}
|
||
|
|
print(f"❌ Task 3.3 failed with error: {e}")
|
||
|
|
|
||
|
|
total_time = time.time() - start_time
|
||
|
|
results['total_duration'] = total_time
|
||
|
|
|
||
|
|
return results
|
||
|
|
|
||
|
|
|
||
|
|
def print_phase3_summary(results: Dict[str, Any]):
|
||
|
|
"""Print comprehensive summary of Phase 3 results."""
|
||
|
|
print("\n" + "="*80)
|
||
|
|
print("🎯 PHASE 3 COMPREHENSIVE SUMMARY")
|
||
|
|
print("="*80)
|
||
|
|
|
||
|
|
# Task results
|
||
|
|
all_passed = True
|
||
|
|
for task_key, task_result in results.items():
|
||
|
|
if task_key == 'total_duration':
|
||
|
|
continue
|
||
|
|
|
||
|
|
status = "✅ PASSED" if task_result['success'] else "❌ FAILED"
|
||
|
|
duration = task_result['duration']
|
||
|
|
|
||
|
|
print(f"{task_result['name']:<25} {status:<12} {duration:>8.2f}s")
|
||
|
|
|
||
|
|
if not task_result['success']:
|
||
|
|
all_passed = False
|
||
|
|
if task_result['error']:
|
||
|
|
print(f" Error: {task_result['error']}")
|
||
|
|
|
||
|
|
print("-" * 80)
|
||
|
|
print(f"Total Duration: {results['total_duration']:.2f}s")
|
||
|
|
|
||
|
|
# Overall status
|
||
|
|
if all_passed:
|
||
|
|
print("\n🎉 PHASE 3 COMPLETED SUCCESSFULLY!")
|
||
|
|
print("✅ All timeframe aggregation tests PASSED")
|
||
|
|
print("\n🔧 Verified Capabilities:")
|
||
|
|
print(" ✓ No future data leakage")
|
||
|
|
print(" ✓ Correct signal timing at timeframe boundaries")
|
||
|
|
print(" ✓ Multi-strategy compatibility")
|
||
|
|
print(" ✓ Bounded memory usage")
|
||
|
|
print(" ✓ Mathematical correctness (matches pandas)")
|
||
|
|
print(" ✓ Performance benchmarks met")
|
||
|
|
print(" ✓ Realistic trading results")
|
||
|
|
print(" ✓ Aggregation consistency")
|
||
|
|
print(" ✓ Real-time processing capability")
|
||
|
|
print(" ✓ Latency requirements met")
|
||
|
|
|
||
|
|
print("\n🚀 READY FOR PRODUCTION:")
|
||
|
|
print(" • New timeframe aggregation system is fully validated")
|
||
|
|
print(" • All strategies work correctly with new utilities")
|
||
|
|
print(" • Real-time performance meets requirements")
|
||
|
|
print(" • Memory usage is bounded and efficient")
|
||
|
|
print(" • No future data leakage detected")
|
||
|
|
|
||
|
|
else:
|
||
|
|
print("\n❌ PHASE 3 INCOMPLETE")
|
||
|
|
print("Some tests failed - review errors above")
|
||
|
|
|
||
|
|
failed_tasks = [task['name'] for task in results.values()
|
||
|
|
if isinstance(task, dict) and not task.get('success', True)]
|
||
|
|
if failed_tasks:
|
||
|
|
print(f"Failed tasks: {', '.join(failed_tasks)}")
|
||
|
|
|
||
|
|
print("\n" + "="*80)
|
||
|
|
|
||
|
|
return all_passed
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
"""Main execution function."""
|
||
|
|
print("Starting Phase 3: Testing and Validation...")
|
||
|
|
print("This will run comprehensive tests to validate the timeframe aggregation fix.")
|
||
|
|
print()
|
||
|
|
|
||
|
|
# Run all tests
|
||
|
|
results = run_all_phase3_tests()
|
||
|
|
|
||
|
|
# Print summary
|
||
|
|
success = print_phase3_summary(results)
|
||
|
|
|
||
|
|
# Exit with appropriate code
|
||
|
|
sys.exit(0 if success else 1)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|