[Quantproject-developers] QuantProject/b3_Data/DataTables Quotes.cs, 1.27, 1.28
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:56:13
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv9859/b3_Data/DataTables Modified Files: Quotes.cs Log Message: - a new constructor public Quotes( string ticker , SortedList marketDays ) has been added. It builds a Quotes data table containing the ticker's quotes for the market days contained in the marketDays SortedList - the new public static method GetCommonMarketDays has been added (it returns the common market days for a given set of ticker, in a given date's interval) - the public static method GetFirstQuoteDate( string ticker ) has been added Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Quotes.cs 2 Jul 2006 19:07:26 -0000 1.27 --- Quotes.cs 22 Jul 2006 20:56:09 -0000 1.28 *************** *** 44,53 **** this.fillDataTable( ticker , startDate , endDate ); } public Quotes( string ticker ) { this.fillDataTable( ticker , ! QuantProject.DataAccess.Tables.Quotes.GetStartDate( ticker ) , ! QuantProject.DataAccess.Tables.Quotes.GetEndDate( ticker ) ); } public Quotes(SerializationInfo info, StreamingContext context) --- 44,75 ---- this.fillDataTable( ticker , startDate , endDate ); } + + /// <summary> + /// builds a Quotes data table containing the ticker's quotes for the + /// market days contained in the marketDays SortedList + /// </summary> + /// <param name="ticker"></param> + /// <param name="marketDays"></param> + public Quotes( string ticker , SortedList marketDays ) + { + DateTime firstDate = (DateTime)marketDays.GetByIndex( 0 ); + DateTime lastDate = (DateTime)marketDays.GetByIndex( + marketDays.Count - 1 ); + this.fillDataTable( ticker , firstDate , lastDate ); + this.removeNonContainedDates( marketDays ); + } + private void removeNonContainedDates( SortedList marketDays ) + { + foreach( DataRow dataRow in this.Rows ) + if ( marketDays.ContainsKey( + (DateTime)dataRow[ Quotes.Date ] ) ) + this.Rows.Remove( dataRow ); + } public Quotes( string ticker ) { this.fillDataTable( ticker , ! QuantProject.DataAccess.Tables.Quotes.GetFirstQuoteDate( ticker ) , ! QuantProject.DataAccess.Tables.Quotes.GetLastQuoteDate( ticker ) ); } public Quotes(SerializationInfo info, StreamingContext context) *************** *** 626,638 **** /// <param name="lastDate">end interval</param> /// <returns></returns> ! public static DateTime[] GetMarketDays( string ticker , DateTime firstDate , DateTime lastDate ) { Quotes quotes = new Quotes( ticker , firstDate , lastDate ); ! DateTime[] marketDays = new DateTime[ quotes.Rows.Count ]; int i = 0; foreach ( DataRow dataRow in quotes.Rows ) { ! marketDays[ i ] = (DateTime)dataRow[ Quotes.Date ]; i++; } --- 648,662 ---- /// <param name="lastDate">end interval</param> /// <returns></returns> ! public static SortedList GetMarketDays( string ticker , DateTime firstDate , DateTime lastDate ) { Quotes quotes = new Quotes( ticker , firstDate , lastDate ); ! // DateTime[] marketDays = new DateTime[ quotes.Rows.Count ]; ! SortedList marketDays = new SortedList(); int i = 0; foreach ( DataRow dataRow in quotes.Rows ) { ! // marketDays[ i ] = (DateTime)dataRow[ Quotes.Date ]; ! marketDays.Add( (DateTime)dataRow[ Quotes.Date ] , (DateTime)dataRow[ Quotes.Date ] ); i++; } *************** *** 641,645 **** ! private History history; /// <summary> --- 665,720 ---- ! #region GetCommonMarketDays ! private static Hashtable getMarketDays( ICollection tickers , DateTime firstDate , ! DateTime lastDate ) ! { ! Hashtable marketDays = new Hashtable(); ! foreach ( string ticker in tickers ) ! if ( !marketDays.ContainsKey( ticker ) ) ! { ! SortedList marketDaysForSingleTicker = ! GetMarketDays( ticker , firstDate , lastDate ); ! marketDays.Add( ticker , marketDaysForSingleTicker ); ! } ! return marketDays; ! } ! private static bool isCommonDate( ICollection tickers , DateTime dateTime , ! Hashtable marketDays ) ! { ! bool itIsCommon = true; ! foreach ( string ticker in tickers ) ! itIsCommon = itIsCommon && ! ((SortedList)marketDays[ ticker ]).ContainsKey( dateTime ); ! return itIsCommon; ! } ! private static void getCommonMarketDays_ifTheCaseAdd( ICollection tickers , DateTime dateTime , ! Hashtable marketDays , AdvancedSortedList commonMarketDays ) ! { ! if ( isCommonDate( tickers , dateTime , marketDays ) ) ! commonMarketDays.Add( dateTime , dateTime ); ! } ! private static SortedList getCommonMarketDays( ICollection tickers , ! DateTime firstDate , DateTime lastDate , Hashtable marketDays ) ! { ! AdvancedSortedList commonMarketDays = new AdvancedSortedList(); ! DateTime currentDateTime = firstDate; ! while ( currentDateTime <= lastDate ) ! { ! getCommonMarketDays_ifTheCaseAdd( tickers , ! currentDateTime , marketDays , commonMarketDays ); ! currentDateTime = currentDateTime.AddDays( 1 ); ! } ! return commonMarketDays; ! } ! ! public static SortedList GetCommonMarketDays( ICollection tickers , ! DateTime firstDate , DateTime lastDate ) ! { ! Hashtable marketDays = getMarketDays( tickers , firstDate , lastDate ); ! return getCommonMarketDays( tickers , firstDate , lastDate , marketDays ); ! } ! ! #endregion ! private History history; /// <summary> *************** *** 861,864 **** --- 936,949 ---- } } + /// <summary> + /// returns the first quote date for the ticker + /// </summary> + /// <param name="ticker"></param> + /// <returns></returns> + public static DateTime GetFirstQuoteDate( string ticker ) + { + return QuantProject.DataAccess.Tables.Quotes.GetFirstQuoteDate( ticker ); + } + /// <summary> |