[Quantproject-developers] QuantProject/b4_Business/a05_Timing IndexBasedHistoricalTimer.cs, 1.3, 1.
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-11-20 20:47:02
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31305/b4_Business/a05_Timing Modified Files: IndexBasedHistoricalTimer.cs Log Message: - the method protected bool isDone() has been overridden (implemented) - now a NewDateTime event is sent out (every market day) for one hour after market close (to be used by strategies, for in sample optimization) Index: IndexBasedHistoricalTimer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/IndexBasedHistoricalTimer.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IndexBasedHistoricalTimer.cs 18 Nov 2008 23:00:33 -0000 1.3 --- IndexBasedHistoricalTimer.cs 20 Nov 2008 20:46:55 -0000 1.4 *************** *** 34,37 **** --- 34,38 ---- /// index is quoted at those DateTime(s) /// </summary> + [Serializable] public class IndexBasedHistoricalTimer : Timer { *************** *** 62,65 **** --- 63,128 ---- #region initialize_dateTimesToBeThrown + + #region addDateTimeAndIfTheCaseAddEndOfDayDateTime + + #region addOneHourAfterMarketCloseDateTimeIfTheCase + + #region isOneHourAfterMarktetCloseToBeInserted + private bool isOneHourAfterMarktetCloseToBeInserted_withOneAdded( + DateTime nextDateTimeToBeAdded ) + { + Date dateForLastDateTimeAdded = + new Date( this.dateTimesToBeThrown[ this.dateTimesToBeThrown.Count - 1 ] ); + Date dateForNextDateTimeToBeAdded = + new Date( nextDateTimeToBeAdded ); + bool isToBeInserted = ( dateForNextDateTimeToBeAdded > dateForLastDateTimeAdded ); + return isToBeInserted; + } + private bool isOneHourAfterMarktetCloseToBeInserted( DateTime nextDateTimeToBeAdded ) + { + bool isToBeInserted = false; + if ( this.dateTimesToBeThrown.Count > 0 ) + // at least one DateTime has already been added + isToBeInserted = isOneHourAfterMarktetCloseToBeInserted_withOneAdded( + nextDateTimeToBeAdded ); + return isToBeInserted; + } + #endregion isOneHourAfterMarktetCloseToBeInserted + + #region addOneHourAfterMarketCloseDateTime + private DateTime getOneHourAfterMarketCloseForLastDateTimeAdded() + { + DateTime dateTimeForLastDateTimeAdded = + this.dateTimesToBeThrown[ this.dateTimesToBeThrown.Count - 1 ]; + DateTime oneHourAfterMarketCloseForLastDateTimeAdded = + HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( + dateTimeForLastDateTimeAdded ); + return oneHourAfterMarketCloseForLastDateTimeAdded; + } + private void addOneHourAfterMarketCloseDateTime( DateTime dateTime ) + { + DateTime oneHourAfterMarketCloseForLastDateTimeAdded = + this.getOneHourAfterMarketCloseForLastDateTimeAdded(); + this.dateTimesToBeThrown.Add( + oneHourAfterMarketCloseForLastDateTimeAdded ); + } + #endregion addOneHourAfterMarketCloseDateTime + + private void addOneHourAfterMarketCloseDateTimeIfTheCase( + DateTime nextDateTimeToBeAdded ) + { + if ( this.isOneHourAfterMarktetCloseToBeInserted( nextDateTimeToBeAdded ) ) + this.addOneHourAfterMarketCloseDateTime( nextDateTimeToBeAdded ); + } + #endregion addOneHourAfterMarketCloseDateTimeIfTheCase + + private void addDateTimeAndIfTheCaseAddOneHourAfterMarketCloseDateTime( + DateTime nextDateTimeToBeAdded ) + { + this.addOneHourAfterMarketCloseDateTimeIfTheCase( nextDateTimeToBeAdded ); + this.dateTimesToBeThrown.Add( nextDateTimeToBeAdded ); + } + #endregion addDateTimeAndIfTheCaseAddEndOfDayDateTime + private void initialize_dateTimesToBeThrown( History dateTimesToBeThrownHistory ) *************** *** 67,71 **** this.dateTimesToBeThrown = new List< DateTime >(); foreach ( DateTime dateTime in dateTimesToBeThrownHistory.Keys ) ! this.dateTimesToBeThrown.Add( dateTime ); } private void initialize_dateTimesToBeThrown() --- 130,134 ---- this.dateTimesToBeThrown = new List< DateTime >(); foreach ( DateTime dateTime in dateTimesToBeThrownHistory.Keys ) ! this.addDateTimeAndIfTheCaseAddOneHourAfterMarketCloseDateTime( dateTime ); } private void initialize_dateTimesToBeThrown() *************** *** 90,109 **** private void checkIfNoMoreDateTimesAreToBeThrown() { ! if ( this.currentDateTimeIndex >= this.dateTimesToBeThrown.Count ) throw new Exception( "This timer has no other DateTime(s) to be thrown out. " + "This should never happen, the backtest should have invoked the method " + ! "QuantProject.Business.Timing.Timer.Stop() before gettint to this " + "point." ); ! } ! private void moveNext_actually() { ! this.currentDateTimeIndex++; ! this.currentDateTime = this.dateTimesToBeThrown[ currentDateTimeIndex ]; } protected override void moveNext() { ! this.checkIfNoMoreDateTimesAreToBeThrown(); ! this.moveNext_actually(); } #endregion moveNext --- 153,182 ---- private void checkIfNoMoreDateTimesAreToBeThrown() { ! if ( this.currentDateTimeIndex >= this.dateTimesToBeThrown.Count - 1 ) throw new Exception( "This timer has no other DateTime(s) to be thrown out. " + "This should never happen, the backtest should have invoked the method " + ! "QuantProject.Business.Timing.Timer.Stop() before getting to this " + "point." ); ! } ! ! protected override bool isDone() { ! bool isThisTimerDone = ! ( this.currentDateTimeIndex >= ( this.dateTimesToBeThrown.Count - 1 ) ); ! return isThisTimerDone; } + // + // private void moveNext_actually() + // { + // this.currentDateTimeIndex++; + // this.currentDateTime = this.dateTimesToBeThrown[ currentDateTimeIndex ]; + // this.setCompleteIfTheCase(); + // } + protected override void moveNext() { ! this.currentDateTimeIndex++; ! this.currentDateTime = this.dateTimesToBeThrown[ currentDateTimeIndex ]; } #endregion moveNext |