[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes RunEfficien
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2006-01-07 10:29:08
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3224/b7_Scripts/TickerSelectionTesting/TestingOTCTypes Modified Files: RunEfficientOTCTypes.cs EndOfDayTimerHandlerOTCTypes.cs Log Message: Fixed bug in OTCTypes script: positions are now correctly computed for each type of strategy. Index: RunEfficientOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/RunEfficientOTCTypes.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunEfficientOTCTypes.cs 28 Dec 2005 23:22:50 -0000 1.1 --- RunEfficientOTCTypes.cs 7 Jan 2006 10:28:56 -0000 1.2 *************** *** 72,76 **** portfolioType, maxRunningHours) { ! this.ScriptName = "OTC_Types"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.accounts = new Account[4]; --- 72,76 ---- portfolioType, maxRunningHours) { ! this.ScriptName = "OTC_Types_SharpeRatioWithCoeff"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.accounts = new Account[4]; Index: EndOfDayTimerHandlerOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/EndOfDayTimerHandlerOTCTypes.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerOTCTypes.cs 28 Dec 2005 23:22:50 -0000 1.1 --- EndOfDayTimerHandlerOTCTypes.cs 7 Jan 2006 10:28:56 -0000 1.2 *************** *** 59,63 **** Account[] accounts): base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, accounts[0], generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, --- 59,63 ---- Account[] accounts): base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, *************** *** 104,110 **** } protected override void openPositions() { ! this.addChosenTickersToOrderList(); for(int i = 0; i<this.accounts.Length; i++) { --- 104,141 ---- } + protected void addOrderForTickerForTheGivenAccount(int tickerPosition, + int accountNumber ) + { + string tickerCode = + GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[tickerPosition]); + double cashForSinglePosition = + this.accounts[accountNumber].CashAmount * this.chosenTickersPortfolioWeights[tickerPosition]; + long quantity = + Convert.ToInt64( Math.Floor( cashForSinglePosition / this.accounts[accountNumber].DataStreamer.GetCurrentBid( tickerCode ) ) ); + Order order; + if(this.portfolioType == PortfolioType.OnlyShort || + (this.portfolioType == PortfolioType.ShortAndLong && + this.chosenTickers[tickerPosition] != tickerCode)) + order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); + else + order = new Order( OrderType.MarketBuy, new Instrument( tickerCode ) , quantity ); + + this.orders.Add(order); + } + protected void addChosenTickersToOrderListForTheGivenAccount(int accountNumber) + { + for( int i = 0; i<this.chosenTickers.Length; i++) + { + if(this.chosenTickers[i] != null) + { + this.addOrderForTickerForTheGivenAccount( i, accountNumber ); + this.lastOrderedTickers[i] = + GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[i]); + } + } + } protected override void openPositions() { ! for(int i = 0; i<this.accounts.Length; i++) { *************** *** 114,125 **** if(i<=1)//daily classical, and multiday - this.openPositions_openWhenPortfolioIsEmpty(i); - else if(i==2)//for the CTO OTC { ! this.closePositions_close(i); foreach(object item in this.orders) this.accounts[i].AddOrder((Order)item); } ! else if(i==3)//for the CTO, only at night { this.closePositions_close(i); --- 145,163 ---- if(i<=1)//daily classical, and multiday { ! this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); ! this.openPositions_openWhenPortfolioIsEmpty(i); ! } ! else if(i==2)//for the CTO OTC ! { ! this.closePositions_close(i); ! this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); foreach(object item in this.orders) this.accounts[i].AddOrder((Order)item); } ! else if(i==3)//for the CTO, no position is opened ! //at market open. Any open position is closed, instead { this.closePositions_close(i); *************** *** 169,173 **** this.reverseSignOfChosenTickers(); this.orders.Clear(); ! this.addChosenTickersToOrderList(); this.openPositions_openWhenPortfolioIsEmpty(i); this.reverseSignOfChosenTickers(); --- 207,211 ---- this.reverseSignOfChosenTickers(); this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); this.openPositions_openWhenPortfolioIsEmpty(i); this.reverseSignOfChosenTickers(); *************** *** 184,188 **** this.reverseSignOfChosenTickers(); this.orders.Clear(); ! this.addChosenTickersToOrderList(); this.openPositions_openWhenPortfolioIsEmpty(i); this.reverseSignOfChosenTickers(); --- 222,226 ---- this.reverseSignOfChosenTickers(); this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); this.openPositions_openWhenPortfolioIsEmpty(i); this.reverseSignOfChosenTickers(); *************** *** 284,289 **** { ! IGenomeManager genManEfficientCTOPortfolio = ! new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, --- 322,327 ---- { ! IGenomeManager genManEfficientOTCTypes = ! new GenomeManagerForEfficientOTCTypes(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, *************** *** 292,296 **** this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, --- 330,334 ---- this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientOTCTypes, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, |