[Quantproject-developers] QuantProject/b4_Business/a05_Timing IndexBasedEndOfDayTimer.cs, 1.9, 1.10
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:23:06
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19753/b4_Business/a05_Timing Modified Files: IndexBasedEndOfDayTimer.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: IndexBasedEndOfDayTimer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/IndexBasedEndOfDayTimer.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** IndexBasedEndOfDayTimer.cs 14 Jan 2008 23:21:03 -0000 1.9 --- IndexBasedEndOfDayTimer.cs 29 Sep 2008 21:22:45 -0000 1.10 *************** *** 3,7 **** IndexBasedEndOfDayTimer.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- IndexBasedEndOfDayTimer.cs ! Copyright (C) 2003 Marco Milletti *************** *** 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; using System.Collections; --- 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; using System.Collections; *************** *** 30,35 **** { /// <summary> ! /// IEndOfDayTimer implementation using a market index as the base ! /// for time walking simulation /// </summary> [Serializable] --- 30,36 ---- { /// <summary> ! /// ITimer implementation using a market index as the base ! /// for time walking simulation; end of day timing events are risen ! /// only for those days when the index is traded /// </summary> [Serializable] *************** *** 37,132 **** { private string marketIndex; ! public string MarketIndex ! { ! get { return this.marketIndex; } ! } ! ! private Quotes indexQuotes; ! public Quotes IndexQuotes ! { ! get { return this.indexQuotes; } ! } ! private int currentDateArrayPosition; ! public int CurrentDateArrayPosition ! { ! get { return this.currentDateArrayPosition ; } ! } ! private void indexBasedEndOfDayTimer( EndOfDayDateTime startDateTime, ! string marketIndex) ! { ! this.marketIndex = marketIndex; ! if ( this.indexQuotes.Rows.Count == 0 ) ! { ! string errorMessage = "IndexBasedEndOfDayTimer error: the given " + ! "index (" + marketIndex + ") has no quotes in the interval."; ! throw new Exception( errorMessage ); ! } ! this.StartDateTime = ! new EndOfDayDateTime(this.indexQuotes.GetQuoteDateOrFollowing(this.StartDateTime.DateTime), ! EndOfDaySpecificTime.MarketOpen); ! this.tickers = new Hashtable(); ! this.currentDateArrayPosition = 0; ! } ! public IndexBasedEndOfDayTimer( EndOfDayDateTime startDateTime, ! string marketIndex): base(startDateTime) { ! this.indexQuotes = new Quotes(marketIndex,startDateTime.DateTime,DateTime.Now); ! this.indexBasedEndOfDayTimer(startDateTime, marketIndex); } - - public IndexBasedEndOfDayTimer( EndOfDayDateTime startDateTime, - EndOfDayDateTime endDateTime, - string marketIndex): base(startDateTime) - { - this.indexQuotes = new Quotes(marketIndex,startDateTime.DateTime,endDateTime.DateTime.AddDays(10)); - this.indexBasedEndOfDayTimer(startDateTime, marketIndex); - } ! /// <summary> ! /// Starts the time walking simulation, based on index's dates ! /// </summary> ! 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.currentDateArrayPosition++; - } - this.currentTime.EndOfDaySpecificTime = nextSpecificTime; - - } - /// <summary> - /// Gets the previous index based date time - /// </summary> - public DateTime GetPreviousDateTime() - { - return this.indexQuotes.GetPrecedingDate(this.currentTime.DateTime,1); - } - /// <summary> - /// Gets the date time that is 'precedingDays' days before - /// the current date time of the current timer - /// </summary> - public DateTime GetPreviousDateTime(int precedingDays) - { - return this.indexQuotes.GetPrecedingDate( - this.currentTime.DateTime,precedingDays); - } } --- 38,173 ---- { private string marketIndex; ! public string MarketIndex ! { ! get { return this.marketIndex; } ! } ! private Quotes indexQuotes; ! public Quotes IndexQuotes ! { ! get { return this.indexQuotes; } ! } ! ! private int currentDateArrayPosition; ! public int CurrentDateArrayPosition ! { ! get { return this.currentDateArrayPosition ; } ! } ! ! #region commonInitialization ! private void indexBasedEndOfDayTimer( ! DateTime startDateTime, string marketIndex) ! { ! this.marketIndex = marketIndex; ! if ( this.indexQuotes.Rows.Count == 0 ) ! { ! string errorMessage = "IndexBasedEndOfDayTimer error: the given " + ! "index (" + marketIndex + ") has no quotes in the interval."; ! throw new Exception( errorMessage ); ! } ! this.StartDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( startDateTime ); ! this.tickers = new Hashtable(); ! this.currentDateArrayPosition = 0; ! } ! private void commonInitialization( ! string marketIndex , ! DateTime startDateTime , ! DateTime endDateTime ) ! { ! DateTime startDate = ! ExtendedDateTime.GetDate( startDateTime ); ! this.indexQuotes = new Quotes(marketIndex,startDate,DateTime.Now); ! this.indexBasedEndOfDayTimer(startDateTime, marketIndex); ! } ! #endregion commonInitialization ! public IndexBasedEndOfDayTimer( ! DateTime startDateTime, ! string marketIndex): base(startDateTime) { ! this.commonInitialization( marketIndex,startDateTime,DateTime.Now ); } ! public IndexBasedEndOfDayTimer( ! DateTime startDateTime, ! DateTime endDateTime, ! string marketIndex): base(startDateTime) { ! this.commonInitialization( marketIndex,startDateTime,endDateTime.AddDays(10) ); ! } ! ! // /// <summary> ! // /// Starts the time walking simulation, based on index's dates ! // /// </summary> ! // public override void Start() ! // { ! // base.activateTimer(); ! // while ( this.isActive ) ! // { ! // base.callEvents(); ! // this.moveNext(); ! // } ! // } ! ! #region moveNext ! private void moveNext_with_currentDateTime_properlyInitialized() ! { ! if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( ! this.currentDateTime ) ) { ! // current time is the last end of day event for the day ! DateTime followingDateForIndex = ! this.indexQuotes.GetFollowingDate(this.currentDateTime, 1); ! this.currentDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( followingDateForIndex ); ! this.currentDateArrayPosition++; } + else + // current time is the last end of day event for the day + base.moveNext(); + + // this.currentDateTime = + // HistoricalEndOfDayTimer.ge + // 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.currentDateArrayPosition++; + // } + // this.currentTime.EndOfDaySpecificTime = nextSpecificTime; + } + //move the current endOfDayDateTime to the next moment + //at which the market is surely open + protected override void moveNext() + { + DateTime dateTimeForTheFirstStep = + HistoricalEndOfDayTimer.GetMarketOpen( + this.indexQuotes.StartDate ); + if ( this.currentDateTime < dateTimeForTheFirstStep ) + this.currentDateTime = dateTimeForTheFirstStep; + this.moveNext_with_currentDateTime_properlyInitialized(); + } + #endregion moveNext + + /// <summary> + /// Gets the previous index based date time + /// </summary> + public DateTime GetPreviousDateTime() + { + return this.indexQuotes.GetPrecedingDate(this.currentDateTime,1); + } + /// <summary> + /// Gets the date time that is 'precedingDays' days before + /// the current date time of the current timer + /// </summary> + public DateTime GetPreviousDateTime(int precedingDays) + { + return this.indexQuotes.GetPrecedingDate( + this.currentDateTime,precedingDays); } } |