[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-08-19 17:13:38
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3611/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO Modified Files: RunBiasedPVO.cs RunBiasedPVO_OTC.cs Log Message: - the code has been cleaned up to avoid warnings - standard indentation has been applied Index: RunBiasedPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/RunBiasedPVO.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RunBiasedPVO.cs 9 Mar 2008 22:40:51 -0000 1.4 --- RunBiasedPVO.cs 19 Aug 2008 17:13:03 -0000 1.5 *************** *** 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; --- 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; *************** *** 38,42 **** using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 38,42 ---- using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 53,57 **** /// when it is time to open new positions, /// it is not simply chosen the genome with the highest fitness ! /// (as in the PVO base), but it is chosen the genome (from a /// given set of genomes with a good fitness) that /// has the highest degree of deviation from a threshold --- 53,57 ---- /// when it is time to open new positions, /// it is not simply chosen the genome with the highest fitness ! /// (as in the PVO base), but it is chosen the genome (from a /// given set of genomes with a good fitness) that /// has the highest degree of deviation from a threshold *************** *** 60,68 **** public class RunBiasedPVO : RunPVO { ! protected double minPriceForTickersToBeChosen; ! protected double maxPriceForTickersToBeChosen; protected int numOfDifferentGenomesToEvaluateOutOfSample; ! protected int numDaysOfStayingOnTheMarket; ! protected double maxCoefficientForDegreeComputationOfCrossingThreshold; protected double numOfStdDevForThresholdsComputation; protected bool resetThresholdsBeforeCheckingOutOfSample; --- 60,68 ---- public class RunBiasedPVO : RunPVO { ! protected double minPriceForTickersToBeChosen; ! protected double maxPriceForTickersToBeChosen; protected int numOfDifferentGenomesToEvaluateOutOfSample; ! protected int numDaysOfStayingOnTheMarket; ! protected double maxCoefficientForDegreeComputationOfCrossingThreshold; protected double numOfStdDevForThresholdsComputation; protected bool resetThresholdsBeforeCheckingOutOfSample; *************** *** 70,74 **** protected bool doNotOpenReversedPositionsThatHaveJustBeenClosed; protected int numDaysForThresholdsReComputation; ! protected string pathOfFileContainingGenomes; public string PathOfFileContainingGenomes --- 70,74 ---- protected bool doNotOpenReversedPositionsThatHaveJustBeenClosed; protected int numDaysForThresholdsReComputation; ! protected string pathOfFileContainingGenomes; public string PathOfFileContainingGenomes *************** *** 78,168 **** } ! public RunBiasedPVO(string tickerGroupID, int maxNumOfEligibleTickersForOptimization, ! double minPriceForTickersToBeChosen, ! double maxPriceForTickersToBeChosen, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, ! int numOfDifferentGenomesToEvaluateOutOfSample, ! bool resetThresholdsBeforeCheckingOutOfSample, ! int numDaysForThresholdsReComputation, ! double numOfStdDevForThresholdsComputation, ! double maxCoefficientForDegreeComputationOfCrossingThreshold, ! bool buyOnlyPositionsThatAreMovingTogether, ! bool doNotOpenReversedPositionsThatHaveJustBeenClosed, ! int numDaysForOscillatingPeriod, ! int numDaysOfStayingOnTheMarket, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! int numDaysBetweenEachOptimization, ! PortfolioType inSamplePortfolioType, double maxAcceptableCloseToCloseDrawdown, ! double minimumAcceptableGain, double maxRunningHours): ! base(tickerGroupID, maxNumOfEligibleTickersForOptimization, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, ! numDaysForOscillatingPeriod, ! minLevelForOversoldThreshold, ! maxLevelForOversoldThreshold, ! minLevelForOverboughtThreshold, ! maxLevelForOverboughtThreshold, ! divisorForThresholdComputation, ! symmetricalThresholds, ! overboughtMoreThanOversoldForFixedPortfolio, ! numDaysBetweenEachOptimization, ! inSamplePortfolioType, maxAcceptableCloseToCloseDrawdown, ! minimumAcceptableGain, ! maxRunningHours) { ! this.minPriceForTickersToBeChosen = minPriceForTickersToBeChosen; ! this.maxPriceForTickersToBeChosen = maxPriceForTickersToBeChosen; this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample; ! this.minimumAcceptableGain = minimumAcceptableGain; ! //this.ScriptName = "PVO_Biased_WithWeightsPriceSel"; ! this.ScriptName = "PVO_Biased_NoWeightsPriceSel"; ! this.numDaysOfStayingOnTheMarket = numDaysOfStayingOnTheMarket; ! this.maxCoefficientForDegreeComputationOfCrossingThreshold = maxCoefficientForDegreeComputationOfCrossingThreshold; ! this.resetThresholdsBeforeCheckingOutOfSample = resetThresholdsBeforeCheckingOutOfSample; ! this.numDaysForThresholdsReComputation = numDaysForThresholdsReComputation; ! this.numOfStdDevForThresholdsComputation = numOfStdDevForThresholdsComputation; ! this.buyOnlyPositionsThatAreMovingTogether = buyOnlyPositionsThatAreMovingTogether; ! this.doNotOpenReversedPositionsThatHaveJustBeenClosed = doNotOpenReversedPositionsThatHaveJustBeenClosed; ! this.pathOfFileContainingGenomes = null; ! //if this field is set to null, selections of tickers (with ! //optimization), takes place; otherwise, tickers for ! //out of sample testing are chosen from a given ! //set of genomes saved to disk (representing a set of ! //a certain number of optimizations run over a given period) } ! #region auxiliary overriden methods for Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerBiasedPVO(this.tickerGroupID, this.numberOfEligibleTickers, ! this.minPriceForTickersToBeChosen, ! this.maxPriceForTickersToBeChosen, ! this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.PathOfFileContainingGenomes, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, this.benchmark, ! this.numOfDifferentGenomesToEvaluateOutOfSample, ! this.resetThresholdsBeforeCheckingOutOfSample, ! this.numDaysForThresholdsReComputation, ! this.numOfStdDevForThresholdsComputation, ! this.maxCoefficientForDegreeComputationOfCrossingThreshold, ! this.buyOnlyPositionsThatAreMovingTogether, ! this.doNotOpenReversedPositionsThatHaveJustBeenClosed, this.numDaysForOscillatingPeriod, this.numDaysOfStayingOnTheMarket, ! this.minLevelForOversoldThreshold, this.maxLevelForOversoldThreshold, this.minLevelForOverboughtThreshold, --- 78,168 ---- } ! public RunBiasedPVO(string tickerGroupID, int maxNumOfEligibleTickersForOptimization, ! double minPriceForTickersToBeChosen, ! double maxPriceForTickersToBeChosen, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, ! int numOfDifferentGenomesToEvaluateOutOfSample, ! bool resetThresholdsBeforeCheckingOutOfSample, ! int numDaysForThresholdsReComputation, ! double numOfStdDevForThresholdsComputation, ! double maxCoefficientForDegreeComputationOfCrossingThreshold, ! bool buyOnlyPositionsThatAreMovingTogether, ! bool doNotOpenReversedPositionsThatHaveJustBeenClosed, ! int numDaysForOscillatingPeriod, ! int numDaysOfStayingOnTheMarket, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! int numDaysBetweenEachOptimization, ! PortfolioType inSamplePortfolioType, double maxAcceptableCloseToCloseDrawdown, ! double minimumAcceptableGain, double maxRunningHours): ! base(tickerGroupID, maxNumOfEligibleTickersForOptimization, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, ! numDaysForOscillatingPeriod, ! minLevelForOversoldThreshold, ! maxLevelForOversoldThreshold, ! minLevelForOverboughtThreshold, ! maxLevelForOverboughtThreshold, ! divisorForThresholdComputation, ! symmetricalThresholds, ! overboughtMoreThanOversoldForFixedPortfolio, ! numDaysBetweenEachOptimization, ! inSamplePortfolioType, maxAcceptableCloseToCloseDrawdown, ! minimumAcceptableGain, ! maxRunningHours) { ! this.minPriceForTickersToBeChosen = minPriceForTickersToBeChosen; ! this.maxPriceForTickersToBeChosen = maxPriceForTickersToBeChosen; this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample; ! this.minimumAcceptableGain = minimumAcceptableGain; ! //this.ScriptName = "PVO_Biased_WithWeightsPriceSel"; ! this.ScriptName = "PVO_Biased_NoWeightsPriceSel"; ! this.numDaysOfStayingOnTheMarket = numDaysOfStayingOnTheMarket; ! this.maxCoefficientForDegreeComputationOfCrossingThreshold = maxCoefficientForDegreeComputationOfCrossingThreshold; ! this.resetThresholdsBeforeCheckingOutOfSample = resetThresholdsBeforeCheckingOutOfSample; ! this.numDaysForThresholdsReComputation = numDaysForThresholdsReComputation; ! this.numOfStdDevForThresholdsComputation = numOfStdDevForThresholdsComputation; ! this.buyOnlyPositionsThatAreMovingTogether = buyOnlyPositionsThatAreMovingTogether; ! this.doNotOpenReversedPositionsThatHaveJustBeenClosed = doNotOpenReversedPositionsThatHaveJustBeenClosed; ! this.pathOfFileContainingGenomes = null; ! //if this field is set to null, selections of tickers (with ! //optimization), takes place; otherwise, tickers for ! //out of sample testing are chosen from a given ! //set of genomes saved to disk (representing a set of ! //a certain number of optimizations run over a given period) } ! #region auxiliary overriden methods for Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerBiasedPVO(this.tickerGroupID, this.numberOfEligibleTickers, ! this.minPriceForTickersToBeChosen, ! this.maxPriceForTickersToBeChosen, ! this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.PathOfFileContainingGenomes, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, this.benchmark, ! this.numOfDifferentGenomesToEvaluateOutOfSample, ! this.resetThresholdsBeforeCheckingOutOfSample, ! this.numDaysForThresholdsReComputation, ! this.numOfStdDevForThresholdsComputation, ! this.maxCoefficientForDegreeComputationOfCrossingThreshold, ! this.buyOnlyPositionsThatAreMovingTogether, ! this.doNotOpenReversedPositionsThatHaveJustBeenClosed, this.numDaysForOscillatingPeriod, this.numDaysOfStayingOnTheMarket, ! this.minLevelForOversoldThreshold, this.maxLevelForOversoldThreshold, this.minLevelForOverboughtThreshold, *************** *** 171,184 **** this.symmetricalThresholds, this.overboughtMoreThanOversoldForFixedPortfolio, ! this.numDaysBetweenEachOptimization, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, this.minimumAcceptableGain); ! } ! ! protected void saveScriptResults_saveScriptFeaturesToLogFile(string nameForScriptFiles) { ! string pathFile = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + ! "\\" + this.ScriptName + "\\" + nameForScriptFiles + ".txt"; StreamWriter w = File.AppendText(pathFile); w.WriteLine ("\n----------------------------------------------\r\n"); --- 171,185 ---- this.symmetricalThresholds, this.overboughtMoreThanOversoldForFixedPortfolio, ! this.numDaysBetweenEachOptimization, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, this.minimumAcceptableGain); ! } ! ! protected void saveScriptResults_saveScriptFeaturesToLogFile(string nameForScriptFiles) { ! string pathFile = ! System.Configuration.ConfigurationManager.AppSettings["ReportsArchive"] + ! "\\" + this.ScriptName + "\\" + nameForScriptFiles + ".txt"; StreamWriter w = File.AppendText(pathFile); w.WriteLine ("\n----------------------------------------------\r\n"); *************** *** 223,273 **** // Update the underlying file. w.Flush(); ! w.Close(); } ! public override void SaveScriptResults() ! { ! string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Second.ToString().PadLeft(2,'0') + "_" + ! this.scriptName + "GenOS_" + this.numOfDifferentGenomesToEvaluateOutOfSample + ! "_OsDays_" + numDaysForOscillatingPeriod + ! "_From_" + this.tickerGroupID + "_" + this.numberOfEligibleTickers + ! "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tick" + ! this.numberOfTickersToBeChosen + "GenN°" + ! this.generationNumberForGeneticOptimizer + ! "PopSize" + this.populationSizeForGeneticOptimizer + ! Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = System.Configuration.ConfigurationSettings.AppSettings["GenomesArchive"] + ! "\\" + this.ScriptName + "\\"; ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); ! if( this.PathOfFileContainingGenomes == null ) ! { ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! } ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), ! this.benchmark, ! new HistoricalAdjustedQuoteProvider()); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".qPr"); ! this.saveScriptResults_saveScriptFeaturesToLogFile(fileName); ! this.endOfDayTimer.Stop(); ! } ! ! ! #endregion } } --- 224,277 ---- // Update the underlying file. w.Flush(); ! w.Close(); } ! public override void SaveScriptResults() ! { ! string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Second.ToString().PadLeft(2,'0') + "_" + ! this.scriptName + "GenOS_" + this.numOfDifferentGenomesToEvaluateOutOfSample + ! "_OsDays_" + numDaysForOscillatingPeriod + ! "_From_" + this.tickerGroupID + "_" + this.numberOfEligibleTickers + ! "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tick" + ! this.numberOfTickersToBeChosen + "GenN°" + ! this.generationNumberForGeneticOptimizer + ! "PopSize" + this.populationSizeForGeneticOptimizer + ! Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = ! System.Configuration.ConfigurationManager.AppSettings["ReportsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = ! System.Configuration.ConfigurationManager.AppSettings["GenomesArchive"] + ! "\\" + this.ScriptName + "\\"; ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); ! if( this.PathOfFileContainingGenomes == null ) ! { ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! } ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), ! this.benchmark, ! new HistoricalAdjustedQuoteProvider()); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".qPr"); ! this.saveScriptResults_saveScriptFeaturesToLogFile(fileName); ! this.endOfDayTimer.Stop(); ! } ! ! ! #endregion } } Index: RunBiasedPVO_OTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/RunBiasedPVO_OTC.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunBiasedPVO_OTC.cs 9 Mar 2008 22:40:51 -0000 1.2 --- RunBiasedPVO_OTC.cs 19 Aug 2008 17:13:03 -0000 1.3 *************** *** 184,192 **** "PopSize" + this.populationSizeForGeneticOptimizer + Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = System.Configuration.ConfigurationSettings.AppSettings["GenomesArchive"] + "\\" + this.ScriptName + "\\"; --- 184,195 ---- "PopSize" + this.populationSizeForGeneticOptimizer + Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = ! System.Configuration.ConfigurationManager.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = ! System.Configuration.ConfigurationManager.AppSettings["GenomesArchive"] + "\\" + this.ScriptName + "\\"; |