[Quantproject-developers] QuantProject/b4_Business/a2_Strategies EndOfDayStrategyBackTester.cs, 1.2
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-01-28 21:39:46
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10735/b4_Business/a2_Strategies Modified Files: EndOfDayStrategyBackTester.cs Log Message: - the ActualLastDateTime property has been added - the property AccountReport has been added - the property DescriptionForLogFileName has been improved - an AccountReport is now created when the backtest is completed Index: EndOfDayStrategyBackTester.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EndOfDayStrategyBackTester.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayStrategyBackTester.cs 27 Jan 2008 02:27:46 -0000 1.2 --- EndOfDayStrategyBackTester.cs 28 Jan 2008 21:39:42 -0000 1.3 *************** *** 28,31 **** --- 28,32 ---- using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; + using QuantProject.Business.Financial.Accounting.Reporting; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Strategies.Logging; *************** *** 52,57 **** --- 53,61 ---- private DateTime startingTimeForScript; private IEndOfDayTimer endOfDayTimer; + private DateTime actualLastDateTime; private Account account; + private AccountReport accountReport; private BackTestLog backTestLog; + private DateTime realDateTimeWhenTheBackTestIsStopped; public IHistoricalQuoteProvider HistoricalQuoteProvider *************** *** 63,69 **** get { return this.benchmark; } } public Account Account { ! get { return this.account; } } public BackTestLog Log --- 67,100 ---- get { return this.benchmark; } } + /// <summary> + /// Returns the dimulated DateTime when the backtest is stopped + /// (not the real time) + /// </summary> + public DateTime ActualLastDateTime + { + get + { + this.checkThisPropertyRequiresBacktestIsCompleted(); + return this.actualLastDateTime; + } + } public Account Account { ! get ! { ! return this.account; ! } ! } ! /// <summary> ! /// Once the backtest is completed, this property returns the ! /// AccountReport for the internal Account ! /// </summary> ! public AccountReport AccountReport ! { ! get ! { ! this.checkThisPropertyRequiresBacktestIsCompleted(); ! return this.accountReport; ! } } public BackTestLog Log *************** *** 89,97 **** { string description = ! this.backTestID + "_" + "from_" + ExtendedDateTime.GetShortDescriptionForFileName( this.firstDateTime ) + "_to_" + ! ExtendedDateTime.GetShortDescriptionForFileName( this.lastDateTime ) + "_strtgy_" + this.endOfDayStrategy.DescriptionForLogFileName; return description; --- 120,132 ---- { string description = ! ExtendedDateTime.GetCompleteShortDescriptionForFileName( ! this.realDateTimeWhenTheBackTestIsStopped ) + "_" + "from_" + ExtendedDateTime.GetShortDescriptionForFileName( this.firstDateTime ) + "_to_" + ! ExtendedDateTime.GetShortDescriptionForFileName( this.actualLastDateTime ) + ! "_annlRtrn_" + this.AccountReport.Summary.AnnualSystemPercentageReturn.FormattedValue + ! "_maxDD_" + this.AccountReport.Summary.MaxEquityDrawDown.FormattedValue + ! "_qtPrvdr_" + this.historicalQuoteProvider.ShortDescription + "_strtgy_" + this.endOfDayStrategy.DescriptionForLogFileName; return description; *************** *** 99,102 **** --- 134,145 ---- } + private void checkThisPropertyRequiresBacktestIsCompleted() + { + if ( this.actualLastDateTime == DateTime.MinValue ) + // the timer has not been stopped yet + throw new Exception( "This property cannot be invoked " + + "while the backtest is still running!" ); + } + public EndOfDayStrategyBackTester( string backTestID , IEndOfDayStrategyForBacktester endOfDayStrategy , *************** *** 120,123 **** --- 163,168 ---- this.backTestLog = new BackTestLog( backTestID , firstDateTime , lastDateTime , benchmark ); + this.actualLastDateTime = DateTime.MinValue; + this.realDateTimeWhenTheBackTestIsStopped = DateTime.MinValue; } *************** *** 237,247 **** 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.endOfDayTimer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , --- 282,302 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! EndOfDayDateTime currentEndOfDayDateTime = ! ( ( IEndOfDayTimer )sender ).GetCurrentTime(); ! DateTime currentDateTime = currentEndOfDayDateTime.DateTime; ! if ( this.isTimeToStop( currentDateTime ) ) { // either the simulation has reached the ending date or // too much time elapsed since the simulation started + this.actualLastDateTime = + ExtendedDateTime.Min( this.lastDateTime , currentDateTime ); this.endOfDayTimer.Stop(); + this.realDateTimeWhenTheBackTestIsStopped = DateTime.Now; + this.accountReport = this.account.CreateReport( + "" , + 1 , currentEndOfDayDateTime , this.benchmark.Ticker , + this.historicalQuoteProvider ); + this.accountReport.Name = this.DescriptionForLogFileName; + // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , |