[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting GenomeManagerForEfficientPo
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-11-08 18:32:33
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23226/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs Log Message: Changed IGenomeManager interface: added new parameters for the GetNewGeneValue method. Changed access modifier for some methods of GenomeManagerForEfficientPortfolio Updated Genome and GeneticOptimizer. Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** GenomeManagerForEfficientPortfolio.cs 23 Oct 2005 19:09:04 -0000 1.20 --- GenomeManagerForEfficientPortfolio.cs 8 Nov 2005 18:32:25 -0000 1.21 *************** *** 52,56 **** protected double targetPerformance; protected double variance; ! protected double lowerPartialMoment; protected double rateOfReturn; protected PortfolioType portfolioType; --- 52,56 ---- protected double targetPerformance; protected double variance; ! //protected double lowerPartialMoment; protected double rateOfReturn; protected PortfolioType portfolioType; *************** *** 224,228 **** #endregion ! public Genome[] GetChilds(Genome parent1, Genome parent2) { return --- 224,228 ---- #endregion ! public virtual Genome[] GetChilds(Genome parent1, Genome parent2) { return *************** *** 230,237 **** } ! public int GetNewGeneValue(Genome genome) { // in this implementation new gene values must be different from // the others already stored in the given genome int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); --- 230,239 ---- } ! public virtual int GetNewGeneValue(Genome genome, int genePosition) { // in this implementation new gene values must be different from // the others already stored in the given genome + // 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); *************** *** 247,251 **** } ! public void Mutate(Genome genome, double mutationRate) { // in this implementation only one gene is mutated --- 249,253 ---- } ! public virtual void Mutate(Genome genome, double mutationRate) { // in this implementation only one gene is mutated *************** *** 269,273 **** #region Decode ! private string decode_getTickerCodeForLongOrShortTrade(int geneValue) { string initialCharForTickerCode = ""; --- 271,275 ---- #region Decode ! protected string decode_getTickerCodeForLongOrShortTrade(int geneValue) { string initialCharForTickerCode = ""; *************** *** 355,364 **** { float[] returnValue = null; return returnValue; } #region getPortfolioRatesOfReturn ! private int getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(int geneValueForTickerIdx) { int position = geneValueForTickerIdx; --- 357,374 ---- { float[] returnValue = null; + this.numberOfExaminedReturns = returnValue.Length; return returnValue; + + } + + protected virtual double getTickerWeight(int[] genes, int tickerPositionInGenes) + { + return 1.0/genes.Length; + //weights for tickers are all the same in this implementation } #region getPortfolioRatesOfReturn ! protected int getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(int geneValueForTickerIdx) { int position = geneValueForTickerIdx; *************** *** 368,393 **** } ! private float getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(int tickerIdx, int arrayElementPosition) { bool longReturns = false; ! if(tickerIdx > 0) ! //the tickerIdx points to a ticker for which long returns are to be examined longReturns = true; ! int position = this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(tickerIdx); this.setOfCandidates[position].LongRatesOfReturn = longReturns; float[] arrayOfRatesOfReturn = this.setOfCandidates[position].ArrayOfRatesOfReturn; ! return (arrayOfRatesOfReturn[arrayElementPosition]/this.GenomeSize); ! //the investment is assumed to be equally divided for each ticker } ! protected double[] getPortfolioRatesOfReturn(int[] tickersIdx) { double[] returnValue = new double[this.numberOfExaminedReturns]; for(int i = 0; i<returnValue.Length; i++) { ! foreach(int tickerIdx in tickersIdx) returnValue[i] += ! this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(tickerIdx,i); } return returnValue; --- 378,404 ---- } ! protected float getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(int[] genes, ! int tickerPositionInGenes, int arrayElementPosition) { bool longReturns = false; ! if(genes[tickerPositionInGenes] > 0) ! //genes[tickerPositionInGenes], the code for ticker, points to a ticker for which long returns are to be examined longReturns = true; ! int position = this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(genes[tickerPositionInGenes]); this.setOfCandidates[position].LongRatesOfReturn = longReturns; float[] arrayOfRatesOfReturn = this.setOfCandidates[position].ArrayOfRatesOfReturn; ! double tickerWeight = this.getTickerWeight(genes,tickerPositionInGenes); ! return (arrayOfRatesOfReturn[arrayElementPosition]*(float)tickerWeight); } ! protected virtual double[] getPortfolioRatesOfReturn(int[] genes) { double[] returnValue = new double[this.numberOfExaminedReturns]; for(int i = 0; i<returnValue.Length; i++) { ! for(int j=0; j<genes.Length; j++) returnValue[i] += ! this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(genes,j,i); } return returnValue; |