quantproject-developers Mailing List for QuantProject (Page 29)
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-18 23:03:24
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9714/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers Modified Files: OutOfSampleChooser.cs Log Message: regions have been added to make the code more readable Index: OutOfSampleChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers/OutOfSampleChooser.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OutOfSampleChooser.cs 17 Nov 2008 19:51:04 -0000 1.3 --- OutOfSampleChooser.cs 18 Nov 2008 23:03:15 -0000 1.4 *************** *** 86,108 **** #region getInefficientCouples #region getReturnsManagerForLastSecondPhaseInterval ! private DateTime ! getIntervalBeginForLastSecondPhaseInterval( ! ReturnIntervals outOfSampleReturnIntervals ) ! { ! // this method will be invoked only if (this.returnIntervals.Count >= 2) ! int secondLastIntervalIndex = ! outOfSampleReturnIntervals.Count - 2; ! ReturnInterval secondLastInterval = ! outOfSampleReturnIntervals[ secondLastIntervalIndex ]; ! return secondLastInterval.End; ! } ! private DateTime ! getIntervalEndForLastSecondPhaseInterval( ! ReturnIntervals outOfSampleReturnIntervals ) ! { ! return outOfSampleReturnIntervals.LastInterval.Begin; ! } private ReturnInterval getReturnIntervalForLastSecondPhaseInterval( --- 86,112 ---- #region getInefficientCouples + + #region getArrayListOfInefficientCouples #region getReturnsManagerForLastSecondPhaseInterval ! // private DateTime ! // getIntervalBeginForLastSecondPhaseInterval( ! // ReturnIntervals outOfSampleReturnIntervals ) ! // { ! // // this method will be invoked only if (this.returnIntervals.Count >= 2) ! // int secondLastIntervalIndex = ! // outOfSampleReturnIntervals.Count - 2; ! // ReturnInterval secondLastInterval = ! // outOfSampleReturnIntervals[ secondLastIntervalIndex ]; ! // return secondLastInterval.End; ! // } ! // private DateTime ! // getIntervalEndForLastSecondPhaseInterval( ! // ReturnIntervals outOfSampleReturnIntervals ) ! // { ! // return outOfSampleReturnIntervals.LastInterval.Begin; ! // } ! ! #region getReturnIntervalsForLastSecondPhaseInterval private ReturnInterval getReturnIntervalForLastSecondPhaseInterval( *************** *** 140,143 **** --- 144,149 ---- return returnIntervalsForLastSecondPhaseInterval; } + #endregion getReturnIntervalsForLastSecondPhaseInterval + private ReturnsManager getReturnsManagerForLastSecondPhaseInterval( DateTime firstDateTimeToTestInefficiency , *************** *** 159,175 **** } #endregion getReturnsManagerForLastSecondPhaseInterval ! ! private double getReturnForTheLastSecondPhaseInterval( ! ReturnsManager returnsManagerForLastSecondPhaseInterval , ! WeightedPositions weightedPositions ) ! { ! // returnsManager should contain a single ReturnInterval, and ! // this ReturnInterval should be the last second phase interval ! double returnForTheLastSecondPhaseInterval = ! weightedPositions.GetReturn( 0 , ! returnsManagerForLastSecondPhaseInterval ); ! return returnForTheLastSecondPhaseInterval; ! } /// <summary> /// Inverts one of the two positions --- 165,172 ---- } #endregion getReturnsManagerForLastSecondPhaseInterval ! ! #region getInefficientCouples + #region addPositionsIfInefficiencyForCurrentCoupleIsInTheRange /// <summary> /// Inverts one of the two positions *************** *** 190,193 **** --- 187,203 ---- return candidateForPortfolio; } + + #region getPositionsIfInefficiencyIsInTheRange + private double getReturnForTheLastSecondPhaseInterval( + ReturnsManager returnsManagerForLastSecondPhaseInterval , + WeightedPositions weightedPositions ) + { + // returnsManager should contain a single ReturnInterval, and + // this ReturnInterval should be the last second phase interval + double returnForTheLastSecondPhaseInterval = + weightedPositions.GetReturn( 0 , + returnsManagerForLastSecondPhaseInterval ); + return returnForTheLastSecondPhaseInterval; + } // if the currentWeightedPositions' return satisfies the thresholds // then this method returns the WeightedPositions that might be opened. *************** *** 227,230 **** --- 237,242 ---- return weightedPositionsToBeOpened; } + #endregion getPositionsIfInefficiencyIsInTheRange + private void addPositionsIfInefficiencyForCurrentCoupleIsInTheRange( *************** *** 245,248 **** --- 257,262 ---- inefficientCouples.Add( weightedPositionsThatMightBeOpended ); } + #endregion addPositionsIfInefficiencyForCurrentCoupleIsInTheRange + protected ArrayList getInefficientCouples( TestingPositions[] bestTestingPositionsInSample , *************** *** 260,263 **** --- 274,279 ---- return inefficientCouples; } + #endregion getInefficientCouples + private ArrayList getArrayListOfInefficientCouples( *************** *** 280,283 **** --- 296,300 ---- return inefficientCouples; } + #endregion getArrayListOfInefficientCouples #region getInefficientCouplesFromArrayList *************** *** 371,375 **** inSampleReturnsManager ); return positionsToBeOpened; ! } #endregion getPositionsToBeOpened_actually --- 388,392 ---- inSampleReturnsManager ); return positionsToBeOpened; ! } #endregion getPositionsToBeOpened_actually |
|
From: Glauco S. <gla...@us...> - 2008-11-18 23:02:03
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9546/b4_Business/a2_Strategies Modified Files: EndOfDayStrategyBackTester.cs Log Message: a bug has been fixed Index: EndOfDayStrategyBackTester.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EndOfDayStrategyBackTester.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** EndOfDayStrategyBackTester.cs 12 Nov 2008 20:42:39 -0000 1.11 --- EndOfDayStrategyBackTester.cs 18 Nov 2008 23:01:52 -0000 1.12 *************** *** 189,193 **** this.timer = timer; ! this.initialize_endOfDayTimer(); this.account = this.accountProvider.GetAccount( this.timer, this.historicalMarketValueProvider); --- 189,193 ---- this.timer = timer; ! // this.initialize_endOfDayTimer(); this.account = this.accountProvider.GetAccount( this.timer, this.historicalMarketValueProvider); |
|
From: Glauco S. <gla...@us...> - 2008-11-18 23:01:43
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9474/b4_Business/a07_DataProviders Modified Files: HistoricalBarProvider.cs Log Message: TickerNotExchangedException was never thrown in the previous revision Index: HistoricalBarProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders/HistoricalBarProvider.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HistoricalBarProvider.cs 8 Nov 2008 20:25:21 -0000 1.1 --- HistoricalBarProvider.cs 18 Nov 2008 23:01:28 -0000 1.2 *************** *** 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; using QuantProject.Data.DataProviders.Bars.Caching; --- 19,27 ---- 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; using QuantProject.Data.DataProviders.Bars.Caching; *************** *** 46,51 **** DateTime dateTime ) { ! double marketValue = this.historicalBarProvider.GetMarketValue( ticker , dateTime ); return marketValue; } --- 47,61 ---- DateTime dateTime ) { ! double marketValue = double.MinValue; ! try ! { ! marketValue = this.historicalBarProvider.GetMarketValue( ticker , dateTime ); + } + catch( MissingBarException missingBarException ) + { + string forBreakPoint = missingBarException.Message; forBreakPoint += " "; + throw new TickerNotExchangedException( ticker , dateTime ); + } return marketValue; } |
|
From: Glauco S. <gla...@us...> - 2008-11-18 23:00:44
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9364/b4_Business/a05_Timing Modified Files: IndexBasedHistoricalTimer.cs Log Message: a bug has been fixed Index: IndexBasedHistoricalTimer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/IndexBasedHistoricalTimer.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IndexBasedHistoricalTimer.cs 14 Nov 2008 15:51:18 -0000 1.2 --- IndexBasedHistoricalTimer.cs 18 Nov 2008 23:00:33 -0000 1.3 *************** *** 66,70 **** { this.dateTimesToBeThrown = new List< DateTime >(); ! foreach ( DateTime dateTime in dateTimesToBeThrownHistory ) this.dateTimesToBeThrown.Add( dateTime ); } --- 66,70 ---- { this.dateTimesToBeThrown = new List< DateTime >(); ! foreach ( DateTime dateTime in dateTimesToBeThrownHistory.Keys ) this.dateTimesToBeThrown.Add( dateTime ); } |
|
From: Glauco S. <gla...@us...> - 2008-11-18 22:59:38
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9228/b3_Data/DataTables Modified Files: Bars.cs Log Message: a bug has been fixed int the method public static History GetMarketDateTimes( string ticker , DateTime firstDateTime , DateTime lastDateTime , List< Time > dailyTimes, int intervalFrameInSeconds ) Index: Bars.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Bars.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Bars.cs 14 Nov 2008 15:51:18 -0000 1.3 --- Bars.cs 18 Nov 2008 22:59:29 -0000 1.4 *************** *** 65,69 **** { ! QuantProject.DataAccess.Tables.Bars.SetDataTable( tickerCollection , dateTime , this, intervalFrameInSeconds ); --- 65,69 ---- { ! QuantProject.DataAccess.Tables.Bars.SetDataTable( tickerCollection , dateTime , this, intervalFrameInSeconds ); *************** *** 119,129 **** QuantProject.DataAccess.Tables.Bars.GetFirstBarDateTime( ticker, intervalFrameInSeconds ) , QuantProject.DataAccess.Tables.Bars.GetLastBarDateTime( ticker, intervalFrameInSeconds ), ! intervalFrameInSeconds); } ! public Bars(SerializationInfo info, StreamingContext context) ! : base(info, context) ! { ! } private void fillDataTable( string ticker , DateTime startDateTime , DateTime endDateTime, int intervalFrameInSeconds ) --- 119,129 ---- QuantProject.DataAccess.Tables.Bars.GetFirstBarDateTime( ticker, intervalFrameInSeconds ) , QuantProject.DataAccess.Tables.Bars.GetLastBarDateTime( ticker, intervalFrameInSeconds ), ! intervalFrameInSeconds); } ! public Bars(SerializationInfo info, StreamingContext context) ! : base(info, context) ! { ! } private void fillDataTable( string ticker , DateTime startDateTime , DateTime endDateTime, int intervalFrameInSeconds ) *************** *** 131,137 **** { ! QuantProject.DataAccess.Tables.Bars.SetDataTable( ticker , startDateTime , endDateTime , this, intervalFrameInSeconds ); ! this.setPrimaryKeys(); } --- 131,137 ---- { ! QuantProject.DataAccess.Tables.Bars.SetDataTable( ticker , startDateTime , endDateTime , this, intervalFrameInSeconds ); ! this.setPrimaryKeys(); } *************** *** 153,157 **** /// <returns></returns> public static History GetMarketDateTimes( string ticker , ! DateTime firstDateTime , DateTime lastDateTime, int intervalFrameInSeconds ) { --- 153,157 ---- /// <returns></returns> public static History GetMarketDateTimes( string ticker , ! DateTime firstDateTime , DateTime lastDateTime, int intervalFrameInSeconds ) { *************** *** 192,196 **** #region removeMissingTimes ! #region removeMissingTime private static bool isTimeInDailyTimes( DateTime dateTime , List< Time > dailyTimes ) --- 192,200 ---- #region removeMissingTimes ! #region getDateTimesToBeRemoved ! ! #region addDateTimesToBeRemoved ! ! #region addMissingTimeIfTheCase private static bool isTimeInDailyTimes( DateTime dateTime , List< Time > dailyTimes ) *************** *** 201,221 **** return isInDailyTimes; } ! private static void removeMissingTime( DateTime candidateToBeRemoved , ! List< Time > dailyTimes , History marketDateTimes ) { if ( !Bars.isTimeInDailyTimes( candidateToBeRemoved , dailyTimes ) ) // the candidate's time is not in the given list of daily times ! marketDateTimes.Remove( candidateToBeRemoved ); } - #endregion removeMissingTime private static void removeMissingTimes( List< Time > dailyTimes , History marketDateTimes ) { ! foreach ( DateTime dateTime in marketDateTimes ) ! Bars.removeMissingTime( ! dateTime , dailyTimes , marketDateTimes ); } private static History getMarketDateTimes( string ticker , DateTime firstDateTime , DateTime lastDateTime , --- 205,254 ---- return isInDailyTimes; } ! private static void addMissingTimeIfTheCase( DateTime candidateToBeRemoved , ! List< Time > dailyTimes , List< DateTime > dateTimesToBeRemoved ) { if ( !Bars.isTimeInDailyTimes( candidateToBeRemoved , dailyTimes ) ) // the candidate's time is not in the given list of daily times ! dateTimesToBeRemoved.Add( candidateToBeRemoved ); ! } ! #endregion addMissingTimeIfTheCase ! ! private static void addDateTimesToBeRemoved( ! List< Time > dailyTimes , History marketDateTimes , ! List< DateTime > dateTimesToBeRemoved) ! { ! foreach ( DateTime dateTime in marketDateTimes.Keys ) ! Bars.addMissingTimeIfTheCase( ! dateTime , dailyTimes , dateTimesToBeRemoved ); ! } ! #endregion addDateTimesToBeRemoved ! ! private static List< DateTime > getDateTimesToBeRemoved( ! List< Time > dailyTimes , History marketDateTimes ) ! { ! List< DateTime > dateTimesToBeRemoved = new List< DateTime >(); ! Bars.addDateTimesToBeRemoved( ! dailyTimes , marketDateTimes , dateTimesToBeRemoved ); ! return dateTimesToBeRemoved; ! } ! #endregion getDateTimesToBeRemoved ! ! private static void removeMissingTimes( ! List< DateTime > dateTimesToBeRemoved , History marketDateTimes ) ! { ! foreach ( DateTime dateTime in dateTimesToBeRemoved ) ! marketDateTimes.Remove( dateTime ); } private static void removeMissingTimes( List< Time > dailyTimes , History marketDateTimes ) { ! List< DateTime > dateTimesToBeRemoved = Bars.getDateTimesToBeRemoved( ! dailyTimes , marketDateTimes ); ! Bars.removeMissingTimes( dateTimesToBeRemoved , marketDateTimes ); } + #endregion removeMissingTimes + private static History getMarketDateTimes( string ticker , DateTime firstDateTime , DateTime lastDateTime , *************** *** 228,232 **** return marketDateTimes; } - #endregion removeMissingTimes #endregion getMarketDateTimes --- 261,264 ---- *************** *** 255,259 **** #region GetCommonMarketDateTimes private static Hashtable getMarketDateTimes( ICollection tickers , DateTime firstDateTime , ! DateTime lastDateTime, int intervalFrameInSeconds ) { --- 287,291 ---- #region GetCommonMarketDateTimes private static Hashtable getMarketDateTimes( ICollection tickers , DateTime firstDateTime , ! DateTime lastDateTime, int intervalFrameInSeconds ) { *************** *** 261,269 **** foreach ( string ticker in tickers ) if ( !marketDateTimes.ContainsKey( ticker ) ) ! { ! SortedList marketDateTimesForSingleTicker = ! GetMarketDateTimes( ticker , firstDateTime , lastDateTime, intervalFrameInSeconds ); ! marketDateTimes.Add( ticker , marketDateTimesForSingleTicker ); ! } return marketDateTimes; --- 293,301 ---- foreach ( string ticker in tickers ) if ( !marketDateTimes.ContainsKey( ticker ) ) ! { ! SortedList marketDateTimesForSingleTicker = ! GetMarketDateTimes( ticker , firstDateTime , lastDateTime, intervalFrameInSeconds ); ! marketDateTimes.Add( ticker , marketDateTimesForSingleTicker ); ! } return marketDateTimes; *************** *** 300,308 **** public static SortedList GetCommonMarketDateTimes( ICollection tickers , ! DateTime firstDateTime , DateTime lastDateTime, int intervalFrameInSeconds ) { Hashtable marketDateTimes = getMarketDateTimes( tickers , firstDateTime , lastDateTime, intervalFrameInSeconds ); ! return getCommonMarketDateTimes( tickers , firstDateTime , lastDateTime , marketDateTimes ); } --- 332,340 ---- public static SortedList GetCommonMarketDateTimes( ICollection tickers , ! DateTime firstDateTime , DateTime lastDateTime, int intervalFrameInSeconds ) { Hashtable marketDateTimes = getMarketDateTimes( tickers , firstDateTime , lastDateTime, intervalFrameInSeconds ); ! return getCommonMarketDateTimes( tickers , firstDateTime , lastDateTime , marketDateTimes ); } |
|
From: Glauco S. <gla...@us...> - 2008-11-18 22:57:06
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9149/b2_DataAccess/Tables Modified Files: Bars.cs Log Message: bug fixed in sql string: barInterval is numeric (it was treated as a text field) Index: Bars.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Bars.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Bars.cs 14 Nov 2008 15:51:18 -0000 1.2 --- Bars.cs 18 Nov 2008 22:56:54 -0000 1.3 *************** *** 263,267 **** "bars." + Bars.TickerFieldName + "=tickers_tickerGroups." + Tickers_tickerGroups.Ticker + " " + "where " + Tickers_tickerGroups.GroupID + "='" + tickerOrGroupID + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + --- 263,267 ---- "bars." + Bars.TickerFieldName + "=tickers_tickerGroups." + Tickers_tickerGroups.Ticker + " " + "where " + Tickers_tickerGroups.GroupID + "='" + tickerOrGroupID + "' and " + ! Bars.IntervalFrameInSeconds + "=" + intervalFrameInSeconds + " " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + *************** *** 270,274 **** sql = "select * from bars " + "where " + Bars.TickerFieldName + "='" + tickerOrGroupID + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + --- 270,274 ---- sql = "select * from bars " + "where " + Bars.TickerFieldName + "='" + tickerOrGroupID + "' and " + ! Bars.IntervalFrameInSeconds + "=" + intervalFrameInSeconds + " " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + |
|
From: Marco M. <mi...@us...> - 2008-11-18 22:31:35
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Timing In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7856/b1_ADT/Timing Modified Files: Time.cs Log Message: Static method IsValidTimeFormat has been simplified (my previous code was totally insane ...) Index: Time.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Timing/Time.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Time.cs 14 Nov 2008 15:57:46 -0000 1.2 --- Time.cs 18 Nov 2008 22:31:29 -0000 1.3 *************** *** 30,75 **** public struct Time : IEquatable<Time> , IComparable<Time> { - #region IsValidTimeFormat public static bool IsValidTimeFormat ( string stringRepresentingTime ) { ! bool returnValue = false; ! char[] chars = stringRepresentingTime.ToCharArray(); ! if( ! //first - hour ! (chars[0]=='0' || chars[0]=='1' || chars[0]=='2') && ! //second - hour ! ( (chars[0]=='0' || chars[0]=='1') && ! (chars[1]=='0' || chars[1]=='1' || chars[1]=='2' || ! chars[1]=='3' || chars[1]=='4' || chars[1]=='5' || ! chars[1]=='6' || chars[1]=='7' || chars[1]=='8' || chars[1]=='9') || ! chars[0] == '2' && ! (chars[1]=='0' || chars[1]=='1' || chars[1]=='2' || ! chars[1]=='3' || chars[1]=='4') ) && ! //third - separator ! (chars[2]==':') && ! //fourth - minute ! (chars[3]=='0' || chars[3]=='1' || chars[3]=='2' || ! chars[3]=='3' || chars[3]=='4' || chars[3]=='5') && ! //fifth - minute ! (chars[4]=='0' || chars[4]=='1' || chars[4]=='2' || ! chars[4]=='3' || chars[4]=='4' || chars[4]=='5' || ! chars[4]=='6' || chars[4]=='7' || chars[4]=='8' || chars[4]=='9') && ! //sixth - separator ! (chars[5]==':') && ! //seventh - second ! (chars[6]=='0' || chars[6]=='1' || chars[6]=='2' || ! chars[6]=='3' || chars[6]=='4' || chars[6]=='5') && ! //eighth - second ! (chars[7]=='0' || chars[7]=='1' || chars[7]=='2' || ! chars[7]=='3' || chars[7]=='4' || chars[7]=='5' || ! chars[7]=='6' || chars[7]=='7' || chars[7]=='8' || chars[7]=='9') ! ) ! returnValue = true; ! return returnValue; } ! #endregion isValidTimeFormat ! ! /// <summary> /// Returns a new DateTime, having the date as the given dateTime --- 30,49 ---- public struct Time : IEquatable<Time> , IComparable<Time> { public static bool IsValidTimeFormat ( string stringRepresentingTime ) { ! int hour = Convert.ToInt32(stringRepresentingTime.Substring(0,2)); ! int minute = Convert.ToInt32(stringRepresentingTime.Substring(3,2)); ! int second = Convert.ToInt32(stringRepresentingTime.Substring(6,2)); ! string firstSeparator = stringRepresentingTime.Substring(2,1); ! string secondSeparator = stringRepresentingTime.Substring(5,1); ! return (stringRepresentingTime.Length == 8) && ! (hour >= 0 && hour <= 24) && ! (firstSeparator == ":") && ! (minute >= 0 && minute <= 59) && ! (secondSeparator == ":") && ! (second >= 0 && second <= 59); } ! /// <summary> /// Returns a new DateTime, having the date as the given dateTime *************** *** 84,89 **** time.Hour , time.Minute , time.Second ); } ! ! private DateTime standardDateTime; --- 58,62 ---- time.Hour , time.Minute , time.Second ); } ! private DateTime standardDateTime; *************** *** 121,124 **** --- 94,98 ---- int minute = Convert.ToInt32(stringRepresentingTime.Substring(3,2)); int second = Convert.ToInt32(stringRepresentingTime.Substring(6,2)); + return new DateTime(1900, 1, 1, hour, minute, second); } *************** *** 126,131 **** private void time_checkParameter ( string stringRepresentingTime ) { ! if( stringRepresentingTime.Length != 8 || ! !Time.IsValidTimeFormat( stringRepresentingTime ) ) throw new Exception("string is not in the requested time-format hh:mm:ss"); } --- 100,104 ---- private void time_checkParameter ( string stringRepresentingTime ) { ! if( !Time.IsValidTimeFormat( stringRepresentingTime ) ) throw new Exception("string is not in the requested time-format hh:mm:ss"); } |
|
From: Glauco S. <gla...@us...> - 2008-11-17 19:54:05
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv21278/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies Modified Files: PairsTradingStrategy.cs Log Message: - changed to work with the new OutOfSampleChooser - this.returnIntervals is not used anymore - now, the inefficiency is tested between two DateTime(s) Index: PairsTradingStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies/PairsTradingStrategy.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PairsTradingStrategy.cs 29 Sep 2008 21:21:35 -0000 1.5 --- PairsTradingStrategy.cs 17 Nov 2008 19:53:58 -0000 1.6 *************** *** 109,122 **** } ! protected override WeightedPositions getPositionsToBeOpened() { ! WeightedPositions weightedPositions = this.outOfSampleChooser.GetPositionsToBeOpened( this.bestTestingPositionsInSample , ! this.returnIntervals , this.historicalMarketValueProviderForChosingPositionsOutOfSample , this.inSampleReturnsManager ); ! return weightedPositions; } protected override LogItem getLogItem( EligibleTickers eligibleTickers ) --- 109,177 ---- } ! #region getPositionsToBeOpened ! ! #region getPositionsToBeOpened_withAtLeastASecondPhaseInterval ! ! #region getFirstDateTimeToTestInefficiency ! private DateTime ! getIntervalBeginForLastSecondPhaseInterval() { ! // this method will be invoked only if (this.returnIntervals.Count >= 2) ! int secondLastIntervalIndex = ! this.returnIntervals.Count - 2; ! ReturnInterval secondLastInterval = ! this.returnIntervals[ secondLastIntervalIndex ]; ! return secondLastInterval.End; ! } ! private DateTime getFirstDateTimeToTestInefficiency() ! { ! DateTime firstDateTimeToTestInefficiency = ! this.getIntervalBeginForLastSecondPhaseInterval(); ! return firstDateTimeToTestInefficiency; ! } ! #endregion getFirstDateTimeToTestInefficiency ! ! #region getLastDateTimeToTestInefficiency ! private DateTime ! getIntervalEndForLastSecondPhaseInterval() ! { ! return this.returnIntervals.LastInterval.Begin; ! } ! private DateTime getLastDateTimeToTestInefficiency() ! { ! DateTime lastDateTimeToTestInefficiency = ! this.getIntervalEndForLastSecondPhaseInterval(); ! return lastDateTimeToTestInefficiency; ! } ! #endregion getLastDateTimeToTestInefficiency ! ! private WeightedPositions getPositionsToBeOpened_withAtLeastASecondPhaseInterval() ! { ! DateTime firstDateTimeToTestInefficiency = ! this.getFirstDateTimeToTestInefficiency(); ! DateTime lastDateTimeToTestInefficiency = ! this.getLastDateTimeToTestInefficiency(); ! WeightedPositions positionsToBeOpened = this.outOfSampleChooser.GetPositionsToBeOpened( this.bestTestingPositionsInSample , ! firstDateTimeToTestInefficiency , ! lastDateTimeToTestInefficiency , ! // this.returnIntervals , this.historicalMarketValueProviderForChosingPositionsOutOfSample , this.inSampleReturnsManager ); ! return positionsToBeOpened; } + #endregion getPositionsToBeOpened_withAtLeastASecondPhaseInterval + + protected override WeightedPositions getPositionsToBeOpened() + { + WeightedPositions positionsToBeOpened = null; + if ( this.returnIntervals.Count >= 2 ) + // // at least a second phase interval exists + positionsToBeOpened = + this.getPositionsToBeOpened_withAtLeastASecondPhaseInterval(); + return positionsToBeOpened; + } + #endregion getPositionsToBeOpened protected override LogItem getLogItem( EligibleTickers eligibleTickers ) |
|
From: Glauco S. <gla...@us...> - 2008-11-17 19:51:15
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20901/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers Modified Files: OutOfSampleChooser.cs Log Message: - changed to handler intraday strategy - outOfSampleReturnIntervals are not used anymore - now, the inefficiency is tested between two intraday DateTime(s) Index: OutOfSampleChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers/OutOfSampleChooser.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OutOfSampleChooser.cs 29 Sep 2008 21:19:47 -0000 1.2 --- OutOfSampleChooser.cs 17 Nov 2008 19:51:04 -0000 1.3 *************** *** 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; *************** *** 72,75 **** --- 72,87 ---- #region GetPositionsToBeOpened + + private void checkParameters( + DateTime firstDateTimeToTestInefficiency , + DateTime lastDateTimeToTestInefficiency ) + { + if ( firstDateTimeToTestInefficiency >= lastDateTimeToTestInefficiency ) + throw new Exception( + "The first date time to test inefficiency must be strictly before " + + "the last date time to test inefficiency." ); + } + + #region getPositionsToBeOpened_actually #region getInefficientCouples *************** *** 78,82 **** private DateTime getIntervalBeginForLastSecondPhaseInterval( ! ReturnIntervals outOfSampleReturnIntervals ) { // this method will be invoked only if (this.returnIntervals.Count >= 2) --- 90,94 ---- private DateTime getIntervalBeginForLastSecondPhaseInterval( ! ReturnIntervals outOfSampleReturnIntervals ) { // this method will be invoked only if (this.returnIntervals.Count >= 2) *************** *** 89,93 **** private DateTime getIntervalEndForLastSecondPhaseInterval( ! ReturnIntervals outOfSampleReturnIntervals ) { return outOfSampleReturnIntervals.LastInterval.Begin; --- 101,105 ---- private DateTime getIntervalEndForLastSecondPhaseInterval( ! ReturnIntervals outOfSampleReturnIntervals ) { return outOfSampleReturnIntervals.LastInterval.Begin; *************** *** 95,117 **** private ReturnInterval getReturnIntervalForLastSecondPhaseInterval( ! ReturnIntervals outOfSampleReturnIntervals ) { ! DateTime intervalBegin = ! this.getIntervalBeginForLastSecondPhaseInterval( ! outOfSampleReturnIntervals ); ! DateTime intervalEnd = ! this.getIntervalEndForLastSecondPhaseInterval( ! outOfSampleReturnIntervals ); ReturnInterval returnIntervalForLastSecondPhaseInterval = ! new ReturnInterval( intervalBegin , intervalEnd ); return returnIntervalForLastSecondPhaseInterval; } private ReturnIntervals getReturnIntervalsForLastSecondPhaseInterval( ! ReturnIntervals outOfSampleReturnIntervals ) { ReturnInterval returnIntervalForLastSecondPhaseInterval = this.getReturnIntervalForLastSecondPhaseInterval( ! outOfSampleReturnIntervals ); ReturnIntervals returnIntervalsForLastSecondPhaseInterval = new ReturnIntervals( returnIntervalForLastSecondPhaseInterval ); --- 107,139 ---- private ReturnInterval getReturnIntervalForLastSecondPhaseInterval( ! DateTime firstDateTimeToTestInefficiency , ! DateTime lastDateTimeToTestInefficiency ! // ReturnIntervals outOfSampleReturnIntervals ! ) { ! // DateTime intervalBegin = ! // this.getIntervalBeginForLastSecondPhaseInterval( ! // outOfSampleReturnIntervals ); ! // DateTime intervalEnd = ! // this.getIntervalEndForLastSecondPhaseInterval( ! // outOfSampleReturnIntervals ); ReturnInterval returnIntervalForLastSecondPhaseInterval = ! new ReturnInterval( ! firstDateTimeToTestInefficiency , lastDateTimeToTestInefficiency ); return returnIntervalForLastSecondPhaseInterval; } private ReturnIntervals getReturnIntervalsForLastSecondPhaseInterval( ! DateTime firstDateTimeToTestInefficiency , ! DateTime lastDateTimeToTestInefficiency ! // ReturnIntervals outOfSampleReturnIntervals ! ) { ReturnInterval returnIntervalForLastSecondPhaseInterval = this.getReturnIntervalForLastSecondPhaseInterval( ! firstDateTimeToTestInefficiency , ! lastDateTimeToTestInefficiency ! // outOfSampleReturnIntervals ! ); ReturnIntervals returnIntervalsForLastSecondPhaseInterval = new ReturnIntervals( returnIntervalForLastSecondPhaseInterval ); *************** *** 119,123 **** } private ReturnsManager getReturnsManagerForLastSecondPhaseInterval( ! ReturnIntervals outOfSampleReturnIntervals , HistoricalMarketValueProvider historicalMarketValueProviderForChosingPositionsOutOfSample ) --- 141,147 ---- } private ReturnsManager getReturnsManagerForLastSecondPhaseInterval( ! DateTime firstDateTimeToTestInefficiency , ! DateTime lastDateTimeToTestInefficiency , ! // ReturnIntervals outOfSampleReturnIntervals , HistoricalMarketValueProvider historicalMarketValueProviderForChosingPositionsOutOfSample ) *************** *** 125,138 **** ReturnIntervals returnIntervals = this.getReturnIntervalsForLastSecondPhaseInterval( ! outOfSampleReturnIntervals ); ! // ReturnsManager returnsManager = ! // new ReturnsManager( returnIntervals , ! // this.historicalAdjustedQuoteProvider ); ReturnsManager returnsManager = new ReturnsManager( returnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); return returnsManager; } #endregion getReturnsManagerForLastSecondPhaseInterval private double getReturnForTheLastSecondPhaseInterval( ReturnsManager returnsManagerForLastSecondPhaseInterval , --- 149,163 ---- ReturnIntervals returnIntervals = this.getReturnIntervalsForLastSecondPhaseInterval( ! firstDateTimeToTestInefficiency , ! lastDateTimeToTestInefficiency ! // outOfSampleReturnIntervals ! ); ReturnsManager returnsManager = new ReturnsManager( returnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); return returnsManager; } #endregion getReturnsManagerForLastSecondPhaseInterval + private double getReturnForTheLastSecondPhaseInterval( ReturnsManager returnsManagerForLastSecondPhaseInterval , *************** *** 143,147 **** double returnForTheLastSecondPhaseInterval = weightedPositions.GetReturn( 0 , ! returnsManagerForLastSecondPhaseInterval ); return returnForTheLastSecondPhaseInterval; } --- 168,172 ---- double returnForTheLastSecondPhaseInterval = weightedPositions.GetReturn( 0 , ! returnsManagerForLastSecondPhaseInterval ); return returnForTheLastSecondPhaseInterval; } *************** *** 171,176 **** private WeightedPositions getPositionsIfInefficiencyIsInTheRange( ! ReturnsManager returnsManagerForLastSecondPhaseInterval , ! WeightedPositions currentWeightedPositions ) { WeightedPositions weightedPositionsToBeOpened = null; --- 196,201 ---- private WeightedPositions getPositionsIfInefficiencyIsInTheRange( ! ReturnsManager returnsManagerForLastSecondPhaseInterval , ! WeightedPositions currentWeightedPositions ) { WeightedPositions weightedPositionsToBeOpened = null; *************** *** 179,195 **** double returnForTheLastSecondPhaseInterval = this.getReturnForTheLastSecondPhaseInterval( ! returnsManagerForLastSecondPhaseInterval , ! currentWeightedPositions ); if ( ( returnForTheLastSecondPhaseInterval >= ! this.minThresholdForGoingLong ) && ! ( returnForTheLastSecondPhaseInterval <= ! this.maxThresholdForGoingLong ) ) // it looks like there has been an inefficiency that // might be recovered, by going short weightedPositionsToBeOpened = currentWeightedPositions.Opposite; if ( ( -returnForTheLastSecondPhaseInterval >= ! this.minThresholdForGoingShort ) && ! ( -returnForTheLastSecondPhaseInterval <= ! this.maxThresholdForGoingShort ) ) // it looks like there has been an inefficiency that // might be recovered, by going long --- 204,220 ---- double returnForTheLastSecondPhaseInterval = this.getReturnForTheLastSecondPhaseInterval( ! returnsManagerForLastSecondPhaseInterval , ! currentWeightedPositions ); if ( ( returnForTheLastSecondPhaseInterval >= ! this.minThresholdForGoingLong ) && ! ( returnForTheLastSecondPhaseInterval <= ! this.maxThresholdForGoingLong ) ) // it looks like there has been an inefficiency that // might be recovered, by going short weightedPositionsToBeOpened = currentWeightedPositions.Opposite; if ( ( -returnForTheLastSecondPhaseInterval >= ! this.minThresholdForGoingShort ) && ! ( -returnForTheLastSecondPhaseInterval <= ! this.maxThresholdForGoingShort ) ) // it looks like there has been an inefficiency that // might be recovered, by going long *************** *** 204,211 **** private void addPositionsIfInefficiencyForCurrentCoupleIsInTheRange( ! TestingPositions[] bestTestingPositionsInSample , ! ReturnsManager returnsManagerForLastSecondPhaseInterval , ! int currentTestingPositionsIndex , ! ArrayList inefficientCouples ) { WeightedPositions currentWeightedPositions = --- 229,236 ---- private void addPositionsIfInefficiencyForCurrentCoupleIsInTheRange( ! TestingPositions[] bestTestingPositionsInSample , ! ReturnsManager returnsManagerForLastSecondPhaseInterval , ! int currentTestingPositionsIndex , ! ArrayList inefficientCouples ) { WeightedPositions currentWeightedPositions = *************** *** 215,219 **** WeightedPositions weightedPositionsThatMightBeOpended = this.getPositionsIfInefficiencyIsInTheRange( ! returnsManagerForLastSecondPhaseInterval , candidateForPortfolio ); if ( weightedPositionsThatMightBeOpended != null ) // the current couple has not an inefficiency that's in the range --- 240,244 ---- WeightedPositions weightedPositionsThatMightBeOpended = this.getPositionsIfInefficiencyIsInTheRange( ! returnsManagerForLastSecondPhaseInterval , candidateForPortfolio ); if ( weightedPositionsThatMightBeOpended != null ) // the current couple has not an inefficiency that's in the range *************** *** 226,231 **** ArrayList inefficientCouples = new ArrayList(); for ( int currentTestingPositionsIndex = 0 ; ! currentTestingPositionsIndex < bestTestingPositionsInSample.Length ; ! currentTestingPositionsIndex++ ) this.addPositionsIfInefficiencyForCurrentCoupleIsInTheRange( bestTestingPositionsInSample , --- 251,256 ---- ArrayList inefficientCouples = new ArrayList(); for ( int currentTestingPositionsIndex = 0 ; ! currentTestingPositionsIndex < bestTestingPositionsInSample.Length ; ! currentTestingPositionsIndex++ ) this.addPositionsIfInefficiencyForCurrentCoupleIsInTheRange( bestTestingPositionsInSample , *************** *** 233,266 **** currentTestingPositionsIndex , inefficientCouples ); - // - // while ( ( weightedPositionsToBeOpended == null ) - // && ( currentTestingPositionsIndex < bestTestingPositionsInSample.Length ) ) - // { - // weightedPositionsToBeOpended = - // this.getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( - // bestTestingPositionsInSample , - // returnsManagerForLastSecondPhaseInterval , - // currentTestingPositionsIndex ); - // currentTestingPositionsIndex++; - // } - // return weightedPositionsToBeOpended; return inefficientCouples; } private ArrayList getArrayListOfInefficientCouples( ! TestingPositions[] bestTestingPositionsInSample , ! ReturnIntervals outOfSampleReturnIntervals , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample ) { ReturnsManager returnsManagerForLastSecondPhaseInterval = this.getReturnsManagerForLastSecondPhaseInterval( ! outOfSampleReturnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); ArrayList inefficientCouples = this.getInefficientCouples( bestTestingPositionsInSample , ! returnsManagerForLastSecondPhaseInterval ); return inefficientCouples; } #region getInefficientCouplesFromArrayList private WeightedPositions[] getInefficientCouplesFromArrayList_actually( --- 258,284 ---- currentTestingPositionsIndex , inefficientCouples ); return inefficientCouples; } private ArrayList getArrayListOfInefficientCouples( ! TestingPositions[] bestTestingPositionsInSample , ! DateTime firstDateTimeToTestInefficiency , ! DateTime lastDateTimeToTestInefficiency , ! // ReturnIntervals outOfSampleReturnIntervals , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample ) { ReturnsManager returnsManagerForLastSecondPhaseInterval = this.getReturnsManagerForLastSecondPhaseInterval( ! firstDateTimeToTestInefficiency , ! lastDateTimeToTestInefficiency , ! // outOfSampleReturnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); ArrayList inefficientCouples = this.getInefficientCouples( bestTestingPositionsInSample , ! returnsManagerForLastSecondPhaseInterval ); return inefficientCouples; } + #region getInefficientCouplesFromArrayList private WeightedPositions[] getInefficientCouplesFromArrayList_actually( *************** *** 282,339 **** inefficientCouples = this.getInefficientCouplesFromArrayList_actually( ! arrayListOfInefficientCouples ); return inefficientCouples; } #endregion getInefficientCouplesFromArrayList private WeightedPositions[] getInefficientCouples_withAtLeastASecondPhaseInterval( ! TestingPositions[] bestTestingPositionsInSample , ! ReturnIntervals outOfSampleReturnIntervals , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample ) { ArrayList arrayListOfInefficientCouples = this.getArrayListOfInefficientCouples( ! bestTestingPositionsInSample , ! outOfSampleReturnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); WeightedPositions[] inefficientCouples = this.getInefficientCouplesFromArrayList( arrayListOfInefficientCouples ); return inefficientCouples; } - // private WeightedPositions - // getInfefficientCouples_withAtLeastASecondPhaseInterval( - // TestingPositions[] bestTestingPositionsInSample , - // ReturnIntervals outOfSampleReturnIntervals , - // IHistoricalQuoteProvider - // historicalQuoteProviderForChosingPositionsOutOfSample ) - // { - // WeightedPositions weightedPositions = - // this.getPositionsToBeOpened_withAtLeastASecondPhaseInterval_actually( - // bestTestingPositionsInSample , - // outOfSampleReturnIntervals , - // historicalQuoteProviderForChosingPositionsOutOfSample ); - //// WeightedPositions weightedPositionsToBeReturned = null; - //// if ( weightedPositions != null ) - //// // at least one of the BestTestingPositions shows an inefficiency - //// // above the threshold - //// weightedPositionsToBeReturned = - //// selectWeightedPositions( weightedPositions ); - //// return weightedPositionsToBeReturned; - // return weightedPositions; - // } private WeightedPositions[] getInefficientCouples( TestingPositions[] bestTestingPositionsInSample , ! ReturnIntervals outOfSampleReturnIntervals , HistoricalMarketValueProvider historicalMarketValueProviderForChosingPositionsOutOfSample ) { WeightedPositions[] inefficientCouples = null; ! if ( outOfSampleReturnIntervals.Count >= 2 ) ! // at least a second phase interval exists ! inefficientCouples = ! this.getInefficientCouples_withAtLeastASecondPhaseInterval( bestTestingPositionsInSample , ! outOfSampleReturnIntervals , historicalMarketValueProviderForChosingPositionsOutOfSample ); return inefficientCouples; --- 300,345 ---- inefficientCouples = this.getInefficientCouplesFromArrayList_actually( ! arrayListOfInefficientCouples ); return inefficientCouples; } #endregion getInefficientCouplesFromArrayList + private WeightedPositions[] getInefficientCouples_withAtLeastASecondPhaseInterval( ! TestingPositions[] bestTestingPositionsInSample , ! DateTime firstDateTimeToTestInefficiency , ! DateTime lastDateTimeToTestInefficiency , ! // ReturnIntervals outOfSampleReturnIntervals , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample ) { ArrayList arrayListOfInefficientCouples = this.getArrayListOfInefficientCouples( ! bestTestingPositionsInSample , ! firstDateTimeToTestInefficiency , ! lastDateTimeToTestInefficiency , ! // outOfSampleReturnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); WeightedPositions[] inefficientCouples = this.getInefficientCouplesFromArrayList( arrayListOfInefficientCouples ); return inefficientCouples; } private WeightedPositions[] getInefficientCouples( TestingPositions[] bestTestingPositionsInSample , ! DateTime firstDateTimeToTestInefficiency , ! DateTime lastDateTimeToTestInefficiency , ! // ReturnIntervals outOfSampleReturnIntervals , HistoricalMarketValueProvider historicalMarketValueProviderForChosingPositionsOutOfSample ) { WeightedPositions[] inefficientCouples = null; ! // if ( outOfSampleReturnIntervals.Count >= 2 ) ! // // at least a second phase interval exists ! inefficientCouples = ! this.getInefficientCouples_withAtLeastASecondPhaseInterval( bestTestingPositionsInSample , ! firstDateTimeToTestInefficiency , ! lastDateTimeToTestInefficiency , ! // outOfSampleReturnIntervals , historicalMarketValueProviderForChosingPositionsOutOfSample ); return inefficientCouples; *************** *** 341,344 **** --- 347,377 ---- } #endregion getInefficientCouples + + private WeightedPositions getPositionsToBeOpened_actually( + TestingPositions[] bestTestingPositionsInSample , + DateTime firstDateTimeToTestInefficiency , + DateTime lastDateTimeToTestInefficiency , + // ReturnIntervals outOfSampleReturnIntervals , + HistoricalMarketValueProvider + historicalMarketValueProviderForChosingPositionsOutOfSample , + ReturnsManager inSampleReturnsManager ) + { + WeightedPositions positionsToBeOpened = null; + WeightedPositions[] inefficientCouples = + this.getInefficientCouples( + bestTestingPositionsInSample , + firstDateTimeToTestInefficiency , + lastDateTimeToTestInefficiency , + // outOfSampleReturnIntervals , + historicalMarketValueProviderForChosingPositionsOutOfSample ); + if ( inefficientCouples != null ) + // at least an inefficient couple has been found + positionsToBeOpened = + this.getPositionsToBeOpened( inefficientCouples , + inSampleReturnsManager ); + return positionsToBeOpened; + } + #endregion getPositionsToBeOpened_actually + /// <summary> /// Selects the WeghtedPositions to actually be opened *************** *** 346,351 **** /// <param name="bestTestingPositionsInSample">most correlated couples, /// in sample</param> - /// <param name="outOfSampleReturnIntervals">return intervals for - /// the current backtest</param> /// <param name="minThreshold">min requested inefficiency</param> /// <param name="maxThreshold">max allowed inefficiency</param> --- 379,382 ---- *************** *** 354,372 **** public virtual WeightedPositions GetPositionsToBeOpened( TestingPositions[] bestTestingPositionsInSample , ! ReturnIntervals outOfSampleReturnIntervals , HistoricalMarketValueProvider historicalMarketValueProviderForChosingPositionsOutOfSample , ReturnsManager inSampleReturnsManager ) { ! WeightedPositions positionsToBeOpened = null; ! WeightedPositions[] inefficientCouples = ! this.getInefficientCouples( ! bestTestingPositionsInSample , ! outOfSampleReturnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); ! if ( inefficientCouples != null ) ! // at least an inefficient couple has been found ! positionsToBeOpened = ! this.getPositionsToBeOpened( inefficientCouples , inSampleReturnsManager ); return positionsToBeOpened; --- 385,403 ---- public virtual WeightedPositions GetPositionsToBeOpened( TestingPositions[] bestTestingPositionsInSample , ! DateTime firstDateTimeToTestInefficiency , ! DateTime lastDateTimeToTestInefficiency , ! // ReturnIntervals outOfSampleReturnIntervals , HistoricalMarketValueProvider historicalMarketValueProviderForChosingPositionsOutOfSample , ReturnsManager inSampleReturnsManager ) { ! this.checkParameters( ! firstDateTimeToTestInefficiency , lastDateTimeToTestInefficiency ); ! WeightedPositions positionsToBeOpened = ! this.getPositionsToBeOpened_actually( ! bestTestingPositionsInSample , ! firstDateTimeToTestInefficiency , ! lastDateTimeToTestInefficiency , ! historicalMarketValueProviderForChosingPositionsOutOfSample , inSampleReturnsManager ); return positionsToBeOpened; *************** *** 382,387 **** if ( inefficientCouple.Count != 2 ) throw new Exception( "The method getLongPositionTickers() expects " + ! "an array of WeightedPositions, each of wich contains exactly " + ! "two positions!" ); } private void addPositionIfLong( --- 413,418 ---- if ( inefficientCouple.Count != 2 ) throw new Exception( "The method getLongPositionTickers() expects " + ! "an array of WeightedPositions, each of wich contains exactly " + ! "two positions!" ); } private void addPositionIfLong( *************** *** 391,396 **** { if ( ( weightedPosition.IsLong ) && ! ( !alreadyAddedLongPositionTickers.Contains( ! weightedPosition.Ticker ) ) ) // the given weightedPosition is long and its ticker has not // yet been added to the set of tickers for long positions --- 422,427 ---- { if ( ( weightedPosition.IsLong ) && ! ( !alreadyAddedLongPositionTickers.Contains( ! weightedPosition.Ticker ) ) ) // the given weightedPosition is long and its ticker has not // yet been added to the set of tickers for long positions *************** *** 407,415 **** this.checkParameters_forCurrentCouple( inefficientCouple ); this.addPositionIfLong( inefficientCouple[ 0 ] , ! alreadyAddedLongPositionTickers , ! arrayListOfLongPositionTickers ); this.addPositionIfLong( inefficientCouple[ 1 ] , ! alreadyAddedLongPositionTickers , ! arrayListOfLongPositionTickers ); } private ArrayList getArrayListOfLongPositionTickers( --- 438,446 ---- this.checkParameters_forCurrentCouple( inefficientCouple ); this.addPositionIfLong( inefficientCouple[ 0 ] , ! alreadyAddedLongPositionTickers , ! arrayListOfLongPositionTickers ); this.addPositionIfLong( inefficientCouple[ 1 ] , ! alreadyAddedLongPositionTickers , ! arrayListOfLongPositionTickers ); } private ArrayList getArrayListOfLongPositionTickers( *************** *** 420,425 **** foreach( WeightedPositions weightedPositions in inefficientCouples ) this.addLongPositions( weightedPositions , ! alreadyAddedLongPositionTickers , ! arrayListOfLongPositionTickers ); return arrayListOfLongPositionTickers; } --- 451,456 ---- foreach( WeightedPositions weightedPositions in inefficientCouples ) this.addLongPositions( weightedPositions , ! alreadyAddedLongPositionTickers , ! arrayListOfLongPositionTickers ); return arrayListOfLongPositionTickers; } |
|
From: Glauco S. <gla...@us...> - 2008-11-17 19:49:06
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20768/b7_Scripts/WalkForwardTesting/PairsTrading Modified Files: PairsTradingMain.cs Log Message: Added code to use the new intraday strategy PairsTradingIntradayStrategy Index: PairsTradingMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/PairsTradingMain.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** PairsTradingMain.cs 12 Nov 2008 20:44:13 -0000 1.20 --- PairsTradingMain.cs 17 Nov 2008 19:49:02 -0000 1.21 *************** *** 153,157 **** int numberOfBestTestingPositionsToBeReturned = 50; // uncomment the following line for a faster script ! numberOfBestTestingPositionsToBeReturned = 5; IDecoderForTestingPositions decoderForWeightedPositions = --- 153,157 ---- int numberOfBestTestingPositionsToBeReturned = 50; // uncomment the following line for a faster script ! // numberOfBestTestingPositionsToBeReturned = 5; IDecoderForTestingPositions decoderForWeightedPositions = *************** *** 235,252 **** this.historicalMarketValueProviderForChosingPositionsOutOfSample , outOfSampleChooser ); ! // IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = ! // new PairsTradingStrategy( ! // 7 , inSampleDays , intervalsSelector , ! // eligiblesSelector , inSampleChooser , ! // this.historicalQuoteProviderForInSample , ! // this.historicalQuoteProviderForChosingPositionsOutOfSample , ! // 0.006 , 0.99 , 0.006 , 0.99 ); ! // endOfDayStrategyForBacktester = ! // new LongOnlyPairsTradingStrategy( ! // 7 , inSampleDays , intervalsSelector , ! // eligiblesSelector , inSampleChooser , ! // this.historicalQuoteProviderForInSample , ! // this.historicalQuoteProviderForChosingPositionsOutOfSample , ! // 0.006 , 0.02 , 0.006 , 0.02 ); return strategyForBacktester; } --- 235,250 ---- this.historicalMarketValueProviderForChosingPositionsOutOfSample , outOfSampleChooser ); ! ! strategyForBacktester = ! new PairsTradingIntradayStrategy( ! 7 , inSampleDays , ! intervalsSelectorForInSample , ! new Time( 13 , 0 , 0 ) , ! new Time( 14 , 0 , 0 ) , ! new Time( 15 , 0 , 0 ) , ! eligiblesSelector , inSampleChooser , ! this.historicalMarketValueProviderForInSample , ! this.historicalMarketValueProviderForChosingPositionsOutOfSample , ! outOfSampleChooser ); return strategyForBacktester; } *************** *** 260,264 **** new IndexBasedHistoricalTimer( this.benchmark.Ticker , ! firstDateTime , lastDateTime , dailyTimes ); return indexBasedTimer; } --- 258,262 ---- new IndexBasedHistoricalTimer( this.benchmark.Ticker , ! firstDateTime , lastDateTime , dailyTimes , 60 ); return indexBasedTimer; } *************** *** 276,280 **** // uncomment the following two lines for a faster script firstDateTime = new DateTime( 2006 , 2 , 1 ); ! lastDateTime = new DateTime( 2007 , 6 , 30 ); double maxRunningHours = 0.05; --- 274,278 ---- // uncomment the following two lines for a faster script firstDateTime = new DateTime( 2006 , 2 , 1 ); ! lastDateTime = new DateTime( 2006 , 2 , 28 ); double maxRunningHours = 0.05; |
|
From: Glauco S. <gla...@us...> - 2008-11-17 19:47:58
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20535/b7_Scripts Modified Files: Scripts_SD.csproj Log Message: WalkForwardTesting\PairsTrading\Strategies\PairsTradingIntradayStrategy.cs has been added Index: Scripts_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts_SD.csproj,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Scripts_SD.csproj 19 Aug 2008 17:13:13 -0000 1.32 --- Scripts_SD.csproj 17 Nov 2008 19:47:51 -0000 1.33 *************** *** 131,134 **** --- 131,135 ---- <Compile Include="WalkForwardTesting\PairsTrading\PairsTradingMain.cs" /> <Compile Include="WalkForwardTesting\PairsTrading\PairsTradingTestingPositions.cs" /> + <Compile Include="WalkForwardTesting\PairsTrading\Strategies\PairsTradingIntradayStrategy.cs" /> <Compile Include="WalkForwardTesting\PairsTrading\Strategies\PairsTradingStrategy.cs" /> <Compile Include="WalkForwardTesting\WalkForwardLag\RunSimpleLag.cs" /> |
|
From: Glauco S. <gla...@us...> - 2008-11-17 19:47:31
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20451/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies Added Files: PairsTradingIntradayStrategy.cs Log Message: Pairs trading strategy with intraday bars --- NEW FILE: PairsTradingIntradayStrategy.cs --- /* QuantProject - Quantitative Finance Library PairsTradingIntradayStrategy.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.ADT.Timing; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading { /// <summary> /// Pairs trading strategy with intraday bars /// </summary> public class PairsTradingIntradayStrategy : BasicStrategyForBacktester { private Time firstTimeToTestInefficiency; private Time lastTimeToTestInefficiency; private Time timeToClosePositions; private HistoricalMarketValueProvider historicalMarketValueProviderForChosingPositionsOutOfSample; private OutOfSampleChooser outOfSampleChooser; public PairsTradingIntradayStrategy( int numDaysBeetweenEachOtpimization , int numDaysForInSampleOptimization , IIntervalsSelector intervalsSelectorForInSample , // IIntervalsSelector intervalsSelectorForOutOfSample , Time firstTimeToTestInefficiency , Time lastTimeToTestInefficiency , Time timeToClosePositions , IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , HistoricalMarketValueProvider historicalMarketValueProviderForInSample , HistoricalMarketValueProvider historicalMarketValueProviderForChosingPositionsOutOfSample , OutOfSampleChooser outOfSampleChooser ) : base( numDaysBeetweenEachOtpimization , numDaysForInSampleOptimization , intervalsSelectorForInSample , // intervalsSelectorForOutOfSample , eligiblesSelector , inSampleChooser , historicalMarketValueProviderForInSample ) { this.firstTimeToTestInefficiency = firstTimeToTestInefficiency; this.lastTimeToTestInefficiency = lastTimeToTestInefficiency; this.timeToClosePositions = timeToClosePositions; this.historicalMarketValueProviderForChosingPositionsOutOfSample = historicalMarketValueProviderForChosingPositionsOutOfSample; this.outOfSampleChooser = outOfSampleChooser; } protected override string getTextIdentifier() { return "pairsTrdngIntrdy"; } protected override LogItem getLogItem( EligibleTickers eligibleTickers ) { PairsTradingLogItem logItem = new PairsTradingLogItem( this.now() , this.bestTestingPositionsInSample , this.numDaysForInSampleOptimization , eligibleTickers.Count ); return logItem; } protected override bool arePositionsToBeClosed() { bool areToBeClosed = ( this.Account.Portfolio.Count > 1 ); areToBeClosed = ( areToBeClosed && ( this.time() == this.timeToClosePositions ) ); return ( areToBeClosed ); } protected override bool arePositionsToBeOpened() { bool areToBeOpened = ( this.time() == this.lastTimeToTestInefficiency ); return ( areToBeOpened ); } #region getPositionsToBeOpened private DateTime getFirstDateTimeToTestInefficiency() { DateTime now = this.now(); DateTime firstDateTimeToTestInefficiency = new DateTime( now.Year , now.Month , now.Day , this.firstTimeToTestInefficiency.Hour , this.firstTimeToTestInefficiency.Minute , this.firstTimeToTestInefficiency.Second ); return firstDateTimeToTestInefficiency; } private DateTime getLastDateTimeToTestInefficiency() { DateTime now = this.now(); DateTime lastDateTimeToTestInefficiency = new DateTime( now.Year , now.Month , now.Day , this.lastTimeToTestInefficiency.Hour , this.lastTimeToTestInefficiency.Minute , this.lastTimeToTestInefficiency.Second ); return lastDateTimeToTestInefficiency; } protected override WeightedPositions getPositionsToBeOpened() { DateTime firstDateTimeToTestInefficiency = this.getFirstDateTimeToTestInefficiency(); DateTime lastDateTimeToTestInefficiency = this.getLastDateTimeToTestInefficiency(); WeightedPositions weightedPositions = this.outOfSampleChooser.GetPositionsToBeOpened( this.bestTestingPositionsInSample , firstDateTimeToTestInefficiency , lastDateTimeToTestInefficiency , this.historicalMarketValueProviderForChosingPositionsOutOfSample , this.inSampleReturnsManager ); return weightedPositions; } #endregion getPositionsToBeOpened } } |
|
From: Glauco S. <gla...@us...> - 2008-11-17 19:46:50
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20293/b4_Business Modified Files: Business_SD.csproj Log Message: a2_Strategies\BasicStrategyForBacktester.cs has been added Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Business_SD.csproj 14 Nov 2008 16:01:23 -0000 1.32 --- Business_SD.csproj 17 Nov 2008 19:46:39 -0000 1.33 *************** *** 66,69 **** --- 66,70 ---- <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\Tables\StatisticsSummary.cs" /> <Compile Include="a1_Financial\a2_Accounting\Transactions\TimedTransaction.cs" /> + <Compile Include="a2_Strategies\BasicStrategyForBacktester.cs" /> <Compile Include="a2_Strategies\Benchmark.cs" /> <Compile Include="a2_Strategies\Eligibles\ByPriceLessVolatileOTCAlwaysQuoted.cs" /> |
|
From: Glauco S. <gla...@us...> - 2008-11-17 19:46:19
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20138/b4_Business/a2_Strategies Added Files: BasicStrategyForBacktester.cs Log Message: Basic abstract implementation of IStrategyForBacktester, that should be inherited by specific strategies --- NEW FILE: BasicStrategyForBacktester.cs --- /* QuantProject - Quantitative Finance Library BasicStrategyForBacktester.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.ADT.Messaging; using QuantProject.ADT.Timing; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; namespace QuantProject.Business.Strategies { /// <summary> /// Basic abstract implementation of IStrategyForBacktester, /// that should be inherited by specific strategies /// </summary> [Serializable] public abstract class BasicStrategyForBacktester : IStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; public event NewMessageEventHandler NewMessage; protected int numDaysBeetweenEachOtpimization; protected int numDaysForInSampleOptimization; protected IIntervalsSelector intervalsSelectorForInSample; // protected IIntervalsSelector intervalsSelectorForOutOfSample; protected IEligiblesSelector eligiblesSelector; protected IInSampleChooser inSampleChooser; protected HistoricalMarketValueProvider historicalMarketValueProviderForInSample; protected DateTime lastOptimizationDateTime; private Account account; protected ReturnsManager inSampleReturnsManager; protected TestingPositions[] bestTestingPositionsInSample; #region StopBacktestIfMaxRunningHoursHasBeenReached protected DateTime now() { DateTime simulatedDateTime = this.account.Timer.GetCurrentDateTime(); return simulatedDateTime; } private bool areOptimalWeightedPositionsToBeUpdated() { DateTime dateTimeForNextOptimization = this.lastOptimizationDateTime.AddDays( this.numDaysBeetweenEachOtpimization ); DateTime currentSimulatedDateTime = this.now(); bool areToBeUpdated = ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ( currentSimulatedDateTime >= dateTimeForNextOptimization ) ); return areToBeUpdated; } public virtual bool StopBacktestIfMaxRunningHoursHasBeenReached { get { return this.areOptimalWeightedPositionsToBeUpdated(); } } #endregion StopBacktestIfMaxRunningHoursHasBeenReached public Account Account { get { return this.account; } set { this.account = value; } } #region Description protected abstract string getTextIdentifier(); public string Description { get { string descriptionForLogFileName = "Strtgy_" + this.getTextIdentifier() + "nmDysBtwnOptmztns_" + this.numDaysBeetweenEachOtpimization.ToString() + "_" + this.eligiblesSelector.Description + "_" + this.inSampleChooser.Description + "_oS_longOnly"; return descriptionForLogFileName; } } #endregion Description public BasicStrategyForBacktester( int numDaysBeetweenEachOtpimization , int numDaysForInSampleOptimization , IIntervalsSelector intervalsSelectorForInSample , // IIntervalsSelector intervalsSelectorForOutOfSample , IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , HistoricalMarketValueProvider historicalMarketValueProviderForInSample ) { this.numDaysBeetweenEachOtpimization = numDaysBeetweenEachOtpimization; this.numDaysForInSampleOptimization = numDaysForInSampleOptimization; this.intervalsSelectorForInSample = intervalsSelectorForInSample; // this.intervalsSelectorForOutOfSample = intervalsSelectorForOutOfSample; this.eligiblesSelector = eligiblesSelector; this.inSampleChooser = inSampleChooser; this.historicalMarketValueProviderForInSample = historicalMarketValueProviderForInSample; // this.returnIntervals = // new ReturnIntervals( this.intervalsSelectorForOutOfSample ); } #region NewDateTimeEventHandler #region updateOptimalTestingPositions #region updateOptimalTestingPositions_actually #region getInSampleReturnIntervals private DateTime getInSampleReturnIntervals_getFirstDateTime() { DateTime someDaysBefore = this.now().AddDays( -this.numDaysForInSampleOptimization ); DateTime firstDateTime = HistoricalEndOfDayTimer.GetMarketOpen( someDaysBefore ); return firstDateTime; } private ReturnIntervals getInSampleReturnIntervals() { DateTime firstDateTime = this.getInSampleReturnIntervals_getFirstDateTime(); DateTime lastDateTime = HistoricalEndOfDayTimer.GetMarketClose( this.now() ); ReturnIntervals inSampleReturnIntervals = new ReturnIntervals( this.intervalsSelectorForInSample ); inSampleReturnIntervals.AppendFirstInterval( firstDateTime ); if ( inSampleReturnIntervals.LastDateTime < lastDateTime ) inSampleReturnIntervals.AppendIntervalsButDontGoBeyondLastDate( lastDateTime ); return inSampleReturnIntervals; } #endregion getInSampleReturnIntervals private void checkQualityFor_bestTestingPositionsInSample() { for( int i = 0 ; i < this.bestTestingPositionsInSample.Length ; i++ ) if ( this.bestTestingPositionsInSample[ i ] == null ) throw new Exception( "The IInSampleChooser should have returned an array " + "of non null bestTestingPositionsInSample!" ); } private void notifyMessage( EligibleTickers eligibleTickers ) { string message = "Number of Eligible tickers: " + eligibleTickers.Count + " - " + DateTime.Now.ToString(); NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if ( this.NewMessage != null ) this.NewMessage( this , newMessageEventArgs ); } #region logOptimizationInfo protected abstract LogItem getLogItem( EligibleTickers eligibleTickers ); private void raiseNewLogItem( EligibleTickers eligibleTickers ) { LogItem logItem = this.getLogItem( eligibleTickers ); NewLogItemEventArgs newLogItemEventArgs = new NewLogItemEventArgs( logItem ); this.NewLogItem( this , newLogItemEventArgs ); } private void logOptimizationInfo( EligibleTickers eligibleTickers ) { this.raiseNewLogItem( eligibleTickers ); } #endregion logOptimizationInfo private void updateOptimalTestingPositions_actually() { ReturnIntervals inSampleReturnIntervals = this.getInSampleReturnIntervals(); EligibleTickers eligibleTickers = this.eligiblesSelector.GetEligibleTickers( inSampleReturnIntervals.BordersHistory ); this.inSampleReturnsManager = new ReturnsManager( inSampleReturnIntervals , this.historicalMarketValueProviderForInSample ); this.bestTestingPositionsInSample = (TestingPositions[])this.inSampleChooser.AnalyzeInSample( eligibleTickers , this.inSampleReturnsManager ); this.checkQualityFor_bestTestingPositionsInSample(); this.notifyMessage( eligibleTickers ); this.logOptimizationInfo( eligibleTickers ); } #endregion updateOptimalTestingPositions_actually private void updateOptimalTestingPositions() { this.updateOptimalTestingPositions_actually(); this.lastOptimizationDateTime = this.now(); } #endregion updateOptimalTestingPositions protected abstract bool arePositionsToBeClosed(); protected abstract bool arePositionsToBeOpened(); protected abstract WeightedPositions getPositionsToBeOpened(); public void NewDateTimeEventHandler( Object sender , DateTime dateTime ) { if ( this.areOptimalWeightedPositionsToBeUpdated() ) this.updateOptimalTestingPositions(); if ( this.arePositionsToBeClosed() ) AccountManager.ClosePositions( this.account ); if ( this.arePositionsToBeOpened() ) { WeightedPositions positionsToBeOpened = this.getPositionsToBeOpened(); if ( positionsToBeOpened != null ) // positions to be opened are available, actually AccountManager.OpenPositions( positionsToBeOpened , this.account ); } } #endregion NewDateTimeEventHandler /// <summary> /// returns the current simulated time for the current simulated day /// </summary> /// <returns></returns> protected Time time() { DateTime simulatedDateTime = this.account.Timer.GetCurrentDateTime(); Time simulatedTime = new Time( simulatedDateTime ); return simulatedTime; } } } |
|
From: Marco M. <mi...@us...> - 2008-11-14 16:01:27
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv6505/b3_Data Modified Files: Data_SD.csproj Log Message: Updated SharpDevelop project's files Index: Data_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Data_SD.csproj,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Data_SD.csproj 12 Nov 2008 20:34:58 -0000 1.5 --- Data_SD.csproj 14 Nov 2008 16:01:23 -0000 1.6 *************** *** 77,80 **** --- 77,81 ---- <Compile Include="Selectors\SelectorByOpenToCloseLinearCorrelation.cs" /> <Compile Include="Selectors\SelectorByOpenToCloseVolatility.cs" /> + <Compile Include="Selectors\SelectorByQuotationAtAGivenPercentageOfDateTimes.cs" /> <Compile Include="Selectors\SelectorByQuotationAtEachMarketDay.cs" /> <Compile Include="Selectors\SelectorByAverageRawOpenPrice.cs" /> |
|
From: Marco M. <mi...@us...> - 2008-11-14 16:01:26
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv6505/b4_Business Modified Files: Business_SD.csproj Log Message: Updated SharpDevelop project's files Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Business_SD.csproj 12 Nov 2008 20:34:09 -0000 1.31 --- Business_SD.csproj 14 Nov 2008 16:01:23 -0000 1.32 *************** *** 75,78 **** --- 75,79 ---- <Compile Include="a2_Strategies\Eligibles\EligibleTickers.cs" /> <Compile Include="a2_Strategies\Eligibles\IEligiblesSelector.cs" /> + <Compile Include="a2_Strategies\Eligibles\ByPriceMostLiquidQuotedAtEachDateTime.cs" /> <Compile Include="a2_Strategies\EndOfDayStrategies\BasicEndOfDayStrategyForBacktester.cs" /> <Compile Include="a2_Strategies\EndOfDayStrategies\EndOfDayStrategy.cs" /> |
|
From: Marco M. <mi...@us...> - 2008-11-14 15:57:53
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Timing In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv5589/b1_ADT/Timing Modified Files: Time.cs Log Message: Added a new constructor, from a time represented by a formatted string; moved constructor's code out from region hashCode (Glauco, check please ...); added some static and instance method Index: Time.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Timing/Time.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Time.cs 12 Nov 2008 20:31:53 -0000 1.1 --- Time.cs 14 Nov 2008 15:57:46 -0000 1.2 *************** *** 30,33 **** --- 30,89 ---- public struct Time : IEquatable<Time> , IComparable<Time> { + #region IsValidTimeFormat + public static bool IsValidTimeFormat ( string stringRepresentingTime ) + { + bool returnValue = false; + char[] chars = stringRepresentingTime.ToCharArray(); + if( + //first - hour + (chars[0]=='0' || chars[0]=='1' || chars[0]=='2') && + //second - hour + ( (chars[0]=='0' || chars[0]=='1') && + (chars[1]=='0' || chars[1]=='1' || chars[1]=='2' || + chars[1]=='3' || chars[1]=='4' || chars[1]=='5' || + chars[1]=='6' || chars[1]=='7' || chars[1]=='8' || chars[1]=='9') || + chars[0] == '2' && + (chars[1]=='0' || chars[1]=='1' || chars[1]=='2' || + chars[1]=='3' || chars[1]=='4') ) && + //third - separator + (chars[2]==':') && + //fourth - minute + (chars[3]=='0' || chars[3]=='1' || chars[3]=='2' || + chars[3]=='3' || chars[3]=='4' || chars[3]=='5') && + //fifth - minute + (chars[4]=='0' || chars[4]=='1' || chars[4]=='2' || + chars[4]=='3' || chars[4]=='4' || chars[4]=='5' || + chars[4]=='6' || chars[4]=='7' || chars[4]=='8' || chars[4]=='9') && + //sixth - separator + (chars[5]==':') && + //seventh - second + (chars[6]=='0' || chars[6]=='1' || chars[6]=='2' || + chars[6]=='3' || chars[6]=='4' || chars[6]=='5') && + //eighth - second + (chars[7]=='0' || chars[7]=='1' || chars[7]=='2' || + chars[7]=='3' || chars[7]=='4' || chars[7]=='5' || + chars[7]=='6' || chars[7]=='7' || chars[7]=='8' || chars[7]=='9') + ) + returnValue = true; + + return returnValue; + } + #endregion isValidTimeFormat + + + /// <summary> + /// Returns a new DateTime, having the date as the given dateTime + /// and the time as the given time + /// </summary> + /// <param name="dateTime">dateTime containing the date to merge with the given time in a new DateTime</param> + /// /// <param name="time">time containing the hour, minute and second to merge with the given dateTime in a new DateTime</param> + /// <returns></returns> + public static DateTime GetDateTimeFromMerge ( DateTime dateTime, Time time ) + { + return new DateTime( dateTime.Year , dateTime.Month , dateTime.Day, + time.Hour , time.Minute , time.Second ); + } + + private DateTime standardDateTime; *************** *** 47,56 **** } - - - #region Equals and GetHashCode implementation - // The code in this region is useful if you want to use this structure in collections. - // If you don't need it, you can just remove the region and the ": IEquatable<Time>" declaration. - public Time( int hour , int minute , int second ) { --- 103,106 ---- *************** *** 66,69 **** --- 116,150 ---- } + private DateTime time_getStandardTimeFromString ( string stringRepresentingTime ) + { + int hour = Convert.ToInt32(stringRepresentingTime.Substring(0,2)); + int minute = Convert.ToInt32(stringRepresentingTime.Substring(3,2)); + int second = Convert.ToInt32(stringRepresentingTime.Substring(6,2)); + return new DateTime(1900, 1, 1, hour, minute, second); + } + + private void time_checkParameter ( string stringRepresentingTime ) + { + if( stringRepresentingTime.Length != 8 || + !Time.IsValidTimeFormat( stringRepresentingTime ) ) + throw new Exception("string is not in the requested time-format hh:mm:ss"); + } + + /// <summary> + /// Represent a time (for any possible date) + /// </summary> + /// <param name="stringRepresentingTime">String representing time in format: hh:mm:ss</param> + public Time( string stringRepresentingTime ) + { + this.standardDateTime = new DateTime(1900,1,1,0,0,0); + //just for compiling next two lines + this.time_checkParameter( stringRepresentingTime ); + this.standardDateTime = + this.time_getStandardTimeFromString( stringRepresentingTime ); + } + + #region Equals and GetHashCode implementation + // The code in this region is useful if you want to use this structure in collections. + // If you don't need it, you can just remove the region and the ": IEquatable<Time>" declaration. public override bool Equals(object obj) { *************** *** 134,137 **** --- 215,233 ---- return compareTo; } + + /// <summary> + /// True iff the time of the given dateTime is equal to + /// the current instance + /// </summary> + /// <param name="dateTime">dateTime containing time to compare to the current instance</param> + /// <returns></returns> + public bool HasTheSameTime( DateTime dateTime ) + { + bool returnValue = + ( this.Hour == dateTime.Hour ) && + ( this.Minute == dateTime.Minute ) && + ( this.Second == dateTime.Second ); + return returnValue; + } } } |
|
From: Marco M. <mi...@us...> - 2008-11-14 15:51:55
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4534/b3_Data/DataTables Modified Files: TickerDataTable.cs Log Message: Added parameter intervalFrameInSeconds Index: TickerDataTable.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/TickerDataTable.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TickerDataTable.cs 9 Nov 2008 19:22:14 -0000 1.11 --- TickerDataTable.cs 14 Nov 2008 15:51:51 -0000 1.12 *************** *** 249,257 **** private static void getTickersQuotedAtAGivenPercentageOfDateTimes_handleRow( DataRow row , History marketDateTimes , double percentageOfDateTimes , ! DateTime firstQuoteDate , DateTime lastQuoteDate , DataTable tableToWhichRowIsToBeAdded ) { History dateTimesForTicker = Bars.GetMarketDateTimes( (string)row[0], ! firstQuoteDate , lastQuoteDate ); if( dateTimesForTicker.ContainsAtAGivenPercentageDateTimesIn( marketDateTimes , percentageOfDateTimes ) ) //the current ticker has been effectively traded at the given percentage of times --- 249,257 ---- private static void getTickersQuotedAtAGivenPercentageOfDateTimes_handleRow( DataRow row , History marketDateTimes , double percentageOfDateTimes , ! DateTime firstQuoteDate , DateTime lastQuoteDate , int intervalFrameInSeconds, DataTable tableToWhichRowIsToBeAdded ) { History dateTimesForTicker = Bars.GetMarketDateTimes( (string)row[0], ! firstQuoteDate , lastQuoteDate, intervalFrameInSeconds ); if( dateTimesForTicker.ContainsAtAGivenPercentageDateTimesIn( marketDateTimes , percentageOfDateTimes ) ) //the current ticker has been effectively traded at the given percentage of times *************** *** 271,281 **** DataTable setOfTickers, DateTime firstBarDateTime, DateTime lastBarDateTime, long maxNumOfReturnedTickers) { History marketDateTimesForIndex = Bars.GetMarketDateTimes(marketIndex, ! firstBarDateTime , lastBarDateTime); return GetTickersQuotedAtAGivenPercentageOfDateTimes( marketDateTimesForIndex , percentageOfDateTimes , setOfTickers , ! firstBarDateTime , lastBarDateTime , maxNumOfReturnedTickers ); } --- 271,282 ---- DataTable setOfTickers, DateTime firstBarDateTime, DateTime lastBarDateTime, + int intervalFrameInSeconds, long maxNumOfReturnedTickers) { History marketDateTimesForIndex = Bars.GetMarketDateTimes(marketIndex, ! firstBarDateTime , lastBarDateTime, intervalFrameInSeconds); return GetTickersQuotedAtAGivenPercentageOfDateTimes( marketDateTimesForIndex , percentageOfDateTimes , setOfTickers , ! firstBarDateTime , lastBarDateTime , intervalFrameInSeconds, maxNumOfReturnedTickers ); } *************** *** 283,286 **** --- 284,288 ---- string groupID, DateTime firstBarDateTime, DateTime lastBarDateTime, + int intervalFrameInSeconds, long maxNumOfReturnedTickers) { *************** *** 289,293 **** return GetTickersQuotedAtAGivenPercentageOfDateTimes( marketIndex , percentageOfDateTimes , groupOfTicker , ! firstBarDateTime , lastBarDateTime , maxNumOfReturnedTickers ); } --- 291,295 ---- return GetTickersQuotedAtAGivenPercentageOfDateTimes( marketIndex , percentageOfDateTimes , groupOfTicker , ! firstBarDateTime , lastBarDateTime , intervalFrameInSeconds, maxNumOfReturnedTickers ); } *************** *** 307,310 **** --- 309,313 ---- DataTable setOfTickers, DateTime firstBarDateTime, DateTime lastBarDateTime, + int intervalFrameInSeconds, long maxNumOfReturnedTickers) { *************** *** 317,321 **** getTickersQuotedAtAGivenPercentageOfDateTimes_handleRow( row , marketDateTimes , percentageOfDateTimes , ! firstBarDateTime , lastBarDateTime , returnValue ); ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers); return returnValue; --- 320,324 ---- getTickersQuotedAtAGivenPercentageOfDateTimes_handleRow( row , marketDateTimes , percentageOfDateTimes , ! firstBarDateTime , lastBarDateTime , intervalFrameInSeconds , returnValue ); ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers); return returnValue; |
|
From: Marco M. <mi...@us...> - 2008-11-14 15:51:27
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4416/b3_Data/Selectors Modified Files: SelectorByQuotationAtAGivenPercentageOfDateTimes.cs Log Message: Added parameter intervalFrameInSeconds Index: SelectorByQuotationAtAGivenPercentageOfDateTimes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Selectors/SelectorByQuotationAtAGivenPercentageOfDateTimes.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SelectorByQuotationAtAGivenPercentageOfDateTimes.cs 9 Nov 2008 19:20:32 -0000 1.1 --- SelectorByQuotationAtAGivenPercentageOfDateTimes.cs 14 Nov 2008 15:51:18 -0000 1.2 *************** *** 41,44 **** --- 41,45 ---- private History marketDateTimes; private double percentageOfDateTimes; + private int intervalFrameInSeconds; public SelectorByQuotationAtAGivenPercentageOfDateTimes(DataTable setOfTickersToBeSelected, *************** *** 46,49 **** --- 47,51 ---- DateTime firstBarDateTime, DateTime lastBarDateTime, + int intervalFrameInSeconds, long maxNumOfReturnedTickers, string marketIndex, double percentageOfDateTimes): *************** *** 56,59 **** --- 58,62 ---- this.marketIndex = marketIndex; this.percentageOfDateTimes = percentageOfDateTimes; + this.intervalFrameInSeconds = intervalFrameInSeconds; } public SelectorByQuotationAtAGivenPercentageOfDateTimes(string groupID, *************** *** 61,64 **** --- 64,68 ---- DateTime firstBarDateTime, DateTime lastBarDateTime, + int intervalFrameInSeconds, long maxNumOfReturnedTickers, string marketIndex, double percentageOfDateTimes): *************** *** 71,79 **** this.marketIndex = marketIndex; this.percentageOfDateTimes = percentageOfDateTimes; } public SelectorByQuotationAtAGivenPercentageOfDateTimes( DataTable setOfTickersToBeSelected , bool orderInASCmode , ! History marketDateTimes , long maxNumOfReturnedTickers, double percentageOfDateTimes): base(setOfTickersToBeSelected , --- 75,84 ---- this.marketIndex = marketIndex; this.percentageOfDateTimes = percentageOfDateTimes; + this.intervalFrameInSeconds = intervalFrameInSeconds; } public SelectorByQuotationAtAGivenPercentageOfDateTimes( DataTable setOfTickersToBeSelected , bool orderInASCmode , ! History marketDateTimes , int intervalFrameInSeconds, long maxNumOfReturnedTickers, double percentageOfDateTimes): base(setOfTickersToBeSelected , *************** *** 86,89 **** --- 91,95 ---- this.marketDateTimes = marketDateTimes; this.percentageOfDateTimes = percentageOfDateTimes; + this.intervalFrameInSeconds = intervalFrameInSeconds; } *************** *** 94,98 **** QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedAtAGivenPercentageOfDateTimes( this.marketDateTimes , this.percentageOfDateTimes , this.setOfTickersToBeSelected , this.firstQuoteDate , ! this.lastQuoteDate , this.maxNumOfReturnedTickers ); return dataTable; } --- 100,104 ---- QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedAtAGivenPercentageOfDateTimes( this.marketDateTimes , this.percentageOfDateTimes , this.setOfTickersToBeSelected , this.firstQuoteDate , ! this.lastQuoteDate , this.intervalFrameInSeconds , this.maxNumOfReturnedTickers ); return dataTable; } *************** *** 105,114 **** return QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedAtAGivenPercentageOfDateTimes( this.marketIndex, this.percentageOfDateTimes , this.groupID, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers); else return QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedAtAGivenPercentageOfDateTimes( this.marketIndex, this.percentageOfDateTimes , this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers); } public DataTable GetTableOfSelectedTickers() --- 111,120 ---- return QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedAtAGivenPercentageOfDateTimes( this.marketIndex, this.percentageOfDateTimes , this.groupID, this.firstQuoteDate, this.lastQuoteDate, ! this.intervalFrameInSeconds, this.maxNumOfReturnedTickers); else return QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedAtAGivenPercentageOfDateTimes( this.marketIndex, this.percentageOfDateTimes , this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, ! this.intervalFrameInSeconds, this.maxNumOfReturnedTickers); } public DataTable GetTableOfSelectedTickers() |
|
From: Marco M. <mi...@us...> - 2008-11-14 15:51:26
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4416/b2_DataAccess/Tables Modified Files: Bars.cs Log Message: Added parameter intervalFrameInSeconds Index: Bars.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Bars.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Bars.cs 9 Nov 2008 19:11:10 -0000 1.1 --- Bars.cs 14 Nov 2008 15:51:18 -0000 1.2 *************** *** 47,75 **** public static string Close = "baClose"; public static string Volume = "baVolume"; ! ! private DataTable bars; ! ! /// <summary> ! /// Gets the ticker whose bars are contained into the Bars object ! /// </summary> ! /// <returns></returns> ! public string Ticker ! { ! get{ return ((string)this.bars.Rows[ 0 ][ Bars.TickerFieldName ]); } ! } ! public Bars( string ticker) { ! this.bars = Bars.GetTickerBars( ticker ); } ! /// <summary> ! /// Creates bars for the given instrument, since the startDateTime to the endDateTime ! /// </summary> ! /// <param name="ticker"></param> ! /// <param name="startDateTime"></param> ! /// <param name="endDateTime"></param> public Bars( string ticker , DateTime startDateTime , DateTime endDateTime ) { ! /// TO DO } /// <summary> --- 47,59 ---- public static string Close = "baClose"; public static string Volume = "baVolume"; ! public Bars( string ticker) { ! } ! public Bars( string ticker , DateTime startDateTime , DateTime endDateTime ) { ! } /// <summary> *************** *** 77,85 **** /// </summary> /// <param name="ticker">ticker for which the dateTime of the first bar has to be returned</param> /// <returns></returns> ! public static DateTime GetFirstBarDateTime( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select min(" + Bars.DateTimeForOpen + ") as minDate from bars where " + Bars.TickerFieldName + "='" + ticker + "' " + "group by " + Bars.TickerFieldName + ")" ); return (DateTime)(dataTable.Rows[ 0 ][ "minDate" ]); --- 61,72 ---- /// </summary> /// <param name="ticker">ticker for which the dateTime of the first bar has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static DateTime GetFirstBarDateTime( string ticker, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select min(" + Bars.DateTimeForOpen + ") as minDate from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "group by " + Bars.TickerFieldName + ")" ); return (DateTime)(dataTable.Rows[ 0 ][ "minDate" ]); *************** *** 89,97 **** /// </summary> /// <param name="ticker">ticker for which the dateTime of the last bar has to be returned</param> /// <returns></returns> ! public static DateTime GetLastBarDateTime( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars where " + Bars.TickerFieldName + "='" + ticker + "' " + "order by " + Bars.DateTimeForOpen + " DESC"); return (DateTime)(dataTable.Rows[0][ Bars.DateTimeForOpen ]); --- 76,86 ---- /// </summary> /// <param name="ticker">ticker for which the dateTime of the last bar has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static DateTime GetLastBarDateTime( string ticker, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "order by " + Bars.DateTimeForOpen + " DESC"); return (DateTime)(dataTable.Rows[0][ Bars.DateTimeForOpen ]); *************** *** 101,109 **** /// </summary> /// <param name="ticker">ticker for which the number of bars has to be returned</param> /// <returns></returns> ! public static int GetNumberOfBars( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars where " + Bars.TickerFieldName + "='" + ticker + "'" ); return dataTable.Rows.Count; } --- 90,101 ---- /// </summary> /// <param name="ticker">ticker for which the number of bars has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static int GetNumberOfBars( string ticker, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " ); return dataTable.Rows.Count; } *************** *** 114,125 **** /// </summary> /// <param name="ticker">ticker for which the number of bars has to be returned</param> /// <returns></returns> public static int GetNumberOfBarsWithEffectiveTrades( string ticker, DateTime firstDateTime, ! DateTime lastDateTime) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars WHERE " + Bars.TickerFieldName + "='" + ticker + "'" + ! " AND " + Bars.Volume + ">0" + " AND " + Bars.DateTimeForOpen + " BETWEEN " + SQLBuilder.GetDateConstant(firstDateTime) + ! " AND " + SQLBuilder.GetDateConstant(lastDateTime)); return dataTable.Rows.Count; } --- 106,120 ---- /// </summary> /// <param name="ticker">ticker for which the number of bars has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> public static int GetNumberOfBarsWithEffectiveTrades( string ticker, DateTime firstDateTime, ! DateTime lastDateTime, int intervalFrameInSeconds) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from bars " + ! "WHERE " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + ! "and " + Bars.Volume + ">0" + " and " + Bars.DateTimeForOpen + " BETWEEN " + SQLBuilder.GetDateConstant(firstDateTime) + " " + ! "and " + SQLBuilder.GetDateConstant(lastDateTime) ); return dataTable.Rows.Count; } *************** *** 130,138 **** /// </summary> /// <param name="ticker">ticker for which the close has to be returned</param> /// <returns></returns> ! public static float GetClose( string ticker, DateTime dateTime ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Close +" from bars where " + Bars.TickerFieldName + "='" + ticker + "' " + "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateConstant(dateTime) ); return (float)dataTable.Rows[0][0]; --- 125,136 ---- /// </summary> /// <param name="ticker">ticker for which the close has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static float GetClose( string ticker, DateTime dateTime, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Close + " from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateConstant(dateTime) ); return (float)dataTable.Rows[0][0]; *************** *** 143,151 **** /// </summary> /// <param name="ticker">ticker for which the raw open has to be returned</param> /// <returns></returns> ! public static float GetOpen( string ticker, DateTime dateTime ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Open +" from bars where " + Bars.TickerFieldName + "='" + ticker + "' " + "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateConstant(dateTime) ); return (float)dataTable.Rows[0][0]; --- 141,152 ---- /// </summary> /// <param name="ticker">ticker for which the raw open has to be returned</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static float GetOpen( string ticker, DateTime dateTime, int intervalFrameInSeconds ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Open + " from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateConstant(dateTime) ); return (float)dataTable.Rows[0][0]; *************** *** 211,703 **** // } // } ! ! ! /// <summary> ! /// returns tickers ordered by a liquidity index ! /// </summary> ! public static DataTable GetTickersByLiquidity( bool orderInASCMode, string groupID, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! long maxNumOfReturnedTickers) ! { ! string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! "Avg([quVolume]*[quClose]) AS AverageTradedValue " + ! "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! "AND quotes.quDate BETWEEN " + ! SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! SQLBuilder.GetDateConstant(lastQuoteDate) + ! "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! "ORDER BY Avg([quVolume]*[quClose])"; ! string sortDirection = " DESC"; ! if(orderInASCMode) ! sortDirection = " ASC"; ! sql = sql + sortDirection; ! return SqlExecutor.GetDataTable( sql ); ! } ! ! // /// <summary> ! // /// returns tickers ordered by liquidity, with a specified min volume ! // /// </summary> ! // /// <param name="orderInASCMode">true iff return must be ordered</param> ! // /// <param name="groupID"></param> ! // /// <param name="firstQuoteDate"></param> ! // /// <param name="lastQuoteDate"></param> ! // /// <param name="maxNumOfReturnedTickers"></param> ! // /// <param name="minVolume"></param> ! // /// <returns></returns> ! // public static DataTable GetTickersByLiquidity( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long minVolume, ! // long maxNumOfReturnedTickers ! // ) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "Avg([quVolume]*[quClose]) AS AverageTradedValue " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "HAVING Avg([quVolume])>=" + minVolume.ToString() + " " + ! // "ORDER BY Avg([quVolume])"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // ! // ! // /// <summary> ! // /// Returns tickers ordered by a close to close volatility index (stdDev of adjustedCloseToClose ratio) ! // /// </summary> ! // public static DataTable GetTickersByCloseToCloseVolatility( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "StDev(quotes.quAdjustedCloseToCloseRatio) AS AdjCloseToCloseStandDev " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "ORDER BY StDev(quotes.quAdjustedCloseToCloseRatio)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// Returns tickers ordered by the open to close volatility index (stdDev of OTC ratio) ! // /// </summary> ! // public static DataTable GetTickersByOpenToCloseVolatility( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "StDev(quotes.quClose/quotes.quOpen - 1) AS OpenToCloseStandDev " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "ORDER BY StDev(quotes.quClose/quotes.quOpen - 1)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// Returns tickers ordered by average close to close performance ! // /// </summary> ! // public static DataTable GetTickersByAverageCloseToClosePerformance( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quAdjustedCloseToCloseRatio) AS AverageCloseToClosePerformance " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "ORDER BY Avg(quotes.quAdjustedCloseToCloseRatio)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// Returns tickers ordered by average open to close performance (in the same bar) ! // /// </summary> ! // public static DataTable GetTickersByAverageOpenToClosePerformance( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // double maxAbsoluteAverageOTCPerformance, ! // long maxNumOfReturnedTickers) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quClose/quotes.quOpen - 1) AS AverageOpenToClosePerformance " + ! // "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + ! // "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + ! // "ON quotes.quTicker = tickers_tickerGroups.ttTiId " + ! // "WHERE tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "AND quotes.quDate BETWEEN " + ! // SQLBuilder.GetDateConstant(firstQuoteDate) + " AND " + ! // SQLBuilder.GetDateConstant(lastQuoteDate) + ! // "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! // "HAVING Avg(quotes.quClose/quotes.quOpen - 1) <= " + maxAbsoluteAverageOTCPerformance + ! // " AND Avg(quotes.quClose/quotes.quOpen - 1) >= -" + maxAbsoluteAverageOTCPerformance + " " + ! // "ORDER BY Avg(quotes.quClose/quotes.quOpen)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// returns tickers ordered by the average raw open price that is over ! // /// a given minimum, at a given time interval ! // /// </summary> ! // public static DataTable GetTickersByRawOpenPrice( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers, double minPrice ) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " quotes.quTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quOpen) AS AverageRawOpenPrice " + ! // "FROM (quotes INNER JOIN tickers ON quotes.quTicker=tickers.tiTicker) " + ! // "INNER JOIN tickers_tickerGroups ON tickers.tiTicker=tickers_tickerGroups.ttTiId " + ! // "WHERE quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "AND " + "tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "GROUP BY quotes.quTicker, tickers.tiCompanyName " + ! // "HAVING Avg(quotes.quOpen) >= " + minPrice + " " + ! // "ORDER BY Avg(quotes.quOpen)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! // ! // /// <summary> ! // /// returns tickers ordered by average raw open price level, ! // /// with a given standard deviation, in a given time interval ! // /// </summary> ! // public static DataTable GetTickersByRawOpenPrice( bool orderInASCMode, string groupID, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate, ! // long maxNumOfReturnedTickers, double minPrice, ! // double maxPrice, double minStdDeviation, ! // double maxStdDeviation) ! // { ! // string sql = "SELECT TOP " + maxNumOfReturnedTickers + " quotes.quTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quOpen) AS AverageRawOpenPrice, StDev(quotes.quOpen) AS StdDevRawOpenPrice " + ! // "FROM (quotes INNER JOIN tickers ON quotes.quTicker=tickers.tiTicker) " + ! // "INNER JOIN tickers_tickerGroups ON tickers.tiTicker=tickers_tickerGroups.ttTiId " + ! // "WHERE quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "AND " + "tickers_tickerGroups.ttTgId='" + groupID + "' " + ! // "GROUP BY quotes.quTicker, tickers.tiCompanyName " + ! // "HAVING Avg(quotes.quOpen) BETWEEN " + minPrice + " AND " + maxPrice + " " + ! // "AND StDev(quotes.quOpen) BETWEEN " + minStdDeviation + " AND " + maxStdDeviation + " " + ! // "ORDER BY Avg(quotes.quOpen)"; ! // string sortDirection = " DESC"; ! // if(orderInASCMode) ! // sortDirection = " ASC"; ! // sql = sql + sortDirection; ! // return SqlExecutor.GetDataTable( sql ); ! // } ! ! // /// <summary> ! // /// returns the average traded value for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAverageTradedValue( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "Avg([quVolume]*[quClose]) AS AverageTradedValue " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count==0) ! // return 0; ! // else ! // return (double)dt.Rows[0]["AverageTradedValue"]; ! // } ! // ! // /// <summary> ! // /// returns the average traded volume for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAverageTradedVolume( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "Avg([quVolume]) AS AverageTradedVolume " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count==0) ! // return 0; ! // else ! // return (double)dt.Rows[0]["AverageTradedVolume"]; ! // } ! // ! // /// <summary> ! // /// returns the average close to close performance value for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAverageCloseToClosePerformance( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "Avg([quAdjustedCloseToCloseRatio]) AS AverageCloseToClosePerformance " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count==0) ! // return 0; ! // else ! // return (double)dt.Rows[0]["AverageCloseToClosePerformance"]; ! // } ! // ! // /// <summary> ! // /// returns the average open to close performance ! // /// for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAverageOpenToClosePerformance(string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "Avg([quClose]/[quOpen] - 1) AS AverageOpenToClosePerformance " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // return (double)dt.Rows[0]["AverageOpenToClosePerformance"]; ! // } ! // ! // ! // /// <summary> ! // /// returns the standard deviation of the adjusted close to close ratio ! // /// for the given ticker in the specified interval ! // /// </summary> ! // public static double GetAdjustedCloseToCloseStandardDeviation( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // double adjCloseToCloseStdDev = 0.0; ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "StDev(quotes.quAdjustedCloseToCloseRatio) AS AdjCloseToCloseStandDev " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // ! // if( dt.Rows.Count > 0 && ! // DBNull.Value != dt.Rows[0]["AdjCloseToCloseStandDev"] ) ! // adjCloseToCloseStdDev = (double)dt.Rows[0]["AdjCloseToCloseStandDev"]; ! // ! // return adjCloseToCloseStdDev; ! // } ! // ! // /// <summary> ! // /// returns the standard deviation of the open to close ratio ! // /// for the given ticker in the specified interval ! // /// </summary> ! // public static double GetOpenToCloseStandardDeviation( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "StDev(quotes.quClose/quotes.quOpen - 1) AS OpenToCloseStandDev " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // return (double)dt.Rows[0]["OpenToCloseStandDev"]; ! // } ! // ! // /// <summary> ! // /// returns the standard deviation of the adjusted close to open ratio ! // /// for the given ticker in the specified interval ! // /// </summary> ! // public static double GetCloseToOpenStandardDeviation( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // double returnValue = Double.MaxValue; ! // ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, " + ! // "StDev(quotes.quClose/quotes.quOpen) AS CloseToOpenStandDev " + ! // "FROM quotes WHERE quTicker ='" + ! // ticker + "' " + ! // "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + ! // " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + ! // " GROUP BY quotes.quTicker"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count > 0) ! // { ! // if( dt.Rows[0]["CloseToOpenStandDev"] is double ) ! // //cast is possible ! // returnValue = (double)dt.Rows[0]["CloseToOpenStandDev"]; ! // } ! // return returnValue; ! // } ! // ! // /// <summary> ! // /// returns the average raw open price for the given ticker, ! // /// at the specified time interval ! // /// </summary> ! // public static double GetAverageRawOpenPrice( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // double returnValue = 0; ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, tickers.tiCompanyName, " + ! // "Avg(quotes.quOpen) AS AverageRawOpenPrice " + ! // "FROM (quotes INNER JOIN tickers ON quotes.quTicker=tickers.tiTicker) " + ! // "INNER JOIN tickers_tickerGroups ON tickers.tiTicker=tickers_tickerGroups.ttTiId " + ! // "WHERE quotes.quTicker ='" + ticker + ! // "' AND quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "GROUP BY quotes.quTicker, tickers.tiCompanyName"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count > 0) ! // { ! // if( dt.Rows[0]["AverageRawOpenPrice"] is double ) ! // //cast is possible ! // returnValue = (double)dt.Rows[0]["AverageRawOpenPrice"]; ! // } ! // return returnValue; ! // ! // } ! // ! // /// <summary> ! // /// returns raw open price's standard deviation for the given ticker, ! // /// at the specified time interval ! // /// </summary> ! // public static double GetRawOpenPriceStdDeviation( string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // ! // { ! // double returnValue = Double.MaxValue; ! // DataTable dt; ! // string sql = "SELECT quotes.quTicker, tickers.tiCompanyName, " + ! // "StDev(quotes.quOpen) AS RawOpenPriceStdDev " + ! // "FROM (quotes INNER JOIN tickers ON quotes.quTicker=tickers.tiTicker) " + ! // "INNER JOIN tickers_tickerGroups ON tickers.tiTicker=tickers_tickerGroups.ttTiId " + ! // "WHERE quotes.quTicker ='" + ticker + ! // "' AND quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "GROUP BY quotes.quTicker, tickers.tiCompanyName"; ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count > 0) ! // { ! // if( dt.Rows[0]["RawOpenPriceStdDev"] is double ) ! // //cast is possible ! // returnValue = (double)dt.Rows[0]["RawOpenPriceStdDev"]; ! // } ! // return returnValue; ! // } ! // ! // /// <summary> ! // /// Returns number of days for which raw close was greater than raw open ! // /// for the given interval of days (for the given ticker). ! // /// </summary> ! // public static int GetNumberOfOpenToCloseWinningDays(string ticker, ! // DateTime firstQuoteDate, ! // DateTime lastQuoteDate) ! // { ! // DataTable dt; ! // int returnValue = 0; ! // string sql = "SELECT Count(*) AS CloseToOpenWinningDays " + ! // "FROM quotes WHERE " + ! // "quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " + ! // "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " + ! // "AND " + "quotes.quTicker='" + ticker + "' " + ! // "AND quotes.quClose > quotes.quOpen"; ! // ! // dt = SqlExecutor.GetDataTable( sql ); ! // if(dt.Rows.Count > 0) ! // { ! // if(dt.Rows[0][0] is int) ! // returnValue = (int)dt.Rows[0][0]; ! // } ! // return returnValue; ! // } ! /// <summary> /// returns the bars DataTable for the given ticker /// </summary> ! /// <param name="instrumentKey">ticker whose bars are to be returned</param> /// <returns></returns> ! public static DataTable GetTickerBars( string instrumentKey ) { ! string sql = "select * from bars where " + Bars.TickerFieldName + "='" + instrumentKey + "' " + "order by " + Bars.DateTimeForOpen; return SqlExecutor.GetDataTable( sql ); --- 212,227 ---- // } // } ! /// <summary> /// returns the bars DataTable for the given ticker /// </summary> ! /// <param name="ticker">ticker whose bars are to be returned</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static DataTable GetTickerBars( string ticker, int intervalFrameInSeconds ) { ! string sql = "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "order by " + Bars.DateTimeForOpen; return SqlExecutor.GetDataTable( sql ); *************** *** 707,720 **** /// returns the bars DataTable for the given ticker /// </summary> ! /// <param name="instrumentKey">ticker whose quotes are to be returned</param> /// <param name="firstBarDateTime">The first bar date time</param> /// <param name="lastBarDateTime">The last bar date time</param> /// <returns></returns> ! public static DataTable GetTickerBars( string instrumentKey, DateTime firstBarDateTime, ! DateTime lastBarDateTime) { ! string sql = "select * from bars where " + Bars.TickerFieldName + "='" + instrumentKey + "' " + ! "AND " + Bars.DateTimeForOpen + " BETWEEN " + SQLBuilder.GetDateConstant(firstBarDateTime) + ! " AND " + SQLBuilder.GetDateConstant(lastBarDateTime) + " " + "order by " + Bars.DateTimeForOpen; return SqlExecutor.GetDataTable( sql ); --- 231,247 ---- /// returns the bars DataTable for the given ticker /// </summary> ! /// <param name="ticker">ticker whose quotes are to be returned</param> /// <param name="firstBarDateTime">The first bar date time</param> /// <param name="lastBarDateTime">The last bar date time</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static DataTable GetTickerBars( string ticker, DateTime firstBarDateTime, ! DateTime lastBarDateTime, int intervalFrameInSeconds) { ! string sql = "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + ! "and " + Bars.DateTimeForOpen + " between " + SQLBuilder.GetDateConstant(firstBarDateTime) + " " + ! "and " + SQLBuilder.GetDateConstant(lastBarDateTime) + " " + "order by " + Bars.DateTimeForOpen; return SqlExecutor.GetDataTable( sql ); *************** *** 726,732 **** /// <param name="startDateTime"></param> /// <param name="endDateTime"></param> /// <returns></returns> public static void SetDataTable( string tickerOrGroupID , DateTime startDateTime , DateTime endDateTime , ! DataTable dataTable) { string sql; --- 253,260 ---- /// <param name="startDateTime"></param> /// <param name="endDateTime"></param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> public static void SetDataTable( string tickerOrGroupID , DateTime startDateTime , DateTime endDateTime , ! DataTable dataTable, int intervalFrameInSeconds) { string sql; *************** *** 734,738 **** sql = "select * from bars INNER JOIN tickers_tickerGroups ON " + "bars." + Bars.TickerFieldName + "=tickers_tickerGroups." + Tickers_tickerGroups.Ticker + " " + ! "where " + Tickers_tickerGroups.GroupID + "='" + tickerOrGroupID + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + --- 262,267 ---- sql = "select * from bars INNER JOIN tickers_tickerGroups ON " + "bars." + Bars.TickerFieldName + "=tickers_tickerGroups." + Tickers_tickerGroups.Ticker + " " + ! "where " + Tickers_tickerGroups.GroupID + "='" + tickerOrGroupID + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + *************** *** 740,744 **** else sql = "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + tickerOrGroupID + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + --- 269,274 ---- else sql = "select * from bars " + ! "where " + Bars.TickerFieldName + "='" + tickerOrGroupID + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + "and " + Bars.DateTimeForOpen + ">=" + SQLBuilder.GetDateTimeConstant( startDateTime ) + " " + "and " + Bars.DateTimeForOpen + "<=" + SQLBuilder.GetDateTimeConstant( endDateTime ) + " " + *************** *** 774,782 **** /// <param name="dateTime">Date for the quotes to be fetched</param> /// <param name="dataTable">Output parameter</param> ! public static void SetDataTable( ICollection tickerCollection , DateTime dateTime , DataTable dataTable) { string sql; sql = "select * from bars " + ! "where " + setDataTable_getTickerListWhereClause( tickerCollection ) + " and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateTimeConstant( dateTime ) + " " + "order by " + Bars.TickerFieldName; --- 304,314 ---- /// <param name="dateTime">Date for the quotes to be fetched</param> /// <param name="dataTable">Output parameter</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> ! public static void SetDataTable( ICollection tickerCollection , DateTime dateTime , DataTable dataTable, int intervalFrameInSeconds) { string sql; sql = "select * from bars " + ! "where " + setDataTable_getTickerListWhereClause( tickerCollection ) + " and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + " and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateTimeConstant( dateTime ) + " " + "order by " + Bars.TickerFieldName; *************** *** 785,789 **** } #endregion - } } --- 317,320 ---- |
|
From: Marco M. <mi...@us...> - 2008-11-14 15:51:25
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4416/b4_Business/a05_Timing Modified Files: IndexBasedHistoricalTimer.cs Log Message: Added parameter intervalFrameInSeconds Index: IndexBasedHistoricalTimer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/IndexBasedHistoricalTimer.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IndexBasedHistoricalTimer.cs 12 Nov 2008 20:33:37 -0000 1.1 --- IndexBasedHistoricalTimer.cs 14 Nov 2008 15:51:18 -0000 1.2 *************** *** 37,45 **** { private string indexTicker; ! DateTime firstDateTime; ! DateTime lastDateTime; ! List< Time > dailyTimes; ! List< DateTime > dateTimesToBeThrown; private int currentDateTimeIndex; --- 37,46 ---- { private string indexTicker; ! private DateTime firstDateTime; ! private DateTime lastDateTime; ! private List< Time > dailyTimes; ! private int intervalFrameInSeconds; ! private List< DateTime > dateTimesToBeThrown; private int currentDateTimeIndex; *************** *** 48,52 **** DateTime firstDateTime , DateTime lastDateTime , ! List< Time > dailyTimes ) { this.indexTicker = indexTicker; --- 49,54 ---- DateTime firstDateTime , DateTime lastDateTime , ! List< Time > dailyTimes, ! int intervalFrameInSeconds) { this.indexTicker = indexTicker; *************** *** 54,57 **** --- 56,60 ---- this.lastDateTime = lastDateTime; this.dailyTimes = dailyTimes; + this.intervalFrameInSeconds = intervalFrameInSeconds; } *************** *** 71,75 **** Bars.GetMarketDateTimes( this.indexTicker , this.firstDateTime , this.lastDateTime , ! this.dailyTimes ); this.initialize_dateTimesToBeThrown( dateTimesToBeThrownHistory ); } --- 74,78 ---- Bars.GetMarketDateTimes( this.indexTicker , this.firstDateTime , this.lastDateTime , ! this.dailyTimes, this.intervalFrameInSeconds ); this.initialize_dateTimesToBeThrown( dateTimesToBeThrownHistory ); } |
|
From: Marco M. <mi...@us...> - 2008-11-14 15:51:25
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4416/b3_Data/DataTables Modified Files: Bars.cs Log Message: Added parameter intervalFrameInSeconds Index: Bars.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Bars.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Bars.cs 12 Nov 2008 20:40:43 -0000 1.2 --- Bars.cs 14 Nov 2008 15:51:18 -0000 1.3 *************** *** 61,72 **** /// <param name="tickerCollection">Tickers whose quotes are to be fetched</param> /// <param name="dateTime">DateTime for the bars to be fetched</param> ! public Bars( ICollection tickerCollection , DateTime dateTime ) { ! QuantProject.DataAccess.Tables.Bars.SetDataTable( ! tickerCollection , dateTime , this ); } ! public Bars( string ticker , DateTime startDateTime , DateTime endDateTime ) { ! this.fillDataTable( ticker , startDateTime , endDateTime ); } --- 61,75 ---- /// <param name="tickerCollection">Tickers whose quotes are to be fetched</param> /// <param name="dateTime">DateTime for the bars to be fetched</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> ! public Bars( ICollection tickerCollection , DateTime dateTime, int intervalFrameInSeconds ) { ! ! QuantProject.DataAccess.Tables.Bars.SetDataTable( ! tickerCollection , dateTime , this, intervalFrameInSeconds ); ! } ! public Bars( string ticker , DateTime startDateTime , DateTime endDateTime, int intervalFrameInSeconds ) { ! this.fillDataTable( ticker , startDateTime , endDateTime, intervalFrameInSeconds ); } *************** *** 77,86 **** /// <param name="ticker"></param> /// <param name="marketDateTimes"></param> ! public Bars( string ticker , SortedList marketDateTimes ) { DateTime firstDateTime = (DateTime)marketDateTimes.GetByIndex( 0 ); DateTime lastDateTime = (DateTime)marketDateTimes.GetByIndex( marketDateTimes.Count - 1 ); ! this.fillDataTable( ticker , firstDateTime , lastDateTime ); this.removeNonContainedDateTimes( marketDateTimes ); } --- 80,89 ---- /// <param name="ticker"></param> /// <param name="marketDateTimes"></param> ! public Bars( string ticker , SortedList marketDateTimes, int intervalFrameInSeconds ) { DateTime firstDateTime = (DateTime)marketDateTimes.GetByIndex( 0 ); DateTime lastDateTime = (DateTime)marketDateTimes.GetByIndex( marketDateTimes.Count - 1 ); ! this.fillDataTable( ticker , firstDateTime , lastDateTime, intervalFrameInSeconds ); this.removeNonContainedDateTimes( marketDateTimes ); } *************** *** 110,129 **** #endregion ! public Bars( string ticker ) { this.fillDataTable( ticker , ! QuantProject.DataAccess.Tables.Bars.GetFirstBarDateTime( ticker ) , ! QuantProject.DataAccess.Tables.Bars.GetLastBarDateTime( ticker ) ); ! } ! public Bars(SerializationInfo info, StreamingContext context) ! : base(info, context) ! { } ! private void fillDataTable( string ticker , DateTime startDateTime , DateTime endDateTime ) { ! QuantProject.DataAccess.Tables.Bars.SetDataTable( ! ticker , startDateTime , endDateTime , this ); ! this.setPrimaryKeys(); } private void setPrimaryKeys() --- 113,138 ---- #endregion ! public Bars( string ticker, int intervalFrameInSeconds ) { this.fillDataTable( ticker , ! QuantProject.DataAccess.Tables.Bars.GetFirstBarDateTime( ticker, intervalFrameInSeconds ) , ! QuantProject.DataAccess.Tables.Bars.GetLastBarDateTime( ticker, intervalFrameInSeconds ), ! intervalFrameInSeconds); } ! ! public Bars(SerializationInfo info, StreamingContext context) ! : base(info, context) ! { ! } ! private void fillDataTable( string ticker , DateTime startDateTime , DateTime endDateTime, int intervalFrameInSeconds ) ! ! { ! ! QuantProject.DataAccess.Tables.Bars.SetDataTable( ! ticker , startDateTime , endDateTime , this, intervalFrameInSeconds ); ! this.setPrimaryKeys(); ! } private void setPrimaryKeys() *************** *** 141,149 **** /// <param name="firstDateTime">begin interval</param> /// <param name="lastDateTime">end interval</param> /// <returns></returns> public static History GetMarketDateTimes( string ticker , ! DateTime firstDateTime , DateTime lastDateTime ) { ! Bars bars = new Bars( ticker , firstDateTime , lastDateTime ); History marketDateTimes = new History(); // int i = 0; --- 150,160 ---- /// <param name="firstDateTime">begin interval</param> /// <param name="lastDateTime">end interval</param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> public static History GetMarketDateTimes( string ticker , ! DateTime firstDateTime , DateTime lastDateTime, int intervalFrameInSeconds ) ! { ! Bars bars = new Bars( ticker , firstDateTime , lastDateTime, intervalFrameInSeconds ); History marketDateTimes = new History(); // int i = 0; *************** *** 209,217 **** private static History getMarketDateTimes( string ticker , DateTime firstDateTime , DateTime lastDateTime , ! List< Time > dailyTimes ) { History marketDateTimes = Bars.GetMarketDateTimes( ! ticker , firstDateTime , lastDateTime ); Bars.removeMissingTimes( dailyTimes , marketDateTimes ); return marketDateTimes; --- 220,228 ---- private static History getMarketDateTimes( string ticker , DateTime firstDateTime , DateTime lastDateTime , ! List< Time > dailyTimes, int intervalFrameInSeconds ) { History marketDateTimes = Bars.GetMarketDateTimes( ! ticker , firstDateTime , lastDateTime, intervalFrameInSeconds ); Bars.removeMissingTimes( dailyTimes , marketDateTimes ); return marketDateTimes; *************** *** 232,241 **** public static History GetMarketDateTimes( string ticker , DateTime firstDateTime , DateTime lastDateTime , ! List< Time > dailyTimes ) { // Bars.checkIfAreTimes( dailyTimes ); History marketDateTimes = Bars.getMarketDateTimes( ! ticker , firstDateTime , lastDateTime , dailyTimes ); return marketDateTimes; } --- 243,252 ---- public static History GetMarketDateTimes( string ticker , DateTime firstDateTime , DateTime lastDateTime , ! List< Time > dailyTimes, int intervalFrameInSeconds ) { // Bars.checkIfAreTimes( dailyTimes ); History marketDateTimes = Bars.getMarketDateTimes( ! ticker , firstDateTime , lastDateTime , dailyTimes, intervalFrameInSeconds ); return marketDateTimes; } *************** *** 244,257 **** #region GetCommonMarketDateTimes private static Hashtable getMarketDateTimes( ICollection tickers , DateTime firstDateTime , ! DateTime lastDateTime ) { Hashtable marketDateTimes = new Hashtable(); foreach ( string ticker in tickers ) if ( !marketDateTimes.ContainsKey( ticker ) ) ! { ! History marketDateTimesForSingleTicker = ! GetMarketDateTimes( ticker , firstDateTime , lastDateTime ); ! marketDateTimes.Add( ticker , marketDateTimesForSingleTicker ); ! } return marketDateTimes; } --- 255,270 ---- #region GetCommonMarketDateTimes private static Hashtable getMarketDateTimes( ICollection tickers , DateTime firstDateTime , ! DateTime lastDateTime, int intervalFrameInSeconds ) ! { Hashtable marketDateTimes = new Hashtable(); foreach ( string ticker in tickers ) if ( !marketDateTimes.ContainsKey( ticker ) ) ! { ! SortedList marketDateTimesForSingleTicker = ! GetMarketDateTimes( ticker , firstDateTime , lastDateTime, intervalFrameInSeconds ); ! marketDateTimes.Add( ticker , marketDateTimesForSingleTicker ); ! } ! return marketDateTimes; } *************** *** 287,294 **** public static SortedList GetCommonMarketDateTimes( ICollection tickers , ! DateTime firstDateTime , DateTime lastDateTime ) { ! Hashtable marketDateTimes = getMarketDateTimes( tickers , firstDateTime , lastDateTime ); ! return getCommonMarketDateTimes( tickers , firstDateTime , lastDateTime , marketDateTimes ); } --- 300,309 ---- public static SortedList GetCommonMarketDateTimes( ICollection tickers , ! DateTime firstDateTime , DateTime lastDateTime, int intervalFrameInSeconds ) { ! ! Hashtable marketDateTimes = getMarketDateTimes( tickers , firstDateTime , lastDateTime, intervalFrameInSeconds ); ! return getCommonMarketDateTimes( tickers , firstDateTime , lastDateTime , marketDateTimes ); ! } *************** *** 519,526 **** /// </summary> /// <param name="ticker"></param> /// <returns></returns> ! public static DateTime GetFirstBarDateTime( string ticker ) { ! return QuantProject.DataAccess.Tables.Bars.GetFirstBarDateTime( ticker ); } --- 534,542 ---- /// </summary> /// <param name="ticker"></param> + /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> ! public static DateTime GetFirstBarDateTime( string ticker, int intervalFrameInSeconds ) { ! return QuantProject.DataAccess.Tables.Bars.GetFirstBarDateTime( ticker, intervalFrameInSeconds ); } |
|
From: Marco M. <mi...@us...> - 2008-11-14 15:51:25
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4416/b4_Business/a2_Strategies/Eligibles Modified Files: ByPriceMostLiquidQuotedAtEachDateTime.cs Log Message: Added parameter intervalFrameInSeconds Index: ByPriceMostLiquidQuotedAtEachDateTime.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles/ByPriceMostLiquidQuotedAtEachDateTime.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ByPriceMostLiquidQuotedAtEachDateTime.cs 9 Nov 2008 19:21:48 -0000 1.1 --- ByPriceMostLiquidQuotedAtEachDateTime.cs 14 Nov 2008 15:51:18 -0000 1.2 *************** *** 54,57 **** --- 54,58 ---- private double minPrice; private double maxPrice; + private int intervalFrameInSeconds; private string marketIndex; *************** *** 73,77 **** int maxNumberOfEligibleTickersToBeChosen, int numOfDaysForAverageOpenRawPriceComputation, double minPrice, double maxPrice, ! string marketIndex) { this.temporizedGroup = temporizedGroup; --- 74,78 ---- int maxNumberOfEligibleTickersToBeChosen, int numOfDaysForAverageOpenRawPriceComputation, double minPrice, double maxPrice, ! int intervalFrameInSeconds, string marketIndex) { this.temporizedGroup = temporizedGroup; *************** *** 83,86 **** --- 84,88 ---- this.minPrice = minPrice; this.maxPrice = maxPrice; + this.intervalFrameInSeconds = intervalFrameInSeconds; this.marketIndex = marketIndex; } *************** *** 124,128 **** History marketDateTimes = Bars.GetMarketDateTimes(this.marketIndex,history.FirstDateTime, ! history.LastDateTime); double percentageOfDateTimes = 100.0; --- 126,130 ---- History marketDateTimes = Bars.GetMarketDateTimes(this.marketIndex,history.FirstDateTime, ! history.LastDateTime, this.intervalFrameInSeconds); double percentageOfDateTimes = 100.0; *************** *** 130,133 **** --- 132,136 ---- new SelectorByQuotationAtAGivenPercentageOfDateTimes( dataTableMostLiquid , false, marketDateTimes, + this.intervalFrameInSeconds, this.maxNumberOfEligibleTickersToBeChosen, percentageOfDateTimes); |
|
From: Glauco S. <gla...@us...> - 2008-11-12 20:44:42
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14085/b7_Scripts/WalkForwardTesting/PairsTrading/Logging Modified Files: TesterForPairsTradingTestingPositions.cs Log Message: A new parameter of type Timer has been added to the EndOfDayStrategyBackTester Index: TesterForPairsTradingTestingPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging/TesterForPairsTradingTestingPositions.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TesterForPairsTradingTestingPositions.cs 29 Sep 2008 21:21:34 -0000 1.5 --- TesterForPairsTradingTestingPositions.cs 12 Nov 2008 20:44:38 -0000 1.6 *************** *** 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; *************** *** 100,104 **** SimpleStrategy simpleStrategy = new SimpleStrategy( weightedPositions , ! intervalsSelector , historicalMarketValueProvider ); IAccountProvider accountProvider = new SimpleAccountProvider(); --- 100,104 ---- SimpleStrategy simpleStrategy = new SimpleStrategy( weightedPositions , ! intervalsSelector , historicalMarketValueProvider ); IAccountProvider accountProvider = new SimpleAccountProvider(); *************** *** 106,110 **** DateTime firstDateTime = this.dateTimeWhenThisObjectWasLogged.AddDays( ! - this.numberOfInSampleDays ); DateTime lastDateTime = this.dateTimeWhenThisObjectWasLogged; --- 106,110 ---- DateTime firstDateTime = this.dateTimeWhenThisObjectWasLogged.AddDays( ! - this.numberOfInSampleDays ); DateTime lastDateTime = this.dateTimeWhenThisObjectWasLogged; *************** *** 112,119 **** EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! "SinglePosition" , simpleStrategy , ! historicalMarketValueProvider , accountProvider , ! firstDateTime , lastDateTime , ! benchmark , cashToStart , maxRunningHours ); // simpleStrategy.Account = endOfDayStrategyBackTester.Account; --- 112,123 ---- EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! "SinglePosition" , ! new QuantProject.Business.Timing.IndexBasedEndOfDayTimer( ! HistoricalEndOfDayTimer.GetMarketOpen( firstDateTime ) , ! benchmark.Ticker ) , ! simpleStrategy , ! historicalMarketValueProvider , accountProvider , ! firstDateTime , lastDateTime , ! benchmark , cashToStart , maxRunningHours ); // simpleStrategy.Account = endOfDayStrategyBackTester.Account; *************** *** 161,165 **** WeightedPositions weightedPositions = this.testingPositions.WeightedPositions; ! WeightedPositions firstPosition = this.getWeightedPositions( weightedPositions[ 0 ] ); --- 165,169 ---- WeightedPositions weightedPositions = this.testingPositions.WeightedPositions; ! WeightedPositions firstPosition = this.getWeightedPositions( weightedPositions[ 0 ] ); *************** *** 168,179 **** AccountReport accountReportForFirstPosition = this.getAccountReport( firstPosition , intervalsSelector , ! historicalMarketValueProvider , ! benchmark , 30000 ); AccountReport accountReportForSecondPosition = this.getAccountReport( secondPosition , intervalsSelector , ! historicalMarketValueProvider , ! benchmark , ! Math.Abs( 30000 * weightedPositions[ 1 ].Weight / ! weightedPositions[ 0 ].Weight ) ); Report report = --- 172,183 ---- AccountReport accountReportForFirstPosition = this.getAccountReport( firstPosition , intervalsSelector , ! historicalMarketValueProvider , ! benchmark , 30000 ); AccountReport accountReportForSecondPosition = this.getAccountReport( secondPosition , intervalsSelector , ! historicalMarketValueProvider , ! benchmark , ! Math.Abs( 30000 * weightedPositions[ 1 ].Weight / ! weightedPositions[ 0 ].Weight ) ); Report report = *************** *** 185,194 **** // accountReportForFirstPosition.EquityLine.LastDateTime , // EndOfDaySpecificTime.OneHourAfterMarketClose ); ! // report.Create( "PearsonDebug" , 1 , // lastEndOfDayDateTimeForReport , // benchmark.Ticker , false ); report.AddEquityLine( accountReportForSecondPosition.EquityLine , ! Color.Brown ); report.ShowDialog(); } --- 189,198 ---- // accountReportForFirstPosition.EquityLine.LastDateTime , // EndOfDaySpecificTime.OneHourAfterMarketClose ); ! // report.Create( "PearsonDebug" , 1 , // lastEndOfDayDateTimeForReport , // benchmark.Ticker , false ); report.AddEquityLine( accountReportForSecondPosition.EquityLine , ! Color.Brown ); report.ShowDialog(); } |
|
From: Glauco S. <gla...@us...> - 2008-11-12 20:44:20
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14049/b7_Scripts/WalkForwardTesting/PairsTrading Modified Files: PairsTradingMain.cs Log Message: A new parameter of type Timer has been added to the EndOfDayStrategyBackTester Index: PairsTradingMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/PairsTradingMain.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** PairsTradingMain.cs 8 Nov 2008 20:36:36 -0000 1.19 --- PairsTradingMain.cs 12 Nov 2008 20:44:13 -0000 1.20 *************** *** 22,27 **** --- 22,29 ---- using System; + using System.Collections.Generic; using QuantProject.ADT; + using QuantProject.ADT.Timing; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting.AccountProviding; *************** *** 89,104 **** #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; --- 91,105 ---- #region getBarCache ! private List< Time > getDailyTimes() { ! List< Time > dailyTimes = new List< Time >(); ! dailyTimes.Add( new Time( 13 , 0 , 0 ) ); ! dailyTimes.Add( new Time( 14 , 0 , 0 ) ); ! dailyTimes.Add( new Time( 15 , 0 , 0 ) ); return dailyTimes; } private IBarCache getBarCache() { ! List< Time > dailyTimes = this.getDailyTimes(); IBarCache barCache = new DailyBarCache( 60 , dailyTimes ); return barCache; *************** *** 121,125 **** string tickersGroupId = "SP500"; // uncomment the following line for a faster script ! // tickersGroupId = "fastTest"; // IEligiblesSelector eligiblesSelector = --- 122,126 ---- string tickersGroupId = "SP500"; // uncomment the following line for a faster script ! tickersGroupId = "fastTest"; // IEligiblesSelector eligiblesSelector = *************** *** 152,156 **** int numberOfBestTestingPositionsToBeReturned = 50; // uncomment the following line for a faster script ! // numberOfBestTestingPositionsToBeReturned = 5; IDecoderForTestingPositions decoderForWeightedPositions = --- 153,157 ---- int numberOfBestTestingPositionsToBeReturned = 50; // uncomment the following line for a faster script ! numberOfBestTestingPositionsToBeReturned = 5; IDecoderForTestingPositions decoderForWeightedPositions = *************** *** 202,206 **** // uncomment the following line for a faster script // inSampleDays = 5; ! // inSampleDays = 60; IIntervalsSelector intervalsSelectorForOutOfSample = --- 203,207 ---- // uncomment the following line for a faster script // inSampleDays = 5; ! inSampleDays = 60; IIntervalsSelector intervalsSelectorForOutOfSample = *************** *** 250,253 **** --- 251,266 ---- return strategyForBacktester; } + + #region getEndOfDayStrategyBackTester + private Timer getTimer( + DateTime firstDateTime , DateTime lastDateTime) + { + List< Time > dailyTimes = this.getDailyTimes(); + IndexBasedHistoricalTimer indexBasedTimer = + new IndexBasedHistoricalTimer( + this.benchmark.Ticker , + firstDateTime , lastDateTime , dailyTimes ); + return indexBasedTimer; + } protected override EndOfDayStrategyBackTester getEndOfDayStrategyBackTester() *************** *** 262,266 **** // uncomment the following two lines for a faster script ! firstDateTime = new DateTime( 2002 , 1 , 1 ); lastDateTime = new DateTime( 2007 , 6 , 30 ); --- 275,279 ---- // uncomment the following two lines for a faster script ! firstDateTime = new DateTime( 2006 , 2 , 1 ); lastDateTime = new DateTime( 2007 , 6 , 30 ); *************** *** 269,273 **** EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.strategyForBacktester , this.historicalMarketValueProviderForTheBacktesterAccount , accountProvider , --- 282,288 ---- EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , ! this.getTimer( firstDateTime , lastDateTime ) , ! this.strategyForBacktester , this.historicalMarketValueProviderForTheBacktesterAccount , accountProvider , *************** *** 276,279 **** --- 291,295 ---- return endOfDayStrategyBackTester; } + #endregion getEndOfDayStrategyBackTester protected override string getPathForTheMainFolderWhereScriptsResultsAreToBeSaved() |