File size: 5,456 Bytes
859af74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
"""
Demonstration script for the Algorithmic Trading System

This script demonstrates the key features of the system:
- Synthetic data generation
- Trading workflow execution
- Backtesting
- Logging
"""

import yaml
import pandas as pd
from agentic_ai_system.synthetic_data_generator import SyntheticDataGenerator
from agentic_ai_system.logger_config import setup_logging
from agentic_ai_system.orchestrator import run, run_backtest
from agentic_ai_system.main import load_config

def main():
    """Main demonstration function"""
    print("πŸš€ Algorithmic Trading System Demo")
    print("=" * 50)
    
    # Load configuration
    try:
        config = load_config()
        print("βœ… Configuration loaded successfully")
    except Exception as e:
        print(f"❌ Error loading configuration: {e}")
        return
    
    # Setup logging
    setup_logging(config)
    print("βœ… Logging system initialized")
    
    # Demo 1: Synthetic Data Generation
    print("\nπŸ“Š Demo 1: Synthetic Data Generation")
    print("-" * 30)
    
    try:
        generator = SyntheticDataGenerator(config)
        
        # Generate OHLCV data
        print("Generating OHLCV data...")
        ohlcv_data = generator.generate_ohlcv_data(
            symbol='AAPL',
            start_date='2024-01-01',
            end_date='2024-01-02',
            frequency='1H'
        )
        print(f"βœ… Generated {len(ohlcv_data)} OHLCV data points")
        
        # Show sample data
        print("\nSample OHLCV data:")
        print(ohlcv_data.head())
        
        # Generate different market scenarios
        print("\nGenerating market scenarios...")
        scenarios = ['normal', 'volatile', 'trending', 'crash']
        
        for scenario in scenarios:
            scenario_data = generator.generate_market_scenarios(scenario)
            avg_price = scenario_data['close'].mean()
            print(f"  {scenario.capitalize()} market: {len(scenario_data)} points, avg price: ${avg_price:.2f}")
        
    except Exception as e:
        print(f"❌ Error in synthetic data generation: {e}")
    
    # Demo 2: Trading Workflow
    print("\nπŸ€– Demo 2: Trading Workflow")
    print("-" * 30)
    
    try:
        print("Running trading workflow...")
        result = run(config)
        
        if result['success']:
            print("βœ… Trading workflow completed successfully")
            print(f"  Data loaded: {result['data_loaded']}")
            print(f"  Signal generated: {result['signal_generated']}")
            print(f"  Order executed: {result['order_executed']}")
            print(f"  Execution time: {result['execution_time']:.2f} seconds")
            
            if result['order_executed'] and result['execution_result']:
                exec_result = result['execution_result']
                print(f"  Order details: {exec_result['action']} {exec_result['quantity']} {exec_result['symbol']} @ ${exec_result['price']:.2f}")
        else:
            print("❌ Trading workflow failed")
            print(f"  Errors: {result['errors']}")
            
    except Exception as e:
        print(f"❌ Error in trading workflow: {e}")
    
    # Demo 3: Backtesting
    print("\nπŸ“ˆ Demo 3: Backtesting")
    print("-" * 30)
    
    try:
        print("Running backtest...")
        backtest_result = run_backtest(config, '2024-01-01', '2024-01-07')
        
        if backtest_result['success']:
            print("βœ… Backtest completed successfully")
            print(f"  Initial capital: ${backtest_result['initial_capital']:,.2f}")
            print(f"  Final value: ${backtest_result['final_value']:,.2f}")
            print(f"  Total return: {backtest_result['total_return']:.2%}")
            print(f"  Total trades: {backtest_result['total_trades']}")
            print(f"  Positions: {backtest_result['positions']}")
        else:
            print("❌ Backtest failed")
            print(f"  Error: {backtest_result['error']}")
            
    except Exception as e:
        print(f"❌ Error in backtesting: {e}")
    
    # Demo 4: System Statistics
    print("\nπŸ“Š Demo 4: System Statistics")
    print("-" * 30)
    
    try:
        # Show configuration summary
        print("Configuration Summary:")
        print(f"  Trading symbol: {config['trading']['symbol']}")
        print(f"  Timeframe: {config['trading']['timeframe']}")
        print(f"  Capital: ${config['trading']['capital']:,.2f}")
        print(f"  Max position: {config['risk']['max_position']}")
        print(f"  Max drawdown: {config['risk']['max_drawdown']:.1%}")
        print(f"  Broker API: {config['execution']['broker_api']}")
        
        # Show synthetic data parameters
        print("\nSynthetic Data Parameters:")
        print(f"  Base price: ${config['synthetic_data']['base_price']:.2f}")
        print(f"  Volatility: {config['synthetic_data']['volatility']:.3f}")
        print(f"  Trend: {config['synthetic_data']['trend']:.3f}")
        print(f"  Noise level: {config['synthetic_data']['noise_level']:.3f}")
        
    except Exception as e:
        print(f"❌ Error showing statistics: {e}")
    
    print("\nπŸŽ‰ Demo completed!")
    print("\nπŸ“ Check the logs directory for detailed logs:")
    print("  - logs/trading_system.log")
    print("  - logs/trading.log")
    print("  - logs/performance.log")
    print("  - logs/errors.log")

if __name__ == '__main__':
    main()