[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting GenomeManagerForEfficientPo
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-07-31 20:03:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17771/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs Log Message: Fixed bugs in GenomeManagerForEfficientPortfolio; - added new property CurrentGeneticOptimizer to the IGenomeManager interface; - added new public method CalculateRandomFitness() for a new computation of fitness (now the code this new computation of fitness has been remarked: if you want more details, please write to me) Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GenomeManagerForEfficientPortfolio.cs 27 Jul 2005 22:30:55 -0000 1.14 --- GenomeManagerForEfficientPortfolio.cs 31 Jul 2005 20:03:31 -0000 1.15 *************** *** 48,52 **** protected CandidateProperties[] setOfCandidates; protected int originalNumOfTickers; - protected int constToDiscoverDuplicateGenes; protected DateTime firstQuoteDate; protected DateTime lastQuoteDate; --- 48,51 ---- *************** *** 58,61 **** --- 57,61 ---- protected double[] portfolioRatesOfReturn; protected int numberOfExaminedReturns; + protected GeneticOptimizer currentGeneticOptimizer; static public string GetCleanTickerCode(string tickerCodeForLongOrShortTrade) *************** *** 100,103 **** --- 100,109 ---- } + public GeneticOptimizer CurrentGeneticOptimizer + { + get{return this.currentGeneticOptimizer;} + set{this.currentGeneticOptimizer = value;} + } + //setOfInitialTickers has to contain the //ticker's symbol in the first column ! *************** *** 113,117 **** this.setOfTickers = setOfInitialTickers; this.originalNumOfTickers = setOfInitialTickers.Rows.Count; - this.constToDiscoverDuplicateGenes = this.originalNumOfTickers + 1; this.firstQuoteDate = firstQuoteDate; this.lastQuoteDate = lastQuoteDate; --- 119,122 ---- *************** *** 130,134 **** if(this.portfolioType == PortfolioType.ShortAndLong) this.minValueForGenes = - this.originalNumOfTickers; ! //if gene g is negative, it refers to the ticker Abs(g+1) to be shorted } --- 135,139 ---- if(this.portfolioType == PortfolioType.ShortAndLong) this.minValueForGenes = - this.originalNumOfTickers; ! //if gene g is negative, it refers to the ticker |g|-1 to be shorted } *************** *** 168,172 **** //returnValue = normal.GetProbability(-this.targetPerformance*1.25,-this.targetPerformance*0.75); returnValue = normal.GetProbability(-this.targetPerformance); ! return returnValue; --- 173,188 ---- //returnValue = normal.GetProbability(-this.targetPerformance*1.25,-this.targetPerformance*0.75); returnValue = normal.GetProbability(-this.targetPerformance); ! /*the following code has to be tested ! if(this.currentGeneticOptimizer.AverageRandomFitness != 0.0 && ! this.currentGeneticOptimizer.StandardDeviationOfRandomFitness != 0.0) ! //the two properties remain equal to 0.0 for the GeneticOptimizer ! //instance created in the Run method: the two properties are updated ! //effectively only for the GO instance calling the Run method ! returnValue = (returnValue - this.CurrentGeneticOptimizer.AverageRandomFitness)/ ! this.CurrentGeneticOptimizer.StandardDeviationOfRandomFitness; ! if(returnValue < 0.0) ! returnValue = 0.0; ! //fitness should be now pure positive number ! */ return returnValue; *************** *** 205,210 **** { return ! GenomeManagement.MixGenesWithoutDuplicates(parent1, parent2, ! this.constToDiscoverDuplicateGenes); } --- 221,225 ---- { return ! GenomeManipulator.MixGenesWithoutDuplicates(parent1, parent2); } *************** *** 216,221 **** genome.MaxValueForGenes + 1); while(genome.HasGene(returnValue) || ! genome.HasGene(returnValue + this.constToDiscoverDuplicateGenes) || ! genome.HasGene(returnValue - this.constToDiscoverDuplicateGenes) ) //the portfolio can't have a long position and a short one for the same ticker { --- 231,236 ---- genome.MaxValueForGenes + 1); while(genome.HasGene(returnValue) || ! genome.HasGene(Math.Abs(returnValue) - 1 ) || ! genome.HasGene(- Math.Abs(returnValue) - 1) ) //the portfolio can't have a long position and a short one for the same ticker { *************** *** 232,240 **** // 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(genome.HasGene(newValueForGene) || ! genome.HasGene(newValueForGene + this.constToDiscoverDuplicateGenes) || ! genome.HasGene(newValueForGene - this.constToDiscoverDuplicateGenes) ) //the efficient portfolio, in this implementation, // can't have a long position and a short position --- 247,255 ---- // 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(genome.HasGene(newValueForGene) || ! genome.HasGene(Math.Abs(newValueForGene) - 1 ) || ! genome.HasGene(- Math.Abs(newValueForGene) - 1) ) //the efficient portfolio, in this implementation, // can't have a long position and a short position *************** *** 256,260 **** if(geneValue<0) { ! position = Math.Abs(geneValue + 1); initialCharForTickerCode = "-"; } --- 271,275 ---- if(geneValue<0) { ! position = Math.Abs(geneValue) - 1; initialCharForTickerCode = "-"; } |