[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting RunTestOptimizedCTCPortfoli
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-11-17 21:37:33
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18464/b7_Scripts/TickerSelectionTesting Modified Files: RunTestOptimizedCTCPortfolio.cs RunEfficientCTOPortfolio.cs RunEfficientCTCPortfolio.cs GenomeManagerForWeightedEfficientPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientCTCPortfolio.cs EndOfDayTimerHandlerCTCTest.cs EndOfDayTimerHandlerCTC.cs Log Message: Updated script files Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GenomeManagerForEfficientCTOPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.14 --- GenomeManagerForEfficientCTOPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.15 *************** *** 97,104 **** */ ! protected override double getFitnessValue_calculate() ! { ! return this.RateOfReturn/Math.Sqrt(this.Variance); ! } --- 97,104 ---- */ ! // protected override double getFitnessValue_calculate() ! // { ! // return this.RateOfReturn/Math.Sqrt(this.Variance); ! // } Index: RunEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTCPortfolio.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RunEfficientCTCPortfolio.cs 18 Sep 2005 21:13:36 -0000 1.11 --- RunEfficientCTCPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.12 *************** *** 62,65 **** --- 62,66 ---- protected int numDaysForReturnCalculation; protected double maxAcceptableCloseToCloseDrawdown; + protected int numDaysBetweenEachOptimization; public RunEfficientCTCPortfolio(string tickerGroupID, int numberOfEligibleTickers, *************** *** 71,75 **** double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, --- 72,76 ---- double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, *************** *** 79,86 **** portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScripts"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; } --- 80,89 ---- portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScriptsDiscontinuos"; ! //this.ScriptName = "CloseToCloseScriptsDiscontinuosWithCoeff"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; + this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } *************** *** 96,100 **** this.numDayOfPortfolioLife, this.numDaysForReturnCalculation, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } --- 99,104 ---- this.numDayOfPortfolioLife, this.numDaysForReturnCalculation, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, ! this.numDaysBetweenEachOptimization); } Index: RunTestOptimizedCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunTestOptimizedCTCPortfolio.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RunTestOptimizedCTCPortfolio.cs 18 Sep 2005 21:13:36 -0000 1.7 --- RunTestOptimizedCTCPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.8 *************** *** 69,73 **** double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, --- 69,73 ---- double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, *************** *** 78,82 **** targetReturn, portfolioType, maxAcceptableCloseToCloseDrawdown, ! maxRunningHours) { this.ScriptName = "TestOptimizedCTCPortfolio"; --- 78,82 ---- targetReturn, portfolioType, maxAcceptableCloseToCloseDrawdown, ! maxRunningHours, numDaysBetweenEachOptimization) { this.ScriptName = "TestOptimizedCTCPortfolio"; *************** *** 94,98 **** this.numDaysForReturnCalculation, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } --- 94,99 ---- this.numDaysForReturnCalculation, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, ! this.numDaysBetweenEachOptimization); } Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GenomeManagerForEfficientCTCPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.10 --- GenomeManagerForEfficientCTCPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.11 *************** *** 62,84 **** this.retrieveData(); } protected override float[] getArrayOfRatesOfReturn(string ticker) { ! float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); returnValue = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; int i = 0; //index for ratesOfReturns array ! for(int idx = 0; idx + this.numDaysForReturnCalculation < allAdjValues.Length; idx += this.numDaysForReturnCalculation ) ! { ! returnValue[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ ! allAdjValues[idx] - 1); ! i++; ! } this.numberOfExaminedReturns = returnValue.Length; return returnValue; } ! /* protected override double getFitnessValue_calculate() { --- 62,131 ---- this.retrieveData(); } + // old implementation, where a "continuos" adjusted close to close ratio, + // based on a particular fixed interval of days, is considered + // In this case, there is no discontinuity between the returned ratesOfReturn + // + // protected override float[] getArrayOfRatesOfReturn(string ticker) + // { + // float[] returnValue = null; + // Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); + // float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); + // returnValue = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; + // int i = 0; //index for ratesOfReturns array + // for(int idx = 0; idx + this.numDaysForReturnCalculation < allAdjValues.Length; idx += this.numDaysForReturnCalculation ) + // { + // returnValue[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ + // allAdjValues[idx] - 1); + // i++; + // } + // this.numberOfExaminedReturns = returnValue.Length; + // + // return returnValue; + // } + // new implementation, where a "discontinuos" adjusted close to close ratio, + // based on a particular fixed interval of days, is considered + // In this case, there is a discontinuity between each pair of ratesOfReturn, + // equal to the given interval of days protected override float[] getArrayOfRatesOfReturn(string ticker) { ! /* ! float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); returnValue = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; int i = 0; //index for ratesOfReturns array ! int lastIdxAccessed = 0; ! for(int idx = 0; ! (idx + this.numDaysForReturnCalculation) < allAdjValues.Length; ! idx += this.numDaysForReturnCalculation ) ! { ! if(idx-lastIdxAccessed>numDaysForReturnCalculation || idx == 0) ! //there is a discontinuity, as wanted ! { ! returnValue[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ ! allAdjValues[idx] - 1); ! lastIdxAccessed = idx; ! i++; ! } ! } this.numberOfExaminedReturns = returnValue.Length; return returnValue; + */ + float[] returnValue = null; + returnValue = + QuantProject.Data.DataTables.Quotes.GetArrayOfCloseToCloseRatios(ticker, + this.firstQuoteDate, + this.lastQuoteDate, + this.numDaysForReturnCalculation); + + this.numberOfExaminedReturns = returnValue.Length; + + return returnValue; + } ! ! /*LPM as fitness protected override double getFitnessValue_calculate() { Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** EndOfDayTimerHandlerCTC.cs 8 Nov 2005 18:36:48 -0000 1.17 --- EndOfDayTimerHandlerCTC.cs 17 Nov 2005 21:37:19 -0000 1.18 *************** *** 47,54 **** --- 47,57 ---- protected int numDaysForReturnCalculation; protected int daysCounter; + protected int daysWithNoPositions; protected double maxAcceptableCloseToCloseDrawdown; protected bool stopLossConditionReached; protected double currentAccountValue; protected double previousAccountValue; + protected int numDaysBetweenEachOptimization; + private int numDaysElapsedSinceLastOptimization; public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, *************** *** 61,65 **** int numDaysForReturnCalculation, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, --- 64,69 ---- int numDaysForReturnCalculation, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, *************** *** 76,79 **** --- 80,84 ---- this.currentAccountValue = 0.0; this.previousAccountValue = 0.0; + this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } *************** *** 101,105 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! bool positionsJustClosed = false; this.updateStopLossCondition(); if(this.account.Portfolio.Count > 0) --- 106,110 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! //bool positionsJustClosed = false; this.updateStopLossCondition(); if(this.account.Portfolio.Count > 0) *************** *** 114,129 **** this.closePositions(); this.daysCounter = 0; ! positionsJustClosed = true; } } ! ! if(this.account.Portfolio.Count == 0 && ! !positionsJustClosed) ! //portfolio is empty but it has not been closed ! //at the current close { ! this.openPositions(); ! this.daysCounter = 0; ! } } --- 119,145 ---- this.closePositions(); this.daysCounter = 0; ! //positionsJustClosed = true; } } ! //old ! // if(this.account.Portfolio.Count == 0 && ! // !positionsJustClosed) ! // //portfolio is empty but it has not been closed ! // //at the current close ! // { ! // this.openPositions(); ! // this.daysCounter = 0; ! // } ! ! if(this.account.Portfolio.Count == 0) ! //portfolio is empty { ! this.daysWithNoPositions++; ! if(this.daysWithNoPositions>this.numDaysOfPortfolioLife) ! { ! this.openPositions(); ! this.daysWithNoPositions = 0; ! } ! } } *************** *** 136,141 **** SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! ! this.eligibleTickers = temporizedGroup.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, --- 152,168 ---- SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! ! SelectorByCloseToCloseCorrelationToBenchmark lessCorrelatedFromTemporized = ! new SelectorByCloseToCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), ! this.benchmark,true, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! currentDate, ! this.numberOfEligibleTickers, ! this.numDaysForReturnCalculation); ! ! ! ! ! this.eligibleTickers = lessCorrelatedFromTemporized.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, *************** *** 194,202 **** { ConstantsProvider.SeedForRandomGenerator++; ! if(this.account.Portfolio.Count == 0 ) { - this.orders.Clear(); this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! //it sets tickers to be chosen at next close } } --- 221,243 ---- { ConstantsProvider.SeedForRandomGenerator++; ! //old ! // if(this.account.Portfolio.Count == 0 ) ! // { ! // this.orders.Clear(); ! // this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! // //it sets tickers to be chosen at next close ! // } ! this.orders.Clear(); ! //this.oneHourAfterMarketCloseEventHandler_updatePrices(); ! if(this.numDaysElapsedSinceLastOptimization == ! this.numDaysBetweenEachOptimization - 1) { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! //sets tickers to be chosen next Market Open event ! this.numDaysElapsedSinceLastOptimization = 0; ! } ! else ! { ! this.numDaysElapsedSinceLastOptimization++; } } Index: GenomeManagerForWeightedEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForWeightedEfficientPortfolio.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenomeManagerForWeightedEfficientPortfolio.cs 8 Nov 2005 18:34:02 -0000 1.1 --- GenomeManagerForWeightedEfficientPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.2 *************** *** 123,132 **** #endregion - public override Genome[] GetChilds(Genome parent1, Genome parent2) - { - return - GenomeManipulator.MixGenesWithoutDuplicates(parent1, parent2); - } - public override int GetNewGeneValue(Genome genome, int genePosition) { --- 123,126 ---- Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** RunEfficientCTOPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.23 --- RunEfficientCTOPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.24 *************** *** 71,76 **** portfolioType, maxRunningHours) { ! this.ScriptName = "OpenCloseScriptsSharpeRatioWithCoeff"; //this.ScriptName = "OpenCloseScriptsSharpeRatio"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } --- 71,77 ---- portfolioType, maxRunningHours) { ! //this.ScriptName = "OpenCloseScriptsSharpeRatioWithCoeff"; //this.ScriptName = "OpenCloseScriptsSharpeRatio"; + this.ScriptName = "OpenCloseScriptsWithCoeff"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } Index: EndOfDayTimerHandlerCTCTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCTest.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerCTCTest.cs 18 Sep 2005 21:13:36 -0000 1.4 --- EndOfDayTimerHandlerCTCTest.cs 17 Nov 2005 21:37:19 -0000 1.5 *************** *** 56,60 **** int numDaysForReturnCalculation, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, --- 56,61 ---- int numDaysForReturnCalculation, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, *************** *** 66,70 **** numDaysForReturnCalculation, targetReturn, ! portfolioType, maxAcceptableCloseToCloseDrawdown) { --- 67,72 ---- numDaysForReturnCalculation, targetReturn, ! portfolioType, maxAcceptableCloseToCloseDrawdown, ! numDaysBetweenEachOptimization) { |