diff --git a/src/Managing.Api/Controllers/BacktestController.cs b/src/Managing.Api/Controllers/BacktestController.cs index 53ffa0e..d21d0a2 100644 --- a/src/Managing.Api/Controllers/BacktestController.cs +++ b/src/Managing.Api/Controllers/BacktestController.cs @@ -306,9 +306,6 @@ public class BacktestController : BaseController request.MaxTakeProfit, request.EligibleIndicators); - // TODO: Trigger background genetic algorithm execution - // This will be implemented in the next step with a background service - return Ok(geneticRequest); } catch (Exception ex) diff --git a/src/Managing.Api/Models/Requests/RunGeneticRequest.cs b/src/Managing.Api/Models/Requests/RunGeneticRequest.cs index b4bcb03..84b2cd9 100644 --- a/src/Managing.Api/Models/Requests/RunGeneticRequest.cs +++ b/src/Managing.Api/Models/Requests/RunGeneticRequest.cs @@ -50,7 +50,7 @@ public class RunGeneticRequest /// /// The selection method to use /// - public string SelectionMethod { get; set; } = "tournament"; + public GeneticSelectionMethod SelectionMethod { get; set; } /// /// The percentage of elite individuals to preserve (1-50) diff --git a/src/Managing.Application.Abstractions/Services/IGeneticService.cs b/src/Managing.Application.Abstractions/Services/IGeneticService.cs index d53790c..754e943 100644 --- a/src/Managing.Application.Abstractions/Services/IGeneticService.cs +++ b/src/Managing.Application.Abstractions/Services/IGeneticService.cs @@ -36,7 +36,7 @@ public interface IGeneticService int populationSize, int generations, double mutationRate, - string selectionMethod, + GeneticSelectionMethod selectionMethod, int elitismPercentage, double maxTakeProfit, List eligibleIndicators); diff --git a/src/Managing.Application/GeneticService.cs b/src/Managing.Application/GeneticService.cs index f1a417c..50802b2 100644 --- a/src/Managing.Application/GeneticService.cs +++ b/src/Managing.Application/GeneticService.cs @@ -203,7 +203,7 @@ public class GeneticService : IGeneticService int populationSize, int generations, double mutationRate, - string selectionMethod, + GeneticSelectionMethod selectionMethod, int elitismPercentage, double maxTakeProfit, List eligibleIndicators) @@ -422,13 +422,13 @@ public class GeneticService : IGeneticService } } - private ISelection GetSelection(string selectionMethod) + private ISelection GetSelection(GeneticSelectionMethod selectionMethod) { - return selectionMethod.ToLower() switch + return selectionMethod switch { - "tournament" => new TournamentSelection(), - "roulette" => new RouletteWheelSelection(), - "fitness-weighted" => new RankSelection(), // Use rank selection as approximation + GeneticSelectionMethod.Tournament => new TournamentSelection(), + GeneticSelectionMethod.Roulette => new RouletteWheelSelection(), + GeneticSelectionMethod.FitnessWeighted => new RankSelection(), // Use rank selection as approximation _ => new TournamentSelection() }; } diff --git a/src/Managing.Common/Enums.cs b/src/Managing.Common/Enums.cs index 7d8be3b..075a64f 100644 --- a/src/Managing.Common/Enums.cs +++ b/src/Managing.Common/Enums.cs @@ -416,4 +416,14 @@ public static class Enums Moderate = 2, Aggressive = 3 } + + /// + /// Selection methods for genetic algorithm optimization + /// + public enum GeneticSelectionMethod + { + Tournament, + Roulette, + FitnessWeighted + } } \ No newline at end of file diff --git a/src/Managing.Domain/Backtests/GeneticRequest.cs b/src/Managing.Domain/Backtests/GeneticRequest.cs index d7f4176..751c501 100644 --- a/src/Managing.Domain/Backtests/GeneticRequest.cs +++ b/src/Managing.Domain/Backtests/GeneticRequest.cs @@ -110,7 +110,7 @@ public class GeneticRequest /// The selection method to use /// [Required] - public string SelectionMethod { get; set; } = "tournament"; + public GeneticSelectionMethod SelectionMethod { get; set; } = GeneticSelectionMethod.Tournament; /// /// The percentage of elite individuals to preserve (1-50) diff --git a/src/Managing.Infrastructure.Database/MongoDb/Collections/GeneticRequestDto.cs b/src/Managing.Infrastructure.Database/MongoDb/Collections/GeneticRequestDto.cs index b066459..c14b085 100644 --- a/src/Managing.Infrastructure.Database/MongoDb/Collections/GeneticRequestDto.cs +++ b/src/Managing.Infrastructure.Database/MongoDb/Collections/GeneticRequestDto.cs @@ -19,7 +19,7 @@ namespace Managing.Infrastructure.Databases.MongoDb.Collections public int PopulationSize { get; set; } public int Generations { get; set; } public double MutationRate { get; set; } - public string SelectionMethod { get; set; } + public GeneticSelectionMethod SelectionMethod { get; set; } public int ElitismPercentage { get; set; } public double MaxTakeProfit { get; set; } public List EligibleIndicators { get; set; } = new(); diff --git a/src/Managing.WebApp/src/generated/ManagingApi.ts b/src/Managing.WebApp/src/generated/ManagingApi.ts index 53bf8c2..060dedc 100644 --- a/src/Managing.WebApp/src/generated/ManagingApi.ts +++ b/src/Managing.WebApp/src/generated/ManagingApi.ts @@ -3721,7 +3721,7 @@ export interface GeneticRequest { populationSize: number; generations: number; mutationRate: number; - selectionMethod: string; + selectionMethod: GeneticSelectionMethod; elitismPercentage: number; maxTakeProfit: number; eligibleIndicators: IndicatorType[]; @@ -3743,6 +3743,12 @@ export enum GeneticRequestStatus { Cancelled = "Cancelled", } +export enum GeneticSelectionMethod { + Tournament = "Tournament", + Roulette = "Roulette", + FitnessWeighted = "FitnessWeighted", +} + export interface RunGeneticRequest { ticker?: Ticker; timeframe?: Timeframe; @@ -3752,7 +3758,7 @@ export interface RunGeneticRequest { populationSize?: number; generations?: number; mutationRate?: number; - selectionMethod?: string | null; + selectionMethod?: GeneticSelectionMethod; elitismPercentage?: number; maxTakeProfit?: number; eligibleIndicators?: IndicatorType[] | null; diff --git a/src/Managing.WebApp/src/generated/ManagingApiTypes.ts b/src/Managing.WebApp/src/generated/ManagingApiTypes.ts index 912822e..75bfb08 100644 --- a/src/Managing.WebApp/src/generated/ManagingApiTypes.ts +++ b/src/Managing.WebApp/src/generated/ManagingApiTypes.ts @@ -668,7 +668,7 @@ export interface GeneticRequest { populationSize: number; generations: number; mutationRate: number; - selectionMethod: string; + selectionMethod: GeneticSelectionMethod; elitismPercentage: number; maxTakeProfit: number; eligibleIndicators: IndicatorType[]; @@ -690,6 +690,12 @@ export enum GeneticRequestStatus { Cancelled = "Cancelled", } +export enum GeneticSelectionMethod { + Tournament = "Tournament", + Roulette = "Roulette", + FitnessWeighted = "FitnessWeighted", +} + export interface RunGeneticRequest { ticker?: Ticker; timeframe?: Timeframe; @@ -699,7 +705,7 @@ export interface RunGeneticRequest { populationSize?: number; generations?: number; mutationRate?: number; - selectionMethod?: string | null; + selectionMethod?: GeneticSelectionMethod; elitismPercentage?: number; maxTakeProfit?: number; eligibleIndicators?: IndicatorType[] | null; diff --git a/src/Managing.WebApp/src/pages/backtestPage/backtestGeneticBundle.tsx b/src/Managing.WebApp/src/pages/backtestPage/backtestGeneticBundle.tsx index d234d6f..804afba 100644 --- a/src/Managing.WebApp/src/pages/backtestPage/backtestGeneticBundle.tsx +++ b/src/Managing.WebApp/src/pages/backtestPage/backtestGeneticBundle.tsx @@ -7,6 +7,7 @@ import { type Backtest, BacktestClient, type GeneticRequest, + GeneticSelectionMethod, IndicatorType, type RunGeneticRequest, Ticker, @@ -37,18 +38,18 @@ const ALL_INDICATORS = [ // Form Interface interface GeneticBundleFormData { - ticker: Ticker - timeframe: Timeframe - startDate: string - endDate: string - balance: number - populationSize: number - generations: number - mutationRate: number - selectionMethod: string - elitismPercentage: number - maxTakeProfit: number - eligibleIndicators: IndicatorType[] + ticker: Ticker + timeframe: Timeframe + startDate: string + endDate: string + balance: number + populationSize: number + generations: number + mutationRate: number + selectionMethod: GeneticSelectionMethod + elitismPercentage: number + maxTakeProfit: number + eligibleIndicators: IndicatorType[] } const BacktestGeneticBundle: React.FC = () => { @@ -75,7 +76,7 @@ const BacktestGeneticBundle: React.FC = () => { populationSize: 10, generations: 5, mutationRate: 0.3, - selectionMethod: 'tournament', + selectionMethod: GeneticSelectionMethod.Tournament, elitismPercentage: 10, maxTakeProfit: 2.0, eligibleIndicators: ALL_INDICATORS, @@ -153,7 +154,7 @@ const BacktestGeneticBundle: React.FC = () => { setValue('populationSize', 10) setValue('generations', 5) setValue('mutationRate', 0.3) - setValue('selectionMethod', 'tournament') + setValue('selectionMethod', GeneticSelectionMethod.Tournament) setValue('elitismPercentage', 10) setValue('maxTakeProfit', 2.0) setSelectedIndicators(ALL_INDICATORS) @@ -407,14 +408,14 @@ const BacktestGeneticBundle: React.FC = () => { - +