quantproject-developers Mailing List for QuantProject (Page 31)
Brought to you by:
glauco_1
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(7) |
Nov
(103) |
Dec
(67) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(52) |
Feb
(9) |
Mar
(69) |
Apr
(53) |
May
(80) |
Jun
(23) |
Jul
(24) |
Aug
(112) |
Sep
(9) |
Oct
|
Nov
(58) |
Dec
(93) |
| 2005 |
Jan
(90) |
Feb
(93) |
Mar
(61) |
Apr
(56) |
May
(37) |
Jun
(61) |
Jul
(55) |
Aug
(68) |
Sep
(25) |
Oct
(46) |
Nov
(41) |
Dec
(37) |
| 2006 |
Jan
(33) |
Feb
(7) |
Mar
(19) |
Apr
(27) |
May
(73) |
Jun
(49) |
Jul
(83) |
Aug
(66) |
Sep
(45) |
Oct
(16) |
Nov
(15) |
Dec
(7) |
| 2007 |
Jan
(14) |
Feb
(33) |
Mar
|
Apr
(21) |
May
|
Jun
(34) |
Jul
(18) |
Aug
(100) |
Sep
(39) |
Oct
(55) |
Nov
(12) |
Dec
(2) |
| 2008 |
Jan
(120) |
Feb
(133) |
Mar
(129) |
Apr
(104) |
May
(42) |
Jun
(2) |
Jul
(52) |
Aug
(99) |
Sep
(134) |
Oct
|
Nov
(137) |
Dec
(48) |
| 2009 |
Jan
(48) |
Feb
(55) |
Mar
(61) |
Apr
(3) |
May
(2) |
Jun
(1) |
Jul
|
Aug
(51) |
Sep
|
Oct
(7) |
Nov
|
Dec
|
| 2010 |
Jan
(7) |
Feb
(1) |
Mar
(145) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
| 2011 |
Jan
(78) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(88) |
Sep
(6) |
Oct
(1) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:36:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv19578/b7_Scripts/WalkForwardTesting/PairsTrading Modified Files: PairsTradingMain.cs Log Message: The test has been changed to use intraday data, out of sample Index: PairsTradingMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/PairsTradingMain.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** PairsTradingMain.cs 29 Sep 2008 21:21:34 -0000 1.18 --- PairsTradingMain.cs 8 Nov 2008 20:36:36 -0000 1.19 *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 37,40 **** --- 37,41 ---- using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; + using QuantProject.Data.DataProviders.Bars.Caching; using QuantProject.Presentation; using QuantProject.Scripts.General; *************** *** 68,77 **** this.historicalMarketValueProviderForChosingPositionsOutOfSample = ! new HistoricalAdjustedQuoteProvider(); // this.historicalQuoteProviderForChosingPositionsOutOfSample = // new HistoricalRawQuoteProvider(); this.historicalMarketValueProviderForTheBacktesterAccount = ! new HistoricalRawQuoteProvider(); // this.historicalQuoteProviderForTheBacktesterAccount = // new HistoricalAdjustedQuoteProvider(); --- 69,82 ---- this.historicalMarketValueProviderForChosingPositionsOutOfSample = ! this.getHistoricalBarProvider(); ! // this.historicalMarketValueProviderForChosingPositionsOutOfSample = ! // new HistoricalAdjustedQuoteProvider(); // this.historicalQuoteProviderForChosingPositionsOutOfSample = // new HistoricalRawQuoteProvider(); this.historicalMarketValueProviderForTheBacktesterAccount = ! this.historicalMarketValueProviderForChosingPositionsOutOfSample; ! // this.historicalMarketValueProviderForTheBacktesterAccount = ! // new HistoricalRawQuoteProvider(); // this.historicalQuoteProviderForTheBacktesterAccount = // new HistoricalAdjustedQuoteProvider(); *************** *** 80,83 **** --- 85,117 ---- // IEquityEvaluator equityEvaluator = new SharpeRatio(); } + + #region getHistoricalBarProvider + + #region getBarCache + private DateTime[] getDailyTimes() + { + DateTime[] dailyTimes = { + new DateTime( 1900 , 1 , 1 , 10 , 0 , 0 ) , + new DateTime( 1900 , 1 , 1 , 10 , 30 , 0 ) , + new DateTime( 1900 , 1 , 1 , 11 , 0 , 0 ) + }; + return dailyTimes; + } + private IBarCache getBarCache() + { + DateTime[] dailyTimes = this.getDailyTimes(); + IBarCache barCache = new DailyBarCache( 60 , dailyTimes ); + return barCache; + } + #endregion getBarCache + + private HistoricalBarProvider getHistoricalBarProvider() + { + IBarCache barCache = getBarCache(); + HistoricalBarProvider historicalBarProvider = + new HistoricalBarProvider( barCache ); + return historicalBarProvider; + } + #endregion getHistoricalBarProvider protected override IEligiblesSelector getEligiblesSelector() *************** *** 101,109 **** eligiblesSelector = new ByPriceMostLiquidLessVolatileOTCAlwaysQuoted( ! tickersGroupId , ! true , ! maxNumberOfEligiblesToBeChosen , ! maxNumberOfEligiblesToBeChosen + 50 , ! 10 , 10 , 20 , 75 ); --- 135,143 ---- eligiblesSelector = new ByPriceMostLiquidLessVolatileOTCAlwaysQuoted( ! tickersGroupId , ! true , ! maxNumberOfEligiblesToBeChosen , ! maxNumberOfEligiblesToBeChosen + 50 , ! 10 , 10 , 20 , 75 ); *************** *** 137,148 **** IInSampleChooser inSampleChooser = new PairsTradingGeneticChooser( ! numberOfBestTestingPositionsToBeReturned , ! this.benchmark , ! decoderForWeightedPositions , fitnessEvaluator , ! this.historicalMarketValueProviderForInSample , ! crossoverRate , mutationRate , elitismRate , ! populationSizeForGeneticOptimizer , ! generationNumberForGeneticOptimizer , ! seedForRandomGenerator ); inSampleChooser = --- 171,182 ---- IInSampleChooser inSampleChooser = new PairsTradingGeneticChooser( ! numberOfBestTestingPositionsToBeReturned , ! this.benchmark , ! decoderForWeightedPositions , fitnessEvaluator , ! this.historicalMarketValueProviderForInSample , ! crossoverRate , mutationRate , elitismRate , ! populationSizeForGeneticOptimizer , ! generationNumberForGeneticOptimizer , ! seedForRandomGenerator ); inSampleChooser = *************** *** 187,191 **** OutOfSampleChooser outOfSampleChooser = new OutOfSampleChooserForSingleLongAndShort( ! 0.006 , 0.02 , 0.006 , 0.02 ); // outOfSampleChooser = // new OutOfSampleChooserForExactNumberOfBestLongPositions( --- 221,225 ---- OutOfSampleChooser outOfSampleChooser = new OutOfSampleChooserForSingleLongAndShort( ! 0.006 , 0.02 , 0.006 , 0.02 ); // outOfSampleChooser = // new OutOfSampleChooserForExactNumberOfBestLongPositions( *************** *** 194,203 **** IStrategyForBacktester strategyForBacktester = new PairsTradingStrategy( ! 7 , inSampleDays , ! intervalsSelectorForInSample , intervalsSelectorForOutOfSample , ! eligiblesSelector , inSampleChooser , ! this.historicalMarketValueProviderForInSample , ! this.historicalMarketValueProviderForChosingPositionsOutOfSample , ! outOfSampleChooser ); // IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = // new PairsTradingStrategy( --- 228,237 ---- IStrategyForBacktester strategyForBacktester = new PairsTradingStrategy( ! 7 , inSampleDays , ! intervalsSelectorForInSample , intervalsSelectorForOutOfSample , ! eligiblesSelector , inSampleChooser , ! this.historicalMarketValueProviderForInSample , ! this.historicalMarketValueProviderForChosingPositionsOutOfSample , ! outOfSampleChooser ); // IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = // new PairsTradingStrategy( *************** *** 224,228 **** DateTime firstDateTime = new DateTime( 2001 , 1 , 1 ); ! firstDateTime = new DateTime( 2006 , 8 , 1 ); DateTime lastDateTime = new DateTime( 2008 , 4 , 30 ); --- 258,262 ---- DateTime firstDateTime = new DateTime( 2001 , 1 , 1 ); ! firstDateTime = new DateTime( 2006 , 8 , 1 ); DateTime lastDateTime = new DateTime( 2008 , 4 , 30 ); *************** *** 235,243 **** EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.strategyForBacktester , ! this.historicalMarketValueProviderForTheBacktesterAccount , ! accountProvider , ! firstDateTime , lastDateTime , ! this.benchmark , cashToStart , maxRunningHours ); return endOfDayStrategyBackTester; } --- 269,277 ---- EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.strategyForBacktester , ! this.historicalMarketValueProviderForTheBacktesterAccount , ! accountProvider , ! firstDateTime , lastDateTime , ! this.benchmark , cashToStart , maxRunningHours ); return endOfDayStrategyBackTester; } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:31:22
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv19322/b2_DataAccess Modified Files: SQLBuilder.cs Log Message: the following method has been added internal static string GetDateTimeConstant( DateTime dateTime ) the following method has been added public static string GetTimeConstant( DateTime dateTime ) the following method has been added internal static string GetFilterForTime( string fieldName , SqlComparisonOperator sqlComparisonOperator , DateTime time ) Index: SQLBuilder.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/SQLBuilder.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SQLBuilder.cs 13 Oct 2003 21:58:01 -0000 1.1.1.1 --- SQLBuilder.cs 8 Nov 2008 20:31:17 -0000 1.2 *************** *** 3,7 **** SQLBuilder.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- SQLBuilder.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,26 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; namespace QuantProject.DataAccess { --- 19,28 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; + using QuantProject.ADT; + namespace QuantProject.DataAccess { *************** *** 37,47 **** } ! internal static string GetDateConstant( DateTime dateTime ) ! { ! string getDateConstant; ! getDateConstant = "#" + dateTime.Month + "/" + dateTime.Day + "/" + ! dateTime.Year + "#"; ! return getDateConstant; ! } } } --- 39,153 ---- } ! internal static string GetDateConstant( DateTime dateTime ) ! { ! string getDateConstant; ! getDateConstant = "#" + dateTime.Month + "/" + dateTime.Day + "/" + ! dateTime.Year + "#"; ! return getDateConstant; ! } ! ! /// <summary> ! /// returns a string to be used as a DateTime constant for a query ! /// for an Access database ! /// </summary> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! internal static string GetDateTimeConstant( DateTime dateTime ) ! { ! string dateTimeConstant = ! "#" + ! dateTime.Month + "/" + ! dateTime.Day + "/" + ! dateTime.Year + " " + ! dateTime.Hour + ":" + ! dateTime.Minute + ":" + ! dateTime.Second + ! "#"; ! return dateTimeConstant; ! } ! ! #region GetTimeConstant ! public static string GetTimeConstant( DateTime dateTime ) ! { ! string timeConstant = ! "'" + ! dateTime.Hour.ToString( "00" ) + "." + ! dateTime.Minute.ToString( "00" ) + "." + ! dateTime.Second.ToString( "00" ) + "'"; ! return timeConstant; ! } ! #endregion GetTimeConstant ! ! #region GetFilterForTime ! private static void getFilterForTime_checkParameters( DateTime time ) ! { ! // if ( ( comparisonOperator != "=" ) && ! // ( comparisonOperator != "<" ) && ! // ( comparisonOperator != "<=" ) && ! // ( comparisonOperator != ">" ) && ! // ( comparisonOperator != ">=" ) ) ! // throw new Exception( ! // "comparisonOperator can either be '=' or '<' or '<=' or '>' or '>='" ); ! if ( !ExtendedDateTime.IsTime( time ) ) ! throw new Exception( ! "time is actually not a time. Use the method " + ! "QuantProject.ADT.ExtendedDateTime.GetTime() to build your time" ); ! } ! ! #region getFilterForTime_actually ! private static string getSqlStringForComparisonOperator( ! SqlComparisonOperator sqlComparisonOperator ) ! { ! string sqlStringForComparisonOperator = ""; ! switch( sqlComparisonOperator ) ! { ! case SqlComparisonOperator.Equal: ! sqlStringForComparisonOperator = "="; ! break; ! case SqlComparisonOperator.LessThan: ! sqlStringForComparisonOperator = "<"; ! break; ! case SqlComparisonOperator.LessThanOrEqual: ! sqlStringForComparisonOperator = "<="; ! break; ! case SqlComparisonOperator.GreaterThan: ! sqlStringForComparisonOperator = ">"; ! break; ! case SqlComparisonOperator.GreaterThanOrEqual: ! sqlStringForComparisonOperator = ">="; ! break; ! } ! return sqlStringForComparisonOperator; ! } ! private static string getFilterForTime_actually( ! string fieldName , SqlComparisonOperator sqlComparisonOperator , DateTime time ) ! { ! string filterForDailyTime = ! "(Format([baDateTimeForOpen],'hh:mm:ss')" + ! SQLBuilder.getSqlStringForComparisonOperator( sqlComparisonOperator ) + ! SQLBuilder.GetTimeConstant( time ); ! return filterForDailyTime; ! } ! #endregion getFilterForTime_actually ! ! /// <summary> ! /// returns a sql where expression, to compare a field value with ! /// the given time ! /// </summary> ! /// <param name="fieldName"></param> ! /// <param name="comparisonOperator">it can either be "=" or "<" or ! /// "<=" or ">" or ">="</param> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! internal static string GetFilterForTime( ! string fieldName , SqlComparisonOperator sqlComparisonOperator , DateTime time ) ! { ! SQLBuilder.getFilterForTime_checkParameters( time ); ! string filterForTime = ! SQLBuilder.getFilterForTime_actually( ! fieldName , sqlComparisonOperator , time ); ! return filterForTime; ! } ! #endregion GetFilterForTime } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:29:14
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv19134/b2_DataAccess Modified Files: DataBase.cs Log Message: the following method has been added public static History GetBarOpenHistory( string ticker , int barInterval , DateTime firstDateTime , DateTime lastDateTime , DateTime[] dailyTimes ) Index: DataBase.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/DataBase.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** DataBase.cs 29 Sep 2008 21:12:37 -0000 1.9 --- DataBase.cs 8 Nov 2008 20:29:09 -0000 1.10 *************** *** 3,7 **** DataBase.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- DataBase.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 83,89 **** } ! #region "GetHistory" private static History getHistory_try( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { History history = new History(); --- 83,89 ---- } ! #region "GetHistory" private static History getHistory_try( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { History history = new History(); *************** *** 99,103 **** } private static History getHistory_common( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { History history; --- 99,103 ---- } private static History getHistory_common( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { History history; *************** *** 135,139 **** /// <returns>The history for the given instrument and quote field</returns> public static History GetHistory( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { return getHistory_common( instrumentKey , quoteField , firstDate , lastDate ); --- 135,139 ---- /// <returns>The history for the given instrument and quote field</returns> public static History GetHistory( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { return getHistory_common( instrumentKey , quoteField , firstDate , lastDate ); *************** *** 141,145 **** #endregion public static double GetQuote( string ticker , ! QuoteField quoteField , DateTime dateTime ) { double quote = Double.MinValue; --- 141,145 ---- #endregion public static double GetQuote( string ticker , ! QuoteField quoteField , DateTime dateTime ) { double quote = Double.MinValue; *************** *** 164,168 **** } public static bool WasExchanged( string ticker , ! DateTime dateTime ) { string sqlQuery = --- 164,168 ---- } public static bool WasExchanged( string ticker , ! DateTime dateTime ) { string sqlQuery = *************** *** 182,185 **** --- 182,304 ---- return ( quotes.Rows.Count > 0 ); } + + #region getHistory + private static History getHistory( + DataTable barDataTable , string barFieldName ) + { + History history = new History(); + history.Import( + barDataTable , BarFieldNames.DateTimeForOpen , barFieldName ); + return history; + } + #endregion getHistory + + #region GetBarOpenHistory + + #region getBarDataTable + + #region getSqlForBarDataTable + + #region getFilterForDailyTimes + + // #region getFilterForDailyTime + // private getFilterForDailyTime( DateTime dateTime ) + // { + // string filterForDailyTime = + // "(Format([baDateTimeForOpen],'hh:mm:ss')>='" + + // this.getSqlTimeConstantForFirstDailyBar() + "')"; + // } + // #endregion getFilterForDailyTime + + private static string getFilterForDailyTimes( DateTime[] dailyTimes ) + { + string filterForDailyTimes = ""; + foreach( DateTime dateTime in dailyTimes ) + filterForDailyTimes = + filterForDailyTimes + + SQLBuilder.GetFilterForTime( + "baDateTimeForOpen" , SqlComparisonOperator.Equal , dateTime ) + + " and "; + filterForDailyTimes = filterForDailyTimes.Substring( + 0 , filterForDailyTimes.Length - " and ".Length ); + return filterForDailyTimes; + } + #endregion getFilterForDailyTimes + + private static string getSqlForBarDataTable( + string ticker , + int barInterval , + string barFieldName , + DateTime firstDateTime , + DateTime lastDateTime , + DateTime[] dailyTimes ) + { + string sql = + "select baOpen from bars " + + "where (baTicker='" + ticker + "') and " + + "(baInterval=" + barInterval + ") and" + + "(baDateTimeForOpen>=" + + SQLBuilder.GetDateTimeConstant( firstDateTime ) + ") and" + + "(baDateTimeForOpen<=" + + SQLBuilder.GetDateTimeConstant( lastDateTime ) + + ") and" + + DataBase.getFilterForDailyTimes( dailyTimes ); + // "(Format([baDateTimeForOpen],'hh:mm:ss')>='" + + // DataBase.getSqlTimeConstantForFirstDailyBar() + "') and" + + // "(Format([baDateTimeForOpen],'hh:mm:ss')<='" + + // DataBase.getSqlTimeConstantForLastDailyBar() + "');"; + return sql; + } + #endregion getSqlForBarDataTable + + private static DataTable getBarDataTable( + string ticker , + int barInterval , + string barFieldName , + DateTime firstDateTime , + DateTime lastDateTime , + DateTime[] dailyTimes ) + { + string sql = DataBase.getSqlForBarDataTable( + ticker , + barInterval , + barFieldName , + firstDateTime , + lastDateTime , + dailyTimes ); + DataTable barDataTable = SqlExecutor.GetDataTable( sql ); + return barDataTable; + } + #endregion getBarDataTable + + /// <summary> + /// returns the market value for the given ticker, for all days in the given + /// interval, at the open of all the bars that begin at dailyTimes + /// </summary> + /// <param name="ticker"></param> + /// <param name="barInterval"></param> + /// <param name="firstDateTime"></param> + /// <param name="lastDateTime"></param> + /// <param name="dailyTimes"></param> + /// <returns></returns> + public static History GetBarOpenHistory( + string ticker , + int barInterval , + DateTime firstDateTime , + DateTime lastDateTime , + DateTime[] dailyTimes ) + { + DataTable barDataTable = DataBase.getBarDataTable( + ticker , + barInterval , + BarFieldNames.Open , + firstDateTime , + lastDateTime , + dailyTimes ); + History barOpenHistory = DataBase.getHistory( + barDataTable , BarFieldNames.Open ); + return barOpenHistory; + } + #endregion GetBarOpenHistory } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:27:52
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv19066/b1_ADT Modified Files: ExtendedDateTime.cs Log Message: the method public static bool IsTime( DateTime dateTime ) has been added the method public static DateTime GetTime( DateTime dateTime ) has been added Index: ExtendedDateTime.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ExtendedDateTime.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ExtendedDateTime.cs 29 Sep 2008 21:12:25 -0000 1.7 --- ExtendedDateTime.cs 8 Nov 2008 20:27:25 -0000 1.8 *************** *** 3,7 **** ExtendedDateTime.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- ExtendedDateTime.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 29,34 **** /// Summary description for DateTime. /// </summary> ! public static class ExtendedDateTime ! { /// <summary> /// Returns a DateTime short description suitable for file names (no slashes) --- 29,34 ---- /// Summary description for DateTime. /// </summary> ! public static class ExtendedDateTime ! { /// <summary> /// Returns a DateTime short description suitable for file names (no slashes) *************** *** 101,105 **** dateTime.Hour , dateTime.Minute , dateTime.Second ); return newDateTime; ! } public static bool IsDate( DateTime dateTime ) --- 101,105 ---- dateTime.Hour , dateTime.Minute , dateTime.Second ); return newDateTime; ! } public static bool IsDate( DateTime dateTime ) *************** *** 113,116 **** --- 113,128 ---- /// <summary> + /// true iif the given dateTime can be interpreted as a time + /// </summary> + /// <param name="dateTime"></param> + /// <returns></returns> + public static bool IsTime( DateTime dateTime ) + { + bool isTime = + ( dateTime == ExtendedDateTime.GetTime( dateTime ) ); + return isTime; + } + + /// <summary> /// True iff the time for the first argument is equal /// to the time for the second argument *************** *** 129,134 **** } ! #region IsFirstTimeLessThenSecondTime ! private static DateTime getTime( DateTime dateTime ) { DateTime time = new DateTime( --- 141,151 ---- } ! /// <summary> ! /// Returns a standardized version of a given DateTime, that will ! /// be interpreted as a time ! /// </summary> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! public static DateTime GetTime( DateTime dateTime ) { DateTime time = new DateTime( *************** *** 137,140 **** --- 154,158 ---- return time; } + /// <summary> /// true iif the time for dateTime1 is less than the time *************** *** 146,156 **** DateTime dateTime1 , DateTime dateTime2 ) { ! DateTime time1 = ExtendedDateTime.getTime( dateTime1 ); ! DateTime time2 = ExtendedDateTime.getTime( dateTime2 ); bool isFirstTimeLessThenSecondTime = ( time1 < time2 ); return isFirstTimeLessThenSecondTime; } - #endregion IsFirstTimeLessThenSecondTime } } --- 164,173 ---- DateTime dateTime1 , DateTime dateTime2 ) { ! DateTime time1 = ExtendedDateTime.GetTime( dateTime1 ); ! DateTime time2 = ExtendedDateTime.GetTime( dateTime2 ); bool isFirstTimeLessThenSecondTime = ( time1 < time2 ); return isFirstTimeLessThenSecondTime; } } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:26:32
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv19007/b4_Business Modified Files: Business_SD.csproj Log Message: a07_DataProviders\HistoricalBarProvider.cs has been added Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Business_SD.csproj 29 Sep 2008 21:03:22 -0000 1.29 --- Business_SD.csproj 8 Nov 2008 20:26:04 -0000 1.30 *************** *** 47,50 **** --- 47,51 ---- <ItemGroup> <Compile Include="a05_Timing\Timer.cs" /> + <Compile Include="a07_DataProviders\HistoricalBarProvider.cs" /> <Compile Include="a07_DataProviders\HistoricalMarketValueProvider.cs" /> <Compile Include="a07_DataProviders\TickerNotExchangedException.cs" /> |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:25:42
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18974/b4_Business/a07_DataProviders Added Files: HistoricalBarProvider.cs Log Message: Returns historical bars --- NEW FILE: HistoricalBarProvider.cs --- /* QuantProject - Quantitative Finance Library HistoricalBarProvider.cs Copyright (C) 2008 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Data.DataProviders.Bars.Caching; namespace QuantProject.Business.DataProviders { /// <summary> /// Returns historical bars /// </summary> public class HistoricalBarProvider : HistoricalMarketValueProvider { private QuantProject.Data.DataProviders.Bars.HistoricalBarProvider historicalBarProvider; public HistoricalBarProvider( IBarCache barCache ) { this.historicalBarProvider = new QuantProject.Data.DataProviders.Bars.HistoricalBarProvider( barCache ); } public override double GetMarketValue( string ticker , DateTime dateTime ) { double marketValue = this.historicalBarProvider.GetMarketValue( ticker , dateTime ); return marketValue; } protected override string getDescription() { return "barProvider"; } } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:24:45
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18928 Added Files: MissingBarException.cs Log Message: Thrown when a bar is requested, but it is not present in the database --- NEW FILE: MissingBarException.cs --- /* QuantProject - Quantitative Finance Library MissingBarException.cs Copyright (C) 2008 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Data.DataProviders.Bars { /// <summary> /// Thrown when a bar is requested, but it is not present in /// the database /// </summary> public class MissingBarException : Exception { private string ticker; private DateTime dateTimeForOpen; private int barInterval; public override string Message { get { return "The database doesn't contain a bar for the ticker " + this.ticker + ", that begins at the DateTime " + this.dateTimeForOpen.ToString() + " and with an interval of " + this.barInterval + " seconds"; } } public MissingBarException( string ticker , DateTime dateTimeForOpen , int barInterval ) { this.ticker = ticker; this.dateTimeForOpen = dateTimeForOpen; this.barInterval = barInterval; } } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:24:14
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18899 Added Files: HistoricalBarProvider.cs Log Message: Returns historical bars, playing with caching --- NEW FILE: HistoricalBarProvider.cs --- /* QuantProject - Quantitative Finance Library HistoricalBarProvider.cs Copyright (C) 2008 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Data.DataProviders.Bars.Caching; namespace QuantProject.Data.DataProviders.Bars { /// <summary> /// Returns historical bars, playing with caching /// </summary> public class HistoricalBarProvider { IBarCache barCache; public HistoricalBarProvider( IBarCache barCache ) { this.barCache = barCache; } public double GetMarketValue( string ticker , DateTime dateTime ) { double marketValue = barCache.GetMarketValue( ticker , dateTime ); return marketValue; } } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:22:40
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18791/b3_Data Modified Files: Data_SD.csproj Log Message: - DataProviders\Bars\Caching\BarCacheData.cs has been added - DataProviders\Bars\Caching\DailyBarCache.cs has been added - DataProviders\Bars\Caching\IBarCache.cs has been added - DataProviders\Bars\HistoricalBarProvider.cs has been added - DataProviders\Bars\MissingBarException.cs has been added Index: Data_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Data_SD.csproj,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Data_SD.csproj 29 Sep 2008 21:09:27 -0000 1.3 --- Data_SD.csproj 8 Nov 2008 20:22:11 -0000 1.4 *************** *** 46,49 **** --- 46,54 ---- <ItemGroup> <Compile Include="AssemblyInfo.cs" /> + <Compile Include="DataProviders\Bars\Caching\BarCacheData.cs" /> + <Compile Include="DataProviders\Bars\Caching\DailyBarCache.cs" /> + <Compile Include="DataProviders\Bars\Caching\IBarCache.cs" /> + <Compile Include="DataProviders\Bars\HistoricalBarProvider.cs" /> + <Compile Include="DataProviders\Bars\MissingBarException.cs" /> <Compile Include="DataProviders\Quotes\HistoricalQuotesProvider.cs" /> <Compile Include="DataProviders\Quotes\MarketStatusSwitch.cs" /> *************** *** 100,103 **** --- 105,110 ---- <Name>b1_ADT</Name> </ProjectReference> + <Folder Include="DataProviders\Bars" /> + <Folder Include="DataProviders\Bars\Caching" /> <Folder Include="DataProviders\Quotes" /> <Folder Include="Selectors\ByLinearIndipendence" /> |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:20:24
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars/Caching In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18606 Added Files: IBarCache.cs Log Message: Interface to be implemented by caches for bars --- NEW FILE: IBarCache.cs --- /* QuantProject - Quantitative Finance Library IBarCache.cs Copyright (C) 2008 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Data.DataProviders.Bars.Caching { /// <summary> /// Interface to be implemented by caches for bars /// </summary> public interface IBarCache { double GetMarketValue( string ticker , DateTime dateTime ); } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:20:06
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars/Caching In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18479 Added Files: DailyBarCache.cs Log Message: Caches bar values for some days, for the given times --- NEW FILE: DailyBarCache.cs --- /* QuantProject - Quantitative Finance Library DailyBarCache.cs Copyright (C) 2008 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using QuantProject.ADT; using QuantProject.ADT.Histories; using QuantProject.DataAccess; namespace QuantProject.Data.DataProviders.Bars.Caching { /// <summary> /// Caches bar values for some days, for the given times /// </summary> public class DailyBarCache : IBarCache { private int barInterval; private DateTime[] dailyTimes; private int roughNumberOfItemsToBeCachedWithASingleQuery; private BarCacheData barOpenValues; // private int numberOfBarsIn_barOpenValues; // private int maxNumberOfItemsIn_barOpenValues; // private int numberOfItemsToBeRemovedFrom_barOpenValues_whenCacheIsCleanedUp; // List<DateTime> dateTimesForCleaningUp_barOpenValues; // List<string> tickersForCleaningUp_barOpenValues; private BarCacheData barsMissingInTheDatabase; // private int numberOfBarsIn_barsMissingInTheDatabase; // private int maxNumberOfItemsIn_barsMissingInTheDatabase; // private int numberOfItemsToBeRemovedFrom_barsMissingInTheDatabase_whenCacheIsCleanedUp; // List<DateTime> dateTimesForCleaningUp_barsMissingInTheDatabase; // List<string> tickersForCleaningUp_barsMissingInTheDatabase; public DailyBarCache( int barInterval , DateTime[] dailyTimes ) { this.checkParameters( dailyTimes ); this.barInterval = barInterval; this.dailyTimes = dailyTimes; this.roughNumberOfItemsToBeCachedWithASingleQuery = 100; int maxNumberOfItemsIn_barOpenValues = 100000; int numberOfItemsToBeRemovedFrom_barOpenValues_whenCacheIsCleanedUp = maxNumberOfItemsIn_barOpenValues / 2; this.barOpenValues = new BarCacheData( maxNumberOfItemsIn_barOpenValues , numberOfItemsToBeRemovedFrom_barOpenValues_whenCacheIsCleanedUp ); // this.barOpenValues = new Dictionary< DateTime , Dictionary< string , double > >(); // this.numberOfBarsIn_barOpenValues = 0; int maxNumberOfItemsIn_barsMissingInTheDatabase = 100000; int numberOfItemsToBeRemovedFrom_barsMissingInTheDatabase_whenCacheIsCleanedUp = maxNumberOfItemsIn_barOpenValues / 2; this.barsMissingInTheDatabase = new BarCacheData( maxNumberOfItemsIn_barsMissingInTheDatabase , numberOfItemsToBeRemovedFrom_barsMissingInTheDatabase_whenCacheIsCleanedUp ); // this.numberOfBarsIn_barsMissingInTheDatabase = 0; } #region checkParameters #region checkDailyTimesAreActuallyTimes private void checkIfItActuallyIsATime( DateTime dateTime ) { if ( !ExtendedDateTime.IsTime( dateTime ) ) throw new Exception( "dailyTimes have to be times: use the method " + "QuantProject.ADT.ExtendedDateTime.GetTime() " + "to build them" ); } private void checkDailyTimesAreActuallyTimes( DateTime[] dailyTimes ) { foreach ( DateTime dateTime in dailyTimes ) this.checkIfItActuallyIsATime( dateTime ); } #endregion checkDailyTimesAreActuallyTimes #region checkIfDailyTimesAreInStrictAscendingOrder private void checkIfDailyTimesAreInStrictAscendingOrder( int indexForCurrentDailyTime , DateTime[] dailyTimes ) { DateTime currentDailyTime = dailyTimes[ indexForCurrentDailyTime ]; DateTime nextDailyTime = dailyTimes[ indexForCurrentDailyTime + 1 ]; if ( currentDailyTime >= nextDailyTime ) throw new Exception( "dailyTimes are not in strict ascending order. " + "dailyTimes have to be in strict ascending order. " + "dailyTime with index " + indexForCurrentDailyTime + " is >= than dailyTime with index " + ( indexForCurrentDailyTime + 1 ) + " while it should <" ); } private void checkIfDailyTimesAreInStrictAscendingOrder( DateTime[] dailyTimes ) { for ( int index = 0 ; index < dailyTimes.Length - 1 ; index++ ) this.checkIfDailyTimesAreInStrictAscendingOrder( index , dailyTimes ); } #endregion checkIfDailyTimesAreInStrictAscendingOrder private void checkParameters( DateTime[] dailyTimes ) { this.checkDailyTimesAreActuallyTimes( dailyTimes ); this.checkIfDailyTimesAreInStrictAscendingOrder( dailyTimes ); } #endregion checkParameters #region GetMarketValue private bool isABarMissingInTheDatabase( string ticker, DateTime dateTime ) { // bool isMissing = false; // if ( this.barsMissingInTheDatabase.Bars.ContainsKey( dateTime ) ) // // it is known at least a missing bar for the given dateTime // isMissing = // this.barsMissingInTheDatabase.Bars[ dateTime ].ContainsKey( ticker ); bool isMissing = this.barsMissingInTheDatabase.ContainsBar( ticker , dateTime ); return isMissing; } #region getMarketValueForBarThatCouldBeInTheDatabase private bool isInCache( string ticker , DateTime dateTime ) { // bool isIn_barOpenValues = // ( ( this.barOpenValues.Bars.ContainsKey( dateTime ) ) && // this.barOpenValues.Bars[ dateTime ].ContainsKey( ticker ) ); bool isIn_barOpenValues = this.barOpenValues.ContainsBar( ticker , dateTime ); return isIn_barOpenValues; } #region getMarketValueForBarThatsNotInCacheButCouldBeInTheDatabase #region updateDictionaries #region getBarOpenValues #region getLastDateTime private int getNumberOfDaysToBeCachedForASingleQuery() { int numberOfDaysToBeCachedForASingleQuery = this.roughNumberOfItemsToBeCachedWithASingleQuery / this.dailyTimes.Length; return numberOfDaysToBeCachedForASingleQuery; } private DateTime getLastDateTime( DateTime firstDateTime ) { int numberOfDaysToBeCachedForASingleQuery = this.getNumberOfDaysToBeCachedForASingleQuery(); DateTime lastDateTime = firstDateTime.AddDays( numberOfDaysToBeCachedForASingleQuery ); return lastDateTime; } #endregion getLastDateTime private History getBarOpenValues( string ticker, DateTime firstDateTime ) { DateTime lastDateTime = this.getLastDateTime( firstDateTime ); History barOpenValues = DataBase.GetBarOpenHistory( ticker , this.barInterval , firstDateTime , lastDateTime , this.dailyTimes ); return barOpenValues; } #endregion getBarOpenValues #region update_barOpenValues private void addBarOpenValue( string ticker, DateTime dateTime , History barOpenValuesFromQuery ) { double barOpenValue = (double)barOpenValuesFromQuery[ dateTime ]; this.barOpenValues.AddBar( ticker , dateTime , barOpenValue ); } private void update_barOpenValues( string ticker, History barOpenValuesFromQuery ) { foreach ( DateTime dateTime in barOpenValuesFromQuery.TimeLine ) this.addBarOpenValue( ticker , dateTime , barOpenValuesFromQuery ); } #endregion update_barOpenValues #region update_barsMissingInTheDatabase #region getDateTimesForMissingBarsToBeAdded // private List< DateTime > getDateTimesIn_barOpenValues() // { // List< DateTime > dateTimesIn_barOpenValues = // new List<DateTime>( this.barOpenValues.Bars.Keys ); // dateTimesIn_barOpenValues.Sort(); // return dateTimesIn_barOpenValues; // } #region removeThisDateIfItIsNotToBeAddedToMissingBars // private bool isIn_barsMissingInTheDatabase( // string ticker , DateTime dateTime ) // { // bool isInCacheForMissingBars = // ( ( this.barsMissingInTheDatabase.Bars.ContainsKey( dateTime ) ) && // this.barOpenValues.Bars[ dateTime ].ContainsKey( ticker ) ); // return isInCacheForMissingBars; // } private bool hasToBeAddedToMissingBars( string ticker , DateTime firstDateTime , DateTime lastDateTime , DateTime candidateDateTime ) { bool hasToBeAdded = ( ( candidateDateTime >= firstDateTime ) && ( candidateDateTime <= lastDateTime ) && ( !this.isInCache( ticker , candidateDateTime ) ) && ( !this.barsMissingInTheDatabase.ContainsBar( ticker , candidateDateTime ) ) ); return hasToBeAdded; } private void removeThisDateIfItIsNotToBeAddedToMissingBars( string ticker , DateTime firstDateTime , DateTime lastDateTime , DateTime candidateDateTime , List< DateTime > dateTimesForMissingBarsToBeAdded ) { if ( !this.hasToBeAddedToMissingBars( ticker , firstDateTime , lastDateTime , candidateDateTime ) ) dateTimesForMissingBarsToBeAdded.Remove( candidateDateTime ); } private void removeThisDateIfItIsNotToBeAddedToMissingBars( string ticker , DateTime firstDateTime , DateTime lastDateTime , int indexFor_dateTimesForMissingBarsToBeAdded , List< DateTime > dateTimesForMissingBarsToBeAdded ) { DateTime candidateDateTime = dateTimesForMissingBarsToBeAdded[ indexFor_dateTimesForMissingBarsToBeAdded ]; this.removeThisDateIfItIsNotToBeAddedToMissingBars( ticker , firstDateTime , lastDateTime , candidateDateTime , dateTimesForMissingBarsToBeAdded ); } #endregion removeThisDateIfItIsNotToBeAddedToMissingBars private List< DateTime > getDateTimesForMissingBarsToBeAdded( string ticker , DateTime firstDateTime , DateTime lastDateTime , List< DateTime > dateTimesForMissingBarsToBeAdded ) { int indexFor_dateTimesForMissingBarsToBeAdded = 0; while ( ( indexFor_dateTimesForMissingBarsToBeAdded < dateTimesForMissingBarsToBeAdded.Count ) && ( dateTimesForMissingBarsToBeAdded[ indexFor_dateTimesForMissingBarsToBeAdded ] <= lastDateTime ) ) this.removeThisDateIfItIsNotToBeAddedToMissingBars( ticker , firstDateTime , lastDateTime , indexFor_dateTimesForMissingBarsToBeAdded , dateTimesForMissingBarsToBeAdded ); return dateTimesForMissingBarsToBeAdded; } private List< DateTime > getDateTimesForMissingBarsToBeAdded( string ticker , DateTime firstDateTime , DateTime lastDateTime ) { List< DateTime > dateTimesIn_barOpenValues = this.barOpenValues.DateTimes; // this.getDateTimesIn_barOpenValues(); List< DateTime > dateTimesForMissingBarsToBeAdded = this.getDateTimesForMissingBarsToBeAdded( ticker , firstDateTime , lastDateTime , dateTimesIn_barOpenValues ); return dateTimesForMissingBarsToBeAdded; } private List< DateTime > getDateTimesForMissingBarsToBeAdded( string ticker , DateTime firstDateTime ) { DateTime lastDateTime = this.getLastDateTime( firstDateTime ); List< DateTime > dateTimesForMissingBarsToBeAdded = this.getDateTimesForMissingBarsToBeAdded( ticker , firstDateTime , lastDateTime ); return dateTimesForMissingBarsToBeAdded; } #endregion getDateTimesForMissingBarsToBeAdded #region update_barsMissingInTheDatabase // // #region addBarTo_barsMissingInTheDatabase // // #region removeValuesFrom_barsMissingInTheDatabase_ifMaxSizeHasBeenReached // // #region removeValuesFrom_barsMissingInTheDatabase // // #region initializeMembersForCleaningUp_barsMissingInTheDatabase // private void initialize_dateTimesForCleaningUp_barsMissingInTheDatabase() // { // this.dateTimesForCleaningUp_barsMissingInTheDatabase = // new List<DateTime>( this.barsMissingInTheDatabase.Keys ); // this.dateTimesForCleaningUp_barsMissingInTheDatabase.Sort(); // } // // #region initialize_tickersForCleaningUp_barsMissingInTheDatabase // private List< string > // getTickersForTheCurrentDateTimeToBeCleanedUpInMissingBars() // { // DateTime currentDateTimeForCleaningUp_barsMissingInTheDatabase = // this.dateTimesForCleaningUp_barsMissingInTheDatabase[ 0 ]; // List< string > // tickersForTheCurrentDateTimeToBeCleanedUpInMissingBars = // this.barsMissingInTheDatabase[ // currentDateTimeForCleaningUp_barsMissingInTheDatabase ]; // return tickersForTheCurrentDateTimeToBeCleanedUpInMissingBars; // } // private void initialize_tickersForCleaningUp_barsMissingInTheDatabase() // { // this.tickersForCleaningUp_barOpenValues = // this.getTickersForTheCurrentDateTimeToBeCleanedUpInMissingBars(); // } // #endregion initialize_tickersForCleaningUp_barsMissingInTheDatabase // // private void initializeMembersForCleaningUp_barsMissingInTheDatabase() // { // this.initialize_dateTimesForCleaningUp_barsMissingInTheDatabase(); // this.initialize_tickersForCleaningUp_barsMissingInTheDatabase(); // } // #endregion initializeMembersForCleaningUp_barsMissingInTheDatabase // // private void removeValuesFrom_barsMissingInTheDatabase() // { // this.initializeMembersForCleaningUp_barsMissingInTheDatabase(); // while ( this.numberOfBarsIn_barsMissingInTheDatabase > // this.maxNumberOfItemsIn_barsMissingInTheDatabase - // this.numberOfItemsToBeRemovedFrom_barsMissingInTheDatabase_whenCacheIsCleanedUp ) // this.removeNextItemFrom_barsMissingInTheDatabase(); // } // #endregion removeValuesFrom_barsMissingInTheDatabase // // private void removeValuesFrom_barsMissingInTheDatabase_ifMaxSizeHasBeenReached() // { // if ( this.numberOfBarsIn_barsMissingInTheDatabase >= // this.maxNumberOfItemsIn_barsMissingInTheDatabase ) // // the cache for missing bars is full // this.removeValuesFrom_barsMissingInTheDatabase(); // } // #endregion removeValuesFrom_barsMissingInTheDatabase_ifMaxSizeHasBeenReached // // private void addBarTo_barsMissingInTheDatabase( // string ticker, DateTime dateTime ) // { // this.removeValuesFrom_barsMissingInTheDatabase_ifMaxSizeHasBeenReached(); // this.addBarTo_barsMissingInTheDatabase_withFreeSpaceAssured(); // } // #endregion addBarTo_barsMissingInTheDatabase // private void update_barsMissingInTheDatabase( string ticker, List< DateTime > dateTimesForMissingBarsToBeAdded ) { foreach ( DateTime dateTime in dateTimesForMissingBarsToBeAdded ) this.barsMissingInTheDatabase.AddBar( ticker , dateTime , double.MinValue ); // this.addBarTo_barsMissingInTheDatabase( ticker , dateTime ); } #endregion update_barsMissingInTheDatabase private void update_barsMissingInTheDatabase( string ticker, DateTime firstDateTime , History barOpenValues ) { List< DateTime > dateTimesForMissingBarsToBeAdded = this.getDateTimesForMissingBarsToBeAdded( ticker , firstDateTime ); this.update_barsMissingInTheDatabase( ticker , dateTimesForMissingBarsToBeAdded ); } #endregion update_barsMissingInTheDatabase private void updateDictionaries( string ticker, DateTime dateTime , History barOpenValues ) { this.update_barOpenValues( ticker, barOpenValues ); this.update_barsMissingInTheDatabase( ticker , dateTime , barOpenValues ); } private void updateDictionaries( string ticker, DateTime dateTime ) { History barOpenValues = this.getBarOpenValues( ticker , dateTime ); this.updateDictionaries( ticker , dateTime , barOpenValues ); } #endregion updateDictionaries #region getMarketValueWithUpdatedDictionaries private double getMarketValueWithUpdatedDictionaries( string ticker, DateTime dateTime ) { double marketValue = double.MinValue; if ( !this.barOpenValues.ContainsBar( ticker , dateTime ) ) // the requested bar is not in the database throw new MissingBarException( ticker , dateTime , this.barInterval ); else // the requested bar is in the database marketValue = this.barOpenValues.GetBarValue( ticker , dateTime ); return marketValue; } #endregion getMarketValueWithUpdatedDictionaries private double getMarketValueForBarThatsNotInCacheButCouldBeInTheDatabase( string ticker, DateTime dateTime ) { this.updateDictionaries( ticker , dateTime ); double marketValue = this.getMarketValueWithUpdatedDictionaries( ticker , dateTime ); return marketValue; } #endregion getMarketValueForBarThatsNotInCacheButCouldBeInTheDatabase private double getMarketValueForBarThatCouldBeInTheDatabase( string ticker, DateTime dateTime ) { double marketValue = double.MinValue; if ( this.isInCache( ticker , dateTime ) ) // the requested bar is already in cache marketValue = this.barOpenValues.GetBarValue( ticker , dateTime ); else // the requested bar is not in cache, but it could be in the database marketValue = this.getMarketValueForBarThatsNotInCacheButCouldBeInTheDatabase( ticker , dateTime ); return marketValue; } #endregion getMarketValueForBarThatCouldBeInTheDatabase /// <summary> /// returns the market value for the given ticker, for the bar /// that opens at the given dateTime /// </summary> /// <param name="ticker"></param> /// <param name="dateTime"></param> /// <returns></returns> public double GetMarketValue( string ticker, DateTime dateTime ) { double marketValue = double.MinValue; if ( this.isABarMissingInTheDatabase( ticker , dateTime ) ) // the bar is not in the database throw new MissingBarException( ticker , dateTime , this.barInterval ); else // the bar can be in the database marketValue = this.getMarketValueForBarThatCouldBeInTheDatabase( ticker , dateTime ); return marketValue; } #endregion GetMarketValue } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:14:00
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars/Caching In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17969 Added Files: BarCacheData.cs Log Message: Basic data structure used by bar caches: each IBarCache will use its own strategy, but it will probably use this class for adding bars to the cache and for checking if bars are already in the cache --- NEW FILE: BarCacheData.cs --- /* QuantProject - Quantitative Finance Library BarCacheData.cs Copyright (C) 2008 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; namespace QuantProject.Data.DataProviders.Bars.Caching { /// <summary> /// Basic data structure used by bar caches: each IBarCache will use its own /// strategy, but it will probably use this class for adding bars to the cache /// and for checking if bars are already in the cache /// </summary> public class BarCacheData { private int maxNumberOfItemsIn_bars; private int numberOfItemsToBeRemovedFrom_bars_whenCacheIsCleanedUp; private Dictionary< DateTime , Dictionary< string , double > > bars; // public Dictionary<DateTime, Dictionary<string, double>> Bars { // get { return this.bars; } // } private int numberOfBarsIn_bars; List<DateTime> dateTimesForCleaningUp_bars; List<string> tickersForCleaningUp_bars; /// <summary> /// date times for which at least a bar is in the dictionary /// </summary> public List< DateTime > DateTimes { get { List<DateTime> dateTimes = new List<DateTime>( this.bars.Keys ); return dateTimes; } } public BarCacheData( int maxNumberOfItemsIn_bars , int numberOfItemsToBeRemovedFrom_bars_whenCacheIsCleanedUp ) { this.maxNumberOfItemsIn_bars = maxNumberOfItemsIn_bars; this.numberOfItemsToBeRemovedFrom_bars_whenCacheIsCleanedUp = numberOfBarsIn_bars; this.bars = new Dictionary< DateTime , Dictionary< string , double > >(); this.numberOfBarsIn_bars = 0; } #region AddBar private void add_dateTime_toCacheIfTheCase( DateTime dateTime ) { if ( !this.bars.ContainsKey( dateTime ) ) // no data is yet in cache for this dateTime and a this.bars.Add( dateTime , new Dictionary< string , double >() ); } #region addBar_with_dateTime_alreadyInCache #region addBar_actually #region removeValuesFromTheCacheIfMaxSizeHasBeenReached #region removeValuesFromTheCache #region initializeMembersForCleaningUp_bars private void initialize_dateTimesForCleaningUp_bars() { this.dateTimesForCleaningUp_bars = new List<DateTime>(this.bars.Keys); this.dateTimesForCleaningUp_bars.Sort(); } #region initialize_tickersForCleaningUp_bars private Dictionary< string , double > getBarOpenValuesForTheCurrentDateTimeToBeCleanedUpInCache() { DateTime currentDateTimeForCleaningUp_bars = this.dateTimesForCleaningUp_bars[ 0 ]; Dictionary< string , double > barOpenValuesForTheCurrentDateTimeToBeCleanedUpInCache = this.bars[ currentDateTimeForCleaningUp_bars ]; return barOpenValuesForTheCurrentDateTimeToBeCleanedUpInCache; } private void initialize_tickersForCleaningUp_bars() { Dictionary< string , double > barOpenValuesForTheCurrentDateTimeToBeCleanedUpInCache = this.getBarOpenValuesForTheCurrentDateTimeToBeCleanedUpInCache(); this.tickersForCleaningUp_bars = new List<string>( barOpenValuesForTheCurrentDateTimeToBeCleanedUpInCache.Keys ); } #endregion initialize_tickersForCleaningUp_bars private void initializeMembersForCleaningUp_bars() { this.initialize_dateTimesForCleaningUp_bars(); // this.currentDateTimeIndexForCleaningUp_bars = 0; this.initialize_tickersForCleaningUp_bars(); } #endregion initializeMembersForCleaningUp_bars #region removeNextItemFrom_bars // private void update_tickersForCleaningUp_bars() // { // 344 // } #region removeNextItemFrom_bars_withUpdated_tickersForCleaningUp #region removeCurrentItemFrom_bars #region removeCurrentItemFrom_bars_actually private void removeCurrentItemFrom_bars_only() { DateTime dateTimeForCurrentItemToBeRemoved = this.dateTimesForCleaningUp_bars[ 0 ]; string tickerForCurrentItemToBeRemoved = this.tickersForCleaningUp_bars[ 0 ]; this.bars[ dateTimeForCurrentItemToBeRemoved ].Remove( tickerForCurrentItemToBeRemoved ); } #region updateMembersUsedToCleanUp_bars #region moveToTheNextDateTimeForCleaningUp_bars private void moveToTheNextDateTimeForCleaningUp_bars() { this.dateTimesForCleaningUp_bars.RemoveAt( 0 ); this.initialize_tickersForCleaningUp_bars(); } #endregion moveToTheNextDateTimeForCleaningUp_bars private void updateMembersUsedToCleanUp_bars() { this.tickersForCleaningUp_bars.RemoveAt( 0 ); if ( this.tickersForCleaningUp_bars.Count == 0 ) // all the tickers have been removed for the current DateTime this.moveToTheNextDateTimeForCleaningUp_bars(); } #endregion updateMembersUsedToCleanUp_bars private void removeCurrentItemFrom_bars_actually() { this.removeCurrentItemFrom_bars_only(); this.updateMembersUsedToCleanUp_bars(); } #endregion removeCurrentItemFrom_bars_actually private void removeCurrentItemFrom_bars() { removeCurrentItemFrom_bars_actually(); this.numberOfBarsIn_bars--; } #endregion removeCurrentItemFrom_bars private void removeNextItemFrom_bars_withUpdated_tickersForCleaningUp() { this.removeCurrentItemFrom_bars(); this.updateMembersUsedToCleanUp_bars(); } #endregion removeNextItemFrom_bars_withUpdated_tickersForCleaningUp private void removeNextItemFrom_bars() { this.removeNextItemFrom_bars_withUpdated_tickersForCleaningUp(); } #endregion removeNextItemFrom_bars private void removeValuesFromTheCache() { this.initializeMembersForCleaningUp_bars(); while ( this.numberOfBarsIn_bars > this.maxNumberOfItemsIn_bars - this.numberOfItemsToBeRemovedFrom_bars_whenCacheIsCleanedUp ) this.removeNextItemFrom_bars(); } #endregion removeValuesFromTheCache private void removeValuesFromTheCacheIfMaxSizeHasBeenReached() { if ( this.numberOfBarsIn_bars >= this.maxNumberOfItemsIn_bars ) // the cache is full this.removeValuesFromTheCache(); } #endregion removeValuesFromTheCacheIfMaxSizeHasBeenReached private void addBar_actually( string ticker, double barOpenValue , Dictionary< string , double > barsInDictionaryForTheGivenDateTime ) { this.removeValuesFromTheCacheIfMaxSizeHasBeenReached(); barsInDictionaryForTheGivenDateTime.Add( ticker , barOpenValue ); this.numberOfBarsIn_bars++; } #endregion addBar_actually private void addBar( string ticker, double barOpenValue , Dictionary< string , double > barsInDictionaryForTheGivenDateTime ) { if ( !barsInDictionaryForTheGivenDateTime.ContainsKey( ticker ) ) // the cache doesn't contain the open value // for the given ticker and the given dateTime this.addBar_actually( ticker , barOpenValue , barsInDictionaryForTheGivenDateTime); } // private void addBarOpenValue( // Dictionary< string , double > barOpenValuesInCacheForGivenDateTime , // string ticker, DateTime dateTime , double theValue ) // { // this.addBarOpenValue( // barOpenValuesInCacheForGivenDateTime , ticker , barOpenValue ); // } private void addBar_with_dateTime_alreadyInCache( string ticker, DateTime dateTime , double theValue ) { Dictionary< string , double > barsInDictionaryForTheGivenDateTime = this.bars[ dateTime ]; this.addBar( ticker , theValue , barsInDictionaryForTheGivenDateTime ); } #endregion addBar_with_dateTime_alreadyInCache /// <summary> /// adds a bar to the cache; if there is no more space in the cache, (supposed) /// old items are removed before adding the new bar /// </summary> /// <param name="ticker"></param> /// <param name="dateTime"></param> /// <param name="theValue"></param> public void AddBar( string ticker, DateTime dateTime , double theValue ) { this.add_dateTime_toCacheIfTheCase( dateTime ); this.addBar_with_dateTime_alreadyInCache( ticker , dateTime , theValue ); } #endregion AddBar /// <summary> /// true iif the dictionary contains the requested bar /// </summary> /// <param name="ticker"></param> /// <param name="dateTime"></param> /// <returns></returns> public bool ContainsBar( string ticker , DateTime dateTime ) { bool containsBar = ( ( this.bars.ContainsKey( dateTime ) ) && ( this.bars[ dateTime ].ContainsKey( ticker ) ) ); return containsBar; } /// <summary> /// returns the value for the given bar /// </summary> /// <param name="ticker"></param> /// <param name="dateTime"></param> /// <returns></returns> public double GetBarValue( string ticker , DateTime dateTime ) { // we don't check if the bar is actually in the database, // because we want this method to be as fast as possible; // if the bar is missing, then an exception will be thrown by // the framework. It is responsability of the caller to decide if // to invoke the ContainsBar method before invoking this method double barValue = this.bars[ dateTime ][ ticker ]; return barValue; } } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:11:54
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars/Caching In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17751/Caching Log Message: Directory /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars/Caching added to the repository |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:11:38
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17718/Bars Log Message: Directory /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars added to the repository |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:09:16
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17419/b2_DataAccess Modified Files: DataAccess_SD.csproj Log Message: - BarFieldNames.cs has been added - SqlComparisonOperator.cs has been added Index: DataAccess_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/DataAccess_SD.csproj,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DataAccess_SD.csproj 29 Aug 2007 10:34:57 -0000 1.2 --- DataAccess_SD.csproj 8 Nov 2008 20:08:48 -0000 1.3 *************** *** 46,49 **** --- 46,50 ---- <ItemGroup> <Compile Include="AssemblyInfo.cs" /> + <Compile Include="BarFieldNames.cs" /> <Compile Include="ConnectionProvider.cs" /> <Compile Include="DataBase.cs" /> *************** *** 53,56 **** --- 54,58 ---- <Compile Include="QuoteField.cs" /> <Compile Include="SQLBuilder.cs" /> + <Compile Include="SqlComparisonOperator.cs" /> <Compile Include="SqlExecutor.cs" /> <Compile Include="ValidationTypes.cs" /> |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:06:42
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17173 Added Files: BarFieldNames.cs Log Message: Provides field names for the bars table --- NEW FILE: BarFieldNames.cs --- /* QuantProject - Quantitative Finance Library BarFieldNames.cs Copyright (C) 2008 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.DataAccess { /// <summary> /// Provides field names for the bars table /// </summary> public class BarFieldNames { public static string Open { get { return "baOpen"; } } public static string DateTimeForOpen { get { return "baDateTimeForOpen"; } } public BarFieldNames() { } } } |
|
From: Glauco S. <gla...@us...> - 2008-11-08 20:06:27
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17128 Added Files: SqlComparisonOperator.cs Log Message: Comparison operators that can be used in a Sql where clause --- NEW FILE: SqlComparisonOperator.cs --- /* QuantProject - Quantitative Finance Library DataBase.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.DataAccess { /// <summary> /// Comparison operators that can be used in a Sql where clause /// </summary> public enum SqlComparisonOperator { Equal , LessThan , LessThanOrEqual , GreaterThan , GreaterThanOrEqual } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:23:06
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19753/b4_Business/a05_Timing Modified Files: IndexBasedEndOfDayTimer.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: IndexBasedEndOfDayTimer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/IndexBasedEndOfDayTimer.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** IndexBasedEndOfDayTimer.cs 14 Jan 2008 23:21:03 -0000 1.9 --- IndexBasedEndOfDayTimer.cs 29 Sep 2008 21:22:45 -0000 1.10 *************** *** 3,7 **** IndexBasedEndOfDayTimer.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- IndexBasedEndOfDayTimer.cs ! Copyright (C) 2003 Marco Milletti *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Collections; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Collections; *************** *** 30,35 **** { /// <summary> ! /// IEndOfDayTimer implementation using a market index as the base ! /// for time walking simulation /// </summary> [Serializable] --- 30,36 ---- { /// <summary> ! /// ITimer implementation using a market index as the base ! /// for time walking simulation; end of day timing events are risen ! /// only for those days when the index is traded /// </summary> [Serializable] *************** *** 37,132 **** { private string marketIndex; ! public string MarketIndex ! { ! get { return this.marketIndex; } ! } ! ! private Quotes indexQuotes; ! public Quotes IndexQuotes ! { ! get { return this.indexQuotes; } ! } ! private int currentDateArrayPosition; ! public int CurrentDateArrayPosition ! { ! get { return this.currentDateArrayPosition ; } ! } ! private void indexBasedEndOfDayTimer( EndOfDayDateTime startDateTime, ! string marketIndex) ! { ! this.marketIndex = marketIndex; ! if ( this.indexQuotes.Rows.Count == 0 ) ! { ! string errorMessage = "IndexBasedEndOfDayTimer error: the given " + ! "index (" + marketIndex + ") has no quotes in the interval."; ! throw new Exception( errorMessage ); ! } ! this.StartDateTime = ! new EndOfDayDateTime(this.indexQuotes.GetQuoteDateOrFollowing(this.StartDateTime.DateTime), ! EndOfDaySpecificTime.MarketOpen); ! this.tickers = new Hashtable(); ! this.currentDateArrayPosition = 0; ! } ! public IndexBasedEndOfDayTimer( EndOfDayDateTime startDateTime, ! string marketIndex): base(startDateTime) { ! this.indexQuotes = new Quotes(marketIndex,startDateTime.DateTime,DateTime.Now); ! this.indexBasedEndOfDayTimer(startDateTime, marketIndex); } - - public IndexBasedEndOfDayTimer( EndOfDayDateTime startDateTime, - EndOfDayDateTime endDateTime, - string marketIndex): base(startDateTime) - { - this.indexQuotes = new Quotes(marketIndex,startDateTime.DateTime,endDateTime.DateTime.AddDays(10)); - this.indexBasedEndOfDayTimer(startDateTime, marketIndex); - } ! /// <summary> ! /// Starts the time walking simulation, based on index's dates ! /// </summary> ! public override void Start() { ! base.activeTimer(); ! while ( this.isActive ) { ! base.callEvents(); ! this.moveNext(); } } - //move the current endOfDayDateTime to the next moment - //at which the market is surely open - protected override void moveNext() - { - EndOfDaySpecificTime nextSpecificTime = this.currentTime.GetNextEndOfDaySpecificTime(); - if ( nextSpecificTime < this.currentTime.EndOfDaySpecificTime ) - { - // the current end of day specific time is the last end of day specific time in the day - this.currentTime.DateTime = - this.indexQuotes.GetFollowingDate(this.currentTime.DateTime, 1); - this.currentDateArrayPosition++; - } - this.currentTime.EndOfDaySpecificTime = nextSpecificTime; - - } - /// <summary> - /// Gets the previous index based date time - /// </summary> - public DateTime GetPreviousDateTime() - { - return this.indexQuotes.GetPrecedingDate(this.currentTime.DateTime,1); - } - /// <summary> - /// Gets the date time that is 'precedingDays' days before - /// the current date time of the current timer - /// </summary> - public DateTime GetPreviousDateTime(int precedingDays) - { - return this.indexQuotes.GetPrecedingDate( - this.currentTime.DateTime,precedingDays); - } } --- 38,173 ---- { private string marketIndex; ! public string MarketIndex ! { ! get { return this.marketIndex; } ! } ! private Quotes indexQuotes; ! public Quotes IndexQuotes ! { ! get { return this.indexQuotes; } ! } ! ! private int currentDateArrayPosition; ! public int CurrentDateArrayPosition ! { ! get { return this.currentDateArrayPosition ; } ! } ! ! #region commonInitialization ! private void indexBasedEndOfDayTimer( ! DateTime startDateTime, string marketIndex) ! { ! this.marketIndex = marketIndex; ! if ( this.indexQuotes.Rows.Count == 0 ) ! { ! string errorMessage = "IndexBasedEndOfDayTimer error: the given " + ! "index (" + marketIndex + ") has no quotes in the interval."; ! throw new Exception( errorMessage ); ! } ! this.StartDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( startDateTime ); ! this.tickers = new Hashtable(); ! this.currentDateArrayPosition = 0; ! } ! private void commonInitialization( ! string marketIndex , ! DateTime startDateTime , ! DateTime endDateTime ) ! { ! DateTime startDate = ! ExtendedDateTime.GetDate( startDateTime ); ! this.indexQuotes = new Quotes(marketIndex,startDate,DateTime.Now); ! this.indexBasedEndOfDayTimer(startDateTime, marketIndex); ! } ! #endregion commonInitialization ! public IndexBasedEndOfDayTimer( ! DateTime startDateTime, ! string marketIndex): base(startDateTime) { ! this.commonInitialization( marketIndex,startDateTime,DateTime.Now ); } ! public IndexBasedEndOfDayTimer( ! DateTime startDateTime, ! DateTime endDateTime, ! string marketIndex): base(startDateTime) { ! this.commonInitialization( marketIndex,startDateTime,endDateTime.AddDays(10) ); ! } ! ! // /// <summary> ! // /// Starts the time walking simulation, based on index's dates ! // /// </summary> ! // public override void Start() ! // { ! // base.activateTimer(); ! // while ( this.isActive ) ! // { ! // base.callEvents(); ! // this.moveNext(); ! // } ! // } ! ! #region moveNext ! private void moveNext_with_currentDateTime_properlyInitialized() ! { ! if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( ! this.currentDateTime ) ) { ! // current time is the last end of day event for the day ! DateTime followingDateForIndex = ! this.indexQuotes.GetFollowingDate(this.currentDateTime, 1); ! this.currentDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( followingDateForIndex ); ! this.currentDateArrayPosition++; } + else + // current time is the last end of day event for the day + base.moveNext(); + + // this.currentDateTime = + // HistoricalEndOfDayTimer.ge + // EndOfDaySpecificTime nextSpecificTime = this.currentTime.GetNextEndOfDaySpecificTime(); + // if ( nextSpecificTime < this.currentTime.EndOfDaySpecificTime ) + // { + // // the current end of day specific time is the last end of day specific time in the day + // this.currentTime.DateTime = + // this.indexQuotes.GetFollowingDate(this.currentTime.DateTime, 1); + // this.currentDateArrayPosition++; + // } + // this.currentTime.EndOfDaySpecificTime = nextSpecificTime; + } + //move the current endOfDayDateTime to the next moment + //at which the market is surely open + protected override void moveNext() + { + DateTime dateTimeForTheFirstStep = + HistoricalEndOfDayTimer.GetMarketOpen( + this.indexQuotes.StartDate ); + if ( this.currentDateTime < dateTimeForTheFirstStep ) + this.currentDateTime = dateTimeForTheFirstStep; + this.moveNext_with_currentDateTime_properlyInitialized(); + } + #endregion moveNext + + /// <summary> + /// Gets the previous index based date time + /// </summary> + public DateTime GetPreviousDateTime() + { + return this.indexQuotes.GetPrecedingDate(this.currentDateTime,1); + } + /// <summary> + /// Gets the date time that is 'precedingDays' days before + /// the current date time of the current timer + /// </summary> + public DateTime GetPreviousDateTime(int precedingDays) + { + return this.indexQuotes.GetPrecedingDate( + this.currentDateTime,precedingDays); } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:23:04
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19753/b4_Business/a07_DataProviders Modified Files: TickerNotExchangedException.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: TickerNotExchangedException.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders/TickerNotExchangedException.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TickerNotExchangedException.cs 27 Feb 2008 21:21:21 -0000 1.1 --- TickerNotExchangedException.cs 29 Sep 2008 21:22:45 -0000 1.2 *************** *** 33,37 **** { private string ticker; ! private EndOfDayDateTime endOfDayDateTime; public override string Message { --- 33,37 ---- { private string ticker; ! private DateTime dateTime; public override string Message { *************** *** 40,51 **** return "Missing quote for ticker " + this.ticker + " for end of day date time " + ! this.endOfDayDateTime.Description; } } public TickerNotExchangedException( string ticker , ! EndOfDayDateTime endOfDayDateTime ) { this.ticker = ticker; ! this.endOfDayDateTime = endOfDayDateTime; } } --- 40,51 ---- return "Missing quote for ticker " + this.ticker + " for end of day date time " + ! this.dateTime.ToString(); } } public TickerNotExchangedException( string ticker , ! DateTime dateTime ) { this.ticker = ticker; ! this.dateTime = dateTime; } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:22:48
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19614/b4_Business/a07_DataProviders Modified Files: HistoricalAdjustedQuoteProvider.cs HistoricalEndOfDayDataStreamer.cs HistoricalRawQuoteProvider.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: HistoricalEndOfDayDataStreamer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders/HistoricalEndOfDayDataStreamer.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** HistoricalEndOfDayDataStreamer.cs 4 Feb 2005 00:10:25 -0000 1.5 --- HistoricalEndOfDayDataStreamer.cs 29 Sep 2008 21:22:23 -0000 1.6 *************** *** 26,29 **** --- 26,30 ---- using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; + using QuantProject.Data.DataProviders.Quotes; namespace QuantProject.Business.DataProviders *************** *** 37,47 **** private Hashtable tickers; ! private IEndOfDayTimer endOfDayTimer; ! private IHistoricalQuoteProvider historicalQuoteProvider; ! private EndOfDayDateTime startDateTime; ! private EndOfDayDateTime endDateTime; ! public EndOfDayDateTime StartDateTime { get { return this.startDateTime; } --- 38,48 ---- private Hashtable tickers; ! private Timer timer; ! private HistoricalMarketValueProvider historicalMarketValueProvider; ! private DateTime startDateTime; ! private DateTime endDateTime; ! public DateTime StartDateTime { get { return this.startDateTime; } *************** *** 49,53 **** } ! public EndOfDayDateTime EndDateTime { get { return this.endDateTime; } --- 50,54 ---- } ! public DateTime EndDateTime { get { return this.endDateTime; } *************** *** 55,68 **** } ! public HistoricalEndOfDayDataStreamer( IEndOfDayTimer endOfDayTimer , ! IHistoricalQuoteProvider historicalQuoteProvider ) { ! this.endOfDayTimer = endOfDayTimer; ! this.historicalQuoteProvider = historicalQuoteProvider; ! this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( ! this.marketOpenEventHandler ); this.tickers = new Hashtable(); } /// <summary> /// Returns the current bid for the given ticker --- 56,117 ---- } ! public HistoricalEndOfDayDataStreamer( ! Timer timer , ! HistoricalMarketValueProvider historicalMarketValueProvider ) { ! this.timer = timer; ! this.historicalMarketValueProvider = historicalMarketValueProvider; ! this.timer.NewDateTime += ! new NewDateTimeEventHandler( ! this.newTimeEventHandler ); this.tickers = new Hashtable(); } + #region newTimeEventHandler + private void riseNewQuotesIfTheCase( + DateTime dateTime , MarketStatusSwitch marketStatusSwitch ) + { + if ( this.tickers.Count > 0 ) + { + // the data streamer is monitoring some ticker + Hashtable quotes = + HistoricalQuotesProvider.GetAdjustedQuotes( + this.tickers , dateTime , marketStatusSwitch ); + foreach ( Quote quote in quotes ) + this.NewQuote( this , new NewQuoteEventArgs( quote ) ); + } + } + private void newTimeEventHandler( + Object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + this.riseNewQuotesIfTheCase( dateTime , MarketStatusSwitch.Open ); + if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + this.riseNewQuotesIfTheCase( dateTime , MarketStatusSwitch.Close ); + } + #endregion newTimeEventHandler + + #region GetCurrentBid + private void getCurrentBid_checkValidTime() + { + DateTime currentDateTime = this.timer.GetCurrentDateTime(); + if ( !HistoricalEndOfDayTimer.IsMarketStatusSwitch( currentDateTime ) ) + throw new Exception( + "With this data streamer, GetCurrentBid can be invoked only " + + "if the current time is either on market open or on market " + + "close." ); + } + + #region getCurrentBid_actually + private double getCurrentBid_actually( string ticker ) + { + double currentBid = + this.historicalMarketValueProvider.GetMarketValue( + ticker , + this.timer.GetCurrentDateTime() ); + return currentBid; + } + #endregion getCurrentBid_actually + /// <summary> /// Returns the current bid for the given ticker *************** *** 72,78 **** public double GetCurrentBid( string ticker ) { ! return historicalQuoteProvider.GetMarketValue( ticker , ! this.endOfDayTimer.GetCurrentTime() ); } /// <summary> --- 121,130 ---- public double GetCurrentBid( string ticker ) { ! this.getCurrentBid_checkValidTime(); ! double currentBid = ! this.getCurrentBid_actually( ticker ); ! return currentBid; } + #endregion GetCurrentBid /// <summary> *************** *** 83,88 **** public double GetCurrentAsk( string ticker ) { ! return historicalQuoteProvider.GetMarketValue( ticker , ! this.endOfDayTimer.GetCurrentTime() ); } --- 135,139 ---- public double GetCurrentAsk( string ticker ) { ! return this.GetCurrentBid( ticker ); } *************** *** 94,99 **** public bool IsExchanged( string ticker ) { ! return HistoricalDataProvider.WasExchanged( ticker , ! this.endOfDayTimer.GetCurrentTime().GetNearestExtendedDateTime() ); } /// <summary> --- 145,150 ---- public bool IsExchanged( string ticker ) { ! return HistoricalQuotesProvider.WasExchanged( ! ticker , this.timer.GetCurrentDateTime() ); } /// <summary> *************** *** 119,136 **** // timer.Start(); // } - - private void marketOpenEventHandler( - Object sender , EndOfDayTimingEventArgs eventArgs ) - { - if ( this.tickers.Count > 0 ) - { - // the data streamer is monitoring some ticker - Hashtable quotes = - HistoricalDataProvider.GetQuotes( this.tickers , - this.endOfDayTimer.GetCurrentTime().GetNearestExtendedDateTime() ); - foreach ( Quote quote in quotes ) - this.NewQuote( this , new NewQuoteEventArgs( quote ) ); - } - } } } --- 170,173 ---- Index: HistoricalRawQuoteProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders/HistoricalRawQuoteProvider.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** HistoricalRawQuoteProvider.cs 10 Feb 2008 14:28:09 -0000 1.5 --- HistoricalRawQuoteProvider.cs 29 Sep 2008 21:22:23 -0000 1.6 *************** *** 3,7 **** HistoricalRawQuoteProvider.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- HistoricalRawQuoteProvider.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,28 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using QuantProject.Business.Timing; ! using QuantProject.Data.DataProviders; namespace QuantProject.Business.DataProviders --- 19,29 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; + using QuantProject.ADT; using QuantProject.Business.Timing; ! using QuantProject.Data.DataProviders.Quotes; namespace QuantProject.Business.DataProviders *************** *** 32,45 **** /// </summary> [Serializable] ! public class HistoricalRawQuoteProvider : HistoricalQuoteProvider { public HistoricalRawQuoteProvider() { } ! public override double GetMarketValue( string instrumentKey , ! EndOfDayDateTime endOfDayDateTime ) { ! return HistoricalDataProvider.GetRawMarketValue( instrumentKey , ! endOfDayDateTime.GetNearestExtendedDateTime() ); } --- 33,52 ---- /// </summary> [Serializable] ! public class HistoricalRawQuoteProvider : HistoricalMarketValueProvider { public HistoricalRawQuoteProvider() { } ! public override double GetMarketValue( ! string instrumentKey , ! DateTime dateTime ) { ! MarketStatusSwitch marketStatusSwitch = ! HistoricalAdjustedQuoteProvider.GetMarketStatusSwitch( dateTime ); // TO DO move this method to an abstract class BasicQuotesProvider to be inherited both by HistoricalAdjustedQuoteProvider and by HistoricalRawQuoteProvider ! double marketValue = HistoricalQuotesProvider.GetRawMarketValue( ! instrumentKey , ! ExtendedDateTime.GetDate( dateTime ) , ! marketStatusSwitch ); ! return marketValue; } Index: HistoricalAdjustedQuoteProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders/HistoricalAdjustedQuoteProvider.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** HistoricalAdjustedQuoteProvider.cs 10 Feb 2008 14:28:09 -0000 1.6 --- HistoricalAdjustedQuoteProvider.cs 29 Sep 2008 21:22:23 -0000 1.7 *************** *** 3,7 **** HistoricalAdjustedQuoteProvider.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- HistoricalAdjustedQuoteProvider.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,28 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using QuantProject.Business.Timing; ! using QuantProject.Data.DataProviders; namespace QuantProject.Business.DataProviders --- 19,29 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; + using QuantProject.ADT; using QuantProject.Business.Timing; ! using QuantProject.Data.DataProviders.Quotes; namespace QuantProject.Business.DataProviders *************** *** 32,49 **** /// </summary> [Serializable] ! public class HistoricalAdjustedQuoteProvider : HistoricalQuoteProvider { public HistoricalAdjustedQuoteProvider() { } ! public override double GetMarketValue( string instrumentKey , ! EndOfDayDateTime endOfDayDateTime ) { ! double marketValue = ! HistoricalDataProvider.GetAdjustedMarketValue( instrumentKey , ! endOfDayDateTime.GetNearestExtendedDateTime() ); return marketValue; } protected override string getDescription() { --- 33,97 ---- /// </summary> [Serializable] ! public class HistoricalAdjustedQuoteProvider : HistoricalMarketValueProvider { public HistoricalAdjustedQuoteProvider() { } ! ! // TO DO move GetMarketStatusSwitch to an abstract class ! // BasicQuotesProvider to be inherited both by HistoricalAdjustedQuoteProvider ! // and by HistoricalRawQuoteProvider ! #region GetMarketStatusSwitch ! private static void riseExceptionIfNotAtMarketSwitch( DateTime dateTime ) { ! if ( !HistoricalEndOfDayTimer.IsMarketStatusSwitch( dateTime ) ) ! throw new Exception( ! "when GetCurrentMarketStatusSwitch() is invoked, dateTime " + ! "is expected to either be a market open or a market close." ); ! } ! /// <summary> ! /// Returns the market status switch that corresponds to dateTime ! /// </summary> ! /// <param name="dateTime">it has to be either a market open or a ! /// market close</param> ! /// <returns></returns> ! public static MarketStatusSwitch GetMarketStatusSwitch( ! DateTime dateTime ) ! { ! HistoricalAdjustedQuoteProvider.riseExceptionIfNotAtMarketSwitch( dateTime ); ! MarketStatusSwitch marketStatusSwitch = ! MarketStatusSwitch.Open; ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! marketStatusSwitch = MarketStatusSwitch.Close; ! return marketStatusSwitch; ! } ! #endregion GetMarketStatusSwitch ! ! // public override double GetMarketValue( ! // string instrumentKey , ! // DateTime date , ! // MarketStatusSwitch marketStatusSwitch ) ! // { ! // double marketValue = ! // HistoricalQuotesProvider.GetAdjustedMarketValue( ! // instrumentKey , date , marketStatusSwitch ); ! // return marketValue; ! // } ! ! public override double GetMarketValue( ! string instrumentKey , ! DateTime dateTime ) ! { ! MarketStatusSwitch marketStatusSwitch = ! HistoricalAdjustedQuoteProvider.GetMarketStatusSwitch( dateTime ); ! double marketValue = ! HistoricalQuotesProvider.GetAdjustedMarketValue( ! instrumentKey , ! ExtendedDateTime.GetDate( dateTime ) , ! marketStatusSwitch ); return marketValue; } + protected override string getDescription() { |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:22:46
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19614/b4_Business/a05_Timing Modified Files: HistoricalEndOfDayTimer.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: HistoricalEndOfDayTimer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/HistoricalEndOfDayTimer.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** HistoricalEndOfDayTimer.cs 7 Feb 2008 18:43:35 -0000 1.9 --- HistoricalEndOfDayTimer.cs 29 Sep 2008 21:22:23 -0000 1.10 *************** *** 2,7 **** QuantProject - Quantitative Finance Library ! HistoricalDataStreamer.cs ! Copyright (C) 2003 Glauco Siliprandi --- 2,7 ---- QuantProject - Quantitative Finance Library ! HistoricalEndOfDayTimer.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Collections; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Collections; *************** *** 31,46 **** /// </summary> [Serializable] ! public class HistoricalEndOfDayTimer : IEndOfDayTimer { - protected bool isActive; // true iff the timer is started and not stopped - protected Hashtable tickers; ! protected EndOfDayDateTime currentTime; ! ! protected EndOfDayDateTime startDateTime; // private EndOfDayDateTime endDateTime; ! public EndOfDayDateTime StartDateTime { get { return this.startDateTime; } --- 31,68 ---- /// </summary> [Serializable] ! public class HistoricalEndOfDayTimer : Timer { protected Hashtable tickers; ! protected DateTime startDateTime; // private EndOfDayDateTime endDateTime; + + private static DateTime timeForMarketOpen = + new DateTime( 1900 , 1 , 1 , 9 , 30 , 00 ); + private static DateTime timeForMarketClose = + new DateTime( 1900 , 1 , 1 , 16 , 00 , 00 ); + + /// <summary> + /// time when the market opens + /// </summary> + public static DateTime TimeForMarketOpen { + get { return HistoricalEndOfDayTimer.timeForMarketOpen; } + } + + /// <summary> + /// time when the market closes + /// </summary> + public static DateTime TimeForMarketClose { + get { return HistoricalEndOfDayTimer.timeForMarketClose; } + } ! /// <summary> ! /// time for one hour after market closes ! /// </summary> ! public static DateTime TimeForOneHourAfterMarketClose { ! get { return HistoricalEndOfDayTimer.TimeForMarketClose.AddHours( 1 ); } ! } ! ! public DateTime StartDateTime { get { return this.startDateTime; } *************** *** 53,125 **** // set { this.endDateTime = value; } // } - [field:NonSerialized] - public event MarketOpenEventHandler MarketOpen; - [field:NonSerialized] - public event FiveMinutesBeforeMarketCloseEventHandler FiveMinutesBeforeMarketClose; - [field:NonSerialized] - public event MarketCloseEventHandler MarketClose; - [field:NonSerialized] - public event OneHourAfterMarketCloseEventHandler OneHourAfterMarketClose; ! public HistoricalEndOfDayTimer( EndOfDayDateTime startDateTime ) { this.startDateTime = startDateTime; // this.endDateTime = EndDateTime; this.tickers = new Hashtable(); } ! ! protected void callEvents() ! { ! if ( ( this.MarketOpen != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.MarketOpen ) ) ! this.MarketOpen( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! if ( ( this.FiveMinutesBeforeMarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ) ) ! this.FiveMinutesBeforeMarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! if ( ( this.MarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.MarketClose ) ) ! this.MarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! if ( ( this.OneHourAfterMarketClose != null ) && ( this.currentTime.EndOfDaySpecificTime == ! EndOfDaySpecificTime.OneHourAfterMarketClose ) ) ! this.OneHourAfterMarketClose( this , new EndOfDayTimingEventArgs( this.currentTime ) ); ! } - protected virtual void moveNext() - { - this.currentTime.MoveNext(); - } - - protected virtual void activeTimer() - { - this.isActive = true; - this.currentTime = this.startDateTime.Copy(); - } /// <summary> ! /// Starts the time walking simulation /// </summary> ! public virtual void Start() { ! this.activeTimer(); ! while ( this.isActive ) { ! this.callEvents(); ! this.moveNext(); } } ! public EndOfDayDateTime GetCurrentTime() { ! if ( !this.isActive ) ! throw new Exception( "Start() has not been invoked yet!" + ! "GetCurrentTime() cannot be invoked before Start()" ); ! return this.currentTime; } /// <summary> ! /// Stops the timer /// </summary> ! public void Stop() { ! this.isActive = false; } } --- 75,321 ---- // set { this.endDateTime = value; } // } ! public HistoricalEndOfDayTimer( DateTime startDateTime ) { this.startDateTime = startDateTime; // this.endDateTime = EndDateTime; this.tickers = new Hashtable(); + + // HistoricalEndOfDayTimer.timeForMarketOpen = + // new DateTime( 1900 , 1 , 1 , 9 , 30 , 00 ); + // HistoricalEndOfDayTimer.timeForMarketClose = + // new DateTime( 1900 , 1 , 1 , 16 , 00 , 00 ); } ! ! protected override void initializeTimer() ! { ! this.currentDateTime = ! ExtendedDateTime.Copy( this.startDateTime ); ! } ! ! #region moveNext ! protected bool isBetweenMarketCloseAndOneHourAfterMarketClose() ! { ! bool isBetween = ! ( ( this.currentDateTime >= ! HistoricalEndOfDayTimer.GetMarketClose( this.currentDateTime ) ) ! && ! ( this.currentDateTime < ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! this.currentDateTime ) ) ); ! return isBetween; ! } ! protected override void moveNext() ! { ! if ( this.isBetweenMarketCloseAndOneHourAfterMarketClose() ) ! this.currentDateTime = ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! this.currentDateTime ); ! else ! // current time is either before market close or >= one hour ! // after market close ! this.currentDateTime = ! HistoricalEndOfDayTimer.GetNextMarketStatusSwitch( ! this.currentDateTime ); ! } ! #endregion moveNext /// <summary> ! /// true iif the argument is at market open /// </summary> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! public static bool IsMarketOpen( DateTime dateTime ) { ! bool returnValue = ! ExtendedDateTime.HaveTheSameTime( ! dateTime , HistoricalEndOfDayTimer.TimeForMarketOpen ); ! return returnValue; ! } ! ! /// <summary> ! /// true iif the argument is at market close ! /// </summary> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! public static bool IsMarketClose( DateTime dateTime ) ! { ! bool returnValue = ! ExtendedDateTime.HaveTheSameTime( ! dateTime , HistoricalEndOfDayTimer.TimeForMarketClose ); ! return returnValue; ! } ! ! /// <summary> ! /// true iif the argument is one our after market close ! /// </summary> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! public static bool IsOneHourAfterMarketClose( DateTime dateTime ) ! { ! bool returnValue = ! ExtendedDateTime.HaveTheSameTime( ! dateTime , ! HistoricalEndOfDayTimer.TimeForOneHourAfterMarketClose ); ! return returnValue; ! } ! ! /// <summary> ! /// true iif the argument is an end of day relevant time ! /// </summary> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! public static bool IsEndOfDayDateTime( DateTime dateTime ) ! { ! bool isEndOfDayDateTime = ! ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) || ! HistoricalEndOfDayTimer.IsMarketClose( dateTime ) || ! HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ); ! return isEndOfDayDateTime; ! } ! ! /// <summary> ! /// true iif the argument is either at market close or at market open ! /// </summary> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! public static bool IsMarketStatusSwitch( DateTime dateTime ) ! { ! bool isEndOfDayDateTime = ! ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) || ! HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ); ! return isEndOfDayDateTime; ! } ! ! #region GetNextMarketStatusSwitch ! // private void getNextMarketStatusSwitch_checkParameters( ! // DateTime dateTime) ! // { ! // if ( !HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) && ! // !HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! // throw new Exception( "dateTime must be a ! // } ! /// <summary> ! /// Returns either the next market close or the next market open, ! /// whichever is the nearest (all days are considered as market ! /// days, week-ends included) ! /// We have a market status switch when the market opens and when ! /// the market closes ! /// </summary> ! /// <returns></returns> ! public static DateTime GetNextMarketStatusSwitch( ! DateTime dateTime) ! { ! // this.getNextMarketStatusSwitch_checkParameters( ! // dateTime ); ! DateTime nextMarketStatusSwitch; ! if ( ExtendedDateTime.IsFirstTimeLessThenSecondTime( ! dateTime , HistoricalEndOfDayTimer.TimeForMarketOpen ) ) ! // dateTime's time is before market open ! nextMarketStatusSwitch = new DateTime( ! dateTime.Year , dateTime.Month , dateTime.Day , ! HistoricalEndOfDayTimer.TimeForMarketOpen.Hour , ! HistoricalEndOfDayTimer.TimeForMarketOpen.Minute , ! HistoricalEndOfDayTimer.TimeForMarketOpen.Second ); ! else { ! // dateTime's time is equal or after the market open ! if ( ExtendedDateTime.IsFirstTimeLessThenSecondTime( ! dateTime , HistoricalEndOfDayTimer.TimeForMarketClose ) ) ! // dateTime's time is equal or after the market open ! // AND dateTime's time is before market close ! nextMarketStatusSwitch = new DateTime( ! dateTime.Year , dateTime.Month , dateTime.Day , ! HistoricalEndOfDayTimer.TimeForMarketClose.Hour , ! HistoricalEndOfDayTimer.TimeForMarketClose.Minute , ! HistoricalEndOfDayTimer.TimeForMarketClose.Second ); ! else ! // dateTime's time is equal or after the market close ! { ! DateTime nextDay = ! dateTime.AddDays( 1 ); ! nextMarketStatusSwitch = new DateTime( ! nextDay.Year , nextDay.Month , nextDay.Day , ! HistoricalEndOfDayTimer.TimeForMarketOpen.Hour , ! HistoricalEndOfDayTimer.TimeForMarketOpen.Minute , ! HistoricalEndOfDayTimer.TimeForMarketOpen.Second ); ! } } + + // + // if ( this.EndOfDaySpecificTime < EndOfDaySpecificTime.MarketOpen ) + // nextMarketStatusSwitch = new EndOfDayDateTime( + // this.DateTime , EndOfDaySpecificTime.MarketOpen ); + // else + // { + // // this.EndOfDaySpecificTime >= EndOfDaySpecificTime.MarketOpen + // if ( this.EndOfDaySpecificTime < EndOfDaySpecificTime.MarketClose ) + // // ( this.EndOfDaySpecificTime >= EndOfDaySpecificTime.MarketOpen ) + // // AND ( this.EndOfDaySpecificTime < EndOfDaySpecificTime.MarketClose ) + // nextMarketStatusSwitch = new EndOfDayDateTime( + // this.DateTime , EndOfDaySpecificTime.MarketClose ); + // else + // // ( this.EndOfDaySpecificTime >= EndOfDaySpecificTime.MarketClose ) + // nextMarketStatusSwitch = new EndOfDayDateTime( + // this.DateTime.AddDays( 1 ) , EndOfDaySpecificTime.MarketOpen ); + // } + return nextMarketStatusSwitch; + } + #endregion GetNextMarketStatusSwitch + + /// <summary> + /// Returns the market open time, for the date of the given dateTime + /// </summary> + /// <param name="dateTime"></param> + /// <returns></returns> + public static DateTime GetMarketOpen( DateTime dateTime ) + { + DateTime date = ExtendedDateTime.GetDate( dateTime ); + DateTime marketOpen = + HistoricalEndOfDayTimer.GetNextMarketStatusSwitch( date ); + return marketOpen; + } + + /// <summary> + /// Returns the market close time, for the date of the given dateTime + /// </summary> + /// <param name="dateTime"></param> + /// <returns></returns> + public static DateTime GetMarketClose( DateTime dateTime ) + { + DateTime marketOpen = + HistoricalEndOfDayTimer.GetMarketOpen( dateTime ); + DateTime marketClose = + HistoricalEndOfDayTimer.GetNextMarketStatusSwitch( marketOpen ); + return marketClose; } ! ! /// <summary> ! /// Returns the one hour after market close time, for the ! /// date of the given dateTime ! /// </summary> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! public static DateTime GetOneHourAfterMarketClose( DateTime dateTime ) { ! DateTime marketClose = ! HistoricalEndOfDayTimer.GetMarketClose( dateTime ); ! DateTime oneHourAfterMarketClose = marketClose.AddHours( 1 ); ! return oneHourAfterMarketClose; } /// <summary> ! /// Returns returns five minutes before market close time, for the ! /// date of the given dateTime /// </summary> ! /// <param name="dateTime"></param> ! /// <returns></returns> ! public static DateTime GetFiveMinutesBeforeMarketClose( DateTime dateTime ) { ! DateTime marketClose = ! HistoricalEndOfDayTimer.GetMarketClose( dateTime ); ! DateTime fiveMinutesBeforeMarketClose = marketClose.AddMinutes( -5 ); ! return fiveMinutesBeforeMarketClose; } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:22:15
|
Update of /cvsroot/quantproject/QuantProject/b91_QuantProject In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19100 Modified Files: Main.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: Main.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b91_QuantProject/Main.cs,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Main.cs 19 Aug 2008 17:27:01 -0000 1.21 --- Main.cs 29 Sep 2008 21:22:01 -0000 1.22 *************** *** 474,479 **** // new WFLagMain().ShowDialog(); ! new FixedLengthTwoPhasesMain().Run(); ! // new PairsTradingMain().Run(); // new RunOneRank().Run(); --- 474,479 ---- // new WFLagMain().ShowDialog(); ! // new FixedLengthTwoPhasesMain().Run(); ! new PairsTradingMain().Run(); // new RunOneRank().Run(); |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:22:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19021 Modified Files: RunWalkForwardOneRank.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: RunWalkForwardOneRank.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/RunWalkForwardOneRank.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RunWalkForwardOneRank.cs 15 Oct 2005 18:21:01 -0000 1.11 --- RunWalkForwardOneRank.cs 29 Sep 2008 21:21:47 -0000 1.12 *************** *** 3,7 **** RunWalkForwardOneRank.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- RunWalkForwardOneRank.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 51,65 **** public class RunWalkForwardOneRank : Script , IWalkForwardProgressNotifier { ! private IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); ! private ReportTable reportTable; ! private EndOfDayDateTime startDateTime; ! private EndOfDayDateTime endDateTime; int numberDaysForPerformanceCalculation; ! private int numIntervalDays; ! private ProgressBarForm progressBarForm; private EndOfDayTimerHandler endOfDayTimerHandler; --- 51,65 ---- public class RunWalkForwardOneRank : Script , IWalkForwardProgressNotifier { ! private HistoricalMarketValueProvider historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); ! private ReportTable reportTable; ! private DateTime startDateTime; ! private DateTime endDateTime; int numberDaysForPerformanceCalculation; ! private int numIntervalDays; ! private ProgressBarForm progressBarForm; private EndOfDayTimerHandler endOfDayTimerHandler; *************** *** 67,79 **** private Account account; ! private IEndOfDayTimer endOfDayTimer; public RunWalkForwardOneRank() { this.reportTable = new ReportTable( "Summary_Reports" ); ! this.startDateTime = new EndOfDayDateTime( ! new DateTime( 2002 , 1 , 1 ) , EndOfDaySpecificTime.MarketOpen ); ! this.endDateTime = new EndOfDayDateTime( ! new DateTime( 2002 , 12 , 31 ) , EndOfDaySpecificTime.OneHourAfterMarketClose ); this.numberDaysForPerformanceCalculation = 120; this.numIntervalDays = 1; --- 67,85 ---- private Account account; ! private QuantProject.Business.Timing.Timer endOfDayTimer; public RunWalkForwardOneRank() { this.reportTable = new ReportTable( "Summary_Reports" ); ! this.startDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( ! new DateTime( 2002 , 1 , 1 ) ); ! // new EndOfDayDateTime( ! // new DateTime( 2002 , 1 , 1 ) , EndOfDaySpecificTime.MarketOpen ); ! this.endDateTime = ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! new DateTime( 2002 , 12 , 31 ) ); ! // new EndOfDayDateTime( ! // new DateTime( 2002 , 12 , 31 ) , EndOfDaySpecificTime.OneHourAfterMarketClose ); this.numberDaysForPerformanceCalculation = 120; this.numIntervalDays = 1; *************** *** 83,87 **** public event NewProgressEventHandler OutOfSampleNewProgress; ! #region Run private void run_initializeEndOfDayTimer() { --- 89,93 ---- public event NewProgressEventHandler OutOfSampleNewProgress; ! #region Run private void run_initializeEndOfDayTimer() { *************** *** 92,105 **** { this.account = new Account( "WalkForwardOneRank" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ) ); } private void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandler( 400 , 20 , 5 , ! this.numberDaysForPerformanceCalculation , 30 , ! this.account ); // this.endOfDayTimerHandler = new EndOfDayTimerHandler( 4 , 3 , 2 , 100 , 30 , // this.account ); --- 98,111 ---- { this.account = new Account( "WalkForwardOneRank" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider ) ); } private void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandler( 400 , 20 , 5 , ! this.numberDaysForPerformanceCalculation , 30 , ! this.account ); // this.endOfDayTimerHandler = new EndOfDayTimerHandler( 4 , 3 , 2 , 100 , 30 , // this.account ); *************** *** 128,141 **** new InSampleNewProgressEventHandler( this.inSampleNewProgressEventHandler ); } #region oneHourAfterMarketCloseEventHandler private void oneHourAfterMarketCloseEventHandler_handleProgessBarForm( ! IEndOfDayTimer endOfDayTimer ) { ! long elapsedDays = Convert.ToInt64( ((TimeSpan)( endOfDayTimer.GetCurrentTime().DateTime - ! this.startDateTime.DateTime )).TotalDays ); ! double totalDays = Convert.ToDouble( ((TimeSpan)( this.endDateTime.DateTime - ! this.startDateTime.DateTime )).TotalDays + 1); if ( Math.Floor( elapsedDays / totalDays * 100 ) > ! Math.Floor( ( elapsedDays - 1 ) / totalDays * 100 ) ) { // a new out of sample time percentage point has been elapsed --- 134,155 ---- new InSampleNewProgressEventHandler( this.inSampleNewProgressEventHandler ); } + + public void marketOpenEventHandler( + Object sender , DateTime dateTime ) + { + if ( this.account.Transactions.Count == 0 ) + this.account.AddCash( 30000 ); + } + #region oneHourAfterMarketCloseEventHandler private void oneHourAfterMarketCloseEventHandler_handleProgessBarForm( ! QuantProject.Business.Timing.Timer endOfDayTimer ) { ! long elapsedDays = Convert.ToInt64( ((TimeSpan)( endOfDayTimer.GetCurrentDateTime() - ! this.startDateTime )).TotalDays ); ! double totalDays = Convert.ToDouble( ((TimeSpan)( this.endDateTime - ! this.startDateTime )).TotalDays + 1); if ( Math.Floor( elapsedDays / totalDays * 100 ) > ! Math.Floor( ( elapsedDays - 1 ) / totalDays * 100 ) ) { // a new out of sample time percentage point has been elapsed *************** *** 146,158 **** } } ! public void marketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! if ( this.account.Transactions.Count == 0 ) ! this.account.AddCash( 30000 ); ! } ! #region oneHourAfterMarketCloseEventHandler private void showOneRankForm( object sender , ! MouseEventArgs eventArgs ) { DataGrid dataGrid = (DataGrid)sender; --- 160,167 ---- } } ! ! #region mouseEventHandler private void showOneRankForm( object sender , ! MouseEventArgs eventArgs ) { DataGrid dataGrid = (DataGrid)sender; *************** *** 177,192 **** } #endregion ! public void oneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if ( ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime > ! this.endDateTime.DateTime ) { // the simulation has reached the ending date ! this.account.EndOfDayTimer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , // @"C:\Documents and Settings\Glauco\Desktop\reports\final.qP" ); ! Report report = new Report( this.account , this.historicalQuoteProvider ); report.Create( "WFT One Rank" , this.numIntervalDays , this.endDateTime , "MSFT" ); report.TransactionGrid.MouseUp += --- 186,202 ---- } #endregion ! ! private void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! if ( ( ( QuantProject.Business.Timing.Timer )sender ).GetCurrentDateTime() > ! this.endDateTime ) { // the simulation has reached the ending date ! this.account.Timer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , // @"C:\Documents and Settings\Glauco\Desktop\reports\final.qP" ); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); report.Create( "WFT One Rank" , this.numIntervalDays , this.endDateTime , "MSFT" ); report.TransactionGrid.MouseUp += *************** *** 197,203 **** // the simulation has not reached the ending date, yet this.oneHourAfterMarketCloseEventHandler_handleProgessBarForm( ! ( IEndOfDayTimer )sender ); } #endregion public override void Run() { --- 207,226 ---- // the simulation has not reached the ending date, yet this.oneHourAfterMarketCloseEventHandler_handleProgessBarForm( ! ( QuantProject.Business.Timing.Timer )sender ); } #endregion + + private void newDateTimeEventHandler( + Object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + this.marketOpenEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + // this.marketCloseEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + } + + public override void Run() { *************** *** 207,225 **** run_initializeProgressBar(); run_initializeProgressHandlers(); ! this.endOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( this.marketOpenEventHandler ); ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.oneHourAfterMarketCloseEventHandler ); ! this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! new FiveMinutesBeforeMarketCloseEventHandler( ! this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); // this.progressBarForm.Show(); this.endOfDayTimer.Start(); } ! #endregion } } --- 230,254 ---- run_initializeProgressBar(); run_initializeProgressHandlers(); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( this.marketOpenEventHandler ); ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.oneHourAfterMarketCloseEventHandler ); ! // this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! // new FiveMinutesBeforeMarketCloseEventHandler( ! // this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! // this.progressBarForm.Show(); this.endOfDayTimer.Start(); } ! #endregion } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:22:05
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18958/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio Modified Files: WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs 28 Oct 2007 22:35:28 -0000 1.9 --- WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs 29 Sep 2008 21:21:41 -0000 1.10 *************** *** 55,59 **** protected GeneticOptimizer geneticOptimizer; protected WFLagWeightedPositions wFLagChosenPositions; ! private EndOfDayDateTime timeWhenChosePositionsIsRequested; // // first in sample quote date for driving positions --- 55,59 ---- protected GeneticOptimizer geneticOptimizer; protected WFLagWeightedPositions wFLagChosenPositions; ! private DateTime timeWhenChosePositionsIsRequested; // // first in sample quote date for driving positions *************** *** 138,154 **** } #region setChosenPositions_usingTheGeneticOptimizer ! private ReturnIntervals getReturnIntervals( EndOfDayDateTime now ) { DateTime firstInSampleDateForDrivingPositions = ! now.DateTime.AddDays( -( this.NumberDaysForInSampleOptimization - 1 ) ); DateTime lastInSampleOptimizationDate = ! now.DateTime; ReturnIntervals returnIntervals = new CloseToCloseIntervals( ! new EndOfDayDateTime( firstInSampleDateForDrivingPositions , ! EndOfDaySpecificTime.MarketClose ) , ! new EndOfDayDateTime( lastInSampleOptimizationDate , ! EndOfDaySpecificTime.MarketClose ) , this.benchmark ); return returnIntervals; --- 138,156 ---- } #region setChosenPositions_usingTheGeneticOptimizer ! private ReturnIntervals getReturnIntervals( DateTime now ) { DateTime firstInSampleDateForDrivingPositions = ! now.AddDays( -( this.NumberDaysForInSampleOptimization - 1 ) ); DateTime lastInSampleOptimizationDate = ! now; ReturnIntervals returnIntervals = new CloseToCloseIntervals( ! HistoricalEndOfDayTimer.GetMarketClose( firstInSampleDateForDrivingPositions ) , ! HistoricalEndOfDayTimer.GetMarketClose( lastInSampleOptimizationDate ) , ! // new EndOfDayDateTime( firstInSampleDateForDrivingPositions , ! // EndOfDaySpecificTime.MarketClose ) , ! // new EndOfDayDateTime( lastInSampleOptimizationDate , ! // EndOfDaySpecificTime.MarketClose ) , this.benchmark ); return returnIntervals; *************** *** 162,166 **** new WFLagGenerationDebugger( e.Generation , ! this.timeWhenChosePositionsIsRequested.DateTime , this.NumberDaysForInSampleOptimization , this.benchmark ); --- 164,168 ---- new WFLagGenerationDebugger( e.Generation , ! this.timeWhenChosePositionsIsRequested , this.NumberDaysForInSampleOptimization , this.benchmark ); *************** *** 190,194 **** private void setChosenPositions_FromDecodableGenome( IGenomeManager genomeManager , Genome genome , ! EndOfDayDateTime now ) { this.wFLagChosenPositions = --- 192,196 ---- private void setChosenPositions_FromDecodableGenome( IGenomeManager genomeManager , Genome genome , ! DateTime now ) { this.wFLagChosenPositions = *************** *** 209,213 **** public virtual void setChosenPositions_usingTheGeneticOptimizer( WFLagEligibleTickers eligibleTickersForDrivingPositions , ! EndOfDayDateTime now ) { ReturnIntervals returnIntervals = --- 211,215 ---- public virtual void setChosenPositions_usingTheGeneticOptimizer( WFLagEligibleTickers eligibleTickersForDrivingPositions , ! DateTime now ) { ReturnIntervals returnIntervals = *************** *** 247,253 **** private void chosePositions_checkParameters( WFLagEligibleTickers eligibleTickersForDrivingPositions , ! EndOfDayDateTime now ) { ! if ( now.EndOfDaySpecificTime != EndOfDaySpecificTime.OneHourAfterMarketClose ) throw new Exception( "The 'now' parameter must be one hour after market " + "close. It is not." ); --- 249,256 ---- private void chosePositions_checkParameters( WFLagEligibleTickers eligibleTickersForDrivingPositions , ! DateTime now ) { ! if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( now ) ) ! // if ( now.EndOfDaySpecificTime != EndOfDaySpecificTime.OneHourAfterMarketClose ) throw new Exception( "The 'now' parameter must be one hour after market " + "close. It is not." ); *************** *** 269,273 **** WFLagEligibleTickers eligibleTickersForDrivingPositions , WFLagEligibleTickers eligibleTickersForPortfolioPositions , ! EndOfDayDateTime now ) { this.timeWhenChosePositionsIsRequested = now; --- 272,276 ---- WFLagEligibleTickers eligibleTickersForDrivingPositions , WFLagEligibleTickers eligibleTickersForPortfolioPositions , ! DateTime now ) { this.timeWhenChosePositionsIsRequested = now; Index: WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio/WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs 16 Sep 2007 22:17:18 -0000 1.6 --- WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs 29 Sep 2008 21:21:41 -0000 1.7 *************** *** 127,135 **** // 11 ); GenomeManagement.SetRandomGenerator( seedForRandomGenerator ); ! IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); this.closeToCloseReturnsManager = new ReturnsManager( this.returnIntervalsForOptimization , ! historicalQuoteProvider ); this.wFLagMeaningForUndecodableGenomes = --- 127,135 ---- // 11 ); GenomeManagement.SetRandomGenerator( seedForRandomGenerator ); ! HistoricalMarketValueProvider historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); this.closeToCloseReturnsManager = new ReturnsManager( this.returnIntervalsForOptimization , ! historicalMarketValueProvider ); this.wFLagMeaningForUndecodableGenomes = |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:22:02
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18958/WFLagDebugger Modified Files: WFLagRunDebugger.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WFLagRunDebugger.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagRunDebugger.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFLagRunDebugger.cs 22 Jun 2006 21:39:24 -0000 1.2 --- WFLagRunDebugger.cs 29 Sep 2008 21:21:42 -0000 1.3 *************** *** 3,7 **** WFLagRunDebugger.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- WFLagRunDebugger.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 49,62 **** DateTime lastDateTime = ((DateTime)transactionHistory.GetKey( ! transactionHistory.Count - 1 ) ).AddDays( 1 ); RebuildableAccount account = new RebuildableAccount( "FromSerializedTransactions" ); account.Add( transactionHistory ); Report report = new Report( account , ! new HistoricalAdjustedQuoteProvider() ); ! report.Create( "WFT One Rank" , 1 , ! new EndOfDayDateTime( ! lastDateTime , ! EndOfDaySpecificTime.OneHourAfterMarketClose ) , "^SPX" ); WFLagReportDebugger wFLagReportDebugger = --- 49,65 ---- DateTime lastDateTime = ((DateTime)transactionHistory.GetKey( ! transactionHistory.Count - 1 ) ).AddDays( 1 ); RebuildableAccount account = new RebuildableAccount( "FromSerializedTransactions" ); account.Add( transactionHistory ); Report report = new Report( account , ! new HistoricalAdjustedQuoteProvider() ); ! report.Create( ! "WFT One Rank" , 1 , ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! lastDateTime ) , ! // new EndOfDayDateTime( ! // lastDateTime , ! // EndOfDaySpecificTime.OneHourAfterMarketClose ) , "^SPX" ); WFLagReportDebugger wFLagReportDebugger = *************** *** 64,68 **** report.TransactionGrid.MouseUp += new MouseEventHandler( ! wFLagReportDebugger.MouseClickEventHandler ); report.Show(); } --- 67,71 ---- report.TransactionGrid.MouseUp += new MouseEventHandler( ! wFLagReportDebugger.MouseClickEventHandler ); report.Show(); } |