quantproject-developers Mailing List for QuantProject (Page 105)
Brought to you by:
glauco_1
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(7) |
Nov
(103) |
Dec
(67) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(52) |
Feb
(9) |
Mar
(69) |
Apr
(53) |
May
(80) |
Jun
(23) |
Jul
(24) |
Aug
(112) |
Sep
(9) |
Oct
|
Nov
(58) |
Dec
(93) |
| 2005 |
Jan
(90) |
Feb
(93) |
Mar
(61) |
Apr
(56) |
May
(37) |
Jun
(61) |
Jul
(55) |
Aug
(68) |
Sep
(25) |
Oct
(46) |
Nov
(41) |
Dec
(37) |
| 2006 |
Jan
(33) |
Feb
(7) |
Mar
(19) |
Apr
(27) |
May
(73) |
Jun
(49) |
Jul
(83) |
Aug
(66) |
Sep
(45) |
Oct
(16) |
Nov
(15) |
Dec
(7) |
| 2007 |
Jan
(14) |
Feb
(33) |
Mar
|
Apr
(21) |
May
|
Jun
(34) |
Jul
(18) |
Aug
(100) |
Sep
(39) |
Oct
(55) |
Nov
(12) |
Dec
(2) |
| 2008 |
Jan
(120) |
Feb
(133) |
Mar
(129) |
Apr
(104) |
May
(42) |
Jun
(2) |
Jul
(52) |
Aug
(99) |
Sep
(134) |
Oct
|
Nov
(137) |
Dec
(48) |
| 2009 |
Jan
(48) |
Feb
(55) |
Mar
(61) |
Apr
(3) |
May
(2) |
Jun
(1) |
Jul
|
Aug
(51) |
Sep
|
Oct
(7) |
Nov
|
Dec
|
| 2010 |
Jan
(7) |
Feb
(1) |
Mar
(145) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
| 2011 |
Jan
(78) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(88) |
Sep
(6) |
Oct
(1) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Marco M. <mi...@us...> - 2005-07-25 22:30:40
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20838/b1_ADT/Optimizing/Genetic Modified Files: GenomeManagement.cs Log Message: - Added new public method SetRandomGenerator, for setting the Random generator used by the other public methods. Index: GenomeManagement.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagement.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GenomeManagement.cs 13 Jul 2005 16:37:04 -0000 1.4 --- GenomeManagement.cs 25 Jul 2005 22:30:32 -0000 1.5 *************** *** 43,48 **** static GenomeManagement() { ! RandomGenerator = new Random((int)DateTime.Now.Ticks); ! childs = new Genome[2]; } --- 43,48 ---- static GenomeManagement() { ! RandomGenerator = new Random((int)DateTime.Now.Ticks); ! childs = new Genome[2]; } *************** *** 64,68 **** } } ! /// <summary> /// Returns an array of genome (length = 2) based /// on classical one point crossover genes recombination --- 64,80 ---- } } ! ! /// <summary> ! /// It sets randomGenerator used by all other public methods ! /// provided by the class. ! /// If random generation process has to be controlled, ! /// it needs to be called before all the other public methods ! /// </summary> ! public static void SetRandomGenerator(int seedForRandomGenerator) ! { ! GenomeManagement.RandomGenerator = new Random(seedForRandomGenerator); ! } ! ! /// <summary> /// Returns an array of genome (length = 2) based /// on classical one point crossover genes recombination |
|
From: Marco M. <mi...@us...> - 2005-07-25 22:27:58
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20238/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: - Added if condition for calling NewGeneration event (just to avoid run time errors if no handler has been added to the event) - added new constructor: now it is possible to set directly the randomGenerator Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GeneticOptimizer.cs 23 Jul 2005 18:02:23 -0000 1.6 --- GeneticOptimizer.cs 25 Jul 2005 22:27:49 -0000 1.7 *************** *** 41,45 **** { #region fields ! private static Random random = new Random((int)DateTime.Now.Ticks); private double mutationRate; --- 41,45 ---- { #region fields ! private Random random; private double mutationRate; *************** *** 143,147 **** this.populationSize = populationSize; this.generationNumber = generationNumber; ! this.commonInitialization(); } --- 143,147 ---- this.populationSize = populationSize; this.generationNumber = generationNumber; ! this.random = new Random((int)DateTime.Now.Ticks); this.commonInitialization(); } *************** *** 158,162 **** this.generationNumber = generationNumber; this.genomeManager = genomeManager; ! this.commonInitialization(); } --- 158,176 ---- this.generationNumber = generationNumber; this.genomeManager = genomeManager; ! this.random = new Random((int)DateTime.Now.Ticks); ! this.commonInitialization(); ! } ! ! public GeneticOptimizer(double crossoverRate, double mutationRate, double elitismRate, ! int populationSize, int generationNumber, ! IGenomeManager genomeManager, int seedForRandomGenerator) ! { ! this.crossoverRate = crossoverRate; ! this.mutationRate = mutationRate; ! this.elitismRate = elitismRate; ! this.populationSize = populationSize; ! this.generationNumber = generationNumber; ! this.genomeManager = genomeManager; ! this.random = new Random(seedForRandomGenerator); this.commonInitialization(); } *************** *** 234,239 **** this.createGenomes(); this.currentGeneration.Sort(this.genomeComparer); ! this.NewGeneration( this , new NewGenerationEventArgs( ! this.currentGeneration , this.generationCounter , this.generationNumber ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); --- 248,254 ---- this.createGenomes(); this.currentGeneration.Sort(this.genomeComparer); ! if(this.NewGeneration != null) ! this.NewGeneration( this , new NewGenerationEventArgs( ! this.currentGeneration , this.generationCounter , this.generationNumber ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); *************** *** 263,267 **** private int rouletteSelection() { ! double randomFitness = this.totalFitness *(double)GeneticOptimizer.random.Next(1,1001)/1000; int idx = -1; int first = 0; --- 278,282 ---- private int rouletteSelection() { ! double randomFitness = this.totalFitness *(double)this.random.Next(1,1001)/1000; int idx = -1; int first = 0; *************** *** 294,303 **** { this.totalFitness = 0.0; - for (int i = 0; i < this.populationSize; i++) - { - Genome g = ((Genome) this.currentGeneration[i]); - this.totalFitness += g.Fitness; - } } --- 309,316 ---- { this.totalFitness = 0.0; + foreach(Genome g in this.currentGeneration) + this.totalFitness += g.Fitness; + } *************** *** 364,368 **** parent1 = ((Genome) this.currentGeneration[indexForParent1]); parent2 = ((Genome) this.currentGeneration[indexForParent2]); ! if ((double)GeneticOptimizer.random.Next(1,1001)/1000 < this.crossoverRate) { childs = this.genomeManager.GetChilds(parent1, parent2); --- 377,381 ---- parent1 = ((Genome) this.currentGeneration[indexForParent1]); parent2 = ((Genome) this.currentGeneration[indexForParent2]); ! if ((double)this.random.Next(1,1001)/1000 < this.crossoverRate) { childs = this.genomeManager.GetChilds(parent1, parent2); *************** *** 387,392 **** this.updateCurrentGeneration(); this.currentGeneration.Sort(this.genomeComparer); ! this.NewGeneration( this , new NewGenerationEventArgs( ! this.currentGeneration , this.generationCounter , this.generationNumber ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); --- 400,406 ---- this.updateCurrentGeneration(); this.currentGeneration.Sort(this.genomeComparer); ! if(this.NewGeneration != null) ! this.NewGeneration( this , new NewGenerationEventArgs( ! this.currentGeneration , this.generationCounter , this.generationNumber ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); |
|
From: Marco M. <mi...@us...> - 2005-07-25 22:24:18
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19073/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: Added CandidateProperties class, where to store information on tickers used by the GenomeManagerForEfficientPortfolio. Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** b7_Scripts.csproj 23 Jul 2005 17:11:22 -0000 1.31 --- b7_Scripts.csproj 25 Jul 2005 22:24:09 -0000 1.32 *************** *** 164,167 **** --- 164,172 ---- /> <File + RelPath = "TickerSelectionTesting\CandidateProperties.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\EndOfDayTimerHandler.cs" SubType = "Code" *************** *** 279,287 **** /> <File - RelPath = "WalkForwardTesting\LinearCombination\TestDisplayer.resx" - DependentUpon = "TestDisplayer.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "WalkForwardTesting\LinearCombination\VisualObjectArchiver.cs" SubType = "Code" --- 284,287 ---- |
|
From: Marco M. <mi...@us...> - 2005-07-25 22:24:18
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19073/b7_Scripts/TickerSelectionTesting Added Files: CandidateProperties.cs Log Message: Added CandidateProperties class, where to store information on tickers used by the GenomeManagerForEfficientPortfolio. --- NEW FILE: CandidateProperties.cs --- /* QuantProject - Quantitative Finance Library CandidateProperties.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// This is the class containing basic information /// for each candidate to be evaluated in order /// to discover the efficient frontier /// </summary> [Serializable] public class CandidateProperties { private string ticker; private float[] arrayOfRatesOfReturn; private float[] oppositeArrayOfRatesOfReturn; private bool longRatesOfReturn; public CandidateProperties(string ticker, float[] arrayOfRatesOfReturn) { this.ticker = ticker; this.longRatesOfReturn = true; this.arrayOfRatesOfReturn = arrayOfRatesOfReturn; } private float[] arrayOfRatesOfReturn_getOppositeArrayOfRatesOfReturn() { if(this.oppositeArrayOfRatesOfReturn == null) //opposite array of rates of returns not set yet { this.oppositeArrayOfRatesOfReturn = new float[this.arrayOfRatesOfReturn.Length]; for(int i = 0; i<this.arrayOfRatesOfReturn.Length; i++) oppositeArrayOfRatesOfReturn[i] = -this.arrayOfRatesOfReturn[i]; } return this.oppositeArrayOfRatesOfReturn; } public float[] ArrayOfRatesOfReturn { get { float[] returnValue = this.arrayOfRatesOfReturn; if(!this.longRatesOfReturn) returnValue = this.arrayOfRatesOfReturn_getOppositeArrayOfRatesOfReturn(); return returnValue; } } public bool LongRatesOfReturn { set{this.longRatesOfReturn = value;} get{return this.longRatesOfReturn;} } public string Ticker { get{return this.ticker;} } } } |
|
From: Glauco S. <gla...@us...> - 2005-07-23 18:10:42
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14965/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: TestDisplayer.cs Log Message: Improvements: - a gris shows the better optimized genomes - a firstDate and lastDate date selectors are displayed * default is the optimization interval * they can be changed to check the out of sample behavior - right click on a grid row to backtest the selected genome Index: TestDisplayer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/TestDisplayer.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestDisplayer.cs 13 Jul 2005 16:43:49 -0000 1.1 --- TestDisplayer.cs 23 Jul 2005 18:10:33 -0000 1.2 *************** *** 1,3 **** --- 1,26 ---- + /* + QuantProject - Quantitative Finance Library + + TestDisplayer.cs + Copyright (C) 2003 + Glauco Siliprandi + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + using System; + using System.Data; using System.Drawing; using System.Collections; *************** *** 17,20 **** --- 40,45 ---- /// </summary> private System.ComponentModel.Container components = null; + private System.Windows.Forms.DateTimePicker dtpFirstDate; + private System.Windows.Forms.DateTimePicker dtpLastDate; // Glauco code *************** *** 25,29 **** this.dgBestGenomes.DataSource = this.bestGenomes; } ! public TestDisplayer( ArrayList bestGenomes ) { // --- 50,55 ---- this.dgBestGenomes.DataSource = this.bestGenomes; } ! public TestDisplayer( DateTime firstDate , DateTime lastDate , ! ArrayList bestGenomes ) { // *************** *** 33,36 **** --- 59,64 ---- // Glauco code + this.dtpFirstDate.Value = firstDate; + this.dtpLastDate.Value = lastDate; this.bestGenomes = bestGenomes; this.testdisplayer(); *************** *** 60,63 **** --- 88,93 ---- { this.dgBestGenomes = new System.Windows.Forms.DataGrid(); + this.dtpFirstDate = new System.Windows.Forms.DateTimePicker(); + this.dtpLastDate = new System.Windows.Forms.DateTimePicker(); ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); this.SuspendLayout(); *************** *** 66,80 **** // this.dgBestGenomes.DataMember = ""; this.dgBestGenomes.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dgBestGenomes.Location = new System.Drawing.Point(48, 32); this.dgBestGenomes.Name = "dgBestGenomes"; ! this.dgBestGenomes.Size = new System.Drawing.Size(208, 216); this.dgBestGenomes.TabIndex = 0; // // TestDisplayer // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.dgBestGenomes}); this.Name = "TestDisplayer"; --- 96,127 ---- // this.dgBestGenomes.DataMember = ""; + this.dgBestGenomes.Dock = System.Windows.Forms.DockStyle.Bottom; this.dgBestGenomes.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dgBestGenomes.Location = new System.Drawing.Point(0, 93); this.dgBestGenomes.Name = "dgBestGenomes"; ! this.dgBestGenomes.Size = new System.Drawing.Size(496, 248); this.dgBestGenomes.TabIndex = 0; + this.dgBestGenomes.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgBestGenomes_MouseUp); + // + // dtpFirstDate + // + this.dtpFirstDate.Location = new System.Drawing.Point(16, 24); + this.dtpFirstDate.Name = "dtpFirstDate"; + this.dtpFirstDate.TabIndex = 1; + // + // dtpLastDate + // + this.dtpLastDate.Location = new System.Drawing.Point(264, 24); + this.dtpLastDate.Name = "dtpLastDate"; + this.dtpLastDate.Size = new System.Drawing.Size(208, 20); + this.dtpLastDate.TabIndex = 2; // // TestDisplayer // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(496, 341); this.Controls.AddRange(new System.Windows.Forms.Control[] { + this.dtpLastDate, + this.dtpFirstDate, this.dgBestGenomes}); this.Name = "TestDisplayer"; *************** *** 85,88 **** --- 132,157 ---- } #endregion + + private void dgBestGenomes_MouseUp_actually(object sender, System.Windows.Forms.MouseEventArgs e) + { + DataGrid dataGrid = (DataGrid)sender; + Point point = new Point( e.X , e.Y ); + DataGrid.HitTestInfo hitTestInfo = dataGrid.HitTest( point ); + ArrayList bestGenomes = (ArrayList)dataGrid.DataSource; + // DataRow dataRow = dataTable.Rows[ hitTestInfo.Row ]; + GenomeRepresentation genomeRepresentation = + (GenomeRepresentation)bestGenomes[ hitTestInfo.Row ]; + string[] signedTickers = GenomeRepresentation.GetSignedTickers( + genomeRepresentation.SignedTickers ); + LinearCombinationTest linearCombinationTest = + new LinearCombinationTest( this.dtpFirstDate.Value , + this.dtpLastDate.Value , signedTickers ); + linearCombinationTest.Run(); + } + private void dgBestGenomes_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) + { + if ( e.Button == MouseButtons.Right ) + this.dgBestGenomes_MouseUp_actually( sender , e ); + } } } |
|
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(); } |
|
From: Glauco S. <gla...@us...> - 2005-07-23 18:03:19
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13831/b4_Business/a1_Financial/a2_Accounting Modified Files: Portfolio.cs Log Message: The property Positions has been added Index: Portfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/Portfolio.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Portfolio.cs 4 Feb 2005 00:12:25 -0000 1.6 --- Portfolio.cs 23 Jul 2005 18:03:08 -0000 1.7 *************** *** 39,42 **** --- 39,46 ---- public class Portfolio : Hashtable { + public ICollection Positions + { + get { return this.Values; } + } public Portfolio() : base() { |
|
From: Glauco S. <gla...@us...> - 2005-07-23 18:02:33
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13685/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: The NewGeneration event args are enriched with currentGeneration and generationNumber Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GeneticOptimizer.cs 13 Jul 2005 16:36:03 -0000 1.5 --- GeneticOptimizer.cs 23 Jul 2005 18:02:23 -0000 1.6 *************** *** 234,238 **** this.createGenomes(); this.currentGeneration.Sort(this.genomeComparer); ! this.NewGeneration( this , new NewGenerationEventArgs( this.currentGeneration ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); --- 234,239 ---- this.createGenomes(); this.currentGeneration.Sort(this.genomeComparer); ! this.NewGeneration( this , new NewGenerationEventArgs( ! this.currentGeneration , this.generationCounter , this.generationNumber ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); *************** *** 386,390 **** this.updateCurrentGeneration(); this.currentGeneration.Sort(this.genomeComparer); ! this.NewGeneration( this , new NewGenerationEventArgs( this.currentGeneration ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); --- 387,392 ---- this.updateCurrentGeneration(); this.currentGeneration.Sort(this.genomeComparer); ! this.NewGeneration( this , new NewGenerationEventArgs( ! this.currentGeneration , this.generationCounter , this.generationNumber ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); |
|
From: Glauco S. <gla...@us...> - 2005-07-23 18:01:11
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13352/b1_ADT/Optimizing/Genetic Modified Files: NewGenerationEventArgs.cs Log Message: - The property GenerationNumber has been added - The property GenerationCounter has been added Index: NewGenerationEventArgs.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/NewGenerationEventArgs.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NewGenerationEventArgs.cs 13 Jul 2005 16:32:10 -0000 1.1 --- NewGenerationEventArgs.cs 23 Jul 2005 18:01:02 -0000 1.2 *************** *** 33,41 **** --- 33,60 ---- { private ArrayList generation; + private int generationNumber; + private int generationCounter; + /// <summary> + /// Current generation + /// </summary> public ArrayList Generation { get { return this.generation; } } + /// <summary> + /// Total number of generations to be created + /// </summary> + public int GenerationNumber + { + get { return this.generationNumber; } + } + /// <summary> + /// Number of the current generation + /// </summary> + public int GenerationCounter + { + get { return this.generationCounter; } + } public NewGenerationEventArgs( ArrayList generation ) *************** *** 43,46 **** --- 62,72 ---- this.generation = generation; } + public NewGenerationEventArgs( ArrayList generation , + int generationCounter , int generationNumber ) + { + this.generation = generation; + this.generationCounter = generationCounter; + this.generationNumber = generationNumber; + } } } |
|
From: Glauco S. <gla...@us...> - 2005-07-23 17:58:52
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12752/b7_Scripts/WalkForwardTesting/LinearCombination Added Files: GenomeRepresentation.cs Log Message: Provides the genome relevant informations --- NEW FILE: GenomeRepresentation.cs --- /* QuantProject - Quantitative Finance Library GenomeRepresentation.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Financial.Ordering; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Provides the genome relevant informations /// </summary> [Serializable] public class GenomeRepresentation { private Genome genome; public string SignedTickers { get { string signedTickers = ""; foreach ( string geneValue in (string[])genome.Meaning ) signedTickers += geneValue + ";"; signedTickers = signedTickers.Substring( 0 , signedTickers.Length - 1 ); return signedTickers; } } public double Fitness { get { return this.genome.Fitness; } } public static string[] GetSignedTickers( string signedTickers ) { string[] returnValue = signedTickers.Split( ";".ToCharArray() ); return returnValue; } public static OrderType GetOrderType( string signedTicker ) { OrderType returnValue; if ( signedTicker.IndexOf( "-" ) == 0 ) returnValue = OrderType.MarketSellShort; else returnValue = OrderType.MarketBuy; return returnValue; } public static string GetTicker( string signedTicker ) { string returnValue; if ( signedTicker.IndexOf( "-" ) == 0 ) returnValue = signedTicker.Substring( 1 , signedTicker.Length - 1 ); else returnValue = signedTicker; return returnValue; } public GenomeRepresentation( Genome genome ) { this.genome = genome; } } } |
|
From: Glauco S. <gla...@us...> - 2005-07-23 17:57:10
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12281/b7_Scripts/WalkForwardTesting/LinearCombination Added Files: LinearCombinationTest.cs Log Message: Object to test a linear combination strategy on given positions, on a given period of time --- NEW FILE: LinearCombinationTest.cs --- /* QuantProject - Quantitative Finance Library LinearCombinationTest.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Object to test a linear combination strategy on given positions, /// on a given period of time /// </summary> public class LinearCombinationTest { private DateTime firstDate; private DateTime lastDate; private string[] signedTickers; private HistoricalRawQuoteProvider historicalQuoteProvider; private HistoricalEndOfDayTimer historicalEndOfDayTimer; private Account account; public LinearCombinationTest( DateTime firstDate , DateTime lastDate , string[] signedTickers ) { this.firstDate = firstDate; this.lastDate = lastDate; this.signedTickers = signedTickers; } private long marketOpenEventHandler_addOrder_getQuantity( string ticker ) { double accountValue = this.account.GetMarketValue(); double currentTickerAsk = this.account.DataStreamer.GetCurrentAsk( ticker ); double maxPositionValueForThisTicker = accountValue/this.signedTickers.Length; long quantity = Convert.ToInt64( Math.Floor( maxPositionValueForThisTicker / currentTickerAsk ) ); return quantity; } private void marketOpenEventHandler_addOrder( string signedTicker ) { OrderType orderType = GenomeRepresentation.GetOrderType( signedTicker ); string ticker = GenomeRepresentation.GetTicker( signedTicker ); long quantity = marketOpenEventHandler_addOrder_getQuantity( ticker ); Order order = new Order( orderType , new Instrument( ticker ) , quantity ); this.account.AddOrder( order ); } private void marketOpenEventHandler_addOrders() { foreach ( string signedTicker in this.signedTickers ) marketOpenEventHandler_addOrder( signedTicker ); } private void marketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( ( this.account.CashAmount == 0 ) && ( this.account.Transactions.Count == 0 ) ) // cash has not been added yet this.account.AddCash( 30000 ); marketOpenEventHandler_addOrders(); } private void fiveMinutesBeforeMarketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); foreach ( Position position in this.account.Portfolio.Positions ) tickers.Add( position.Instrument.Key ); foreach ( string ticker in tickers ) this.account.ClosePosition( ticker ); } private void fiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { fiveMinutesBeforeMarketCloseEventHandler_closePositions(); } private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.EndOfDayTimer.GetCurrentTime().DateTime >= this.lastDate ) this.account.EndOfDayTimer.Stop(); } public void Run() { this.historicalEndOfDayTimer = new IndexBasedEndOfDayTimer( new EndOfDayDateTime( this.firstDate , EndOfDaySpecificTime.MarketOpen ) , "DYN" ); this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); this.account = new Account( "LinearCombination" , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , this.historicalQuoteProvider ) ); // OneRank oneRank = new OneRank( account , // this.endDateTime ); this.historicalEndOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.marketOpenEventHandler ); this.historicalEndOfDayTimer.FiveMinutesBeforeMarketClose += new FiveMinutesBeforeMarketCloseEventHandler( this.fiveMinutesBeforeMarketCloseEventHandler ); this.historicalEndOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.oneHourAfterMarketCloseEventHandler ); this.account.EndOfDayTimer.Start(); Report report = new Report( this.account , this.historicalQuoteProvider ); report.Create( "Linear Combination" , 1 , new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^SPX" ); // ObjectArchiver.Archive( report.AccountReport , // @"C:\Documents and Settings\Glauco\Desktop\reports\runOneRank.qPr" ); report.Show(); } } } |
|
From: Glauco S. <gla...@us...> - 2005-07-23 17:54:41
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11921/b7_Scripts/WalkForwardTesting/LinearCombination Added Files: OptimizationOutput.cs Log Message: Data to be saved/load to/from disk, resulting from the optimization process. --- NEW FILE: OptimizationOutput.cs --- /* QuantProject - Quantitative Finance Library GenomeRepresentation.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Data to be saved/load to/from disk, resulting from the /// optimization process. /// </summary> [Serializable] public class OptimizationOutput { private DateTime firstDate; public DateTime FirstDate { get { return this.firstDate; } } private DateTime lastDate; public DateTime LastDate { get { return this.lastDate; } } private ArrayList bestGenomes; public ArrayList BestGenomes { get { return this.bestGenomes; } } public OptimizationOutput( DateTime firstDate , DateTime lastDate , ArrayList bestGenomes ) { this.firstDate = firstDate; this.lastDate = lastDate; this.bestGenomes = bestGenomes; } } } |
|
From: Glauco S. <gla...@us...> - 2005-07-23 17:11:58
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3693/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: - WalkForwardTesting\LinearCombination\GenomeRepresentation.cs has been added - WalkForwardTesting\LinearCombination\LinearCombinationTest.cs has been added - WalkForwardTesting\LinearCombination\OptimizationOutput.cs has been added Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** b7_Scripts.csproj 13 Jul 2005 16:42:24 -0000 1.30 --- b7_Scripts.csproj 23 Jul 2005 17:11:22 -0000 1.31 *************** *** 244,247 **** --- 244,257 ---- /> <File + RelPath = "WalkForwardTesting\LinearCombination\GenomeRepresentation.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\LinearCombination\LinearCombinationTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\MainForm.cs" SubType = "Form" *************** *** 254,257 **** --- 264,272 ---- /> <File + RelPath = "WalkForwardTesting\LinearCombination\OptimizationOutput.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\RunBestLinearCombination.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2005-07-13 16:50:36
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26378 Added Files: VisualObjectArchiver.cs Log Message: Saves/Loads objects to/form disk, invoking a dialog form to ask for the full file path to write/read to/from. Now it is in the Script "area", but it is written to be fully purpose. Millo, I believe it may be useful in the presentation layer (I've seen it would semplify some code you wrote to serialize/deserialize objects to/from disk). Please let me know your thoughts. --- NEW FILE: VisualObjectArchiver.cs --- /* QuantProject - Quantitative Finance Library VisualObjectArchiver.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using QuantProject.ADT.FileManaging; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Saves/Loads objects to/form disk, invoking a dialog form to ask for /// the full file path to write/read to/from. /// </summary> public class VisualObjectArchiver { private SaveFileDialog saveFileDialog; /// <summary> /// object to be saved /// </summary> private Object obj; public VisualObjectArchiver() { } // public VisualObjectArchiver( ArrayList bestGenomes , string suffix , // string initialDirectory , string title ) // { // this.visualObjectArchiver( bestGenomes , suffix , initialDirectory , // title ); // } private void fileOkEventHandler( object sender , CancelEventArgs e ) { QuantProject.ADT.FileManaging.ObjectArchiver.Archive( this.obj , ((SaveFileDialog)this.saveFileDialog).FileName ); } private void save( object obj , string suffix , string title , string initialDirectory ) { this.obj = obj; this.saveFileDialog = new SaveFileDialog(); this.saveFileDialog.DefaultExt = suffix; this.saveFileDialog.Title = title; this.saveFileDialog.InitialDirectory = initialDirectory; this.saveFileDialog.AddExtension = true; this.saveFileDialog.CreatePrompt = true; this.saveFileDialog.OverwritePrompt = true; //the saveFileDialog title is the same as the //menu item clicked by the user this.saveFileDialog.CheckPathExists = true; this.saveFileDialog.FileOk += new CancelEventHandler( this.fileOkEventHandler ); this.saveFileDialog.ShowDialog(); } public void Save( object obj , string suffix , string title , string initialDirectory ) { this.save( obj , suffix , title , initialDirectory ); } public void Save( object obj , string suffix , string title ) { this.Save( obj , suffix , title , System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] ); } private string getPath( string title ) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = title; openFileDialog.Multiselect = false; openFileDialog.CheckFileExists = true; openFileDialog.ShowDialog(); return openFileDialog.FileName; } private object load( object obj , string suffix , string title , string initialDirectory ) { string chosenPath = this.getPath( title ); return ObjectArchiver.Extract( chosenPath ); } public object Load( object obj , string suffix , string title ) { return this.load( obj , suffix , title , System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] ); } } } |
|
From: Glauco S. <gla...@us...> - 2005-07-13 16:43:57
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24531 Added Files: TestDisplayer.cs RunBestLinearCombination.cs MainForm.cs Log Message: A new Script (LinearCombination) has been add to study linear combination optimizations. --- NEW FILE: MainForm.cs --- using System; using System.Data; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using QuantProject.ADT; using QuantProject.ADT.FileManaging; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Accounting.Reporting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Scripting; using QuantProject.Business.Strategies; using QuantProject.Business.Testing; using QuantProject.Business.Timing; using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Summary description for MainForm. /// </summary> public class MainForm : System.Windows.Forms.Form { private int numberOfTickersToBeSavedFromEachGeneration = 5; private string tickerGroupID; private int numberOfEligibleTickers; private int numberOfTickersToBeChosen; // private int numDaysForLiquidity; private int generationNumberForGeneticOptimizer; private int populationSizeForGeneticOptimizer; private string benchmark; private DateTime firstDate; private DateTime lastDate; private double targetReturn; private PortfolioType portfolioType; /// <summary> /// bestGenomes[ i ] contains an array list with the best genomes /// for generation i /// </summary> private ArrayList bestGenomes; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public MainForm( string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime firstDate, DateTime lastDate, double targetReturn, PortfolioType portfolioType) { // // Required for Windows Form Designer support // InitializeComponent(); this.tickerGroupID = tickerGroupID; this.numberOfEligibleTickers = numberOfEligibleTickers; this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; // this.numDaysForLiquidity = numDaysForLiquidity; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.benchmark = benchmark; this.firstDate = firstDate; this.lastDate = lastDate; this.targetReturn = targetReturn; this.portfolioType = portfolioType; } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2, this.menuItem3}); this.menuItem1.Text = "File"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "Create Optimized Genomes"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // menuItem3 // this.menuItem3.Index = 1; this.menuItem3.Text = "Test Optimized Genomes"; this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click); // // MainForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 273); this.Menu = this.mainMenu1; this.Name = "MainForm"; this.Text = "MainForm"; } #endregion #region createOptimizedGenomes protected DataTable getSetOfTickersToBeOptimized_quickly() { DataTable returnValue = new QuantProject.Data.DataTables.Tickers_tickerGroups( "test" ); returnValue.Columns[ 0 ].ColumnName = "tiTicker"; return returnValue; } protected DataTable getSetOfTickersToBeOptimized() { SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, this.firstDate, this.lastDate, this.numberOfEligibleTickers); DataTable eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( eligibleTickers, false, this.firstDate, this.lastDate, this.numberOfEligibleTickers, this.benchmark); 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() { VisualObjectArchiver visualObjectArchiver = new VisualObjectArchiver(); visualObjectArchiver.Save( this.bestGenomes , "bgn" , "Save best genomes" ); } private void createOptimizedGenomes() { this.bestGenomes = new ArrayList(); // DataTable setOfTickersToBeOptimized = // this.getSetOfTickersToBeOptimized_quickly(); DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(); GenomeManagerForEfficientCTOPortfolio genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, this.firstDate, this.lastDate, this.numberOfTickersToBeChosen, this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); GO.NewGeneration += new NewGenerationEventHandler( this.newGenerationEventHandler ); GO.Run(false); this.writeOptimizedGenomesToDisk(); } private void menuItem2_Click(object sender, System.EventArgs e) { this.createOptimizedGenomes(); } #endregion #region testOptimizedGenomes private void loadBestGenomesFromDisk() { if ( this.bestGenomes == null ) { 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(); } private void testOptimizedGenomes() { this.loadBestGenomesFromDisk(); this.testOptimizedGenomesActually(); } private void menuItem3_Click(object sender, System.EventArgs e) { this.testOptimizedGenomes(); } #endregion } } --- NEW FILE: TestDisplayer.cs --- using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Summary description for TestDisplayer. /// </summary> public class TestDisplayer : System.Windows.Forms.Form { private System.Windows.Forms.DataGrid dgBestGenomes; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; // Glauco code private ArrayList bestGenomes; private void testdisplayer() { this.dgBestGenomes.DataSource = this.bestGenomes; } public TestDisplayer( ArrayList bestGenomes ) { // // Required for Windows Form Designer support // InitializeComponent(); // Glauco code this.bestGenomes = bestGenomes; this.testdisplayer(); } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.dgBestGenomes = new System.Windows.Forms.DataGrid(); ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); this.SuspendLayout(); // // dgBestGenomes // this.dgBestGenomes.DataMember = ""; this.dgBestGenomes.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dgBestGenomes.Location = new System.Drawing.Point(48, 32); this.dgBestGenomes.Name = "dgBestGenomes"; this.dgBestGenomes.Size = new System.Drawing.Size(208, 216); this.dgBestGenomes.TabIndex = 0; // // TestDisplayer // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.dgBestGenomes}); this.Name = "TestDisplayer"; this.Text = "TestDisplayer"; ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).EndInit(); this.ResumeLayout(false); } #endregion } } --- NEW FILE: RunBestLinearCombination.cs --- /* QuantProject - Quantitative Finance Library RunBestLinearCombination.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.Scripting; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Script to buy at open and sell at close /// the best in sample linear combination. /// The generation rules /// (contained in the EndOfDayTimerHandler) are: /// - choose the most liquid tickers; /// - choose the best linear combination among these tickers /// </summary> [Serializable] public class RunBestLinearCombination : Script { private string tickerGroupID; private int numberOfEligibleTickers; private int numberOfTickersToBeChosen; private int numDaysForLiquidity; private int generationNumberForGeneticOptimizer; private int populationSizeForGeneticOptimizer; private string benchmark; private DateTime firstDate; private DateTime lastDate; private double targetReturn; private PortfolioType portfolioType; public RunBestLinearCombination(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime firstDate, DateTime lastDate, double targetReturn, PortfolioType portfolioType ) { this.tickerGroupID = tickerGroupID; this.numberOfEligibleTickers = numberOfEligibleTickers; this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; this.numDaysForLiquidity = numDaysForLiquidity; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.benchmark = benchmark; this.firstDate = firstDate; this.lastDate = lastDate; this.targetReturn = targetReturn; this.portfolioType = portfolioType; } public override void Run() { MainForm mainForm = new MainForm( tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, firstDate, lastDate, targetReturn, portfolioType); mainForm.ShowDialog(); } } } |
|
From: Glauco S. <gla...@us...> - 2005-07-13 16:43:31
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24450/LinearCombination Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination added to the repository |
|
From: Glauco S. <gla...@us...> - 2005-07-13 16:42:32
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24260/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: A new Script (LinearCombination) has been add to study linear combination optimizations. Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** b7_Scripts.csproj 24 Jun 2005 22:52:25 -0000 1.29 --- b7_Scripts.csproj 13 Jul 2005 16:42:24 -0000 1.30 *************** *** 244,247 **** --- 244,277 ---- /> <File + RelPath = "WalkForwardTesting\LinearCombination\MainForm.cs" + SubType = "Form" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\LinearCombination\MainForm.resx" + DependentUpon = "MainForm.cs" + BuildAction = "EmbeddedResource" + /> + <File + RelPath = "WalkForwardTesting\LinearCombination\RunBestLinearCombination.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\LinearCombination\TestDisplayer.cs" + SubType = "Form" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\LinearCombination\TestDisplayer.resx" + DependentUpon = "TestDisplayer.cs" + BuildAction = "EmbeddedResource" + /> + <File + RelPath = "WalkForwardTesting\LinearCombination\VisualObjectArchiver.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\MSFTwalkForward\TsMSFTwalkForward.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2005-07-13 16:37:29
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23124/b1_ADT/Optimizing/Genetic Modified Files: GenomeManagerTest.cs GenomeManagement.cs GenomeComparer.cs Genome.cs Log Message: The [Serializable] attribute has been added. Index: Genome.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/Genome.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Genome.cs 24 Jun 2005 22:23:15 -0000 1.4 --- Genome.cs 13 Jul 2005 16:37:04 -0000 1.5 *************** *** 31,34 **** --- 31,35 ---- /// provided by biology /// </summary> + [Serializable] public class Genome : IComparable { Index: GenomeManagerTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagerTest.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManagerTest.cs 10 Jun 2005 18:48:45 -0000 1.2 --- GenomeManagerTest.cs 13 Jul 2005 16:37:04 -0000 1.3 *************** *** 31,34 **** --- 31,35 ---- /// behaviour of the genetic optimizer /// </summary> + [Serializable] public class GenomeManagerTest : IGenomeManager { Index: GenomeComparer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeComparer.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeComparer.cs 17 May 2005 23:02:35 -0000 1.2 --- GenomeComparer.cs 13 Jul 2005 16:37:04 -0000 1.3 *************** *** 29,32 **** --- 29,33 ---- /// Compares genomes by fitness /// </summary> + [Serializable] public sealed class GenomeComparer : IComparer { Index: GenomeManagement.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagement.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GenomeManagement.cs 24 Jun 2005 22:25:49 -0000 1.3 --- GenomeManagement.cs 13 Jul 2005 16:37:04 -0000 1.4 *************** *** 32,35 **** --- 32,36 ---- /// (crossovering, mutating, etc.) /// </summary> + [Serializable] public sealed class GenomeManagement { |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23124/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientCTCPortfolio.cs Log Message: The [Serializable] attribute has been added. Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GenomeManagerForEfficientCTOPortfolio.cs 25 Jun 2005 09:50:44 -0000 1.11 --- GenomeManagerForEfficientCTOPortfolio.cs 13 Jul 2005 16:37:04 -0000 1.12 *************** *** 37,40 **** --- 37,41 ---- /// GeneticOptimizer /// </summary> + [Serializable] public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForEfficientPortfolio { Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GenomeManagerForEfficientPortfolio.cs 25 Jun 2005 09:50:44 -0000 1.11 --- GenomeManagerForEfficientPortfolio.cs 13 Jul 2005 16:37:04 -0000 1.12 *************** *** 36,39 **** --- 36,40 ---- /// efficient portfolios using the GeneticOptimizer /// </summary> + [Serializable] public class GenomeManagerForEfficientPortfolio : IGenomeManager { Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GenomeManagerForEfficientCTCPortfolio.cs 25 Jun 2005 09:50:44 -0000 1.6 --- GenomeManagerForEfficientCTCPortfolio.cs 13 Jul 2005 16:37:04 -0000 1.7 *************** *** 37,40 **** --- 37,41 ---- /// using the GeneticOptimizer /// </summary> + [Serializable] public class GenomeManagerForEfficientCTCPortfolio : GenomeManagerForEfficientPortfolio { |
|
From: Glauco S. <gla...@us...> - 2005-07-13 16:36:15
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22902/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: - The NewGeneration event has been added. - The [Serializable] attribute has been added. Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GeneticOptimizer.cs 2 Jun 2005 18:03:59 -0000 1.4 --- GeneticOptimizer.cs 13 Jul 2005 16:36:03 -0000 1.5 *************** *** 27,31 **** namespace QuantProject.ADT.Optimizing.Genetic { ! /// <summary> /// The class needs to be initialized by an object implementing /// IGenomeManager interface --- 27,34 ---- namespace QuantProject.ADT.Optimizing.Genetic { ! public delegate void NewGenerationEventHandler( ! Object sender , NewGenerationEventArgs eventArgs ); ! ! /// <summary> /// The class needs to be initialized by an object implementing /// IGenomeManager interface *************** *** 34,37 **** --- 37,41 ---- /// keepOnRunningUntilConvergenceIsReached = false, minConvergenceRate = 0.80 /// </summary> + [Serializable] public class GeneticOptimizer { *************** *** 124,127 **** --- 128,133 ---- } #endregion + + public event NewGenerationEventHandler NewGeneration; /// <summary> *************** *** 228,231 **** --- 234,238 ---- this.createGenomes(); this.currentGeneration.Sort(this.genomeComparer); + this.NewGeneration( this , new NewGenerationEventArgs( this.currentGeneration ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); *************** *** 378,382 **** this.nextGeneration.Sort(this.genomeComparer); this.updateCurrentGeneration(); ! this.currentGeneration.Sort(this.genomeComparer); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); --- 385,390 ---- this.nextGeneration.Sort(this.genomeComparer); this.updateCurrentGeneration(); ! this.currentGeneration.Sort(this.genomeComparer); ! this.NewGeneration( this , new NewGenerationEventArgs( this.currentGeneration ) ); this.calculateTotalFitness(); this.updateCumulativeFitnessList(); |
|
From: Glauco S. <gla...@us...> - 2005-07-13 16:32:23
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22009/b1_ADT/Optimizing/Genetic Added Files: NewGenerationEventArgs.cs Log Message: EventArgs for the NewGeneration event --- NEW FILE: NewGenerationEventArgs.cs --- /* QuantProject - Quantitative Finance Library NewGenerationEventArgs.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; namespace QuantProject.ADT.Optimizing.Genetic { /// <summary> /// EventArgs for the NewGeneration event /// </summary> [Serializable] public class NewGenerationEventArgs { private ArrayList generation; public ArrayList Generation { get { return this.generation; } } public NewGenerationEventArgs( ArrayList generation ) { this.generation = generation; } } } |
|
From: Glauco S. <gla...@us...> - 2005-07-13 16:31:11
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21674/b1_ADT Modified Files: b1_ADT.csproj Log Message: NewGenerationEventArgs.cs has been added Index: b1_ADT.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/b1_ADT.csproj,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** b1_ADT.csproj 24 Jun 2005 22:32:09 -0000 1.17 --- b1_ADT.csproj 13 Jul 2005 16:30:30 -0000 1.18 *************** *** 213,216 **** --- 213,221 ---- /> <File + RelPath = "Optimizing\Genetic\NewGenerationEventArgs.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Statistics\AdvancedFunctions.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2005-06-26 14:53:16
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3817/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerCTCTest.cs EndOfDayTimerHandlerCTOTest.cs RunTestOptimizedCTOPortfolio.cs Log Message: Fixed bug in classes for testing the trading strategies on optimized tickers. Now the equity line is really "in sample". Index: RunTestOptimizedCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunTestOptimizedCTOPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunTestOptimizedCTOPortfolio.cs 24 Jun 2005 22:52:25 -0000 1.3 --- RunTestOptimizedCTOPortfolio.cs 26 Jun 2005 14:53:07 -0000 1.4 *************** *** 96,100 **** new EndOfDayDateTime( this.endDateTime.DateTime , EndOfDaySpecificTime.MarketClose ) , ! "^SPX" ); report.Show(); } --- 96,100 ---- new EndOfDayDateTime( this.endDateTime.DateTime , EndOfDaySpecificTime.MarketClose ) , ! "^NDX" ); report.Show(); } Index: EndOfDayTimerHandlerCTCTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerCTCTest.cs 2 Jun 2005 18:00:47 -0000 1.1 --- EndOfDayTimerHandlerCTCTest.cs 26 Jun 2005 14:53:07 -0000 1.2 *************** *** 75,79 **** if(!EndOfDayTimerHandlerCTCTest.optimized) { ! base.setTickers(currentDate); EndOfDayTimerHandlerCTCTest.optimized = true; } --- 75,79 ---- if(!EndOfDayTimerHandlerCTCTest.optimized) { ! base.setTickers(currentDate.AddDays(this.numDaysForLiquidity)); EndOfDayTimerHandlerCTCTest.optimized = true; } Index: EndOfDayTimerHandlerCTOTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTOTest.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerCTOTest.cs 24 Jun 2005 22:52:25 -0000 1.4 --- EndOfDayTimerHandlerCTOTest.cs 26 Jun 2005 14:53:07 -0000 1.5 *************** *** 65,69 **** if(!EndOfDayTimerHandlerCTOTest.optimized) { ! base.setTickers(currentDate); EndOfDayTimerHandlerCTOTest.optimized = true; } --- 65,69 ---- if(!EndOfDayTimerHandlerCTOTest.optimized) { ! base.setTickers(currentDate.AddDays(this.numDaysForLiquidity)); EndOfDayTimerHandlerCTOTest.optimized = true; } |
|
From: Marco M. <mi...@us...> - 2005-06-25 10:02:08
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19468/b1_ADT Modified Files: ExtendedDataTable.cs Log Message: Added GetRatesOfReturnsFromColumns method Index: ExtendedDataTable.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ExtendedDataTable.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ExtendedDataTable.cs 10 Jun 2005 18:52:00 -0000 1.9 --- ExtendedDataTable.cs 25 Jun 2005 10:01:54 -0000 1.10 *************** *** 161,165 **** } ! /// <summary> /// It returns a hashtable containing the common values in two --- 161,191 ---- } ! /// <summary> ! /// Get an array of float corresponding to the rates of return ! /// of columnA with respect to columnB ! /// </summary> ! public static float[] GetRatesOfReturnsFromColumns(DataTable table, ! string columnAName, string columnBName) ! { ! int numRows = table.Rows.Count; ! float[] arrayOfFloat = new float[numRows]; ! int index = 0; ! try ! { ! for(; index!= numRows; index++) ! { ! arrayOfFloat[index] = (float) table.Rows[index][columnAName] / ! (float) table.Rows[index][columnBName] - 1; ! } ! ! } ! catch(Exception ex) ! { ! MessageBox.Show(ex.ToString()); ! index = numRows; //for getting out of the for block ! } ! return arrayOfFloat; ! ! } /// <summary> /// It returns a hashtable containing the common values in two |
|
From: Marco M. <mi...@us...> - 2005-06-25 09:51:00
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14463/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerLastChosenPortfolio.cs GenomeManagerForEfficientCTCPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientPortfolio.cs RunEfficientPortfolio.cs RunLastChosenPortfolioOutOfSample.cs Log Message: (Sorry: for the last commit I was too confident. I didn't diff files before committing) Updated files for the EfficientPortfolio script: - new classes for testing a given array of tickers (normally, for testing out of sample an optimization's result); - reorganized code in a more object oriented way (now code duplication has been completely erased); - now, the optimization process for the shortAndLong portfolio should be more efficient (memory is now used properly) Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GenomeManagerForEfficientCTOPortfolio.cs 24 Jun 2005 22:52:25 -0000 1.10 --- GenomeManagerForEfficientCTOPortfolio.cs 25 Jun 2005 09:50:44 -0000 1.11 *************** *** 86,100 **** protected override float[] getArrayOfRatesOfReturn(string ticker) { ! float[] returnValue; ! float coefficient = this.getCoefficient(ticker); ! string tickerCode = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! Quotes tickerQuotes = new Quotes(tickerCode, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = ExtendedDataTable.GetArrayOfFloatFromRatioOfColumns(tickerQuotes, "quClose", "quOpen"); ! ! for(int idx = 0; idx!= returnValue.Length; idx++) { ! returnValue[idx] = coefficient*(returnValue[idx] - 1); } ! return returnValue; } /* --- 86,98 ---- protected override float[] getArrayOfRatesOfReturn(string ticker) { ! float[] returnValue = null; ! if(!ticker.StartsWith("-")) { ! string tickerCode = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! Quotes tickerQuotes = new Quotes(tickerCode, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = ExtendedDataTable.GetRatesOfReturnsFromColumns(tickerQuotes, "quClose", "quOpen"); ! this.numberOfExaminedReturns = returnValue.Length; } ! return returnValue; } /* Index: RunEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientPortfolio.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RunEfficientPortfolio.cs 24 Jun 2005 22:52:25 -0000 1.9 --- RunEfficientPortfolio.cs 25 Jun 2005 09:50:44 -0000 1.10 *************** *** 96,104 **** get { return this.portfolioType; } } ! ! public IHistoricalQuoteProvider HistoricalQuoteProvider ! { ! get { return this.historicalQuoteProvider; } ! } public virtual string ScriptName { --- 96,100 ---- get { return this.portfolioType; } } ! public virtual string ScriptName { Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GenomeManagerForEfficientCTCPortfolio.cs 24 Jun 2005 22:52:25 -0000 1.5 --- GenomeManagerForEfficientCTCPortfolio.cs 25 Jun 2005 09:50:44 -0000 1.6 *************** *** 82,100 **** protected override float[] getArrayOfRatesOfReturn(string ticker) { ! float coefficient = this.getCoefficient(ticker); ! string tickerCode = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! Quotes tickerQuotes = new Quotes(tickerCode, this.firstQuoteDate, this.lastQuoteDate); ! float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); ! float[] ratesOfReturns = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; ! int i = 0; //index for ratesOfReturns array ! ! for(int idx = 0; idx + this.numDaysForReturnCalculation < allAdjValues.Length; idx += this.numDaysForReturnCalculation ) { ! ratesOfReturns[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ ! allAdjValues[idx] - 1)*coefficient; ! i++; } ! ! return ratesOfReturns; } /* --- 82,104 ---- protected override float[] getArrayOfRatesOfReturn(string ticker) { ! float[] returnValue = null; ! if(!ticker.StartsWith("-")) { ! string tickerCode = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! Quotes tickerQuotes = new Quotes(tickerCode, this.firstQuoteDate, this.lastQuoteDate); ! float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); ! returnValue = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; ! int i = 0; //index for ratesOfReturns array ! ! for(int idx = 0; idx + this.numDaysForReturnCalculation < allAdjValues.Length; idx += this.numDaysForReturnCalculation ) ! { ! returnValue[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ ! allAdjValues[idx] - 1); ! i++; ! } ! this.numberOfExaminedReturns = returnValue.Length; } ! return returnValue; ! } /* Index: EndOfDayTimerHandlerLastChosenPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerLastChosenPortfolio.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerLastChosenPortfolio.cs 24 Jun 2005 22:52:25 -0000 1.1 --- EndOfDayTimerHandlerLastChosenPortfolio.cs 25 Jun 2005 09:50:44 -0000 1.2 *************** *** 81,85 **** //if(endOfDayTimingEventArgs.EndOfDayDateTime.CompareTo(this.lastDate) == 0) // this.closePositions(); ! if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.CompareTo(this.firstDate.DateTime) == 0) this.closePositions(); } --- 81,85 ---- //if(endOfDayTimingEventArgs.EndOfDayDateTime.CompareTo(this.lastDate) == 0) // this.closePositions(); ! if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.CompareTo(this.lastDate.DateTime.AddDays(-1)) == 0) this.closePositions(); } Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GenomeManagerForEfficientPortfolio.cs 24 Jun 2005 22:52:25 -0000 1.10 --- GenomeManagerForEfficientPortfolio.cs 25 Jun 2005 09:50:44 -0000 1.11 *************** *** 52,55 **** --- 52,56 ---- protected PortfolioType portfolioType; protected double[] portfolioRatesOfReturn; + protected int numberOfExaminedReturns; static public string GetCleanTickerCode(string tickerModifiedCode) *************** *** 62,66 **** else return tickerModifiedCode; - } --- 63,66 ---- *************** *** 150,153 **** --- 150,155 ---- } + + protected float getCoefficient(string ticker) { *************** *** 189,194 **** { double returnValue = 0; - //OLD IMPLEMENTATION double portfolioRateOfReturn = this.getPortfolioRateOfReturn(genome.Genes()); - //OLD IMPLEMENTATION double portfolioVariance = this.getPortfolioVariance(genome.Genes()); this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); double averagePortfolioRateOfReturn = --- 191,194 ---- *************** *** 278,281 **** --- 278,283 ---- // end of implementation of IGenomeManager + #region old implementation for variance computation + protected double getPortfolioVariance(int[] tickerIdx) { *************** *** 320,323 **** --- 322,328 ---- } + #endregion + + protected void retrieveData() { *************** *** 326,379 **** // float[] arrayOfRatesOfReturn = this.getArrayOfRatesOfReturn((string)row[0]); ! row["ArrayOfRatesOfReturn"] = arrayOfRatesOfReturn; } } ! //this protected method can be overriden by inherited classes ! //which can specify the type of rates of return ! ! //in this basic implementation rates of returns ! //are based on daily close to close protected virtual float[] getArrayOfRatesOfReturn(string ticker) { ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); ! float[] ratesOfReturns = new float[allAdjValues.Length]; ! int i = 0; //index for ratesOfReturns array ! ! for(int idx = 0; idx < allAdjValues.Length; idx++) ! { ! ratesOfReturns[i] = allAdjValues[idx+1]/ ! allAdjValues[idx] - 1; ! i++; ! } ! ! return ratesOfReturns; } ! protected double getPortfolioRateOfReturn(int[] tickerIdx) ! { ! double returnValue = 0; ! foreach(int idx in tickerIdx) ! { ! returnValue += ! BasicFunctions.SimpleAverage((float[])this.setOfTickers.Rows[idx]["ArrayOfRatesOfReturn"]); ! } ! //the investment is assumed to be equally divided ! return (returnValue/this.GenomeSize); ! ! } ! protected double[] getPortfolioRatesOfReturn(int[] tickerIdx) { ! int numberOfExaminedReturns = ! ((float[])this.setOfTickers.Rows[tickerIdx[0]]["ArrayOfRatesOfReturn"]).Length; ! double[] returnValue = new double[numberOfExaminedReturns]; for(int i = 0; i<returnValue.Length; i++) { foreach(int idx in tickerIdx) { ! float[] tickerRatesOfReturn = (float[])this.setOfTickers.Rows[idx]["ArrayOfRatesOfReturn"]; ! returnValue[i] += tickerRatesOfReturn[i]/this.genomeSize; //the investment is assumed to be equally divided for each ticker } --- 331,371 ---- // float[] arrayOfRatesOfReturn = this.getArrayOfRatesOfReturn((string)row[0]); ! if(arrayOfRatesOfReturn == null) ! row["ArrayOfRatesOfReturn"] = DBNull.Value; ! else ! row["ArrayOfRatesOfReturn"] = arrayOfRatesOfReturn; } } ! //this protected method must be overriden by inherited classes ! //specifing the type of rates of return that have to ! //be analyzed ! protected virtual float[] getArrayOfRatesOfReturn(string ticker) { ! float[] returnValue = null; ! return returnValue; } ! protected double[] getPortfolioRatesOfReturn(int[] tickerIdx) { ! double[] returnValue = new double[this.numberOfExaminedReturns]; ! float[] tickerRatesOfReturn; for(int i = 0; i<returnValue.Length; i++) { foreach(int idx in tickerIdx) { ! if(this.setOfTickers.Rows[idx]["ArrayOfRatesOfReturn"] is System.DBNull) ! //the idx points to a ticker for which short returns are ! //to be examined ! tickerRatesOfReturn = ! (float[])this.setOfTickers.Rows[idx - this.originalNumOfTickers]["ArrayOfRatesOfReturn"]; ! else ! tickerRatesOfReturn = (float[])this.setOfTickers.Rows[idx]["ArrayOfRatesOfReturn"]; ! ! returnValue[i] += ! this.getCoefficient((string)this.setOfTickers.Rows[idx][0])* ! tickerRatesOfReturn[i]/this.genomeSize; //the investment is assumed to be equally divided for each ticker } Index: RunLastChosenPortfolioOutOfSample.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunLastChosenPortfolioOutOfSample.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunLastChosenPortfolioOutOfSample.cs 24 Jun 2005 22:52:25 -0000 1.1 --- RunLastChosenPortfolioOutOfSample.cs 25 Jun 2005 09:50:44 -0000 1.2 *************** *** 49,60 **** /// <summary> /// Class for running a test based on last chosen tickers of a given ! /// RunEfficientPortfolio - normally, one with optimization purposes - ! /// , after it has been executed /// </summary> [Serializable] public class RunLastChosenPortfolioOutOfSample : RunEfficientPorfolio { ! RunEfficientPorfolio testEfficientPortfolio; ! public RunLastChosenPortfolioOutOfSample(RunEfficientPorfolio testEfficientPortfolio, string benchmark, DateTime startDate, --- 49,61 ---- /// <summary> /// Class for running a test based on last chosen tickers of a given ! /// PortfolioType /// </summary> [Serializable] public class RunLastChosenPortfolioOutOfSample : RunEfficientPorfolio { ! private string[] tickers; ! private PortfolioType typeOfPortfolio; ! public RunLastChosenPortfolioOutOfSample(string[] chosenTickers, ! PortfolioType typeOfPortfolio, string benchmark, DateTime startDate, *************** *** 64,77 **** startDate, endDate, ! testEfficientPortfolio.TypeOfPortfolio, maxRunningHours) { ! this.startDateTime = new EndOfDayDateTime( startDate, EndOfDaySpecificTime.MarketOpen ); this.endDateTime = new EndOfDayDateTime( endDate, EndOfDaySpecificTime.MarketClose ); this.ScriptName = "LastChosenPortfolioOutOfSample"; ! this.testEfficientPortfolio = testEfficientPortfolio; ! } #region Run --- 65,79 ---- startDate, endDate, ! typeOfPortfolio, maxRunningHours) { ! this.tickers = chosenTickers; ! this.typeOfPortfolio = typeOfPortfolio; ! this.startDateTime = new EndOfDayDateTime( startDate, EndOfDaySpecificTime.MarketOpen ); this.endDateTime = new EndOfDayDateTime( endDate, EndOfDaySpecificTime.MarketClose ); this.ScriptName = "LastChosenPortfolioOutOfSample"; ! } #region Run *************** *** 80,85 **** { this.endOfDayTimerHandler = ! new EndOfDayTimerHandlerLastChosenPortfolio(this.testEfficientPortfolio.LastChosenTickers, ! this.testEfficientPortfolio.TypeOfPortfolio, this.account, this.benchmark, --- 82,87 ---- { this.endOfDayTimerHandler = ! new EndOfDayTimerHandlerLastChosenPortfolio(this.tickers, ! this.typeOfPortfolio, this.account, this.benchmark, *************** *** 96,100 **** protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = this.testEfficientPortfolio.HistoricalQuoteProvider; } protected override void run_initializeAccount() --- 98,103 ---- protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); ! } protected override void run_initializeAccount() |