[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/BiasedOTC_PVONoThresholds In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13724/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/BiasedOTC_PVONoThresholds Modified Files: EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.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: EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/BiasedOTC_PVONoThresholds/EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs 27 Feb 2007 22:52:41 -0000 1.1 --- EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs 29 Aug 2007 09:50:20 -0000 1.2 *************** *** 51,59 **** protected int numOfDifferentGenomesToEvaluateOutOfSample; protected int currentGenomeIndex = 0; ! protected double currentTickersGainOrLoss = 0.0; protected Hashtable genomesCollector; ! new protected string[,] chosenTickers; ! new protected double[,] chosenTickersPortfolioWeights; public EndOfDayTimerHandlerBiasedOTC_PVONoThresholds(string tickerGroupID, int numberOfEligibleTickers, --- 51,58 ---- protected int numOfDifferentGenomesToEvaluateOutOfSample; protected int currentGenomeIndex = 0; ! protected double currentWeightedPositionsGainOrLoss = 0.0; protected Hashtable genomesCollector; ! protected WeightedPositions[] weightedPositionsToEvaluateOutOfSample; public EndOfDayTimerHandlerBiasedOTC_PVONoThresholds(string tickerGroupID, int numberOfEligibleTickers, *************** *** 84,94 **** { this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample; ! this.chosenTickers = new string[numOfDifferentGenomesToEvaluateOutOfSample, numberOfTickersToBeChosen]; ! this.chosenTickersPortfolioWeights = new double[numOfDifferentGenomesToEvaluateOutOfSample, numberOfTickersToBeChosen]; this.genomesCollector = new Hashtable(); } ! protected virtual double getCurrentChosenTickersGainOrLoss(IndexBasedEndOfDayTimer timer, ! int indexForChosenTickers) { double returnValue = 999.0; --- 83,92 ---- { this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample; ! this.weightedPositionsToEvaluateOutOfSample = new WeightedPositions[numOfDifferentGenomesToEvaluateOutOfSample]; this.genomesCollector = new Hashtable(); } ! protected virtual double getCurrentWeightedPositionsGainOrLoss(IndexBasedEndOfDayTimer timer, ! int indexForChosenWeightedPositions) { double returnValue = 999.0; *************** *** 99,114 **** DateTime lastMarketDay = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - 1]["quDate"]; - - string[] tickers = new string[this.numberOfTickersToBeChosen]; - double[] tickerWeights = new double[this.numberOfTickersToBeChosen]; - for(int i = 0; i < this.numberOfTickersToBeChosen; i++) - { - tickers[i] = this.chosenTickers[indexForChosenTickers,i]; - tickerWeights[i] = this.chosenTickersPortfolioWeights[indexForChosenTickers,i]; - } returnValue = ! SignedTicker.GetLastNightPortfolioReturn( ! tickers, tickerWeights, ! lastMarketDay, today); } catch(MissingQuotesException ex) --- 97,103 ---- DateTime lastMarketDay = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - 1]["quDate"]; returnValue = ! this.weightedPositionsToEvaluateOutOfSample[indexForChosenWeightedPositions].GetLastNightReturn( ! lastMarketDay, today); } catch(MissingQuotesException ex) *************** *** 121,137 **** //sets currentGenomeIndex with the genome's index that crosses an overbought/oversold threshold with the //highest degree and sets currentTickersGainOrLoss accordingly ! private void marketOpenEventHandler_openPositions_chooseBestGenome(IndexBasedEndOfDayTimer timer) { //default genome index is the first //genome (with the highest plain fitness), if no other genome //presents a gain or a loss greater than the first genome ! double currentTickersGainOrLoss = 0.0; double currentMaxAbsoluteMove = 0.0; double currentAbsoluteMove = 0.0; for(int i = 0; i < this.numOfDifferentGenomesToEvaluateOutOfSample; i++) { ! currentTickersGainOrLoss = this.getCurrentChosenTickersGainOrLoss(timer, i); currentAbsoluteMove = ! Math.Abs( currentTickersGainOrLoss ); if(currentAbsoluteMove != 999.0 && currentAbsoluteMove > currentMaxAbsoluteMove) --- 110,126 ---- //sets currentGenomeIndex with the genome's index that crosses an overbought/oversold threshold with the //highest degree and sets currentTickersGainOrLoss accordingly ! protected virtual void openPositions_chooseBestGenome(IndexBasedEndOfDayTimer timer) { //default genome index is the first //genome (with the highest plain fitness), if no other genome //presents a gain or a loss greater than the first genome ! double currentWeightedPositionsGainOrLoss = 0.0; double currentMaxAbsoluteMove = 0.0; double currentAbsoluteMove = 0.0; for(int i = 0; i < this.numOfDifferentGenomesToEvaluateOutOfSample; i++) { ! currentWeightedPositionsGainOrLoss = this.getCurrentWeightedPositionsGainOrLoss(timer, i); currentAbsoluteMove = ! Math.Abs( currentWeightedPositionsGainOrLoss ); if(currentAbsoluteMove != 999.0 && currentAbsoluteMove > currentMaxAbsoluteMove) *************** *** 141,168 **** currentMaxAbsoluteMove = currentAbsoluteMove; this.currentGenomeIndex = i; ! this.currentTickersGainOrLoss = currentTickersGainOrLoss; } } } ! ! ! protected void marketOpenEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { ! this.currentTickersGainOrLoss = 999.0; ! this.marketOpenEventHandler_openPositions_chooseBestGenome(timer); ! if(this.currentTickersGainOrLoss != 999.0) ! //currentChosenTickersValue has been properly computed { ! string[] tickers = new string[this.numberOfTickersToBeChosen]; ! for(int i = 0; i < this.numberOfTickersToBeChosen; i++) ! tickers[i] = this.chosenTickers[this.currentGenomeIndex,i]; ! if(this.currentTickersGainOrLoss > 0.0) { ! SignedTicker.ChangeSignOfEachTicker(tickers); ! base.openPositions(tickers); } else //(currentChosenTickersGainOrLoss < 0.0) { ! base.openPositions(tickers); } } --- 130,164 ---- currentMaxAbsoluteMove = currentAbsoluteMove; this.currentGenomeIndex = i; ! this.currentWeightedPositionsGainOrLoss = currentWeightedPositionsGainOrLoss; } } } ! //no thresholds ! protected virtual void openPositions(IndexBasedEndOfDayTimer timer) { ! this.currentWeightedPositionsGainOrLoss = 999.0; ! this.openPositions_chooseBestGenome(timer); ! if(this.currentWeightedPositionsGainOrLoss != 999.0) ! //currentWeightedPositionsGainOrLoss has been properly computed { ! if(this.currentWeightedPositionsGainOrLoss > 0.0) { ! this.weightedPositionsToEvaluateOutOfSample[this.currentGenomeIndex].Reverse(); ! try ! { ! AccountManager.OpenPositions(this.weightedPositionsToEvaluateOutOfSample[this.currentGenomeIndex], ! this.account); ! } ! catch(Exception ex) ! {ex=ex;} ! finally ! { ! this.weightedPositionsToEvaluateOutOfSample[this.currentGenomeIndex].Reverse(); ! } } else //(currentChosenTickersGainOrLoss < 0.0) { ! AccountManager.OpenPositions(this.weightedPositionsToEvaluateOutOfSample[this.currentGenomeIndex], ! this.account); } } *************** *** 174,178 **** if(this.account.Portfolio.Count == 0 && this.genomesCollector.Count > 0) ! this.marketOpenEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); } --- 170,174 ---- if(this.account.Portfolio.Count == 0 && this.genomesCollector.Count > 0) ! this.openPositions((IndexBasedEndOfDayTimer)sender); } *************** *** 180,190 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! base.closePositions(); ! this.orders.Clear(); } #region OneHourAfterMarketCloseEventHandler ! private void setTickers_updateTickersListAndAddGenomesForLog(GeneticOptimizer GO, int eligibleTickersForGO) { --- 176,185 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! AccountManager.ClosePositions(this.account); } #region OneHourAfterMarketCloseEventHandler ! protected void setTickers_updateTickersListAndAddGenomesForLog(GeneticOptimizer GO, int eligibleTickersForGO) { *************** *** 202,215 **** // fitness has been added to the hashtable yet { ! for(int i = 0; i<this.numberOfTickersToBeChosen; i++) ! { ! this.chosenTickers[addedGenomes,i] = ! ((GenomeMeaningPVO)currentGenome.Meaning).Tickers[i]; ! this.chosenTickersPortfolioWeights[addedGenomes,i] = ! ((GenomeMeaningPVO)currentGenome.Meaning).TickersPortfolioWeights[i]; ! } ! this.genomesCollector.Add(currentGenome.Fitness, null); - this.addPVOGenomeToBestGenomes(currentGenome,((GenomeManagerForEfficientPortfolio)this.iGenomeManager).FirstQuoteDate, ((GenomeManagerForEfficientPortfolio)this.iGenomeManager).LastQuoteDate, eligibleTickersForGO, --- 197,204 ---- // fitness has been added to the hashtable yet { ! this.weightedPositionsToEvaluateOutOfSample[addedGenomes] = new WeightedPositions( ! ((GenomeMeaningPVO)currentGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaningPVO)currentGenome.Meaning).Tickers ) ); this.genomesCollector.Add(currentGenome.Fitness, null); this.addPVOGenomeToBestGenomes(currentGenome,((GenomeManagerForEfficientPortfolio)this.iGenomeManager).FirstQuoteDate, ((GenomeManagerForEfficientPortfolio)this.iGenomeManager).LastQuoteDate, eligibleTickersForGO, |