[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag RunWalkForward
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:21:43
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18316 Modified Files: RunWalkForwardLag.cs WFLagChosenTickers.cs WFLagEligibleTickers.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WFLagEligibleTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagEligibleTickers.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WFLagEligibleTickers.cs 18 Feb 2007 01:02:24 -0000 1.5 --- WFLagEligibleTickers.cs 29 Sep 2008 21:20:52 -0000 1.6 *************** *** 38,42 **** private int numberEligibleTickersToBeChosen; private int numberDaysForPerformanceCalculation; ! private IEndOfDayTimer endOfDayTimer; private DataTable eligibleTickers; --- 38,42 ---- private int numberEligibleTickersToBeChosen; private int numberDaysForPerformanceCalculation; ! private Timer endOfDayTimer; private DataTable eligibleTickers; *************** *** 56,60 **** int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! IEndOfDayTimer endOfDayTimer ) { this.checkParametersForWFLagEligibleTickers( tickerGroupID , benchmark , --- 56,60 ---- int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! Timer endOfDayTimer ) { this.checkParametersForWFLagEligibleTickers( tickerGroupID , benchmark , *************** *** 73,77 **** int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! IEndOfDayTimer endOfDayTimer ) { if ( numberDaysForPerformanceCalculation <= 0 ) --- 73,77 ---- int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! Timer endOfDayTimer ) { if ( numberDaysForPerformanceCalculation <= 0 ) *************** *** 82,86 **** private DataTable setTickers_build_getSelectedTickers() { ! DateTime dateTime = this.endOfDayTimer.GetCurrentTime().DateTime; // SelectorByGroup selectorByGroup = // new SelectorByGroup( this.tickerGroupID , dateTime ); --- 82,86 ---- private DataTable setTickers_build_getSelectedTickers() { ! DateTime dateTime = this.endOfDayTimer.GetCurrentDateTime(); // SelectorByGroup selectorByGroup = // new SelectorByGroup( this.tickerGroupID , dateTime ); Index: RunWalkForwardLag.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/RunWalkForwardLag.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** RunWalkForwardLag.cs 19 Aug 2008 17:13:11 -0000 1.13 --- RunWalkForwardLag.cs 29 Sep 2008 21:20:51 -0000 1.14 *************** *** 3,7 **** RunWalkForwardLag.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- RunWalkForwardLag.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** 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; --- 19,23 ---- 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; *************** *** 59,69 **** private double maxRunningHours; ! private IHistoricalQuoteProvider historicalQuoteProvider; ! private IEndOfDayTimer endOfDayTimer; private DateTime startingTimeForScript; private Account account; private WFLagEndOfDayTimerHandler endOfDayTimerHandler; ! private WFLagLog wFLagLog; public event NewProgressEventHandler InSampleNewProgress; --- 59,69 ---- private double maxRunningHours; ! private HistoricalMarketValueProvider historicalMarketValueProvider; ! private Timer endOfDayTimer; private DateTime startingTimeForScript; private Account account; private WFLagEndOfDayTimerHandler endOfDayTimerHandler; ! private WFLagLog wFLagLog; public event NewProgressEventHandler InSampleNewProgress; *************** *** 94,121 **** this.wFLagLog = new WFLagLog( this.numberDaysForInSampleOptimization , ! this.benchmark ); } private void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } private void run_initializeEndOfDayTimer() { ! EndOfDayDateTime endOfDayDateTime = ! new EndOfDayDateTime( firstDateTime , ! EndOfDaySpecificTime.MarketOpen ); this.endOfDayTimer = ! new IndexBasedEndOfDayTimer( endOfDayDateTime , ! this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WalkForwardLag" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ) ); } private void run_initializeEndOfDayTimerHandler() --- 94,122 ---- this.wFLagLog = new WFLagLog( this.numberDaysForInSampleOptimization , ! this.benchmark ); } private void run_initializeHistoricalQuoteProvider() { ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); } private void run_initializeEndOfDayTimer() { ! DateTime dateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( firstDateTime ); ! // new EndOfDayDateTime( firstDateTime , ! // EndOfDaySpecificTime.MarketOpen ); this.endOfDayTimer = ! new IndexBasedEndOfDayTimer( dateTime , ! this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WalkForwardLag" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider ) ); } private void run_initializeEndOfDayTimerHandler() *************** *** 123,132 **** this.endOfDayTimerHandler = new WFLagEndOfDayTimerHandler( ! this.tickerGroupID , ! this.benchmark , ! this.numberEligibleTickers , ! this.wFLagWeightedPositionsChooser , ! this.numDaysBetweenEachOptimization , ! this.account ); } public static void WriteToTextLog( string message ) --- 124,133 ---- this.endOfDayTimerHandler = new WFLagEndOfDayTimerHandler( ! this.tickerGroupID , ! this.benchmark , ! this.numberEligibleTickers , ! this.wFLagWeightedPositionsChooser , ! this.numDaysBetweenEachOptimization , ! this.account ); } public static void WriteToTextLog( string message ) *************** *** 139,143 **** // FileMode.OpenOrCreate ); StreamWriter streamWriter = new StreamWriter( "WFLagLog.Txt" , ! true ); streamWriter.WriteLine( message ); streamWriter.Close(); --- 140,144 ---- // FileMode.OpenOrCreate ); StreamWriter streamWriter = new StreamWriter( "WFLagLog.Txt" , ! true ); streamWriter.WriteLine( message ); streamWriter.Close(); *************** *** 153,161 **** // when large populations are chosen // if ( eventArgs.CurrentProgress % 20 == 0 ) ! RunWalkForwardLag.WriteToTextLog( ! eventArgs.CurrentProgress.ToString() + " / " + ! eventArgs.Goal.ToString() + ! " - " + ! DateTime.Now.ToString() ); } private void run_initializeProgressHandlers() --- 154,162 ---- // when large populations are chosen // if ( eventArgs.CurrentProgress % 20 == 0 ) ! RunWalkForwardLag.WriteToTextLog( ! eventArgs.CurrentProgress.ToString() + " / " + ! eventArgs.Goal.ToString() + ! " - " + ! DateTime.Now.ToString() ); } private void run_initializeProgressHandlers() *************** *** 165,169 **** } public void marketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Transactions.Count == 0 ) --- 166,170 ---- } public void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if ( this.account.Transactions.Count == 0 ) *************** *** 172,179 **** #region marketCloseEventHandler private void marketCloseEventHandler_handleProgessBarForm( ! IEndOfDayTimer endOfDayTimer ) { string progress = "Current out of sample date:" + ! endOfDayTimer.GetCurrentTime().DateTime.ToString() + " - " + "First date:" + this.firstDateTime.ToString() + " - " + "Last date:" + this.lastDateTime.ToString(); --- 173,180 ---- #region marketCloseEventHandler private void marketCloseEventHandler_handleProgessBarForm( ! Timer endOfDayTimer ) { string progress = "Current out of sample date:" + ! endOfDayTimer.GetCurrentDateTime().ToString() + " - " + "First date:" + this.firstDateTime.ToString() + " - " + "Last date:" + this.lastDateTime.ToString(); *************** *** 210,214 **** this.wFLagWeightedPositionsChooser.NumberOfPortfolioPositions + "_" + "From_" + this.getShortStringForDateTime( ! (DateTime)this.account.Transactions.GetKey( 0 ) ) + "_" + "To_" + this.getShortStringForDateTime( currentTime ) + "_" + "inSample_" + this.numberDaysForInSampleOptimization.ToString() + "_" + --- 211,215 ---- this.wFLagWeightedPositionsChooser.NumberOfPortfolioPositions + "_" + "From_" + this.getShortStringForDateTime( ! (DateTime)this.account.Transactions.GetKey( 0 ) ) + "_" + "To_" + this.getShortStringForDateTime( currentTime ) + "_" + "inSample_" + this.numberDaysForInSampleOptimization.ToString() + "_" + *************** *** 224,240 **** new VisualObjectArchiver(); visualObjectArchiver.Save( this.wFLagLog , "qPWFLagLog" , ! this.getDefaultLogFileName( currentTime ) , defaultFolderPath ); } private void showReport( object sender ) { DateTime lastReportDateTime = this.lastDateTime; ! if ( ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime < ! lastReportDateTime ) lastReportDateTime = ! ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime; ! Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "Walk Forward Lag" , 1 , ! new EndOfDayDateTime( lastReportDateTime , ! EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark ); report.Show(); --- 225,244 ---- new VisualObjectArchiver(); visualObjectArchiver.Save( this.wFLagLog , "qPWFLagLog" , ! this.getDefaultLogFileName( currentTime ) , defaultFolderPath ); } private void showReport( object sender ) { DateTime lastReportDateTime = this.lastDateTime; ! if ( ( ( Timer )sender ).GetCurrentDateTime() < ! lastReportDateTime ) lastReportDateTime = ! ( ( Timer )sender ).GetCurrentDateTime(); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "Walk Forward Lag" , 1 , ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! lastReportDateTime ) , ! // new EndOfDayDateTime( lastReportDateTime , ! // EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark ); report.Show(); *************** *** 248,264 **** this.endOfDayTimerHandler.AreBestTickersToBeChosen(); return ! ( ( currentTime > this.lastDateTime ) || ! ( scriptTimeElapsed && areBestTickersToBeChosen ) ); } private void marketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { DateTime currentTime = ! ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime; if ( this.isTimeToStop( currentTime ) ) { // either the simulation has reached the ending date or // too much time elapsed since the simulation started ! this.account.EndOfDayTimer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , --- 252,268 ---- this.endOfDayTimerHandler.AreBestTickersToBeChosen(); return ! ( ( currentTime > this.lastDateTime ) || ! ( scriptTimeElapsed && areBestTickersToBeChosen ) ); } private void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { DateTime currentTime = ! ( ( Timer )sender ).GetCurrentDateTime(); if ( this.isTimeToStop( currentTime ) ) { // either the simulation has reached the ending date or // too much time elapsed since the simulation started ! this.account.Timer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , *************** *** 276,284 **** // the simulation has not reached the ending date, yet this.marketCloseEventHandler_handleProgessBarForm( ! ( IEndOfDayTimer )sender ); } #endregion private void newChosenPositionsEventHandler( object sender , ! WFLagNewChosenPositionsEventArgs eventArgs ) { // WFLagChosenPositions wFLagChosenPositions = --- 280,288 ---- // the simulation has not reached the ending date, yet this.marketCloseEventHandler_handleProgessBarForm( ! ( Timer )sender ); } #endregion private void newChosenPositionsEventHandler( object sender , ! WFLagNewChosenPositionsEventArgs eventArgs ) { // WFLagChosenPositions wFLagChosenPositions = *************** *** 287,306 **** this.wFLagLog.Add( eventArgs.WFLagLogItem ); } private void run_addEventHandlers() { ! this.endOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( this.marketOpenEventHandler ); ! this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! new FiveMinutesBeforeMarketCloseEventHandler( ! this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.marketCloseEventHandler ); this.endOfDayTimerHandler.NewChosenPositions += new NewChosenPositionsEventHandler( ! this.newChosenPositionsEventHandler ); } public override void Run() --- 291,321 ---- this.wFLagLog.Add( eventArgs.WFLagLogItem ); } + + private void newDateTimeEventHandler( object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + this.marketCloseEventHandler( sender , dateTime ); + } private void run_addEventHandlers() { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( this.marketOpenEventHandler ); ! // this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! // new FiveMinutesBeforeMarketCloseEventHandler( ! // this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.marketCloseEventHandler ); this.endOfDayTimerHandler.NewChosenPositions += new NewChosenPositionsEventHandler( ! this.newChosenPositionsEventHandler ); } public override void Run() Index: WFLagChosenTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagChosenTickers.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** WFLagChosenTickers.cs 19 Aug 2008 17:13:12 -0000 1.11 --- WFLagChosenTickers.cs 29 Sep 2008 21:20:52 -0000 1.12 *************** *** 48,52 **** protected int numberOfPositionsToBeChosen; protected int inSampleDays; ! protected IEndOfDayTimer endOfDayTimer; protected int generationNumberForGeneticOptimizer; protected int populationSizeForGeneticOptimizer; --- 48,52 ---- protected int numberOfPositionsToBeChosen; protected int inSampleDays; ! protected Timer endOfDayTimer; protected int generationNumberForGeneticOptimizer; protected int populationSizeForGeneticOptimizer; *************** *** 112,116 **** int numberOfPositionsToBeChosen , int inSampleDays , ! IEndOfDayTimer endOfDayTimer , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer , --- 112,116 ---- int numberOfPositionsToBeChosen , int inSampleDays , ! Timer endOfDayTimer , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer , *************** *** 167,174 **** { this.firstOptimizationDate = ! this.endOfDayTimer.GetCurrentTime().DateTime.AddDays( -( this.inSampleDays - 1 ) ); this.lastOptimizationDate = ! this.endOfDayTimer.GetCurrentTime().DateTime; WFLagGenomeManager genomeManager = --- 167,174 ---- { this.firstOptimizationDate = ! this.endOfDayTimer.GetCurrentDateTime().AddDays( -( this.inSampleDays - 1 ) ); this.lastOptimizationDate = ! this.endOfDayTimer.GetCurrentDateTime(); WFLagGenomeManager genomeManager = |