[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination LinearCombi
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2008-01-14 23:41:48
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22669/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: LinearCombinationTest.cs MainForm.cs TestDisplayer.cs Log Message: Updated classes for single genomes testing Index: MainForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/MainForm.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** MainForm.cs 3 Aug 2006 21:15:57 -0000 1.10 --- MainForm.cs 14 Jan 2008 23:41:44 -0000 1.11 *************** *** 235,239 **** this.numberOfTickersToBeChosen, this.targetReturn, ! this.portfolioType); this.GO = new GeneticOptimizer(genManEfficientOTCPortfolio, --- 235,240 ---- this.numberOfTickersToBeChosen, this.targetReturn, ! this.portfolioType, ! this.benchmark); this.GO = new GeneticOptimizer(genManEfficientOTCPortfolio, Index: LinearCombinationTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/LinearCombinationTest.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** LinearCombinationTest.cs 29 Aug 2007 09:43:36 -0000 1.12 --- LinearCombinationTest.cs 14 Jan 2008 23:41:44 -0000 1.13 *************** *** 52,55 **** --- 52,58 ---- private double stopLoss; private double takeProfit; + private double oversoldThreshold; + private double overboughtThreshold; + private bool setDirectlyThresholdLevels; private IHistoricalQuoteProvider historicalQuoteProvider; *************** *** 58,61 **** --- 61,83 ---- private IEndOfDayStrategy endOfDayStrategy; private PortfolioType portfolioType; + + private void linearCombinationTest_commonInitialization(DateTime firstDate , DateTime lastDate , + GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, + PortfolioType portfolioType, int numDaysForOscillatorStrategy, + double stopLoss, double takeProfit, + double oversoldThreshold, double overboughtThreshold, bool setDirectlyThresholdLevels) + { + this.firstDate = firstDate; + this.lastDate = lastDate; + this.genomeRepresentations = genomeRepresentations; + this.strategyType = strategyType; + this.portfolioType = portfolioType; + this.numDaysForOscillatorStrategy = numDaysForOscillatorStrategy; + this.stopLoss = stopLoss; + this.takeProfit = takeProfit; + this.oversoldThreshold = oversoldThreshold; + this.overboughtThreshold = overboughtThreshold; + this.setDirectlyThresholdLevels = setDirectlyThresholdLevels; + } public LinearCombinationTest( DateTime firstDate , DateTime lastDate , *************** *** 63,72 **** PortfolioType portfolioType) { ! this.firstDate = firstDate; ! this.lastDate = lastDate; ! this.genomeRepresentations = genomeRepresentations; ! // this.openToCloseDaily = openToCloseDaily; ! this.strategyType = strategyType; ! this.portfolioType = portfolioType; } --- 85,90 ---- PortfolioType portfolioType) { ! this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, 0,0,0,0,0,false); } *************** *** 76,87 **** int numDaysForOscillatorStrategy) { ! this.firstDate = firstDate; ! this.lastDate = lastDate; ! this.genomeRepresentations = genomeRepresentations; ! // this.openToCloseDaily = openToCloseDaily; ! this.strategyType = strategyType; ! this.portfolioType = portfolioType; ! this.numDaysForOscillatorStrategy = numDaysForOscillatorStrategy; } public LinearCombinationTest( DateTime firstDate , DateTime lastDate , GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, --- 94,102 ---- int numDaysForOscillatorStrategy) { ! this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! 0,0,0,0,false); } + public LinearCombinationTest( DateTime firstDate , DateTime lastDate , GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, *************** *** 89,102 **** int numDaysForOscillatorStrategy, double stopLoss, double takeProfit) { ! this.firstDate = firstDate; ! this.lastDate = lastDate; ! this.genomeRepresentations = genomeRepresentations; ! // this.openToCloseDaily = openToCloseDaily; ! this.strategyType = strategyType; ! this.portfolioType = portfolioType; ! this.numDaysForOscillatorStrategy = numDaysForOscillatorStrategy; ! this.stopLoss = stopLoss; ! this.takeProfit = takeProfit; } private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) --- 104,122 ---- int numDaysForOscillatorStrategy, double stopLoss, double takeProfit) { ! this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! stopLoss, takeProfit, 0,0,false); } + public LinearCombinationTest( DateTime firstDate , DateTime lastDate , + GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, + PortfolioType portfolioType, + int numDaysForOscillatorStrategy, double stopLoss, double takeProfit, + double oversoldThreshold, double overboughtThreshold, bool setDirectlyThresholdLevels) + { + this.linearCombinationTest_commonInitialization( firstDate, lastDate, + genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, + stopLoss, takeProfit, oversoldThreshold, overboughtThreshold, + setDirectlyThresholdLevels); + } private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) *************** *** 115,151 **** } ! private void run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy() ! { ! WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! for(int i = 0; i<this.genomeRepresentations.Length;i++) ! { ! weightedPositions[i] = ! new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! ! } ! ! this.endOfDayStrategy = new FixedLevelOscBiasedOTC_PVONoThresholdsStrategy( ! this.account , weightedPositions, ! this.genomeRepresentations.Length); ! } ! private void run_setStrategy_setBiasedPVONoThresholdsStrategy() ! { ! WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! for(int i = 0; i<this.genomeRepresentations.Length;i++) ! { ! weightedPositions[i] = ! new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! ! } ! this.endOfDayStrategy = new FixedLevelOscillatorBiasedPVONoThresholdsStrategy( ! this.account , weightedPositions, ! this.genomeRepresentations.Length, ! this.stopLoss, ! this.takeProfit); ! } private void run_setStrategy_setBiasedPVOStrategy() { --- 135,192 ---- } ! // private void run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy() ! // { ! // WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! // for(int i = 0; i<this.genomeRepresentations.Length;i++) ! // { ! // weightedPositions[i] = ! // new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! // new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! // ! // } ! // ! // this.endOfDayStrategy = new FixedLevelOscBiasedOTC_PVONoThresholdsStrategy( ! // this.account , weightedPositions, ! // this.genomeRepresentations.Length); ! // } ! // private void run_setStrategy_setBiasedPVONoThresholdsStrategy() ! // { ! // WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! // for(int i = 0; i<this.genomeRepresentations.Length;i++) ! // { ! // weightedPositions[i] = ! // new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! // new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! // ! // } ! // this.endOfDayStrategy = new FixedLevelOscillatorBiasedPVONoThresholdsStrategy( ! // this.account , weightedPositions, ! // this.genomeRepresentations.Length, ! // this.stopLoss, ! // this.takeProfit); ! // } + private double run_setStrategy_setBiasedPVOStrategy_getOversoldThreshold(int i) + { + double returnValue; + if(this.setDirectlyThresholdLevels) + returnValue = this.oversoldThreshold; + else + returnValue = this.genomeRepresentations[i].OversoldThreshold; + + return returnValue; + } + private double run_setStrategy_setBiasedPVOStrategy_getOverboughtThreshold(int i) + { + double returnValue; + if(this.setDirectlyThresholdLevels) + returnValue = this.overboughtThreshold; + else + returnValue = this.genomeRepresentations[i].OverboughtThreshold; + + return returnValue; + } + private void run_setStrategy_setBiasedPVOStrategy() { *************** *** 158,163 **** new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! oversoldThresholds[i] = this.genomeRepresentations[i].OversoldThreshold; ! overboughtThresholds[i] = this.genomeRepresentations[i].OverboughtThreshold; } --- 199,204 ---- new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! oversoldThresholds[i] = this.run_setStrategy_setBiasedPVOStrategy_getOversoldThreshold(i); ! overboughtThresholds[i] = this.run_setStrategy_setBiasedPVOStrategy_getOverboughtThreshold(i); } *************** *** 223,233 **** break; ! case StrategyType.PortfolioValueOscillatorBiasedNoThresholds: ! this.run_setStrategy_setBiasedPVONoThresholdsStrategy(); ! break; ! ! case StrategyType.OTC_PVOBiasedNoThresholds: ! this.run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy(); ! break; } } --- 264,274 ---- break; ! // case StrategyType.PortfolioValueOscillatorBiasedNoThresholds: ! // this.run_setStrategy_setBiasedPVONoThresholdsStrategy(); ! // break; ! // ! // case StrategyType.OTC_PVOBiasedNoThresholds: ! // this.run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy(); ! // break; } } *************** *** 262,265 **** --- 303,321 ---- } + private void run_addEquityLineForEachPositionInWeightedPositions( + WeightedPositions weightedPositions , Color color , Report report ) + { + foreach(WeightedPosition position in weightedPositions.Values) + { + WeightedPositions wp = new WeightedPositions(new SignedTickers( + position.Ticker)); + EquityLine equityLineForWeightedPositions = + wp.GetVirtualEquityLine( + 15000 , report.AccountReport.EquityLine ); + report.AddEquityLine( equityLineForWeightedPositions , + color ); + } + } + private WeightedPositions run_getWeightedPositions(GenomeRepresentation genomeRepresentation) *************** *** 313,324 **** new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^GSPC"); ! WeightedPositions weightedPositions = ! this.run_getWeightedPositions(this.genomeRepresentations[0]); ! this.run_addEquityLineForWeightedPositions(weightedPositions, Color.Brown, ! report); ! ! // ObjectArchiver.Archive( report.AccountReport , ! // @"C:\Documents and Settings\Glauco\Desktop\reports\runOneRank.qPr" ); ! report.Text = this.run_getReportTitle(); report.Show(); } --- 369,386 ---- new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^GSPC"); ! foreach(GenomeRepresentation genomeRepresentation in this.genomeRepresentations) ! { ! WeightedPositions weightedPositions = this.run_getWeightedPositions( genomeRepresentation ); ! this.run_addEquityLineForWeightedPositions( ! weightedPositions, ! Color.Brown, ! report); ! this.run_addEquityLineForEachPositionInWeightedPositions( ! weightedPositions, ! Color.DimGray, ! report); ! ! } ! report.Text = this.run_getReportTitle(); report.Show(); } Index: TestDisplayer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/TestDisplayer.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TestDisplayer.cs 29 Aug 2007 10:05:29 -0000 1.13 --- TestDisplayer.cs 14 Jan 2008 23:41:44 -0000 1.14 *************** *** 69,72 **** --- 69,77 ---- private System.Windows.Forms.RadioButton radioButtonPVOBiasedNoThresholds; private System.Windows.Forms.RadioButton radioButtonOTCPVOBiasedNoThresholds; + private System.Windows.Forms.TextBox textBoxOversoldThreshold; + private System.Windows.Forms.TextBox textBoxOverboughtThreshold; + private System.Windows.Forms.Label labelOversoldThreshold; + private System.Windows.Forms.Label labelOverboughtThreshold; + private System.Windows.Forms.CheckBox checkBoxSetDirectlyThresholdLevels; private System.Windows.Forms.ComboBox comboBoxPortfolioType; *************** *** 220,223 **** --- 225,233 ---- this.radioButtonPVOBiasedNoThresholds = new System.Windows.Forms.RadioButton(); this.radioButtonOTCPVOBiasedNoThresholds = new System.Windows.Forms.RadioButton(); + this.textBoxOversoldThreshold = new System.Windows.Forms.TextBox(); + this.textBoxOverboughtThreshold = new System.Windows.Forms.TextBox(); + this.labelOversoldThreshold = new System.Windows.Forms.Label(); + this.labelOverboughtThreshold = new System.Windows.Forms.Label(); + this.checkBoxSetDirectlyThresholdLevels = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); this.SuspendLayout(); *************** *** 419,422 **** --- 429,472 ---- this.radioButtonOTCPVOBiasedNoThresholds.CheckedChanged += new System.EventHandler(this.radioButtonOTCPVOBiasedNoThresholds_CheckedChanged); // + // textBoxOversoldThreshold + // + this.textBoxOversoldThreshold.Location = new System.Drawing.Point(504, 216); + this.textBoxOversoldThreshold.Name = "textBoxOversoldThreshold"; + this.textBoxOversoldThreshold.Size = new System.Drawing.Size(40, 20); + this.textBoxOversoldThreshold.TabIndex = 23; + this.textBoxOversoldThreshold.Text = "0.01"; + // + // textBoxOverboughtThreshold + // + this.textBoxOverboughtThreshold.Location = new System.Drawing.Point(656, 216); + this.textBoxOverboughtThreshold.Name = "textBoxOverboughtThreshold"; + this.textBoxOverboughtThreshold.Size = new System.Drawing.Size(40, 20); + this.textBoxOverboughtThreshold.TabIndex = 24; + this.textBoxOverboughtThreshold.Text = "0.01"; + // + // labelOversoldThreshold + // + this.labelOversoldThreshold.Location = new System.Drawing.Point(424, 216); + this.labelOversoldThreshold.Name = "labelOversoldThreshold"; + this.labelOversoldThreshold.Size = new System.Drawing.Size(80, 16); + this.labelOversoldThreshold.TabIndex = 25; + this.labelOversoldThreshold.Text = "OvSold thresh."; + // + // labelOverboughtThreshold + // + this.labelOverboughtThreshold.Location = new System.Drawing.Point(552, 216); + this.labelOverboughtThreshold.Name = "labelOverboughtThreshold"; + this.labelOverboughtThreshold.Size = new System.Drawing.Size(96, 16); + this.labelOverboughtThreshold.TabIndex = 26; + this.labelOverboughtThreshold.Text = "OvBought thresh."; + // + // checkBoxSetDirectlyThresholdLevels + // + this.checkBoxSetDirectlyThresholdLevels.Location = new System.Drawing.Point(432, 184); + this.checkBoxSetDirectlyThresholdLevels.Name = "checkBoxSetDirectlyThresholdLevels"; + this.checkBoxSetDirectlyThresholdLevels.Size = new System.Drawing.Size(232, 24); + this.checkBoxSetDirectlyThresholdLevels.TabIndex = 27; + this.checkBoxSetDirectlyThresholdLevels.Text = "set directly threshold-levels"; + // // TestDisplayer // *************** *** 424,427 **** --- 474,482 ---- this.ClientSize = new System.Drawing.Size(704, 414); this.Controls.AddRange(new System.Windows.Forms.Control[] { + this.checkBoxSetDirectlyThresholdLevels, + this.labelOverboughtThreshold, + this.labelOversoldThreshold, + this.textBoxOverboughtThreshold, + this.textBoxOversoldThreshold, this.radioButtonOTCPVOBiasedNoThresholds, this.radioButtonPVOBiasedNoThresholds, *************** *** 515,519 **** this.selectedStrategyType, (PortfolioType)this.comboBoxPortfolioType.SelectedItem, Convert.ToInt32(this.textBoxDaysFPOscillatorAndRevOneRank.Text), ! Convert.ToDouble(this.textBoxStopLoss.Text),Convert.ToDouble(this.textBoxTakeProfit.Text) ); linearCombinationTest.Run(); this.lastSelectedGenomeRepresentations = genomeRepresentations; --- 570,577 ---- this.selectedStrategyType, (PortfolioType)this.comboBoxPortfolioType.SelectedItem, Convert.ToInt32(this.textBoxDaysFPOscillatorAndRevOneRank.Text), ! Convert.ToDouble(this.textBoxStopLoss.Text),Convert.ToDouble(this.textBoxTakeProfit.Text), ! Convert.ToDouble(this.textBoxOversoldThreshold.Text), ! Convert.ToDouble(this.textBoxOverboughtThreshold.Text), ! this.checkBoxSetDirectlyThresholdLevels.Checked); linearCombinationTest.Run(); this.lastSelectedGenomeRepresentations = genomeRepresentations; |