[Quantproject-developers] QuantProject/b4_Business/a05_Timing HistoricalEndOfDayTimer.cs,1.4,1.5 Ind
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-01-15 10:54:34
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23847/b4_Business/a05_Timing Modified Files: HistoricalEndOfDayTimer.cs IndexBasedEndOfDayTimer.cs Log Message: Reorganized the classes, in order to avoid code duplication (the virtual method Start() has been divided into sub-methods) Index: HistoricalEndOfDayTimer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/HistoricalEndOfDayTimer.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HistoricalEndOfDayTimer.cs 8 Jan 2005 11:38:53 -0000 1.4 --- HistoricalEndOfDayTimer.cs 15 Jan 2005 10:54:14 -0000 1.5 *************** *** 53,60 **** // } ! public virtual event MarketOpenEventHandler MarketOpen; ! public virtual event FiveMinutesBeforeMarketCloseEventHandler FiveMinutesBeforeMarketClose; ! public virtual event MarketCloseEventHandler MarketClose; ! public virtual event OneHourAfterMarketCloseEventHandler OneHourAfterMarketClose; public HistoricalEndOfDayTimer( EndOfDayDateTime startDateTime ) --- 53,60 ---- // } ! public event MarketOpenEventHandler MarketOpen; ! public event FiveMinutesBeforeMarketCloseEventHandler FiveMinutesBeforeMarketClose; ! public event MarketCloseEventHandler MarketClose; ! public event OneHourAfterMarketCloseEventHandler OneHourAfterMarketClose; public HistoricalEndOfDayTimer( EndOfDayDateTime startDateTime ) *************** *** 64,68 **** --- 64,94 ---- this.tickers = new Hashtable(); } + + protected void callEvents() + { + if ( ( this.MarketOpen != null ) && ( this.currentTime.EndOfDaySpecificTime == + EndOfDaySpecificTime.MarketOpen ) ) + this.MarketOpen( this , new EndOfDayTimingEventArgs( this.currentTime ) ); + if ( ( this.FiveMinutesBeforeMarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == + EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ) ) + this.FiveMinutesBeforeMarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); + if ( ( this.MarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == + EndOfDaySpecificTime.MarketClose ) ) + this.MarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); + if ( ( this.OneHourAfterMarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == + EndOfDaySpecificTime.OneHourAfterMarketClose ) ) + this.OneHourAfterMarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); + } + protected virtual void moveNext() + { + this.currentTime.MoveNext(); + } + + protected virtual void activeTimer() + { + this.isActive = true; + this.currentTime = this.startDateTime.Copy(); + } /// <summary> /// Starts the time walking simulation *************** *** 70,90 **** public virtual void Start() { ! this.isActive = true; ! this.currentTime = this.startDateTime.Copy(); while ( this.isActive ) { ! if ( ( this.MarketOpen != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.MarketOpen ) ) ! this.MarketOpen( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! if ( ( this.FiveMinutesBeforeMarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ) ) ! this.FiveMinutesBeforeMarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! if ( ( this.MarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.MarketClose ) ) ! this.MarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! if ( ( this.OneHourAfterMarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.OneHourAfterMarketClose ) ) ! this.OneHourAfterMarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! this.currentTime.MoveNext(); } } --- 96,104 ---- public virtual void Start() { ! this.activeTimer(); while ( this.isActive ) { ! this.callEvents(); ! this.moveNext(); } } Index: IndexBasedEndOfDayTimer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/IndexBasedEndOfDayTimer.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IndexBasedEndOfDayTimer.cs 8 Jan 2005 11:44:33 -0000 1.1 --- IndexBasedEndOfDayTimer.cs 15 Jan 2005 10:54:20 -0000 1.2 *************** *** 41,49 **** private Quotes indexQuotes; - public override event MarketOpenEventHandler MarketOpen; - public override event FiveMinutesBeforeMarketCloseEventHandler FiveMinutesBeforeMarketClose; - public override event MarketCloseEventHandler MarketClose; - public override event OneHourAfterMarketCloseEventHandler OneHourAfterMarketClose; - public IndexBasedEndOfDayTimer( EndOfDayDateTime startDateTime, string marketIndex): base(startDateTime) --- 41,44 ---- *************** *** 62,96 **** public override void Start() { ! this.isActive = true; ! this.currentTime = this.startDateTime.Copy(); while ( this.isActive ) { ! if ( ( this.MarketOpen != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.MarketOpen ) ) ! this.MarketOpen( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! if ( ( this.FiveMinutesBeforeMarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ) ) ! this.FiveMinutesBeforeMarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! if ( ( this.MarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.MarketClose ) ) ! this.MarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! if ( ( this.OneHourAfterMarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.OneHourAfterMarketClose ) ) ! this.OneHourAfterMarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! this.moveNext(this.currentTime); } } //move the current endOfDayDateTime to the next moment //at which the market is surely open ! private void moveNext( EndOfDayDateTime endOfDayDateTimeToMove) { ! EndOfDaySpecificTime nextSpecificTime = endOfDayDateTimeToMove.GetNextEndOfDaySpecificTime(); ! if ( nextSpecificTime < endOfDayDateTimeToMove.EndOfDaySpecificTime ) { // the current end of day specific time is the last end of day specific time in the day ! endOfDayDateTimeToMove.DateTime = ! this.indexQuotes.GetFollowingDate(endOfDayDateTimeToMove.DateTime, 1); } ! endOfDayDateTimeToMove.EndOfDaySpecificTime = nextSpecificTime; } --- 57,79 ---- public override void Start() { ! base.activeTimer(); while ( this.isActive ) { ! base.callEvents(); ! this.moveNext(); } } //move the current endOfDayDateTime to the next moment //at which the market is surely open ! protected override void moveNext() { ! EndOfDaySpecificTime nextSpecificTime = this.currentTime.GetNextEndOfDaySpecificTime(); ! if ( nextSpecificTime < this.currentTime.EndOfDaySpecificTime ) { // the current end of day specific time is the last end of day specific time in the day ! this.currentTime.DateTime = ! this.indexQuotes.GetFollowingDate(this.currentTime.DateTime, 1); } ! this.currentTime.EndOfDaySpecificTime = nextSpecificTime; } |