Thread: [Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-08-19 17:11:33
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2916/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: EndOfDayTimerHandlerPVO.cs Log Message: - the code has been cleaned up to avoid warnings - standard indentation has been applied Index: EndOfDayTimerHandlerPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/EndOfDayTimerHandlerPVO.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EndOfDayTimerHandlerPVO.cs 12 Mar 2008 22:06:05 -0000 1.9 --- EndOfDayTimerHandlerPVO.cs 19 Aug 2008 17:11:28 -0000 1.10 *************** *** 3,7 **** EndOfDayTimerHandlerPVO.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- EndOfDayTimerHandlerPVO.cs ! Copyright (C) 2003 Marco Milletti *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Data; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Data; *************** *** 46,320 **** { /// <summary> ! /// Implements MarketOpenEventHandler and MarketCloseEventHandler ! /// These handlers contain the core strategy for the Portfolio Value ! /// Oscillator ! /// </summary> ! [Serializable] ! public class EndOfDayTimerHandlerPVO : EndOfDayTimerHandler ! { ! protected int minLevelForOversoldThreshold; ! protected int maxLevelForOversoldThreshold; ! protected int minLevelForOverboughtThreshold; ! protected int maxLevelForOverboughtThreshold; ! protected int divisorForThresholdComputation; ! protected int numDaysForOscillatingPeriod; ! protected double currentOversoldThreshold; ! protected double currentOverboughtThreshold; ! protected double maxAcceptableCloseToCloseDrawdown; ! protected double minimumAcceptableGain; ! protected DateTime lastCloseDate; ! protected IGenomeManager iGenomeManager; ! protected int seedForRandomGenerator; ! protected bool portfolioHasBeenOverbought; ! protected bool portfolioHasBeenOversold; ! protected bool symmetricalThresholds; ! protected bool overboughtMoreThanOversoldForFixedPortfolio; ! protected HistoricalAdjustedQuoteProvider historicalQuoteProvider; ! ! public EndOfDayTimerHandlerPVO(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, ! int numDaysForOscillatingPeriod, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! int numDaysBetweenEachOptimization, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double minimumAcceptableGain): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, 0.0, ! portfolioType) ! { ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; ! this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; ! this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; ! this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; ! this.divisorForThresholdComputation = divisorForThresholdComputation; ! this.symmetricalThresholds = symmetricalThresholds; ! this.overboughtMoreThanOversoldForFixedPortfolio = overboughtMoreThanOversoldForFixedPortfolio; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; ! this.minimumAcceptableGain = minimumAcceptableGain; ! this.stopLossConditionReached = false; ! this.currentAccountValue = 0.0; ! this.previousAccountValue = 0.0; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; ! this.portfolioHasBeenOverbought = false; ! this.portfolioHasBeenOversold = false; ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! ; ! } ! #region MarketCloseEventHandler ! ! protected virtual double getCurrentChosenWeightedPositionsReturn(IndexBasedEndOfDayTimer timer) ! { ! double returnValue = 999.0; ! try ! { ! DateTime firstDayOfOscillatingPeriod = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - this.numDaysForOscillatingPeriod]["quDate"]; ! DateTime today = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; ReturnsManager returnsManager = new ReturnsManager(new CloseToCloseIntervals( new EndOfDayDateTime(firstDayOfOscillatingPeriod, ! EndOfDaySpecificTime.MarketClose) , new EndOfDayDateTime(today, ! EndOfDaySpecificTime.MarketClose) , this.benchmark , this.numDaysForOscillatingPeriod ) , ! this.historicalQuoteProvider ); returnValue = this.chosenWeightedPositions.GetReturn(0,returnsManager); ! } ! catch(MissingQuotesException ex) ! { ! ex = ex; ! } ! return returnValue; ! } ! private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) ! { ! double currentChosenWeightedPositionsReturn = ! this.getCurrentChosenWeightedPositionsReturn(timer); ! if(currentChosenWeightedPositionsReturn != 999.0 && ! this.portfolioType == PortfolioType.ShortAndLong) ! //currentChosenWeightedPositionsReturn has been ! //properly computedand it is possible to reverse positions ! { ! if(currentChosenWeightedPositionsReturn >= currentOverboughtThreshold && ! this.portfolioHasBeenOversold) ! //open positions derive from an overSold period but now ! //the overbought threshold has been reached ! { ! this.reversePositions(); ! this.portfolioHasBeenOversold = false; ! this.portfolioHasBeenOverbought = true; ! this.previousAccountValue = this.account.GetMarketValue(); ! } ! if(currentChosenWeightedPositionsReturn <= - currentOversoldThreshold && ! this.portfolioHasBeenOverbought) ! //open positions derive from an overBought period but now ! //the overSold threshold has been reached ! { ! this.reversePositions(); ! this.portfolioHasBeenOversold = true; ! this.portfolioHasBeenOverbought = false; ! this.previousAccountValue = this.account.GetMarketValue(); ! } ! } ! } ! protected void marketCloseEventHandler_openPositions(IndexBasedEndOfDayTimer timer) ! { ! if(this.account.CashAmount == 0.0 && this.account.Transactions.Count == 0) this.account.AddCash(15000); ! double currentChosenWeightedPositionsReturn = ! this.getCurrentChosenWeightedPositionsReturn(timer); ! if(currentChosenWeightedPositionsReturn != 999.0) ! //currentChosenTickersValue has been properly computed ! { ! if(currentChosenWeightedPositionsReturn >= currentOverboughtThreshold && ! this.portfolioType == PortfolioType.ShortAndLong) ! { ! this.chosenWeightedPositions.Reverse(); ! try ! { ! AccountManager.OpenPositions( this.chosenWeightedPositions, ! this.account ); ! this.portfolioHasBeenOverbought = true; ! this.portfolioHasBeenOversold = false; ! this.previousAccountValue = this.account.GetMarketValue(); ! } ! catch(Exception ex) ! { ! ex = ex; ! } ! finally ! { ! this.chosenWeightedPositions.Reverse(); ! } ! } ! else if (currentChosenWeightedPositionsReturn <= - currentOversoldThreshold) ! { ! AccountManager.OpenPositions( this.chosenWeightedPositions, ! this.account ); ! this.portfolioHasBeenOverbought = false; ! this.portfolioHasBeenOversold = true; ! this.previousAccountValue = this.account.GetMarketValue(); ! } ! } ! } ! ! protected virtual void marketCloseEventHandler_closePositionsIfNeeded() ! { ! if(this.stopLossConditionReached || ! this.takeProfitConditionReached || ! this.numDaysElapsedSinceLastOptimization + 1 == this.numDaysBetweenEachOptimization ) ! { ! AccountManager.ClosePositions(this.account); ! this.portfolioHasBeenOverbought = false; ! this.portfolioHasBeenOversold = false; ! } ! } ! ! protected virtual void marketCloseEventHandler_updateStopLossAndTakeProfitConditions() ! { ! //this.previousAccountValue has been set at opening positions ! this.currentAccountValue = this.account.GetMarketValue(); ! double portfolioGainOrLoss = (this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue; ! ! if( portfolioGainOrLoss <= -this.maxAcceptableCloseToCloseDrawdown ) ! { ! this.stopLossConditionReached = true; ! this.takeProfitConditionReached = false; ! } ! else if (portfolioGainOrLoss >= this.minimumAcceptableGain) ! ! { ! this.stopLossConditionReached = false; ! this.takeProfitConditionReached = true; ! } ! } ! ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! this.marketCloseEventHandler_updateStopLossAndTakeProfitConditions(); ! this.marketCloseEventHandler_closePositionsIfNeeded(); ! if(this.chosenWeightedPositions != null) ! //tickers to buy have been chosen by the optimizer ! { ! if(this.account.Portfolio.Count == 0) ! this.marketCloseEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); ! //positions are opened only if thresholds are reached ! else//there are some opened positions ! this.marketCloseEventHandler_reverseIfNeeded((IndexBasedEndOfDayTimer)sender); ! } ! } ! #endregion ! ! #region OneHourAfterMarketCloseEventHandler ! ! protected virtual DataTable getSetOfTickersToBeOptimized(DateTime currentDate) ! { SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! DataTable tickersFromGroup = temporizedGroup.GetTableOfSelectedTickers(); ! int numOfTickersInGroupAtCurrentDate = tickersFromGroup.Rows.Count; ! ! SelectorByAverageRawOpenPrice byPrice = ! new SelectorByAverageRawOpenPrice(tickersFromGroup,false,currentDate.AddDays(-15), ! currentDate, ! numOfTickersInGroupAtCurrentDate, ! 30,3000, 0.0001,100); ! ! SelectorByLiquidity mostLiquidSelector = ! new SelectorByLiquidity(byPrice.GetTableOfSelectedTickers(), ! false,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! this.numberOfEligibleTickers); ! ! // SelectorByCloseToCloseCorrelationToBenchmark byCorrelationToBenchmark = ! // new SelectorByCloseToCloseCorrelationToBenchmark(mostLiquidSelector.GetTableOfSelectedTickers(), ! // "^GSPC",false, ! // currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! // this.numberOfEligibleTickers/2,false); ! // ! ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromLastSelection = ! new SelectorByQuotationAtEachMarketDay(mostLiquidSelector.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! // SelectorByMaxLinearDipendence dipendentTickers = // new SelectorByMaxLinearDipendence(quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers(), // currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, // this.numberOfEligibleTickers/2,2,1000, this.benchmark); // return dipendentTickers.GetTableOfSelectedTickers(); ! ! // DataTable quotedAtEachMarketDay = // quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers(); ! // ! // CloseToCloseCorrelationProvider correlationProvider = // new CloseToCloseCorrelationProvider( // QuantProject.ADT.ExtendedDataTable.GetArrayOfStringFromColumn( // quotedAtEachMarketDay, 0 ), ! // currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! // currentDate,1,0.005,this.benchmark); // SelectorByCloseToCloseCorrelationToBenchmark byCorrelationToBenchmark = --- 46,320 ---- { /// <summary> ! /// Implements MarketOpenEventHandler and MarketCloseEventHandler ! /// These handlers contain the core strategy for the Portfolio Value ! /// Oscillator ! /// </summary> ! [Serializable] ! public class EndOfDayTimerHandlerPVO : EndOfDayTimerHandler ! { ! protected int minLevelForOversoldThreshold; ! protected int maxLevelForOversoldThreshold; ! protected int minLevelForOverboughtThreshold; ! protected int maxLevelForOverboughtThreshold; ! protected int divisorForThresholdComputation; ! protected int numDaysForOscillatingPeriod; ! protected double currentOversoldThreshold; ! protected double currentOverboughtThreshold; ! protected double maxAcceptableCloseToCloseDrawdown; ! protected double minimumAcceptableGain; ! protected DateTime lastCloseDate; ! protected IGenomeManager iGenomeManager; ! protected int seedForRandomGenerator; ! protected bool portfolioHasBeenOverbought; ! protected bool portfolioHasBeenOversold; ! protected bool symmetricalThresholds; ! protected bool overboughtMoreThanOversoldForFixedPortfolio; ! protected HistoricalAdjustedQuoteProvider historicalQuoteProvider; ! ! public EndOfDayTimerHandlerPVO(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, ! int numDaysForOscillatingPeriod, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! int numDaysBetweenEachOptimization, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double minimumAcceptableGain): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, 0.0, ! portfolioType) ! { ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; ! this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; ! this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; ! this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; ! this.divisorForThresholdComputation = divisorForThresholdComputation; ! this.symmetricalThresholds = symmetricalThresholds; ! this.overboughtMoreThanOversoldForFixedPortfolio = overboughtMoreThanOversoldForFixedPortfolio; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; ! this.minimumAcceptableGain = minimumAcceptableGain; ! this.stopLossConditionReached = false; ! this.currentAccountValue = 0.0; ! this.previousAccountValue = 0.0; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; ! this.portfolioHasBeenOverbought = false; ! this.portfolioHasBeenOversold = false; ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! ; ! } ! #region MarketCloseEventHandler ! ! protected virtual double getCurrentChosenWeightedPositionsReturn(IndexBasedEndOfDayTimer timer) ! { ! double returnValue = 999.0; ! try ! { ! DateTime firstDayOfOscillatingPeriod = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - this.numDaysForOscillatingPeriod]["quDate"]; ! DateTime today = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; ReturnsManager returnsManager = new ReturnsManager(new CloseToCloseIntervals( new EndOfDayDateTime(firstDayOfOscillatingPeriod, ! EndOfDaySpecificTime.MarketClose) , new EndOfDayDateTime(today, ! EndOfDaySpecificTime.MarketClose) , this.benchmark , this.numDaysForOscillatingPeriod ) , ! this.historicalQuoteProvider ); returnValue = this.chosenWeightedPositions.GetReturn(0,returnsManager); ! } ! catch(MissingQuotesException ex) ! { ! string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + ""; ! } ! return returnValue; ! } ! private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) ! { ! double currentChosenWeightedPositionsReturn = ! this.getCurrentChosenWeightedPositionsReturn(timer); ! if(currentChosenWeightedPositionsReturn != 999.0 && ! this.portfolioType == PortfolioType.ShortAndLong) ! //currentChosenWeightedPositionsReturn has been ! //properly computedand it is possible to reverse positions ! { ! if(currentChosenWeightedPositionsReturn >= currentOverboughtThreshold && ! this.portfolioHasBeenOversold) ! //open positions derive from an overSold period but now ! //the overbought threshold has been reached ! { ! this.reversePositions(); ! this.portfolioHasBeenOversold = false; ! this.portfolioHasBeenOverbought = true; ! this.previousAccountValue = this.account.GetMarketValue(); ! } ! if(currentChosenWeightedPositionsReturn <= - currentOversoldThreshold && ! this.portfolioHasBeenOverbought) ! //open positions derive from an overBought period but now ! //the overSold threshold has been reached ! { ! this.reversePositions(); ! this.portfolioHasBeenOversold = true; ! this.portfolioHasBeenOverbought = false; ! this.previousAccountValue = this.account.GetMarketValue(); ! } ! } ! } ! protected void marketCloseEventHandler_openPositions(IndexBasedEndOfDayTimer timer) ! { ! if(this.account.CashAmount == 0.0 && this.account.Transactions.Count == 0) this.account.AddCash(15000); ! double currentChosenWeightedPositionsReturn = ! this.getCurrentChosenWeightedPositionsReturn(timer); ! if(currentChosenWeightedPositionsReturn != 999.0) ! //currentChosenTickersValue has been properly computed ! { ! if(currentChosenWeightedPositionsReturn >= currentOverboughtThreshold && ! this.portfolioType == PortfolioType.ShortAndLong) ! { ! this.chosenWeightedPositions.Reverse(); ! try ! { ! AccountManager.OpenPositions( this.chosenWeightedPositions, ! this.account ); ! this.portfolioHasBeenOverbought = true; ! this.portfolioHasBeenOversold = false; ! this.previousAccountValue = this.account.GetMarketValue(); ! } ! catch(Exception ex) ! { ! string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + ""; ! } ! finally ! { ! this.chosenWeightedPositions.Reverse(); ! } ! } ! else if (currentChosenWeightedPositionsReturn <= - currentOversoldThreshold) ! { ! AccountManager.OpenPositions( this.chosenWeightedPositions, ! this.account ); ! this.portfolioHasBeenOverbought = false; ! this.portfolioHasBeenOversold = true; ! this.previousAccountValue = this.account.GetMarketValue(); ! } ! } ! } ! ! protected virtual void marketCloseEventHandler_closePositionsIfNeeded() ! { ! if(this.stopLossConditionReached || ! this.takeProfitConditionReached || ! this.numDaysElapsedSinceLastOptimization + 1 == this.numDaysBetweenEachOptimization ) ! { ! AccountManager.ClosePositions(this.account); ! this.portfolioHasBeenOverbought = false; ! this.portfolioHasBeenOversold = false; ! } ! } ! ! protected virtual void marketCloseEventHandler_updateStopLossAndTakeProfitConditions() ! { ! //this.previousAccountValue has been set at opening positions ! this.currentAccountValue = this.account.GetMarketValue(); ! double portfolioGainOrLoss = (this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue; ! ! if( portfolioGainOrLoss <= -this.maxAcceptableCloseToCloseDrawdown ) ! { ! this.stopLossConditionReached = true; ! this.takeProfitConditionReached = false; ! } ! else if (portfolioGainOrLoss >= this.minimumAcceptableGain) ! ! { ! this.stopLossConditionReached = false; ! this.takeProfitConditionReached = true; ! } ! } ! ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! this.marketCloseEventHandler_updateStopLossAndTakeProfitConditions(); ! this.marketCloseEventHandler_closePositionsIfNeeded(); ! if(this.chosenWeightedPositions != null) ! //tickers to buy have been chosen by the optimizer ! { ! if(this.account.Portfolio.Count == 0) ! this.marketCloseEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); ! //positions are opened only if thresholds are reached ! else//there are some opened positions ! this.marketCloseEventHandler_reverseIfNeeded((IndexBasedEndOfDayTimer)sender); ! } ! } ! #endregion ! ! #region OneHourAfterMarketCloseEventHandler ! ! protected virtual DataTable getSetOfTickersToBeOptimized(DateTime currentDate) ! { SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! DataTable tickersFromGroup = temporizedGroup.GetTableOfSelectedTickers(); ! int numOfTickersInGroupAtCurrentDate = tickersFromGroup.Rows.Count; ! ! SelectorByAverageRawOpenPrice byPrice = ! new SelectorByAverageRawOpenPrice(tickersFromGroup,false,currentDate.AddDays(-15), ! currentDate, ! numOfTickersInGroupAtCurrentDate, ! 30,3000, 0.0001,100); ! ! SelectorByLiquidity mostLiquidSelector = ! new SelectorByLiquidity(byPrice.GetTableOfSelectedTickers(), ! false,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! this.numberOfEligibleTickers); ! ! // SelectorByCloseToCloseCorrelationToBenchmark byCorrelationToBenchmark = ! // new SelectorByCloseToCloseCorrelationToBenchmark(mostLiquidSelector.GetTableOfSelectedTickers(), ! // "^GSPC",false, ! // currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! // this.numberOfEligibleTickers/2,false); ! // ! ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromLastSelection = ! new SelectorByQuotationAtEachMarketDay(mostLiquidSelector.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! // SelectorByMaxLinearDipendence dipendentTickers = // new SelectorByMaxLinearDipendence(quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers(), // currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, // this.numberOfEligibleTickers/2,2,1000, this.benchmark); // return dipendentTickers.GetTableOfSelectedTickers(); ! ! // DataTable quotedAtEachMarketDay = // quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers(); ! // ! // CloseToCloseCorrelationProvider correlationProvider = // new CloseToCloseCorrelationProvider( // QuantProject.ADT.ExtendedDataTable.GetArrayOfStringFromColumn( // quotedAtEachMarketDay, 0 ), ! // currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! // currentDate,1,0.005,this.benchmark); // SelectorByCloseToCloseCorrelationToBenchmark byCorrelationToBenchmark = *************** *** 325,424 **** // this.numberOfEligibleTickers / 2, false); // return byCorrelationToBenchmark.GetTableOfSelectedTickers(); ! return quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers(); ! //for debug ! // SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromLastSelection = ! // new SelectorByQuotationAtEachMarketDay(temporizedGroup.GetTableOfSelectedTickers(), ! // false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! // this.numberOfEligibleTickers, this.benchmark); ! // return quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers(); ! } ! protected void addPVOGenomeToBestGenomes(Genome genome, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers, int daysForOscillatingPeriod, ! PortfolioType portfolioType, ! int createdGenerations, ! double oversoldThreshold, ! double overboughtThreshold) ! { ! if(this.bestGenomes == null) ! this.bestGenomes = new ArrayList(); ! ! this.bestGenomes.Add(new GenomeRepresentation(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! genome.Generation, ! eligibleTickers, ! daysForOscillatingPeriod, portfolioType, createdGenerations, ! oversoldThreshold, overboughtThreshold)); ! } ! ! protected virtual void setTickers(DateTime currentDate, ! bool setGenomeCounter) ! { ! 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 ! ! { ! this.iGenomeManager = ! new GenomeManagerPVO(setOfTickersToBeOptimized, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfTickersToBeChosen, ! this.numDaysForOscillatingPeriod, ! this.minLevelForOversoldThreshold, ! this.maxLevelForOversoldThreshold, ! this.minLevelForOverbou... [truncated message content] |