[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection RunSimple
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-08-19 17:13:46
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3611/b7_Scripts/TickerSelectionTesting/SimpleSelection Modified Files: RunSimpleSelection.cs RunSimpleSelectionOpenToClose.cs Log Message: - the code has been cleaned up to avoid warnings - standard indentation has been applied Index: RunSimpleSelectionOpenToClose.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection/RunSimpleSelectionOpenToClose.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunSimpleSelectionOpenToClose.cs 14 May 2006 18:21:47 -0000 1.2 --- RunSimpleSelectionOpenToClose.cs 19 Aug 2008 17:13:10 -0000 1.3 *************** *** 128,134 **** "Target" + Convert.ToString(this.targetReturn) + Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; --- 128,136 ---- "Target" + Convert.ToString(this.targetReturn) + Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = ! System.Configuration.ConfigurationManager.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; Index: RunSimpleSelection.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection/RunSimpleSelection.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunSimpleSelection.cs 29 Aug 2007 10:04:30 -0000 1.2 --- RunSimpleSelection.cs 19 Aug 2008 17:13:10 -0000 1.3 *************** *** 3,7 **** RunSimpleSelection.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunSimpleSelection.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; *************** *** 39,43 **** using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 39,43 ---- using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 47,255 **** { /// <summary> ! /// Base class for simple selection test /// The strategy simply chooses the tickers with the highest fitness, /// for short or long trading /// </summary> [Serializable] ! public class RunSimpleSelection { ! protected string tickerGroupID; ! protected int numberOfEligibleTickers; ! protected int numberOfTickersToBeChosen; ! protected int numDaysForOptimizationPeriod; ! protected ReportTable reportTable; ! protected EndOfDayDateTime startDateTime; ! protected EndOfDayDateTime endDateTime; protected IHistoricalQuoteProvider historicalQuoteProvider; ! protected EndOfDayTimerHandlerSimpleSelection endOfDayTimerHandler; ! protected Account account; ! protected IEndOfDayTimer endOfDayTimer; ! protected string benchmark; ! ! protected string scriptName; ! ! protected double targetReturn; ! ! protected PortfolioType portfolioType; ! ! protected DateTime startingTimeForScript; ! protected double maxRunningHours; ! //if MaxNumberOfHoursForScript has elapsed and the script ! //is still running, it will be stopped. ! ! public PortfolioType TypeOfPortfolio ! { ! get { return this.portfolioType; } ! } ! ! public virtual string ScriptName ! { ! get{return this.scriptName;} ! set{this.scriptName = value;} ! } ! ! public DateTime TimerLastDate ! { ! get{return this.endOfDayTimer.GetCurrentTime().DateTime ;} ! } ! public RunSimpleSelection(string benchmark, ! DateTime startDate, DateTime endDate, ! PortfolioType portfolioType, ! double maxRunningHours) { ! ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); ! this.benchmark = benchmark; ! this.ScriptName = "SimpleTestGeneric"; ! this.portfolioType = portfolioType; ! this.startingTimeForScript = DateTime.Now; ! this.maxRunningHours = maxRunningHours; ! //this.numIntervalDays = 3; } ! ! public RunSimpleSelection(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! string benchmark, ! DateTime startDate, DateTime endDate, ! double targetReturn, ! PortfolioType portfolioType, ! double maxRunningHours) { ! //this.progressBarForm = new ProgressBarForm(); ! this.tickerGroupID = tickerGroupID; ! this.numberOfEligibleTickers = numberOfEligibleTickers; ! this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; ! this.numDaysForOptimizationPeriod = numDaysForOptimizationPeriod; ! 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 = "SimpleTestGeneric"; ! this.targetReturn = targetReturn; ! this.portfolioType = portfolioType; ! this.startingTimeForScript = DateTime.Now; ! this.maxRunningHours = maxRunningHours; ! //this.numIntervalDays = 3; } ! ! #region Run ! ! protected virtual void run_initializeEndOfDayTimer() ! { ! //default endOfDayTimer ! this.endOfDayTimer = ! new IndexBasedEndOfDayTimer( this.startDateTime, this.benchmark ); ! ! } ! ! protected virtual 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 virtual void run_initializeEndOfDayTimerHandler() ! { ! //always needs specific implementation in inherited classes; ! } ! ! protected virtual void run_initializeHistoricalQuoteProvider() ! { ! //always needs specific implementation in inherited classes; ! } ! ! protected void checkDateForReport_createDirIfNotPresent(string dirPath) ! { ! if(!Directory.Exists(dirPath)) ! Directory.CreateDirectory(dirPath); ! } ! ! 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(); ! } ! ! public virtual void SaveScriptResults() ! { ! string fileName = "SimpleSelectionFrom"+this.numberOfEligibleTickers + ! "OptDays" + this.numDaysForOptimizationPeriod + "Portfolio" + ! this.numberOfTickersToBeChosen + ! "Target" + Convert.ToString(this.targetReturn) + ! Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! //default report with numIntervalDays = 1 ! AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), ! this.benchmark, ! new HistoricalAdjustedQuoteProvider()); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".qPr"); ! // ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ! ObjectArchiver.Archive(this.account.Transactions, ! dirNameWhereToSaveTransactions + ! fileName + ".qPt"); ! // ! this.endOfDayTimer.Stop(); ! } ! ! protected virtual void run_initialize() ! { ! run_initializeHistoricalQuoteProvider(); ! run_initializeEndOfDayTimer(); ! run_initializeAccount(); ! run_initializeEndOfDayTimerHandler(); ! //run_initializeProgressHandlers(); ! } ! protected virtual void run_addEventHandlers() ! { ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! //in inherited classes'override method: ! //add here TimerHandler's handlers to timer's events ! //example ! //this.endOfDayTimer.EVENT_NAME += ! // new EVENT_NAMEEventHandler( ! // this.endOfDayTimerHandler.EVENT_NAMEEventHandler); ! } ! ! ! public virtual void Run() ! { ! this.run_initialize(); ! this.run_addEventHandlers(); ! //this.progressBarForm.Show(); ! this.endOfDayTimer.Start(); ! } ! ! #endregion ! } } --- 47,257 ---- { /// <summary> ! /// Base class for simple selection test /// The strategy simply chooses the tickers with the highest fitness, /// for short or long trading /// </summary> [Serializable] ! public class RunSimpleSelection { ! protected string tickerGroupID; ! protected int numberOfEligibleTickers; ! protected int numberOfTickersToBeChosen; ! protected int numDaysForOptimizationPeriod; ! protected ReportTable reportTable; ! protected EndOfDayDateTime startDateTime; ! protected EndOfDayDateTime endDateTime; protected IHistoricalQuoteProvider historicalQuoteProvider; ! protected EndOfDayTimerHandlerSimpleSelection endOfDayTimerHandler; ! protected Account account; ! protected IEndOfDayTimer endOfDayTimer; ! protected string benchmark; ! ! protected string scriptName; ! ! protected double targetReturn; ! ! protected PortfolioType portfolioType; ! ! protected DateTime startingTimeForScript; ! protected double maxRunningHours; ! //if MaxNumberOfHoursForScript has elapsed and the script ! //is still running, it will be stopped. ! ! public PortfolioType TypeOfPortfolio ! { ! get { return this.portfolioType; } ! } ! ! public virtual string ScriptName ! { ! get{return this.scriptName;} ! set{this.scriptName = value;} ! } ! ! public DateTime TimerLastDate ! { ! get{return this.endOfDayTimer.GetCurrentTime().DateTime ;} ! } ! public RunSimpleSelection(string benchmark, ! DateTime startDate, DateTime endDate, ! PortfolioType portfolioType, ! double maxRunningHours) { ! ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); ! this.benchmark = benchmark; ! this.ScriptName = "SimpleTestGeneric"; ! this.portfolioType = portfolioType; ! this.startingTimeForScript = DateTime.Now; ! this.maxRunningHours = maxRunningHours; ! //this.numIntervalDays = 3; } ! ! public RunSimpleSelection(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! string benchmark, ! DateTime startDate, DateTime endDate, ! double targetReturn, ! PortfolioType portfolioType, ! double maxRunningHours) { ! //this.progressBarForm = new ProgressBarForm(); ! this.tickerGroupID = tickerGroupID; ! this.numberOfEligibleTickers = numberOfEligibleTickers; ! this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; ! this.numDaysForOptimizationPeriod = numDaysForOptimizationPeriod; ! 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 = "SimpleTestGeneric"; ! this.targetReturn = targetReturn; ! this.portfolioType = portfolioType; ! this.startingTimeForScript = DateTime.Now; ! this.maxRunningHours = maxRunningHours; ! //this.numIntervalDays = 3; } ! ! #region Run ! ! protected virtual void run_initializeEndOfDayTimer() ! { ! //default endOfDayTimer ! this.endOfDayTimer = ! new IndexBasedEndOfDayTimer( this.startDateTime, this.benchmark ); ! ! } ! ! protected virtual 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 virtual void run_initializeEndOfDayTimerHandler() ! { ! //always needs specific implementation in inherited classes; ! } ! ! protected virtual void run_initializeHistoricalQuoteProvider() ! { ! //always needs specific implementation in inherited classes; ! } ! ! protected void checkDateForReport_createDirIfNotPresent(string dirPath) ! { ! if(!Directory.Exists(dirPath)) ! Directory.CreateDirectory(dirPath); ! } ! ! 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(); ! } ! ! public virtual void SaveScriptResults() ! { ! string fileName = "SimpleSelectionFrom"+this.numberOfEligibleTickers + ! "OptDays" + this.numDaysForOptimizationPeriod + "Portfolio" + ! this.numberOfTickersToBeChosen + ! "Target" + Convert.ToString(this.targetReturn) + ! Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = ! System.Configuration.ConfigurationManager.AppSettings["ReportsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! //default report with numIntervalDays = 1 ! AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), ! this.benchmark, ! new HistoricalAdjustedQuoteProvider()); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".qPr"); ! // ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ! ObjectArchiver.Archive(this.account.Transactions, ! dirNameWhereToSaveTransactions + ! fileName + ".qPt"); ! // ! this.endOfDayTimer.Stop(); ! } ! ! protected virtual void run_initialize() ! { ! run_initializeHistoricalQuoteProvider(); ! run_initializeEndOfDayTimer(); ! run_initializeAccount(); ! run_initializeEndOfDayTimerHandler(); ! //run_initializeProgressHandlers(); ! } ! protected virtual void run_addEventHandlers() ! { ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! //in inherited classes'override method: ! //add here TimerHandler's handlers to timer's events ! //example ! //this.endOfDayTimer.EVENT_NAME += ! // new EVENT_NAMEEventHandler( ! // this.endOfDayTimerHandler.EVENT_NAMEEventHandler); ! } ! ! ! public virtual void Run() ! { ! this.run_initialize(); ! this.run_addEventHandlers(); ! //this.progressBarForm.Show(); ! this.endOfDayTimer.Start(); ! } ! ! #endregion ! } } |