[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting EndOfDayTimerHandlerCTC.cs,
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-07-25 23:00:06
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26639/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerCTC.cs Log Message: Now the EndOfDayTimerHandler for the Close To Close efficient portfolio contains a handler for the OneHourAfterMarketCloseEvent. Now, if at a given Close some positions are closed, new positions are opened at the next Close. Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EndOfDayTimerHandlerCTC.cs 24 Jun 2005 22:52:25 -0000 1.9 --- EndOfDayTimerHandlerCTC.cs 25 Jul 2005 22:59:57 -0000 1.10 *************** *** 51,55 **** protected double currentAccountValue; protected double previousAccountValue; ! public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, --- 51,55 ---- protected double currentAccountValue; protected double previousAccountValue; ! public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, *************** *** 71,75 **** this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.daysCounter = -1; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.stopLossConditionReached = false; --- 71,75 ---- this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.daysCounter = 0; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.stopLossConditionReached = false; *************** *** 77,82 **** this.previousAccountValue = 0.0; } ! ! #region MarketOpenEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { --- 77,135 ---- this.previousAccountValue = 0.0; } ! ! ! #region MarketCloseEventHandler ! ! ! ! protected void updateStopLossCondition() ! { ! this.previousAccountValue = this.currentAccountValue; ! this.currentAccountValue = this.account.GetMarketValue(); ! if((this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) ! { ! this.stopLossConditionReached = true; ! } ! else ! { ! this.stopLossConditionReached = false; ! } ! } ! ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! bool positionsJustClosed = false; ! this.updateStopLossCondition(); ! if(this.account.Portfolio.Count > 0) ! //portfolio is not empty ! { ! this.daysCounter++; ! if(this.daysCounter == this.numDaysOfPortfolioLife || ! this.stopLossConditionReached) ! //num days of portfolio life or ! //max acceptable close to close drawdown reached ! { ! this.closePositions(); ! this.daysCounter = 0; ! positionsJustClosed = true; ! } ! } ! ! if(this.account.Portfolio.Count == 0 && ! !positionsJustClosed) ! //portfolio is empty but it has not been closed ! //at the current close ! { ! this.openPositions(); ! this.daysCounter = 0; ! } ! } ! ! #endregion ! ! #region OneHourAfterMarketCloseEventHandler ! protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { *************** *** 125,191 **** } /// <summary> ! /// Handles a "Market Open" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.updateStopLossCondition(); ! if(this.daysCounter == -1 || this.daysCounter == this.numDaysOfPortfolioLife - 1 || ! this.stopLossConditionReached ) ! //at the beginning, after num days of porfolio life has elasped, ! //or when the stop loss condition is reached { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //it sets tickers to be chosen at next close - this.orders.Clear(); } } #endregion - - #region MarketCloseEventHandler - - - - protected void updateStopLossCondition() - { - this.previousAccountValue = this.currentAccountValue; - this.currentAccountValue = this.account.GetMarketValue(); - if((this.currentAccountValue - this.previousAccountValue) - /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) - { - this.stopLossConditionReached = true; - } - else - { - this.stopLossConditionReached = false; - } - } - - public override void MarketCloseEventHandler( - Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) - { - if(this.daysCounter == -1 || - this.daysCounter == this.numDaysOfPortfolioLife || - this.stopLossConditionReached) - //it is the first day or num days of portfolio life or - //max acceptable close to close draw down - //has been reached - { - this.closePositions(); - this.openPositions(); - this.daysCounter = 0; - } - else - { - this.daysCounter++; - } - } - - #endregion - - } } --- 178,199 ---- } + /// <summary> ! /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! ! if(this.account.Portfolio.Count == 0 ) { + this.orders.Clear(); this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //it sets tickers to be chosen at next close } } #endregion } } |