[Quantproject-developers] QuantProject/b3_Data/DataTables Quotes.cs, 1.31, 1.32
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2006-10-07 09:46:27
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv29317/b3_Data/DataTables Modified Files: Quotes.cs Log Message: Added RecalculateCloseToCloseRatios method, in order to recalculate CTC ratios from adjusted close quotes stored in the database. Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Quotes.cs 17 Sep 2006 21:36:09 -0000 1.31 --- Quotes.cs 7 Oct 2006 09:46:22 -0000 1.32 *************** *** 1092,1095 **** --- 1092,1149 ---- // precedingDays ) ); // } + + #region RecalculateCloseToCloseRatios + + private float recalculateCloseToCloseRatios_getAdjCloseJustBeforeCurrentFirstClose() + { + float returnValue = float.MinValue; + DateTime firstCurrentDate = (DateTime)this.Rows[0][Quotes.Date]; + int daysBeforeCurrent = 1; + if(firstCurrentDate > DataAccess.Tables.Quotes.GetFirstQuoteDate(this.Ticker) ) + //there exist other quotes in the database that precede first current quote + { + while(returnValue == float.MinValue) + { + try{ + returnValue = + DataAccess.Tables.Quotes.GetAdjustedClose(this.Ticker, + firstCurrentDate.AddDays( + -daysBeforeCurrent) ); + + } + catch(Exception ex){ex = ex;} + finally{ + daysBeforeCurrent++; + } + } + } + return returnValue; + } + + /// <summary> + /// Recalculate close to close ratios + /// overwriting the value(if present) stored in the + /// database + /// </summary> + /// <returns></returns> + public void RecalculateCloseToCloseRatios() + { + float adjustedCloseJustBeforeTheCurrentFirstClose = + this.recalculateCloseToCloseRatios_getAdjCloseJustBeforeCurrentFirstClose(); + for(int i = 0; i<this.Rows.Count; i++) + { + if(i == 0 && adjustedCloseJustBeforeTheCurrentFirstClose > float.MinValue) + //there exists a valid quote just before the first current close + this.Rows[i][Quotes.AdjustedCloseToCloseRatio] = + (float)this.Rows[i][Quotes.AdjustedClose] / + adjustedCloseJustBeforeTheCurrentFirstClose; + else if(i>0) + this.Rows[i][Quotes.AdjustedCloseToCloseRatio] = + (float)this.Rows[i][Quotes.AdjustedClose] / + (float)this.Rows[i - 1][Quotes.AdjustedClose]; + } + } + #endregion + } } |