[Quantproject-developers] QuantProject/b2_DataAccess/Tables Bars.cs, 1.1, 1.2
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2008-11-14 15:51:26
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4416/b2_DataAccess/Tables Modified Files: Bars.cs Log Message: Added parameter intervalFrameInSeconds Index: Bars.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Bars.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Bars.cs 9 Nov 2008 19:11:10 -0000 1.1 --- Bars.cs 14 Nov 2008 15:51:18 -0000 1.2 *************** *** 47,75 **** public static string Close = "baClose"; public static string Volume = "baVolume"; ! ! private DataTable bars; ! ! /// <summary> ! /// Gets the ticker whose bars are contained into the Bars object ! /// </summary> ! /// <returns></returns> ! public string Ticker ! { ! get{ return ((string)this.bars.Rows[ 0 ][ Bars.TickerFieldName ]); } ! } ! public Bars( string ticker) { ! this.bars = Bars.GetTickerBars( ticker ); } ! /// <summary> ! /// Creates bars for the given instrument, since the startDateTime to the endDateTime ! /// </summary> ! /// <param name="ticker"></param> ! /// <param name="startDateTime"></param> ! /// <param name="endDateTime"></param> public Bars( string ticker , DateTime startDateTime , DateTime endDateTime ) { ! /// TO DO } /// <summary> --- 47,59 ---- public static string Close = "baClose"; public static string Volume = "baVolume"; ! public Bars( string ticker) { ! } ! public Bars( string ticker , DateTime startDateTime , DateTime endDateTime ) { ! } /// <summary> *************** *** 77,85 **** /// </summary> /// <param name="ticker">ticker for which the dateTime of the first bar has to be returned</param> /// <returns></returns> ! public static DateTime GetFirstBarDateTime( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select min(" + Bars.DateTimeForOpen + ") as minDate from bars where " + Bars.TickerFieldName + "='" + ticker + "' " + "group by " + Bars.TickerFieldName + ")" ); return (DateTime)(dataTable.Rows[ 0 ][ "minDate" ]); --- 61,72 ---- /// </summary> /// <param name="ticker">ticker for which the dateTime of the first bar has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static DateTime GetFirstBarDateTime( string ticker, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select min(" + Bars.DateTimeForOpen + ") as minDate from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "group by " + Bars.TickerFieldName + ")" ); return (DateTime)(dataTable.Rows[ 0 ][ "minDate" ]); *************** *** 89,97 **** /// </summary> /// <param name="ticker">ticker for which the dateTime of the last bar has to be returned</param> /// <returns></returns> ! public static DateTime GetLastBarDateTime( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars where " + Bars.TickerFieldName + "='" + ticker + "' " + "order by " + Bars.DateTimeForOpen + " DESC"); return (DateTime)(dataTable.Rows[0][ Bars.DateTimeForOpen ]); --- 76,86 ---- /// </summary> /// <param name="ticker">ticker for which the dateTime of the last bar has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static DateTime GetLastBarDateTime( string ticker, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "order by " + Bars.DateTimeForOpen + " DESC"); return (DateTime)(dataTable.Rows[0][ Bars.DateTimeForOpen ]); *************** *** 101,109 **** /// </summary> /// <param name="ticker">ticker for which the number of bars has to be returned</param> /// <returns></returns> ! public static int GetNumberOfBars( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars where " + Bars.TickerFieldName + "='" + ticker + "'" ); return dataTable.Rows.Count; } --- 90,101 ---- /// </summary> /// <param name="ticker">ticker for which the number of bars has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static int GetNumberOfBars( string ticker, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " ); return dataTable.Rows.Count; } *************** *** 114,125 **** /// </summary> /// <param name="ticker">ticker for which the number of bars has to be returned</param> /// <returns></returns> public static int GetNumberOfBarsWithEffectiveTrades( string ticker, DateTime firstDateTime, ! DateTime lastDateTime) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars WHERE " + Bars.TickerFieldName + "='" + ticker + "'" + ! " AND " + Bars.Volume + ">0" + " AND " + Bars.DateTimeForOpen + " BETWEEN " + SQLBuilder.GetDateConstant(firstDateTime) + ! " AND " + SQLBuilder.GetDateConstant(lastDateTime)); return dataTable.Rows.Count; } --- 106,120 ---- /// </summary> /// <param name="ticker">ticker for which the number of bars has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> public static int GetNumberOfBarsWithEffectiveTrades( string ticker, DateTime firstDateTime, ! DateTime lastDateTime, int intervalFrameInSeconds) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars " + ! "WHERE " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + ! "and " + Bars.Volume + ">0" + " and " + Bars.DateTimeForOpen + " BETWEEN " + SQLBuilder.GetDateConstant(firstDateTime) + " " + ! "and " + SQLBuilder.GetDateConstant(lastDateTime) ); return dataTable.Rows.Count; } *************** *** 130,138 **** /// </summary> /// <param name="ticker">ticker for which the close has to be returned</param> /// <returns></returns> ! public static float GetClose( string ticker, DateTime dateTime ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Close +" from bars where " + Bars.TickerFieldName + "='" + ticker + "' " + "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateConstant(dateTime) ); return (float)dataTable.Rows[0][0]; --- 125,136 ---- /// </summary> /// <param name="ticker">ticker for which the close has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static float GetClose( string ticker, DateTime dateTime, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Close + " from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateConstant(dateTime) ); return (float)dataTable.Rows[0][0]; *************** *** 143,151 **** /// </summary> /// <param name="ticker">ticker for which the raw open has to be returned</param> /// <returns></returns> ! public static float GetOpen( string ticker, DateTime dateTime ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Open +" from bars where " + Bars.TickerFieldName + "='" + ticker + "' " + "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateConstant(dateTime) ); return (float)dataTable.Rows[0][0]; --- 141,152 ---- /// </summary> /// <param name="ticker">ticker for which the raw open has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static float GetOpen( string ticker, DateTime dateTime, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Open + " from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateConstant(dateTime) ); return (float)dataTable.Rows[0][0]; *************** *** 211,703 **** // } // } ! ! ! /// <summary> ! /// returns tickers ordered by a liquidity index ! /// </summary> ! public static DataTable GetTickersByLiquidity( bool orderInASCMode, string groupID, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! long maxNumOfReturnedTickers) ! { ! string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! "Avg([quVolume]*[quClose]) AS AverageTradedValue " + ! "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! "AND quotes.quDate BETWEEN " + ! SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! SQLBuilder.GetDateConstant(lastQuoteDate) + ! "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! "ORDER BY Avg([quVolume]*[quClose])"; ! string sortDirection = " DESC"; ! if(orderInASCMode) ! sortDirection = " ASC"; ! sql = sql + sortDirection; ! return SqlExecutor.GetDataTable( sql ); ! } ! ! // /// <summary> ! // /// returns tickers ordered by liquidity, with a specified min volume ! // /// </summary> ! // /// <param name="orderInASCMode">true iff return must be ordered</param> ! // /// <param name="groupID"></param> ! // /// <param name="firstQuoteDate"></param> ! // /// <param name="lastQuoteDate"></param> ! // /// <param name="maxNumOfReturnedTickers"></param> ! // /// <param name="minVolume"></param> ! // /// <returns></returns> ! // public static DataTable GetTickersByLiquidity( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long minVolume, ! // long maxNumOfReturnedTickers ! // ) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "Avg([quVolume]*[quClose]) AS AverageTradedValue " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "HAVING Avg([quVolume])>=" + minVolume.ToString() + " " + ! // "ORDER BY Avg([quVolume])"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // ! // ! // /// <summary> ! // /// Returns tickers ordered by a close to close volatility index (stdDev of adjustedCloseToClose ratio) ! // /// </summary> ! // public static DataTable GetTickersByCloseToCloseVolatility( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "StDev(quotes.quAdjustedCloseToCloseRatio) AS AdjCloseToCloseStandDev " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "ORDER BY StDev(quotes.quAdjustedCloseToCloseRatio)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// Returns tickers ordered by the open to close volatility index (stdDev of OTC ratio) ! // /// </summary> ! // public static DataTable GetTickersByOpenToCloseVolatility( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "StDev(quotes.quClose/quotes.quOpen - 1) AS OpenToCloseStandDev " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "ORDER BY StDev(quotes.quClose/quotes.quOpen - 1)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// Returns tickers ordered by average close to close performance ! // /// </summary> ! // public static DataTable GetTickersByAverageCloseToClosePerformance( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quAdjustedCloseToCloseRatio) AS AverageCloseToClosePerformance " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "ORDER BY Avg(quotes.quAdjustedCloseToCloseRatio)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// Returns tickers ordered by average open to close performance (in the same bar) ! // /// </summary> ! // public static DataTable GetTickersByAverageOpenToClosePerformance( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // double maxAbsoluteAverageOTCPerformance, ! // long maxNumOfReturnedTickers) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quClose/quotes.quOpen - 1) AS AverageOpenToClosePerformance " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "HAVING Avg(quotes.quClose/quotes.quOpen - 1) <= " + maxAbsoluteAverageOTCPerformance + ! // " AND Avg(quotes.quClose/quotes.quOpen - 1) >= -" + maxAbsoluteAverageOTCPerformance + " " + ! // "ORDER BY Avg(quotes.quClose/quotes.quOpen)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// returns tickers ordered by the average raw open price that is over ! // /// a given minimum, at a given time interval ! // /// </summary> ! // public static DataTable GetTickersByRawOpenPrice( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers, double minPrice ) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " quotes.quTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quOpen) AS AverageRawOpenPrice " + ! // "FROM (quotes INNER JOIN tickers ON quotes.quTicker=tickers.tiTicker) " + ! // "INNER JOIN tickers_tickerGroups ON tickers.tiTicker=tickers_tickerGroups.ttTiId " + ! // "WHERE quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "AND " + "tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "GROUP BY quotes.quTicker, tickers.tiCompanyName " + ! // "HAVING Avg(quotes.quOpen) >= " + minPrice + " " + ! // "ORDER BY Avg(quotes.quOpen)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// returns tickers ordered by average raw open price level, ! // /// with a given standard deviation, in a given time interval ! // /// </summary> ! // public static DataTable GetTickersByRawOpenPrice( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers, double minPrice, ! // double maxPrice, double minStdDeviation, ! // double maxStdDeviation) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " quotes.quTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quOpen) AS AverageRawOpenPrice, StDev(quotes.quOpen) AS StdDevRawOpenPrice " + ! // "FROM (quotes INNER JOIN tickers ON quotes.quTicker=tickers.tiTicker) " + ! // "INNER JOIN tickers_tickerGroups ON tickers.tiTicker=tickers_tickerGroups.ttTiId " + ! // "WHERE quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "AND " + "tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "GROUP BY quotes.quTicker, tickers.tiCompanyName " + ! // "HAVING Avg(quotes.quOpen) BETWEEN " + minPrice + " AND " + maxPrice + " " + ! // "AND StDev(quotes.quOpen) BETWEEN " + minStdDeviation + " AND " + maxStdDeviation + " " + ! // "ORDER BY Avg(quotes.quOpen)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! ! // /// <summary> ! // /// returns the average traded value for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAverageTradedValue( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "Avg([quVolume]*[quClose]) AS AverageTradedValue " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count==0) ! // return 0; ! // else ! // return (double)dt.Rows[0]["AverageTradedValue"]; ! // } ! // ! // /// <summary> ! // /// returns the average traded volume for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAverageTradedVolume( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "Avg([quVolume]) AS AverageTradedVolume " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count==0) ! // return 0; ! // else ! // return (double)dt.Rows[0]["AverageTradedVolume"]; ! // } ! // ! // /// <summary> ! // /// returns the average close to close performance value for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAverageCloseToClosePerformance( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "Avg([quAdjustedCloseToCloseRatio]) AS AverageCloseToClosePerformance " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count==0) ! // return 0; ! // else ! // return (double)dt.Rows[0]["AverageCloseToClosePerformance"]; ! // } ! // ! // /// <summary> ! // /// returns the average open to close performance ! // /// for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAverageOpenToClosePerformance(string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "Avg([quClose]/[quOpen] - 1) AS AverageOpenToClosePerformance " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // return (double)dt.Rows[0]["AverageOpenToClosePerformance"]; ! // } ! // ! // ! // /// <summary> ! // /// returns the standard deviation of the adjusted close to close ratio ! // /// for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAdjustedCloseToCloseStandardDeviation( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // double adjCloseToCloseStdDev = 0.0; ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "StDev(quotes.quAdjustedCloseToCloseRatio) AS AdjCloseToCloseStandDev " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // ! // if( dt.Rows.Count > 0 && ! // DBNull.Value != dt.Rows[0]["AdjCloseToCloseStandDev"] ) ! // adjCloseToCloseStdDev = (double)dt.Rows[0]["AdjCloseToCloseStandDev"]; ! // ! // return adjCloseToCloseStdDev; ! // } ! // ! // /// <summary> ! // /// returns the standard deviation of the open to close ratio ! // /// for the given ticker in the specified interval ! // /// </summary> ! // public static double GetOpenToCloseStandardDeviation( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "StDev(quotes.quClose/quotes.quOpen - 1) AS OpenToCloseStandDev " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // return (double)dt.Rows[0]["OpenToCloseStandDev"]; ! // } ! // ! // /// <summary> ! // /// returns the standard deviation of the adjusted close to open ratio ! // /// for the given ticker in the specified interval ! // /// </summary> ! // public static double GetCloseToOpenStandardDeviation( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // double returnValue = Double.MaxValue; ! // ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "StDev(quotes.quClose/quotes.quOpen) AS CloseToOpenStandDev " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count > 0) ! // { ! // if( dt.Rows[0]["CloseToOpenStandDev"] is double ) ! // //cast is possible ! // returnValue = (double)dt.Rows[0]["CloseToOpenStandDev"]; ! // } ! // return returnValue; ! // } ! // ! // /// <summary> ! // /// returns the average raw open price for the given ticker, ! // /// at the specified time interval ! // /// </summary> ! // public static double GetAverageRawOpenPrice( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // double returnValue = 0; ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quOpen) AS AverageRawOpenPrice " + ! // "FROM (quotes INNER JOIN tickers ON quotes.quTicker=tickers.tiTicker) " + ! // "INNER JOIN tickers_tickerGroups ON tickers.tiTicker=tickers_tickerGroups.ttTiId " + ! // "WHERE quotes.quTicker ='" + ticker + ! // "' AND quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "GROUP BY quotes.quTicker, tickers.tiCompanyName"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count > 0) ! // { ! // if( dt.Rows[0]["AverageRawOpenPrice"] is double ) ! // //cast is possible ! // returnValue = (double)dt.Rows[0]["AverageRawOpenPrice"]; ! // } ! // return returnValue; ! // ! // } ! // ! // /// <summary> ! // /// returns raw open price's standard deviation for the given ticker, ! // /// at the specified time interval ! // /// </summary> ! // public static double GetRawOpenPriceStdDeviation( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // double returnValue = Double.MaxValue; ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, tickers.tiCompanyName, " + ! // "StDev(quotes.quOpen) AS RawOpenPriceStdDev " + ! // "FROM (quotes INNER JOIN tickers ON quotes.quTicker=tickers.tiTicker) " + ! // "INNER JOIN tickers_tickerGroups ON tickers.tiTicker=tickers_tickerGroups.ttTiId " + ! // "WHERE quotes.quTicker ='" + ticker + ! // "' AND quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "GROUP BY quotes.quTicker, tickers.tiCompanyName"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count > 0) ! // { ! // if( dt.Rows[0]["RawOpenPriceStdDev"] is double ) ! // //cast is possible ! // returnValue = (double)dt.Rows[0]["RawOpenPriceStdDev"]; ! // } ! // return returnValue; ! // } ! // ! // /// <summary> ! // /// Returns number of days for which raw close was greater than raw open ! // /// for the given interval of days (for the given ticker). ! // /// </summary> ! // public static int GetNumberOfOpenToCloseWinningDays(string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // { ! // DataTable dt; ! // int returnValue = 0; ! // string sql = "SELECT Count(*) AS CloseToOpenWinningDays " + ! // "FROM quotes WHERE " + ! // "quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "AND " + "quotes.quTicker='" + ticker + "' " + ! // "AND quotes.quClose > quotes.quOpen"; ! // ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count > 0) ! // { ! // if(dt.Rows[0][0] is int) ! // returnValue = (int)dt.Rows[0][0]; ! // } ! // return returnValue; ! // } ! /// <summary> /// returns the bars DataTable for the given ticker /// </summary> ! /// <param name="instrumentKey">ticker whose bars are to be returned</param> /// <returns></returns> ! public static DataTable GetTickerBars( string instrumentKey ) { ! string sql = "select * from bars where " + Bars.TickerFieldName + "='" + instrumentKey + "' " + "order by " + Bars.DateTimeForOpen; return SqlExecutor.GetDataTable( sql ); --- 212,227 ---- // } // } ! /// <summary> /// returns the bars DataTable for the given ticker /// </summary> ! /// <param name="ticker">ticker whose bars are to be returned</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static DataTable GetTickerBars( string ticker, int intervalFrameInSeconds ) { ! string sql = "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "order by " + Bars.DateTimeForOpen; return SqlExecutor.GetDataTable( sql ); *************** *** 707,720 **** /// returns the bars DataTable for the given ticker /// </summary> ! /// <param name="instrumentKey">ticker whose quotes are to be returned</param> /// <param name="firstBarDateTime">The first bar date time</param> /// <param name="lastBarDateTime">The last bar date time</param> /// <returns></returns> ! public static DataTable GetTickerBars( string instrumentKey, DateTime firstBarDateTime, ! DateTime lastBarDateTime) { ! string sql = "select * from bars where " + Bars.TickerFieldName + "='" + instrumentKey + "' " + ! "AND " + Bars.DateTimeForOpen + " BETWEEN " + SQLBuilder.GetDateConstant(firstBarDateTime) + ! " AND " + SQLBuilder.GetDateConstant(lastBarDateTime) + " " + "order by " + Bars.DateTimeForOpen; return SqlExecutor.GetDataTable( sql ); --- 231,247 ---- /// returns the bars DataTable for the given ticker /// </summary> ! /// <param name="ticker">ticker whose quotes are to be returned</param> /// <param name="firstBarDateTime">The first bar date time</param> /// <param name="lastBarDateTime">The last bar date time</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static DataTable GetTickerBars( string ticker, DateTime firstBarDateTime, ! DateTime lastBarDateTime, int intervalFrameInSeconds) { ! string sql = "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + ! "and " + Bars.DateTimeForOpen + " between " + SQLBuilder.GetDateConstant(firstBarDateTime) + " " + ! "and " + SQLBuilder.GetDateConstant(lastBarDateTime) + " " + "order by " + Bars.DateTimeForOpen; return SqlExecutor.GetDataTable( sql ); *************** *** 726,732 **** /// <param name="startDateTime"></param> /// <param name="endDateTime"></param> /// <returns></returns> public static void SetDataTable( string tickerOrGroupID , DateTime startDateTime , DateTime endDateTime , ! DataTable dataTable) { string sql; --- 253,260 ---- /// <param name="startDateTime"></param> /// <param name="endDateTime"></param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> public static void SetDataTable( string tickerOrGroupID , DateTime startDateTime , DateTime endDateTime , ! DataTable dataTable, int intervalFrameInSeconds) { string sql; *************** *** 734,738 **** sql = "select * from bars INNER JOIN tickers_tickerGroups ON " + "bars." + Bars.TickerFieldName + "=tickers_tickerGroups." + Tickers_tickerGroups.Ticker + " " + ! "where " + Tickers_tickerGroups.GroupID + "='" + tickerOrGroupID + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + --- 262,267 ---- sql = "select * from bars INNER JOIN tickers_tickerGroups ON " + "bars." + Bars.TickerFieldName + "=tickers_tickerGroups." + Tickers_tickerGroups.Ticker + " " + ! "where " + Tickers_tickerGroups.GroupID + "='" + tickerOrGroupID + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + *************** *** 740,744 **** else sql = "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + tickerOrGroupID + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + --- 269,274 ---- else sql = "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + tickerOrGroupID + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + *************** *** 774,782 **** /// <param name="dateTime">Date for the quotes to be fetched</param> /// <param name="dataTable">Output parameter</param> ! public static void SetDataTable( ICollection tickerCollection , DateTime dateTime , DataTable dataTable) { string sql; sql = "select * from bars " + ! "where " + setDataTable_getTickerListWhereClause( tickerCollection ) + " and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateTimeConstant( dateTime ) + " " + "order by " + Bars.TickerFieldName; --- 304,314 ---- /// <param name="dateTime">Date for the quotes to be fetched</param> /// <param name="dataTable">Output parameter</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> ! public static void SetDataTable( ICollection tickerCollection , DateTime dateTime , DataTable dataTable, int intervalFrameInSeconds) { string sql; sql = "select * from bars " + ! "where " + setDataTable_getTickerListWhereClause( tickerCollection ) + " and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + " and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateTimeConstant( dateTime ) + " " + "order by " + Bars.TickerFieldName; *************** *** 785,789 **** } #endregion - } } --- 317,320 ---- |