[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting RunEfficientCTOPortfolio.cs
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-11-08 18:37:01
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24791/b7_Scripts/TickerSelectionTesting Modified Files: RunEfficientCTOPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientCTCPortfolio.cs EndOfDayTimerHandlerOTCMultiday.cs EndOfDayTimerHandlerOTCCTO.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandlerCTCWeekly.cs EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandler.cs Log Message: Added GenomeManagerForWeightedEfficientPortfolio to the project. Updated script files for managing weights returned by the new Meaning implementation for genomes. Index: EndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandler.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** EndOfDayTimerHandler.cs 18 Sep 2005 21:13:36 -0000 1.17 --- EndOfDayTimerHandler.cs 8 Nov 2005 18:36:48 -0000 1.18 *************** *** 46,49 **** --- 46,50 ---- protected DataTable eligibleTickers; protected string[] chosenTickers; + protected double[] chosenTickersPortfolioWeights; protected string[] lastOrderedTickers; *************** *** 118,121 **** --- 119,123 ---- this.targetReturn = targetReturn; this.portfolioType = portfolioType; + this.setDefaultChosenTickersPortfolioWeights(); } *************** *** 134,144 **** this.lastOrderedTickers = new string[chosenTickers.Length]; this.portfolioType = portfolioType; } ! protected virtual void addOrderForTicker(string ticker ) { string tickerCode = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! double cashForSinglePosition = this.account.CashAmount / this.numberOfTickersToBeChosen; long quantity = Convert.ToInt64( Math.Floor( cashForSinglePosition / this.account.DataStreamer.GetCurrentBid( tickerCode ) ) ); --- 136,155 ---- this.lastOrderedTickers = new string[chosenTickers.Length]; this.portfolioType = portfolioType; + this.setDefaultChosenTickersPortfolioWeights(); } ! private void setDefaultChosenTickersPortfolioWeights() ! { ! this.chosenTickersPortfolioWeights = new double[this.chosenTickers.Length]; ! for(int i = 0;i<this.chosenTickers.Length;i++) ! this.chosenTickersPortfolioWeights[i]=1.0/this.chosenTickers.Length; ! } ! ! protected virtual void addOrderForTicker(int tickerPosition ) { string tickerCode = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[tickerPosition]); ! double cashForSinglePosition = ! this.account.CashAmount * this.chosenTickersPortfolioWeights[tickerPosition]; long quantity = Convert.ToInt64( Math.Floor( cashForSinglePosition / this.account.DataStreamer.GetCurrentBid( tickerCode ) ) ); *************** *** 146,150 **** if(this.portfolioType == PortfolioType.OnlyShort || (this.portfolioType == PortfolioType.ShortAndLong && ! ticker != tickerCode)) order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); else --- 157,161 ---- if(this.portfolioType == PortfolioType.OnlyShort || (this.portfolioType == PortfolioType.ShortAndLong && ! this.chosenTickers[tickerPosition] != tickerCode)) order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); else *************** *** 180,193 **** protected virtual void addChosenTickersToOrderList() { ! int idx = 0; ! foreach ( string ticker in this.chosenTickers ) { ! if(ticker != null) { ! this.addOrderForTicker( ticker ); ! this.lastOrderedTickers[idx] = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); } - idx++; } } --- 191,202 ---- protected virtual void addChosenTickersToOrderList() { ! for( int i = 0; i<this.chosenTickers.Length; i++) { ! if(this.chosenTickers[i] != null) { ! this.addOrderForTicker( i ); ! this.lastOrderedTickers[i] = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[i]); } } } Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GenomeManagerForEfficientCTCPortfolio.cs 27 Jul 2005 22:30:55 -0000 1.9 --- GenomeManagerForEfficientCTCPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.10 *************** *** 109,112 **** --- 109,120 ---- } */ + + //sharpe ratio as fitness + /* + protected override double getFitnessValue_calculate() + { + return this.RateOfReturn/Math.Sqrt(this.Variance); + } + */ } Index: EndOfDayTimerHandlerOTCCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCCTO.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerOTCCTO.cs 21 Oct 2005 18:07:45 -0000 1.1 --- EndOfDayTimerHandlerOTCCTO.cs 8 Nov 2005 18:36:48 -0000 1.2 *************** *** 106,110 **** this.reverseSignOfChosenTickers(); this.openPositions(); ! } --- 106,110 ---- this.reverseSignOfChosenTickers(); this.openPositions(); ! this.reverseSignOfChosenTickers(); } *************** *** 179,183 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = (string[])GO.BestGenome.Meaning; } //else it will be buyed again the previous optimized portfolio --- 179,183 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio Index: EndOfDayTimerHandlerOTCMultiday.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCMultiday.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerOTCMultiday.cs 23 Oct 2005 19:09:04 -0000 1.2 --- EndOfDayTimerHandlerOTCMultiday.cs 8 Nov 2005 18:36:48 -0000 1.3 *************** *** 182,188 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! //this.chosenTickers = ((MeaningForGenome)GO.BestGenome.Meaning).Tickers; ! this.chosenTickers = ! this.setTickers_getBestTickersLosingAtLastDay(genManEfficientCTOPortfolio); } //else it will be buyed again the previous optimized portfolio --- 182,189 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; ! //this.chosenTickers = ! // this.setTickers_getBestTickersLosingAtLastDay(genManEfficientCTOPortfolio); } //else it will be buyed again the previous optimized portfolio Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** GenomeManagerForEfficientCTOPortfolio.cs 25 Jul 2005 22:49:54 -0000 1.13 --- GenomeManagerForEfficientCTOPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.14 *************** *** 38,42 **** /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForEfficientPortfolio { --- 38,42 ---- /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForWeightedEfficientPortfolio { *************** *** 67,71 **** return returnValue; } ! /* protected override double getFitnessValue_calculate() { --- 67,71 ---- return returnValue; } ! /*using LPM protected override double getFitnessValue_calculate() { *************** *** 96,99 **** --- 96,106 ---- } */ + + 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.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** EndOfDayTimerHandlerCTO.cs 23 Oct 2005 19:09:04 -0000 1.20 --- EndOfDayTimerHandlerCTO.cs 8 Nov 2005 18:36:48 -0000 1.21 *************** *** 163,166 **** --- 163,167 ---- currentDate); this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; + this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** EndOfDayTimerHandlerCTC.cs 23 Oct 2005 19:09:04 -0000 1.16 --- EndOfDayTimerHandlerCTC.cs 8 Nov 2005 18:36:48 -0000 1.17 *************** *** 178,181 **** --- 178,182 ---- currentDate); this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; + this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** RunEfficientCTOPortfolio.cs 18 Sep 2005 21:13:36 -0000 1.22 --- RunEfficientCTOPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.23 *************** *** 71,75 **** portfolioType, maxRunningHours) { ! this.ScriptName = "OpenCloseScripts"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } --- 71,76 ---- portfolioType, maxRunningHours) { ! this.ScriptName = "OpenCloseScriptsSharpeRatioWithCoeff"; ! //this.ScriptName = "OpenCloseScriptsSharpeRatio"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } *************** *** 105,110 **** protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! //this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } --- 106,111 ---- protected override void run_initializeHistoricalQuoteProvider() { ! //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } Index: EndOfDayTimerHandlerCTCWeekly.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCWeekly.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerCTCWeekly.cs 23 Oct 2005 19:09:04 -0000 1.4 --- EndOfDayTimerHandlerCTCWeekly.cs 8 Nov 2005 18:36:48 -0000 1.5 *************** *** 153,156 **** --- 153,157 ---- GO.Run(false); this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; + this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio |