[Quantproject-developers] QuantProject/b4_Business/a2_Strategies EndOfDayStrategyBackTester.cs, 1.1
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-11-20 20:55:47
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv32461/b4_Business/a2_Strategies Modified Files: EndOfDayStrategyBackTester.cs Log Message: the backtester was bug about deciding when to stop (and to produce and save the report) Index: EndOfDayStrategyBackTester.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EndOfDayStrategyBackTester.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** EndOfDayStrategyBackTester.cs 18 Nov 2008 23:01:52 -0000 1.12 --- EndOfDayStrategyBackTester.cs 20 Nov 2008 20:55:36 -0000 1.13 *************** *** 153,157 **** private void checkThisPropertyRequiresBacktestIsCompleted() { ! if ( this.actualLastDateTime == DateTime.MinValue ) // the timer has not been stopped yet throw new Exception( "This property cannot be invoked " + --- 153,158 ---- private void checkThisPropertyRequiresBacktestIsCompleted() { ! // if ( this.actualLastDateTime == DateTime.MinValue ) ! if ( !this.timer.IsDone ) // the timer has not been stopped yet throw new Exception( "This property cannot be invoked " + *************** *** 294,297 **** --- 295,312 ---- } #endregion run_addEventHandlers + + private void completeTheScript() + { + this.actualLastDateTime = + ExtendedDateTime.Min( + this.lastDateTime , this.timer.GetCurrentDateTime() ); + this.realDateTimeWhenTheBackTestIsStopped = DateTime.Now; + this.accountReport = this.account.CreateReport( + "" , 1 , + this.timer.GetCurrentDateTime() , this.benchmark.Ticker , + this.historicalMarketValueProvider ); + this.accountReport.Name = this.Description; + } + /// <summary> /// Performes the actual backtest *************** *** 308,311 **** --- 323,327 ---- // this.progressBarForm.Show(); this.timer.Start(); + this.completeTheScript(); } #endregion Run *************** *** 313,354 **** #region newDateTimeEventHandler ! private bool isTimeToStop( DateTime currentTime ) { DateTime maxEndingDateTimeForScript = this.startingTimeForScript.AddHours( this.maxRunningHours ); DateTime realTime = DateTime.Now; ! bool scriptTimeElapsed = ( realTime >= maxEndingDateTimeForScript ); bool stopBacktestIfMaxRunningHoursHasBeenReached = this.strategyForBacktester.StopBacktestIfMaxRunningHoursHasBeenReached; return ( ( currentTime > this.lastDateTime ) || ! ( scriptTimeElapsed && ! stopBacktestIfMaxRunningHoursHasBeenReached ) ); } ! // private void removeTimerEventHandlers() ! // { ! // foreach( NewDateTimeEventHandler newDateTimeEventHandler in ! // this.timer.NewDateTime.GetInvocationList()) ! // { ! // this.timer.NewDateTime -= newDateTimeEventHandler; ! // } ! // } #region stopTheScript private void stopTheScript( DateTime currentDateTime ) { ! this.actualLastDateTime = ! ExtendedDateTime.Min( this.lastDateTime , currentDateTime ); this.timer.Stop(); ! // this.removeTimerEventHandlers(); ! // this.timer.NewDateTime -= ! // new NewDateTimeEventHandler( ! // this.strategyForBacktester.NewDateTimeEventHandler ); ! this.realDateTimeWhenTheBackTestIsStopped = DateTime.Now; ! this.accountReport = this.account.CreateReport( ! "" , ! 1 , currentDateTime , this.benchmark.Ticker , ! this.historicalMarketValueProvider ); ! this.accountReport.Name = this.Description; } // private void stopTheScriptIfTheCase( Object sender ) --- 329,370 ---- #region newDateTimeEventHandler ! #region isTimeToStop ! private bool getIsMaxScriptRealTimeElapsed() { DateTime maxEndingDateTimeForScript = this.startingTimeForScript.AddHours( this.maxRunningHours ); DateTime realTime = DateTime.Now; ! bool isMaxScriptRealTimeElapsed = ( realTime >= maxEndingDateTimeForScript ); ! return isMaxScriptRealTimeElapsed; ! } ! private bool isTimeToStop( DateTime currentTime ) ! { ! bool isMaxScriptRealTimeElapsed = ! this.getIsMaxScriptRealTimeElapsed(); bool stopBacktestIfMaxRunningHoursHasBeenReached = this.strategyForBacktester.StopBacktestIfMaxRunningHoursHasBeenReached; + bool hasTheTimerAlreadyThrownOutAllItsNewDateTime = this.timer.IsDone; return ( ( currentTime > this.lastDateTime ) || ! ( isMaxScriptRealTimeElapsed && ! stopBacktestIfMaxRunningHoursHasBeenReached ) || ! hasTheTimerAlreadyThrownOutAllItsNewDateTime ); } ! #endregion isTimeToStop #region stopTheScript private void stopTheScript( DateTime currentDateTime ) { ! // this.actualLastDateTime = ! // ExtendedDateTime.Min( this.lastDateTime , currentDateTime ); ! this.timer.Stop(); ! ! // this.realDateTimeWhenTheBackTestIsStopped = DateTime.Now; ! // this.accountReport = this.account.CreateReport( ! // "" , ! // 1 , currentDateTime , this.benchmark.Ticker , ! // this.historicalMarketValueProvider ); ! // this.accountReport.Name = this.Description; } // private void stopTheScriptIfTheCase( Object sender ) |