[Quantproject-developers] QuantProject/b3_Data/DataProviders HistoricalDataProvider.cs,1.7,1.8
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:42:33
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28522/b3_Data/DataProviders Modified Files: HistoricalDataProvider.cs Log Message: The private Cache privateCache object is used now Index: HistoricalDataProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/HistoricalDataProvider.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** HistoricalDataProvider.cs 20 Jan 2005 01:21:21 -0000 1.7 --- HistoricalDataProvider.cs 26 May 2005 23:42:25 -0000 1.8 *************** *** 24,29 **** --- 24,31 ---- using System.Collections; using System.Data; + using QuantProject.ADT; using QuantProject.ADT.Histories; + using QuantProject.Data.DataProviders.Caching; using QuantProject.DataAccess; using QuantProject.DataAccess.Tables; *************** *** 36,40 **** public class HistoricalDataProvider { ! private static Hashtable cachedHistories = new Hashtable(); public HistoricalDataProvider() --- 38,66 ---- public class HistoricalDataProvider { ! private static Hashtable cachedHistories = new Hashtable(); ! ! private static Cache privateCache = new Cache(); ! ! ! private static DateTime minDate = DateTime.MinValue; ! private static DateTime maxDate = DateTime.MaxValue; ! ! /// <summary> ! /// When defined, sets the minimum DateTime to be cached ! /// </summary> ! public static DateTime MinDate ! { ! get { return minDate; } ! set { minDate = value; } ! } ! ! /// <summary> ! /// When defined, sets the maximum DateTime to be cached ! /// </summary> ! public static DateTime MaxDate ! { ! get { return maxDate; } ! set { maxDate = value; } ! } public HistoricalDataProvider() *************** *** 97,100 **** --- 123,140 ---- } + private static History getHistory( string ticker , QuoteField quoteField , + DateTime firstDate , DateTime lastDate ) + { + History returnValue = new History(); + DateTime currentDate = firstDate; + while ( currentDate <= lastDate ) + { + returnValue.Add( currentDate , privateCache.GetQuote( + ticker , currentDate , quoteField ) ); + currentDate = currentDate.AddDays( 1 ); + } + return returnValue; + } + public static History GetOpenHistory( string instrumentKey ) { *************** *** 122,125 **** --- 162,186 ---- } + public static History GetAdjustedCloseHistory( string ticker , + DateTime firstDate , DateTime lastDate ) + { + return getHistory( ticker , QuoteField.AdjustedClose , + firstDate , lastDate ); + } + + private static History cache_getHistory( string instrumentKey , QuoteField quoteField ) + { + History returnValue; + if ( ( MinDate != DateTime.MinValue ) && + ( MaxDate != DateTime.MaxValue ) ) + // the script has set a min date value and a max date value for the historical quotes + returnValue = DataBase.GetHistory( instrumentKey , quoteField , + MinDate , MaxDate ); + else + // the script has NOT set a min date value and a max date value for the historical quotes + returnValue = DataBase.GetHistory( instrumentKey , quoteField ); + return returnValue; + } + private static void cache( string instrumentKey , QuoteField quoteField ) { *************** *** 127,132 **** // no component at all for the instrument instrumentKey has been cached yet cachedHistories.Add( instrumentKey , new Hashtable() ); ((Hashtable)cachedHistories[ instrumentKey ]).Add( quoteField , ! DataBase.GetHistory( instrumentKey , quoteField ) ); } // public static double GetMarketValue( string instrumentKey , ExtendedDateTime extendedDateTime ) --- 188,194 ---- // no component at all for the instrument instrumentKey has been cached yet cachedHistories.Add( instrumentKey , new Hashtable() ); + History quoteHistory = cache_getHistory( instrumentKey , quoteField ); ((Hashtable)cachedHistories[ instrumentKey ]).Add( quoteField , ! quoteHistory ); } // public static double GetMarketValue( string instrumentKey , ExtendedDateTime extendedDateTime ) *************** *** 176,180 **** { double returnValue; ! double adjustedClose = getQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.AdjustedClose ); if ( extendedDateTime.BarComponent == BarComponent.Close ) --- 238,242 ---- { double returnValue; ! double adjustedClose = privateCache.GetQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.AdjustedClose ); if ( extendedDateTime.BarComponent == BarComponent.Close ) *************** *** 183,189 **** // extendedDateTime.BarComponent is equal to BarComponent.Open { ! double open = getQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.Open ); ! double close = getQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.Close ); returnValue = open * adjustedClose / close; --- 245,251 ---- // extendedDateTime.BarComponent is equal to BarComponent.Open { ! double open = privateCache.GetQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.Open ); ! double close = privateCache.GetQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.Close ); returnValue = open * adjustedClose / close; *************** *** 209,221 **** return returnValue; } ! public static bool WasExchanged( string instrumentKey , ExtendedDateTime extendedDateTime ) { ! ExtendedDateTime atClose = new ExtendedDateTime( ! extendedDateTime.DateTime , BarComponent.Close ); ! double marketValue = GetRawMarketValue( instrumentKey , ! atClose ); // forces caching if needed ! return ( (History) ((Hashtable) ! cachedHistories[ instrumentKey ])[ QuoteField.Close ] ).ContainsKey( ! extendedDateTime.DateTime ); } --- 271,288 ---- return returnValue; } ! // public static bool WasExchanged( string instrumentKey , ExtendedDateTime extendedDateTime ) ! // { ! // ExtendedDateTime atClose = new ExtendedDateTime( ! // extendedDateTime.DateTime , BarComponent.Close ); ! // double marketValue = GetRawMarketValue( instrumentKey , ! // atClose ); // forces caching if needed ! // History instrumentQuotes = ! // (History)((Hashtable)cachedHistories[ instrumentKey ])[ QuoteField.Close ]; ! // bool returnValue = instrumentQuotes.ContainsKey( extendedDateTime.DateTime ); ! // return returnValue; ! // } ! public static bool WasExchanged( string ticker , ExtendedDateTime extendedDateTime ) { ! return privateCache.WasExchanged( ticker , extendedDateTime ); } |