[Quantproject-developers] QuantProject/b4_Business/a2_Strategies AccountStrategy.cs, 1.3, 1.4 Bench
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:14:47
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13959 Modified Files: AccountStrategy.cs Benchmark.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: AccountStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/AccountStrategy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AccountStrategy.cs 9 Jan 2005 22:08:47 -0000 1.3 --- AccountStrategy.cs 29 Sep 2008 21:14:23 -0000 1.4 *************** *** 61,65 **** virtualOrder.Instrument , (long) - ((Position)this.account.Portfolio[ virtualOrder.Instrument.Key ]).Quantity , ! virtualOrder.EndOfDayDateTime ) ); if ( !this.account.Portfolio.IsLong( virtualOrder.Instrument ) ) orders.Add( new Order( OrderType.MarketBuy , --- 61,65 ---- virtualOrder.Instrument , (long) - ((Position)this.account.Portfolio[ virtualOrder.Instrument.Key ]).Quantity , ! virtualOrder.DateTime ) ); if ( !this.account.Portfolio.IsLong( virtualOrder.Instrument ) ) orders.Add( new Order( OrderType.MarketBuy , *************** *** 68,72 **** this.account.CashAmount + this.account.Portfolio.GetMarketValue( this.account.DataStreamer ) , ! this.account.DataStreamer ) , virtualOrder.EndOfDayDateTime ) ); break; case OrderType.MarketSell: --- 68,72 ---- this.account.CashAmount + this.account.Portfolio.GetMarketValue( this.account.DataStreamer ) , ! this.account.DataStreamer ) , virtualOrder.DateTime ) ); break; case OrderType.MarketSell: *************** *** 75,79 **** virtualOrder.Instrument , (long) this.account.Portfolio.GetPosition( virtualOrder.Instrument ).Quantity , ! virtualOrder.EndOfDayDateTime ) ); if ( !this.account.Portfolio.IsShort( virtualOrder.Instrument ) ) orders.Add( new Order( OrderType.MarketSellShort , --- 75,79 ---- virtualOrder.Instrument , (long) this.account.Portfolio.GetPosition( virtualOrder.Instrument ).Quantity , ! virtualOrder.DateTime ) ); if ( !this.account.Portfolio.IsShort( virtualOrder.Instrument ) ) orders.Add( new Order( OrderType.MarketSellShort , *************** *** 83,87 **** this.account.Portfolio.GetMarketValue( dataStreamer ) , dataStreamer ) , ! virtualOrder.EndOfDayDateTime ) ); break; default: --- 83,87 ---- this.account.Portfolio.GetMarketValue( dataStreamer ) , dataStreamer ) , ! virtualOrder.DateTime ) ); break; default: Index: Benchmark.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Benchmark.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Benchmark.cs 7 Feb 2008 18:35:38 -0000 1.3 --- Benchmark.cs 29 Sep 2008 21:14:23 -0000 1.4 *************** *** 1,4 **** --- 1,6 ---- using System; + using QuantProject.ADT; + using QuantProject.ADT.Histories; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies.ReturnsManagement.Time; *************** *** 15,19 **** { private string ticker; ! private HistoricalQuoteProvider historicalQuoteProvider; public string Ticker --- 17,21 ---- { private string ticker; ! private HistoricalMarketValueProvider historicalQuoteProvider; public string Ticker *************** *** 31,35 **** #region GetTimeStep private void getTimeStep_checkParameters( ! EndOfDayDateTime timeStepBegin ) { if ( !this.historicalQuoteProvider.WasExchanged( this.ticker , --- 33,37 ---- #region GetTimeStep private void getTimeStep_checkParameters( ! DateTime timeStepBegin ) { if ( !this.historicalQuoteProvider.WasExchanged( this.ticker , *************** *** 40,46 **** } private void isExchanged_checkParameter( ! EndOfDayDateTime endOfDayDateTime ) { ! if ( endOfDayDateTime.DateTime.Year > DateTime.Now.Year ) throw new Exception( "It looks like this is a loop! " + --- 42,48 ---- } private void isExchanged_checkParameter( ! DateTime dateTime ) { ! if ( dateTime.Year > DateTime.Now.Year ) throw new Exception( "It looks like this is a loop! " + *************** *** 49,69 **** this.ticker + "'" ); } ! private bool isExchanged( EndOfDayDateTime endOfDayDateTime ) { ! this.isExchanged_checkParameter( endOfDayDateTime ); bool isTraded = this.historicalQuoteProvider.WasExchanged( ! this.ticker , endOfDayDateTime ); return isTraded; } private ReturnInterval getTimeStep_actually( ! EndOfDayDateTime timeStepBegin ) { ! EndOfDayDateTime currentEndOfDayDateTime = ! timeStepBegin.GetNextMarketStatusSwitch(); ! while ( !this.isExchanged( currentEndOfDayDateTime ) ) ! currentEndOfDayDateTime = ! currentEndOfDayDateTime.GetNextMarketStatusSwitch(); ReturnInterval timeStep = ! new ReturnInterval( timeStepBegin , currentEndOfDayDateTime ); return timeStep; } --- 51,74 ---- this.ticker + "'" ); } ! private bool isExchanged( DateTime dateTime ) { ! this.isExchanged_checkParameter( dateTime ); bool isTraded = this.historicalQuoteProvider.WasExchanged( ! this.ticker , dateTime ); return isTraded; } private ReturnInterval getTimeStep_actually( ! DateTime timeStepBegin ) { ! DateTime currentDateTime = ! HistoricalEndOfDayTimer.GetNextMarketStatusSwitch( timeStepBegin ); ! // timeStepBegin.GetNextMarketStatusSwitch(); ! while ( !this.isExchanged( currentDateTime ) ) ! currentDateTime = ! HistoricalEndOfDayTimer.GetNextMarketStatusSwitch( currentDateTime ); ! // currentEndOfDayDateTime = ! // currentEndOfDayDateTime.GetNextMarketStatusSwitch(); ReturnInterval timeStep = ! new ReturnInterval( timeStepBegin , currentDateTime ); return timeStep; } *************** *** 73,80 **** /// <param name="timeStepBegin"></param> /// <returns></returns> ! public ReturnInterval GetTimeStep( EndOfDayDateTime timeStepBegin ) { this.getTimeStep_checkParameters( timeStepBegin ); ! ReturnInterval timeStep = this.getTimeStep_actually( timeStepBegin ); return timeStep; } --- 78,86 ---- /// <param name="timeStepBegin"></param> /// <returns></returns> ! public ReturnInterval GetTimeStep( DateTime timeStepBegin ) { this.getTimeStep_checkParameters( timeStepBegin ); ! ReturnInterval timeStep = ! this.getTimeStep_actually( timeStepBegin ); return timeStep; } *************** *** 84,123 **** /// Returns either the next market close or the next market open /// (when the benchmark is exchanged), whichever is the nearest. ! /// If endOfDayDateTime is either a market close or a market open ! /// when the benchmark is exchanged, then endOfDayDateTime itself /// is returned /// </summary> ! /// <param name="endOfDayDateTime"></param> /// <returns></returns> ! public EndOfDayDateTime GetThisOrNextMarketStatusSwitch( ! EndOfDayDateTime endOfDayDateTime ) { ! EndOfDayDateTime currentEndOfDayDateTime = endOfDayDateTime; ! while ( !this.isExchanged( currentEndOfDayDateTime ) ) ! currentEndOfDayDateTime = ! currentEndOfDayDateTime.GetNextMarketStatusSwitch(); ! return currentEndOfDayDateTime; } /// <summary> ! /// Returns the EndOfDayHistory of the benchmark /// between the two given EndOfDayDateTimes /// </summary> ! public EndOfDayHistory GetEndOfDayHistory( ! EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime ) { ! if( lastEndOfDayDateTime.IsLessThanOrEqualTo(firstEndOfDayDateTime) ) ! throw new Exception("lastEndOfDayDateTime has to be greater than " + "firstEndOfDayDateTime !!"); ! EndOfDayHistory endOfDayHistory = new EndOfDayHistory(); ! EndOfDayDateTime endOfDayDateTimeToAddToHistory = ! firstEndOfDayDateTime.Copy(); ! while( endOfDayDateTimeToAddToHistory.IsLessThanOrEqualTo(lastEndOfDayDateTime) ) { ! if( this.isExchanged( endOfDayDateTimeToAddToHistory ) ) ! endOfDayHistory.Add( endOfDayDateTimeToAddToHistory, endOfDayDateTimeToAddToHistory ); ! endOfDayDateTimeToAddToHistory = ! endOfDayDateTimeToAddToHistory.GetNextMarketStatusSwitch(); } return endOfDayHistory; --- 90,139 ---- /// Returns either the next market close or the next market open /// (when the benchmark is exchanged), whichever is the nearest. ! /// If dateTime is either a market close or a market open ! /// when the benchmark is exchanged, then dateTime itself /// is returned /// </summary> ! /// <param name="dateTime"></param> /// <returns></returns> ! public DateTime GetThisOrNextMarketStatusSwitch( ! DateTime dateTime ) { ! DateTime currentDateTime = dateTime; ! if ( !HistoricalEndOfDayTimer.IsMarketStatusSwitch( currentDateTime ) ) ! currentDateTime = ! HistoricalEndOfDayTimer.GetNextMarketStatusSwitch( ! currentDateTime ); ! while ( !this.isExchanged( currentDateTime ) ) ! currentDateTime = ! HistoricalEndOfDayTimer.GetNextMarketStatusSwitch( ! currentDateTime ); ! // currentEndOfDayDateTime.GetNextMarketStatusSwitch(); ! return currentDateTime; } /// <summary> ! /// Returns the End of Day History of the benchmark /// between the two given EndOfDayDateTimes /// </summary> ! public History GetEndOfDayHistory( ! DateTime firstDateTime, ! DateTime lastDateTime ) { ! if( lastDateTime <= firstDateTime ) ! throw new Exception("lastDateTime has to be greater than " + "firstEndOfDayDateTime !!"); ! History endOfDayHistory = new History(); ! DateTime dateTimeToAddToHistory = ! ExtendedDateTime.Copy( firstDateTime ); ! // firstDateTime.Copy(); ! while( dateTimeToAddToHistory <= lastDateTime ) { ! if( this.isExchanged( dateTimeToAddToHistory ) ) ! endOfDayHistory.Add( ! dateTimeToAddToHistory , ! dateTimeToAddToHistory ); ! dateTimeToAddToHistory = ! HistoricalEndOfDayTimer.GetNextMarketStatusSwitch( ! dateTimeToAddToHistory ); } return endOfDayHistory; |