[Quantproject-developers] QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2006-05-14 18:10:36
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv28845/EfficientPortfolio Modified Files: RunTestingOptimizationOpenToClose.cs RunTestingOptimizationCloseToOpen.cs Log Message: Updated the way fitness out of sample is computed for the OTC and CTO strategies Index: RunTestingOptimizationOpenToClose.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio/RunTestingOptimizationOpenToClose.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RunTestingOptimizationOpenToClose.cs 7 Jan 2006 10:35:39 -0000 1.7 --- RunTestingOptimizationOpenToClose.cs 14 May 2006 18:10:31 -0000 1.8 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; + using QuantProject.ADT.Statistics; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; *************** *** 141,164 **** //Quotes tickerQuotes = new Quotes(ticker, dateOutOfSample, // dateOutOfSample); - //returnValue += // (tickerQuotes.GetFirstValidRawClose(dateOutOfSample)/ // tickerQuotes.GetFirstValidRawOpen(dateOutOfSample) - 1.0)*coefficient; ! // //returnValue is the average return for the interval between //the given market date and the numDaysAfterLastOptimizationDay - th //day after the given market date ! Quotes tickerQuotes = new Quotes(ticker, this.marketDate, dateOutOfSample); double close, open; ! for(int i = 0; i<this.numDaysAfterLastOptimizationDay; i++) ! { ! close = tickerQuotes.GetFirstValidRawClose(this.marketDate.AddDays(i)); ! open = tickerQuotes.GetFirstValidRawOpen(this.marketDate.AddDays(i)); ! returnValue += ! (close/open - 1.0)*coefficient/this.numDaysAfterLastOptimizationDay; ! ! } } return returnValue/genome.Size; --- 142,180 ---- //Quotes tickerQuotes = new Quotes(ticker, dateOutOfSample, // dateOutOfSample); //returnValue += // (tickerQuotes.GetFirstValidRawClose(dateOutOfSample)/ // tickerQuotes.GetFirstValidRawOpen(dateOutOfSample) - 1.0)*coefficient; ! //returnValue is the average return for the interval between //the given market date and the numDaysAfterLastOptimizationDay - th //day after the given market date ! //Quotes tickerQuotes = new Quotes(ticker, this.marketDate, ! // dateOutOfSample); ! //double close, open; ! //for(int i = 0; i<this.numDaysAfterLastOptimizationDay; i++) ! //{ ! //close = tickerQuotes.GetFirstValidRawClose(this.marketDate.AddDays(i)); ! //open = tickerQuotes.GetFirstValidRawOpen(this.marketDate.AddDays(i)); ! //returnValue += ! //(close/open - 1.0)*coefficient/this.numDaysAfterLastOptimizationDay; ! ! //} ! ! //returnValue is the sharpe ratio for the interval between ! //the given market date and the numDaysAfterLastOptimizationDay - th ! //day after the given market date ! Quotes tickerQuotes = new Quotes(ticker, this.marketDate, dateOutOfSample); double close, open; ! double[] returns = new double[this.numDaysAfterLastOptimizationDay]; ! for(int i = 0; i<this.numDaysAfterLastOptimizationDay; i++) ! { ! close = tickerQuotes.GetFirstValidRawClose(this.marketDate.AddDays(i)); ! open = tickerQuotes.GetFirstValidRawOpen(this.marketDate.AddDays(i)); ! returns[i] = (close/open - 1.0)*coefficient; ! } ! returnValue += BasicFunctions.SimpleAverage(returns) / BasicFunctions.StdDev(returns); } + return returnValue/genome.Size; *************** *** 260,264 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(this.marketDate); ! IGenomeManager genManEfficientOTCPortfolio = new GenomeManagerForEfficientOTCPortfolio(setOfTickersToBeOptimized, this.marketDate.AddDays(-this.numDaysForOptimization), --- 276,280 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(this.marketDate); ! IGenomeManager genManEfficientOTC = new GenomeManagerForEfficientOTCPortfolio(setOfTickersToBeOptimized, this.marketDate.AddDays(-this.numDaysForOptimization), *************** *** 268,272 **** this.portfolioType); ! this.setFitnesses_setFitnessesActually(genManEfficientOTCPortfolio); } --- 284,288 ---- this.portfolioType); ! this.setFitnesses_setFitnessesActually(genManEfficientOTC); } *************** *** 298,302 **** int differentEvaluatedGenomes = genomeCounter.TotalEvaluatedGenomes; string pathFile = System.Configuration.ConfigurationSettings.AppSettings["GenericArchive"] + ! "\\OpenToCloseOptimizationEvaluation.txt"; StreamWriter w = File.AppendText(pathFile); w.WriteLine ("\n----------------------------------------------\r\n"); --- 314,318 ---- int differentEvaluatedGenomes = genomeCounter.TotalEvaluatedGenomes; string pathFile = System.Configuration.ConfigurationSettings.AppSettings["GenericArchive"] + ! "\\OptimizationEvaluation.txt"; StreamWriter w = File.AppendText(pathFile); w.WriteLine ("\n----------------------------------------------\r\n"); *************** *** 304,312 **** w.Write("\r\nNum days for optimization {0}\r", this.numDaysForOptimization.ToString()); w.Write("\r\nOptimizing market date {0}\r", this.marketDate.ToLongDateString()); ! w.Write("\r\nMarket date for test (out of sample){0}\r", this.marketDate.AddDays(this.numDaysAfterLastOptimizationDay).ToLongDateString()); w.Write("\r\nNumber of tickers: {0}\r", this.numberOfTickersToBeChosen.ToString()); w.WriteLine ("\n----------------------------------------------"); ! w.Write("\r\nFitnesses compared: {0}\r", this.fitnessesInSample.Length.ToString()); w.Write("\r\nDifferent evaluated genomes: {0}\r", differentEvaluatedGenomes.ToString()); w.Write("\r\nAverages of the {0} sub sets of fitnesses In Sample:\r", --- 320,328 ---- w.Write("\r\nNum days for optimization {0}\r", this.numDaysForOptimization.ToString()); w.Write("\r\nOptimizing market date {0}\r", this.marketDate.ToLongDateString()); ! w.Write("\r\nMarket date for test out of sample (sharpe ratio as fitness OS){0}\r", this.marketDate.AddDays(this.numDaysAfterLastOptimizationDay).ToLongDateString()); w.Write("\r\nNumber of tickers: {0}\r", this.numberOfTickersToBeChosen.ToString()); w.WriteLine ("\n----------------------------------------------"); ! w.Write("\r\nFitnesses compared (sharpe r. OTC): {0}\r", this.fitnessesInSample.Length.ToString()); w.Write("\r\nDifferent evaluated genomes: {0}\r", differentEvaluatedGenomes.ToString()); w.Write("\r\nAverages of the {0} sub sets of fitnesses In Sample:\r", Index: RunTestingOptimizationCloseToOpen.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio/RunTestingOptimizationCloseToOpen.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunTestingOptimizationCloseToOpen.cs 8 Jan 2006 23:36:05 -0000 1.1 --- RunTestingOptimizationCloseToOpen.cs 14 May 2006 18:10:31 -0000 1.2 *************** *** 27,30 **** --- 27,31 ---- using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; + using QuantProject.ADT.Statistics; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; *************** *** 120,134 **** //the given market date and the numDaysAfterLastOptimizationDay - th //day after the given market date ! Quotes tickerQuotes = new Quotes(ticker, this.marketDate, ! dateOutOfSample); ! double close, open; ! for(int i = 0; i<this.numDaysAfterLastOptimizationDay; i++) ! { ! close = tickerQuotes.GetFirstValidAdjustedClose(this.marketDate.AddDays(i)); ! open = tickerQuotes.GetFirstValidAdjustedOpen(this.marketDate.AddDays(i+1)); ! returnValue += ! (open/close - 1.0)*coefficient/this.numDaysAfterLastOptimizationDay; ! } } return returnValue/genome.Size; --- 121,150 ---- //the given market date and the numDaysAfterLastOptimizationDay - th //day after the given market date ! //Quotes tickerQuotes = new Quotes(ticker, this.marketDate, ! // dateOutOfSample); ! //double close, open; ! //for(int i = 0; i<this.numDaysAfterLastOptimizationDay; i++) ! //{ ! //close = tickerQuotes.GetFirstValidAdjustedClose(this.marketDate.AddDays(i)); ! //open = tickerQuotes.GetFirstValidAdjustedOpen(this.marketDate.AddDays(i+1)); ! //returnValue += ! //(open/close - 1.0)*coefficient/this.numDaysAfterLastOptimizationDay; ! //} ! ! //returnValue is the sharpe ratio for the interval between ! //the given market date and the numDaysAfterLastOptimizationDay - th ! //day after the given market date ! Quotes tickerQuotes = new Quotes(ticker, this.marketDate, ! dateOutOfSample); ! double close, open; ! double[] returns = new double[this.numDaysAfterLastOptimizationDay]; ! for(int i = 0; i<this.numDaysAfterLastOptimizationDay; i++) ! { ! close = tickerQuotes.GetFirstValidAdjustedClose(this.marketDate.AddDays(i)); ! open = tickerQuotes.GetFirstValidAdjustedOpen(this.marketDate.AddDays(i+1)); ! returns[i] = (open/close - 1.0)*coefficient; ! } ! returnValue += BasicFunctions.SimpleAverage(returns) / BasicFunctions.StdDev(returns); } return returnValue/genome.Size; *************** *** 269,273 **** int differentEvaluatedGenomes = genomeCounter.TotalEvaluatedGenomes; string pathFile = System.Configuration.ConfigurationSettings.AppSettings["GenericArchive"] + ! "\\CloseToOpenOptimizationEvaluation.txt"; StreamWriter w = File.AppendText(pathFile); w.WriteLine ("\n----------------------------------------------\r\n"); --- 285,289 ---- int differentEvaluatedGenomes = genomeCounter.TotalEvaluatedGenomes; string pathFile = System.Configuration.ConfigurationSettings.AppSettings["GenericArchive"] + ! "\\OptimizationEvaluation.txt"; StreamWriter w = File.AppendText(pathFile); w.WriteLine ("\n----------------------------------------------\r\n"); *************** *** 275,283 **** w.Write("\r\nNum days for optimization {0}\r", this.numDaysForOptimization.ToString()); w.Write("\r\nOptimizing market date {0}\r", this.marketDate.ToLongDateString()); ! w.Write("\r\nMarket date for test (out of sample){0}\r", this.marketDate.AddDays(this.numDaysAfterLastOptimizationDay).ToLongDateString()); w.Write("\r\nNumber of tickers: {0}\r", this.numberOfTickersToBeChosen.ToString()); w.WriteLine ("\n----------------------------------------------"); ! w.Write("\r\nFitnesses compared: {0}\r", this.fitnessesInSample.Length.ToString()); w.Write("\r\nDifferent evaluated genomes: {0}\r", differentEvaluatedGenomes.ToString()); w.Write("\r\nAverages of the {0} sub sets of fitnesses In Sample:\r", --- 291,299 ---- w.Write("\r\nNum days for optimization {0}\r", this.numDaysForOptimization.ToString()); w.Write("\r\nOptimizing market date {0}\r", this.marketDate.ToLongDateString()); ! w.Write("\r\nMarket date for test out of sample (sharpe ratio as fitness OS){0}\r", this.marketDate.AddDays(this.numDaysAfterLastOptimizationDay).ToLongDateString()); w.Write("\r\nNumber of tickers: {0}\r", this.numberOfTickersToBeChosen.ToString()); w.WriteLine ("\n----------------------------------------------"); ! w.Write("\r\nFitnesses compared (sharpe ratio CTO): {0}\r", this.fitnessesInSample.Length.ToString()); w.Write("\r\nDifferent evaluated genomes: {0}\r", differentEvaluatedGenomes.ToString()); w.Write("\r\nAverages of the {0} sub sets of fitnesses In Sample:\r", |