[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForce
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:19
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17551/TestingOTCTypes/BruteForceOptimization Modified Files: RunEfficientOTCTypesBruteForce.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: RunEfficientOTCTypesBruteForce.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization/RunEfficientOTCTypesBruteForce.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunEfficientOTCTypesBruteForce.cs 19 Aug 2008 17:13:05 -0000 1.2 --- RunEfficientOTCTypesBruteForce.cs 29 Sep 2008 21:19:35 -0000 1.3 *************** *** 3,7 **** RunEfficientOTCTypesBruteForce.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientOTCTypesBruteForce.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; *************** *** 48,174 **** { ! /// <summary> /// Script to test OTC daily, OTC multiday and OTC - CTO ! /// all together with one brute force optimization and 3 accounts (each for /// each type of strategy) /// </summary> ! [Serializable] ! public class RunEfficientOTCTypesBruteForce : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! private Account[] accounts; ! ! public RunEfficientOTCTypesBruteForce(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! string benchmark, ! DateTime startDate, DateTime endDate, ! double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! 1,100, benchmark, ! startDate, endDate, 0.0, ! PortfolioType.ShortAndLong, maxRunningHours) ! { ! this.ScriptName = "OTC_SR_PriceSelBruteForce"; ! 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 EndOfDayTimerHandlerOTCTypesBruteForce(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.benchmark, 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 = "From"+this.numberOfEligibleTickers + ! "OptDays" + this.numDaysForOptimizationPeriod + "Portfolio" + ! this.numberOfTickersToBeChosen + "BruteForce"; ! 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(); ! } } } --- 48,185 ---- { ! /// <summary> /// Script to test OTC daily, OTC multiday and OTC - CTO ! /// all together with one brute force optimization and 3 accounts (each for /// each type of strategy) /// </summary> ! [Serializable] ! public class RunEfficientOTCTypesBruteForce : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! private Account[] accounts; ! ! public RunEfficientOTCTypesBruteForce(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! string benchmark, ! DateTime startDate, DateTime endDate, ! double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! 1,100, benchmark, ! startDate, endDate, 0.0, ! PortfolioType.ShortAndLong, maxRunningHours) ! { ! this.ScriptName = "OTC_SR_PriceSelBruteForce"; ! 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 EndOfDayTimerHandlerOTCTypesBruteForce(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.benchmark, this.numDaysBetweenEachOptimization, ! this.accounts); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! 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 ); ! } ! #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 = "From"+this.numberOfEligibleTickers + ! "OptDays" + this.numDaysForOptimizationPeriod + "Portfolio" + ! this.numberOfTickersToBeChosen + "BruteForce"; ! 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(); ! } } } |