[Quantproject-developers] QuantProject/b2_DataAccess/Tables Quotes.cs,1.1,1.2
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2004-03-28 20:07:16
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24079/b2_DataAccess/Tables Modified Files: Quotes.cs Log Message: - now the constructor populates a private DataTable with quotes for a single ticker - most static methods have been changed to instance methods - added the Ticker read only property - the GetHashValue (non static now) has been changed to work on the private DataTable, rather than on the DataBase quotes (the reason is that the user is meant to validate the values it actully looks at, and to avoid to validate DataBase quotes that may have changed in the meanwhile) - GetHasValue has been overloaded to get the has value for a specific date range - added the GetPrecedingDate to return the date that comes a specific number of days before the argument date - added the GetFollowingDate to return the date that comes a specific number of days after the argument date Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Quotes.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Quotes.cs 18 Mar 2004 22:37:22 -0000 1.1 --- Quotes.cs 28 Mar 2004 19:55:54 -0000 1.2 *************** *** 3,6 **** --- 3,7 ---- using System.Text; using QuantProject.ADT; + using QuantProject.ADT.Histories; namespace QuantProject.DataAccess.Tables *************** *** 11,19 **** public class Quotes { ! public Quotes() { ! // ! // TODO: Add constructor logic here ! // } /// <summary> --- 12,29 ---- public class Quotes { ! private DataTable quotes; ! ! /// <summary> ! /// Gets the ticker whose quotes are contained into the Quotes object ! /// </summary> ! /// <returns></returns> ! public string Ticker { ! get{ return ((string)this.quotes.Rows[ 0 ][ "quTicker" ]); } ! } ! ! public Quotes( string ticker) ! { ! this.quotes = Quotes.GetTickerQuotes( ticker ); } /// <summary> *************** *** 40,44 **** } #region GetHashValue ! private static string getHashValue_getQuoteString_getRowString_getSingleValueString( Object value ) { string returnValue; --- 50,54 ---- } #region GetHashValue ! private string getHashValue_getQuoteString_getRowString_getSingleValueString( Object value ) { string returnValue; *************** *** 60,73 **** /// <param name="dataRow"></param> /// <returns></returns> ! private static StringBuilder getHashValue_getQuoteString_getRowString( DataRow dataRow ) { StringBuilder returnValue = new StringBuilder( "" ); ! foreach ( DataColumn dataColumn in dataRow.Table.Columns ) if ( dataColumn.ColumnName != "quTicker" ) returnValue.Append( getHashValue_getQuoteString_getRowString_getSingleValueString( ! dataRow[ dataColumn ] ) ); // returnValue += "ggg"; ! // returnValue += getHashValue_getQuoteString_getRowString_getSingleValueString( ! // dataRow[ dataColumn ] ); return returnValue; } --- 70,83 ---- /// <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; } *************** *** 77,99 **** /// <param name="ticker"></param> /// <returns></returns> ! private static string getHashValue_getQuoteString( string ticker ) { StringBuilder returnValue = new StringBuilder( "" ); ! DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from quotes where quTicker='" + ticker + "'" ); ! foreach ( DataRow dataRow in dataTable.Rows ) returnValue.Append( getHashValue_getQuoteString_getRowString( dataRow ) ); return returnValue.ToString(); } /// <summary> /// Computes the hash value for the quotes for the given ticker /// </summary> /// <param name="ticker">Ticker whose quotes must be hashed</param> /// <returns>Hash value for all the quotes for the given ticker</returns> ! public static string GetHashValue( string ticker ) { ! return HashProvider.GetHashValue( getHashValue_getQuoteString( ticker ) ); } - #endregion } } --- 87,175 ---- /// <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.quotes ); + 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 ); + quotes.RowFilter = "( (quDate>=" + SQLBuilder.GetDateConstant( startDate ) + + ") and (quDate<=" + SQLBuilder.GetDateConstant( endDate ) + ") )"; + return HashProvider.GetHashValue( getHashValue_getQuoteString( quotes ) ); + } + #endregion + + /// <summary> /// Computes the hash value for the quotes for the given ticker /// </summary> /// <param name="ticker">Ticker whose quotes must be hashed</param> /// <returns>Hash value for all the quotes for the given ticker</returns> ! // public static string GetHashValue( string ticker ) ! // { ! // return HashProvider.GetHashValue( GetHashValue( GetTickerQuotes( ticker ) ) ); ! // } ! ! /// <summary> ! /// returns the quotes DataTable for the given ticker ! /// </summary> ! /// <param name="instrumentKey">ticker whose quotes are to be returned</param> ! /// <returns></returns> ! public static DataTable GetTickerQuotes( string instrumentKey ) { ! string sql = "select * from quotes where quTicker='" + instrumentKey + "' " + ! "order by quDate"; ! return SqlExecutor.GetDataTable( sql ); ! } ! ! /// <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.quotes , "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.quotes , "quDate" , "quAdjustedClose" ); ! return (DateTime) history.GetKey( Math.Max( 0 , ! history.IndexOfKeyOrPrevious( quoteDate ) - ! followingDays ) ); } } } |