public PercentChange(StrategyParameters _parameters, List<StrategyAdditionalParameter> _additional, ref Data _data, ref IndicatorPortfolio _indicators) { parameters = _parameters; additional = _additional; bars = _data.Bars; indicators = _indicators; }
public OptimizerReport(List <IIStrategyParameter> paramaters) { for (int i = 0; i < paramaters.Count; i++) { StrategyParameters.Add(paramaters[i].Type + "$" + paramaters[i].GetStringToSave() + "$" + paramaters[i].Name); } }
public AntiEmaPrcBL(StrategyParameters _parameters, List<StrategyAdditionalParameter> _additional, ref Data _data, ref IndicatorPortfolio _indicators) { parameters = _parameters; additional = _additional; bars = _data.Bars; indicators = _indicators; MaxIntradayIndex = _data.GetIndexDictionary().Values.ToList<int>().Max(); }
public OptimizerReport(int fazeUid, string securityName, List <IIStrategyParameter> paramaters) { Uid = NumberGen.GetNumberDeal(StartProgram.IsOsOptimizer); FazeUid = fazeUid; SecurityName = securityName; for (int i = 0; i < paramaters.Count; i++) { StrategyParameters.Add(paramaters[i].GetStringToSave()); } }
public void Message_ShouldSetAndGetTheSameValue() { var parameters = new StrategyParameters(); parameters.Message = null; var result1 = parameters.Message; parameters.Message = "TEST"; Assert.Equal("TEST", parameters.Message); }
/// <param name="parameters">Parameters of the strategy specifying input coins, the target and final selection restrictions.</param> /// <param name="bestSelection">Best selection so far.</param> public SelectionStrategy(StrategyParameters parameters, CoinSelection bestSelection) { Parameters = parameters; BestSelection = bestSelection; RemainingAmounts = new long[InputValues.Length]; long accumulator = InputValues.Sum(); for (int i = 0; i < InputValues.Length; i++) { accumulator -= InputValues[i]; RemainingAmounts[i] = accumulator; } }
/// <summary> /// </summary> public override object Clone() { return(new GeneticOptimizer { Parameters = (ParameterCollection)Parameters.Clone(), StrategyParameters = StrategyParameters != null ? (Chromosomes)StrategyParameters.Clone() : null, MaxGenerations = MaxGenerations, PopulationSize = PopulationSize, MutationRate = MutationRate, MutationStrength = MutationStrength, StabilitySize = StabilitySize, ResetSize = ResetSize, MinimumPerformance = MinimumPerformance, CrossoverRate = CrossoverRate }); }
public void Constructor_ShouldNotThrow() { var result = new StrategyParameters(); Assert.NotNull(result); }
/// <summary> /// Runs the optimizer on a given parameter set. /// Beware: this method might be called in a non-main, worker thread. E.g. driving GUI logic from here forward would cause issues. /// </summary> public override void Optimize() { Individual supremeIndividual = null; try { var realStabilitySize = (int)Math.Ceiling(populationSize * stabilitySize); var realResetSize = (int)Math.Ceiling(populationSize * resetSize); var numberOfStrategyParameters = StrategyParameters.Count; var combinations = StrategyParameters.CountCombinations; var siblings = new Dictionary <Individual, bool>(); var children = new List <Individual>(); var parents = new List <Individual>(); var prevStabilityScore = double.NaN; // Start optimization process for (int generation = 1; generation <= maxGenerations; generation++) { //If Initial generation, seed the population with random individuals while (children.Count < populationSize && siblings.Count < combinations) { ValidateIndividual(children, siblings, CreateRandomIndividual()); } foreach (Individual individual in children) { if (UserAbort) { throw new AbortException(); } StrategyParameters.SetStrategyParameters(individual, Strategy, Parameters); RunIteration(IterationCompleted, individual); } WaitForIterationsCompleted(false); //Make sure that each individual completed its iteration parents.AddRange(children); parents.Sort(); Individual generationBest = parents[0]; //This is the best performing individual since stability reset if (parents.Count > 0 && generationBest != null && (supremeIndividual == null || supremeIndividual.Performance < generationBest.Performance)) { supremeIndividual = generationBest; } int stabilityIndividuals = Math.Max(1, Math.Min(parents.Count, realStabilitySize)); double stabilityScore = 0.0; for (int i = 0; i < stabilityIndividuals; i++) { stabilityScore += parents[i].Performance; } if (supremeIndividual != null && minimumPerformance > 0 && supremeIndividual.Performance > minimumPerformance) { break; } children.Clear(); //Clearing up space for the next generation if (siblings.Count >= combinations || generation == maxGenerations) { break; } //Repopulating the next generation. //If Population is stable, leave just best performing individuals if (stabilityScore == prevStabilityScore) { if (realResetSize <= 0) { parents.Clear(); } else if (parents.Count > 0) { parents = parents.GetRange(0, Math.Min(parents.Count, realResetSize)); } continue; } //Assign a weight for each parent RankPopulation(parents); //Reproduce extra individuals mutated from the best ShakeBestPerformer(children, siblings, combinations, generationBest, numberOfStrategyParameters); //Reproduce children using Crossover, Mutation and totally random genomes while (children.Count < populationSize && siblings.Count < combinations) { if (UserAbort) { throw new AbortException(); } if (random.NextDouble() <= crossoverRate) { int[] chromosomeIndexesForSon; int[] chromosomeIndexesForDaughter; //Produce two children from two parents //Parents are selected using Roulette Selection Method //Note: There are many other selection algorithms (Google them out...) //TODO: Implements some additional selection methods //Crossover is performed using single break point //TODO: implement 2 or 3 break points Crossover algorithms Crossover(numberOfStrategyParameters, parents[RouletteSelection(parents)], parents[RouletteSelection(parents)], out chromosomeIndexesForSon, out chromosomeIndexesForDaughter); for (var idx = 0; idx < numberOfStrategyParameters; idx++) { if (StrategyParameters[idx].Count <= 1) { continue; } //After children are produced from crossover, small part should be mutated if (random.NextDouble() <= mutationRate) { chromosomeIndexesForSon[idx] = Mutate(mutationStrength, StrategyParameters[idx].Count, chromosomeIndexesForSon[idx]); } if (random.NextDouble() <= mutationRate) { chromosomeIndexesForDaughter[idx] = Mutate(mutationStrength, StrategyParameters[idx].Count, chromosomeIndexesForDaughter[idx]); } } //Make sure that children are unique, so we wont waste any time for evaluation of their performance ValidateIndividual(children, siblings, new Individual(chromosomeIndexesForSon)); ValidateIndividual(children, siblings, new Individual(chromosomeIndexesForDaughter)); } else { //Create random children //Make sure that children are unique, so we wont waste any time for evaluation of their performance ValidateIndividual(children, siblings, CreateRandomIndividual()); ValidateIndividual(children, siblings, CreateRandomIndividual()); } } prevStabilityScore = stabilityScore; } } catch { } finally { WaitForIterationsCompleted(true); if (options != null) { options.Dispose(); options = null; } } }
/// <inheritdoc/> public LessSelectionStrategy(StrategyParameters parameters, double minPaymentThreshold = MinPaymentThreshold) : base(parameters, new CoinSelection(long.MinValue, long.MinValue)) { MinimumTarget = (long)(parameters.Target * minPaymentThreshold); }
/// <inheritdoc/> public MoreSelectionStrategy(StrategyParameters parameters, double maxExtraPayment = MaxExtraPayment) : base(parameters, new CoinSelection(long.MaxValue, long.MaxValue)) { MaximumTarget = (long)(parameters.Target * maxExtraPayment); }
public StepChange(StrategyParameters _parameters, List<StrategyAdditionalParameter> _additional, ref Data _data) { parameters = _parameters; additional = _additional; ticks = _data.Bars; }
public StepChange() { ticks = new List<Tick>(); parameters = new StrategyParameters(); }