[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:23
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16680/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVO_OTCStrategy.cs PVO_OTCStrategyLessCorrelated.cs PVOLogItem.cs PVOMain.cs PVOPositions.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: PVOMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOMain.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PVOMain.cs 19 Aug 2008 17:13:00 -0000 1.6 --- PVOMain.cs 29 Sep 2008 21:18:13 -0000 1.7 *************** *** 59,63 **** { private Benchmark benchmark; ! private HistoricalQuoteProvider historicalQuoteProvider; public PVOMain() --- 59,63 ---- { private Benchmark benchmark; ! private HistoricalMarketValueProvider historicalQuoteProvider; public PVOMain() *************** *** 159,163 **** } ! protected override IEndOfDayStrategyForBacktester getEndOfDayStrategy() { int inSampleDays = 180; --- 159,163 ---- } ! protected override IStrategyForBacktester getStrategyForBacktester() { int inSampleDays = 180; *************** *** 172,176 **** double minimumAcceptableGain = 0.002; int closeToCloseIntervalLength = 1; ! IEndOfDayStrategyForBacktester endOfDayStrategy // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , // inSampleDays , benchmark , numDaysBetweenEachOptimization , --- 172,176 ---- double minimumAcceptableGain = 0.002; int closeToCloseIntervalLength = 1; ! IStrategyForBacktester strategyForBacktester // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , // inSampleDays , benchmark , numDaysBetweenEachOptimization , *************** *** 182,186 **** oversoldThresholdMAX , overboughtThresholdMAX , historicalQuoteProvider, maxAcceptableDrawDown, minimumAcceptableGain ); ! return endOfDayStrategy; } protected override EndOfDayStrategyBackTester getEndOfDayStrategyBackTester() --- 182,186 ---- oversoldThresholdMAX , overboughtThresholdMAX , historicalQuoteProvider, maxAcceptableDrawDown, minimumAcceptableGain ); ! return strategyForBacktester; } protected override EndOfDayStrategyBackTester getEndOfDayStrategyBackTester() *************** *** 197,201 **** DateTime lastDateTime = new DateTime( 2004 , 12, 31 ); double maxRunningHours = 8; ! HistoricalQuoteProvider quoteProviderForBackTester = this.historicalQuoteProvider; quoteProviderForBackTester = --- 197,201 ---- DateTime lastDateTime = new DateTime( 2004 , 12, 31 ); double maxRunningHours = 8; ! HistoricalMarketValueProvider quoteProviderForBackTester = this.historicalQuoteProvider; quoteProviderForBackTester = *************** *** 203,207 **** EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.endOfDayStrategy , quoteProviderForBackTester , accountProvider , firstDateTime , lastDateTime , --- 203,207 ---- EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.strategyForBacktester , quoteProviderForBackTester , accountProvider , firstDateTime , lastDateTime , Index: PVOPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOPositions.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PVOPositions.cs 14 Aug 2008 23:28:06 -0000 1.3 --- PVOPositions.cs 29 Sep 2008 21:18:13 -0000 1.4 *************** *** 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; *************** *** 34,67 **** namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { ! /// <summary> ! /// This is the class representing a TestingPositions for the ! /// portfolio value oscillator strategy ! /// </summary> ! [Serializable] ! public class PVOPositions : TestingPositions, IGeneticallyOptimizable ! { ! private double oversoldThreshold; ! private double overboughtThreshold; ! private int numDaysForOscillatingPeriod; ! private int generation; ! private static ReturnsManager returnsManager; ! ! public double OversoldThreshold ! { ! get{return this.oversoldThreshold;} set{this.oversoldThreshold = value;} ! } ! public double OverboughtThreshold ! { ! get{return this.overboughtThreshold;} set{this.overboughtThreshold = value;} ! } ! public int NumDaysForOscillatingPeriod ! { ! get{return this.numDaysForOscillatingPeriod;} ! } ! //explicit interface implementation //the property can be used only by a interface --- 34,67 ---- namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { ! /// <summary> ! /// This is the class representing a TestingPositions for the ! /// portfolio value oscillator strategy ! /// </summary> ! [Serializable] ! public class PVOPositions : TestingPositions, IGeneticallyOptimizable ! { ! private double oversoldThreshold; ! private double overboughtThreshold; ! private int numDaysForOscillatingPeriod; ! private int generation; ! private static ReturnsManager returnsManager; ! ! public double OversoldThreshold ! { ! get{return this.oversoldThreshold;} set{this.oversoldThreshold = value;} ! } ! public double OverboughtThreshold ! { ! get{return this.overboughtThreshold;} set{this.overboughtThreshold = value;} ! } ! public int NumDaysForOscillatingPeriod ! { ! get{return this.numDaysForOscillatingPeriod;} ! } ! //explicit interface implementation //the property can be used only by a interface *************** *** 77,82 **** return new PVOPositions(this.WeightedPositions, this.OversoldThreshold, ! this.overboughtThreshold, ! this.numDaysForOscillatingPeriod); } --- 77,82 ---- return new PVOPositions(this.WeightedPositions, this.OversoldThreshold, ! this.overboughtThreshold, ! this.numDaysForOscillatingPeriod); } *************** *** 88,158 **** public PVOPositions(WeightedPositions weightedPositions, ! double oversoldThreshold, ! double overboughtThreshold, ! int numDaysForOscillatingPeriod) : ! base(weightedPositions) ! ! { ! this.oversoldThreshold = oversoldThreshold; ! this.overboughtThreshold = overboughtThreshold; ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.generation = -1; } ! private void setReturnsManager(EndOfDayDateTime beginOfPeriod, ! EndOfDayDateTime endOfPeriod, ! string benchmark, ! HistoricalQuoteProvider quoteProvider) { if(PVOPositions.returnsManager == null || PVOPositions.returnsManager.ReturnIntervals[0].Begin != beginOfPeriod || ! PVOPositions.returnsManager.ReturnIntervals[0].End != endOfPeriod) ! //if a returnsManager has not been set yet or a different one has to be set ! //for a different returnInterval ! PVOPositions.returnsManager = new ReturnsManager(new ReturnIntervals( ! new ReturnInterval( beginOfPeriod, endOfPeriod ) ) , ! quoteProvider ); } ! private double getOscillatingPeriodReturn(EndOfDayDateTime beginOfPeriod, ! EndOfDayDateTime endOfPeriod, ! string benchmark, ! HistoricalQuoteProvider quoteProvider) ! { ! this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); return this.WeightedPositions.GetReturn(0, PVOPositions.returnsManager); ! } ! public PVOPositionsStatus GetStatus(EndOfDayDateTime beginOfPeriod, ! EndOfDayDateTime endOfPeriod, string benchmark, ! HistoricalQuoteProvider quoteProvider, ! double maxOversoldThreshold, double maxOverboughtThreshold) ! { ! PVOPositionsStatus returnValue; double oscillatingPeriodReturn = double.NaN; ! oscillatingPeriodReturn = ! this.getOscillatingPeriodReturn(beginOfPeriod, endOfPeriod, benchmark, ! quoteProvider); ! if(oscillatingPeriodReturn >= this.overboughtThreshold && ! oscillatingPeriodReturn <= maxOverboughtThreshold) ! returnValue = PVOPositionsStatus.Overbought; ! else if(oscillatingPeriodReturn <= -this.oversoldThreshold && ! Math.Abs(oscillatingPeriodReturn) <= maxOversoldThreshold) ! returnValue = PVOPositionsStatus.Oversold; ! else if ( Math.Abs(oscillatingPeriodReturn) > maxOversoldThreshold || ! oscillatingPeriodReturn > maxOverboughtThreshold ) ! returnValue = PVOPositionsStatus.OverMaximumThresholds; ! else ! returnValue = PVOPositionsStatus.InTheMiddle; ! return returnValue; ! } ! public bool AreAllTickersMovingTogetherUpOrDown(EndOfDayDateTime beginOfPeriod, ! EndOfDayDateTime endOfPeriod, ! string benchmark, ! HistoricalQuoteProvider quoteProvider) { bool returnValue = true; --- 88,158 ---- public PVOPositions(WeightedPositions weightedPositions, ! double oversoldThreshold, ! double overboughtThreshold, ! int numDaysForOscillatingPeriod) : ! base(weightedPositions) ! ! { ! this.oversoldThreshold = oversoldThreshold; ! this.overboughtThreshold = overboughtThreshold; ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.generation = -1; } ! private void setReturnsManager(DateTime beginOfPeriod, ! DateTime endOfPeriod, ! string benchmark, ! HistoricalMarketValueProvider quoteProvider) { if(PVOPositions.returnsManager == null || PVOPositions.returnsManager.ReturnIntervals[0].Begin != beginOfPeriod || ! PVOPositions.returnsManager.ReturnIntervals[0].End != endOfPeriod) ! //if a returnsManager has not been set yet or a different one has to be set ! //for a different returnInterval ! PVOPositions.returnsManager = new ReturnsManager(new ReturnIntervals( ! new ReturnInterval( beginOfPeriod, endOfPeriod ) ) , ! quoteProvider ); } ! private double getOscillatingPeriodReturn(DateTime beginOfPeriod, ! DateTime endOfPeriod, ! string benchmark, ! HistoricalMarketValueProvider quoteProvider) ! { ! this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); return this.WeightedPositions.GetReturn(0, PVOPositions.returnsManager); ! } ! public PVOPositionsStatus GetStatus(DateTime beginOfPeriod, ! DateTime endOfPeriod, string benchmark, ! HistoricalMarketValueProvider quoteProvider, ! double maxOversoldThreshold, double maxOverboughtThreshold) ! { ! PVOPositionsStatus returnValue; double oscillatingPeriodReturn = double.NaN; ! oscillatingPeriodReturn = ! this.getOscillatingPeriodReturn(beginOfPeriod, endOfPeriod, benchmark, ! quoteProvider); ! if(oscillatingPeriodReturn >= this.overboughtThreshold && ! oscillatingPeriodReturn <= maxOverboughtThreshold) ! returnValue = PVOPositionsStatus.Overbought; ! else if(oscillatingPeriodReturn <= -this.oversoldThreshold && ! Math.Abs(oscillatingPeriodReturn) <= maxOversoldThreshold) ! returnValue = PVOPositionsStatus.Oversold; ! else if ( Math.Abs(oscillatingPeriodReturn) > maxOversoldThreshold || ! oscillatingPeriodReturn > maxOverboughtThreshold ) ! returnValue = PVOPositionsStatus.OverMaximumThresholds; ! else ! returnValue = PVOPositionsStatus.InTheMiddle; ! return returnValue; ! } ! public bool AreAllTickersMovingTogetherUpOrDown(DateTime beginOfPeriod, ! DateTime endOfPeriod, ! string benchmark, ! HistoricalMarketValueProvider quoteProvider) { bool returnValue = true; *************** *** 161,176 **** this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); for( int i = 0; ! signedTickers.Count > 1 && i < signedTickers.Count - 1 && returnValue == true; ! i++ ) { returnOfCurrentTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i ].Ticker, 0); returnOfNextTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i+1 ].Ticker, 0); if( (returnOfCurrentTicker > 0 && returnOfNextTicker < 0) || ! (returnOfCurrentTicker < 0 && returnOfNextTicker > 0) ) returnValue = false; ! } return returnValue; } ! } } --- 161,176 ---- this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); for( int i = 0; ! signedTickers.Count > 1 && i < signedTickers.Count - 1 && returnValue == true; ! i++ ) { returnOfCurrentTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i ].Ticker, 0); returnOfNextTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i+1 ].Ticker, 0); if( (returnOfCurrentTicker > 0 && returnOfNextTicker < 0) || ! (returnOfCurrentTicker < 0 && returnOfNextTicker > 0) ) returnValue = false; ! } return returnValue; } ! } } Index: PVO_OTCStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCStrategy.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PVO_OTCStrategy.cs 19 Aug 2008 17:13:00 -0000 1.6 --- PVO_OTCStrategy.cs 29 Sep 2008 21:18:13 -0000 1.7 *************** *** 25,28 **** --- 25,29 ---- using QuantProject.ADT; + using QuantProject.ADT.Histories; using QuantProject.ADT.Messaging; using QuantProject.Business.Financial.Accounting; *************** *** 57,61 **** /// </summary> [Serializable] ! public class PVO_OTCStrategy : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; --- 58,64 ---- /// </summary> [Serializable] ! public class PVO_OTCStrategy : ! QuantProject.Business.Strategies.EndOfDayTimerHandler , ! IStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; *************** *** 68,72 **** protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalQuoteProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; --- 71,75 ---- protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalMarketValueProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; *************** *** 136,140 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider) { this.numOfClosingsWithOpenPositions = 0; --- 139,143 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider) { this.numOfClosingsWithOpenPositions = 0; *************** *** 165,169 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 168,172 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 185,189 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 188,192 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 206,210 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 209,213 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 226,230 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 229,233 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 239,254 **** ! #region MarketOpenEventHandler ! protected virtual EndOfDayDateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], ! EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! EndOfDayDateTime today = timer.GetCurrentTime(); ! EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = --- 242,261 ---- ! #region marketOpenEventHandler ! protected virtual DateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! DateTime beginOfOscillatingPeriod = ! HistoricalEndOfDayTimer.GetMarketClose( ! (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"] ); ! return beginOfOscillatingPeriod; ! // return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], ! // EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentDateTime(); ! DateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = *************** *** 318,323 **** } ! public virtual void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Portfolio.Count == 0 && --- 325,330 ---- } ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if ( this.account.Portfolio.Count == 0 && *************** *** 340,355 **** public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } ! private EndOfDayDateTime now() { ! return this.account.EndOfDayTimer.GetCurrentTime(); } ! public virtual void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) --- 347,362 ---- public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { } ! private DateTime now() { ! return this.account.Timer.GetCurrentDateTime(); } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.account.Portfolio.Count > 0) *************** *** 364,374 **** } ! #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime) { ReturnIntervals returnIntervals = ! new DailyOpenToCloseIntervals( firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ); if( this.inSampleChooser is PVOCorrelationChooser ) --- 371,381 ---- } ! #region oneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(DateTime firstDateTime, ! DateTime lastDayDateTime) { ReturnIntervals returnIntervals = ! new DailyOpenToCloseIntervals( firstDateTime, lastDayDateTime, this.benchmark.Ticker ); if( this.inSampleChooser is PVOCorrelationChooser ) *************** *** 377,402 **** { case IntervalsType.CloseToCloseIntervals: ! returnIntervals = new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.OpenToOpenIntervals: ! returnIntervals = new OpenToOpenIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.CloseToOpenIntervals: ! returnIntervals = new CloseToOpenIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker); break; case IntervalsType.OpenToCloseIntervals: ! returnIntervals = new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ); break; case IntervalsType.OpenToCloseCloseToOpenIntervals: returnIntervals = new OpenToCloseCloseToOpenIntervals( ! firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker); break; default: // it should never be reached ! returnIntervals = new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ); break; --- 384,409 ---- { case IntervalsType.CloseToCloseIntervals: ! returnIntervals = new CloseToCloseIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.OpenToOpenIntervals: ! returnIntervals = new OpenToOpenIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.CloseToOpenIntervals: ! returnIntervals = new CloseToOpenIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker); break; case IntervalsType.OpenToCloseIntervals: ! returnIntervals = new DailyOpenToCloseIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker ); break; case IntervalsType.OpenToCloseCloseToOpenIntervals: returnIntervals = new OpenToCloseCloseToOpenIntervals( ! firstDateTime, lastDayDateTime, this.benchmark.Ticker); break; default: // it should never be reached ! returnIntervals = new DailyOpenToCloseIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker ); break; *************** *** 505,518 **** protected virtual void updateTestingPositions(DateTime currentDate) { ! EndOfDayHistory endOfDayHistory = this.benchmark.GetEndOfDayHistory( ! new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! EndOfDaySpecificTime.MarketOpen), ! new EndOfDayDateTime(currentDate, ! EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = ! this.eligiblesSelector.GetEligibleTickers(endOfDayHistory); ! this.updateReturnsManager(endOfDayHistory.FirstEndOfDayDateTime, ! endOfDayHistory.LastEndOfDayDateTime); if( ( this.eligiblesSelector is DummyEligibleSelector && this.inSampleChooser != null ) || --- 512,529 ---- protected virtual void updateTestingPositions(DateTime currentDate) { ! History history = this.benchmark.GetEndOfDayHistory( ! HistoricalEndOfDayTimer.GetMarketOpen( ! currentDate.AddDays( -this.inSampleDays ) ) , ! HistoricalEndOfDayTimer.GetMarketClose( ! currentDate ) ); ! // new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! // EndOfDaySpecificTime.MarketOpen), ! // new EndOfDayDateTime(currentDate, ! // EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = ! this.eligiblesSelector.GetEligibleTickers(history); ! this.updateReturnsManager(history.FirstDateTime, ! history.LastDateTime); if( ( this.eligiblesSelector is DummyEligibleSelector && this.inSampleChooser != null ) || *************** *** 542,546 **** ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ! ( this.now().DateTime >= dateTimeForNextOptimization ) ); } return areToBeUpdated; --- 553,557 ---- ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ! ( this.now() >= dateTimeForNextOptimization ) ); } return areToBeUpdated; *************** *** 552,559 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public virtual void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.numDaysElapsedSinceLastOptimization++; //OLD - numDaysBetweenEachOptimization --> market days --- 563,570 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! this.lastCloseDate = dateTime; this.numDaysElapsedSinceLastOptimization++; //OLD - numDaysBetweenEachOptimization --> market days *************** *** 566,576 **** if ( this.optimalTestingPositionsAreToBeUpdated() ) { ! this.updateTestingPositions(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; ! this.lastOptimizationDateTime = this.now().DateTime; } } #endregion } } --- 577,598 ---- if ( this.optimalTestingPositionsAreToBeUpdated() ) { ! this.updateTestingPositions(dateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; ! this.lastOptimizationDateTime = this.now(); } } #endregion + + // public virtual void NewDateTimeEventHandler( + // Object sender , DateTime dateTime ) + // { + // if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + // this.marketOpenEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + // this.marketCloseEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + // this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + // } } } Index: PVOLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOLogItem.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PVOLogItem.cs 14 Aug 2008 23:28:06 -0000 1.4 --- PVOLogItem.cs 29 Sep 2008 21:18:13 -0000 1.5 *************** *** 140,146 **** } ! public PVOLogItem(EndOfDayDateTime endOfDayDateTime, int numberOfInSampleDays) ! : base( endOfDayDateTime ) { this.numberOfInSampleDays = numberOfInSampleDays; --- 140,146 ---- } ! public PVOLogItem(DateTime dateTime, int numberOfInSampleDays) ! : base( dateTime ) { this.numberOfInSampleDays = numberOfInSampleDays; *************** *** 153,158 **** { //general ! DateTime firstDateTime = this.SimulatedCreationTime.DateTime.AddDays(-this.numberOfInSampleDays); ! DateTime lastDateTime = this.SimulatedCreationTime.DateTime; double maxRunningHours = 1; Benchmark benchmark = new Benchmark( "^GSPC" ); --- 153,158 ---- { //general ! DateTime firstDateTime = this.SimulatedCreationDateTime.AddDays(-this.numberOfInSampleDays); ! DateTime lastDateTime = this.SimulatedCreationDateTime; double maxRunningHours = 1; Benchmark benchmark = new Benchmark( "^GSPC" ); *************** *** 167,171 **** double maxAcceptableCloseToCloseDrawdown = 0.02; double minimumAcceptableGain = 0.007; ! HistoricalQuoteProvider historicalQuoteProviderForBackTester, historicalQuoteProviderForInSampleChooser, historicalQuoteProviderForStrategy; --- 167,171 ---- double maxAcceptableCloseToCloseDrawdown = 0.02; double minimumAcceptableGain = 0.007; ! HistoricalMarketValueProvider historicalQuoteProviderForBackTester, historicalQuoteProviderForInSampleChooser, historicalQuoteProviderForStrategy; *************** *** 211,215 **** int currentIndex , TestingPositions testingPositions , ! EndOfDayDateTime simulatedCreationTime ) { this.dummyTestersForBestTestingPositionsInSample[ currentIndex ] = --- 211,215 ---- int currentIndex , TestingPositions testingPositions , ! DateTime simulatedCreationDateTime ) { this.dummyTestersForBestTestingPositionsInSample[ currentIndex ] = *************** *** 217,221 **** testingPositions , this.numberOfInSampleDays , ! simulatedCreationTime ); } --- 217,221 ---- testingPositions , this.numberOfInSampleDays , ! simulatedCreationDateTime ); } *************** *** 228,232 **** i , BestPVOPositionsInSample[ i ] , ! this.SimulatedCreationTime ); } --- 228,232 ---- i , BestPVOPositionsInSample[ i ] , ! this.SimulatedCreationDateTime ); } Index: PVO_OTCStrategyLessCorrelated.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCStrategyLessCorrelated.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PVO_OTCStrategyLessCorrelated.cs 19 Aug 2008 17:13:00 -0000 1.3 --- PVO_OTCStrategyLessCorrelated.cs 29 Sep 2008 21:18:13 -0000 1.4 *************** *** 25,29 **** --- 25,31 ---- using QuantProject.ADT; + using QuantProject.ADT.Histories; using QuantProject.ADT.Messaging; + using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; *************** *** 44,48 **** using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; - using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; --- 46,49 ---- *************** *** 56,60 **** /// </summary> [Serializable] ! public class PVO_OTCStrategyLessCorrelated : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; --- 57,61 ---- /// </summary> [Serializable] ! public class PVO_OTCStrategyLessCorrelated : IStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; *************** *** 67,71 **** protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalQuoteProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; --- 68,72 ---- protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalMarketValueProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; *************** *** 125,129 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { this.eligiblesSelector = eligiblesSelector; --- 126,130 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { this.eligiblesSelector = eligiblesSelector; *************** *** 143,147 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 144,148 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 159,163 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 160,164 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 169,182 **** #region MarketOpenEventHandler ! protected virtual EndOfDayDateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], ! EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! EndOfDayDateTime today = timer.GetCurrentTime(); ! EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = --- 170,188 ---- #region MarketOpenEventHandler ! protected virtual DateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! DateTime beginOfOscillatingPeriod = ! HistoricalEndOfDayTimer.GetMarketClose( ! (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"] ); ! return beginOfOscillatingPeriod; ! // ! // return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], ! // EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentDateTime(); ! DateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = *************** *** 246,251 **** } ! public virtual void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Portfolio.Count == 0 && --- 252,257 ---- } ! private void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if ( this.account.Portfolio.Count == 0 && *************** *** 266,282 **** #endregion ! public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } ! private EndOfDayDateTime now() { ! return this.account.EndOfDayTimer.GetCurrentTime(); } ! public virtual void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) --- 272,288 ---- #endregion ! private void fiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { } ! private DateTime now() { ! return this.account.Timer.GetCurrentDateTime(); } ! private void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.account.Portfolio.Count > 0) *************** *** 286,294 **** #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime) { this.returnsManager = ! new ReturnsManager( new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ) , this.historicalQuoteProvider); --- 292,300 ---- #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(DateTime firstDateTime, ! DateTime lastDateTime) { this.returnsManager = ! new ReturnsManager( new DailyOpenToCloseIntervals(firstDateTime, lastDateTime, this.benchmark.Ticker ) , this.historicalQuoteProvider); *************** *** 373,386 **** protected virtual void updateTestingPositions(DateTime currentDate) { ! EndOfDayHistory endOfDayHistory = this.benchmark.GetEndOfDayHistory( ! new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! EndOfDaySpecificTime.MarketOpen), ! new EndOfDayDateTime(currentDate, ! EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = ! this.eligiblesSelector.GetEligibleTickers(endOfDayHistory); ! this.updateReturnsManager(endOfDayHistory.FirstEndOfDayDateTime, ! endOfDayHistory.LastEndOfDayDateTime); if(this.inSampleChooser != null) this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager); --- 379,395 ---- protected virtual void updateTestingPositions(DateTime currentDate) { ! History history = this.benchmark.GetEndOfDayHistory( ! HistoricalEndOfDayTimer.GetMarketOpen( ! currentDate.AddDays(-this.inSampleDays) ) , ! HistoricalEndOfDayTimer.GetMarketClose( currentDate ) ); ! // new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! // EndOfDaySpecificTime.MarketOpen), ! // new EndOfDayDateTime(currentDate, ! // EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = ! this.eligiblesSelector.GetEligibleTickers(history); ! this.updateReturnsManager(history.FirstDateTime, ! history.LastDateTime); if(this.inSampleChooser != null) this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager); *************** *** 401,405 **** ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ! ( this.now().DateTime >= dateTimeForNextOptimization ) ); } return areToBeUpdated; --- 410,414 ---- ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ! ( this.now() >= dateTimeForNextOptimization ) ); } return areToBeUpdated; *************** *** 411,418 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public virtual void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.numDaysElapsedSinceLastOptimization++; //OLD - numDaysBetweenEachOptimization --> market days --- 420,427 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! private void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! this.lastCloseDate = dateTime; this.numDaysElapsedSinceLastOptimization++; //OLD - numDaysBetweenEachOptimization --> market days *************** *** 425,435 **** if ( this.optimalTestingPositionsAreToBeUpdated() ) { ! this.updateTestingPositions(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; ! this.lastOptimizationDateTime = this.now().DateTime; } } #endregion } } --- 434,455 ---- if ( this.optimalTestingPositionsAreToBeUpdated() ) { ! this.updateTestingPositions(dateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; ! this.lastOptimizationDateTime = this.now(); } } #endregion + + public virtual void NewDateTimeEventHandler( + Object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + this.marketOpenEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + this.marketCloseEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + } } } |