[Quantproject-developers] QuantProject/b2_DataAccess DataBase.cs, 1.9, 1.10
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:29:14
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv19134/b2_DataAccess Modified Files: DataBase.cs Log Message: the following method has been added public static History GetBarOpenHistory( string ticker , int barInterval , DateTime firstDateTime , DateTime lastDateTime , DateTime[] dailyTimes ) Index: DataBase.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/DataBase.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** DataBase.cs 29 Sep 2008 21:12:37 -0000 1.9 --- DataBase.cs 8 Nov 2008 20:29:09 -0000 1.10 *************** *** 3,7 **** DataBase.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- DataBase.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 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; --- 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; *************** *** 83,89 **** } ! #region "GetHistory" private static History getHistory_try( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { History history = new History(); --- 83,89 ---- } ! #region "GetHistory" private static History getHistory_try( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { History history = new History(); *************** *** 99,103 **** } private static History getHistory_common( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { History history; --- 99,103 ---- } private static History getHistory_common( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { History history; *************** *** 135,139 **** /// <returns>The history for the given instrument and quote field</returns> public static History GetHistory( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { return getHistory_common( instrumentKey , quoteField , firstDate , lastDate ); --- 135,139 ---- /// <returns>The history for the given instrument and quote field</returns> public static History GetHistory( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { return getHistory_common( instrumentKey , quoteField , firstDate , lastDate ); *************** *** 141,145 **** #endregion public static double GetQuote( string ticker , ! QuoteField quoteField , DateTime dateTime ) { double quote = Double.MinValue; --- 141,145 ---- #endregion public static double GetQuote( string ticker , ! QuoteField quoteField , DateTime dateTime ) { double quote = Double.MinValue; *************** *** 164,168 **** } public static bool WasExchanged( string ticker , ! DateTime dateTime ) { string sqlQuery = --- 164,168 ---- } public static bool WasExchanged( string ticker , ! DateTime dateTime ) { string sqlQuery = *************** *** 182,185 **** --- 182,304 ---- return ( quotes.Rows.Count > 0 ); } + + #region getHistory + private static History getHistory( + DataTable barDataTable , string barFieldName ) + { + History history = new History(); + history.Import( + barDataTable , BarFieldNames.DateTimeForOpen , barFieldName ); + return history; + } + #endregion getHistory + + #region GetBarOpenHistory + + #region getBarDataTable + + #region getSqlForBarDataTable + + #region getFilterForDailyTimes + + // #region getFilterForDailyTime + // private getFilterForDailyTime( DateTime dateTime ) + // { + // string filterForDailyTime = + // "(Format([baDateTimeForOpen],'hh:mm:ss')>='" + + // this.getSqlTimeConstantForFirstDailyBar() + "')"; + // } + // #endregion getFilterForDailyTime + + private static string getFilterForDailyTimes( DateTime[] dailyTimes ) + { + string filterForDailyTimes = ""; + foreach( DateTime dateTime in dailyTimes ) + filterForDailyTimes = + filterForDailyTimes + + SQLBuilder.GetFilterForTime( + "baDateTimeForOpen" , SqlComparisonOperator.Equal , dateTime ) + + " and "; + filterForDailyTimes = filterForDailyTimes.Substring( + 0 , filterForDailyTimes.Length - " and ".Length ); + return filterForDailyTimes; + } + #endregion getFilterForDailyTimes + + private static string getSqlForBarDataTable( + string ticker , + int barInterval , + string barFieldName , + DateTime firstDateTime , + DateTime lastDateTime , + DateTime[] dailyTimes ) + { + string sql = + "select baOpen from bars " + + "where (baTicker='" + ticker + "') and " + + "(baInterval=" + barInterval + ") and" + + "(baDateTimeForOpen>=" + + SQLBuilder.GetDateTimeConstant( firstDateTime ) + ") and" + + "(baDateTimeForOpen<=" + + SQLBuilder.GetDateTimeConstant( lastDateTime ) + + ") and" + + DataBase.getFilterForDailyTimes( dailyTimes ); + // "(Format([baDateTimeForOpen],'hh:mm:ss')>='" + + // DataBase.getSqlTimeConstantForFirstDailyBar() + "') and" + + // "(Format([baDateTimeForOpen],'hh:mm:ss')<='" + + // DataBase.getSqlTimeConstantForLastDailyBar() + "');"; + return sql; + } + #endregion getSqlForBarDataTable + + private static DataTable getBarDataTable( + string ticker , + int barInterval , + string barFieldName , + DateTime firstDateTime , + DateTime lastDateTime , + DateTime[] dailyTimes ) + { + string sql = DataBase.getSqlForBarDataTable( + ticker , + barInterval , + barFieldName , + firstDateTime , + lastDateTime , + dailyTimes ); + DataTable barDataTable = SqlExecutor.GetDataTable( sql ); + return barDataTable; + } + #endregion getBarDataTable + + /// <summary> + /// returns the market value for the given ticker, for all days in the given + /// interval, at the open of all the bars that begin at dailyTimes + /// </summary> + /// <param name="ticker"></param> + /// <param name="barInterval"></param> + /// <param name="firstDateTime"></param> + /// <param name="lastDateTime"></param> + /// <param name="dailyTimes"></param> + /// <returns></returns> + public static History GetBarOpenHistory( + string ticker , + int barInterval , + DateTime firstDateTime , + DateTime lastDateTime , + DateTime[] dailyTimes ) + { + DataTable barDataTable = DataBase.getBarDataTable( + ticker , + barInterval , + BarFieldNames.Open , + firstDateTime , + lastDateTime , + dailyTimes ); + History barOpenHistory = DataBase.getHistory( + barDataTable , BarFieldNames.Open ); + return barOpenHistory; + } + #endregion GetBarOpenHistory } } |