Add enum for Selection method

This commit is contained in:
2025-07-11 17:15:11 +07:00
parent f720cb7321
commit c62570e15d
10 changed files with 59 additions and 39 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 = () => {
<label className="label">
<span className="label-text">Selection Method</span>
</label>
<select
className="select select-bordered w-full"
{...register('selectionMethod')}
>
<option value="tournament">Tournament Selection</option>
<option value="roulette">Roulette Wheel</option>
<option value="fitness-weighted">Fitness Weighted</option>
</select>
<select
className="select select-bordered w-full"
{...register('selectionMethod')}
>
<option value={GeneticSelectionMethod.Tournament}>Tournament Selection</option>
<option value={GeneticSelectionMethod.Roulette}>Roulette Wheel</option>
<option value={GeneticSelectionMethod.FitnessWeighted}>Fitness Weighted</option>
</select>
</div>
<div className="form-control">