[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination TestDisplayer
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2005-07-29 13:32:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28345/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: TestDisplayer.cs Log Message: - better exception handling - first date and last date now are handled for each genome (and can be different and automatically computed for each genome) - both right click and left click is handled now: * left click resets the first date and last date to the in sample optimization date for the selected genome * right click keeps the date displacements visually chosen by the user; right click starts the backtest also Index: TestDisplayer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/TestDisplayer.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TestDisplayer.cs 23 Jul 2005 18:10:33 -0000 1.2 --- TestDisplayer.cs 29 Jul 2005 13:32:34 -0000 1.3 *************** *** 45,48 **** --- 45,50 ---- // Glauco code private ArrayList bestGenomes; + private System.Windows.Forms.Label label1; + private GenomeRepresentation lastSelectedGenomeRepresentation; private void testdisplayer() *************** *** 53,56 **** --- 55,61 ---- ArrayList bestGenomes ) { + if ( bestGenomes.Count == 0 ) + throw new Exception( "bestGenomes is empty! It should contain " + + "a genome, at least." ); // // Required for Windows Form Designer support *************** *** 59,64 **** // Glauco code ! this.dtpFirstDate.Value = firstDate; ! this.dtpLastDate.Value = lastDate; this.bestGenomes = bestGenomes; this.testdisplayer(); --- 64,73 ---- // Glauco code ! this.lastSelectedGenomeRepresentation = ! ((GenomeRepresentation)bestGenomes[0]); ! this.dtpFirstDate.Value = ! this.lastSelectedGenomeRepresentation.FirstOptimizationDate; ! this.dtpLastDate.Value = ! this.lastSelectedGenomeRepresentation.LastOptimizationDate; this.bestGenomes = bestGenomes; this.testdisplayer(); *************** *** 90,93 **** --- 99,103 ---- this.dtpFirstDate = new System.Windows.Forms.DateTimePicker(); this.dtpLastDate = new System.Windows.Forms.DateTimePicker(); + this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); this.SuspendLayout(); *************** *** 98,104 **** 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); --- 108,114 ---- this.dgBestGenomes.Dock = System.Windows.Forms.DockStyle.Bottom; this.dgBestGenomes.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dgBestGenomes.Location = new System.Drawing.Point(0, 117); this.dgBestGenomes.Name = "dgBestGenomes"; ! this.dgBestGenomes.Size = new System.Drawing.Size(496, 224); this.dgBestGenomes.TabIndex = 0; this.dgBestGenomes.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgBestGenomes_MouseUp); *************** *** 117,120 **** --- 127,139 ---- this.dtpLastDate.TabIndex = 2; // + // label1 + // + this.label1.Location = new System.Drawing.Point(32, 64); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(400, 40); + this.label1.TabIndex = 3; + this.label1.Text = "Left click data grid rows to reset dates to the optimization period. Right click " + + "to preserve date displacements and backtest."; + // // TestDisplayer // *************** *** 122,125 **** --- 141,145 ---- this.ClientSize = new System.Drawing.Size(496, 341); this.Controls.AddRange(new System.Windows.Forms.Control[] { + this.label1, this.dtpLastDate, this.dtpFirstDate, *************** *** 133,145 **** #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 ); --- 153,198 ---- #endregion ! private bool aRowHasBeenClicked( ! 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 ); + return hitTestInfo.Row>=0; + } + private GenomeRepresentation dgBestGenomes_MouseUp_getClickedGenomeRepresentation( + object sender, System.Windows.Forms.MouseEventArgs e ) + { + GenomeRepresentation genomeRepresentation = null; + 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 ]; ! if ( hitTestInfo.Row >= 0 ) ! // a grid row has been clicked, not the header ! genomeRepresentation = (GenomeRepresentation)bestGenomes[ hitTestInfo.Row ]; + return genomeRepresentation; + } + private void dgBestGenomes_MouseUp_rightButton_updateDates( + GenomeRepresentation newSelectedGenomeRepresentation ) + { + TimeSpan currentFirstDateDisplacement = + ( this.dtpFirstDate.Value - + this.lastSelectedGenomeRepresentation.FirstOptimizationDate ); + TimeSpan currentLastDateDisplacement = + ( this.dtpLastDate.Value - + this.lastSelectedGenomeRepresentation.LastOptimizationDate ); + this.dtpFirstDate.Value = newSelectedGenomeRepresentation.FirstOptimizationDate + + currentFirstDateDisplacement; + this.dtpLastDate.Value = newSelectedGenomeRepresentation.LastOptimizationDate + + currentLastDateDisplacement; + } + private void dgBestGenomes_MouseUp_rightButton(object sender, System.Windows.Forms.MouseEventArgs e) + { + GenomeRepresentation genomeRepresentation = + this.dgBestGenomes_MouseUp_getClickedGenomeRepresentation( sender , e ); + dgBestGenomes_MouseUp_rightButton_updateDates( genomeRepresentation ); string[] signedTickers = GenomeRepresentation.GetSignedTickers( genomeRepresentation.SignedTickers ); *************** *** 148,156 **** 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 ); } } --- 201,231 ---- this.dtpLastDate.Value , signedTickers ); linearCombinationTest.Run(); + this.lastSelectedGenomeRepresentation = genomeRepresentation; + } + private void dgBestGenomes_MouseUp_leftButton_updateDates( + GenomeRepresentation newSelectedGenomeRepresentation ) + { + this.dtpFirstDate.Value = + newSelectedGenomeRepresentation.FirstOptimizationDate; + this.dtpLastDate.Value = + newSelectedGenomeRepresentation.LastOptimizationDate; + } + private void dgBestGenomes_MouseUp_leftButton(object sender, System.Windows.Forms.MouseEventArgs e) + { + if ( aRowHasBeenClicked( sender , e ) ) + // a grid row has been clicked, not the header + { + GenomeRepresentation newSelectedGenomeRepresentation = + this.dgBestGenomes_MouseUp_getClickedGenomeRepresentation( sender , e ); + dgBestGenomes_MouseUp_leftButton_updateDates( newSelectedGenomeRepresentation ); + this.lastSelectedGenomeRepresentation = newSelectedGenomeRepresentation; + } } private void dgBestGenomes_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if ( e.Button == MouseButtons.Right ) ! this.dgBestGenomes_MouseUp_rightButton( sender , e ); ! if ( e.Button == MouseButtons.Left ) ! this.dgBestGenomes_MouseUp_leftButton( sender , e ); } } |