[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting EndOfDayTimerHandler.cs,1.4
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2004-12-27 18:24:01
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29542/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandler.cs RunEfficientCTOPortfolio.cs Log Message: Updated script for TickerSelection Testing, using Efficient portfolio theory Index: EndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandler.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandler.cs 20 Dec 2004 20:25:11 -0000 1.4 --- EndOfDayTimerHandler.cs 27 Dec 2004 18:23:51 -0000 1.5 *************** *** 73,76 **** --- 73,104 ---- #region MarketOpenEventHandler + + private void marketOpenEventHandler_orderChosenTickers_addToOrderList_forTicker( + string ticker ) + { + + double cashForSinglePosition = this.account.CashAmount / this.numberOfTickersToBeChosen; + long quantity = + Convert.ToInt64( Math.Floor( cashForSinglePosition / this.account.DataStreamer.GetCurrentBid( ticker ) ) ); + Order order = new Order( OrderType.MarketBuy , new Instrument( ticker ) , quantity ); + this.orders.Add(order); + } + + private void marketOpenEventHandler_orderChosenTickers_addToOrderList() + { + foreach ( string ticker in this.chosenTickers ) + { + //if ( !this.account.Contains( ticker ) ) + //{ + marketOpenEventHandler_orderChosenTickers_addToOrderList_forTicker( ticker ); + //} + } + } + + private void marketOpenEventHandler_orderChosenTickers() + { + this.marketOpenEventHandler_orderChosenTickers_addToOrderList(); + } + /// <summary> /// Handles a "Market Open" event. *************** *** 81,87 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.account.Transactions.Count == 0) ! this.account.AddCash(endOfDayTimingEventArgs.EndOfDayDateTime, ! 16000); foreach(object item in this.orders) { --- 109,117 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(16000); ! ! this.marketOpenEventHandler_orderChosenTickers(); ! foreach(object item in this.orders) { *************** *** 112,130 **** } } ! private void marketCloseEventHandler_openPosition( ! string ticker ) ! { ! double maxPositionValue = this.account.CashAmount / this.numberOfTickersToBeChosen; ! long sharesToBeBought = Convert.ToInt64( ! Math.Floor( maxPositionValue / ! this.account.DataStreamer.GetCurrentAsk( ticker ) ) ); ! this.account.AddOrder( new Order( OrderType.MarketBuy , ! new Instrument( ticker ) , sharesToBeBought ) ); ! } ! private void marketCloseEventHandler_openPositions() ! { ! foreach ( string ticker in this.chosenTickers ) ! this.marketCloseEventHandler_openPosition( ticker ); ! } public void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) --- 142,146 ---- } } ! public void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) *************** *** 132,136 **** this.marketCloseEventHandler_closePositions(); - //fiveMinutesBeforeMarketCloseEventHandler_openPositions(); } --- 148,151 ---- *************** *** 138,191 **** #region OneHourAfterMarketCloseEventHandler ! private void oneHourAfterMarketCloseEventHandler_orderChosenTickers_closePositions( ! IEndOfDayTimer endOfDayTimer ) ! { ! foreach ( Position position in this.account.Portfolio ) ! foreach(string ticker in this.chosenTickers) ! { ! if (position.Instrument.Key == ticker ) ! { ! this.account.ClosePosition( position ); ! } ! } ! ! } ! private void oneHourAfterMarketCloseEventHandler_orderChosenTickers_openPositions_forTicker( ! string ticker ) ! { ! double cashForSinglePosition = this.account.CashAmount / this.numberOfTickersToBeChosen; ! long quantity = ! Convert.ToInt64( Math.Floor( cashForSinglePosition / this.account.DataStreamer.GetCurrentBid( ticker ) ) ); ! Order order = new Order( OrderType.MarketBuy , new Instrument( ticker ) , quantity ); ! this.orders.Add(order); ! } ! private void oneHourAfterMarketCloseEventHandler_orderChosenTickers_openPositions() ! { ! foreach ( string ticker in this.chosenTickers ) ! if ( !this.account.Contains( ticker ) ) ! { ! oneHourAfterMarketCloseEventHandler_orderChosenTickers_openPositions_forTicker( ticker ); ! } ! } ! private void oneHourAfterMarketCloseEventHandler_orderChosenTickers( ! IEndOfDayTimer endOfDayTimer ) ! { ! //this.oneHourAfterMarketCloseEventHandler_orderChosenTickers_closePositions( endOfDayTimer ); ! this.oneHourAfterMarketCloseEventHandler_orderChosenTickers_openPositions(); ! } ! /// <summary> ! /// Handles a "One hour after market close" event. ! /// </summary> ! /// <param name="sender"></param> ! /// <param name="eventArgs"></param> ! public void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); ! this.orders.Clear(); ! oneHourAfterMarketCloseEventHandler_orderChosenTickers( ( IEndOfDayTimer ) sender ); ! } ! ! private void setTickers(DateTime currentDate) { --- 153,157 ---- #region OneHourAfterMarketCloseEventHandler ! private void setTickers(DateTime currentDate) { *************** *** 204,207 **** --- 170,187 ---- this.chosenTickers = (string[])GO.BestGenome.Meaning; } + + /// <summary> + /// Handles a "One hour after market close" event. + /// </summary> + /// <param name="sender"></param> + /// <param name="eventArgs"></param> + public void OneHourAfterMarketCloseEventHandler( + Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) + { + this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); + //sets tickers to be chosen next Market Open event + this.orders.Clear(); + } + #endregion Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunEfficientCTOPortfolio.cs 20 Dec 2004 20:25:12 -0000 1.3 --- RunEfficientCTOPortfolio.cs 27 Dec 2004 18:23:51 -0000 1.4 *************** *** 79,84 **** new DateTime( 2004 , 10 , 4 ) , EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); this.endDateTime = new EndOfDayDateTime( ! new DateTime( 2004 , 10 , 10 ) , EndOfDaySpecificTime.OneHourAfterMarketClose ); ! this.numIntervalDays = 1; } #region Run --- 79,84 ---- new DateTime( 2004 , 10 , 4 ) , EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); this.endDateTime = new EndOfDayDateTime( ! new DateTime( 2004 , 10 , 20 ) , EndOfDaySpecificTime.OneHourAfterMarketClose ); ! this.numIntervalDays = 7; } #region Run |