[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2007-01-03 23:20:48
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv4394/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: GenomeManagerPVO.cs Log Message: Deleted the mutationRate parameter from the IGenomeManager's Mutate method. Now classes implementing Mutate method just need to pass only the genome that has to be mutated to the method. As the mutationRate is now used only by the GeneticOptimizer, all the methods that effectively mutate genes of a given genome don't need anymore the mutation rate parameter. Index: GenomeManagerPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/GenomeManagerPVO.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManagerPVO.cs 22 Oct 2006 18:49:20 -0000 1.2 --- GenomeManagerPVO.cs 3 Jan 2007 23:20:14 -0000 1.3 *************** *** 47,50 **** --- 47,51 ---- private int divisorForThresholdComputation; private bool symmetricalThresholds = false; + private bool overboughtMoreThanOversoldForFixedPortfolio = false; private int numOfGenesDedicatedToThresholds; private double currentOversoldThreshold = 0.0; *************** *** 63,67 **** this.divisorForThresholdComputation < this.maxLevelForOversoldThreshold || (this.symmetricalThresholds && (this.minLevelForOversoldThreshold != this.minLevelForOverboughtThreshold || ! this.maxLevelForOversoldThreshold != this.maxLevelForOverboughtThreshold) ) ) throw new Exception("Bad parameters for thresholds computation!"); --- 64,73 ---- this.divisorForThresholdComputation < this.maxLevelForOversoldThreshold || (this.symmetricalThresholds && (this.minLevelForOversoldThreshold != this.minLevelForOverboughtThreshold || ! this.maxLevelForOversoldThreshold != this.maxLevelForOverboughtThreshold) ) || ! (this.overboughtMoreThanOversoldForFixedPortfolio && ! (this.minLevelForOverboughtThreshold > Convert.ToInt32(Convert.ToDouble(this.minLevelForOversoldThreshold)* Convert.ToDouble(this.divisorForThresholdComputation) / ! (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(this.minLevelForOversoldThreshold) ) ) || ! this.maxLevelForOverboughtThreshold < Convert.ToInt32(Convert.ToDouble(this.maxLevelForOversoldThreshold) * Convert.ToDouble(this.divisorForThresholdComputation) / ! (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(this.maxLevelForOversoldThreshold) ) ) ) ) ) throw new Exception("Bad parameters for thresholds computation!"); *************** *** 79,82 **** --- 85,89 ---- int divisorForThresholdComputation, bool symmetricalThresholds, + bool overboughtMoreThanOversoldForFixedPortfolio, PortfolioType inSamplePortfolioType) : *************** *** 97,100 **** --- 104,108 ---- this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; this.symmetricalThresholds = symmetricalThresholds; + this.overboughtMoreThanOversoldForFixedPortfolio = overboughtMoreThanOversoldForFixedPortfolio; if(this.symmetricalThresholds)//value for thresholds must be unique numOfGenesDedicatedToThresholds = 1; *************** *** 364,391 **** int minValueForGene = genome.GetMinValueForGenes(genePosition); int maxValueForGene = genome.GetMaxValueForGenes(genePosition); ! int returnValue = minValueForGene; ! if( minValueForGene != maxValueForGene) ! { ! returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene + 1); ! while(genePosition > this.numOfGenesDedicatedToThresholds - 1 ! && GenomeManipulator.IsTickerContainedInGenome(returnValue, ! genome, ! this.numOfGenesDedicatedToThresholds, ! genome.Size - 1)) ! //while in the given position has to be stored ! //a new gene pointing to a ticker and ! //the proposed returnValue points to a ticker ! //already stored in the given genome ! { ! // a new returnValue has to be generated ! returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene + 1); ! } ! } return returnValue; } ! public override void Mutate(Genome genome, double mutationRate) { // in this implementation only one gene is mutated --- 372,401 ---- int minValueForGene = genome.GetMinValueForGenes(genePosition); int maxValueForGene = genome.GetMaxValueForGenes(genePosition); ! int returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene + 1); ! ! if(this.numOfGenesDedicatedToThresholds == 2 && ! this.overboughtMoreThanOversoldForFixedPortfolio && genePosition == 1) ! //genePosition points to overbought threshold, ! //dipendent from the oversold one such that the portfolio tends to be fix ! returnValue = Convert.ToInt32(Convert.ToDouble(genome.GetGeneValue(0)) * Convert.ToDouble(this.divisorForThresholdComputation) / ! (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(genome.GetGeneValue(0)))); ! ! while(genePosition > this.numOfGenesDedicatedToThresholds - 1 ! && GenomeManipulator.IsTickerContainedInGenome(returnValue, ! genome, ! this.numOfGenesDedicatedToThresholds, ! genome.Size - 1)) ! //while in the given position has to be stored ! //a new gene pointing to a ticker and ! //the proposed returnValue points to a ticker ! //already stored in the given genome ! returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene + 1); ! return returnValue; } ! public override void Mutate(Genome genome) { // in this implementation only one gene is mutated *************** *** 393,417 **** int minValueForGene = genome.GetMinValueForGenes(genePositionToBeMutated); int maxValueForGene = genome.GetMaxValueForGenes(genePositionToBeMutated); ! if(minValueForGenes != maxValueForGenes) ! { ! int newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene + 1); ! ! while(genePositionToBeMutated > this.numOfGenesDedicatedToThresholds - 1 && ! GenomeManipulator.IsTickerContainedInGenome(newValueForGene, ! genome, ! this.numOfGenesDedicatedToThresholds, ! genome.Size - 1)) ! //while in the proposed genePositionToBeMutated has to be stored ! //a new gene pointing to a ticker and ! //the proposed newValueForGene points to a ticker ! //already stored in the given genome ! { ! newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene +1); ! } ! GenomeManagement.MutateOneGene(genome, mutationRate, ! genePositionToBeMutated, newValueForGene); ! } } } --- 403,424 ---- int minValueForGene = genome.GetMinValueForGenes(genePositionToBeMutated); int maxValueForGene = genome.GetMaxValueForGenes(genePositionToBeMutated); ! int newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene +1); ! while(genePositionToBeMutated > this.numOfGenesDedicatedToThresholds - 1 && ! GenomeManipulator.IsTickerContainedInGenome(newValueForGene, ! genome, ! this.numOfGenesDedicatedToThresholds, ! genome.Size - 1)) ! //while in the proposed genePositionToBeMutated has to be stored ! //a new gene pointing to a ticker and ! //the proposed newValueForGene points to a ticker ! //already stored in the given genome ! newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene +1); ! //TODO add if when it is mutated a threshold ! //(just a single threshold or the pair of thresholds) ! if(genePositionToBeMutated > this.numOfGenesDedicatedToThresholds - 1) ! GenomeManagement.MutateOneGene(genome, ! genePositionToBeMutated, newValueForGene); } } |