private WeeklyIncomeActionPlan Crossover(WeeklyIncomeActionPlan r1, WeeklyIncomeActionPlan r2, List <PairCondor> pairCondorCandidates, int slots)
        {
            WeeklyIncomeActionPlan co = new WeeklyIncomeActionPlan();

            co.GenerationMethod = r1.GenerationMethod;

            int splitIdx = random.Next(1, slots - 1);

            co.Pairs.AddRange(r1.Pairs.Take(splitIdx));

            for (int i = splitIdx; i < r2.Pairs.Count; i++)
            {
                co.AddPairCondor(r2.Pairs[splitIdx]);
            }

            while (co.Pairs.Count < slots)
            {
                int idx = random.Next(pairCondorCandidates.Count);
                co.AddPairCondor(pairCondorCandidates[idx]);
            }

            return(co);
        }
        private WeeklyIncomeActionPlan BuildRandomSolution(List <PairCondor> pairCondorCandidates, WeeklyActionPlanGenerationMethods generationMethod, int slots)
        {
            WeeklyIncomeActionPlan actionPlan = new WeeklyIncomeActionPlan();

            actionPlan.GenerationMethod = generationMethod;

            while (actionPlan.Pairs.Count < slots)
            {
                int idx = random.Next(pairCondorCandidates.Count);
                actionPlan.AddPairCondor(pairCondorCandidates[idx]);
            }

            return(actionPlan);
        }
        private void Mutate(WeeklyIncomeActionPlan actionPlan, List <PairCondor> pairCondorCandidates, int slots)
        {
            int        step    = random.Next(0, 2) == 0 ? 1 : -1;
            int        rmvIdx  = random.Next(0, actionPlan.Pairs.Count);
            PairCondor rmvPair = actionPlan.Pairs[rmvIdx];
            int        pairIdx = pairCondorCandidates.FindIndex(x => x.BullPutSpread.SecurityIdentifier == rmvPair.BullPutSpread.SecurityIdentifier &&
                                                                x.BearCallSpread.SecurityIdentifier == rmvPair.BearCallSpread.SecurityIdentifier);

            actionPlan.Pairs.RemoveAt(rmvIdx);

            pairIdx = MutateIndex(pairIdx, step, pairCondorCandidates);
            while (actionPlan.Pairs.Count < slots)
            {
                actionPlan.AddPairCondor(pairCondorCandidates[pairIdx]);
                pairIdx = MutateIndex(pairIdx, step, pairCondorCandidates);
            }
        }
        private WeeklyIncomeActionPlan PcBruteForceActionPlanGenerator(List <PairCondor> pairCondorCandidates, int slots)
        {
            WeeklyIncomeActionPlan actionPlan = new WeeklyIncomeActionPlan();

            actionPlan.GenerationMethod = Enums.WeeklyActionPlanGenerationMethods.BruteForce;

            foreach (PairCondor pairCondor in pairCondorCandidates.OrderByDescending(x => x.Credit))
            {
                actionPlan.AddPairCondor(pairCondor);

                if (actionPlan.Pairs.Count == slots)
                {
                    break;
                }
            }

            return(actionPlan);
        }