[Quantproject-developers] QuantProject/b3_Data/DataTables Quotes.cs,1.20,1.21
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-12-28 23:28:04
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27459/b3_Data/DataTables Modified Files: Quotes.cs Log Message: Selection of couples of tickers by correlation coefficient is now much more efficient. Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Quotes.cs 20 Dec 2005 19:33:12 -0000 1.20 --- Quotes.cs 28 Dec 2005 23:27:56 -0000 1.21 *************** *** 188,196 **** return tableToReturn; } ! /// <summary> ! /// Returns a table containing the Pearson correlation coefficient of the adjusted close to close ratios /// for any possible couple of tickers contained in the given table, for the specified interval /// </summary> --- 188,211 ---- return tableToReturn; } + + private static void getTickersByAdjCloseToClosePearsonCorrelationCoefficient_setTickersReturns(out float[][] + tickersReturns, DataTable setOfTickers, DateTime firstQuoteDate, DateTime lastQuoteDate) + + { + tickersReturns = new float[setOfTickers.Rows.Count][]; + for(int i = 0; i<setOfTickers.Rows.Count; i++) + { + DataTable tickerQuoteTable = + QuantProject.DataAccess.Tables.Quotes.GetTickerQuotes((string)setOfTickers.Rows[i][0], + firstQuoteDate, + lastQuoteDate); + tickersReturns[i] = + ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuoteTable,"quAdjustedClose"); ! } ! } /// <summary> ! /// Returns a table containing the Pearson correlation coefficient for the adjusted close values /// for any possible couple of tickers contained in the given table, for the specified interval /// </summary> *************** *** 206,209 **** --- 221,226 ---- setOfTickers.Columns.Add("PearsonCorrelationCoefficient", System.Type.GetType("System.Double")); int initialNumberOfRows = setOfTickers.Rows.Count; + float[][] tickersReturns; + getTickersByAdjCloseToClosePearsonCorrelationCoefficient_setTickersReturns(out tickersReturns, setOfTickers, firstQuoteDate, lastQuoteDate); for(int j=0; j!= initialNumberOfRows; j++) { *************** *** 212,223 **** { string secondTicker = (string)setOfTickers.Rows[i][0]; - DataTable dtFirstTicker = QuantProject.DataAccess.Tables.Quotes.GetTickerQuotes(firstTicker, - firstQuoteDate, - lastQuoteDate); - DataTable dtSecondTicker = QuantProject.DataAccess.Tables.Quotes.GetTickerQuotes(secondTicker, - firstQuoteDate, - lastQuoteDate); DataRow rowToAdd = setOfTickers.NewRow(); rowToAdd[0] = firstTicker; rowToAdd["CorrelatedTicker"] = secondTicker; try --- 229,236 ---- { string secondTicker = (string)setOfTickers.Rows[i][0]; DataRow rowToAdd = setOfTickers.NewRow(); rowToAdd[0] = firstTicker; + rowToAdd["PearsonCorrelationCoefficient"] = -2.0; + //unassigned value for this column rowToAdd["CorrelatedTicker"] = secondTicker; try *************** *** 225,240 **** rowToAdd["PearsonCorrelationCoefficient"] = QuantProject.ADT.Statistics.BasicFunctions.PearsonCorrelationCoefficient( ! ExtendedDataTable.GetArrayOfFloatFromColumn(dtFirstTicker, "quAdjustedCloseToCloseRatio"), ! ExtendedDataTable.GetArrayOfFloatFromColumn(dtSecondTicker, "quAdjustedCloseToCloseRatio")); ! setOfTickers.Rows.Add(rowToAdd); } catch(Exception ex) { ! string notUsed = ex.ToString(); } } } ExtendedDataTable.DeleteRows(setOfTickers, 0, initialNumberOfRows - 1); ! return ExtendedDataTable.CopyAndSort(setOfTickers,"PearsonCorrelationCoefficient", orderByASC); } --- 238,276 ---- rowToAdd["PearsonCorrelationCoefficient"] = QuantProject.ADT.Statistics.BasicFunctions.PearsonCorrelationCoefficient( ! tickersReturns[j],tickersReturns[i]); } catch(Exception ex) { ! ex = ex; ! } ! finally ! { ! setOfTickers.Rows.Add(rowToAdd); } } } ExtendedDataTable.DeleteRows(setOfTickers, 0, initialNumberOfRows - 1); ! //delete initial rows that don't contain correlated ticker and Pearson coeff. ! return ExtendedDataTable.CopyAndSort(setOfTickers,"PearsonCorrelationCoefficient>-2.0", ! "PearsonCorrelationCoefficient", orderByASC); ! } ! ! /// <summary> ! /// Returns a table containing the Pearson correlation coefficient for the adjusted close values ! /// for any possible couple of tickers contained in the given group of tickers, ! /// for the specified interval ! /// </summary> ! public static DataTable GetTickersByAdjCloseToClosePearsonCorrelationCoefficient( bool orderByASC, ! string groupID, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! ! { ! ! DataTable tickersOfGroup = new Tickers_tickerGroups(groupID); ! return GetTickersByAdjCloseToClosePearsonCorrelationCoefficient(orderByASC, ! tickersOfGroup, ! firstQuoteDate, ! lastQuoteDate); } *************** *** 244,250 **** /// </summary> public static DataTable GetTickersByCloseToOpenPearsonCorrelationCoefficient( bool orderByASC, ! DataTable setOfTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate) { --- 280,286 ---- /// </summary> public static DataTable GetTickersByCloseToOpenPearsonCorrelationCoefficient( bool orderByASC, ! DataTable setOfTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate) { |