quantproject-developers Mailing List for QuantProject (Page 92)
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: Glauco S. <gla...@us...> - 2006-04-08 18:15:42
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8447/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions Added Files: WFLagDebugPositions.cs Log Message: Class used to test the Lag Strategy in sample --- NEW FILE: WFLagDebugPositions.cs --- /* QuantProject - Quantitative Finance Library WFLagDebugPositions.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.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WFLagDebugger { /// <summary> /// Class used to test the Lag Strategy in sample /// </summary> public class WFLagDebugPositions { private WFLagChosenPositions wFLagChosenPositions; private DateTime preSampleFirstDateTime; private DateTime inSampleFirstDateTime; private DateTime inSampleLastDateTime; private DateTime postSampleLastDateTime; private string benchmark; private HistoricalAdjustedQuoteProvider historicalQuoteProvider; private IndexBasedEndOfDayTimer endOfDayTimer; private Account account; private WFLagDebugPositionsEndOfDayTimerHandler endOfDayTimerHandler; /// <summary> /// To test the log for a Lag Strategy's walk forward test /// </summary> /// <param name="WFLagRunDebugPositions"></param> /// <param name="transactionDateTime"></param> /// <param name="inSampleDays"></param> /// <param name="preSampleDays"></param> /// <param name="postSampleDays"></param> public WFLagDebugPositions( WFLagChosenPositions wFLagChosenPositions , DateTime inSampleLastDateTime , int preSampleDays , int inSampleDays , int postSampleDays , string benchmark ) { this.wFLagChosenPositions = wFLagChosenPositions; this.inSampleLastDateTime = inSampleLastDateTime; this.inSampleFirstDateTime = this.inSampleLastDateTime.AddDays( -inSampleDays + 1 ); this.preSampleFirstDateTime = this.inSampleFirstDateTime.AddDays( -preSampleDays ); this.postSampleLastDateTime = this.inSampleLastDateTime.AddDays( postSampleDays ); this.benchmark = benchmark; } #region Run private void run_initializeHistoricalQuoteProvider() { this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } private void run_initializeEndOfDayTimer() { this.endOfDayTimer = new IndexBasedEndOfDayTimer( new EndOfDayDateTime( this.preSampleFirstDateTime , EndOfDaySpecificTime.MarketOpen ), this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WFLagDebugPositions" , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , this.historicalQuoteProvider ) ); } private void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new WFLagDebugPositionsEndOfDayTimerHandler( this.account , this.wFLagChosenPositions ); } public void marketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Transactions.Count == 0 ) this.account.AddCash( 30000 ); } public void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime > this.postSampleLastDateTime ) { // the simulation has reached the ending date this.account.EndOfDayTimer.Stop(); Report report = new Report( this.account , this.historicalQuoteProvider ); report.Create( "WFLag debug positions" , 1 , new EndOfDayDateTime( this.postSampleLastDateTime , EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark ); report.Show(); } } public void Run() { run_initializeHistoricalQuoteProvider(); run_initializeEndOfDayTimer(); run_initializeAccount(); run_initializeEndOfDayTimerHandler(); this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.marketOpenEventHandler ); this.endOfDayTimer.FiveMinutesBeforeMarketClose += new FiveMinutesBeforeMarketCloseEventHandler( this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.oneHourAfterMarketCloseEventHandler ); this.endOfDayTimer.Start(); } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-04-08 18:15:18
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8154/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger Added Files: WFLagRunDebugger.cs Log Message: Script to run a Lag strategy (not walk forward) --- NEW FILE: WFLagRunDebugger.cs --- /* QuantProject - Quantitative Finance Library WFLagRunDebugger.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.Windows.Forms; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Accounting.Transactions; using QuantProject.Business.Timing; using QuantProject.Presentation; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WFLagDebugger { /// <summary> /// Script to run a Lag strategy (not walk forward) /// </summary> public class WFLagRunDebugger { public WFLagRunDebugger() { // // TODO: Add constructor logic here // } public void Run() { VisualObjectArchiver visualObjectArchiver = new VisualObjectArchiver(); WFLagLog wFLagLog = ( WFLagLog )visualObjectArchiver.Load( "Load WFLag backtest log" , "qPWFLagLog" , "Load transactions" ); TransactionHistory transactionHistory = wFLagLog.TransactionHistory; DateTime lastDateTime = ((DateTime)transactionHistory.GetKey( transactionHistory.Count - 1 ) ).AddDays( 1 ); RebuildableAccount account = new RebuildableAccount( "FromSerializedTransactions" ); account.Add( transactionHistory ); Report report = new Report( account , new HistoricalAdjustedQuoteProvider() ); report.Create( "WFT One Rank" , 1 , new EndOfDayDateTime( lastDateTime , EndOfDaySpecificTime.OneHourAfterMarketClose ) , "^SPX" ); WFLagReportDebugger wFLagReportDebugger = new WFLagReportDebugger( wFLagLog , "^SPX" ); report.TransactionGrid.MouseUp += new MouseEventHandler( wFLagReportDebugger.MouseClickEventHandler ); report.Show(); } } } |
|
From: Glauco S. <gla...@us...> - 2006-04-08 18:13:03
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6590/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger Added Files: WFLagReportDebugger.cs Log Message: Script to debug the walk forward Lag Strategy backtest --- NEW FILE: WFLagReportDebugger.cs --- /* QuantProject - Quantitative Finance Library WFLagReportDebugger.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.Windows.Forms; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WFLagDebugger { /// <summary> /// Script to debug the walk forward Lag Strategy backtest /// </summary> public class WFLagReportDebugger { private WFLagLog wFLagLog; private string benchmark; public WFLagReportDebugger( WFLagLog wFLagLog , string benchmark ) { this.wFLagLog = wFLagLog; this.benchmark = benchmark; } #region MouseClickEventHandler private int rightClickEventHandler_getRowNumber( object sender , MouseEventArgs eventArgs ) { DataGrid dataGrid = (DataGrid)sender; Point point = new Point( eventArgs.X , eventArgs.Y ); DataGrid.HitTestInfo hitTestInfo = dataGrid.HitTest( point ); DataTable dataTable = (DataTable)dataGrid.DataSource; return hitTestInfo.Row; } private DateTime getRowDateTime( DataGrid dataGrid , int rowNumber ) { DataTable dataTable = (DataTable)dataGrid.DataSource; DataRow dataRow = dataTable.Rows[ rowNumber ]; DateTime dateTime = (DateTime)dataRow[ "DateTime" ]; return dateTime; } private void rightClickEventHandler_withRowNumber( DataGrid dataGrid , int rowNumber ) { DateTime transactionDateTime = this.getRowDateTime( dataGrid , rowNumber ); WFLagChosenPositions wFLagChosenPositions = this.wFLagLog.GetChosenPositions( transactionDateTime ); WFLagDebugPositions wFLagDebugPositions = new WFLagDebugPositions( wFLagChosenPositions , transactionDateTime , 30 , this.wFLagLog.InSampleDays , 30 , this.wFLagLog.Benchmark ); wFLagDebugPositions.Run(); // WFMultiOneRankDebugInSample wFMultiOneRankDebugInSample = // new WFMultiOneRankDebugInSample( signedTickers , firstDateTime , // lastDateTime , // this.benchmark ); // wFMultiOneRankDebugInSample.Run(); } private void rightClickEventHandler( object sender , MouseEventArgs eventArgs ) { // rightClickEventHandler_checkExceptions( sender , // eventArgs ); int rowNumber = rightClickEventHandler_getRowNumber( sender , eventArgs ); rightClickEventHandler_withRowNumber( (DataGrid)sender , rowNumber ); // MessageBox.Show( dataRow[ "DateTime" ].ToString() ); } public void MouseClickEventHandler( object sender , MouseEventArgs eventArgs ) { if ( eventArgs.Button == MouseButtons.Right ) this.rightClickEventHandler( sender , eventArgs ); } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-04-08 18:12:43
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6447/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger Added Files: WFLagChosenPositions.cs Log Message: Creates a copy of the relevant data for the WFLagChosenTickers object --- NEW FILE: WFLagChosenPositions.cs --- /* QuantProject - Quantitative Finance Library WFLagChosenPositions.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.Collections; using QuantProject.Scripts.WalkForwardTesting.WalkForwardLag; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WFLagDebugger { /// <summary> /// Creates a copy of the relevant data for the WFLagChosenTickers object /// </summary> [Serializable] public class WFLagChosenPositions { private QPHashtable drivingPositions; private QPHashtable portfolioPositions; private DateTime lastOptimizationDate; public QPHashtable DrivingPositions { get { return this.drivingPositions; } } public QPHashtable PortfolioPositions { get { return this.portfolioPositions; } } public DateTime LastOptimizationDate { get { return this.lastOptimizationDate; } } public WFLagChosenPositions( WFLagChosenTickers wFLagChosenTickers , DateTime lastOptimizationDate ) { this.drivingPositions = this.copy( wFLagChosenTickers.DrivingPositions ); this.portfolioPositions = this.copy( wFLagChosenTickers.PortfolioPositions ); this.lastOptimizationDate = lastOptimizationDate; } private QPHashtable copy( QPHashtable qPHashTable ) { QPHashtable newCopy = new QPHashtable(); foreach ( string key in qPHashTable.Keys ) newCopy.Add( key , null ); return newCopy; } } } |
|
From: Glauco S. <gla...@us...> - 2006-04-08 18:11:26
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5693/b7_Scripts/WalkForwardTesting/WalkForwardLag Added Files: WFLagNewChosenTickersEventArgs.cs Log Message: EventArgs for new chosen tickers for the walk forward Lag Strategy --- NEW FILE: WFLagNewChosenTickersEventArgs.cs --- /* QuantProject - Quantitative Finance Library WFLagNewChosenTickersEventArgs.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; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { /// <summary> /// EventArgs for new chosen tickers for the walk forward /// Lag Strategy /// </summary> public class WFLagNewChosenTickersEventArgs : EventArgs { private WFLagChosenTickers wFLagChosenTickers; public WFLagChosenTickers WFLagChosenTickers { get { return this.wFLagChosenTickers; } } public WFLagNewChosenTickersEventArgs( WFLagChosenTickers wFLagChosenTickers ) { this.wFLagChosenTickers = wFLagChosenTickers; } } } |
|
From: Glauco S. <gla...@us...> - 2006-04-08 18:10:25
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4952/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger Added Files: WFLagLog.cs Log Message: Log for a walk forward lag backtest --- NEW FILE: WFLagLog.cs --- /* QuantProject - Quantitative Finance Library WFLagLog.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.Histories; using QuantProject.Business.Financial.Accounting.Transactions; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WFLagDebugger { /// <summary> /// Log for a walk forward lag backtest /// </summary> [Serializable] public class WFLagLog { private int inSampleDays; private string benchmark; private TransactionHistory transactionHistory; private History chosenPositionsHistory; public int InSampleDays { get { return this.inSampleDays; } } public string Benchmark { get { return this.benchmark; } } public TransactionHistory TransactionHistory { get { return this.transactionHistory; } set { this.transactionHistory = value; } } public WFLagLog( int inSampleDays , string benchmark ) { this.inSampleDays = inSampleDays; this.benchmark = benchmark; this.chosenPositionsHistory = new History(); } public void Add( WFLagChosenPositions wFLagChosenPositions ) { this.chosenPositionsHistory.Add( wFLagChosenPositions.LastOptimizationDate , wFLagChosenPositions ); } public WFLagChosenPositions GetChosenPositions( DateTime transactionDateTime ) { DateTime maxDateTimeForSettingRequestedChosenPosition = transactionDateTime.AddDays( - 1 ); WFLagChosenPositions wFLagChosenPositions = (WFLagChosenPositions)this.chosenPositionsHistory.GetByKeyOrPrevious( maxDateTimeForSettingRequestedChosenPosition ); return wFLagChosenPositions; } } } |
|
From: Glauco S. <gla...@us...> - 2006-04-08 18:09:46
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4511/b7_Scripts/WalkForwardTesting/WalkForwardLag Added Files: WFLagMain.cs Log Message: Main form to test the walk forward lag strategy: you can chose either to backtest the strategy or to debug a previous backtest --- NEW FILE: WFLagMain.cs --- /* QuantProject - Quantitative Finance Library WFLagMain.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.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WFLagDebugger; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { /// <summary> /// Summary description for WFLagMain. /// </summary> public class WFLagMain : System.Windows.Forms.Form { private System.Windows.Forms.Button NewBacktest; private System.Windows.Forms.Button debugOldBacktest; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public WFLagMain() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <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.NewBacktest = new System.Windows.Forms.Button(); this.debugOldBacktest = new System.Windows.Forms.Button(); this.SuspendLayout(); // // NewBacktest // this.NewBacktest.Location = new System.Drawing.Point(64, 56); this.NewBacktest.Name = "NewBacktest"; this.NewBacktest.Size = new System.Drawing.Size(88, 23); this.NewBacktest.TabIndex = 0; this.NewBacktest.Text = "New Backtest"; this.NewBacktest.Click += new System.EventHandler(this.NewBacktest_Click); // // debugOldBacktest // this.debugOldBacktest.Location = new System.Drawing.Point(216, 56); this.debugOldBacktest.Name = "debugOldBacktest"; this.debugOldBacktest.TabIndex = 1; this.debugOldBacktest.Text = "Debug Log"; this.debugOldBacktest.Click += new System.EventHandler(this.debugOldBacktest_Click); // // WFLagMain // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(352, 149); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.debugOldBacktest, this.NewBacktest}); this.Name = "WFLagMain"; this.Text = "WFLagMain"; this.ResumeLayout(false); } #endregion private void NewBacktest_Click(object sender, System.EventArgs e) { // new RunWalkForwardLag( "millo" , 500 , // 3 , 3 , 90 , 7 , 15 , 30000 , "MSFT" , // new DateTime( 2002 , 1 , 1 ) , // new DateTime( 2002 , 3 , 31 ) , // 7 ).Run(); new RunWalkForwardLag( "SP500" , 500 , 3 , 3 , 90 , 7 , 1 , 30000 , "MSFT" , new DateTime( 2002 , 1 , 30 ) , new DateTime( 2002 , 2 , 3 ) , 1 ).Run(); } private void debugOldBacktest_Click(object sender, System.EventArgs e) { new WFLagRunDebugger().Run(); } } } |
|
From: Glauco S. <gla...@us...> - 2006-04-08 18:06:55
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2754/WFLagDebugPositions Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions added to the repository |
|
From: Glauco S. <gla...@us...> - 2006-04-08 18:06:43
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2672/WFLagDebugger Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger added to the repository |
|
From: Marco M. <mi...@us...> - 2006-04-08 14:25:55
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader/TickerSelectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23867/Downloader/TickerSelectors Modified Files: TickerSelectorForm.cs Log Message: Added SelectorByQuotationNotAtEachMarketDay to the SelectorForm's combo box Index: TickerSelectorForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerSelectors/TickerSelectorForm.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** TickerSelectorForm.cs 7 Jan 2006 11:12:30 -0000 1.18 --- TickerSelectorForm.cs 8 Apr 2006 14:25:50 -0000 1.19 *************** *** 92,95 **** --- 92,96 ---- this.comboBoxAvailableSelectionRules.Items.Add("AverageCloseToOpenPerformance"); this.comboBoxAvailableSelectionRules.Items.Add("QuotedAtEachMarketDay"); + this.comboBoxAvailableSelectionRules.Items.Add("QuotedNotAtEachMarketDay"); this.comboBoxAvailableSelectionRules.Items.Add("AverageRawOpenPrice"); this.comboBoxAvailableSelectionRules.Items.Add("WinningOpenToClose"); *************** *** 633,636 **** --- 634,650 ---- this.textBoxMarketIndex.Text); } + else if (this.comboBoxAvailableSelectionRules.Text == "QuotedNotAtEachMarketDay") + { + if(this.textBoxGroupID.Text != "") + returnValue = new SelectorByQuotationNotAtEachMarketDay (this.textBoxGroupID.Text, + this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, + this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text), + this.textBoxMarketIndex.Text); + else + returnValue = new SelectorByQuotationNotAtEachMarketDay(this.tableOfSelectedTickers, + this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, + this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text), + this.textBoxMarketIndex.Text); + } else if (this.comboBoxAvailableSelectionRules.Text == "AverageRawOpenPrice") { *************** *** 723,726 **** --- 737,741 ---- { if(this.comboBoxAvailableSelectionRules.Text == "QuotedAtEachMarketDay" || + this.comboBoxAvailableSelectionRules.Text == "QuotedNotAtEachMarketDay" || this.comboBoxAvailableSelectionRules.Text == "OpenToCloseCorrelationToBenchmark") { |
|
From: Marco M. <mi...@us...> - 2006-04-08 14:24:32
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22994 Modified Files: b3_Data.csproj Data.prjx Log Message: Added SelectorByQuotationNotAtEachMarketDay to the project. Index: Data.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Data.prjx,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Data.prjx 17 Nov 2005 21:41:39 -0000 1.10 --- Data.prjx 8 Apr 2006 14:24:28 -0000 1.11 *************** *** 20,24 **** <File name=".\Selectors\ITickerRemover.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\Selectors\ITickerSelector.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\Selectors\SelectionType.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\Selectors\SelectorByAbsolutePerformance.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\Selectors\SelectorByAverageCloseToClosePerformance.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> --- 20,23 ---- *************** *** 39,42 **** --- 38,46 ---- <File name=".\Selectors\SelectorByGroup.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\Selectors\SelectorByCloseToCloseCorrelationToBenchmark.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\Selectors\SelectorByCloseToOpenVolatility.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\Selectors\SelectorByAverageCloseToOpenPerformance.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\DataProviders\Caching\ICache.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\DataProviders\Caching\SimpleCache.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\Selectors\SelectorByQuotationNotAtEachMarketDay.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** b3_Data.csproj 11 Jan 2006 18:46:12 -0000 1.36 --- b3_Data.csproj 8 Apr 2006 14:24:28 -0000 1.37 *************** *** 338,341 **** --- 338,346 ---- /> <File + RelPath = "Selectors\SelectorByQuotationNotAtEachMarketDay.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Selectors\SelectorByWinningOpenToClose.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2006-04-08 14:23:37
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22307 Added Files: SelectorByQuotationNotAtEachMarketDay.cs Log Message: Added SelectorByQuotationNotAtEachMarketDay to the project. --- NEW FILE: SelectorByQuotationNotAtEachMarketDay.cs --- /* QuantProject - Quantitative Finance Library SelectorByQuotationNotAtEachMarketDay.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; using System.Data; using System.Windows.Forms; using QuantProject.DataAccess.Tables; using QuantProject.Data.DataTables; namespace QuantProject.Data.Selectors { /// <summary> /// Class for selection on tickers NOT quoted at each market day (market index) /// </summary> public class SelectorByQuotationNotAtEachMarketDay : TickerSelector , ITickerSelector { private string marketIndex; public SelectorByQuotationNotAtEachMarketDay(DataTable setOfTickersToBeSelected, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers, string marketIndex): base(setOfTickersToBeSelected, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { this.marketIndex = marketIndex; } public SelectorByQuotationNotAtEachMarketDay(string groupID, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers, string marketIndex): base(groupID, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { this.marketIndex = marketIndex; } public DataTable GetTableOfSelectedTickers() { if(this.marketIndex == "") throw new Exception("You first need to set TickerSelector's property <<MarketIndex>>!"); if(this.setOfTickersToBeSelected == null) return QuantProject.Data.DataTables.TickerDataTable.GetTickersNotQuotedAtEachMarketDay( this.marketIndex, this.groupID, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers); else return QuantProject.Data.DataTables.TickerDataTable.GetTickersNotQuotedAtEachMarketDay( this.marketIndex, this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers); } public void SelectAllTickers() { ; } } } |
|
From: Marco M. <mi...@us...> - 2006-04-08 14:21:00
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20280/b3_Data/DataTables Modified Files: TickerDataTable.cs Log Message: Added GetTickersNotQuotedAtEachMarketDay method. Useful for retrieving tickers with missing quotes. Index: TickerDataTable.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/TickerDataTable.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TickerDataTable.cs 20 Dec 2005 19:31:02 -0000 1.6 --- TickerDataTable.cs 8 Apr 2006 14:20:56 -0000 1.7 *************** *** 213,216 **** --- 213,217 ---- tableToWhichRowIsToBeAdded.Rows.Add(newRow); } + public static DataTable GetTickersQuotedInEachMarketDay(string marketIndex, string groupID, DateTime firstQuoteDate, *************** *** 258,261 **** --- 259,319 ---- } + private static void getTickersQuotedNotAtEachMarketDay_addRow(DataRow rowToBeAdded, + int numberOfTradingDays, + int numberOfMissingQuotes, + DataTable tableToWhichRowIsToBeAdded) + { + DataRow newRow = tableToWhichRowIsToBeAdded.NewRow(); + newRow[0]= rowToBeAdded[0]; + newRow["NumberOfTradingDays"] = numberOfTradingDays; + newRow["NumberOfMissingQuotes"] = numberOfMissingQuotes; + tableToWhichRowIsToBeAdded.Rows.Add(newRow); + } + + private static void getTickersQuotedNotAtEachMarketDay_addColumns(DataTable tableToAnalyze) + { + if(!tableToAnalyze.Columns.Contains("NumberOfTradingDays")) + tableToAnalyze.Columns.Add("NumberOfTradingDays", System.Type.GetType("System.Int32")); + if(!tableToAnalyze.Columns.Contains("NumberOfMissingQuotes")) + tableToAnalyze.Columns.Add("NumberOfMissingQuotes", System.Type.GetType("System.Int32")); + } + + public static DataTable GetTickersNotQuotedAtEachMarketDay(string marketIndex, string groupID, + DateTime firstQuoteDate, + DateTime lastQuoteDate, + long maxNumOfReturnedTickers) + { + + DataTable groupOfTickers = QuantProject.DataAccess.Tables.Tickers_tickerGroups.GetTickers(groupID); + + return GetTickersNotQuotedAtEachMarketDay(marketIndex,groupOfTickers,firstQuoteDate,lastQuoteDate, + maxNumOfReturnedTickers); + } + + public static DataTable GetTickersNotQuotedAtEachMarketDay(string marketIndex, DataTable setOfTickers, + DateTime firstQuoteDate, + DateTime lastQuoteDate, + long maxNumOfReturnedTickers) + { + int marketDaysForTheGivenMarket = + TickerDataTable.getNumberOfTradingDays(marketIndex, firstQuoteDate, lastQuoteDate); + TickerDataTable.getTickersQuotedNotAtEachMarketDay_addColumns(setOfTickers); + DataTable returnValue = setOfTickers.Clone(); + int numberOfMissingQuotes = 0; + foreach(DataRow row in setOfTickers.Rows) + { + DataTable tickerQuotes = new Quotes((string)row[0],firstQuoteDate,lastQuoteDate); + numberOfMissingQuotes = marketDaysForTheGivenMarket - tickerQuotes.Rows.Count; + if( numberOfMissingQuotes > 0 ) + //the current ticker has NOT been effectively traded at each market day + TickerDataTable.getTickersQuotedNotAtEachMarketDay_addRow(row, marketDaysForTheGivenMarket, + numberOfMissingQuotes, + returnValue); + } + ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers); + + return returnValue; + } + } } |
|
From: Marco M. <mi...@us...> - 2006-04-08 14:15:16
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16429/b2_DataAccess/Tables Modified Files: FaultyTickers.cs Log Message: Changed constructor for FaultyTickers class to access faultyTickers table. If the parameter deleteOldFaultyTickersRecords is set true, tickers are deleted from table if their last Attempt Date is older than the Date of the last Quote stored in the database. Index: FaultyTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/FaultyTickers.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FaultyTickers.cs 20 Jan 2005 19:12:29 -0000 1.1 --- FaultyTickers.cs 8 Apr 2006 14:15:10 -0000 1.2 *************** *** 43,52 **** private int count; ! public FaultyTickers() { this.faultyTickers = SqlExecutor.GetDataTable("SELECT * FROM faultyTickers"); this.count = this.faultyTickers.Rows.Count; } ! /// <summary> /// Number of tickers in FaultyTickers table --- 43,79 ---- private int count; ! private void faultyTickers_deleteRowsFromDatabaseTable() { this.faultyTickers = SqlExecutor.GetDataTable("SELECT * FROM faultyTickers"); + + foreach(DataRow row in this.faultyTickers.Rows) + { + if(SqlExecutor.GetDataTable("SELECT * FROM quotes WHERE quTicker='" + + (string)row[0] + "' AND quDate>" + + SQLBuilder.GetDateConstant((DateTime)row[1])).Rows.Count>0) + //there are quotes with date > than last attempt date + + SqlExecutor.ExecuteNonQuery("DELETE * FROM faultyTickers " + + "WHERE ftTicker='" + (string)row[0] + "'"); + + } + + } + + /// <summary> + /// Class to access the Faulty Tickers table (containing tickers not + /// downloaded because of some error). + /// </summary> + /// <param name="deleteOldFaultyTickersRecords">If the parameter is set on true, + /// tickers are deleted from table if their lastAttemptDate is older than + /// last quote Date stored in the database</param> + public FaultyTickers(bool deleteOldFaultyTickersRecords) + { + if(deleteOldFaultyTickersRecords) + this.faultyTickers_deleteRowsFromDatabaseTable(); + this.faultyTickers = SqlExecutor.GetDataTable("SELECT * FROM faultyTickers ORDER BY ftDate"); this.count = this.faultyTickers.Rows.Count; } ! /// <summary> /// Number of tickers in FaultyTickers table |
|
From: Marco M. <mi...@us...> - 2006-04-08 14:11:35
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader/TickerSelectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13992/Downloader/TickerSelectors Modified Files: TickerViewer.cs Log Message: Changed constructor for FaultyTickers class to access faultyTickers table Index: TickerViewer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerSelectors/TickerViewer.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TickerViewer.cs 11 Sep 2005 15:36:02 -0000 1.7 --- TickerViewer.cs 8 Apr 2006 14:11:28 -0000 1.8 *************** *** 702,706 **** Cursor.Current = Cursors.WaitCursor; ! this.tableTickers = new FaultyTickers().Table; this.dataGrid1.DataSource = this.tableTickers; --- 702,706 ---- Cursor.Current = Cursors.WaitCursor; ! this.tableTickers = new FaultyTickers(true).Table; this.dataGrid1.DataSource = this.tableTickers; |
|
From: Marco M. <mi...@us...> - 2006-04-08 13:54:26
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2942/Downloader Modified Files: WebDownloader.cs TickerDownloader.cs Log Message: Fixed bug: now it is possible to select tickers for download also from faulty tickers data grid in TickerViewer form. Index: WebDownloader.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/WebDownloader.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** WebDownloader.cs 2 Jun 2005 17:52:10 -0000 1.19 --- WebDownloader.cs 8 Apr 2006 13:54:10 -0000 1.20 *************** *** 600,604 **** this.DsTickerCurrentlyDownloaded.Tables.Add( "Tickers" ); this.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Columns.Add( ! new DataColumn( dt.Columns[ "tiTicker" ].ColumnName , dt.Columns[ "tiTicker" ].DataType ) ); this.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Columns.Add( "currentState" , System.Type.GetType( "System.String" ) ); this.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Columns.Add( "databaseUpdated" , System.Type.GetType( "System.String" ) ); --- 600,604 ---- this.DsTickerCurrentlyDownloaded.Tables.Add( "Tickers" ); this.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Columns.Add( ! new DataColumn( dt.Columns[0].ColumnName , dt.Columns[0].DataType ) ); this.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Columns.Add( "currentState" , System.Type.GetType( "System.String" ) ); this.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Columns.Add( "databaseUpdated" , System.Type.GetType( "System.String" ) ); *************** *** 617,621 **** //if (this.dsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Rows.Count>5) // Monitor.Wait( this.dsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ); ! TickerDownloader qd = new TickerDownloader( this , myRow , myRow["tiTicker"].ToString() , ds.Tables[0].Rows.Count ); //Thread newThread = new Thread( new ThreadStart( qd.downloadTicker)); //newThread.Start(); --- 617,621 ---- //if (this.dsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Rows.Count>5) // Monitor.Wait( this.dsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ); ! TickerDownloader qd = new TickerDownloader( this , myRow , myRow[0].ToString() , ds.Tables[0].Rows.Count ); //Thread newThread = new Thread( new ThreadStart( qd.downloadTicker)); //newThread.Start(); Index: TickerDownloader.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerDownloader.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** TickerDownloader.cs 22 Jan 2006 09:53:13 -0000 1.18 --- TickerDownloader.cs 8 Apr 2006 13:54:10 -0000 1.19 *************** *** 63,67 **** lock( p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ) { ! DataRow[] myRows = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Select( "tiTicker='" + p_quTicker + "'" ); myRows[ 0 ][ "currentState" ] = newState; p_myForm.dataGrid1.Refresh(); --- 63,68 ---- lock( p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ) { ! string columnName = p_myForm.DsTickerCurrentlyDownloaded.Tables["Tickers"].Columns[0].ColumnName; ! DataRow[] myRows = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Select( columnName + "='" + p_quTicker + "'" ); myRows[ 0 ][ "currentState" ] = newState; p_myForm.dataGrid1.Refresh(); *************** *** 73,77 **** lock( p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ) { ! DataRow[] myRows = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Select( "tiTicker='" + p_quTicker + "'" ); myRows[ 0 ][ "adjustedClose" ] = status; p_myForm.dataGrid1.Refresh(); --- 74,79 ---- lock( p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ) { ! string columnName = p_myForm.DsTickerCurrentlyDownloaded.Tables["Tickers"].Columns[0].ColumnName; ! DataRow[] myRows = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Select( columnName + "='" + p_quTicker + "'" ); myRows[ 0 ][ "adjustedClose" ] = status; p_myForm.dataGrid1.Refresh(); *************** *** 83,87 **** lock( p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ) { ! DataRow[] myRows = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Select( "tiTicker='" + p_quTicker + "'" ); myRows[ 0 ][ "adjCloseToCloseRatio" ] = status; p_myForm.dataGrid1.Refresh(); --- 85,90 ---- lock( p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ) { ! string columnName = p_myForm.DsTickerCurrentlyDownloaded.Tables["Tickers"].Columns[0].ColumnName; ! DataRow[] myRows = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Select(columnName + "='" + p_quTicker + "'" ); myRows[ 0 ][ "adjCloseToCloseRatio" ] = status; p_myForm.dataGrid1.Refresh(); *************** *** 93,97 **** lock( p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ) { ! DataRow[] myRows = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Select( "tiTicker='" + p_quTicker + "'" ); myRows[ 0 ][ "databaseUpdated" ] = status; p_myForm.dataGrid1.Refresh(); --- 96,101 ---- lock( p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ) { ! string columnName = p_myForm.DsTickerCurrentlyDownloaded.Tables["Tickers"].Columns[0].ColumnName; ! DataRow[] myRows = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Select(columnName + "='" + p_quTicker + "'" ); myRows[ 0 ][ "databaseUpdated" ] = status; p_myForm.dataGrid1.Refresh(); *************** *** 271,275 **** { DataRow newRow = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].NewRow(); ! newRow[ "tiTicker" ] = p_quTicker; newRow[ "currentState" ] = "Searching ..."; newRow[ "databaseUpdated" ] = "No"; --- 275,279 ---- { DataRow newRow = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].NewRow(); ! newRow[ 0 ] = p_quTicker; newRow[ "currentState" ] = "Searching ..."; newRow[ "databaseUpdated" ] = "No"; |
|
From: Marco M. <mi...@us...> - 2006-03-26 20:07:25
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5147/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManipulator.cs Log Message: Fixed bug in IsTickerContainedInGenome method. Index: GenomeManipulator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManipulator.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GenomeManipulator.cs 8 Aug 2005 19:15:41 -0000 1.5 --- GenomeManipulator.cs 26 Mar 2006 20:07:17 -0000 1.6 *************** *** 232,236 **** (geneCorrespondingToATicker<0 && genome.HasGene(Math.Abs(geneCorrespondingToATicker)-1)) || ! (geneCorrespondingToATicker>0 && genome.HasGene(- Math.Abs(geneCorrespondingToATicker)- 1)) ); --- 232,236 ---- (geneCorrespondingToATicker<0 && genome.HasGene(Math.Abs(geneCorrespondingToATicker)-1)) || ! (geneCorrespondingToATicker>=0 && genome.HasGene(- Math.Abs(geneCorrespondingToATicker)- 1)) ); |
|
From: Glauco S. <gla...@us...> - 2006-03-14 15:21:43
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Collections In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12457 Added Files: QPHashtable.cs Log Message: Extends standard Hashtable features. The KeyConcat property returns all Keys in a single (semicolon separated) string. Useful for debugging purposes. --- NEW FILE: QPHashtable.cs --- /* QuantProject - Quantitative Finance Library QPHashtable.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.Runtime.Serialization; namespace QuantProject.ADT.Collections { /// <summary> /// Extends standard Hashtable features /// </summary> [Serializable] public class QPHashtable : Hashtable { /// <summary> /// Keys are returned in a single (semicolon separated) /// string. Useful for debugging purposes /// </summary> public string KeyConcat { get { string keyConcat = ""; foreach ( object key in this.Keys ) keyConcat += ";" + key.ToString(); return keyConcat; } } public QPHashtable() { // // TODO: Add constructor logic here // } public QPHashtable(SerializationInfo info, StreamingContext context) : base(info, context) { } } } |
|
From: Glauco S. <gla...@us...> - 2006-03-14 15:20:02
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Collections In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11522/Collections Log Message: Directory /cvsroot/quantproject/QuantProject/b1_ADT/Collections added to the repository |
|
From: Glauco S. <gla...@us...> - 2006-03-14 15:07:28
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4463/b1_ADT Modified Files: b1_ADT.csproj Log Message: Collections\QPHashtable.cs has been added Index: b1_ADT.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/b1_ADT.csproj,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** b1_ADT.csproj 27 Jul 2005 22:36:48 -0000 1.19 --- b1_ADT.csproj 14 Mar 2006 15:07:24 -0000 1.20 *************** *** 148,151 **** --- 148,156 ---- /> <File + RelPath = "Collections\QPHashtable.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "FileManaging\ObjectArchiver.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2006-03-14 15:06:49
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3987/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: The Lag Strategy has been added Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** b7_Scripts.csproj 8 Jan 2006 23:33:53 -0000 1.49 --- b7_Scripts.csproj 14 Mar 2006 15:06:46 -0000 1.50 *************** *** 464,467 **** --- 464,502 ---- /> <File + RelPath = "WalkForwardTesting\WalkForwardLag\RunWalkForwardLag.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\WalkForwardLag\WFLagCandidates.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\WalkForwardLag\WFLagChosenTickers.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\WalkForwardLag\WFLagEligibleTickers.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\WalkForwardLag\WFLagEndOfDayTimerHandler.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\WalkForwardLag\WFLagGenomeManager.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\WalkForwardLag\WFLagSignedTickers.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\RunWalkForwardMultiOneRank.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2006-03-14 15:05:56
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3309 Added Files: WFLagSignedTickers.cs Log Message: This class identifies all the signed tickers to apply the lag strategy our of sample: it contains both the driving positions and the portfolio positions. Each genome can be decoded to an instance of this class --- NEW FILE: WFLagSignedTickers.cs --- /* QuantProject - Quantitative Finance Library WFLagSignedTickers.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.ADT.Collections; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { /// <summary> /// This class identifies all the signed tickers to apply /// the lag strategy our of sample: it contains both the /// driving positions and the portfolio positions. Each genome /// can be decoded to an instance of this class /// </summary> public class WFLagSignedTickers { private QPHashtable drivingPositions; private QPHashtable portfolioPositions; public QPHashtable DrivingPositions { get { return this.drivingPositions; } } public QPHashtable PortfolioPositions { get { return this.portfolioPositions; } } public WFLagSignedTickers() { this.drivingPositions = new QPHashtable(); this.portfolioPositions = new QPHashtable(); } } } |
|
From: Glauco S. <gla...@us...> - 2006-03-14 15:04:57
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2760 Added Files: WFLagGenomeManager.cs Log Message: This class implements IGenomeManager, in order to find the best driving position group and the best portfolio position group with respect to the lag strategy --- NEW FILE: WFLagGenomeManager.cs --- /* QuantProject - Quantitative Finance Library WFLagGenomeManager.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.Data; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.ADT.Statistics; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { /// <summary> /// This class implements IGenomeManager, in order to find the /// best driving position group and the best /// portfolio position group with respect to the lag strategy /// </summary> public class WFLagGenomeManager : IGenomeManager { private DataTable eligibleTickers; private DateTime firstQuoteDate; private DateTime lastQuoteDate; private int numberOfDrivingPositions; private int numberOfTickersInPortfolio; private int numberOfEligibleTickers; private GeneticOptimizer currentGeneticOptimizer; private WFLagCandidates wFLagCandidates; public int GenomeSize { get { return this.numberOfDrivingPositions + this.numberOfTickersInPortfolio; } } public int MinValueForGenes { get { return -this.numberOfEligibleTickers; } } public int MaxValueForGenes { get { return this.numberOfEligibleTickers - 1; } } public GeneticOptimizer CurrentGeneticOptimizer { get{ return this.currentGeneticOptimizer; } set{ this.currentGeneticOptimizer = value; } } public WFLagGenomeManager( DataTable eligibleTickers , DateTime firstQuoteDate , DateTime lastQuoteDate , int numberOfDrivingPositions , int numberOfTickersInPortfolio ) { this.eligibleTickers = eligibleTickers; this.firstQuoteDate = firstQuoteDate; this.lastQuoteDate = lastQuoteDate; this.numberOfDrivingPositions = numberOfDrivingPositions; this.numberOfTickersInPortfolio = numberOfTickersInPortfolio; this.numberOfEligibleTickers = eligibleTickers.Rows.Count; GenomeManagement.SetRandomGenerator(QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator); this.wFLagCandidates = new WFLagCandidates( this.eligibleTickers , this.firstQuoteDate , this.lastQuoteDate ); // this.retrieveData(); } // #region retrieveData // private float[] getArrayOfRatesOfReturn( string ticker ) // { // float[] returnValue = null; // Quotes tickerQuotes = // new Quotes( ticker , this.firstQuoteDate , this.lastQuoteDate ); // float[] allAdjValues = // QuantProject.Data.ExtendedDataTable.GetArrayOfFloatFromColumn( // tickerQuotes , "quAdjustedClose"); // returnValue = new float[ allAdjValues.Length ]; // int i = 0; //index for ratesOfReturns array // for( int idx = 0 ; idx < allAdjValues.Length - 1 ; idx++ ) // { // returnValue[ i ] = allAdjValues[ idx + 1 ] / allAdjValues[ idx ] - 1; // i++; // } // return returnValue; // } // private void retrieveData() // { // this.closeToCloseReturns = // new double[ this.eligibleTickers.Rows.Count ]; // for(int i = 0; i<this.eligibleTickers.Rows.Count; i++) // { // string ticker = (string)this.eligibleTickers.Rows[i][0]; // this.closeToCloseReturns[i] = new WFLagCandidate( ticker, // this.getArrayOfRatesOfReturn( ticker ) ); //// this.closeToCloseReturns[i] = new CandidateProperties( ticker, //// this.getArrayOfRatesOfReturn( ticker ) ); // } // } // #endregion public static string GetTicker( string signedTicker ) { string returnValue; if ( signedTicker.IndexOf( "-" ) == 0 ) returnValue = signedTicker.Substring( 1 , signedTicker.Length - 1 ); else returnValue = signedTicker; return returnValue; } #region GetFitnessValue #region getFitnessValue_getLinearCombinationReturns private Hashtable getTickers( ICollection signedTickers ) { Hashtable tickers = new Hashtable(); foreach ( string signedTicker in signedTickers ) tickers.Add( WFLagGenomeManager.GetTicker( signedTicker ) , null ); return tickers; } private float[] getMultipliers( ICollection signedTickers ) { float[] multipliers = new float[ signedTickers.Count ]; int i = 0; foreach ( string signedTicker in signedTickers ) { float multiplier = 1F; if ( signedTicker.IndexOf( "-" ) == 0 ) multiplier = -1F; multipliers[ i ] = multiplier; i++; } return multipliers; } private double[] getFitnessValue_getLinearCombinationReturns( ICollection signedTickers ) { int numberOfSignedTickers = signedTickers.Count; Hashtable tickers = this.getTickers( signedTickers ); float[] multipliers = this.getMultipliers( signedTickers ); // arrays of close to close returns, one for each signed ticker float[][] tickersReturns = this.wFLagCandidates.GetTickersReturns( tickers.Keys ); double[] linearCombinationReturns = new double[ tickersReturns[ 0 ].Length ]; for( int i = 0; i < linearCombinationReturns.Length ; i++ ) // computes linearCombinationReturns[ i ] { linearCombinationReturns[ i ] = 0; for ( int j=0 ; j < numberOfSignedTickers ; j++ ) { double signedTickerReturn = tickersReturns[ j ][ i ] * multipliers[ j ]; // the investment is assumed to be equally divided for each // signed ticker linearCombinationReturns[ i ] += signedTickerReturn / numberOfSignedTickers; } } return linearCombinationReturns; } #endregion private double[] getFitnessValue_getStrategyReturn( double[] drivingPositionsReturns , double[] portfolioPositionsReturns ) { // strategyReturns contains one element less than drivingPositionsReturns, // because there is no strategy for the very first period (at least // one day signal is needed) double[] strategyReturns = new double[ portfolioPositionsReturns.Length - 1 ]; for ( int i = 0 ; i < portfolioPositionsReturns.Length - 1 ; i++ ) if ( drivingPositionsReturns[ i ] < 0 ) // the current linear combination of tickers, at period i // has a negative return // go short tomorrow strategyReturns[ i ] = -portfolioPositionsReturns[ i + 1 ]; else // the current linear combination of tickers, at period i // has a positive return // go long tomorrow strategyReturns[ i ] = portfolioPositionsReturns[ i + 1 ]; return strategyReturns; } private double getFitnessValue( WFLagSignedTickers wFLagSignedTickers ) { double[] drivingPositionsReturns = this.getFitnessValue_getLinearCombinationReturns( wFLagSignedTickers.DrivingPositions.Keys ); double[] portfolioPositionsReturns = this.getFitnessValue_getLinearCombinationReturns( wFLagSignedTickers.PortfolioPositions.Keys ); double[] strategyReturns = this.getFitnessValue_getStrategyReturn( drivingPositionsReturns , portfolioPositionsReturns ); double fitnessValue = AdvancedFunctions.GetSharpeRatio( strategyReturns ); return fitnessValue; } public double GetFitnessValue( Genome genome ) { WFLagSignedTickers wFLagSignedTickers = ( WFLagSignedTickers )this.Decode( genome ); return this.getFitnessValue( wFLagSignedTickers ); } #endregion public Genome[] GetChilds( Genome parent1 , Genome parent2 ) { return GenomeManipulator.MixGenesWithoutDuplicates(parent1, parent2); } public void Mutate( Genome genome , double mutationRate ) { // in this implementation only one gene is mutated // the new value has to be different from all the other genes of the genome int newValueForGene = GenomeManagement.RandomGenerator.Next( genome.MinValueForGenes , genome.MaxValueForGenes + 1 ); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next( genome.Size ); while( GenomeManipulator.IsTickerContainedInGenome( newValueForGene , genome ) ) // the portfolio, in this implementation, // can't have a long position and a short position // for the same ticker { newValueForGene = GenomeManagement.RandomGenerator.Next( genome.MinValueForGenes , genome.MaxValueForGenes + 1 ); } GenomeManagement.MutateOneGene( genome , mutationRate , genePositionToBeMutated , newValueForGene ); } #region Decode private string decode_getSignedTicker( int geneValue ) { string initialCharForTickerCode = ""; int position = geneValue; if( geneValue < 0 ) { position = Math.Abs( geneValue ) - 1; initialCharForTickerCode = "-"; } return initialCharForTickerCode + ( string )this.eligibleTickers.Rows[ position ][ 0 ]; } private void decode_addDrivingPosition( Genome genome , int geneIndex , WFLagSignedTickers wFLagSignedTickers ) { int indexOfTicker = (int)genome.Genes().GetValue( geneIndex ); string signedTicker = this.decode_getSignedTicker( indexOfTicker ); wFLagSignedTickers.DrivingPositions.Add( signedTicker , null ); } private void decode_addPortfolioPosition( Genome genome , int geneIndex , WFLagSignedTickers wFLagSignedTickers ) { int indexOfTicker = (int)genome.Genes().GetValue( geneIndex ); string signedTicker = this.decode_getSignedTicker( indexOfTicker ); wFLagSignedTickers.PortfolioPositions.Add( signedTicker , null ); } private string decode_getSignedTickerForGeneValue( int geneValue ) { string initialCharForTickerCode = ""; int position = geneValue; if( geneValue < 0 ) { position = Math.Abs( geneValue ) - 1; initialCharForTickerCode = "-"; } return initialCharForTickerCode + ( string )this.eligibleTickers.Rows[ position ][ 0 ]; } public virtual object Decode(Genome genome) { WFLagSignedTickers wFLagSignedTickers = new WFLagSignedTickers(); for ( int geneIndex = 0 ; geneIndex < this.numberOfDrivingPositions ; geneIndex ++ ) this.decode_addDrivingPosition( genome , geneIndex , wFLagSignedTickers ); for ( int geneIndex = this.numberOfDrivingPositions ; geneIndex < this.numberOfDrivingPositions + this.numberOfTickersInPortfolio ; geneIndex ++ ) this.decode_addPortfolioPosition( genome , geneIndex , wFLagSignedTickers ); string[] arrayOfTickers = new string[genome.Genes().Length]; int indexOfTicker; for(int index = 0; index < genome.Genes().Length; index++) { indexOfTicker = (int)genome.Genes().GetValue(index); arrayOfTickers[index] = this.decode_getSignedTickerForGeneValue(indexOfTicker); } return wFLagSignedTickers; } #endregion public int GetNewGeneValue( Genome genome , int i ) { // in this implementation new gene values must be different from // the others already stored in the given genome int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); while( GenomeManipulator.IsTickerContainedInGenome(returnValue, genome) ) // the portfolio can't have a long position and a // short one for the same ticker { returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); } return returnValue; } } } |
|
From: Glauco S. <gla...@us...> - 2006-03-14 15:04:10
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2207 Added Files: WFLagEndOfDayTimerHandler.cs Log Message: Implements OneHourAfterMarketCloseEventHandler and FiveMinutesBeforeMarketCloseEventHandler for the Lag strategy. This is the core strategy! --- NEW FILE: WFLagEndOfDayTimerHandler.cs --- /* QuantProject - Quantitative Finance Library WFLagEndOfDayTimerHandler.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.ADT; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Timing; using QuantProject.Scripts.SimpleTesting; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { /// <summary> /// Implements OneHourAfterMarketCloseEventHandler /// and FiveMinutesBeforeMarketCloseEventHandler for the /// Lag strategy. This is the core strategy! /// </summary> public class WFLagEndOfDayTimerHandler { private string tickerGroupID; private string benchmark; private int numberEligibleTickers; private int numberOfPositionsToBeChosen; private int numberOfDrivingPositions; private int inSampleWindowDays; private int outOfSampleWindowDays; private Account account; private int generationNumberForGeneticOptimizer; private int populationSizeForGeneticOptimizer; private WFLagEligibleTickers eligibleTickers; private WFLagChosenTickers chosenTickers; private HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider; private DateTime lastOptimizationDate; public event InSampleNewProgressEventHandler InSampleNewProgress; public WFLagEndOfDayTimerHandler( string tickerGroupID , string benchmark , int numberEligibleTickers , int numberOfPositionsToBeChosen , int numberOfDrivingPositions , int inSampleWindowDays , int outOfSampleWindowDays , Account account , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer ) { this.tickerGroupID = tickerGroupID; this.benchmark = benchmark; this.numberEligibleTickers = numberEligibleTickers; this.numberOfPositionsToBeChosen = numberOfPositionsToBeChosen; this.numberOfDrivingPositions = numberOfDrivingPositions; this.inSampleWindowDays = inSampleWindowDays; this.outOfSampleWindowDays = outOfSampleWindowDays; this.account = account; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.eligibleTickers = new WFLagEligibleTickers( this.tickerGroupID , this.benchmark , this.numberEligibleTickers , this.inSampleWindowDays , this.account.EndOfDayTimer ); this.chosenTickers = new WFLagChosenTickers( this.numberOfDrivingPositions , this.numberOfPositionsToBeChosen , this.inSampleWindowDays , this.account.EndOfDayTimer , this.generationNumberForGeneticOptimizer , this.populationSizeForGeneticOptimizer ); this.chosenTickers.NewProgress += new NewProgressEventHandler( this.bestPerformingNewProgress ); this.historicalAdjustedQuoteProvider = new HistoricalAdjustedQuoteProvider(); this.lastOptimizationDate = DateTime.MinValue; } private EndOfDayDateTime now() { return this.account.EndOfDayTimer.GetCurrentTime(); } private void bestPerformingNewProgress( Object sender , NewProgressEventArgs eventArgs ) { this.InSampleNewProgress( sender , eventArgs ); } #region fiveMinutesBeforeMarketCloseEventHandler_openPositions private string getTicker( string signedTicker ) { string returnValue; if ( signedTicker.IndexOf( "-" ) == 0 ) returnValue = signedTicker.Substring( 1 , signedTicker.Length - 1 ); else returnValue = signedTicker; return returnValue; } private int getReturnMultiplier( string signedTicker ) { int returnValue; if ( signedTicker.IndexOf( "-" ) == 0 ) returnValue = -1; else returnValue = 1; return returnValue; } private double getTodayReturnForTicker( string ticker ) { double todayMarketValueAtClose = this.account.DataStreamer.GetCurrentBid( ticker ); EndOfDayDateTime yesterdayAtClose = new EndOfDayDateTime( this.account.EndOfDayTimer.GetCurrentTime().DateTime.AddDays( - 1 ) , EndOfDaySpecificTime.MarketClose ); double yesterdayMarketValueAtClose = this.historicalAdjustedQuoteProvider.GetMarketValue( ticker , yesterdayAtClose ); double returnValue = ( todayMarketValueAtClose - yesterdayMarketValueAtClose ) / yesterdayMarketValueAtClose ; return returnValue; } private double getTodayReturnForSignedTicker( string signedTicker ) { double todayReturnForTicker = this.getTodayReturnForTicker( WFLagGenomeManager.GetTicker( signedTicker ) ); int returnMultiplier = this.getReturnMultiplier( signedTicker ); return todayReturnForTicker * returnMultiplier; } /// <summary> /// true iff driving positions are down today /// </summary> /// <returns></returns> private bool isToReverse() { double totalReturn = 0; foreach ( string signedTicker in this.chosenTickers.DrivingPositions.Keys ) totalReturn += this.getTodayReturnForSignedTicker( signedTicker ); return totalReturn < 0; } private OrderType fiveMinutesBeforeMarketCloseEventHandler_openPosition_getOrderType( string signedTicker , bool isToReverse ) { OrderType orderType = OrderType.MarketBuy; if ( ( signedTicker.StartsWith( "-" ) && !isToReverse ) || ( !signedTicker.StartsWith( "-" ) && isToReverse ) ) orderType = OrderType.MarketSellShort; return orderType; } private void fiveMinutesBeforeMarketCloseEventHandler_openPosition( string signedTicker , bool isToReverse ) { string ticker = this.getTicker( signedTicker ); OrderType orderType = this.fiveMinutesBeforeMarketCloseEventHandler_openPosition_getOrderType( signedTicker , isToReverse ); double maxPositionValue = this.account.GetMarketValue() / this.numberOfPositionsToBeChosen; long sharesToBeTraded = OneRank.MaxBuyableShares( ticker , maxPositionValue , this.account.DataStreamer ); this.account.AddOrder( new Order( orderType , new Instrument( ticker ) , sharesToBeTraded ) ); } private void fiveMinutesBeforeMarketCloseEventHandler_openPositions_actually() { bool isToReverse = this.isToReverse(); foreach ( string signedTicker in this.chosenTickers.PortfolioPositions.Keys ) this.fiveMinutesBeforeMarketCloseEventHandler_openPosition( signedTicker , isToReverse ); } private void fiveMinutesBeforeMarketCloseEventHandler_openPositions() { if ( this.chosenTickers.DrivingPositions != null ) this.fiveMinutesBeforeMarketCloseEventHandler_openPositions_actually(); } private double getTodayReturnForDrivingPositions() { double totalReturn = 0; foreach ( string signedTicker in this.chosenTickers.DrivingPositions.Keys ) totalReturn += this.getTodayReturnForSignedTicker( signedTicker ); return totalReturn; } private Position getFirstPosition() { IEnumerator positions = this.account.Portfolio.Values.GetEnumerator(); positions.Reset(); positions.MoveNext(); Position position = (Position)positions.Current; return position; } private string getSignedTicker( string ticker ) { string signedTicker = ""; if ( this.chosenTickers.PortfolioPositions.ContainsKey( ticker ) ) signedTicker = ticker; if ( this.chosenTickers.PortfolioPositions.ContainsKey( "-" + ticker ) ) signedTicker = "-" + ticker; if ( signedTicker == "" ) throw new Exception( "Nor ticker, nor '-'+ticker are contained in " + "chosenTickers.PortfolioPositions ; this is an unexpected " + "situation, when this method is invoked." ); return signedTicker; } private bool isShort( string signedTicker ) { return ( signedTicker.StartsWith( "-" ) ); } private bool isLong( string signedTicker ) { return ( !this.isShort( signedTicker ) ); } private bool isContainedInPortfolio( string signedTicker ) { string ticker = this.getTicker( signedTicker ); bool isContained = ( this.account.Portfolio.ContainsKey( ticker ) ) && ( ( this.isLong( signedTicker ) && this.account.Portfolio.IsLong( ticker ) ) || ( !this.isLong( signedTicker ) && this.account.Portfolio.IsShort( ticker ) ) ); return isContained; } private bool doPositionsCorrespondTo( ICollection signedTickers ) { bool areUpTodate = true; foreach ( string signedTicker in signedTickers ) areUpTodate = areUpTodate && this.isContainedInPortfolio( signedTicker ); return areUpTodate; } private string reverse( string signedTicker ) { string reversedSignedTicker = ""; if ( this.isLong( signedTicker ) ) reversedSignedTicker = "-" + signedTicker; if ( !this.isLong( signedTicker ) ) // signedTicker starts with a "-" character reversedSignedTicker = signedTicker.Substring( 1 ); return reversedSignedTicker; } private ICollection reverse( ICollection signedTickers ) { Hashtable reversedCollection = new Hashtable(); foreach ( string signedTicker in signedTickers ) reversedCollection.Add( this.reverse( signedTicker ) , null ); return reversedCollection.Keys; } private bool arePositionsUpToDateWithChosenTickers() { bool areUpTodate = this.doPositionsCorrespondTo( this.chosenTickers.PortfolioPositions.Keys ) || this.doPositionsCorrespondTo( this.reverse( this.chosenTickers.PortfolioPositions.Keys ) ); return areUpTodate; } private bool isReversed() { Position position = this.getFirstPosition(); PositionType positionType = position.Type; string positionTicker = position.Instrument.Key; String signedTicker = this.getSignedTicker( positionTicker ); bool isReversedPosition = ( ( this.isLong( signedTicker )&& ( position.Type == PositionType.Short ) ) || ( !this.isLong( signedTicker ) && ( position.Type == PositionType.Long ) ) ); return isReversedPosition; } private bool isReversingNeeded() { double todayReturnForDrivingPositions = this.getTodayReturnForDrivingPositions(); bool portfolioIsReversed = this.isReversed(); bool areToBeClosed = ( ( todayReturnForDrivingPositions < 0 ) && ( !portfolioIsReversed ) ) || ( ( todayReturnForDrivingPositions > 0 ) && ( portfolioIsReversed ) ); return areToBeClosed; } private bool arePositionsToBeClosed() { bool areToBeClosed = (!this.arePositionsUpToDateWithChosenTickers()) || this.isReversingNeeded(); return areToBeClosed; } private void fiveMinutesBeforeMarketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); foreach ( string ticker in this.account.Portfolio.Keys ) tickers.Add( ticker ); foreach ( string ticker in tickers ) this.account.ClosePosition( ticker ); } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Portfolio.Count == 0 ) fiveMinutesBeforeMarketCloseEventHandler_openPositions(); else { if ( this.arePositionsToBeClosed() ) { this.fiveMinutesBeforeMarketCloseEventHandler_closePositions(); this.fiveMinutesBeforeMarketCloseEventHandler_openPositions(); } } } #endregion private bool areBestTickersToBeChosen() { bool returnValue = ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDate == DateTime.MinValue ) ) ) || ( this.now().DateTime >= this.lastOptimizationDate.AddDays( this.outOfSampleWindowDays ) ) ); return returnValue; } public void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.areBestTickersToBeChosen() ) // the portfolio is empty and // either the lastOptimizationDate has not been set yet // or outOfSampleWindowDays elapsed since last optimization { this.eligibleTickers.SetTickers(); Console.WriteLine( "Number of Eligible tickers: " + this.eligibleTickers.EligibleTickers.Rows.Count ); this.chosenTickers.SetSignedTickers( this.eligibleTickers ); this.lastOptimizationDate = this.now().DateTime; } // oneHourAfterMarketCloseEventHandler_orderChosenTickers( ( IEndOfDayTimer ) sender ); } } } |
|
From: Glauco S. <gla...@us...> - 2006-03-14 15:02:33
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1465 Added Files: WFLagEligibleTickers.cs Log Message: Tickers eligible for the lag strategy --- NEW FILE: WFLagEligibleTickers.cs --- /* QuantProject - Quantitative Finance Library WFLagEligibleTickers.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 QuantProject.Business.Timing; using QuantProject.Data.Selectors; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { /// <summary> /// Tickers eligible for the lag strategy /// </summary> public class WFLagEligibleTickers { private string tickerGroupID; private string benchmark; private int numberEligibleTickersToBeChosen; private int numberDaysForPerformanceCalculation; private IEndOfDayTimer endOfDayTimer; private DataTable eligibleTickers; public DataTable EligibleTickers { get { if ( this.eligibleTickers == null ) this.SetTickers(); return this.eligibleTickers; } } public WFLagEligibleTickers( string tickerGroupID , string benchmark , int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , IEndOfDayTimer endOfDayTimer ) { this.tickerGroupID = tickerGroupID; this.benchmark = benchmark; this.numberEligibleTickersToBeChosen = numberEligibleTickersToBeChosen; this.numberDaysForPerformanceCalculation = numberDaysForPerformanceCalculation; this.endOfDayTimer = endOfDayTimer; this.eligibleTickers = new DataTable(); } #region setTickers private DataTable setTickers_build_getSelectedTickers() { DateTime dateTime = this.endOfDayTimer.GetCurrentTime().DateTime; SelectorByGroup selectorByGroup = new SelectorByGroup( this.tickerGroupID , dateTime ); DataTable groupTickers = selectorByGroup.GetTableOfSelectedTickers(); // SelectorByLiquidity mostLiquid = // new SelectorByLiquidity("Test", false , dateTime.AddDays( - this.numDaysToComputeLiquidity ) , dateTime , // this.numberEligibleTickersToBeChosen ); // DataTable mostLiquidTickers = // mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedInEachMarketDay = new SelectorByQuotationAtEachMarketDay( groupTickers , false , dateTime.AddDays( - this.numberDaysForPerformanceCalculation ) , dateTime , this.numberEligibleTickersToBeChosen , this.benchmark ); return quotedInEachMarketDay.GetTableOfSelectedTickers(); } private DataTable setTickers_buildQuickly_getSelectedTickers() { DataTable returnValue = new QuantProject.Data.DataTables.Tickers_tickerGroups( "millo" ); returnValue.Columns[ 0 ].ColumnName = "tiTicker"; return returnValue; } private void setTickers_build() { // for fast debug, comment the following line this.eligibleTickers = setTickers_build_getSelectedTickers(); // for fast debug, uncomment the following line // DataTable selectedTickers = setTickers_buildQuickly_getSelectedTickers(); } /// <summary> /// Populates the collection of eligible tickers /// </summary> /// <param name="dateTime"></param> public void SetTickers() { this.eligibleTickers.Clear(); setTickers_build(); } #endregion } } |