[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForce
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2007-08-29 09:44:15
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10276/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization Modified Files: EndOfDayTimerHandlerOTCTypesBruteForce.cs Log Message: Code has been re-organized in a more logical and Object Oriented way: - WeightedPositions class has been used. - Some static methods have been deleted from SignedTicker class. They have been moved to WeightedPositions. - Basic orders'management has been moved to the primitive base class EndOfDayTimerHandler and to AccountManager class Index: EndOfDayTimerHandlerOTCTypesBruteForce.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization/EndOfDayTimerHandlerOTCTypesBruteForce.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerOTCTypesBruteForce.cs 3 Jan 2007 23:01:52 -0000 1.2 --- EndOfDayTimerHandlerOTCTypesBruteForce.cs 29 Aug 2007 09:43:34 -0000 1.3 *************** *** 48,56 **** public class EndOfDayTimerHandlerOTCTypesBruteForce : EndOfDayTimerHandler { - private int numDaysBetweenEachOptimization; - private int numDaysElapsedSinceLastOptimization; private int seedForRandomGenerator; private Account[] accounts; - private string[,] lastOrderedTickersForTheAccount; int numOfClosesWithOpenPositionsFor2DaysStrategy; --- 48,53 ---- *************** *** 71,76 **** this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; this.accounts = accounts; - this.lastOrderedTickersForTheAccount = new string[this.accounts.Length, - this.numberOfTickersToBeChosen]; } --- 68,71 ---- *************** *** 78,156 **** { if(this.accounts[accountNumber].Portfolio.Count == 0) ! { ! this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(accountNumber); ! for(int i = 0; i<this.orders.Count;i++) ! { ! this.accounts[accountNumber].AddOrder((Order)this.orders[i]); ! this.lastOrderedTickersForTheAccount[accountNumber, i] = ! SignedTicker.GetTicker(((Order)this.orders[i]).Instrument.Key); ! } ! } ! } ! ! 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 ); ! } } - private void closePositionsForTheAccount(int accountNumber) { ! string ticker; ! if(this.accounts[accountNumber].Portfolio.Count >0) ! { ! for(int j = 0; j<this.numberOfTickersToBeChosen; j++) ! { ! ticker = this.lastOrderedTickersForTheAccount[accountNumber, j]; ! if( ticker != null) ! { ! if(this.accounts[accountNumber].Portfolio[ticker]!=null) ! this.accounts[accountNumber].ClosePosition(ticker); ! } ! } ! } } private void marketCloseEventHandler_reversePositionsForTheAccount(int accountNumber) { ! this.closePositionsForTheAccount(accountNumber); ! SignedTicker.ChangeSignOfEachTicker(this.chosenTickers); ! try ! { ! this.openPositionsForTheAccountWhenPortfolioIsEmpty(accountNumber); ! } ! catch(Exception ex) ! { ! ex = ex; ! } ! finally ! { ! SignedTicker.ChangeSignOfEachTicker(this.chosenTickers); ! } } --- 73,87 ---- { if(this.accounts[accountNumber].Portfolio.Count == 0) ! AccountManager.OpenPositions(this.chosenWeightedPositions, this.accounts[accountNumber]); } private void closePositionsForTheAccount(int accountNumber) { ! AccountManager.ClosePositions(this.accounts[accountNumber]); } private void marketCloseEventHandler_reversePositionsForTheAccount(int accountNumber) { ! AccountManager.ReversePositions(this.accounts[accountNumber]); } *************** *** 166,171 **** { //add cash first for each account ! if(this.orders.Count == 0 && this.accounts[i].Transactions.Count == 0) ! this.accounts[i].AddCash(30000); if(i<=1)//daily classical and multiday --- 97,102 ---- { //add cash first for each account ! if( this.accounts[i].Transactions.Count == 0) ! this.accounts[i].AddCash(15000); if(i<=1)//daily classical and multiday *************** *** 207,213 **** } } ! ! ! #region OneHourAfterMarketCloseEventHandler --- 138,142 ---- } } ! #region OneHourAfterMarketCloseEventHandler *************** *** 250,254 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen --- 179,183 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen *************** *** 260,274 **** setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate,this.chosenTickers.Length); BruteForceOptimizer BFO = new BruteForceOptimizer(otcBruteForceParamManager); BFO.Run(); - this.chosenTickers = - ((GenomeMeaning)otcBruteForceParamManager.Decode(BFO.BestParameters)).Tickers; //this.setTickers_getChosenTickers(BFO.BestParameters); ! this.addGenomeToBestGenomes(BFO.BestParameters,this.chosenTickers, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate,setOfTickersToBeOptimized.Rows.Count); ! this.chosenTickersPortfolioWeights = this.setTickers_getWeights(this.chosenTickers); } --- 189,202 ---- setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate,this.numberOfTickersToBeChosen); BruteForceOptimizer BFO = new BruteForceOptimizer(otcBruteForceParamManager); BFO.Run(); //this.setTickers_getChosenTickers(BFO.BestParameters); ! this.addGenomeToBestGenomes(BFO.BestParameters,this.chosenWeightedPositions.SignedTickers, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate,setOfTickersToBeOptimized.Rows.Count); ! this.chosenWeightedPositions = ! new WeightedPositions(new SignedTickers(((GenomeMeaning)otcBruteForceParamManager.Decode(BFO.BestParameters)).Tickers)); } *************** *** 286,290 **** { this.seedForRandomGenerator++; - this.orders.Clear(); if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) --- 214,217 ---- *************** *** 298,304 **** this.numDaysElapsedSinceLastOptimization++; } - } - #endregion --- 225,229 ---- |