[Quantproject-developers] QuantProject/b3_Data/DataTables Quotes.cs,1.1,1.2 ValidatedTickers.cs,1.1,
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2004-05-26 15:30:21
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19524/b3_Data/DataTables Modified Files: Quotes.cs ValidatedTickers.cs Log Message: Many features have been moved from the DataAccess.Tables namespace to the Data.DataTables namespace Index: ValidatedTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/ValidatedTickers.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ValidatedTickers.cs 8 May 2004 17:57:12 -0000 1.1 --- ValidatedTickers.cs 26 May 2004 15:30:10 -0000 1.2 *************** *** 20,23 **** --- 20,37 ---- QuantProject.DataAccess.Tables.ValidatedTickers.SetDataTable( ticker , this ); } + /// <summary> + /// Validates the ticker contained in the quotes DataTable + /// </summary> + /// <param name="quotes">Contains the quotes for the ticker to be validated</param> + public static void Validate( QuantProject.Data.DataTables.Quotes quotes ) + { + DateTime startDate = (DateTime)quotes.Rows[ 0 ][ QuantProject.Data.DataTables.Quotes.Date ]; + DateTime endDate = (DateTime)quotes.Rows[ quotes.Rows.Count - 1 ][ + QuantProject.Data.DataTables.Quotes.Date ]; + string ticker = quotes.Ticker; + string hashValue = quotes.GetHashValue(); + QuantProject.DataAccess.Tables.ValidatedTickers.Validate( + ticker , startDate , endDate , hashValue ); + } } } Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Quotes.cs 8 May 2004 17:56:17 -0000 1.1 --- Quotes.cs 26 May 2004 15:30:10 -0000 1.2 *************** *** 1,4 **** --- 1,8 ---- using System; using System.Data; + using System.Text; + using QuantProject.ADT; + using QuantProject.ADT.Histories; + using QuantProject.DataAccess; using QuantProject.DataAccess.Tables; *************** *** 10,13 **** --- 14,37 ---- public class Quotes : DataTable { + public static string TickerFieldName = "quTicker"; // Ticker cannot be simply used because + // it is already used below + public static string Date = "quDate"; + public static string Open = "quOpen"; + public static string High = "quHigh"; + public static string Low = "quLow"; + public static string Close = "quClose"; + public static string Volume = "quVolume"; + public static string AdjustedClose = "quAdjustedClose"; + public static string AdjustedCloseToCloseRatio = "quAdjustedCloseToCloseRatio"; + + /// <summary> + /// Gets the ticker whose quotes are contained into the Quotes object + /// </summary> + /// <returns></returns> + public string Ticker + { + get{ return ((string)this.Rows[ 0 ][ Quotes.TickerFieldName ]); } + } + private void fillDataTable( string ticker , DateTime startDate , DateTime endDate ) { *************** *** 26,29 **** --- 50,165 ---- QuantProject.DataAccess.Tables.Quotes.GetEndDate( ticker ) ); } + #region GetHashValue + private string getHashValue_getQuoteString_getRowString_getSingleValueString( Object value ) + { + string returnValue; + if ( value.GetType() == Type.GetType( "System.DateTime" ) ) + returnValue = ( (DateTime) value ).ToString(); + else + { + if ( value.GetType() == Type.GetType( "System.Double" ) ) + returnValue = ( (float) value ).ToString( "F2" ); + else + returnValue = value.ToString(); + } + + return returnValue + ";"; + } + /// <summary> + /// Computes the string representing the concatenation for a single quote row + /// </summary> + /// <param name="dataRow"></param> + /// <returns></returns> + private StringBuilder getHashValue_getQuoteString_getRowString( DataRowView dataRow ) + { + StringBuilder returnValue = new StringBuilder( "" ); + foreach ( DataColumn dataColumn in dataRow.DataView.Table.Columns ) + if ( dataColumn.ColumnName != "quTicker" ) + returnValue.Append( getHashValue_getQuoteString_getRowString_getSingleValueString( + dataRow[ dataColumn.Ordinal ] ) ); + // returnValue += "ggg"; + // returnValue += getHashValue_getQuoteString_getRowString_getSingleValueString( + // dataRow[ dataColumn ] ); + return returnValue; + } + /// <summary> + /// Computes the string representing the concatenation of all the quotes + /// </summary> + /// <param name="ticker"></param> + /// <returns></returns> + private string getHashValue_getQuoteString( DataView quotes ) + { + StringBuilder returnValue = new StringBuilder( "" ); + foreach ( DataRowView dataRow in quotes ) + returnValue.Append( getHashValue_getQuoteString_getRowString( dataRow ) ); + return returnValue.ToString(); + } + /// <summary> + /// Computes the hash value for the contained quotes + /// </summary> + /// <returns>Hash value for all the quotes</returns> + public string GetHashValue() + { + DataView quotes = new DataView( this ); + return HashProvider.GetHashValue( getHashValue_getQuoteString( quotes ) ); + } + /// <summary> + /// Computes the hash value for the contained quotes + /// since startDate, to endDate + /// </summary> + /// <param name="startDate">date where hash begins being computed</param> + /// <param name="endDate">date where hash ends being computed</param> + /// <returns></returns> + public string GetHashValue( DateTime startDate , DateTime endDate ) + { + DataView quotes = new DataView( this ); + quotes.RowFilter = "( (quDate>=" + FilterBuilder.GetDateConstant( startDate ) + + ") and (quDate<=" + FilterBuilder.GetDateConstant( endDate ) + ") )"; + return HashProvider.GetHashValue( getHashValue_getQuoteString( quotes ) ); + } + #endregion + + /// <summary> + /// returns the Date for the quote that is precedingDays before + /// quoteDate + /// </summary> + /// <param name="quoteDate"></param> + /// <param name="precedingDays"></param> + /// <returns></returns> + public DateTime GetPrecedingDate( DateTime quoteDate , int precedingDays ) + { + History history = new History(); + history.Import( this , "quDate" , "quAdjustedClose" ); + return (DateTime) history.GetKey( Math.Max( 0 , + history.IndexOfKeyOrPrevious( quoteDate ) - + precedingDays ) ); + } + + + /// <summary> + /// returns the Date for the quote that is followingDays after + /// quoteDate + /// </summary> + /// <param name="quoteDate"></param> + /// <param name="precedingDays"></param> + /// <returns></returns> + public DateTime GetFollowingDate( DateTime quoteDate , int followingDays ) + { + History history = new History(); + history.Import( this , "quDate" , "quAdjustedClose" ); + return (DateTime) history.GetKey( Math.Max( 0 , + history.IndexOfKeyOrPrevious( quoteDate ) - + followingDays ) ); + } + + + // public DateTime GetPrecedingDate( DateTime quoteDate , int precedingDays ) + // { + // History history = new History(); + // history.Import( this.quotes , "quDate" , "quAdjustedClose" ); + // return (DateTime) history.GetKey( Math.Max( 0 , + // history.IndexOfKeyOrPrevious( quoteDate ) - + // precedingDays ) ); + // } } } |