[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting GenomeManagerForEfficient
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv22618/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs GenomeManagerForWeightedEfficientPortfolio.cs GenomeManipulator.cs Log Message: Changed IGenomeManager interface. Now, properties MinValueForGenes and MaxValueForGenes have been replaced by GetMinValueForGenes(int genePosition) and GetMaxValueForGenes(int genePosition) methods. Property CurrentGeneticOptimizer has been deleted from the interface. Modified the constructor of Genome class: now a GeneticOptimizer object is necessary for a creating a new instance of Genome. Some useless code has been deleted through out the classes used for genetic optimization. Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** GenomeManagerForEfficientPortfolio.cs 14 May 2006 18:35:46 -0000 1.23 --- GenomeManagerForEfficientPortfolio.cs 7 Aug 2006 21:03:24 -0000 1.24 *************** *** 73,84 **** } ! public int MinValueForGenes { ! get{return this.minValueForGenes;} } ! public int MaxValueForGenes { ! get{return this.maxValueForGenes;} } //end of implementation for properties --- 73,84 ---- } ! public int GetMinValueForGenes(int genePosition) { ! return this.minValueForGenes; } ! public int GetMaxValueForGenes(int genePosition) { ! return this.maxValueForGenes; } //end of implementation for properties *************** *** 100,108 **** } - public GeneticOptimizer CurrentGeneticOptimizer - { - get{return this.currentGeneticOptimizer;} - set{this.currentGeneticOptimizer = value;} - } public double[] PortfolioRatesOfReturn { --- 100,103 ---- *************** *** 145,154 **** private void setMinAndMaxValueForGenes() { ! this.minValueForGenes = 0; ! this.maxValueForGenes = this.originalNumOfTickers - 1; ! ! if(this.portfolioType == PortfolioType.ShortAndLong) ! this.minValueForGenes = - this.originalNumOfTickers; ! //if gene g is negative, it refers to the ticker |g|-1 to be shorted } --- 140,162 ---- private void setMinAndMaxValueForGenes() { ! switch (this.portfolioType) ! { ! case QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios.PortfolioType.OnlyLong : ! //OnlyLong orders are admitted ! this.minValueForGenes = 0; ! this.maxValueForGenes = this.originalNumOfTickers - 1; ! break; ! case QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios.PortfolioType.OnlyShort : ! //OnlyShort orders are admitted ! this.minValueForGenes = - this.originalNumOfTickers; ! //if gene g is negative, it refers to the ticker |g|-1 to be shorted ! this.maxValueForGenes = 0; ! break; ! case QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios.PortfolioType.ShortAndLong : ! //Both Long and Short orders are admitted ! this.minValueForGenes = - this.originalNumOfTickers; ! this.maxValueForGenes = this.originalNumOfTickers - 1; ! break; ! } } *************** *** 245,256 **** // the generation of new genes doesn't depend on gene's position // within the genome ! int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, ! genome.MaxValueForGenes + 1); while(GenomeManipulator.IsTickerContainedInGenome(returnValue, genome) ) //the portfolio can't have a long position and a short one for the same ticker { ! returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, ! genome.MaxValueForGenes + 1); } --- 253,264 ---- // the generation of new genes doesn't depend on gene's position // within the genome ! int returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); while(GenomeManipulator.IsTickerContainedInGenome(returnValue, genome) ) //the portfolio can't have a long position and a short one for the same ticker { ! returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); } *************** *** 262,268 **** // in this implementation only one gene is mutated // the new value has to be different from all the other genes of the genome ! int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, ! genome.MaxValueForGenes +1); ! int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); while(GenomeManipulator.IsTickerContainedInGenome(newValueForGene, genome) ) --- 270,277 ---- // in this implementation only one gene is mutated // the new value has to be different from all the other genes of the genome ! int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); ! while(GenomeManipulator.IsTickerContainedInGenome(newValueForGene, genome) ) *************** *** 271,276 **** // for the same ticker { ! newValueForGene = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, ! genome.MaxValueForGenes + 1); } GenomeManagement.MutateOneGene(genome, mutationRate, --- 280,285 ---- // for the same ticker { ! newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); } GenomeManagement.MutateOneGene(genome, mutationRate, Index: GenomeManipulator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManipulator.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GenomeManipulator.cs 26 Mar 2006 20:07:17 -0000 1.6 --- GenomeManipulator.cs 7 Aug 2006 21:03:24 -0000 1.7 *************** *** 205,212 **** { initializeStaticMembers(parent1, parent2); - if(parent1.Size > (parent1.MaxValueForGenes - parent1.MinValueForGenes + 1)) - //it is impossible not to duplicate genes if size is too - // large for the range of variation of each gene - throw new Exception("Impossible to avoid duplicates with the given size!"); if(parent1.Size != parent2.Size) throw new Exception("Genomes must have the same size!"); --- 205,208 ---- Index: GenomeManagerForWeightedEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForWeightedEfficientPortfolio.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GenomeManagerForWeightedEfficientPortfolio.cs 25 Jul 2006 15:22:50 -0000 1.4 --- GenomeManagerForWeightedEfficientPortfolio.cs 7 Aug 2006 21:03:24 -0000 1.5 *************** *** 127,132 **** // in this implementation only new gene values pointing to tickers // must be different from the others already stored (in odd positions of genome) ! int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, ! genome.MaxValueForGenes + 1); while(genePosition%2 == 1 && GenomeManipulator.IsTickerContainedInGenome(returnValue,genome)) --- 127,132 ---- // in this implementation only new gene values pointing to tickers // must be different from the others already stored (in odd positions of genome) ! int returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); while(genePosition%2 == 1 && GenomeManipulator.IsTickerContainedInGenome(returnValue,genome)) *************** *** 137,142 **** { // a new returnValue has to be generated ! returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, ! genome.MaxValueForGenes + 1); } --- 137,142 ---- { // a new returnValue has to be generated ! returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); } *************** *** 147,153 **** { // in this implementation only one gene is mutated ! int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, ! genome.MaxValueForGenes +1); ! int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); while(genePositionToBeMutated%2 == 1 && GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome)) --- 147,154 ---- { // in this implementation only one gene is mutated ! int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) +1); ! while(genePositionToBeMutated%2 == 1 && GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome)) *************** *** 157,162 **** //already stored in the given genome { ! newValueForGene = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, ! genome.MaxValueForGenes + 1); } GenomeManagement.MutateOneGene(genome, mutationRate, --- 158,163 ---- //already stored in the given genome { ! newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) +1); } GenomeManagement.MutateOneGene(genome, mutationRate, |