[Quantproject-developers] QuantProject/b2_DataAccess/Tables Quotes.cs,1.6,1.7
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2004-05-22 07:09:13
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21746/b2_DataAccess/Tables Modified Files: Quotes.cs Log Message: Added new methods for the check of the adjusted close to close ratio Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Quotes.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Quotes.cs 11 May 2004 21:57:27 -0000 1.6 --- Quotes.cs 22 May 2004 07:09:04 -0000 1.7 *************** *** 29,32 **** --- 29,34 ---- public static string AdjustedCloseToCloseRatio = "quAdjustedCloseToCloseRatio"; + public static DateTime DateWithDifferentCloseToClose = new DateTime(1900,1,1); + /// <summary> *************** *** 93,103 **** /// (the table refers to the ticker passed as the first parameter) /// </summary> ! private static void commitAllCloseToCloseRatios(string ticker, ! DataTable tableContainingCloseToCloseRatios ) { - string notUsed = ticker; OleDbSingleTableAdapter adapter = new OleDbSingleTableAdapter("SELECT * FROM quotes WHERE 1=2", tableContainingCloseToCloseRatios); adapter.OleDbDataAdapter.Update(tableContainingCloseToCloseRatios); --- 95,104 ---- /// (the table refers to the ticker passed as the first parameter) /// </summary> ! private static void commitAllCloseToCloseRatios(DataTable tableContainingCloseToCloseRatios ) { OleDbSingleTableAdapter adapter = new OleDbSingleTableAdapter("SELECT * FROM quotes WHERE 1=2", tableContainingCloseToCloseRatios); + adapter.OleDbDataAdapter.ContinueUpdateOnError = true; adapter.OleDbDataAdapter.Update(tableContainingCloseToCloseRatios); *************** *** 113,131 **** /// <summary> ! /// It provides computation of the adjustedCloseToCloseRatios for the given ticker /// </summary> public static void ComputeAndCommitCloseToCloseRatios( string ticker) { - DateTime start = DateTime.Now; DataTable tickerQuotes = Quotes.GetTickerQuotes(ticker); - DateTime tickerQuotesTime = DateTime.Now; Quotes.ComputeCloseToCloseValues(tickerQuotes); ! DateTime computation = DateTime.Now; ! Quotes.commitAllCloseToCloseRatios(ticker, tickerQuotes); ! DateTime commit = DateTime.Now; ! MessageBox.Show("start : " + start.ToString() + "\n" + ! "loading quotes - finished : " + tickerQuotesTime.ToString() + "\n" + ! "computation - finished: " + computation.ToString() + "\n" + ! "commit - finished: " + commit.ToString()); } --- 114,125 ---- /// <summary> ! /// It provides computation and commiting to database ! /// of the adjustedCloseToCloseRatios for the given ticker /// </summary> public static void ComputeAndCommitCloseToCloseRatios( string ticker) { DataTable tickerQuotes = Quotes.GetTickerQuotes(ticker); Quotes.ComputeCloseToCloseValues(tickerQuotes); ! Quotes.commitAllCloseToCloseRatios(tickerQuotes); } *************** *** 244,250 **** double adjCTCInSource; double absoluteRelativeDifference; - DataColumn[] columnPrimaryKey = new DataColumn[0]; - columnPrimaryKey[0]= tableSource.Columns["quDate"]; - tableSource.PrimaryKey = columnPrimaryKey; DataRow rowToCheck; for(int i = 0;i != numRows;i++) --- 238,241 ---- *************** *** 256,262 **** { adjCTCInSource = (double)rowToCheck[Quotes.AdjustedCloseToCloseRatio]; ! absoluteRelativeDifference = Math.Abs((adjCTCInDatabase - adjCTCInSource)/adjCTCInSource); ! if(absoluteRelativeDifference > ConstantsProvider.MaxRelativeDifferenceForCloseToCloseRatios ) ! return true; } } --- 247,269 ---- { adjCTCInSource = (double)rowToCheck[Quotes.AdjustedCloseToCloseRatio]; ! if(adjCTCInSource != 0) ! { ! absoluteRelativeDifference = Math.Abs((adjCTCInDatabase - adjCTCInSource)/adjCTCInSource); ! if(absoluteRelativeDifference > ConstantsProvider.MaxRelativeDifferenceForCloseToCloseRatios ) ! { ! Quotes.DateWithDifferentCloseToClose = date; ! return true; ! } ! } ! else if(adjCTCInSource == 0) ! { ! absoluteRelativeDifference = Math.Abs(adjCTCInDatabase - adjCTCInSource); ! if(absoluteRelativeDifference > ConstantsProvider.MaxRelativeDifferenceForCloseToCloseRatios ) ! { ! Quotes.DateWithDifferentCloseToClose = date; ! return true; ! } ! ! } } } *************** *** 271,309 **** ! public static void ComputeCloseToCloseValues(DataTable tableContainingNewAdjustedValues) ! { ! try { ! if(!tableContainingNewAdjustedValues.Columns.Contains(Quotes.AdjustedCloseToCloseRatio)) { ! tableContainingNewAdjustedValues.Columns.Add(Quotes.AdjustedCloseToCloseRatio, ! System.Type.GetType("System.Double")); } ! int numRows = tableContainingNewAdjustedValues.Rows.Count; ! float previousClose; ! float currentClose; ! for(int i = 0;i != numRows;i++) { ! if(i == 0) ! //the first available quote has 0 as closeToClose ratio ! { ! tableContainingNewAdjustedValues.Rows[i][Quotes.AdjustedCloseToCloseRatio] = 0; ! } ! else ! { ! previousClose = (float)tableContainingNewAdjustedValues.Rows[i-1]["quAdjustedClose"]; ! currentClose = (float)tableContainingNewAdjustedValues.Rows[i]["quAdjustedClose"]; ! tableContainingNewAdjustedValues.Rows[i][Quotes.AdjustedCloseToCloseRatio] = ! (currentClose - previousClose)/previousClose; ! } ! } ! ! } ! catch(Exception ex) ! { ! MessageBox.Show(ex.ToString()); } - } --- 278,320 ---- ! public static void ComputeCloseToCloseValues(DataTable tableOfAllQuotesOfAGivenTicker) { ! DataColumn[] columnPrimaryKey = new DataColumn[1]; ! columnPrimaryKey[0]= tableOfAllQuotesOfAGivenTicker.Columns[Quotes.Date]; ! tableOfAllQuotesOfAGivenTicker.PrimaryKey = columnPrimaryKey; ! ! int numRows = tableOfAllQuotesOfAGivenTicker.Rows.Count; ! DataView orderedDyDate = new DataView(tableOfAllQuotesOfAGivenTicker, ! Quotes.AdjustedClose + ">=0", ! Quotes.Date + " ASC", DataViewRowState.CurrentRows); ! float previousClose; ! float currentClose; ! double currentCloseToCloseRatio; ! DateTime date; ! DataRow rowToBeChanged; ! for(int i = 0;i != numRows;i++) { ! date = (DateTime)orderedDyDate[i].Row[Quotes.Date]; ! rowToBeChanged = tableOfAllQuotesOfAGivenTicker.Rows.Find(date); ! if(i == 0) ! //the first available quote has 0 as closeToClose ratio { ! rowToBeChanged[Quotes.AdjustedCloseToCloseRatio] = 0; } ! else { ! previousClose = (float)orderedDyDate[i-1].Row[Quotes.AdjustedClose]; ! currentClose = (float)orderedDyDate[i].Row[Quotes.AdjustedClose]; ! currentCloseToCloseRatio = (double)orderedDyDate[i].Row[Quotes.AdjustedCloseToCloseRatio]; ! ! if(previousClose != 0 && (currentCloseToCloseRatio == 0 && ! (previousClose != currentClose))) ! // if the previouse adj close is not 0 and the current CTC should not be 0 ! // because previous and current are not equal ! rowToBeChanged[Quotes.AdjustedCloseToCloseRatio] = ! (currentClose - previousClose)/previousClose; ! } ! } } *************** *** 520,524 **** } ! /* Now useless, maybe ... /// <summary> /// Returns a DataTable containing ticker, date and adjusted value --- 531,535 ---- } ! /* Now useless /// <summary> /// Returns a DataTable containing ticker, date and adjusted value |