[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes EndOfDayT
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2007-08-29 09:44:17
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10276/b7_Scripts/TickerSelectionTesting/TestingOTCTypes Modified Files: EndOfDayTimerHandlerOTCTypes.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: EndOfDayTimerHandlerOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/EndOfDayTimerHandlerOTCTypes.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** EndOfDayTimerHandlerOTCTypes.cs 9 Apr 2007 18:08:59 -0000 1.7 --- EndOfDayTimerHandlerOTCTypes.cs 29 Aug 2007 09:43:34 -0000 1.8 *************** *** 36,41 **** namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { ! ! /// <summary> /// Implements MarketOpenEventHandler, /// MarketCloseEventHandler and OneHourAfterMarketCloseEventHandler --- 36,40 ---- namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { ! /// <summary> /// Implements MarketOpenEventHandler, /// MarketCloseEventHandler and OneHourAfterMarketCloseEventHandler *************** *** 46,57 **** public class EndOfDayTimerHandlerOTCTypes : EndOfDayTimerHandler { - private int numDaysBetweenEachOptimization; - private int numDaysElapsedSinceLastOptimization; private int seedForRandomGenerator; private Account[] accounts; - private string[,] lastOrderedTickersForTheAccount; int numOfClosesWithOpenPositionsFor2DaysStrategy; ! ! public EndOfDayTimerHandlerOTCTypes(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, --- 45,52 ---- public class EndOfDayTimerHandlerOTCTypes : EndOfDayTimerHandler { private int seedForRandomGenerator; private Account[] accounts; int numOfClosesWithOpenPositionsFor2DaysStrategy; ! public EndOfDayTimerHandlerOTCTypes(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, *************** *** 72,77 **** this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; this.accounts = accounts; - this.lastOrderedTickersForTheAccount = new string[this.accounts.Length, - this.numberOfTickersToBeChosen]; } --- 67,70 ---- *************** *** 79,159 **** { 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); ! } } ! /// <summary> /// Handles a "Market Open" event. --- 72,83 ---- { if(this.accounts[accountNumber].Portfolio.Count == 0) ! AccountManager.OpenPositions(this.chosenWeightedPositions, this.accounts[accountNumber]); } private void closePositionsForTheAccount(int accountNumber) { ! AccountManager.ClosePositions(this.accounts[accountNumber]); } ! /// <summary> /// Handles a "Market Open" event. *************** *** 167,172 **** { //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 --- 91,96 ---- { //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 *************** *** 205,214 **** if(i>=2)//for the OTC-CTO and CTO ! this.marketCloseEventHandler_reversePositionsForTheAccount(i); } } - - #region OneHourAfterMarketCloseEventHandler --- 129,136 ---- if(i>=2)//for the OTC-CTO and CTO ! AccountManager.ReversePositions(this.accounts[i]); } } #region OneHourAfterMarketCloseEventHandler *************** *** 222,227 **** currentDate, tickersFromGroup.Rows.Count, ! 20,500, 0.0001,100); ! SelectorByLiquidity mostLiquidSelector = --- 144,148 ---- currentDate, tickersFromGroup.Rows.Count, ! 25); SelectorByLiquidity mostLiquidSelector = *************** *** 241,247 **** bool setGenomeCounter) { - 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 --- 162,167 ---- bool setGenomeCounter) { 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 *************** *** 268,274 **** currentDate,setOfTickersToBeOptimized.Rows.Count,-1, this.portfolioType, GO.GenerationCounter); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; ! } //else it will be buyed again the previous optimized portfolio --- 188,193 ---- currentDate,setOfTickersToBeOptimized.Rows.Count,-1, this.portfolioType, GO.GenerationCounter); ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); } //else it will be buyed again the previous optimized portfolio *************** *** 285,290 **** { this.seedForRandomGenerator++; ! this.orders.Clear(); ! if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) { --- 204,208 ---- { this.seedForRandomGenerator++; ! if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) { *************** *** 299,305 **** } - #endregion - } } --- 217,221 ---- |