[Quantproject-developers] QuantProject/b3_Data/DataTables TickerDataTable.cs, 1.10, 1.11
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2008-11-09 19:22:17
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22501/b3_Data/DataTables Modified Files: TickerDataTable.cs Log Message: Added method GetTickersQuotedAtAGivenPercentageOfDateTimes Index: TickerDataTable.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/TickerDataTable.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TickerDataTable.cs 19 Jan 2008 19:29:34 -0000 1.10 --- TickerDataTable.cs 9 Nov 2008 19:22:14 -0000 1.11 *************** *** 1,4 **** /* ! QuantDownloader - Quantitative Finance Library TickerDataTable.cs --- 1,4 ---- /* ! QuantProject - Quantitative Finance Library TickerDataTable.cs *************** *** 236,239 **** --- 236,327 ---- #endregion GetTickersQuotedInEachMarketDay + #region GetTickersQuotedAtEachDateTime + + private static void getTickersQuotedAtAGivenPercentageOfDateTimes_addRow(DataRow rowToBeAdded, int numberOfTradingDateTimes, + DataTable tableToWhichRowIsToBeAdded) + { + DataRow newRow = tableToWhichRowIsToBeAdded.NewRow(); + newRow[0]= rowToBeAdded[0]; + newRow["NumberOfBars"] = numberOfTradingDateTimes; + tableToWhichRowIsToBeAdded.Rows.Add(newRow); + } + + private static void getTickersQuotedAtAGivenPercentageOfDateTimes_handleRow( + DataRow row , History marketDateTimes , double percentageOfDateTimes , + DateTime firstQuoteDate , DateTime lastQuoteDate , + DataTable tableToWhichRowIsToBeAdded ) + { + History dateTimesForTicker = Bars.GetMarketDateTimes( (string)row[0], + firstQuoteDate , lastQuoteDate ); + if( dateTimesForTicker.ContainsAtAGivenPercentageDateTimesIn( marketDateTimes , percentageOfDateTimes ) ) + //the current ticker has been effectively traded at the given percentage of times + //for the given market date times + TickerDataTable.getTickersQuotedAtAGivenPercentageOfDateTimes_addRow( + row , dateTimesForTicker.Count , tableToWhichRowIsToBeAdded ); + } + + + private static void addColumnNumberOfBars(DataTable tableToAnalyze) + { + if(!tableToAnalyze.Columns.Contains("NumberOfBars")) + tableToAnalyze.Columns.Add("NumberOfBars", System.Type.GetType("System.Int32")); + } + + public static DataTable GetTickersQuotedAtAGivenPercentageOfDateTimes(string marketIndex, double percentageOfDateTimes, + DataTable setOfTickers, + DateTime firstBarDateTime, DateTime lastBarDateTime, + long maxNumOfReturnedTickers) + { + History marketDateTimesForIndex = Bars.GetMarketDateTimes(marketIndex, + firstBarDateTime , lastBarDateTime); + return GetTickersQuotedAtAGivenPercentageOfDateTimes( + marketDateTimesForIndex , percentageOfDateTimes , setOfTickers , + firstBarDateTime , lastBarDateTime , maxNumOfReturnedTickers ); + } + + public static DataTable GetTickersQuotedAtAGivenPercentageOfDateTimes(string marketIndex, double percentageOfDateTimes, + string groupID, + DateTime firstBarDateTime, DateTime lastBarDateTime, + long maxNumOfReturnedTickers) + { + DataTable groupOfTicker = + QuantProject.DataAccess.Tables.Tickers_tickerGroups.GetTickers(groupID); + return GetTickersQuotedAtAGivenPercentageOfDateTimes( + marketIndex , percentageOfDateTimes , groupOfTicker , + firstBarDateTime , lastBarDateTime , maxNumOfReturnedTickers ); + } + + /// <summary> + /// Returns a dataTable containing tickers that are quoted + /// at a given percentage of time with respect to + /// a history of marketDateTimes + /// </summary> + /// <param name="percentageOfDateTimes">percentage (0 to 100) of times of quotation + /// with respect to a given history of marketDateTimes. For example: + /// with 50, it will be returned a dataTable with all the tickers + /// that have at least 0,5*(number of marketDateTimes) quoted dateTimes in common + /// with marketDateTimes</param> + /// <returns></returns> + public static DataTable GetTickersQuotedAtAGivenPercentageOfDateTimes( + History marketDateTimes, double percentageOfDateTimes, + DataTable setOfTickers, + DateTime firstBarDateTime, DateTime lastBarDateTime, + long maxNumOfReturnedTickers) + { + if(percentageOfDateTimes <= 0 || percentageOfDateTimes > 100) + throw new Exception ("invalid percentage"); + + TickerDataTable.addColumnNumberOfBars(setOfTickers); + DataTable returnValue = setOfTickers.Clone(); + foreach(DataRow row in setOfTickers.Rows) + getTickersQuotedAtAGivenPercentageOfDateTimes_handleRow( + row , marketDateTimes , percentageOfDateTimes , + firstBarDateTime , lastBarDateTime , returnValue ); + ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers); + return returnValue; + } + + #endregion GetTickersQuotedAtAGivenPercentageOfDateTimes + public static DataTable GetTickersQuotedInEachMarketDay(string marketIndex, DataTable setOfTickers, DateTime firstQuoteDate, |