[Quantproject-developers] QuantProject/b3_Data/DataTables Quotes.cs,1.24,1.25
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2006-05-14 18:28:29
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv2195/b3_Data/DataTables Modified Files: Quotes.cs Log Message: Added GetArrayCloseToCloseRatios, to be used by the fixed period oscillator strategy (this method will be re-organized soon, yet) Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Quotes.cs 19 Feb 2006 17:58:13 -0000 1.24 --- Quotes.cs 14 May 2006 18:28:24 -0000 1.25 *************** *** 533,536 **** --- 533,558 ---- return tableToReturn; } + + private static float[] getArrayOfCloseToCloseRatios_getAdjustedValues(Quotes sourceQuotes, + int numDaysForHalfPeriod, + ref DateTime firstQuoteDate) + { + float[] returnValue = ExtendedDataTable.GetArrayOfFloatFromColumn(sourceQuotes, "quAdjustedClose"); + //in order to be alligned at the following market day, + //allAdjValues has to be long n, where n is such that + //n%2 * hp + 1 = 2 * hp (hp = half period) + //if some quotes are deleted, first quote day has to be updated + while(returnValue.Length % (2*numDaysForHalfPeriod) + 1 != 2*numDaysForHalfPeriod) + { + float[] newReturnValue = new float[returnValue.Length - 1]; + for(int k = 0;k<returnValue.Length - 1;k++) + newReturnValue[k] = returnValue[k + 1]; + returnValue = newReturnValue; + firstQuoteDate = firstQuoteDate.AddDays(1); + firstQuoteDate = sourceQuotes.GetQuoteDateOrFollowing(firstQuoteDate); + } + return returnValue; + } + /// <summary> /// Gets an array containing close to close ratios *************** *** 544,548 **** /// <returns></returns> public static float[] GetArrayOfCloseToCloseRatios(string ticker, ! DateTime firstQuoteDate, DateTime lastQuoteDate, int numDaysBetweenEachClose, --- 566,570 ---- /// <returns></returns> public static float[] GetArrayOfCloseToCloseRatios(string ticker, ! ref DateTime firstQuoteDate, DateTime lastQuoteDate, int numDaysBetweenEachClose, *************** *** 551,569 **** float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, firstQuoteDate, lastQuoteDate); ! float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); float[] adjValuesMinusInitialMarketDays = new float[allAdjValues.Length - numOfInitialMarketDaysToJump]; for(int k = 0;k<allAdjValues.Length - numOfInitialMarketDaysToJump;k++) adjValuesMinusInitialMarketDays[k] = allAdjValues[k + numOfInitialMarketDaysToJump]; ! ! returnValue = new float[adjValuesMinusInitialMarketDays.Length/(numDaysBetweenEachClose + 1)]; int i = 0; //index for ratesOfReturns array int lastIdxAccessed = 0; for(int idx = 0; ! (idx + numDaysBetweenEachClose) < adjValuesMinusInitialMarketDays.Length; idx += numDaysBetweenEachClose ) { if(idx-lastIdxAccessed>numDaysBetweenEachClose || idx == 0) ! //there is a discontinuity, as wanted { returnValue[i] = (adjValuesMinusInitialMarketDays[idx+numDaysBetweenEachClose]/ --- 573,594 ---- float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, firstQuoteDate, lastQuoteDate); ! //float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); ! float[] allAdjValues = getArrayOfCloseToCloseRatios_getAdjustedValues(tickerQuotes, numDaysBetweenEachClose, ref firstQuoteDate); float[] adjValuesMinusInitialMarketDays = new float[allAdjValues.Length - numOfInitialMarketDaysToJump]; + //fill adjValuesMinusInitialMarketDays array for(int k = 0;k<allAdjValues.Length - numOfInitialMarketDaysToJump;k++) adjValuesMinusInitialMarketDays[k] = allAdjValues[k + numOfInitialMarketDaysToJump]; ! // ! returnValue = new float[adjValuesMinusInitialMarketDays.Length/(numDaysBetweenEachClose * 2)]; int i = 0; //index for ratesOfReturns array int lastIdxAccessed = 0; for(int idx = 0; ! (idx + numDaysBetweenEachClose) < adjValuesMinusInitialMarketDays.Length && i<returnValue.Length; idx += numDaysBetweenEachClose ) { if(idx-lastIdxAccessed>numDaysBetweenEachClose || idx == 0) ! //the current ratio is computed only if the first close, pointed by idx, is ! //not the second close of the previous ratio { returnValue[i] = (adjValuesMinusInitialMarketDays[idx+numDaysBetweenEachClose]/ *************** *** 577,585 **** public static float[] GetArrayOfCloseToCloseRatios(string ticker, ! DateTime firstQuoteDate, DateTime lastQuoteDate, int numDaysBetweenEachClose) { ! return GetArrayOfCloseToCloseRatios(ticker, firstQuoteDate, lastQuoteDate, numDaysBetweenEachClose, 0); } --- 602,610 ---- public static float[] GetArrayOfCloseToCloseRatios(string ticker, ! ref DateTime firstQuoteDate, DateTime lastQuoteDate, int numDaysBetweenEachClose) { ! return GetArrayOfCloseToCloseRatios(ticker, ref firstQuoteDate, lastQuoteDate, numDaysBetweenEachClose, 0); } *************** *** 596,604 **** if(!setOfTickers.Columns.Contains("CloseToCloseCorrelationToBenchmark")) setOfTickers.Columns.Add("CloseToCloseCorrelationToBenchmark", System.Type.GetType("System.Double")); ! float[] benchmarkRatios = GetArrayOfCloseToCloseRatios(benchmark, firstQuoteDate, lastQuoteDate, numDaysBetweenEachClose); foreach(DataRow row in setOfTickers.Rows) { float[] tickerRatios = GetArrayOfCloseToCloseRatios((string)row[0], ! firstQuoteDate, lastQuoteDate, numDaysBetweenEachClose ); if(tickerRatios.Length == benchmarkRatios.Length) row["CloseToCloseCorrelationToBenchmark"] = --- 621,629 ---- if(!setOfTickers.Columns.Contains("CloseToCloseCorrelationToBenchmark")) setOfTickers.Columns.Add("CloseToCloseCorrelationToBenchmark", System.Type.GetType("System.Double")); ! float[] benchmarkRatios = GetArrayOfCloseToCloseRatios(benchmark, ref firstQuoteDate, lastQuoteDate, numDaysBetweenEachClose); foreach(DataRow row in setOfTickers.Rows) { float[] tickerRatios = GetArrayOfCloseToCloseRatios((string)row[0], ! ref firstQuoteDate, lastQuoteDate, numDaysBetweenEachClose ); if(tickerRatios.Length == benchmarkRatios.Length) row["CloseToCloseCorrelationToBenchmark"] = |