-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
666 lines (607 loc) · 34.1 KB
/
Program.cs
File metadata and controls
666 lines (607 loc) · 34.1 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Embeddings;
using Microsoft.SemanticKernel.Connectors.Qdrant;
using Qdrant.Client;
using QuantResearchAgent.Core;
using QuantResearchAgent.Services;
using Feen.Services;
using QuantResearchAgent.Services.ResearchAgents;
using QuantResearchAgent.Plugins;
using Feen.Plugins;
namespace QuantResearchAgent
{
class Program
{
// CLI startup only.
// Do not register WebApp/Server services here.
static async Task Main(string[] args)
{
await RunCliAsync(args);
}
static async Task RunCliAsync(string[] args)
{
try
{
// Build configuration
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
// Create service collection
var services = new ServiceCollection();
// Configure services (DeepSeekService is used for LLM completions)
// Add configuration
services.AddSingleton<IConfiguration>(configuration);
// Register Kernel for DI with AI service configured
services.AddSingleton<Kernel>(sp =>
{
var kernelBuilder = Kernel.CreateBuilder();
var config = sp.GetRequiredService<IConfiguration>();
// Add OpenAI service to kernel
var openAiKey = config["OpenAI:ApiKey"];
var openAiModel = config["OpenAI:ModelId"] ?? "gpt-4o-mini";
if (!string.IsNullOrEmpty(openAiKey))
{
kernelBuilder.AddOpenAIChatCompletion(openAiModel, openAiKey);
}
return kernelBuilder.Build();
});
// Register OpenAI text embedding service for RAG
services.AddSingleton<ITextEmbeddingGenerationService>(sp =>
{
var config = sp.GetRequiredService<IConfiguration>();
var openAiKey = config["OpenAI:ApiKey"];
var embeddingModel = config["OpenAI:EmbeddingModel"] ?? "text-embedding-3-small";
if (string.IsNullOrEmpty(openAiKey))
{
throw new InvalidOperationException("OpenAI API key not configured");
}
return new OpenAITextEmbeddingGenerationService(embeddingModel, openAiKey);
});
// Register LLM services
services.AddSingleton<OpenAIService>();
services.AddSingleton<DeepSeekService>();
services.AddSingleton<LLMRouterService>();
services.AddSingleton<ILLMService, LLMRouterService>();
services.AddSingleton<StrategyGeneratorService>();
// Ensure logs directory exists for file logging
var logDir = Path.Combine(Directory.GetCurrentDirectory(), "logs");
if (!Directory.Exists(logDir))
{
Directory.CreateDirectory(logDir);
}
// Configure logging
services.AddLogging(builder =>
{
builder.ClearProviders();
// Remove console logging to suppress all output
// builder.AddConsole();
builder.SetMinimumLevel(LogLevel.None);
builder.AddFilter("Microsoft", LogLevel.None);
builder.AddFilter("System", LogLevel.None);
builder.AddFilter("QuantResearchAgent", LogLevel.None);
});
// Add IntelligentAIAssistantService (must be registered before InteractiveCLI)
services.AddSingleton<IntelligentAIAssistantService>();
// Add InteractiveCLI
// (Removed default registration; using factory registration below)
// Replace InteractiveCLI registration to inject ILLMService (LLMRouterService)
services.AddSingleton<InteractiveCLI>(sp =>
new InteractiveCLI(
sp.GetRequiredService<Kernel>(),
sp.GetRequiredService<AgentOrchestrator>(),
sp.GetRequiredService<ILogger<InteractiveCLI>>(),
sp.GetRequiredService<ComprehensiveStockAnalysisAgent>(),
sp.GetRequiredService<AcademicResearchPaperAgent>(),
sp.GetRequiredService<YahooFinanceService>(),
sp.GetRequiredService<AlpacaService>(),
sp.GetRequiredService<PolygonService>(),
sp.GetRequiredService<MarketDataService>(),
sp.GetRequiredService<DataBentoService>(),
sp.GetRequiredService<YFinanceNewsService>(),
sp.GetRequiredService<FinvizNewsService>(),
sp.GetRequiredService<NewsSentimentAnalysisService>(),
sp.GetRequiredService<RedditScrapingService>(),
sp.GetRequiredService<PortfolioOptimizationService>(),
sp.GetRequiredService<SocialMediaScrapingService>(),
sp.GetRequiredService<WebDataExtractionService>(),
sp.GetRequiredService<ReportGenerationService>(),
sp.GetRequiredService<SatelliteImageryAnalysisService>(),
sp.GetRequiredService<ILLMService>(),
sp.GetRequiredService<TechnicalAnalysisService>(),
sp.GetRequiredService<IntelligentAIAssistantService>(),
sp.GetRequiredService<TradingTemplateGeneratorAgent>(),
sp.GetRequiredService<StatisticalTestingService>(),
sp.GetRequiredService<TimeSeriesAnalysisService>(),
sp.GetRequiredService<CointegrationAnalysisService>(),
sp.GetRequiredService<TimeSeriesForecastingService>(),
sp.GetRequiredService<FeatureEngineeringService>(),
sp.GetRequiredService<ModelValidationService>(),
sp.GetRequiredService<FactorModelService>(),
sp.GetRequiredService<AdvancedOptimizationService>(),
sp.GetRequiredService<AdvancedRiskService>(),
sp.GetRequiredService<SECFilingsService>(),
sp.GetRequiredService<EarningsCallService>(),
sp.GetRequiredService<SupplyChainService>(),
sp.GetRequiredService<OrderBookAnalysisService>(),
sp.GetRequiredService<MarketImpactService>(),
sp.GetRequiredService<ExecutionService>(),
sp.GetRequiredService<MonteCarloService>(),
sp.GetRequiredService<StrategyBuilderService>(),
sp.GetRequiredService<NotebookService>(),
sp.GetRequiredService<DataValidationService>(),
sp.GetRequiredService<CorporateActionService>(),
sp.GetRequiredService<TimezoneService>(),
sp.GetRequiredService<FREDService>(),
sp.GetRequiredService<WorldBankService>(),
sp.GetRequiredService<AdvancedAlpacaService>(),
sp.GetRequiredService<FactorResearchService>(),
sp.GetRequiredService<AcademicResearchService>(),
sp.GetRequiredService<AutoMLService>(),
sp.GetRequiredService<ModelInterpretabilityService>(),
sp.GetRequiredService<ReinforcementLearningService>(),
sp.GetRequiredService<FIXService>(),
sp.GetRequiredService<WebIntelligenceService>(),
sp.GetRequiredService<PatentAnalysisService>(),
sp.GetRequiredService<FederalReserveService>(),
sp.GetRequiredService<GlobalEconomicService>(),
sp.GetRequiredService<GeopoliticalRiskService>(),
sp.GetRequiredService<WebIntelligencePlugin>(),
sp.GetRequiredService<PatentAnalysisPlugin>(),
sp.GetRequiredService<FederalReservePlugin>(),
sp.GetRequiredService<GlobalEconomicPlugin>(),
// sp.GetRequiredService<GeopoliticalRiskPlugin>(), // Temporarily disabled
sp.GetRequiredService<OptionsFlowService>(),
sp.GetRequiredService<VolatilityTradingService>(),
sp.GetRequiredService<AdvancedMicrostructureService>(),
sp.GetRequiredService<LatencyArbitrageService>(),
sp.GetRequiredService<OptionsFlowPlugin>(),
sp.GetRequiredService<VolatilityTradingPlugin>(),
sp.GetRequiredService<AdvancedMicrostructurePlugin>(),
sp.GetRequiredService<LatencyArbitragePlugin>(),
sp.GetRequiredService<ConversationalResearchPlugin>(),
sp.GetRequiredService<AutomatedReportingPlugin>(),
sp.GetRequiredService<MarketRegimePlugin>(),
sp.GetRequiredService<AnomalyDetectionPlugin>(),
sp.GetRequiredService<DynamicFactorPlugin>(),
sp.GetRequiredService<TradingTemplateGeneratorPlugin>(),
sp.GetRequiredService<AlphaVantageService>(),
sp.GetRequiredService<FinancialModelingPrepService>(),
sp.GetRequiredService<EnhancedFundamentalAnalysisService>(),
sp.GetRequiredService<AlphaVantagePlugin>(),
sp.GetRequiredService<FinancialModelingPrepPlugin>(),
sp.GetRequiredService<EnhancedFundamentalAnalysisPlugin>(),
sp.GetRequiredService<AdvancedRiskAnalyticsService>(),
sp.GetRequiredService<CounterpartyRiskService>(),
sp.GetRequiredService<PerformanceAttributionService>(),
sp.GetRequiredService<BenchmarkingService>(),
sp.GetRequiredService<AdvancedRiskAnalyticsPlugin>(),
sp.GetRequiredService<CounterpartyRiskPlugin>(),
sp.GetRequiredService<PerformanceAttributionPlugin>(),
sp.GetRequiredService<BenchmarkingPlugin>(),
sp.GetRequiredService<LiveStrategyService>(),
sp.GetRequiredService<EventDrivenTradingService>(),
sp.GetRequiredService<RealTimeAlertingService>(),
sp.GetRequiredService<ComplianceMonitoringService>(),
sp.GetRequiredService<LiveStrategyPlugin>(),
sp.GetRequiredService<EventDrivenTradingPlugin>(),
sp.GetRequiredService<RealTimeAlertingPlugin>(),
sp.GetRequiredService<ComplianceMonitoringPlugin>(),
sp.GetRequiredService<PaperRAGService>(),
sp.GetRequiredService<MachineLearningService>()
)
);
// Add Semantic Kernel memory for RAG capabilities - Qdrant via custom implementation
services.AddSingleton<QdrantClient>(sp => new QdrantClient("localhost", port: 6334, https: false));
services.AddSingleton<ISemanticTextMemory>(sp =>
{
var config = sp.GetRequiredService<IConfiguration>();
var openAiKey = config["OpenAI:ApiKey"];
var embeddingModel = config["OpenAI:EmbeddingModel"] ?? "text-embedding-3-small";
if (string.IsNullOrEmpty(openAiKey))
{
throw new InvalidOperationException("OpenAI API key required for RAG");
}
// Create embedding service
var embeddingService = new OpenAITextEmbeddingGenerationService(embeddingModel, openAiKey);
// Use VolatileMemoryStore as interface, actual persistence handled by Qdrant in PaperRAGService
var memoryStore = new VolatileMemoryStore();
return new SemanticTextMemory(memoryStore, embeddingService);
});
// Add RAG and Agentic services
services.AddSingleton<RAGService>();
services.AddSingleton<AgenticOrchestrator>();
// Add core services
services.AddSingleton<LeanDataService>();
services.AddSingleton<AgentOrchestrator>(sp =>
new AgentOrchestrator(
sp.GetRequiredService<Kernel>(),
sp.GetRequiredService<YouTubeAnalysisService>(),
sp.GetRequiredService<TradingSignalService>(),
sp.GetRequiredService<MarketDataService>(),
sp.GetRequiredService<RiskManagementService>(),
sp.GetRequiredService<PortfolioService>(),
sp.GetRequiredService<RAGService>(),
sp.GetRequiredService<AgenticOrchestrator>(),
sp.GetRequiredService<MarketSentimentAgentService>(),
sp.GetRequiredService<StatisticalPatternAgentService>(),
sp.GetRequiredService<CompanyValuationService>(),
sp.GetRequiredService<HighFrequencyDataService>(),
sp.GetRequiredService<TradingStrategyLibraryService>(),
sp.GetRequiredService<AlpacaService>(),
sp.GetRequiredService<TechnicalAnalysisService>(),
sp.GetRequiredService<RedditScrapingService>(),
sp.GetRequiredService<StrategyGeneratorService>(),
sp.GetRequiredService<TradingTemplateGeneratorAgent>(),
sp.GetRequiredService<OptionsFlowService>(),
sp.GetRequiredService<VolatilityTradingService>(),
sp.GetRequiredService<AdvancedMicrostructureService>(),
sp.GetRequiredService<LatencyArbitrageService>(),
sp.GetRequiredService<IConfiguration>(),
sp.GetRequiredService<ILogger<AgentOrchestrator>>(),
sp.GetRequiredService<StatisticalTestingService>(),
sp.GetRequiredService<TimeSeriesForecastingService>(),
sp.GetRequiredService<FeatureEngineeringService>(),
sp.GetRequiredService<ModelValidationService>(),
sp.GetRequiredService<FactorModelService>(),
sp.GetRequiredService<AdvancedOptimizationService>(),
sp.GetRequiredService<AdvancedRiskService>(),
sp.GetRequiredService<OrderBookAnalysisService>(),
sp.GetRequiredService<MarketImpactService>(),
sp.GetRequiredService<ExecutionService>(),
sp.GetRequiredService<MonteCarloService>(),
sp.GetRequiredService<StrategyBuilderService>(),
sp.GetRequiredService<NotebookService>(),
sp.GetRequiredService<FREDService>(),
sp.GetRequiredService<IMFService>(),
sp.GetRequiredService<OECDService>(),
sp.GetRequiredService<WorldBankService>(),
sp.GetRequiredService<AdvancedAlpacaService>(),
sp.GetRequiredService<FIXService>(),
sp.GetRequiredService<WebIntelligenceService>(),
sp.GetRequiredService<PatentAnalysisService>(),
sp.GetRequiredService<FederalReserveService>(),
sp.GetRequiredService<GlobalEconomicService>(),
sp.GetRequiredService<GeopoliticalRiskService>()
)
);
services.AddSingleton<YouTubeAnalysisService>();
services.AddSingleton<MarketDataService>(sp =>
new MarketDataService(
sp.GetRequiredService<ILogger<MarketDataService>>(),
sp.GetRequiredService<IConfiguration>(),
sp.GetRequiredService<AlpacaService>(),
sp.GetRequiredService<LeanDataService>()
)
);
services.AddSingleton<TradingSignalService>();
services.AddSingleton<PortfolioService>();
services.AddSingleton<RiskManagementService>();
services.AddSingleton<CompanyValuationService>(sp =>
new CompanyValuationService(
sp.GetRequiredService<Kernel>(),
sp.GetRequiredService<ILogger<CompanyValuationService>>(),
sp.GetRequiredService<AlpacaService>(),
sp.GetRequiredService<QuantResearchAgent.Plugins.YahooFinanceDataPlugin>(),
sp.GetRequiredService<HttpClient>()
)
);
services.AddSingleton<HighFrequencyDataService>();
services.AddSingleton<TradingStrategyLibraryService>();
services.AddSingleton<AlpacaService>();
services.AddSingleton<TechnicalAnalysisService>();
services.AddSingleton<HttpClient>();
// Add IHttpClientFactory for services that need it
services.AddSingleton<System.Net.Http.IHttpClientFactory>(sp =>
{
return new SimpleHttpClientFactory(sp.GetRequiredService<HttpClient>());
});
services.AddSingleton<PolygonService>();
services.AddSingleton<DataBentoService>();
services.AddSingleton<YFinanceApiService>();
services.AddSingleton<YFinanceNewsService>();
services.AddSingleton<FinvizNewsService>();
services.AddSingleton<NewsApiClient>();
// Add memory cache for embedding caching
services.AddMemoryCache();
// Register enhanced article sentiment analysis services
services.AddHttpClient<ArticleScraperService>()
.ConfigureHttpClient((sp, client) =>
{
var config = sp.GetRequiredService<IConfiguration>();
var timeoutSeconds = config.GetValue<int>("ArticleScraper:TimeoutSeconds", 10);
client.Timeout = TimeSpan.FromSeconds(timeoutSeconds);
})
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
AllowAutoRedirect = true,
MaxAutomaticRedirections = 5
});
services.AddSingleton<ChunkGeneratorService>();
services.AddSingleton<EmbeddingService>();
services.AddSingleton<VectorStoreService>();
services.AddSingleton<NewsSentimentAnalysisService>(); // Uses DeepSeekService now
services.AddSingleton<YahooFinanceService>();
// Register RedditScrapingService with HttpClient
services.AddHttpClient<RedditScrapingService>()
.ConfigureHttpClient((sp, client) =>
{
var config = sp.GetRequiredService<IConfiguration>();
var userAgent = config["Reddit:UserAgent"] ?? "QuantResearchAgent/1.0 (Financial Research Application)";
client.DefaultRequestHeaders.Add("User-Agent", userAgent);
client.Timeout = TimeSpan.FromSeconds(30);
});
services.AddSingleton<PortfolioOptimizationService>();
services.AddSingleton<SocialMediaScrapingService>();
services.AddSingleton<WebDataExtractionService>();
services.AddSingleton<LinkedInScrapingService>();
services.AddSingleton<ReportGenerationService>();
services.AddSingleton<SatelliteImageryAnalysisService>();
// Add statistical testing service
services.AddSingleton<StatisticalTestingService>();
// Add statistical testing service
services.AddSingleton<StatisticalTestingService>();
// Add time series analysis service
services.AddSingleton<TimeSeriesAnalysisService>();
// Add cointegration analysis service
services.AddSingleton<CointegrationAnalysisService>();
// Add Phase 2 ML services
services.AddSingleton<TimeSeriesForecastingService>();
services.AddSingleton<FeatureEngineeringService>();
services.AddSingleton<ModelValidationService>();
// Add Phase 3 Factor Model service
services.AddSingleton<FactorModelService>();
// Add Phase 3.2 Advanced Optimization services
services.AddSingleton<AdvancedOptimizationService>();
// Add Phase 3.3 Advanced Risk services
services.AddSingleton<AdvancedRiskService>();
// Add Phase 4 Alternative Data services
services.AddSingleton<SECFilingsService>();
services.AddSingleton<EarningsCallService>();
services.AddSingleton<SupplyChainService>();
// Add Phase 5 High-Frequency & Market Microstructure services
services.AddSingleton<OrderBookAnalysisService>();
services.AddSingleton<MarketImpactService>();
services.AddSingleton<ExecutionService>();
// Add Phase 6 Research & Strategy Development Tools
services.AddSingleton<MonteCarloService>();
services.AddSingleton<StrategyBuilderService>();
services.AddSingleton<NotebookService>();
// Add Phase 7 Data Quality & Management services
services.AddSingleton<DataValidationService>();
services.AddSingleton<CorporateActionService>();
services.AddSingleton<TimezoneService>();
// Add Phase 8 Free Institutional Data services
services.AddSingleton<FREDService>(sp =>
new FREDService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<FREDService>>(),
sp.GetRequiredService<IConfiguration>()
)
);
services.AddSingleton<IMFService>(sp =>
new IMFService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<IMFService>>(),
sp.GetRequiredService<IConfiguration>()
)
);
services.AddSingleton<OECDService>(sp =>
new OECDService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<OECDService>>(),
sp.GetRequiredService<IConfiguration>()
)
);
services.AddSingleton<WorldBankService>(sp =>
new WorldBankService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<WorldBankService>>(),
sp.GetRequiredService<IConfiguration>()
)
);
services.AddSingleton<AdvancedAlpacaService>(sp =>
new AdvancedAlpacaService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<AdvancedAlpacaService>>(),
sp.GetRequiredService<IConfiguration>(),
sp.GetRequiredService<AlpacaService>()
)
);
// Add Phase 9 Advanced Research Tools services
services.AddSingleton<FactorResearchService>();
services.AddSingleton<AcademicResearchService>();
services.AddSingleton<AutoMLService>();
services.AddSingleton<ModelInterpretabilityService>();
services.AddSingleton<ReinforcementLearningService>();
services.AddSingleton<MachineLearningService>();
// Add Phase 10 Web & Alternative Data Integration services
services.AddSingleton<WebIntelligenceService>();
services.AddSingleton<PatentAnalysisService>();
services.AddSingleton<FederalReserveService>();
services.AddSingleton<GlobalEconomicService>();
services.AddSingleton<GeopoliticalRiskService>();
// Add Phase 11 Derivatives & Options Analytics services
services.AddSingleton<OptionsFlowService>();
services.AddSingleton<VolatilityTradingService>();
services.AddSingleton<AdvancedMicrostructureService>();
services.AddSingleton<LatencyArbitrageService>();
// Add Phase 10 Web & Alternative Data Integration plugins
services.AddSingleton<WebIntelligencePlugin>();
services.AddSingleton<PatentAnalysisPlugin>();
services.AddSingleton<GoogleWebSearchPlugin>();
services.AddSingleton<IWebSearchPlugin, GoogleWebSearchPlugin>();
services.AddSingleton<YahooFinanceDataPlugin>();
services.AddSingleton<IFinancialDataPlugin, YahooFinanceDataPlugin>();
services.AddSingleton<FederalReservePlugin>();
services.AddSingleton<GlobalEconomicPlugin>();
// services.AddSingleton<GeopoliticalRiskPlugin>(); // Temporarily disabled due to mock data removal
// Add Phase 11 Derivatives & Options Analytics plugins
services.AddSingleton<OptionsFlowPlugin>();
services.AddSingleton<VolatilityTradingPlugin>();
services.AddSingleton<AdvancedMicrostructurePlugin>();
services.AddSingleton<LatencyArbitragePlugin>();
// Add Phase 8.3 FIX Protocol service
services.AddSingleton<FIXService>();
// Add Phase 14 AI-Enhanced Research services
services.AddSingleton<ConversationalResearchService>();
services.AddSingleton<AutomatedReportingService>();
services.AddSingleton<MarketRegimeService>();
services.AddSingleton<AnomalyDetectionService>();
services.AddSingleton<DynamicFactorService>();
// Add Phase 14 AI-Enhanced Research plugins
services.AddSingleton<ConversationalResearchPlugin>();
services.AddSingleton<AutomatedReportingPlugin>();
services.AddSingleton<MarketRegimePlugin>();
services.AddSingleton<AnomalyDetectionPlugin>();
services.AddSingleton<DynamicFactorPlugin>();
services.AddSingleton<TradingTemplateGeneratorPlugin>();
// Add Phase 15 Specialized Quantitative Tools services
services.AddSingleton<AdvancedRiskAnalyticsService>();
services.AddSingleton<CounterpartyRiskService>();
services.AddSingleton<PerformanceAttributionService>();
services.AddSingleton<BenchmarkingService>();
// Add Phase 15 Specialized Quantitative Tools plugins
services.AddSingleton<AdvancedRiskAnalyticsPlugin>();
services.AddSingleton<CounterpartyRiskPlugin>();
services.AddSingleton<PerformanceAttributionPlugin>();
services.AddSingleton<BenchmarkingPlugin>();
// Add Phase 12 Research Platforms Integration services (Free Alternatives)
services.AddSingleton<AlphaVantageService>(sp =>
new AlphaVantageService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<AlphaVantageService>>(),
sp.GetRequiredService<IConfiguration>()
)
);
services.AddSingleton<FinancialModelingPrepService>(sp =>
new FinancialModelingPrepService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<FinancialModelingPrepService>>(),
sp.GetRequiredService<IConfiguration>()
)
);
services.AddSingleton<EnhancedFundamentalAnalysisService>(sp =>
new EnhancedFundamentalAnalysisService(
sp.GetRequiredService<AlphaVantageService>(),
sp.GetRequiredService<FinancialModelingPrepService>(),
sp.GetRequiredService<YFinanceApiService>(),
sp.GetRequiredService<AlpacaService>(),
sp.GetRequiredService<DataBentoService>(),
sp.GetRequiredService<ILogger<EnhancedFundamentalAnalysisService>>(),
sp.GetRequiredService<LLMRouterService>()
)
);
// Add Phase 12 Research Platforms Integration plugins
services.AddSingleton<AlphaVantagePlugin>();
services.AddSingleton<FinancialModelingPrepPlugin>();
services.AddSingleton<EnhancedFundamentalAnalysisPlugin>();
// Add Phase 13 Real-Time & Live Features services
services.AddSingleton<LiveStrategyService>(sp =>
new LiveStrategyService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<LiveStrategyService>>(),
sp.GetRequiredService<IConfiguration>(),
sp.GetRequiredService<AdvancedAlpacaService>(),
sp.GetRequiredService<MarketDataService>(),
sp.GetRequiredService<AdvancedRiskService>()
)
);
services.AddSingleton<EventDrivenTradingService>(sp =>
new EventDrivenTradingService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<EventDrivenTradingService>>(),
sp.GetRequiredService<IConfiguration>(),
sp.GetRequiredService<AdvancedAlpacaService>(),
sp.GetRequiredService<NewsSentimentAnalysisService>(),
sp.GetRequiredService<FederalReserveService>(),
sp.GetRequiredService<GeopoliticalRiskService>()
)
);
services.AddSingleton<RealTimeAlertingService>(sp =>
new RealTimeAlertingService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<RealTimeAlertingService>>(),
sp.GetRequiredService<IConfiguration>(),
sp.GetRequiredService<AdvancedAlpacaService>(),
sp.GetRequiredService<MarketDataService>(),
sp.GetRequiredService<TechnicalAnalysisService>()
)
);
services.AddSingleton<ComplianceMonitoringService>(sp =>
new ComplianceMonitoringService(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILogger<ComplianceMonitoringService>>(),
sp.GetRequiredService<IConfiguration>(),
sp.GetRequiredService<AdvancedAlpacaService>(),
sp.GetRequiredService<AdvancedRiskService>()
)
);
// Add Phase 13 Real-Time & Live Features plugins
services.AddSingleton<LiveStrategyPlugin>();
services.AddSingleton<EventDrivenTradingPlugin>();
services.AddSingleton<RealTimeAlertingPlugin>();
services.AddSingleton<ComplianceMonitoringPlugin>();
// Add RAG and Agentic plugins
services.AddSingleton<RAGPlugin>();
services.AddSingleton<AgenticPlugin>();
// Add research agents
services.AddSingleton<NewsScrapingService>();
services.AddSingleton<UrlNewsScrapingService>();
services.AddSingleton<MarketSentimentAgentService>();
services.AddSingleton<StatisticalPatternAgentService>();
services.AddSingleton<ComprehensiveStockAnalysisAgent>();
services.AddSingleton<PaperRAGService>();
services.AddSingleton<AcademicResearchPaperAgent>();
services.AddSingleton<TradingTemplateGeneratorAgent>(sp =>
new TradingTemplateGeneratorAgent(
sp.GetRequiredService<Kernel>(),
sp.GetRequiredService<ILogger<TradingTemplateGeneratorAgent>>(),
sp.GetRequiredService<IConfiguration>(),
sp.GetRequiredService<MarketDataService>(),
sp.GetRequiredService<CompanyValuationService>(),
sp.GetRequiredService<TechnicalAnalysisService>(),
sp.GetRequiredService<NewsSentimentAnalysisService>(),
sp.GetRequiredService<QuantResearchAgent.Plugins.IWebSearchPlugin>(),
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ILLMService>(),
sp.GetRequiredService<WebDataExtractionService>(),
sp.GetRequiredService<DeepSeekService>()
)
);
// Build the service provider
var serviceProvider = services.BuildServiceProvider();
// Initialize VectorStoreService on application startup
try
{
var vectorStoreService = serviceProvider.GetRequiredService<VectorStoreService>();
await vectorStoreService.InitializeAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Warning: Failed to initialize VectorStoreService: {ex.Message}");
Console.WriteLine("The application will continue with in-memory fallback storage.");
}
// Get the CLI and run it
var cli = serviceProvider.GetRequiredService<InteractiveCLI>();
await cli.RunAsync(args);
}
catch (Exception ex)
{
Console.WriteLine($"CLI startup failed: {ex.Message}");
Console.WriteLine($"Stack trace: {ex.StackTrace}");
if (ex.InnerException != null)
{
Console.WriteLine($"Inner exception: {ex.InnerException.Message}");
Console.WriteLine($"Inner stack trace: {ex.InnerException.StackTrace}");
}
Environment.Exit(1);
}
}
}
}