[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting RunEfficientPortfolio.cs,
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:25
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17551 Modified Files: RunEfficientPortfolio.cs RunLastChosenPortfolioOutOfSample.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: RunEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientPortfolio.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** RunEfficientPortfolio.cs 19 Aug 2008 17:13:06 -0000 1.22 --- RunEfficientPortfolio.cs 29 Sep 2008 21:19:35 -0000 1.23 *************** *** 62,69 **** protected ReportTable reportTable; ! protected EndOfDayDateTime startDateTime; ! protected EndOfDayDateTime endDateTime; //protected int numIntervalDays;// number of days for the equity line graph ! protected IHistoricalQuoteProvider historicalQuoteProvider; --- 62,69 ---- protected ReportTable reportTable; ! protected DateTime startDateTime; ! protected DateTime endDateTime; //protected int numIntervalDays;// number of days for the equity line graph ! protected HistoricalMarketValueProvider historicalMarketValueProvider; *************** *** 74,78 **** protected Account account; ! protected IEndOfDayTimer endOfDayTimer; protected string benchmark; --- 74,78 ---- protected Account account; ! protected QuantProject.Business.Timing.Timer endOfDayTimer; protected string benchmark; *************** *** 103,107 **** public DateTime TimerLastDate { ! get{return this.endOfDayTimer.GetCurrentTime().DateTime ;} } --- 103,107 ---- public DateTime TimerLastDate { ! get{return this.endOfDayTimer.GetCurrentDateTime() ;} } *************** *** 112,119 **** { ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "EfficientGeneric"; --- 112,123 ---- { ! this.startDateTime = ! HistoricalEndOfDayTimer.GetFiveMinutesBeforeMarketClose( startDate ); ! // new EndOfDayDateTime( ! // startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( endDate ); ! // new EndOfDayDateTime( ! // endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "EfficientGeneric"; *************** *** 141,148 **** this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.reportTable = new ReportTable( "Summary_Reports" ); ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "EfficientGeneric"; --- 145,156 ---- this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.reportTable = new ReportTable( "Summary_Reports" ); ! this.startDateTime = ! HistoricalEndOfDayTimer.GetFiveMinutesBeforeMarketClose( startDate ); ! // new EndOfDayDateTime( ! // startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( endDate ); ! // new EndOfDayDateTime( ! // endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "EfficientGeneric"; *************** *** 181,187 **** this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider )); } --- 189,195 ---- this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider )); } *************** *** 202,212 **** } ! protected virtual void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.SaveScriptResults(); } --- 210,224 ---- } ! protected virtual void checkDateForReport( ! Object sender , DateTime dateTime) { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! { ! if( dateTime >= this.endDateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.SaveScriptResults(); ! } } *************** *** 239,243 **** //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); --- 251,255 ---- //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentDateTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); *************** *** 273,279 **** protected virtual void run_addEventHandlers() { ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); //in inherited classes'override method: --- 285,294 ---- protected virtual void run_addEventHandlers() { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.checkDateForReport ); ! ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); //in inherited classes'override method: Index: RunLastChosenPortfolioOutOfSample.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunLastChosenPortfolioOutOfSample.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunLastChosenPortfolioOutOfSample.cs 27 Jul 2005 22:30:56 -0000 1.3 --- RunLastChosenPortfolioOutOfSample.cs 29 Sep 2008 21:19:35 -0000 1.4 *************** *** 3,7 **** RunLastChosenPortfolioOutOfSample.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunLastChosenPortfolioOutOfSample.cs ! Copyright (C) 2003 Marco Milletti *************** *** 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; *************** *** 40,44 **** using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 40,44 ---- using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 56,161 **** private string[] tickers; private PortfolioType typeOfPortfolio; ! public RunLastChosenPortfolioOutOfSample(string[] chosenTickers, ! PortfolioType typeOfPortfolio, string benchmark, ! DateTime startDate, ! DateTime endDate, ! double maxRunningHours): ! base(benchmark, ! startDate, ! endDate, ! typeOfPortfolio, ! maxRunningHours) { ! this.tickers = chosenTickers; ! this.typeOfPortfolio = typeOfPortfolio; ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.MarketOpen ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.MarketClose ); ! this.ScriptName = "LastChosenPortfolioOutOfSample"; ! } - #region Run - - protected override void run_initializeEndOfDayTimerHandler() - { - this.endOfDayTimerHandler = - new EndOfDayTimerHandlerLastChosenPortfolio(this.tickers, - this.typeOfPortfolio, - this.account, - this.benchmark, - this.startDateTime, - this.endDateTime); - } - - protected override void run_initializeEndOfDayTimer() - { - this.endOfDayTimer = - new HistoricalEndOfDayTimer(this.startDateTime); - } - - protected override void run_initializeHistoricalQuoteProvider() - { - this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); - - } - protected override void run_initializeAccount() - { - //default account with no commissions - this.account = new Account( this.scriptName , this.endOfDayTimer , - new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , - this.historicalQuoteProvider ) , - new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , - this.historicalQuoteProvider )); - - } - - 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 ); - - } - - - public override void Run() - { - base.Run(); - Report report = new Report( this.account , this.historicalQuoteProvider ); - report.Create( "Run last chosen tickers out of sample", 1 , - new EndOfDayDateTime( this.endDateTime.DateTime , - EndOfDaySpecificTime.MarketClose ) , - "^SPX" ); - report.Show(); - } - - protected override void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) - { - if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || - DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) - //last date is reached by the timer or maxRunning hours - //are elapsed from the time script started - { - this.endOfDayTimer.Stop(); - } ! } ! ! #endregion ! } } --- 56,191 ---- private string[] tickers; private PortfolioType typeOfPortfolio; ! public RunLastChosenPortfolioOutOfSample(string[] chosenTickers, ! PortfolioType typeOfPortfolio, string benchmark, ! DateTime startDate, ! DateTime endDate, ! double maxRunningHours): ! base(benchmark, ! startDate, ! endDate, ! typeOfPortfolio, ! maxRunningHours) { ! this.tickers = chosenTickers; ! this.typeOfPortfolio = typeOfPortfolio; ! this.startDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( startDate ); ! // new EndOfDayDateTime( ! // startDate, EndOfDaySpecificTime.MarketOpen ); ! this.endDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( endDate ); ! // new EndOfDayDateTime( ! // endDate, EndOfDaySpecificTime.MarketClose ); ! this.ScriptName = "LastChosenPortfolioOutOfSample"; ! ! } ! #region Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = ! new EndOfDayTimerHandlerLastChosenPortfolio(this.tickers, ! this.typeOfPortfolio, ! this.account, ! this.benchmark, ! this.startDateTime, ! this.endDateTime); ! } ! ! protected override void run_initializeEndOfDayTimer() ! { ! this.endOfDayTimer = ! new HistoricalEndOfDayTimer(this.startDateTime); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); ! ! } ! protected override void run_initializeAccount() ! { ! //default account with no commissions ! this.account = new Account( this.scriptName , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider )); ! ! } ! ! private void newDateTimeEventHandler( object sender , DateTime dateTime ) ! { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! this.checkDateForReport( sender , dateTime ); } ! protected override void run_addEventHandlers() ! { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! ! // 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 ); ! ! } ! ! ! public override void Run() ! { ! base.Run(); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "Run last chosen tickers out of sample", 1 , ! HistoricalEndOfDayTimer.GetMarketClose( this.endDateTime ) , ! // new EndOfDayDateTime( this.endDateTime.DateTime , ! // EndOfDaySpecificTime.MarketClose ) , ! "^SPX" ); ! report.Show(); ! } ! ! // protected override void checkDateForReport( ! // Object sender , DateTime dateTime) ! // { ! // if(dateTime.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! // DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! // //last date is reached by the timer or maxRunning hours ! // //are elapsed from the time script started ! // { ! // this.endOfDayTimer.Stop(); ! // } ! // ! // } ! ! protected override void checkDateForReport( ! Object sender , DateTime dateTime) ! { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! { ! if( dateTime >= this.endDateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.endOfDayTimer.Stop(); ! } ! } ! #endregion ! } } |