[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination MainForm.cs,1
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2005-07-23 18:06:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14325/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: MainForm.cs Log Message: - bestGenomes is managed in a better way - Console is used to writeln progress while the optimization process goes on Index: MainForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/MainForm.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MainForm.cs 13 Jul 2005 16:43:49 -0000 1.1 --- MainForm.cs 23 Jul 2005 18:06:31 -0000 1.2 *************** *** 1,7 **** using System; - using System.Data; - using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; --- 1,8 ---- using System; using System.Collections; using System.ComponentModel; + using System.Data; + using System.Drawing; + using System.Threading; using System.Windows.Forms; *************** *** 33,37 **** { ! private int numberOfTickersToBeSavedFromEachGeneration = 5; private string tickerGroupID; --- 34,38 ---- { ! // private int numberOfTickersToBeSavedFromEachGeneration = 5; private string tickerGroupID; *************** *** 46,49 **** --- 47,51 ---- private double targetReturn; private PortfolioType portfolioType; + private GeneticOptimizer GO; /// <summary> *************** *** 171,183 **** return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); } private void newGenerationEventHandler( object sender , NewGenerationEventArgs newGenerationEventArgs ) { ! ArrayList newGenerationBestGenomes = new ArrayList(); ArrayList generation = newGenerationEventArgs.Generation; ! for ( int i = generation.Count - 1 ; ! i > generation.Count - 1 - this.numberOfTickersToBeSavedFromEachGeneration ; ! i-- ) ! this.bestGenomes.Add( generation[ i ] ); } private void writeOptimizedGenomesToDisk() --- 173,203 ---- return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); } + private void newGenerationEventHandler_updateProgressBar( + NewGenerationEventArgs newGenerationEventArgs ) + { + // if ( ( newGenerationEventArgs.GenerationCounter == 1 ) || + // ( newGenerationEventArgs.GenerationCounter / 100 * 100 == + // newGenerationEventArgs.GenerationCounter ) ) + Console.WriteLine( + newGenerationEventArgs.GenerationCounter.ToString() + " / " + + newGenerationEventArgs.GenerationNumber.ToString() + + " - " + DateTime.Now.ToString() ); + } private void newGenerationEventHandler( object sender , NewGenerationEventArgs newGenerationEventArgs ) { ! newGenerationEventHandler_updateProgressBar( newGenerationEventArgs ); ArrayList generation = newGenerationEventArgs.Generation; ! if ( this.bestGenomes.Count == 0 ) ! // this is the first generation created and this.bestGenomes is still empty ! this.bestGenomes.Add( new GenomeRepresentation( ! (Genome)generation[ generation.Count - 1 ] ) ); ! for ( int i=0 ; i < generation.Count ; i++ ) ! if ( ((Genome)generation[ i ]).Fitness > ! ((GenomeRepresentation)this.bestGenomes[ ! this.bestGenomes.Count - 1 ]).Fitness ) ! // generation[ i ] is a genome better than the best already stored ! this.bestGenomes.Add( new GenomeRepresentation( ! (Genome)generation[ i ] ) ); } private void writeOptimizedGenomesToDisk() *************** *** 185,192 **** VisualObjectArchiver visualObjectArchiver = new VisualObjectArchiver(); ! visualObjectArchiver.Save( this.bestGenomes , "bgn" , "Save best genomes" ); } private void createOptimizedGenomes() { --- 205,218 ---- VisualObjectArchiver visualObjectArchiver = new VisualObjectArchiver(); ! OptimizationOutput optimizationOutput = ! new OptimizationOutput( this.firstDate , this.lastDate , ! this.bestGenomes ); ! visualObjectArchiver.Save( optimizationOutput , "bgn" , "Save best genomes" ); } + private void createOptimizedGenomes_go() + { + } private void createOptimizedGenomes() { *************** *** 195,199 **** // this.getSetOfTickersToBeOptimized_quickly(); DataTable setOfTickersToBeOptimized = ! this.getSetOfTickersToBeOptimized(); GenomeManagerForEfficientCTOPortfolio genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, --- 221,227 ---- // this.getSetOfTickersToBeOptimized_quickly(); DataTable setOfTickersToBeOptimized = ! this.getSetOfTickersToBeOptimized_quickly(); ! // DataTable setOfTickersToBeOptimized = ! // this.getSetOfTickersToBeOptimized(); GenomeManagerForEfficientCTOPortfolio genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, *************** *** 204,215 **** this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); ! GO.NewGeneration += new NewGenerationEventHandler( this.newGenerationEventHandler ); ! GO.Run(false); ! this.writeOptimizedGenomesToDisk(); } --- 232,247 ---- this.portfolioType); ! this.GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); ! this.GO.NewGeneration += new NewGenerationEventHandler( this.newGenerationEventHandler ); ! ! // Thread thread = new Thread(new ThreadStart(this.createOptimizedGenomes_go)); ! // thread.IsBackground = true; ! // thread.Start(); ! GO.Run(false); ! this.writeOptimizedGenomesToDisk(); } *************** *** 228,238 **** VisualObjectArchiver visualObjectArchiver = new VisualObjectArchiver(); ! this.bestGenomes = (ArrayList)visualObjectArchiver.Load( "Load best genomes" , "bgn" , "Load Genomes"); } } private void testOptimizedGenomesActually() { ! TestDisplayer testDisplayer = new TestDisplayer( this.bestGenomes ); testDisplayer.ShowDialog(); } --- 260,275 ---- VisualObjectArchiver visualObjectArchiver = new VisualObjectArchiver(); ! OptimizationOutput optimizationOutput = ! (OptimizationOutput)visualObjectArchiver.Load( "Load best genomes" , "bgn" , "Load Genomes"); + this.firstDate = optimizationOutput.FirstDate; + this.lastDate = optimizationOutput.LastDate; + this.bestGenomes = optimizationOutput.BestGenomes; } } private void testOptimizedGenomesActually() { ! TestDisplayer testDisplayer = new TestDisplayer( ! this.firstDate , this.lastDate , this.bestGenomes ); testDisplayer.ShowDialog(); } |