[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes RunEffici
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:21
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17551/TestingOTCTypes Modified Files: RunEfficientOTCTypes.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: RunEfficientOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/RunEfficientOTCTypes.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RunEfficientOTCTypes.cs 19 Aug 2008 17:13:05 -0000 1.9 --- RunEfficientOTCTypes.cs 29 Sep 2008 21:19:35 -0000 1.10 *************** *** 3,7 **** RunEfficientOTCTypes.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientOTCTypes.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; *************** *** 38,42 **** using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 38,42 ---- 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,184 **** { ! /// <summary> /// Script to test OTC daily, OTC multiday and OTC - CTO ! /// all together with one optimization and 3 accounts (each for /// each type of strategy) /// </summary> ! [Serializable] ! public class RunEfficientOTCTypes : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! private Account[] accounts; ! ! public RunEfficientOTCTypes(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, double targetReturn, ! PortfolioType portfolioType, double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! this.ScriptName = "OTCTypes_SR_WithCoeffOnlyMutationPriceSel"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.accounts = new Account[4]; ! } ! ! #region auxiliary overriden methods for Run ! ! ! protected override void run_initializeAccount() ! { ! for(int i = 0; i<this.accounts.Length; i++) ! { ! this.accounts[i] = new Account( this.ScriptName, this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider )); ! } ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCTypes(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization, this.accounts); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! 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 ); ! } ! #endregion ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } ! public override void SaveScriptResults() ! { ! string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! "From"+ this.tickerGroupID+ "_" + ! this.numberOfEligibleTickers + ! "_OptDays" + this.numDaysForOptimizationPeriod + "_Portf" + ! this.numberOfTickersToBeChosen + "_GenNum" + ! this.generationNumberForGeneticOptimizer + ! "_PopSize" + this.populationSizeForGeneticOptimizer + ! Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveAccounts = ! System.Configuration.ConfigurationManager.AppSettings["AccountsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = ! System.Configuration.ConfigurationManager.AppSettings["GenomesArchive"] + ! "\\" + this.ScriptName + "\\"; ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); ! ! for(int i = 0; i<this.accounts.Length; i++) ! { ! ObjectArchiver.Archive(accounts[i], ! dirNameWhereToSaveAccounts + ! fileName + "#" + i.ToString() + ".qPa"); ! ObjectArchiver.Archive(this.accounts[i].Transactions, ! dirNameWhereToSaveTransactions + ! fileName + "#" + i.ToString() + ".qPt"); ! } ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! this.endOfDayTimer.Stop(); ! } } } --- 47,190 ---- { ! /// <summary> /// Script to test OTC daily, OTC multiday and OTC - CTO ! /// all together with one optimization and 3 accounts (each for /// each type of strategy) /// </summary> ! [Serializable] ! public class RunEfficientOTCTypes : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! private Account[] accounts; ! ! public RunEfficientOTCTypes(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, double targetReturn, ! PortfolioType portfolioType, double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! this.ScriptName = "OTCTypes_SR_WithCoeffOnlyMutationPriceSel"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.accounts = new Account[4]; ! } ! ! #region auxiliary overriden methods for Run ! ! ! protected override void run_initializeAccount() ! { ! for(int i = 0; i<this.accounts.Length; i++) ! { ! this.accounts[i] = new Account( this.ScriptName, this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider )); ! } ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCTypes(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization, this.accounts); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! 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 ); ! } ! #endregion ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } ! public override void SaveScriptResults() ! { ! string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! "From"+ this.tickerGroupID+ "_" + ! this.numberOfEligibleTickers + ! "_OptDays" + this.numDaysForOptimizationPeriod + "_Portf" + ! this.numberOfTickersToBeChosen + "_GenNum" + ! this.generationNumberForGeneticOptimizer + ! "_PopSize" + this.populationSizeForGeneticOptimizer + ! Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveAccounts = ! System.Configuration.ConfigurationManager.AppSettings["AccountsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = ! System.Configuration.ConfigurationManager.AppSettings["GenomesArchive"] + ! "\\" + this.ScriptName + "\\"; ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); ! ! for(int i = 0; i<this.accounts.Length; i++) ! { ! ObjectArchiver.Archive(accounts[i], ! dirNameWhereToSaveAccounts + ! fileName + "#" + i.ToString() + ".qPa"); ! ObjectArchiver.Archive(this.accounts[i].Transactions, ! dirNameWhereToSaveTransactions + ! fileName + "#" + i.ToString() + ".qPt"); ! } ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! this.endOfDayTimer.Stop(); ! } } } |