[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting EndOfDayTimerHandlerCTC.c
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10276/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandlerCTCWeekly.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandlerCTO_WorstAtDay.cs EndOfDayTimerHandlerLastChosenPortfolio.cs EndOfDayTimerHandlerOTC.cs EndOfDayTimerHandlerOTC_WorstAtNight.cs EndOfDayTimerHandlerOTCCTO.cs EndOfDayTimerHandlerOTCMultiAccount.cs EndOfDayTimerHandlerOTCMultiday.cs Log Message: Code has been re-organized in a more logical and Object Oriented way: - WeightedPositions class has been used. - Some static methods have been deleted from SignedTicker class. They have been moved to WeightedPositions. - Basic orders'management has been moved to the primitive base class EndOfDayTimerHandler and to AccountManager class Index: EndOfDayTimerHandlerLastChosenPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerLastChosenPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** EndOfDayTimerHandlerLastChosenPortfolio.cs 17 Sep 2006 21:48:39 -0000 1.3 --- EndOfDayTimerHandlerLastChosenPortfolio.cs 29 Aug 2007 09:43:32 -0000 1.4 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; *************** *** 54,59 **** EndOfDayDateTime firstDate, EndOfDayDateTime lastDate): ! base(chosenTickers, portfolioType, account, ! benchmark) { this.firstDate = firstDate; --- 55,60 ---- EndOfDayDateTime firstDate, EndOfDayDateTime lastDate): ! base(new WeightedPositions( new SignedTickers(chosenTickers) ), ! portfolioType, account, benchmark) { this.firstDate = firstDate; *************** *** 71,75 **** if(endOfDayTimingEventArgs.EndOfDayDateTime.CompareTo(this.firstDate) == 0) { ! this.openPositions(this.chosenTickers); } } --- 72,76 ---- if(endOfDayTimingEventArgs.EndOfDayDateTime.CompareTo(this.firstDate) == 0) { ! this.openPositions(); } } *************** *** 82,86 **** // this.closePositions(); if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.CompareTo(this.lastDate.DateTime.AddDays(-1)) == 0) ! this.closePositions(); } --- 83,87 ---- // this.closePositions(); if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.CompareTo(this.lastDate.DateTime.AddDays(-1)) == 0) ! AccountManager.ClosePositions(this.account); } Index: EndOfDayTimerHandlerOTCCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCCTO.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** EndOfDayTimerHandlerOTCCTO.cs 17 Sep 2006 21:48:39 -0000 1.6 --- EndOfDayTimerHandlerOTCCTO.cs 29 Aug 2007 09:43:33 -0000 1.7 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; *************** *** 44,49 **** public class EndOfDayTimerHandlerOTCCTO : EndOfDayTimerHandler { - protected int numDaysBetweenEachOptimization; - private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; --- 45,48 ---- *************** *** 77,98 **** //temporarily the if condition //if(this.numDaysElapsedSinceLastOptimization == 0) ! this.closePositions(); ! this.openPositions(this.chosenTickers); ! } ! private void reverseSignOfChosenTickers() ! { ! for(int i = 0; i<this.chosenTickers.Length; i++) ! { ! if(this.chosenTickers[i] != null) ! { ! if(this.chosenTickers[i].StartsWith("-")) ! this.chosenTickers[i] = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[i]); ! else ! this.chosenTickers[i] = "-" + this.chosenTickers[i]; ! } ! } } ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) --- 76,83 ---- //temporarily the if condition //if(this.numDaysElapsedSinceLastOptimization == 0) ! AccountManager.ClosePositions(this.account); ! this.openPositions(); } ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) *************** *** 102,110 **** //if(this.numDaysElapsedSinceLastOptimization == // this.numDaysBetweenEachOptimization) ! this.closePositions(); ! this.orders.Clear(); ! this.reverseSignOfChosenTickers(); ! this.openPositions(this.chosenTickers); ! this.reverseSignOfChosenTickers(); } --- 87,99 ---- //if(this.numDaysElapsedSinceLastOptimization == // this.numDaysBetweenEachOptimization) ! AccountManager.ClosePositions(this.account); ! try{ ! this.chosenWeightedPositions.Reverse(); ! this.openPositions(); ! } ! catch(Exception ex){ ! ex = ex; ! } ! this.chosenWeightedPositions.Reverse(); } *************** *** 145,149 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen --- 134,138 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen *************** *** 168,173 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio --- 157,162 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); } //else it will be buyed again the previous optimized portfolio *************** *** 193,197 **** { this.seedForRandomGenerator++; - this.orders.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == --- 182,185 ---- Index: EndOfDayTimerHandlerCTO_WorstAtDay.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO_WorstAtDay.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerCTO_WorstAtDay.cs 30 Jun 2007 18:52:44 -0000 1.1 --- EndOfDayTimerHandlerCTO_WorstAtDay.cs 29 Aug 2007 09:43:32 -0000 1.2 *************** *** 33,36 **** --- 33,37 ---- using QuantProject.Data.Selectors; using QuantProject.ADT.Optimizing.Genetic; + using QuantProject.Scripts.WalkForwardTesting.WalkForwardLag; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios *************** *** 47,52 **** public class EndOfDayTimerHandlerCTO_WorstAtDay : EndOfDayTimerHandler { - protected int numDaysBetweenEachOptimization; - private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; protected GeneticOptimizer currentGO; --- 48,51 ---- *************** *** 82,86 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.closePositions(); } --- 81,85 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! AccountManager.ClosePositions(this.account); } *************** *** 107,115 **** try{ //retrieves loss at day for the CurrentCombination ! lossOfCurrentCombination = ! - SignedTicker.GetOpenToClosePortfolioReturn( ! ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[populationSize - i - 1]).Meaning).Tickers, ! ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[populationSize - i - 1]).Meaning).TickersPortfolioWeights, ! today);//- because fitness in GenomeOTCCTO is just the reversal of what needed numOfGenomesScanned++; if(lossOfCurrentCombination < lossOfCurrentWorstCombination) --- 106,117 ---- try{ //retrieves loss at day for the CurrentCombination ! SignedTickers signedTickers = ! new SignedTickers( ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[populationSize - i - 1]).Meaning).Tickers); ! WeightedPositions weightedPositions = ! new WeightedPositions( ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[populationSize - i - 1]).Meaning).TickersPortfolioWeights, ! signedTickers); ! lossOfCurrentCombination = ! - weightedPositions.GetOpenToCloseReturn( today ); ! //- because fitness in GenomeOTCCTO is just the reversal of what needed numOfGenomesScanned++; if(lossOfCurrentCombination < lossOfCurrentWorstCombination) *************** *** 125,134 **** } } ! this.chosenTickers = ! ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[indexOfWorstCombination]).Meaning).Tickers; ! SignedTicker.ChangeSignOfEachTicker(this.chosenTickers);//it is used a fitness that is ! //the reversal of qwhat needed ! this.chosenTickersPortfolioWeights = ! ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[indexOfWorstCombination]).Meaning).TickersPortfolioWeights; } --- 127,133 ---- } } ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[indexOfWorstCombination]).Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[indexOfWorstCombination]).Meaning).Tickers)); ! } *************** *** 137,149 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(30000); ! ! if(this.currentGO != null) //so a list of genomes is available this.marketCloseEventHandler_chooseTheWorstOTCGenome(); ! this.openPositions(this.chosenTickers); ! } --- 136,144 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.currentGO != null) //so a list of genomes is available this.marketCloseEventHandler_chooseTheWorstOTCGenome(); ! this.openPositions(); } *************** *** 179,183 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen --- 174,178 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen * 2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen *************** *** 203,209 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; ! this.currentGO = GO; } //else it will be buyed again the previous optimized portfolio --- 198,204 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); ! this.currentGO = GO; } //else it will be buyed again the previous optimized portfolio *************** *** 229,233 **** { this.seedForRandomGenerator++; - this.orders.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == --- 224,227 ---- *************** *** 244,250 **** } - #endregion - } } --- 238,242 ---- Index: EndOfDayTimerHandlerOTCMultiday.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCMultiday.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** EndOfDayTimerHandlerOTCMultiday.cs 17 Sep 2006 21:48:39 -0000 1.7 --- EndOfDayTimerHandlerOTCMultiday.cs 29 Aug 2007 09:43:33 -0000 1.8 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; *************** *** 44,49 **** public class EndOfDayTimerHandlerOTCMultiday : EndOfDayTimerHandler { - protected int numDaysBetweenEachOptimization; - private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; --- 45,48 ---- *************** *** 65,70 **** this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; } ! ! /// <summary> /// Handles a "Market Open" event. --- 64,68 ---- this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; } ! /// <summary> /// Handles a "Market Open" event. *************** *** 77,157 **** if(this.numDaysElapsedSinceLastOptimization == 0) ! this.openPositions(this.chosenTickers); } ! ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! ! ! if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) ! this.closePositions(); ! } ! ! ! ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { ! /* ! SelectorByAverageRawOpenPrice selectorByOpenPrice = ! new SelectorByAverageRawOpenPrice(this.tickerGroupID, false, ! currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers, this.minPriceForMinimumCommission, ! this.maxPriceForMinimumCommission, 0, 2); ! DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); ! */ ! ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromTemporizedGroup = ! new SelectorByOpenCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), ! this.benchmark,true, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! currentDate, ! this.numberOfEligibleTickers); ! this.eligibleTickers = lessCorrelatedFromTemporizedGroup.GetTableOfSelectedTickers(); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = ! new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfEligibleTickers, this.benchmark); ! //SelectorByWinningOpenToClose winners = ! // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), ! // false, currentDate.AddDays(-2), ! // currentDate, this.numberOfEligibleTickers/4); ! //return winners.GetTableOfSelectedTickers(); ! //SelectorByOpenCloseCorrelationToBenchmark lessCorrelated = ! // new SelectorByOpenCloseCorrelationToBenchmark(quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(), ! // this.benchmark, true, ! // currentDate.AddDays(-this.numDaysForLiquidity), ! // currentDate, this.numberOfEligibleTickers/2); ! return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); ! //return lessCorrelated.GetTableOfSelectedTickers(); } ! ! // private string[] setTickers_getBestTickersLosingAtLastDay(IGenomeManager genomeManager) ! // { ! // string[] returnValue = ! // ((GenomeMeaning)genomeManager.CurrentGeneticOptimizer.BestGenome.Meaning).Tickers; ! // int numOfGenomes = genomeManager.CurrentGeneticOptimizer.CurrentGeneration.Count; ! // int i; ! // for(i = 0;i<numOfGenomes; i++) ! // { ! // if(((GenomeMeaning)((Genome)genomeManager.CurrentGeneticOptimizer.CurrentGeneration[numOfGenomes - i - 1]).Meaning).ReturnAtLastDayInSample < 0) ! // //the current portfolio has a negative return at the last day in sample ! // { ! // returnValue = ! // ((GenomeMeaning)((Genome)genomeManager.CurrentGeneticOptimizer.CurrentGeneration[numOfGenomes - i - 1]).Meaning).Tickers; ! // i = numOfGenomes; ! // } ! // } ! // ! // return returnValue; ! // } ! protected virtual void setTickers(DateTime currentDate, bool setGenomeCounter) --- 75,115 ---- if(this.numDaysElapsedSinceLastOptimization == 0) ! this.openPositions(); } ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) ! AccountManager.ClosePositions(this.account); } ! ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! DataTable tickersFromGroup = temporizedGroup.GetTableOfSelectedTickers(); ! SelectorByLiquidity mostLiquid = ! new SelectorByLiquidity(tickersFromGroup, ! false,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! this.numberOfEligibleTickers); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = ! new SelectorByQuotationAtEachMarketDay(mostLiquid.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! ! SelectorByAverageRawOpenPrice byPrice = ! new SelectorByAverageRawOpenPrice(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), ! false,currentDate.AddDays(-30), ! currentDate, ! this.numberOfEligibleTickers, ! 28); ! ! return byPrice.GetTableOfSelectedTickers(); } ! protected virtual void setTickers(DateTime currentDate, bool setGenomeCounter) *************** *** 159,163 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen --- 117,121 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen *************** *** 165,169 **** { IGenomeManager genManEfficientOTCPortfolio = ! new GenomeManagerForEfficientOTCPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, --- 123,127 ---- { IGenomeManager genManEfficientOTCPortfolio = ! new GenomeManagerForEfficientOTCCTOPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, *************** *** 182,189 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; ! //this.chosenTickers = ! // this.setTickers_getBestTickersLosingAtLastDay(genManEfficientCTOPortfolio); } //else it will be buyed again the previous optimized portfolio --- 140,145 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); } //else it will be buyed again the previous optimized portfolio *************** *** 209,213 **** { this.seedForRandomGenerator++; - this.orders.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == --- 165,168 ---- Index: EndOfDayTimerHandlerOTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTC.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** EndOfDayTimerHandlerOTC.cs 17 Sep 2006 21:48:39 -0000 1.5 --- EndOfDayTimerHandlerOTC.cs 29 Aug 2007 09:43:32 -0000 1.6 *************** *** 28,31 **** --- 28,32 ---- using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; + using QuantProject.Business.Strategies; using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; *************** *** 44,51 **** public class EndOfDayTimerHandlerOTC : EndOfDayTimerHandler { - protected int numDaysBetweenEachOptimization; - private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; ! public EndOfDayTimerHandlerOTC(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, --- 45,50 ---- public class EndOfDayTimerHandlerOTC : EndOfDayTimerHandler { protected int seedForRandomGenerator; ! public EndOfDayTimerHandlerOTC(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, *************** *** 64,111 **** this.numDaysElapsedSinceLastOptimization = 0; this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; ! } ! ! private double marketOpenEventHandler_currCombinationHasLost_getValue(ExtendedDateTime extendedDateTime) ! { ! double returnValue = 0.0; ! string signedTicker; ! string unsignedTicker; ! double tickerMarketValue; ! for(int i = 0; i<this.chosenTickers.Length; i++) ! { ! signedTicker = this.chosenTickers[i]; ! unsignedTicker = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(signedTicker); ! tickerMarketValue = ! HistoricalDataProvider.GetAdjustedMarketValue(unsignedTicker,extendedDateTime); ! if(signedTicker == unsignedTicker) ! //long position for the ticker ! returnValue += this.chosenTickersPortfolioWeights[i]*tickerMarketValue; ! else//short position for the ticker ! returnValue -= this.chosenTickersPortfolioWeights[i]*tickerMarketValue; ! } ! return returnValue; ! ! } ! ! private bool marketOpenEventHandler_currCombinationHasLost() ! { ! bool returnValue = false; ! IndexBasedEndOfDayTimer currentTimer = (IndexBasedEndOfDayTimer)this.account.EndOfDayTimer; ! ExtendedDateTime now = ! new ExtendedDateTime(currentTimer.GetCurrentTime().DateTime, ! BarComponent.Open); ! ExtendedDateTime previousClose = ! new ExtendedDateTime(currentTimer.GetPreviousDateTime(), ! BarComponent.Close); ! double currentCombinationValue_Now = ! this.marketOpenEventHandler_currCombinationHasLost_getValue(now); ! double currentCombinationValue_AtPreviousMarketClose = ! this.marketOpenEventHandler_currCombinationHasLost_getValue(previousClose); ! if(currentCombinationValue_Now < currentCombinationValue_AtPreviousMarketClose) ! returnValue = true; ! return returnValue; ! } ! /// <summary> /// Handles a "Market Open" event. --- 63,68 ---- this.numDaysElapsedSinceLastOptimization = 0; this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; ! } ! /// <summary> /// Handles a "Market Open" event. *************** *** 116,131 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(30000); ! bool allTickerHasBeenChosen = true; ! for( int i = 0; i<this.chosenTickers.Length; i++) ! { ! if(this.chosenTickers[i] == null) ! allTickerHasBeenChosen = false; ! } ! if(allTickerHasBeenChosen && ! this.marketOpenEventHandler_currCombinationHasLost()) ! this.openPositions(this.chosenTickers); ! } --- 73,78 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.openPositions(); ! } *************** *** 133,137 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.closePositions(); } --- 80,84 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! AccountManager.ClosePositions(this.account); } *************** *** 153,158 **** false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers, this.benchmark); ! ! return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } --- 100,119 ---- false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers, this.benchmark); ! ! SelectorByAverageRawOpenPrice byPrice = ! new SelectorByAverageRawOpenPrice(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), ! false,currentDate.AddDays(-30), ! currentDate, ! this.numberOfEligibleTickers, ! 35); ! DataTable tickersByPrice = byPrice.GetTableOfSelectedTickers(); ! ! SelectorByOpenCloseCorrelationToBenchmark tickersLessCorrelatedToBenchmark = ! new SelectorByOpenCloseCorrelationToBenchmark(tickersByPrice, ! "^GSPC",true, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! tickersByPrice.Rows.Count/2); ! ! return tickersLessCorrelatedToBenchmark.GetTableOfSelectedTickers(); } *************** *** 163,167 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen --- 124,128 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen *************** *** 188,197 **** if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); ! GO.Run(false); this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio --- 149,159 ---- if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); ! GO.CrossoverRate = 0.0; ! GO.MutationRate = 0.70; GO.Run(false); this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); } //else it will be buyed again the previous optimized portfolio *************** *** 217,221 **** { this.seedForRandomGenerator++; - this.orders.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == --- 179,182 ---- Index: EndOfDayTimerHandlerOTCMultiAccount.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCMultiAccount.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerOTCMultiAccount.cs 17 Sep 2006 21:48:39 -0000 1.2 --- EndOfDayTimerHandlerOTCMultiAccount.cs 29 Aug 2007 09:43:33 -0000 1.3 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; *************** *** 44,55 **** public class EndOfDayTimerHandlerOTCMultiAccount : EndOfDayTimerHandler { - protected int numDaysBetweenEachOptimization; - private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; ! private string[,] chosenTickersForAccounts; private int distanceForEachGenomeToTest; private Account[] accounts; - private ArrayList[] ordersForAccounts; - private string[,] lastOrderedTickersForAccounts; public EndOfDayTimerHandlerOTCMultiAccount(string tickerGroupID, int numberOfEligibleTickers, --- 45,52 ---- public class EndOfDayTimerHandlerOTCMultiAccount : EndOfDayTimerHandler { protected int seedForRandomGenerator; ! private WeightedPositions[] chosenWeightedPositionsForAccounts; private int distanceForEachGenomeToTest; private Account[] accounts; public EndOfDayTimerHandlerOTCMultiAccount(string tickerGroupID, int numberOfEligibleTickers, *************** *** 71,162 **** this.numDaysElapsedSinceLastOptimization = 0; this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; ! this.chosenTickersForAccounts = new string[numberOfAccounts,numberOfTickersToBeChosen]; ! this.lastOrderedTickersForAccounts = new string[numberOfAccounts,numberOfTickersToBeChosen]; ! this.ordersForAccounts = new ArrayList[numberOfAccounts]; ! for(int i = 0; i<numberOfAccounts;i++) ! ordersForAccounts[i] = new ArrayList(); this.distanceForEachGenomeToTest = distanceForEachGenomeToTest; this.accounts = accounts; } ! ! private void addOrderForTickerForEachAccount(int accountNumber, string ticker ) ! { ! string tickerCode = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! double cashForSinglePosition = this.accounts[accountNumber].CashAmount / this.numberOfTickersToBeChosen; ! long quantity = ! Convert.ToInt64( Math.Floor( cashForSinglePosition / this.accounts[accountNumber].DataStreamer.GetCurrentBid( tickerCode ) ) ); ! Order order; ! if(this.portfolioType == PortfolioType.OnlyShort || ! (this.portfolioType == PortfolioType.ShortAndLong && ! ticker != tickerCode)) ! order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); ! else ! order = new Order( OrderType.MarketBuy, new Instrument( tickerCode ) , quantity ); ! ! this.ordersForAccounts[accountNumber].Add(order); ! } ! ! protected override void addChosenTickersToOrderList(string[] tickers) ! { ! for(int i = 0; i<this.accounts.Length; i++) ! { ! for(int j = 0; j<this.numberOfTickersToBeChosen; j++) ! { ! string ticker = this.chosenTickersForAccounts[i,j]; ! if( ticker != null) ! { ! this.addOrderForTickerForEachAccount(i, ticker ); ! this.lastOrderedTickersForAccounts[i,j] = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! } ! } ! } ! } ! ! ! protected override void openPositions(string[] tickers) { //add cash first ! for(int i = 0; i<this.accounts.Length; i++) ! { ! if(this.ordersForAccounts[i].Count == 0 && this.accounts[i].Transactions.Count == 0) ! this.accounts[i].AddCash(17000); ! } ! ! this.addChosenTickersToOrderList(tickers); //execute orders actually for(int i = 0; i<this.accounts.Length; i++) ! { ! foreach(object item in this.ordersForAccounts[i]) ! this.accounts[i].AddOrder((Order)item); ! } ! } ! private void closePositions_closePositionForAccount(int accountNumber, ! string ticker) ! { ! this.accounts[accountNumber].ClosePosition(ticker); ! } ! protected override void closePositions() ! { ! string ticker; ! for(int i = 0; i<this.accounts.Length; i++) ! { ! for(int j = 0; j<this.numberOfTickersToBeChosen; j++) ! { ! ticker = this.lastOrderedTickersForAccounts[i,j]; ! if( ticker != null) ! { ! if(this.accounts[i].Portfolio[ticker]!=null) ! closePositions_closePositionForAccount(i, ticker ); ! } ! } ! } ! } ! ! ! /// <summary> /// Handles a "Market Open" event. /// </summary> --- 68,89 ---- this.numDaysElapsedSinceLastOptimization = 0; this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; ! this.chosenWeightedPositionsForAccounts = new WeightedPositions[numberOfAccounts]; this.distanceForEachGenomeToTest = distanceForEachGenomeToTest; this.accounts = accounts; } ! ! private void openPositions(WeightedPositions[] chosenWeightedPositionsForAccounts) { //add cash first ! for ( int i = 0; i<this.accounts.Length; i++ ) ! if ( this.accounts[i].Transactions.Count == 0 ) ! this.accounts[i].AddCash(15000); //execute orders actually for(int i = 0; i<this.accounts.Length; i++) ! AccountManager.OpenPositions(this.chosenWeightedPositionsForAccounts[i], ! this.accounts[i]); } ! /// <summary> /// Handles a "Market Open" event. /// </summary> *************** *** 168,172 **** //temporarily the if condition //if(this.numDaysElapsedSinceLastOptimization == 0) ! this.openPositions(this.chosenTickers); } --- 95,99 ---- //temporarily the if condition //if(this.numDaysElapsedSinceLastOptimization == 0) ! this.openPositions(this.chosenWeightedPositionsForAccounts); } *************** *** 179,187 **** //if(this.numDaysElapsedSinceLastOptimization == // this.numDaysBetweenEachOptimization) ! this.closePositions(); ! } - - #region OneHourAfterMarketCloseEventHandler --- 106,112 ---- //if(this.numDaysElapsedSinceLastOptimization == // this.numDaysBetweenEachOptimization) ! for(int i = 0; i<this.accounts.Length; i++) ! AccountManager.ClosePositions( this.accounts[i] ); } #region OneHourAfterMarketCloseEventHandler *************** *** 230,234 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen --- 155,159 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen *************** *** 253,266 **** //this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), // currentDate); ! for(int i = 0; i<this.accounts.Length; i++) { ! for(int j = 0; j<this.numberOfTickersToBeChosen; j++) ! this.chosenTickersForAccounts[i,j] = ! ((string[])((Genome)GO.CurrentGeneration[GO.CurrentGeneration.Count - 1 -i*this.distanceForEachGenomeToTest]).Meaning)[j]; ! } ! } //else it will be buyed again the previous optimized portfolio - //that's it the actual chosenTickers member } --- 178,189 ---- //this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), // currentDate); ! SignedTickers signedTickers; ! for(int i = 0; i<this.accounts.Length; i++) { ! signedTickers = new SignedTickers( (string[])((Genome)GO.CurrentGeneration[GO.CurrentGeneration.Count - 1 -i*this.distanceForEachGenomeToTest]).Meaning ); ! this.chosenWeightedPositionsForAccounts[i] = new WeightedPositions( signedTickers ); ! } } //else it will be buyed again the previous optimized portfolio } *************** *** 283,288 **** { this.seedForRandomGenerator++; - foreach(ArrayList arrayList in this.ordersForAccounts) - arrayList.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == --- 206,209 ---- Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** EndOfDayTimerHandlerCTO.cs 17 Sep 2006 21:48:39 -0000 1.25 --- EndOfDayTimerHandlerCTO.cs 29 Aug 2007 09:43:32 -0000 1.26 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; *************** *** 44,49 **** public class EndOfDayTimerHandlerCTO : EndOfDayTimerHandler { - protected int numDaysBetweenEachOptimization; - private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; --- 45,48 ---- *************** *** 75,79 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.closePositions(); } --- 74,78 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! AccountManager.ClosePositions(this.account); } *************** *** 82,93 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(30000); ! ! // if(this.numDaysElapsedSinceLastOptimization < ! // this.numDaysBetweenEachOptimization - 1) ! // { ! this.openPositions(this.chosenTickers); ! // } } --- 81,85 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.openPositions(); } *************** *** 119,123 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen --- 111,115 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen *************** *** 142,148 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; ! } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member --- 134,140 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); ! } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member *************** *** 167,171 **** { this.seedForRandomGenerator++; - this.orders.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == --- 159,162 ---- Index: EndOfDayTimerHandlerCTCWeekly.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCWeekly.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** EndOfDayTimerHandlerCTCWeekly.cs 17 Sep 2006 21:48:39 -0000 1.6 --- EndOfDayTimerHandlerCTCWeekly.cs 29 Aug 2007 09:43:32 -0000 1.7 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; *************** *** 46,53 **** protected int numDaysForReturnCalculation; protected double maxAcceptableCloseToCloseDrawdown; ! protected bool stopLossConditionReached; ! protected double currentAccountValue; ! protected double previousAccountValue; ! public EndOfDayTimerHandlerCTCWeekly(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, --- 47,51 ---- protected int numDaysForReturnCalculation; protected double maxAcceptableCloseToCloseDrawdown; ! public EndOfDayTimerHandlerCTCWeekly(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, *************** *** 68,76 **** this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; - this.stopLossConditionReached = false; - this.currentAccountValue = 0.0; - this.previousAccountValue = 0.0; } - #region MarketCloseEventHandler --- 66,70 ---- *************** *** 100,109 **** if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.DayOfWeek == DayOfWeek.Monday) ! this.openPositions(this.chosenTickers); if(this.stopLossConditionReached || endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.DayOfWeek == DayOfWeek.Friday) ! this.closePositions(); } --- 94,103 ---- if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.DayOfWeek == DayOfWeek.Monday) ! this.openPositions(); if(this.stopLossConditionReached || endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.DayOfWeek == DayOfWeek.Friday) ! AccountManager.ClosePositions(this.account); } *************** *** 130,134 **** { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is meaningful only if the initial set of tickers is //larger than the number of tickers to be chosen --- 124,128 ---- { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) //the optimization process is meaningful only if the initial set of tickers is //larger than the number of tickers to be chosen *************** *** 152,157 **** //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.Run(false); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio --- 146,151 ---- //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.Run(false); ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); } //else it will be buyed again the previous optimized portfolio *************** *** 172,176 **** DayOfWeek.Friday) { - this.orders.Clear(); this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //it sets tickers to be chosen at next Monday --- 166,169 ---- Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** EndOfDayTimerHandlerCTC.cs 17 Sep 2006 21:48:39 -0000 1.22 --- EndOfDayTimerHandlerCTC.cs 29 Aug 2007 09:43:31 -0000 1.23 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; *************** *** 50,59 **** protected int daysCounterWithNoPositions; protected double maxAcceptableCloseToCloseDrawdown; ! protected bool stopLossConditionReached; ! protected double currentAccountValue; ! protected double previousAccountValue; ! protected int numDaysBetweenEachOptimization; ! private int numDaysElapsedSinceLastOptimization; ! public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, --- 51,55 ---- protected int daysCounterWithNoPositions; protected double maxAcceptableCloseToCloseDrawdown; ! public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, *************** *** 121,125 **** //max acceptable close to close drawdown reached { ! this.closePositions(); this.daysCounterWithPositions = 0; //positionsJustClosed = true; --- 117,121 ---- //max acceptable close to close drawdown reached { ! AccountManager.ClosePositions(this.account); this.daysCounterWithPositions = 0; //positionsJustClosed = true; *************** *** 132,136 **** this.Account.Transactions.Count <= 1) { ! this.openPositions(this.chosenTickers); this.daysCounterWithNoPositions = 0; } --- 128,132 ---- this.Account.Transactions.Count <= 1) { ! AccountManager.OpenPositions(this.chosenWeightedPositions,this.account); this.daysCounterWithNoPositions = 0; } *************** *** 188,192 **** { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is meaningful only if the initial set of tickers is //larger than the number of tickers to be chosen --- 184,188 ---- { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) //the optimization process is meaningful only if the initial set of tickers is //larger than the number of tickers to be chosen *************** *** 216,222 **** ((GenomeManagerForEfficientCTCPortfolio)genManEfficientCTCPortfolio).LastQuoteDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; ! } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member --- 212,218 ---- ((GenomeManagerForEfficientCTCPortfolio)genManEfficientCTCPortfolio).LastQuoteDate, setOfTickersToBeOptimized.Rows.Count); ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); ! } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member *************** *** 243,247 **** //this.oneHourAfterMarketCloseEventHandler_updatePrices(); this.numDaysElapsedSinceLastOptimization++; - this.orders.Clear(); if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization) --- 239,242 ---- Index: EndOfDayTimerHandlerOTC_WorstAtNight.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTC_WorstAtNight.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerOTC_WorstAtNight.cs 30 Jun 2007 18:50:38 -0000 1.1 --- EndOfDayTimerHandlerOTC_WorstAtNight.cs 29 Aug 2007 09:43:32 -0000 1.2 *************** *** 45,50 **** public class EndOfDayTimerHandlerOTC_WorstAtNight : EndOfDayTimerHandler { - protected int numDaysBetweenEachOptimization; - private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; protected GeneticOptimizer currentGO; --- 45,48 ---- *************** *** 82,86 **** DateTime lastMarketDay = currentTimer.GetPreviousDateTime(); int numOfGenomesScanned = 0; ! for(int i = 0; numOfGenomesScanned < this.numOfGenomesForCTOScanning; i++) { if( i == 0 || --- 80,87 ---- DateTime lastMarketDay = currentTimer.GetPreviousDateTime(); int numOfGenomesScanned = 0; ! for(int i = 0; ! numOfGenomesScanned < this.numOfGenomesForCTOScanning && ! i < populationSize - 1; ! i++) { if( i == 0 || *************** *** 94,103 **** try{ //tries to retrieve loss at night for the CurrentCombination ! lossOfCurrentCombination = ! SignedTicker.GetLastNightPortfolioReturn( ! ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[populationSize - i - 1]).Meaning).Tickers, ! ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[populationSize - i - 1]).Meaning).TickersPortfolioWeights, ! lastMarketDay, ! today); numOfGenomesScanned++; if(lossOfCurrentCombination < lossOfCurrentWorstCombination) --- 95,105 ---- try{ //tries to retrieve loss at night for the CurrentCombination ! SignedTickers signedTickers = ! new SignedTickers( ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[populationSize - i - 1]).Meaning).Tickers); ! WeightedPositions weightedPositions = ! new WeightedPositions( ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[populationSize - i - 1]).Meaning).TickersPortfolioWeights, ! signedTickers); ! lossOfCurrentCombination = ! weightedPositions.GetLastNightReturn(lastMarketDay,today); numOfGenomesScanned++; if(lossOfCurrentCombination < lossOfCurrentWorstCombination) *************** *** 113,121 **** } } ! ! this.chosenTickers = ! ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[indexOfWorstCombination]).Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ! ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[indexOfWorstCombination]).Meaning).TickersPortfolioWeights; } --- 115,120 ---- } } ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[indexOfWorstCombination]).Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)((Genome)this.currentGO.CurrentGeneration[indexOfWorstCombination]).Meaning).Tickers)); } *************** *** 128,138 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(30000); ! if(this.currentGO != null) //so a list of genomes is available this.marketOpenEventHandler_chooseTheWorstCTOGenome(); ! this.openPositions(this.chosenTickers); } --- 127,135 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.currentGO != null) //so a list of genomes is available this.marketOpenEventHandler_chooseTheWorstCTOGenome(); ! this.openPositions(); } *************** *** 140,144 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.closePositions(); } --- 137,141 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! AccountManager.ClosePositions(this.account); } *************** *** 147,177 **** protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { ! Sel... [truncated message content] |