[Quantproject-developers] QuantProject/b4_Business/a07_DataProviders HistoricalAdjustedQuoteProvide
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:22:48
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19614/b4_Business/a07_DataProviders Modified Files: HistoricalAdjustedQuoteProvider.cs HistoricalEndOfDayDataStreamer.cs HistoricalRawQuoteProvider.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: HistoricalEndOfDayDataStreamer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders/HistoricalEndOfDayDataStreamer.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** HistoricalEndOfDayDataStreamer.cs 4 Feb 2005 00:10:25 -0000 1.5 --- HistoricalEndOfDayDataStreamer.cs 29 Sep 2008 21:22:23 -0000 1.6 *************** *** 26,29 **** --- 26,30 ---- using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; + using QuantProject.Data.DataProviders.Quotes; namespace QuantProject.Business.DataProviders *************** *** 37,47 **** private Hashtable tickers; ! private IEndOfDayTimer endOfDayTimer; ! private IHistoricalQuoteProvider historicalQuoteProvider; ! private EndOfDayDateTime startDateTime; ! private EndOfDayDateTime endDateTime; ! public EndOfDayDateTime StartDateTime { get { return this.startDateTime; } --- 38,48 ---- private Hashtable tickers; ! private Timer timer; ! private HistoricalMarketValueProvider historicalMarketValueProvider; ! private DateTime startDateTime; ! private DateTime endDateTime; ! public DateTime StartDateTime { get { return this.startDateTime; } *************** *** 49,53 **** } ! public EndOfDayDateTime EndDateTime { get { return this.endDateTime; } --- 50,54 ---- } ! public DateTime EndDateTime { get { return this.endDateTime; } *************** *** 55,68 **** } ! public HistoricalEndOfDayDataStreamer( IEndOfDayTimer endOfDayTimer , ! IHistoricalQuoteProvider historicalQuoteProvider ) { ! this.endOfDayTimer = endOfDayTimer; ! this.historicalQuoteProvider = historicalQuoteProvider; ! this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( ! this.marketOpenEventHandler ); this.tickers = new Hashtable(); } /// <summary> /// Returns the current bid for the given ticker --- 56,117 ---- } ! public HistoricalEndOfDayDataStreamer( ! Timer timer , ! HistoricalMarketValueProvider historicalMarketValueProvider ) { ! this.timer = timer; ! this.historicalMarketValueProvider = historicalMarketValueProvider; ! this.timer.NewDateTime += ! new NewDateTimeEventHandler( ! this.newTimeEventHandler ); this.tickers = new Hashtable(); } + #region newTimeEventHandler + private void riseNewQuotesIfTheCase( + DateTime dateTime , MarketStatusSwitch marketStatusSwitch ) + { + if ( this.tickers.Count > 0 ) + { + // the data streamer is monitoring some ticker + Hashtable quotes = + HistoricalQuotesProvider.GetAdjustedQuotes( + this.tickers , dateTime , marketStatusSwitch ); + foreach ( Quote quote in quotes ) + this.NewQuote( this , new NewQuoteEventArgs( quote ) ); + } + } + private void newTimeEventHandler( + Object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + this.riseNewQuotesIfTheCase( dateTime , MarketStatusSwitch.Open ); + if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + this.riseNewQuotesIfTheCase( dateTime , MarketStatusSwitch.Close ); + } + #endregion newTimeEventHandler + + #region GetCurrentBid + private void getCurrentBid_checkValidTime() + { + DateTime currentDateTime = this.timer.GetCurrentDateTime(); + if ( !HistoricalEndOfDayTimer.IsMarketStatusSwitch( currentDateTime ) ) + throw new Exception( + "With this data streamer, GetCurrentBid can be invoked only " + + "if the current time is either on market open or on market " + + "close." ); + } + + #region getCurrentBid_actually + private double getCurrentBid_actually( string ticker ) + { + double currentBid = + this.historicalMarketValueProvider.GetMarketValue( + ticker , + this.timer.GetCurrentDateTime() ); + return currentBid; + } + #endregion getCurrentBid_actually + /// <summary> /// Returns the current bid for the given ticker *************** *** 72,78 **** public double GetCurrentBid( string ticker ) { ! return historicalQuoteProvider.GetMarketValue( ticker , ! this.endOfDayTimer.GetCurrentTime() ); } /// <summary> --- 121,130 ---- public double GetCurrentBid( string ticker ) { ! this.getCurrentBid_checkValidTime(); ! double currentBid = ! this.getCurrentBid_actually( ticker ); ! return currentBid; } + #endregion GetCurrentBid /// <summary> *************** *** 83,88 **** public double GetCurrentAsk( string ticker ) { ! return historicalQuoteProvider.GetMarketValue( ticker , ! this.endOfDayTimer.GetCurrentTime() ); } --- 135,139 ---- public double GetCurrentAsk( string ticker ) { ! return this.GetCurrentBid( ticker ); } *************** *** 94,99 **** public bool IsExchanged( string ticker ) { ! return HistoricalDataProvider.WasExchanged( ticker , ! this.endOfDayTimer.GetCurrentTime().GetNearestExtendedDateTime() ); } /// <summary> --- 145,150 ---- public bool IsExchanged( string ticker ) { ! return HistoricalQuotesProvider.WasExchanged( ! ticker , this.timer.GetCurrentDateTime() ); } /// <summary> *************** *** 119,136 **** // timer.Start(); // } - - private void marketOpenEventHandler( - Object sender , EndOfDayTimingEventArgs eventArgs ) - { - if ( this.tickers.Count > 0 ) - { - // the data streamer is monitoring some ticker - Hashtable quotes = - HistoricalDataProvider.GetQuotes( this.tickers , - this.endOfDayTimer.GetCurrentTime().GetNearestExtendedDateTime() ); - foreach ( Quote quote in quotes ) - this.NewQuote( this , new NewQuoteEventArgs( quote ) ); - } - } } } --- 170,173 ---- Index: HistoricalRawQuoteProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders/HistoricalRawQuoteProvider.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** HistoricalRawQuoteProvider.cs 10 Feb 2008 14:28:09 -0000 1.5 --- HistoricalRawQuoteProvider.cs 29 Sep 2008 21:22:23 -0000 1.6 *************** *** 3,7 **** HistoricalRawQuoteProvider.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- HistoricalRawQuoteProvider.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,28 **** 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 QuantProject.Business.Timing; ! using QuantProject.Data.DataProviders; namespace QuantProject.Business.DataProviders --- 19,29 ---- 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 QuantProject.ADT; using QuantProject.Business.Timing; ! using QuantProject.Data.DataProviders.Quotes; namespace QuantProject.Business.DataProviders *************** *** 32,45 **** /// </summary> [Serializable] ! public class HistoricalRawQuoteProvider : HistoricalQuoteProvider { public HistoricalRawQuoteProvider() { } ! public override double GetMarketValue( string instrumentKey , ! EndOfDayDateTime endOfDayDateTime ) { ! return HistoricalDataProvider.GetRawMarketValue( instrumentKey , ! endOfDayDateTime.GetNearestExtendedDateTime() ); } --- 33,52 ---- /// </summary> [Serializable] ! public class HistoricalRawQuoteProvider : HistoricalMarketValueProvider { public HistoricalRawQuoteProvider() { } ! public override double GetMarketValue( ! string instrumentKey , ! DateTime dateTime ) { ! MarketStatusSwitch marketStatusSwitch = ! HistoricalAdjustedQuoteProvider.GetMarketStatusSwitch( dateTime ); // TO DO move this method to an abstract class BasicQuotesProvider to be inherited both by HistoricalAdjustedQuoteProvider and by HistoricalRawQuoteProvider ! double marketValue = HistoricalQuotesProvider.GetRawMarketValue( ! instrumentKey , ! ExtendedDateTime.GetDate( dateTime ) , ! marketStatusSwitch ); ! return marketValue; } Index: HistoricalAdjustedQuoteProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders/HistoricalAdjustedQuoteProvider.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** HistoricalAdjustedQuoteProvider.cs 10 Feb 2008 14:28:09 -0000 1.6 --- HistoricalAdjustedQuoteProvider.cs 29 Sep 2008 21:22:23 -0000 1.7 *************** *** 3,7 **** HistoricalAdjustedQuoteProvider.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- HistoricalAdjustedQuoteProvider.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,28 **** 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 QuantProject.Business.Timing; ! using QuantProject.Data.DataProviders; namespace QuantProject.Business.DataProviders --- 19,29 ---- 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 QuantProject.ADT; using QuantProject.Business.Timing; ! using QuantProject.Data.DataProviders.Quotes; namespace QuantProject.Business.DataProviders *************** *** 32,49 **** /// </summary> [Serializable] ! public class HistoricalAdjustedQuoteProvider : HistoricalQuoteProvider { public HistoricalAdjustedQuoteProvider() { } ! public override double GetMarketValue( string instrumentKey , ! EndOfDayDateTime endOfDayDateTime ) { ! double marketValue = ! HistoricalDataProvider.GetAdjustedMarketValue( instrumentKey , ! endOfDayDateTime.GetNearestExtendedDateTime() ); return marketValue; } protected override string getDescription() { --- 33,97 ---- /// </summary> [Serializable] ! public class HistoricalAdjustedQuoteProvider : HistoricalMarketValueProvider { public HistoricalAdjustedQuoteProvider() { } ! ! // TO DO move GetMarketStatusSwitch to an abstract class ! // BasicQuotesProvider to be inherited both by HistoricalAdjustedQuoteProvider ! // and by HistoricalRawQuoteProvider ! #region GetMarketStatusSwitch ! private static void riseExceptionIfNotAtMarketSwitch( DateTime dateTime ) { ! if ( !HistoricalEndOfDayTimer.IsMarketStatusSwitch( dateTime ) ) ! throw new Exception( ! "when GetCurrentMarketStatusSwitch() is invoked, dateTime " + ! "is expected to either be a market open or a market close." ); ! } ! /// <summary> ! /// Returns the market status switch that corresponds to dateTime ! /// </summary> ! /// <param name="dateTime">it has to be either a market open or a ! /// market close</param> ! /// <returns></returns> ! public static MarketStatusSwitch GetMarketStatusSwitch( ! DateTime dateTime ) ! { ! HistoricalAdjustedQuoteProvider.riseExceptionIfNotAtMarketSwitch( dateTime ); ! MarketStatusSwitch marketStatusSwitch = ! MarketStatusSwitch.Open; ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! marketStatusSwitch = MarketStatusSwitch.Close; ! return marketStatusSwitch; ! } ! #endregion GetMarketStatusSwitch ! ! // public override double GetMarketValue( ! // string instrumentKey , ! // DateTime date , ! // MarketStatusSwitch marketStatusSwitch ) ! // { ! // double marketValue = ! // HistoricalQuotesProvider.GetAdjustedMarketValue( ! // instrumentKey , date , marketStatusSwitch ); ! // return marketValue; ! // } ! ! public override double GetMarketValue( ! string instrumentKey , ! DateTime dateTime ) ! { ! MarketStatusSwitch marketStatusSwitch = ! HistoricalAdjustedQuoteProvider.GetMarketStatusSwitch( dateTime ); ! double marketValue = ! HistoricalQuotesProvider.GetAdjustedMarketValue( ! instrumentKey , ! ExtendedDateTime.GetDate( dateTime ) , ! marketStatusSwitch ); return marketValue; } + protected override string getDescription() { |