[Quantproject-developers] QuantProject/b4_Business/a2_Strategies/returnsManagement/time ReturnInte
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:23:00
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement/time In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23093/b4_Business/a2_Strategies/returnsManagement/time Modified Files: ReturnIntervals.cs Log Message: - The class is not abstract anymore - the property LastEndOfDayDateTime has been improved (an exception has been added) - A new constructor public ReturnIntervals( IIntervalsSelector intervalSelector) has been added. intervalSelector will be used to add new intervals progressively - derived classes should become IIntervalSelector(s) - the method public void AppendIntervalsButDontGoBeyondLastDate( EndOfDayDateTime lastDate ) has been added - the method public void AppendIntervalsToGoJustBeyond( EndOfDayDateTime lastDate ) has been added - the method public void AppendFirstInterval( EndOfDayDateTime firstDate ) has been added Index: ReturnIntervals.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement/time/ReturnIntervals.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ReturnIntervals.cs 30 Oct 2007 19:06:48 -0000 1.4 --- ReturnIntervals.cs 19 Jan 2008 19:22:57 -0000 1.5 *************** *** 25,28 **** --- 25,29 ---- using QuantProject.ADT.Histories; + using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; *************** *** 33,37 **** /// never begins before the (n)th interval ends /// </summary> ! public abstract class ReturnIntervals : CollectionBase { protected EndOfDayDateTime firstEndOfDayDateTime; --- 34,38 ---- /// never begins before the (n)th interval ends /// </summary> ! public class ReturnIntervals : CollectionBase { protected EndOfDayDateTime firstEndOfDayDateTime; *************** *** 41,46 **** private EndOfDayHistory bordersHistory; protected int intervalLength; ! public ReturnInterval this[ int index ] { get --- 42,49 ---- private EndOfDayHistory bordersHistory; protected int intervalLength; + + private IIntervalsSelector intervalsSelector; ! public ReturnInterval this[ int index ] { get *************** *** 61,64 **** --- 64,71 ---- get { + if ( this.Count == 0 ) + throw new Exception( "LastEndOfDayDateTime " + + "cannot be used when ReturnIntervals has " + + "no ReturnInterval added yet!" ); return this[ this.Count - 1 ].End; } *************** *** 134,137 **** --- 141,156 ---- } + /// <summary> + /// Use this constructor if you want to create an empty + /// collection of intervals. The object will then be populated + /// adding intervals by means of an IIntervalSelector + /// </summary> + /// <param name="intervalSelector">to be used for adding + /// intervals</param> + public ReturnIntervals( IIntervalsSelector intervalSelector) + { + this.intervalsSelector = intervalSelector; + } + protected virtual void setMarketDaysForBenchmark() { *************** *** 141,145 **** } ! protected abstract void setIntervals(); /// <summary> --- 160,168 ---- } ! protected virtual void setIntervals() ! { ! // TO DO remove this method and change ! // derived classes to become IIntervalSelector ! } /// <summary> *************** *** 215,218 **** --- 238,367 ---- this.List.Add( returnInterval ); } + + #region appendIntervalsButDontGoBeyondLastDate + private void appendIntervalsButDontGoBeyondLastDate_checkParameters( + EndOfDayDateTime firstDate , EndOfDayDateTime lastDate ) + { + if ( firstDate.CompareTo( lastDate ) >= 0 ) + throw new Exception( "lastDate must be greater than firstDate!" ); + if ( this.Count > 0 ) + // some interval has already been added + { + EndOfDayDateTime currentLastEndOfDayDateTime = + this[ this.Count - 1 ].End; + if ( firstDate.CompareTo( currentLastEndOfDayDateTime ) < 0 ) + throw new Exception( "firstDate cannot be smaller than " + + "the end of the last interval already in this collection!" ); + } + } + /// <summary> + /// Appends a list of intervals, starting from firstDate and + /// until the next one would go beyond lastDate. + /// This method can be invoked even if the ReturnIntervals object + /// is empty. + /// The firstDate has to be earlier than lastDate + /// </summary> + /// <param name="firstDate"></param> + /// <param name="lastDate"></param> + private void appendIntervalsButDontGoBeyondLastDate( EndOfDayDateTime firstDate , + EndOfDayDateTime lastDate ) + { + this.appendIntervalsButDontGoBeyondLastDate_checkParameters( + firstDate , lastDate ); + ReturnInterval nextInterval = + this.intervalsSelector.GetFirstInterval( firstDate ); + while ( nextInterval.End.CompareTo( lastDate ) <= 0 ) + { + this.Add( nextInterval ); + nextInterval = + this.intervalsSelector.GetNextInterval( this ); + } + } + #endregion appendIntervalsButDontGoBeyondLastDate + + #region AppendIntervalsButDontGoBeyondLastDate + private void appendIntervalsButDontGoBeyondLastDate_checkParameters( + EndOfDayDateTime lastDate ) + { + if ( this.Count == 0 ) + throw new Exception( + "ReturnIntervals.AppendIntervalsButDontGoBeyondLastDate( " + + "EndOfDayDateTime lastDate ) " + + "has been invoked but the current ReturnIntervals " + + "object is empty!" ); + if ( lastDate.IsLessThanOrEqualTo( this.LastEndOfDayDateTime ) ) + throw new Exception( + "ReturnIntervals.AppendIntervalsButDontGoBeyondLastDate( " + + "EndOfDayDateTime lastDate ) " + + "has been invoked but lastDate must be larger than the " + + "end of the last ReturnInterval already in this collection" ); + } + /// <summary> + /// Appends a list of intervals, + /// until the next one would go beyond lastDate. + /// This method can be invoked only if the ReturnIntervals object + /// is not empty. + /// The last added interval must end before lastDate + /// </summary> + /// <param name="lastDate"></param> + public void AppendIntervalsButDontGoBeyondLastDate( + EndOfDayDateTime lastDate ) + { + this.appendIntervalsButDontGoBeyondLastDate_checkParameters( + lastDate ); + EndOfDayDateTime firstDate = this.LastEndOfDayDateTime; + this.appendIntervalsButDontGoBeyondLastDate( firstDate , lastDate ); + } + #endregion AppendIntervalsButDontGoBeyondLastDate + + #region AppendIntervalsToGoJustBeyond + private void appendIntervalsToGoJustBeyondLastDate_checkParameters( + EndOfDayDateTime lastDate ) + { + if ( this.Count == 0 ) + throw new Exception( + "ReturnIntervals.AppendIntervalsToGoJustBeyond( EndOfDayDateTime lastDate ) " + + "has been invoked but the current ReturnIntervals " + + "object is empty!" ); + if ( lastDate.IsLessThan( this.LastEndOfDayDateTime ) ) + throw new Exception( + "ReturnIntervals.AppendIntervalsToGoJustBeyond( EndOfDayDateTime lastDate ) " + + "has been invoked but lastDate must be larger than or equal to " + + "the end of the last ReturnInterval already in the collection" ); + } + + /// <summary> + /// Appends a list of intervals, and stops as soon + /// as the last added interval exceeds lastDate. + /// This method can be invoked only if the ReturnIntervals object + /// is not empty. + /// The last added interval cannot end after lastDate + /// </summary> + /// <param name="lastDate"></param> + public void AppendIntervalsToGoJustBeyond( + EndOfDayDateTime lastDate ) + { + this.appendIntervalsToGoJustBeyondLastDate_checkParameters( + lastDate ); + if ( this.LastEndOfDayDateTime.IsLessThan( lastDate ) ) + // lastDate comes after the last interval already added + this.AppendIntervalsButDontGoBeyondLastDate( lastDate ); + ReturnInterval lastInterval = + this.intervalsSelector.GetNextInterval( this ); + this.Add( lastInterval ); + } + #endregion AppendIntervalsToGoJustBeyond + + /// <summary> + /// Appends the first interval (starting from firstDate) + /// </summary> + /// <param name="firstDate"></param> + public void AppendFirstInterval( + EndOfDayDateTime firstDate ) + { + ReturnInterval firstInterval = + this.intervalsSelector.GetFirstInterval( firstDate ); + this.Add( firstInterval ); + } } } |