Thread: [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); ! ! SelectorByAverageRawOp... [truncated message content] |