[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-08-19 17:13:51
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3611/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO Modified Files: RunWeightedPVO.cs Log Message: - the code has been cleaned up to avoid warnings - standard indentation has been applied Index: RunWeightedPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/RunWeightedPVO.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunWeightedPVO.cs 14 Jan 2008 23:07:04 -0000 1.2 --- RunWeightedPVO.cs 19 Aug 2008 17:13:13 -0000 1.3 *************** *** 3,7 **** RunWeightedPVO.cs ! Copyright (C) 2006 Marco Milletti --- 3,7 ---- RunWeightedPVO.cs ! Copyright (C) 2006 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; --- 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; *************** *** 36,40 **** using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 36,40 ---- using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 47,192 **** /// <summary> /// Script that implements an oscillating strategy using weights for tickers, ! /// based on the classical technical indicator ! /// RelativeStrengthIndex - RSI /// </summary> [Serializable] public class RunWeightedPVO : RunEfficientPortfolio { ! protected int minLevelForOversoldThreshold; ! protected int maxLevelForOversoldThreshold; ! protected int minLevelForOverboughtThreshold; ! protected int maxLevelForOverboughtThreshold; ! protected int divisorForThresholdComputation; ! //to be used by the optimizer ! protected int numDaysBetweenEachOptimization; ! protected double maxAcceptableCloseToCloseDrawdown; ! protected double minimumAcceptableGain; ! protected int numDaysForOscillatingPeriod; ! protected bool symmetricalThresholds = false; ! protected bool overboughtMoreThanOversoldForFixedPortfolio = false; ! ! public RunWeightedPVO(string tickerGroupID, int maxNumOfEligibleTickersForOptimization, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, ! int numDaysForOscillatingPeriod, ! 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, 0.0, ! inSamplePortfolioType, maxRunningHours) { ! this.ScriptName = "PVO_SR_WithWeights_PriceSel"; ! 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.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } ! #region auxiliary overriden methods for Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerWeightedPVO(this.tickerGroupID, this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, this.benchmark, ! this.numDaysForOscillatingPeriod, ! this.minLevelForOversoldThreshold, ! this.maxLevelForOversoldThreshold, ! this.minLevelForOverboughtThreshold, ! this.maxLevelForOverboughtThreshold, ! this.divisorForThresholdComputation, ! this.symmetricalThresholds, ! this.overboughtMoreThanOversoldForFixedPortfolio, ! this.numDaysBetweenEachOptimization, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, ! this.minimumAcceptableGain); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! protected override void run_addEventHandlers() ! { ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.endOfDayTimerHandler.MarketCloseEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); ! } ! public override void SaveScriptResults() ! { ! string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! this.scriptName + "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); ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! ! //default report with numIntervalDays = 1 ! AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), ! this.benchmark, ! new HistoricalAdjustedQuoteProvider()); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".qPr"); ! ! this.endOfDayTimer.Stop(); ! ! } ! ! ! #endregion } } --- 47,195 ---- /// <summary> /// Script that implements an oscillating strategy using weights for tickers, ! /// based on the classical technical indicator ! /// RelativeStrengthIndex - RSI /// </summary> [Serializable] public class RunWeightedPVO : RunEfficientPortfolio { ! protected int minLevelForOversoldThreshold; ! protected int maxLevelForOversoldThreshold; ! protected int minLevelForOverboughtThreshold; ! protected int maxLevelForOverboughtThreshold; ! protected int divisorForThresholdComputation; ! //to be used by the optimizer ! protected int numDaysBetweenEachOptimization; ! protected double maxAcceptableCloseToCloseDrawdown; ! protected double minimumAcceptableGain; ! protected int numDaysForOscillatingPeriod; ! protected bool symmetricalThresholds = false; ! protected bool overboughtMoreThanOversoldForFixedPortfolio = false; ! ! public RunWeightedPVO(string tickerGroupID, int maxNumOfEligibleTickersForOptimization, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, ! int numDaysForOscillatingPeriod, ! 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, 0.0, ! inSamplePortfolioType, maxRunningHours) { ! this.ScriptName = "PVO_SR_WithWeights_PriceSel"; ! 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.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } ! #region auxiliary overriden methods for Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerWeightedPVO(this.tickerGroupID, this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, this.benchmark, ! this.numDaysForOscillatingPeriod, ! this.minLevelForOversoldThreshold, ! this.maxLevelForOversoldThreshold, ! this.minLevelForOverboughtThreshold, ! this.maxLevelForOverboughtThreshold, ! this.divisorForThresholdComputation, ! this.symmetricalThresholds, ! this.overboughtMoreThanOversoldForFixedPortfolio, ! this.numDaysBetweenEachOptimization, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, ! this.minimumAcceptableGain); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! protected override void run_addEventHandlers() ! { ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.endOfDayTimerHandler.MarketCloseEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); ! } ! public override void SaveScriptResults() ! { ! string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! this.scriptName + "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); ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! ! //default report with numIntervalDays = 1 ! AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), ! this.benchmark, ! new HistoricalAdjustedQuoteProvider()); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".qPr"); ! ! this.endOfDayTimer.Stop(); ! ! } ! ! ! #endregion } } |