[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting EndOfDayTimerHandlerCTC.cs,
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-05-17 23:13:34
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18849/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandlerCTOTest.cs RunEfficientCTCPortfolio.cs RunEfficientPortfolio.cs Log Message: Updated files for the EfficientPortfolio script: - new call for the genetic optimizer; - added new parameter for the CloseToClose RunEfficientPortfolio (main.cs may be changed manually); - added minimal changes Index: EndOfDayTimerHandlerCTOTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTOTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerCTOTest.cs 4 May 2005 18:21:07 -0000 1.1 --- EndOfDayTimerHandlerCTOTest.cs 17 May 2005 23:13:25 -0000 1.2 *************** *** 155,159 **** SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers/2); //SelectorByOpenToCloseVolatility lessVolatile = // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), --- 155,159 ---- SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers); //SelectorByOpenToCloseVolatility lessVolatile = // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), *************** *** 166,170 **** new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers/2, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), --- 166,170 ---- new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), *************** *** 194,198 **** this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; --- 194,200 ---- this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; Index: RunEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTCPortfolio.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RunEfficientCTCPortfolio.cs 11 Apr 2005 18:52:31 -0000 1.5 --- RunEfficientCTCPortfolio.cs 17 May 2005 23:13:25 -0000 1.6 *************** *** 60,63 **** --- 60,64 ---- { private int numDayOfPortfolioLife; + private double maxAcceptableCloseToCloseDrawdown; public RunEfficientCTCPorfolio(string tickerGroupID, int numberOfEligibleTickers, *************** *** 67,71 **** DateTime startDate, DateTime endDate, int numDaysOfPortfolioLife, double targetReturn, ! PortfolioType portfolioType): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, --- 68,72 ---- DateTime startDate, DateTime endDate, int numDaysOfPortfolioLife, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, *************** *** 77,80 **** --- 78,82 ---- this.ScriptName = "CloseToCloseScripts"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; + this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; } #region Run *************** *** 89,93 **** this.populationSizeForGeneticOptimizer, this.benchmark, this.numDayOfPortfolioLife, this.targetReturn, ! this.portfolioType); } --- 91,95 ---- this.populationSizeForGeneticOptimizer, this.benchmark, this.numDayOfPortfolioLife, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } Index: RunEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientPortfolio.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RunEfficientPortfolio.cs 4 May 2005 18:30:54 -0000 1.6 --- RunEfficientPortfolio.cs 17 May 2005 23:13:25 -0000 1.7 *************** *** 53,57 **** public class RunEfficientPorfolio { ! public static double MaxNumberOfHoursForScript = 6; //if MaxNumberOfHoursForScript has elapsed and the script //is still running, it will be stopped. --- 53,57 ---- public class RunEfficientPorfolio { ! public static double MaxNumberOfHoursForScript = 5; //if MaxNumberOfHoursForScript has elapsed and the script //is still running, it will be stopped. *************** *** 87,91 **** protected DateTime startingTimeForScript; ! public virtual string ScriptName { --- 87,91 ---- protected DateTime startingTimeForScript; ! public virtual string ScriptName { *************** *** 93,97 **** set{this.scriptName = value;} } ! public RunEfficientPorfolio(string tickerGroupID, int numberOfEligibleTickers, --- 93,101 ---- set{this.scriptName = value;} } ! ! public DateTime TimerLastDate ! { ! get{return this.endOfDayTimer.GetCurrentTime().DateTime ;} ! } public RunEfficientPorfolio(string tickerGroupID, int numberOfEligibleTickers, *************** *** 160,173 **** protected virtual void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { - //Report report; - if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || DateTime.Now >= this.startingTimeForScript.AddHours(RunEfficientPorfolio.MaxNumberOfHoursForScript)) //last date is reached by the timer or MaxNumberOfHoursForScript hours //are elapsed from the time script started ! { ! this.endOfDayTimer.Stop(); ! ! string fileName = "From"+this.numberOfEligibleTickers + "LiqDays" + this.numDaysForLiquidity + "Portfolio" + this.numberOfTickersToBeChosen + "GenNum" + --- 164,177 ---- protected virtual void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || DateTime.Now >= this.startingTimeForScript.AddHours(RunEfficientPorfolio.MaxNumberOfHoursForScript)) //last date is reached by the timer or MaxNumberOfHoursForScript hours //are elapsed from the time script started ! this.SaveScriptResults(); ! } ! ! public virtual void SaveScriptResults() ! { ! string fileName = "From"+this.numberOfEligibleTickers + "LiqDays" + this.numDaysForLiquidity + "Portfolio" + this.numberOfTickersToBeChosen + "GenNum" + *************** *** 176,197 **** "Target" + Convert.ToString(this.targetReturn) + Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveAccounts = System.Configuration.ConfigurationSettings.AppSettings["AccountsArchive"] + ! "\\" + this.ScriptName + "\\"; ! //default report with numIntervalDays = 1 ! AccountReport accountReport = this.account.CreateReport(fileName,1,this.endDateTime,this.benchmark, ! new HistoricalAdjustedQuoteProvider()); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".rep"); ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! ObjectArchiver.Archive(this.account, ! dirNameWhereToSaveAccounts + ! fileName + ".acc"); ! } } public virtual void Run() { --- 180,206 ---- "Target" + Convert.ToString(this.targetReturn) + Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveAccounts = System.Configuration.ConfigurationSettings.AppSettings["AccountsArchive"] + ! "\\" + 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 + ".rep"); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! ObjectArchiver.Archive(this.account, ! dirNameWhereToSaveAccounts + ! fileName + ".acc"); ! ! this.endOfDayTimer.Stop(); ! } + + public virtual void Run() { Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** EndOfDayTimerHandlerCTC.cs 4 May 2005 18:30:54 -0000 1.6 --- EndOfDayTimerHandlerCTC.cs 17 May 2005 23:13:25 -0000 1.7 *************** *** 46,49 **** --- 46,54 ---- private int numDaysOfPortfolioLife; private int daysCounter; + private double maxAcceptableCloseToCloseDrawdown; + private bool stopLossConditionReached; + private double currentAccountValue; + private double previousAccountValue; + public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, *************** *** 54,58 **** int numDaysOfPortfolioLife, double targetReturn, ! PortfolioType portfolioType): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, account, --- 59,63 ---- int numDaysOfPortfolioLife, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, account, *************** *** 64,67 **** --- 69,76 ---- this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; this.daysCounter = 0; + this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; + this.stopLossConditionReached = false; + this.currentAccountValue = 0.0; + this.previousAccountValue = 0.0; } *************** *** 72,81 **** currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers/2); this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedInEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity),currentDate, ! this.numberOfEligibleTickers/2, this.benchmark); return quotedInEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } --- 81,90 ---- currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers); this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedInEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity),currentDate, ! this.numberOfEligibleTickers, this.benchmark); return quotedInEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } *************** *** 101,105 **** this.numDaysOfPortfolioLife, this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; --- 110,116 ---- this.numDaysOfPortfolioLife, this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; *************** *** 126,129 **** --- 137,141 ---- this.orders.Clear(); } + this.updateStopLossCondition(); } #endregion *************** *** 181,190 **** } } ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.daysCounter++; ! if(this.daysCounter == this.numDaysOfPortfolioLife) //it's time to change portfolio { --- 193,218 ---- } } ! ! private void updateStopLossCondition() ! { ! this.previousAccountValue = this.currentAccountValue; ! this.currentAccountValue = this.account.GetMarketValue(); ! if((this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) ! { ! this.stopLossConditionReached = true; ! } ! else ! { ! this.stopLossConditionReached = false; ! } ! } ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.daysCounter++; ! if(this.daysCounter == this.numDaysOfPortfolioLife || ! this.stopLossConditionReached) //it's time to change portfolio { Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** EndOfDayTimerHandlerCTO.cs 4 May 2005 18:30:54 -0000 1.10 --- EndOfDayTimerHandlerCTO.cs 17 May 2005 23:13:25 -0000 1.11 *************** *** 149,153 **** SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers/2); //SelectorByOpenToCloseVolatility lessVolatile = // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), --- 149,153 ---- SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers); //SelectorByOpenToCloseVolatility lessVolatile = // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), *************** *** 160,164 **** new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers/2, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), --- 160,164 ---- new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), *************** *** 186,190 **** this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; --- 186,192 ---- this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; |