[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:31
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16791/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVOStrategy.cs RunPVO.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: PVOStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOStrategy.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PVOStrategy.cs 19 Aug 2008 17:13:01 -0000 1.6 --- PVOStrategy.cs 29 Sep 2008 21:18:34 -0000 1.7 *************** *** 25,28 **** --- 25,29 ---- using QuantProject.ADT; + using QuantProject.ADT.Histories; using QuantProject.ADT.Messaging; using QuantProject.Business.Financial.Accounting; *************** *** 56,60 **** /// </summary> [Serializable] ! public class PVOStrategy : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; --- 57,61 ---- /// </summary> [Serializable] ! public class PVOStrategy : IStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; *************** *** 68,72 **** protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalQuoteProvider historicalQuoteProvider; protected double maxAcceptableCloseToCloseDrawdown; protected double minimumAcceptableGain; --- 69,73 ---- protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalMarketValueProvider historicalQuoteProvider; protected double maxAcceptableCloseToCloseDrawdown; protected double minimumAcceptableGain; *************** *** 137,141 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 138,142 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 172,176 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 173,177 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 195,199 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 196,200 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 220,224 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 221,225 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 243,247 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 244,248 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 257,282 **** } ! public virtual void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } ! public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } ! private EndOfDayDateTime now() { ! return this.account.EndOfDayTimer.GetCurrentTime(); } #region MarketCloseEventHandler //forOutOfSampleTesting ! protected virtual EndOfDayDateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-this.numDaysForOscillatingPeriod]["quDate"], ! EndOfDaySpecificTime.MarketClose ); } --- 258,288 ---- } ! private void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { ; } ! private void fiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { } ! private DateTime now() { ! return this.account.Timer.GetCurrentDateTime(); } #region MarketCloseEventHandler //forOutOfSampleTesting ! protected virtual DateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! DateTime beginOfOscillatingPeriod = ! HistoricalEndOfDayTimer.GetMarketOpen( ! (DateTime)timer.IndexQuotes.Rows[ ! timer.CurrentDateArrayPosition-this.numDaysForOscillatingPeriod]["quDate"] ); ! return beginOfOscillatingPeriod; ! // return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-this.numDaysForOscillatingPeriod]["quDate"], ! // EndOfDaySpecificTime.MarketClose ); } *************** *** 299,304 **** private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) { ! EndOfDayDateTime today = timer.GetCurrentTime(); ! EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus pvoPositionsStatus = this.pvoPositionsForOutOfSample.GetStatus(beginOfOscillatingPeriod, today , this.benchmark.Ticker, this.historicalQuoteProvider, --- 305,310 ---- private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentDateTime(); ! DateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus pvoPositionsStatus = this.pvoPositionsForOutOfSample.GetStatus(beginOfOscillatingPeriod, today , this.benchmark.Ticker, this.historicalQuoteProvider, *************** *** 318,323 **** private PVOPositionsStatus marketCloseEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! EndOfDayDateTime today = timer.GetCurrentTime(); ! EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = --- 324,329 ---- private PVOPositionsStatus marketCloseEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentDateTime(); ! DateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = *************** *** 431,436 **** } ! public virtual void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { try{ --- 437,442 ---- } ! private void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { try{ *************** *** 458,466 **** #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime) { this.returnsManager = ! new ReturnsManager(new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker, this.numDaysForOscillatingPeriod), this.historicalQuoteProvider); --- 464,472 ---- #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(DateTime firstDateTime, ! DateTime lastDateTime) { this.returnsManager = ! new ReturnsManager(new CloseToCloseIntervals(firstDateTime, lastDateTime, this.benchmark.Ticker, this.numDaysForOscillatingPeriod), this.historicalQuoteProvider); *************** *** 530,543 **** protected virtual void updateTestingPositions(DateTime currentDate) { ! EndOfDayHistory endOfDayHistory = this.benchmark.GetEndOfDayHistory( ! new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! EndOfDaySpecificTime.MarketClose), ! 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 ); --- 536,552 ---- protected virtual void updateTestingPositions(DateTime currentDate) { ! History history = this.benchmark.GetEndOfDayHistory( ! HistoricalEndOfDayTimer.GetMarketClose( ! currentDate.AddDays( -this.inSampleDays ) ) , ! HistoricalEndOfDayTimer.GetMarketClose( currentDate ) ); ! // new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! // EndOfDaySpecificTime.MarketClose), ! // 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 ); *************** *** 551,558 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public virtual void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.numDaysElapsedSinceLastOptimization++; if((this.numDaysElapsedSinceLastOptimization == --- 560,567 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! private void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! this.lastCloseDate = dateTime; this.numDaysElapsedSinceLastOptimization++; if((this.numDaysElapsedSinceLastOptimization == *************** *** 560,564 **** //num days without optimization has elapsed { ! this.updateTestingPositions(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; --- 569,573 ---- //num days without optimization has elapsed { ! this.updateTestingPositions(dateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; *************** *** 567,570 **** --- 576,591 ---- } #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: RunPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/RunPVO.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RunPVO.cs 19 Aug 2008 17:13:01 -0000 1.6 --- RunPVO.cs 29 Sep 2008 21:18:34 -0000 1.7 *************** *** 128,151 **** protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { ! this.endOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( ! this.endOfDayTimerHandler.MarketOpenEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.endOfDayTimerHandler.MarketCloseEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); } --- 128,156 ---- protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.checkDateForReport ); ! ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( ! // this.endOfDayTimerHandler.MarketOpenEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.endOfDayTimerHandler.MarketCloseEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); ! // ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); } *************** *** 181,185 **** //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); --- 186,190 ---- //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentDateTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); |