[Quantproject-developers] QuantProject/b4_Business/a2_Strategies/returnsManagement ReturnsManager.
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2007-09-16 22:00:41
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23667/b4_Business/a2_Strategies/returnsManagement Modified Files: ReturnsManager.cs Log Message: - in the previous version, this class was an abstract class (returns where actually computed by classes inheriting ReturnsManager) - in this version, instead, this class itself computes returns - now, an object of type ReturnIntervals must be given to the constructor: returns will be computed on such intervals - now, a IHistoricalQuoteProvider is also required by the constructor: this way, it can be decided either to use adjusted quotes or raw quotes Index: ReturnsManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement/ReturnsManager.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ReturnsManager.cs 4 Aug 2007 19:59:08 -0000 1.3 --- ReturnsManager.cs 16 Sep 2007 22:00:27 -0000 1.4 *************** *** 27,30 **** --- 27,33 ---- using QuantProject.ADT.Histories; using QuantProject.ADT.Statistics; + using QuantProject.Business.DataProviders; + using QuantProject.Business.Strategies.ReturnsManagement.Time; + using QuantProject.Business.Timing; using QuantProject.Data.DataTables; *************** *** 32,42 **** { /// <summary> ! /// This abstract class is used to keep and provide, in an efficient ! /// way, array of returns (to be used by in sample optimizations) /// </summary> ! public abstract class ReturnsManager { ! protected History timeLineForQuotes; // if we have n market days for quotes, ! // we will then have n-1 returns private Set tickersMissingQuotes; --- 35,46 ---- { /// <summary> ! /// This class is used to keep and provide, in an efficient ! /// way, array of returns on EndOfDayIntervals (to be used ! /// by in sample optimizations) /// </summary> ! public class ReturnsManager { ! private ReturnIntervals returnIntervals; // a return for each interval ! private IHistoricalQuoteProvider historicalQuoteProvider; private Set tickersMissingQuotes; *************** *** 46,77 **** /// <summary> ! /// Dates when quotes are computed. If TimeLine contains ! /// n elements, then returns are n-1 elements /// </summary> ! public History TimeLine { ! get { return this.timeLineForQuotes; } } /// <summary> ! /// Number of returns, that is TimeLine's elements minus 1 /// </summary> public int NumberOfReturns { ! get { return this.TimeLine.Count - 1; } ! } ! protected DateTime firstDateTime ! { ! get { return this.timeLineForQuotes.GetDateTime( 0 ); } ! } ! protected DateTime lastDateTime ! { ! get ! { ! int lastIndex = this.timeLineForQuotes.Count - 1; ! return this.timeLineForQuotes.GetDateTime( lastIndex ); ! } } ! /// <summary> /// Abstract class used to store and efficiently provide arrays of --- 50,80 ---- /// <summary> ! /// End of day intervals on which returns are computed /// </summary> ! public ReturnIntervals ReturnIntervals { ! get { return this.returnIntervals; } } /// <summary> ! /// Number of returns, that is number of intervals /// </summary> public int NumberOfReturns { ! get { return this.returnIntervals.Count; } } ! // protected DateTime firstDateTime ! // { ! // get { return this.timeLineForQuotes.GetDateTime( 0 ); } ! // } ! // protected DateTime lastDateTime ! // { ! // get ! // { ! // int lastIndex = this.timeLineForQuotes.Count - 1; ! // return this.timeLineForQuotes.GetDateTime( lastIndex ); ! // } ! // } ! // /// <summary> /// Abstract class used to store and efficiently provide arrays of *************** *** 87,103 **** /// for the benchmark, each array of returns will have exactly /// n-1 elements</param> ! public ReturnsManager( DateTime firstDate , DateTime lastDate , ! string benchmark ) ! { ! // TO DO: let WFLagEligibleTickers use this class also!!! ! this.timeLineForQuotes = ! this.getMarketDaysForQuotes( firstDate , lastDate , benchmark ); ! this.commonInitialization(); ! } ! public ReturnsManager( History timeLine ) { // TO DO: let WFLagEligibleTickers use this class also!!! ! this.timeLineForQuotes = timeLine; this.commonInitialization(); } private void commonInitialization() --- 90,108 ---- /// for the benchmark, each array of returns will have exactly /// n-1 elements</param> ! // public ReturnsManager( DateTime firstDate , DateTime lastDate , ! // string benchmark ) ! // { ! // // TO DO: let WFLagEligibleTickers use this class also!!! ! // this.timeLineForQuotes = ! // this.getMarketDaysForQuotes( firstDate , lastDate , benchmark ); ! // this.commonInitialization(); ! // } ! public ReturnsManager( ReturnIntervals returnIntervals , ! IHistoricalQuoteProvider historicalQuoteProvider ) { // TO DO: let WFLagEligibleTickers use this class also!!! ! this.returnIntervals = returnIntervals; this.commonInitialization(); + this.historicalQuoteProvider = historicalQuoteProvider; } private void commonInitialization() *************** *** 117,121 **** private bool isAValidIndexForAReturn( int index ) { ! return ( ( index >= 0 ) && ( index <= this.TimeLine.Count - 2 ) ); } #region GetReturns --- 122,127 ---- private bool isAValidIndexForAReturn( int index ) { ! return ( ( index >= 0 ) && ! ( index <= this.ReturnIntervals.Count - 1 ) ); } #region GetReturns *************** *** 124,166 **** return this.tickersReturns.ContainsKey( ticker ); } ! protected abstract History getQuotes( string ticker ); #region setReturns ! private bool areMarketDaysForQuotesAllCovered( History returns ) ! { ! bool areAllCovered = true; ! foreach ( DateTime dateTime in this.timeLineForQuotes.TimeLine ) ! if ( !returns.ContainsKey( dateTime ) ) ! areAllCovered = false; ! return areAllCovered; ! } ! private float selectReturnWithRespectToTheTimeLine( History quotes , ! int i ) { ! float currentQuote = (float)quotes.GetByIndex( i ); ! float nextQuote = (float)quotes.GetByIndex( i + 1 ); ! float currentReturn = nextQuote / currentQuote - 1; ! return currentReturn; } ! private float[] selectReturnsWithRespectToTheTimeLine( History quotes ) { // TO DO: this method is n log n, it could be implemented to // be have a linear complexity!!! ! float[] returnsWithRespectToTheTimeLine = ! new float[ this.timeLineForQuotes.Count - 1 ]; ! for ( int i = 0 ; i < this.timeLineForQuotes.Count - 1 ; i++ ) ! returnsWithRespectToTheTimeLine[ i ] = ! this.selectReturnWithRespectToTheTimeLine( quotes , i ); ! return returnsWithRespectToTheTimeLine; } ! private void setReturnsActually( string ticker , History quotes ) { float[] arrayOfReturns = ! this.selectReturnsWithRespectToTheTimeLine( quotes ); this.tickersReturns.Add( ticker , arrayOfReturns ); } ! private void setReturns( string ticker , History quotes ) { ! if ( this.areMarketDaysForQuotesAllCovered( quotes ) ) ! this.setReturnsActually( ticker , quotes ); else this.tickersMissingQuotes.Add( ticker ); --- 130,170 ---- return this.tickersReturns.ContainsKey( ticker ); } ! // protected abstract History getQuotes( string ticker ); #region setReturns ! private float selectReturnWithRespectToTheGivenIterval( ! EndOfDayHistory endOfDayQuotes , int i ) { ! ReturnInterval returnInterval = ! this.returnIntervals[ i ]; ! double firstQuote = (double)endOfDayQuotes[ returnInterval.Begin ]; ! double lastQuote = (double)endOfDayQuotes[ returnInterval.End ]; ! float intervalReturn = Convert.ToSingle( firstQuote / lastQuote - 1 ); ! return intervalReturn; } ! private float[] selectReturnsWithRespectToTheGivenIntervals( ! EndOfDayHistory endOfDayQuotes ) { // TO DO: this method is n log n, it could be implemented to // be have a linear complexity!!! ! float[] returnsWithRespectToTheGivenIntervals = ! new float[ this.returnIntervals.Count ]; ! for ( int i = 0 ; i < this.returnIntervals.Count - 1 ; i++ ) ! returnsWithRespectToTheGivenIntervals[ i ] = ! this.selectReturnWithRespectToTheGivenIterval( endOfDayQuotes , i ); ! return returnsWithRespectToTheGivenIntervals; } ! private void setReturnsActually( string ticker , ! EndOfDayHistory endOfDayQuotes ) { float[] arrayOfReturns = ! this.selectReturnsWithRespectToTheGivenIntervals( endOfDayQuotes ); this.tickersReturns.Add( ticker , arrayOfReturns ); } ! private void setReturns( string ticker , ! EndOfDayHistory endOfDayQuotes ) { ! if ( this.returnIntervals.AreIntervalBordersAllCoveredBy( ! endOfDayQuotes ) ) ! this.setReturnsActually( ticker , endOfDayQuotes ); else this.tickersMissingQuotes.Add( ticker ); *************** *** 168,173 **** private void setReturns( string ticker ) { ! History quotes = this.getQuotes( ticker ); ! this.setReturns( ticker , quotes ); } #endregion setReturns --- 172,183 ---- private void setReturns( string ticker ) { ! // EndOfDayDateTime firstEndOfDayDateTime = ! // this.returnIntervals[ 0 ].Begin; ! // EndOfDayDateTime lastEndOfDayDateTime = ! // this.returnIntervals.LastEndOfDayDateTime; ! EndOfDayHistory endOfDayQuotes = ! this.historicalQuoteProvider.GetEndOfDayQuotes( ticker , ! this.returnIntervals.BordersHistory ); ! this.setReturns( ticker , endOfDayQuotes ); } #endregion setReturns |