[Quantproject-developers] QuantProject/b3_Data/Selectors SelectorByCloseToCloseCorrelationToBenchma
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2006-07-02 19:31:21
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv4685/b3_Data/Selectors Modified Files: SelectorByCloseToCloseCorrelationToBenchmark.cs Log Message: The selector has been simplified, and some bugs have been fixed. Index: SelectorByCloseToCloseCorrelationToBenchmark.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Selectors/SelectorByCloseToCloseCorrelationToBenchmark.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SelectorByCloseToCloseCorrelationToBenchmark.cs 20 Dec 2005 19:29:57 -0000 1.2 --- SelectorByCloseToCloseCorrelationToBenchmark.cs 2 Jul 2006 19:31:18 -0000 1.3 *************** *** 22,30 **** using System; - using System.Collections; using System.Data; - using System.Windows.Forms; using QuantProject.DataAccess.Tables; ! using QuantProject.Data.DataTables; namespace QuantProject.Data.Selectors --- 22,28 ---- using System; using System.Data; using QuantProject.DataAccess.Tables; ! using QuantProject.ADT.Statistics; namespace QuantProject.Data.Selectors *************** *** 41,49 **** { private string benchmark; ! private int numDaysBetweenEachClose; /// <summary> /// Creates a new instance of the selector /// </summary> ! /// <param name="setOfTickersToBeSelected">The data table containing in the first column the tickers that have to be ordered</param> /// <param name="benchmark">Benchmark code</param> /// <param name="orderInASCmode">Ordering mode</param> --- 39,49 ---- { private string benchmark; ! private bool addBenchmarkToTheGivenSetOfTickers; /// <summary> /// Creates a new instance of the selector /// </summary> ! /// <param name="setOfTickersToBeSelected">The data table containing ! /// in the first column the tickers that have to be ordered by pearson correlation ! /// coefficient to a given benchmark</param> /// <param name="benchmark">Benchmark code</param> /// <param name="orderInASCmode">Ordering mode</param> *************** *** 51,73 **** /// <param name="lastQuoteDate">The last date for the interval</param> /// <param name="maxNumOfReturnedTickers">Max number of tickers to be returned</param> - /// <param name="numDaysBetweenEachClose">Number of days between closes to be studied. NOTE that - /// close values are grouped in pairs and the first close value in each group is - /// not the last close in the previous group. There is, in other words, a discontinuity - /// between each group, with length equal to the group's length </param> public SelectorByCloseToCloseCorrelationToBenchmark(DataTable setOfTickersToBeSelected, ! string benchmark, ! bool orderInASCmode, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! long maxNumOfReturnedTickers, ! int numDaysBetweenEachClose): ! base(setOfTickersToBeSelected, ! orderInASCmode, ! firstQuoteDate, ! lastQuoteDate, ! maxNumOfReturnedTickers) { this.benchmark = benchmark; ! this.numDaysBetweenEachClose = numDaysBetweenEachClose; } --- 51,69 ---- /// <param name="lastQuoteDate">The last date for the interval</param> /// <param name="maxNumOfReturnedTickers">Max number of tickers to be returned</param> public SelectorByCloseToCloseCorrelationToBenchmark(DataTable setOfTickersToBeSelected, ! string benchmark, ! bool orderInASCmode, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! long maxNumOfReturnedTickers, ! bool addBenchmarkToTheGivenSetOfTickers): ! base(setOfTickersToBeSelected, ! orderInASCmode, ! firstQuoteDate, ! lastQuoteDate, ! maxNumOfReturnedTickers) { this.benchmark = benchmark; ! this.addBenchmarkToTheGivenSetOfTickers = addBenchmarkToTheGivenSetOfTickers; } *************** *** 76,80 **** /// </summary> /// <param name="groupID">The group ID containing the tickers that have to be ordered</param> ! /// <param name="benchmark">Benchmark code</param> /// <param name="orderInASCmode">Ordering mode</param> /// <param name="firstQuoteDate">The first date for the interval</param> --- 72,76 ---- /// </summary> /// <param name="groupID">The group ID containing the tickers that have to be ordered</param> ! /// <param name="benchmark">Benchmark</param> /// <param name="orderInASCmode">Ordering mode</param> /// <param name="firstQuoteDate">The first date for the interval</param> *************** *** 86,103 **** /// between each group, with length equal to the group's length </param> public SelectorByCloseToCloseCorrelationToBenchmark(string groupID, ! string benchmark, ! bool orderInASCmode, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! long maxNumOfReturnedTickers, ! int numDaysBetweenEachClose): ! base(groupID, ! orderInASCmode, ! firstQuoteDate, ! lastQuoteDate, ! maxNumOfReturnedTickers) { this.benchmark = benchmark; ! this.numDaysBetweenEachClose = numDaysBetweenEachClose; } --- 82,99 ---- /// between each group, with length equal to the group's length </param> public SelectorByCloseToCloseCorrelationToBenchmark(string groupID, ! string benchmark, ! bool orderInASCmode, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! long maxNumOfReturnedTickers, ! bool addBenchmarkToTheGivenSetOfTickers): ! base(groupID, ! orderInASCmode, ! firstQuoteDate, ! lastQuoteDate, ! maxNumOfReturnedTickers) { this.benchmark = benchmark; ! this.addBenchmarkToTheGivenSetOfTickers = addBenchmarkToTheGivenSetOfTickers; } *************** *** 106,124 **** { if(this.setOfTickersToBeSelected == null) ! return QuantProject.Data.DataTables.Quotes.GetTickersByCloseToCloseCorrelationToBenchmark(this.isOrderedInASCMode, this.groupID,this.benchmark, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers, this.numDaysBetweenEachClose); else ! return QuantProject.Data.DataTables.Quotes.GetTickersByCloseToCloseCorrelationToBenchmark(this.isOrderedInASCMode, this.setOfTickersToBeSelected,this.benchmark, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers, this.numDaysBetweenEachClose); } public void SelectAllTickers() { ; ! } } } --- 102,174 ---- { if(this.setOfTickersToBeSelected == null) ! return this.getTickersByCloseToCloseCorrelationToBenchmark(this.isOrderedInASCMode, this.groupID,this.benchmark, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers); else ! return this.getTickersByCloseToCloseCorrelationToBenchmark(this.isOrderedInASCMode, this.setOfTickersToBeSelected,this.benchmark, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers); } public void SelectAllTickers() { ; ! } ! ! private DataTable getTickersByCloseToCloseCorrelationToBenchmark( bool orderByASC, ! DataTable setOfTickers, string benchmark, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! long maxNumOfReturnedTickers) ! { ! if(!setOfTickers.Columns.Contains("CloseToCloseCorrelationToBenchmark")) ! setOfTickers.Columns.Add("CloseToCloseCorrelationToBenchmark", System.Type.GetType("System.Double")); ! float[] benchmarkQuotes = QuantProject.Data.DataTables.Quotes.GetArrayOfAdjustedCloseQuotes(benchmark, firstQuoteDate, lastQuoteDate); ! foreach(DataRow row in setOfTickers.Rows) ! { ! float[] tickerQuotes = QuantProject.Data.DataTables.Quotes.GetArrayOfAdjustedCloseQuotes((string)row[0], ! firstQuoteDate, lastQuoteDate); ! if(tickerQuotes.Length == benchmarkQuotes.Length) ! { ! if((string)row[0] == benchmark) ! row["CloseToCloseCorrelationToBenchmark"] = 1; ! else ! row["CloseToCloseCorrelationToBenchmark"] = ! BasicFunctions.PearsonCorrelationCoefficient(benchmarkQuotes, tickerQuotes); ! } ! ! } ! DataTable tableToReturn = ExtendedDataTable.CopyAndSort(setOfTickers, ! "CloseToCloseCorrelationToBenchmark>=0.0 OR " + ! "CloseToCloseCorrelationToBenchmark<0.0", ! "CloseToCloseCorrelationToBenchmark", ! orderByASC); ! ExtendedDataTable.DeleteRows(tableToReturn, maxNumOfReturnedTickers); ! if(this.addBenchmarkToTheGivenSetOfTickers) ! { ! DataRow newRow = tableToReturn.NewRow(); ! newRow[0] = benchmark; ! tableToReturn.Rows.Add(newRow); ! } ! return tableToReturn; ! } ! ! private DataTable getTickersByCloseToCloseCorrelationToBenchmark( bool orderByASC, ! string groupID, string benchmark, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! long maxNumOfReturnedTickers) ! { ! DataTable tickersOfGroup = Tickers_tickerGroups.GetTickers(groupID); ! return this.getTickersByCloseToCloseCorrelationToBenchmark(orderByASC, ! tickersOfGroup, benchmark, ! firstQuoteDate, ! lastQuoteDate, ! maxNumOfReturnedTickers); ! } ! ! } } |