[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting GenomeManagerForEfficientPo
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-08-10 03:57:04
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20455/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs GenomeManipulator.cs Log Message: GetNewGeneValue and Mutate have been modified. Added new method to GenomeManipulator. Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** GenomeManagerForEfficientPortfolio.cs 7 Aug 2005 22:37:28 -0000 1.16 --- GenomeManagerForEfficientPortfolio.cs 8 Aug 2005 19:15:40 -0000 1.17 *************** *** 230,236 **** int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); ! while(genome.HasGene(returnValue) || ! ( returnValue<0 && genome.HasGene(Math.Abs(returnValue) - 1 ) )|| ! (returnValue>0 && genome.HasGene(- Math.Abs(returnValue) - 1)) ) //the portfolio can't have a long position and a short one for the same ticker { --- 230,235 ---- 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 { *************** *** 249,255 **** genome.MaxValueForGenes +1); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(genome.HasGene(returnValue) || ! ( returnValue<0 && genome.HasGene(Math.Abs(returnValue) - 1 ) )|| ! (returnValue>0 && genome.HasGene(- Math.Abs(returnValue) - 1)) ) //the efficient portfolio, in this implementation, // can't have a long position and a short position --- 248,253 ---- genome.MaxValueForGenes +1); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(GenomeManipulator.IsTickerContainedInGenome(newValueForGene, ! genome) ) //the efficient portfolio, in this implementation, // can't have a long position and a short position Index: GenomeManipulator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManipulator.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GenomeManipulator.cs 7 Aug 2005 08:20:53 -0000 1.4 --- GenomeManipulator.cs 8 Aug 2005 19:15:41 -0000 1.5 *************** *** 217,220 **** --- 217,239 ---- return childs; } + + /// <summary> + /// Returns true if a given gene, when decoded by the + /// GenomeManagerForEfficientPortfolio, refers to a + /// ticker already contained in a given genome + /// </summary> + /// <param name="geneCorrespondingToATicker">Gene, corresponding to a certain ticker, that has to be checked</param> + /// <param name="genome">Genome containing or not the ticker geneCorrespondingToATicker refers to</param> + public static bool IsTickerContainedInGenome(int geneCorrespondingToATicker, + Genome genome) + { + return( + genome.HasGene(geneCorrespondingToATicker) || + (geneCorrespondingToATicker<0 && + genome.HasGene(Math.Abs(geneCorrespondingToATicker)-1)) || + (geneCorrespondingToATicker>0 && genome.HasGene(- Math.Abs(geneCorrespondingToATicker)- 1)) + ); + + } } |