[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting RunTestOptimizedCTOPortfoli
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27724/b7_Scripts/TickerSelectionTesting Modified Files: RunTestOptimizedCTOPortfolio.cs RunTestOptimizedCTCPortfolio.cs RunEfficientPortfolio.cs RunEfficientCTOPortfolio.cs RunEfficientCTCPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientCTCPortfolio.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandlerCTCTest.cs EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandler.cs Log Message: Updated script files for the efficient portfolio Index: RunTestOptimizedCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunTestOptimizedCTOPortfolio.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RunTestOptimizedCTOPortfolio.cs 18 Sep 2005 21:13:36 -0000 1.9 --- RunTestOptimizedCTOPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.10 *************** *** 69,73 **** numDaysBetweenEachOptimization) { ! this.ScriptName = "TestOptimizedCTOPortfolio"; } --- 69,74 ---- numDaysBetweenEachOptimization) { ! //this.ScriptName = "TestOptimizedCTOPortfolio"; ! this.ScriptName = "TestOptimizedCTOWeightedPortfolio"; } Index: EndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandler.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** EndOfDayTimerHandler.cs 8 Nov 2005 18:36:48 -0000 1.18 --- EndOfDayTimerHandler.cs 28 Dec 2005 23:29:40 -0000 1.19 *************** *** 63,67 **** //backtest, for minimizing commission amount, //according to broker's commission scheme ! protected double minPriceForMinimumCommission = 0; protected double maxPriceForMinimumCommission = 500; --- 63,67 ---- //backtest, for minimizing commission amount, //according to broker's commission scheme ! protected double minPriceForMinimumCommission = 30; protected double maxPriceForMinimumCommission = 500; *************** *** 224,228 **** //add cash first if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(17000); if(this.openPositions_allChosenTickersQuotedAtCurrentDate()) //all tickers have quotes at the current date, so orders can be filled --- 224,228 ---- //add cash first if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(30000); if(this.openPositions_allChosenTickersQuotedAtCurrentDate()) //all tickers have quotes at the current date, so orders can be filled Index: RunEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTCPortfolio.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** RunEfficientCTCPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.12 --- RunEfficientCTCPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.13 *************** *** 60,63 **** --- 60,64 ---- { protected int numDayOfPortfolioLife; + protected int numDaysWithNoPositions; protected int numDaysForReturnCalculation; protected double maxAcceptableCloseToCloseDrawdown; *************** *** 69,73 **** int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, ! int numDaysOfPortfolioLife, int numDaysForReturnCalculation, double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, --- 70,75 ---- int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, ! int numDaysOfPortfolioLife, int numDaysForReturnCalculation, ! int numDaysWithNoPositions, double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, *************** *** 80,87 **** portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScriptsDiscontinuos"; //this.ScriptName = "CloseToCloseScriptsDiscontinuosWithCoeff"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; --- 82,90 ---- portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScriptsDiscontinuosWithSharpe"; //this.ScriptName = "CloseToCloseScriptsDiscontinuosWithCoeff"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; + this.numDaysWithNoPositions = numDaysWithNoPositions; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; *************** *** 98,101 **** --- 101,105 ---- this.populationSizeForGeneticOptimizer, this.benchmark, this.numDayOfPortfolioLife, this.numDaysForReturnCalculation, + this.numDaysWithNoPositions, this.targetReturn, this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, Index: RunTestOptimizedCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunTestOptimizedCTCPortfolio.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RunTestOptimizedCTCPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.8 --- RunTestOptimizedCTCPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.9 *************** *** 66,70 **** int populationSizeForGeneticOptimizer, string benchmark, DateTime endDate, ! int numDaysOfPortfolioLife, int numDaysForReturnCalculation, double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, --- 66,71 ---- int populationSizeForGeneticOptimizer, string benchmark, DateTime endDate, ! int numDaysOfPortfolioLife, int numDaysForReturnCalculation, ! int numDaysWithNoPositions, double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, *************** *** 75,79 **** populationSizeForGeneticOptimizer, benchmark, endDate.AddDays(-numDaysForOptimizationPeriod), endDate, ! numDaysOfPortfolioLife - 1, numDaysForReturnCalculation, targetReturn, portfolioType, maxAcceptableCloseToCloseDrawdown, --- 76,81 ---- populationSizeForGeneticOptimizer, benchmark, endDate.AddDays(-numDaysForOptimizationPeriod), endDate, ! numDaysOfPortfolioLife, numDaysForReturnCalculation, ! numDaysWithNoPositions, targetReturn, portfolioType, maxAcceptableCloseToCloseDrawdown, *************** *** 83,87 **** } ! protected override void run_initializeEndOfDayTimerHandler() { --- 85,89 ---- } ! protected override void run_initializeEndOfDayTimerHandler() { *************** *** 93,96 **** --- 95,99 ---- this.numDayOfPortfolioLife, this.numDaysForReturnCalculation, + this.numDaysWithNoPositions, this.targetReturn, this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GenomeManagerForEfficientCTCPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.11 --- GenomeManagerForEfficientCTCPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.12 *************** *** 41,45 **** --- 41,58 ---- { private int numDaysForReturnCalculation; + private double shiftedPortfolioRateOfReturn; + private float[] shiftedPortfolioRatesOfReturn; + //private double shiftedPortfolioVariance; + //rate of return and variance of portfolio + //shifted ahead of numDaysForReturnCalculation + /// <summary> + /// Rates of returns of the portfolio shifted ahead of numDaysForReturnCalculation + /// </summary> + public float[] ShiftedPortfolioRatesOfReturn + { + get{return this.shiftedPortfolioRatesOfReturn;} + } + public GenomeManagerForEfficientCTCPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, *************** *** 90,117 **** 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 = --- 103,108 ---- protected override float[] getArrayOfRatesOfReturn(string ticker) { ! this.calculateShiftedRateOfReturn(ticker); ! float[] returnValue = null; returnValue = *************** *** 156,167 **** } */ - //sharpe ratio as fitness - /* protected override double getFitnessValue_calculate() { ! return this.RateOfReturn/Math.Sqrt(this.Variance); } ! */ } --- 147,177 ---- } */ + private void calculateShiftedRateOfReturn(string ticker) + { + try + { + float[] closeToCloseRatios = Quotes.GetArrayOfCloseToCloseRatios(ticker, this.firstQuoteDate, + this.lastQuoteDate, + this.numDaysForReturnCalculation, + this.numDaysForReturnCalculation); + this.shiftedPortfolioRatesOfReturn = closeToCloseRatios; + this.shiftedPortfolioRateOfReturn = + BasicFunctions.SimpleAverage(closeToCloseRatios); + //this.shiftedPortfolioVariance = + //BasicFunctions.Variance(closeToCloseRatios); + } + catch(Exception ex) + { + ex = ex; + } + } protected override double getFitnessValue_calculate() { ! return (this.RateOfReturn/Math.Sqrt(this.Variance))* ! -this.shiftedPortfolioRateOfReturn * ! -this.ShiftedPortfolioRatesOfReturn[this.ShiftedPortfolioRatesOfReturn.Length -1]; } ! } Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** GenomeManagerForEfficientCTOPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.15 --- GenomeManagerForEfficientCTOPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.16 *************** *** 96,105 **** } */ ! ! // protected override double getFitnessValue_calculate() ! // { ! // return this.RateOfReturn/Math.Sqrt(this.Variance); ! // } ! } --- 96,105 ---- } */ ! /* ! protected override double getFitnessValue_calculate() ! { ! return this.RateOfReturn/Math.Sqrt(this.Variance); ! } ! */ } Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** EndOfDayTimerHandlerCTO.cs 8 Nov 2005 18:36:48 -0000 1.21 --- EndOfDayTimerHandlerCTO.cs 28 Dec 2005 23:29:40 -0000 1.22 *************** *** 65,69 **** this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; } ! /// <summary> --- 65,110 ---- this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; } ! ! private double marketOpenEventHandler_currCombinationHasLost_getValue(ExtendedDateTime extendedDateTime) ! { ! double returnValue = 0.0; ! string signedTicker; ! string unsignedTicker; ! double tickerMarketValue; ! for(int i = 0; i<this.chosenTickers.Length; i++) ! { ! signedTicker = this.chosenTickers[i]; ! unsignedTicker = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(signedTicker); ! tickerMarketValue = ! HistoricalDataProvider.GetAdjustedMarketValue(unsignedTicker,extendedDateTime); ! if(signedTicker == unsignedTicker) ! //long position for the ticker ! returnValue += this.chosenTickersPortfolioWeights[i]*tickerMarketValue; ! else//short position for the ticker ! returnValue -= this.chosenTickersPortfolioWeights[i]*tickerMarketValue; ! } ! return returnValue; ! ! } ! ! private bool marketOpenEventHandler_currCombinationHasLost() ! { ! bool returnValue = false; ! IndexBasedEndOfDayTimer currentTimer = (IndexBasedEndOfDayTimer)this.account.EndOfDayTimer; ! ExtendedDateTime now = ! new ExtendedDateTime(currentTimer.GetCurrentTime().DateTime, ! BarComponent.Open); ! ExtendedDateTime previousClose = ! new ExtendedDateTime(currentTimer.GetPreviousDateTime(), ! BarComponent.Close); ! double currentCombinationValue_Now = ! this.marketOpenEventHandler_currCombinationHasLost_getValue(now); ! double currentCombinationValue_AtPreviousMarketClose = ! this.marketOpenEventHandler_currCombinationHasLost_getValue(previousClose); ! if(currentCombinationValue_Now < currentCombinationValue_AtPreviousMarketClose) ! returnValue = true; ! return returnValue; ! } /// <summary> *************** *** 75,81 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! //temporarily the if condition ! //if(this.numDaysElapsedSinceLastOptimization == 0) ! this.openPositions(); } --- 116,130 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(30000); ! bool allTickerHasBeenChosen = true; ! for( int i = 0; i<this.chosenTickers.Length; i++) ! { ! if(this.chosenTickers[i] == null) ! allTickerHasBeenChosen = false; ! } ! if(allTickerHasBeenChosen && ! this.marketOpenEventHandler_currCombinationHasLost()) ! this.openPositions(); } *************** *** 84,93 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! ! //temporarily ! //if(this.numDaysElapsedSinceLastOptimization == ! // this.numDaysBetweenEachOptimization) ! this.closePositions(); ! } --- 133,137 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.closePositions(); } *************** *** 98,123 **** protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { - /* - SelectorByAverageRawOpenPrice selectorByOpenPrice = - new SelectorByAverageRawOpenPrice(this.tickerGroupID, false, - currentDate.AddDays(-this.numDaysForLiquidity), currentDate, - this.numberOfEligibleTickers, this.minPriceForMinimumCommission, - this.maxPriceForMinimumCommission, 0, 2); - DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); - */ SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromTemporizedGroup = ! new SelectorByOpenCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), this.benchmark,true, currentDate.AddDays(-this.numDaysForOptimizationPeriod ), currentDate, ! this.numberOfEligibleTickers); ! this.eligibleTickers = lessCorrelatedFromTemporizedGroup.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), --- 142,172 ---- protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! ! SelectorByLiquidity mostLiquidFromTemporized = ! new SelectorByLiquidity(temporizedGroup.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfEligibleTickers); ! ! SelectorByAverageRawOpenPrice selectorByOpenPriceFromMostLiquid = ! new SelectorByAverageRawOpenPrice(mostLiquidFromTemporized.GetTableOfSelectedTickers(), false, ! currentDate.AddDays(-10), currentDate, ! this.numberOfEligibleTickers, this.minPriceForMinimumCommission, ! this.maxPriceForMinimumCommission, 0, 10); ! ! SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromSelectedByPrice = ! new SelectorByOpenCloseCorrelationToBenchmark(selectorByOpenPriceFromMostLiquid.GetTableOfSelectedTickers(), this.benchmark,true, currentDate.AddDays(-this.numDaysForOptimizationPeriod ), currentDate, ! this.numberOfEligibleTickers/2); ! this.eligibleTickers = lessCorrelatedFromSelectedByPrice.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfEligibleTickers/2, this.benchmark); ! //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), *************** *** 131,135 **** --- 180,186 ---- // currentDate, this.numberOfEligibleTickers/2); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); + //return mostLiquidFromQuotedAtEachMarketDay.GetTableOfSelectedTickers(); //return lessCorrelated.GetTableOfSelectedTickers(); + //return selectorByOpenPriceFromMostLiquid.GetTableOfSelectedTickers(); } Index: RunEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientPortfolio.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** RunEfficientPortfolio.cs 27 Sep 2005 22:17:51 -0000 1.17 --- RunEfficientPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.18 *************** *** 180,184 **** protected virtual void run_initializeAccount() { ! //default account with no commissions this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , --- 180,184 ---- protected virtual void run_initializeAccount() { ! //default account with no commissions and no slippage calculation this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** EndOfDayTimerHandlerCTC.cs 17 Nov 2005 21:37:19 -0000 1.18 --- EndOfDayTimerHandlerCTC.cs 28 Dec 2005 23:29:40 -0000 1.19 *************** *** 46,51 **** protected int numDaysOfPortfolioLife; protected int numDaysForReturnCalculation; ! protected int daysCounter; ! protected int daysWithNoPositions; protected double maxAcceptableCloseToCloseDrawdown; protected bool stopLossConditionReached; --- 46,52 ---- protected int numDaysOfPortfolioLife; protected int numDaysForReturnCalculation; ! protected int numDaysWithNoPositions; ! protected int daysCounterWithPositions; ! protected int daysCounterWithNoPositions; protected double maxAcceptableCloseToCloseDrawdown; protected bool stopLossConditionReached; *************** *** 63,66 **** --- 64,68 ---- int numDaysOfPortfolioLife, int numDaysForReturnCalculation, + int numDaysWithNoPositions, double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, *************** *** 75,79 **** this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.daysCounter = 0; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.stopLossConditionReached = false; --- 77,83 ---- this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.numDaysWithNoPositions = numDaysWithNoPositions; ! this.daysCounterWithPositions = 0; ! this.daysCounterWithNoPositions = 0; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.stopLossConditionReached = false; *************** *** 111,116 **** //portfolio is not empty { ! this.daysCounter++; ! if(this.daysCounter == this.numDaysOfPortfolioLife || this.stopLossConditionReached) //num days of portfolio life or --- 115,120 ---- //portfolio is not empty { ! this.daysCounterWithPositions++; ! if(this.daysCounterWithPositions == this.numDaysOfPortfolioLife || this.stopLossConditionReached) //num days of portfolio life or *************** *** 118,125 **** { this.closePositions(); ! this.daysCounter = 0; //positionsJustClosed = true; } } //old // if(this.account.Portfolio.Count == 0 && --- 122,141 ---- { this.closePositions(); ! this.daysCounterWithPositions = 0; //positionsJustClosed = true; } } + else//portfolio is empty + { + this.daysCounterWithNoPositions++; + if(this.daysCounterWithNoPositions == this.numDaysWithNoPositions || + this.Account.Transactions.Count <= 1) + { + this.openPositions(); + this.daysCounterWithNoPositions = 0; + } + } + } + //old // if(this.account.Portfolio.Count == 0 && *************** *** 131,147 **** // this.daysCounter = 0; // } ! ! if(this.account.Portfolio.Count == 0) ! //portfolio is empty ! { ! this.daysWithNoPositions++; ! if(this.daysWithNoPositions>this.numDaysOfPortfolioLife) ! { ! this.openPositions(); ! this.daysWithNoPositions = 0; ! } ! } ! } ! #endregion --- 147,151 ---- // this.daysCounter = 0; // } ! #endregion *************** *** 153,173 **** 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, ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod),currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); } --- 157,182 ---- currentDate); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketFromTemporized = ! new SelectorByQuotationAtEachMarketDay(temporizedGroup.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod),currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! ! this.eligibleTickers = quotedAtEachMarketFromTemporized.GetTableOfSelectedTickers(); ! ! SelectorByCloseToCloseCorrelationToBenchmark lessCorrelatedFromEligible = ! new SelectorByCloseToCloseCorrelationToBenchmark(this.eligibleTickers, this.benchmark,true, currentDate.AddDays(-this.numDaysForOptimizationPeriod ), currentDate, ! this.numberOfEligibleTickers/2, this.numDaysForReturnCalculation); ! SelectorByAbsolutePerformance mostQuietFromLessCorrelated = ! new SelectorByAbsolutePerformance(lessCorrelatedFromEligible.GetTableOfSelectedTickers(), ! true,currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! currentDate, ! this.numberOfEligibleTickers/4, ! 0.01f, 0.10f); ! ! return mostQuietFromLessCorrelated.GetTableOfSelectedTickers(); } *************** *** 228,235 **** // //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); --- 237,248 ---- // //it sets tickers to be chosen at next close // } ! //this.oneHourAfterMarketCloseEventHandler_updatePrices(); + this.numDaysElapsedSinceLastOptimization++; + this.orders.Clear(); if(this.numDaysElapsedSinceLastOptimization == ! this.numDaysBetweenEachOptimization) ! //num days without optimization has elapsed or ! //just money has been added to the account { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); *************** *** 237,244 **** this.numDaysElapsedSinceLastOptimization = 0; } ! else ! { ! this.numDaysElapsedSinceLastOptimization++; ! } } #endregion --- 250,254 ---- this.numDaysElapsedSinceLastOptimization = 0; } ! } #endregion Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** RunEfficientCTOPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.24 --- RunEfficientCTOPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.25 *************** *** 37,40 **** --- 37,41 ---- using QuantProject.Business.Timing; using QuantProject.Business.Financial.Accounting.Commissions; + using QuantProject.Business.Financial.Accounting.Slippage; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; *************** *** 74,93 **** //this.ScriptName = "OpenCloseScriptsSharpeRatio"; this.ScriptName = "OpenCloseScriptsWithCoeff"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } - #region auxiliary overriden methods for Run ! /* delete remark delimitations for having ib commission protected override void run_initializeAccount() { ! this.account = new Account( this.ScriptName , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ), new IBCommissionManager()); } ! */ protected override void run_initializeEndOfDayTimerHandler() --- 75,99 ---- //this.ScriptName = "OpenCloseScriptsSharpeRatio"; this.ScriptName = "OpenCloseScriptsWithCoeff"; + //this.ScriptName = "OpenCloseScripts"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } ! // delete remark delimitations for having ib commission ! // and a fixed percentage calculation of slippage protected override void run_initializeAccount() { ! this.account = new Account(this.ScriptName, ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , ! this.historicalQuoteProvider, ! new FixedPercentageSlippageManager(this.historicalQuoteProvider, ! this.endOfDayTimer,0.08)), ! new IBCommissionManager()); } ! protected override void run_initializeEndOfDayTimerHandler() *************** *** 129,133 **** this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); } ! #endregion //necessary far calling RunEfficientPortfolio.Run() --- 135,140 ---- this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); } ! ! //necessary far calling RunEfficientPortfolio.Run() Index: EndOfDayTimerHandlerCTCTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCTest.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** EndOfDayTimerHandlerCTCTest.cs 17 Nov 2005 21:37:19 -0000 1.5 --- EndOfDayTimerHandlerCTCTest.cs 28 Dec 2005 23:29:40 -0000 1.6 *************** *** 55,58 **** --- 55,59 ---- int numDaysOfPortfolioLife, int numDaysForReturnCalculation, + int numDaysWithNoPositions, double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, *************** *** 66,69 **** --- 67,71 ---- numDaysOfPortfolioLife, numDaysForReturnCalculation, + numDaysWithNoPositions, targetReturn, portfolioType, maxAcceptableCloseToCloseDrawdown, |