[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2009-03-13 15:12:04
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv30121/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVOStrategyIntraday.cs PVOStrategyIntradayMain.cs Log Message: PVOStrategyIntraday has been updated Index: PVOStrategyIntraday.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOStrategyIntraday.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PVOStrategyIntraday.cs 12 Jan 2009 18:11:01 -0000 1.3 --- PVOStrategyIntraday.cs 13 Mar 2009 15:12:01 -0000 1.4 *************** *** 104,108 **** --- 104,110 ---- protected double maxOpeningLengthInMinutes; protected double minutesFromLastInefficiencyTimeToWaitBeforeOpening; + protected double minutesFromLastLossOrProfitToWaitBeforeClosing; protected Time lastEntryTime; + protected Time lastProfitOrLossTime; protected Time lastInefficiencyTime; protected List<Time> openingTimesForAvailableBars; *************** *** 172,175 **** --- 174,178 ---- double inefficiencyLengthInMinutes, double minutesFromLastInefficiencyTimeToWaitBeforeOpening, + double minutesFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 191,194 **** --- 194,199 ---- this.minutesFromLastInefficiencyTimeToWaitBeforeOpening = minutesFromLastInefficiencyTimeToWaitBeforeOpening; + this.minutesFromLastLossOrProfitToWaitBeforeClosing = + minutesFromLastLossOrProfitToWaitBeforeClosing; this.maxOpeningLengthInMinutes = maxOpeningLengthInMinutes; this.openingTimesForAvailableBars = openingTimesForAvailableBars; *************** *** 200,204 **** this.lastEntryTime = new Time("00:00:00"); this.lastInefficiencyTime = new Time("00:00:00"); ! // this.optimalPositionsHaveBeenUpdated = false; } --- 205,209 ---- this.lastEntryTime = new Time("00:00:00"); this.lastInefficiencyTime = new Time("00:00:00"); ! this.lastProfitOrLossTime = new Time("00:00:00"); } *************** *** 217,220 **** --- 222,226 ---- double inefficiencyLengthInMinutes, double minutesFromLastInefficiencyTimeToWaitBeforeOpening, + double minutesFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 230,233 **** --- 236,240 ---- inefficiencyLengthInMinutes, minutesFromLastInefficiencyTimeToWaitBeforeOpening, + minutesFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMinutes, openingTimesForAvailableBars, *************** *** 248,251 **** --- 255,259 ---- double inefficiencyLengthInMinutes, double minutesFromLastInefficiencyTimeToWaitBeforeOpening, + double minutesFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 261,264 **** --- 269,273 ---- inefficiencyLengthInMinutes, minutesFromLastInefficiencyTimeToWaitBeforeOpening, + minutesFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMinutes, openingTimesForAvailableBars, *************** *** 280,283 **** --- 289,293 ---- double inefficiencyLengthInMinutes, double minutesFromLastInefficiencyTimeToWaitBeforeOpening, + double minutesFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 293,296 **** --- 303,307 ---- inefficiencyLengthInMinutes, minutesFromLastInefficiencyTimeToWaitBeforeOpening, + minutesFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMinutes, openingTimesForAvailableBars, *************** *** 310,313 **** --- 321,325 ---- double inefficiencyLengthInMinutes, double minutesFromLastInefficiencyTimeToWaitBeforeOpening, + double minutesFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 322,325 **** --- 334,338 ---- inefficiencyLengthInMinutes, minutesFromLastInefficiencyTimeToWaitBeforeOpening, + minutesFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMinutes, openingTimesForAvailableBars, *************** *** 328,435 **** } ! ! #region marketOpenEventHandler ! ! // protected virtual DateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) ! // { ! // DateTime beginOfOscillatingPeriod = ! // HistoricalEndOfDayTimer.GetMarketClose( ! // (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"] ); ! // return beginOfOscillatingPeriod; ! //// return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], ! //// EndOfDaySpecificTime.MarketClose ); ! // } ! // ! // private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) ! // { ! // DateTime today = timer.GetCurrentDateTime(); ! // DateTime beginOfOscillatingPeriod = ! // this.getBeginOfOscillatingPeriod(timer); ! // PVOPositionsStatus currentStatus = ! // PVOPositionsStatus.InTheMiddle; ! // for(int i = 0; i<this.chosenPVOPositions.Length; i++) ! // { ! // if(this.chosenPVOPositions[i] != null) ! // currentStatus = ! // ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, ! // this.benchmark.Ticker, this.historicalMarketValueProviderForInSample, ! // this.oversoldThresholdMAX, this.overboughtThresholdMAX); ! // if(currentStatus == PVOPositionsStatus.Oversold || ! // currentStatus == PVOPositionsStatus.Overbought ) ! // { ! // this.positionsForOutOfSample = (PVOPositions)this.chosenPVOPositions[i]; ! // i = this.chosenPVOPositions.Length;//exit from for ! // } ! // } ! // return currentStatus; ! // } ! // ! // protected void marketOpenEventHandler_openPositions(IndexBasedEndOfDayTimer timer) ! // { ! // PVOPositionsStatus pvoPositionsStatus = PVOPositionsStatus.InTheMiddle; ! // if(timer.CurrentDateArrayPosition >= 1) ! // pvoPositionsStatus = ! // this.marketOpenEventHandler_openPositions_getStatus(timer); ! // switch (pvoPositionsStatus) ! // { ! // case PVOPositionsStatus.Overbought: ! // { ! // #region manage Overbought case ! // this.positionsForOutOfSample.WeightedPositions.Reverse(); ! // try ! // { ! // AccountManager.OpenPositions( this.positionsForOutOfSample.WeightedPositions, ! // this.account ); ! // } ! // catch(Exception ex) ! // { ! // string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + ""; ! // } ! // finally ! // { ! // this.positionsForOutOfSample.WeightedPositions.Reverse(); ! // } ! // #endregion ! // break; ! // } ! // case PVOPositionsStatus.Oversold: ! // { ! // AccountManager.OpenPositions( this.positionsForOutOfSample.WeightedPositions, ! // this.account ); ! // break; ! // } ! // case PVOPositionsStatus.InTheMiddle://that is ! // { //pvoPositionsForOutOfSample has not been set ! // ! // break; ! // } ! // default: ! // { ! // //it should never been reached ! // break; ! // } ! // } ! // } ! // ! // protected void marketOpenEventHandler( ! // Object sender , DateTime dateTime ) ! // { ! // if ( this.account.Portfolio.Count == 0 && ! // this.chosenPVOPositions != null && ! // this.optimalPositionsHaveBeenUpdated == true) ! // //portfolio is empty and optimization has ! // //been already successfully launched ! // { ! // try{ ! // this.marketOpenEventHandler_openPositions( (IndexBasedEndOfDayTimer)sender ); ! // } ! // catch(TickerNotExchangedException ex) ! // { ! // string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + ""; ! // } ! // } ! // } ! ! #endregion private bool allTickersAreExchanged(DateTime dateTime, --- 341,370 ---- } ! private bool allTickersAreExchangedBeforeLastAvailableTime(DateTime fromDateTime, ! string[] tickers) ! { ! bool returnValue = true; ! try{ ! for( int i = 0; i < tickers.Length; i++ ) ! { ! Bars currentTickerBars = ! new Bars(tickers[i], fromDateTime, ! Time.GetDateTimeFromMerge(fromDateTime, ! this.openingTimesForAvailableBars[this.openingTimesForAvailableBars.Count-1]), ! 60); ! if( currentTickerBars.Rows.Count < 1 ) ! { ! returnValue = false; ! i = tickers.Length; //exit from for ! } ! } ! } ! catch(Exception ex){ ! string forBreakpoint = ex.Message; ! forBreakpoint = forBreakpoint + ""; ! returnValue = false; ! } ! return returnValue; ! } private bool allTickersAreExchanged(DateTime dateTime, *************** *** 459,466 **** private void newDateTimeEventHandler_closePositions(Time currentDailyTime) { ! if( this.account.Portfolio.Count > 0 && ! (this.lastEntryTime.AddMinutes(maxOpeningLengthInMinutes) == currentDailyTime || ! this.stopLossConditionReached || this.takeProfitConditionReached ) && ! allTickersAreExchanged( this.now(), AccountManager.GetTickersInOpenedPositions(this.account) ) ) { AccountManager.ClosePositions( this.account ); --- 394,407 ---- private void newDateTimeEventHandler_closePositions(Time currentDailyTime) { ! bool positionsHaveBeenOpenedEnough = ! (this.account.Portfolio.Count > 0 && ! this.lastEntryTime.AddMinutes(maxOpeningLengthInMinutes) <= currentDailyTime); ! bool isTimeToProfitOrToStopALoss = ! this.account.Portfolio.Count > 0 && ! (this.takeProfitConditionReached || this.stopLossConditionReached) && ! (this.lastProfitOrLossTime.AddMinutes(this.minutesFromLastLossOrProfitToWaitBeforeClosing) == currentDailyTime); ! ! if( (positionsHaveBeenOpenedEnough || isTimeToProfitOrToStopALoss ) && ! allTickersAreExchanged( this.now(), AccountManager.GetTickersInOpenedPositions(this.account) ) ) { AccountManager.ClosePositions( this.account ); *************** *** 480,484 **** timeForClose <= getLastEventTimeWithCachedBars() && this.allTickersAreExchanged( this.now(), this.positionsForOutOfSample.WeightedPositions.SignedTickers.Tickers ) && ! this.allTickersAreExchanged( dateTimeForClose, this.positionsForOutOfSample.WeightedPositions.SignedTickers.Tickers ) ) { switch (this.positionsForOutOfSampleStatus) --- 421,425 ---- timeForClose <= getLastEventTimeWithCachedBars() && this.allTickersAreExchanged( this.now(), this.positionsForOutOfSample.WeightedPositions.SignedTickers.Tickers ) && ! this.allTickersAreExchangedBeforeLastAvailableTime( dateTimeForClose, this.positionsForOutOfSample.WeightedPositions.SignedTickers.Tickers ) ) { switch (this.positionsForOutOfSampleStatus) *************** *** 537,541 **** } #endregion newDateTimeEventHandler_openPositions ! #region newDateTimeEventHandler_inefficiencyIsMovingBack private bool newDateTimeEventHandler_inefficiencyIsMovingBack(Time currentDailyTime) --- 478,482 ---- } #endregion newDateTimeEventHandler_openPositions ! #region newDateTimeEventHandler_inefficiencyIsMovingBack private bool newDateTimeEventHandler_inefficiencyIsMovingBack(Time currentDailyTime) *************** *** 549,553 **** PVOPositionsStatus.InTheMiddle; double coefficientForThresholdLevelComputationForMovingBackSignal = ! this.minutesFromLastInefficiencyTimeToWaitBeforeOpening/this.inefficiencyLengthInMinutes; if(this.positionsForOutOfSample != null) try{ --- 490,497 ---- PVOPositionsStatus.InTheMiddle; double coefficientForThresholdLevelComputationForMovingBackSignal = ! //(this.overboughtThreshold - this.takeProfit)/this.overboughtThreshold; ! this.minutesFromLastInefficiencyTimeToWaitBeforeOpening/ ! // this.inefficiencyLengthInMinutes; ! 100000; if(this.positionsForOutOfSample != null) try{ *************** *** 556,570 **** this.benchmark.Ticker, this.historicalMarketValueProviderForOutOfSample, this.oversoldThreshold * coefficientForThresholdLevelComputationForMovingBackSignal, ! 0.50, this.overboughtThreshold * coefficientForThresholdLevelComputationForMovingBackSignal, ! 0.50); ! }catch(Exception ex){string str = ex.ToString();} returnValue = ( (currentStatusForCurrentPositions == PVOPositionsStatus.Overbought && this.positionsForOutOfSampleStatus == PVOPositionsStatus.Oversold) || (currentStatusForCurrentPositions == PVOPositionsStatus.Oversold && this.positionsForOutOfSampleStatus == PVOPositionsStatus.Overbought) ); ! if( returnValue == false ) ! this.positionsForOutOfSample = null; //it forces a new research for inefficiencies return returnValue; } --- 500,518 ---- this.benchmark.Ticker, this.historicalMarketValueProviderForOutOfSample, this.oversoldThreshold * coefficientForThresholdLevelComputationForMovingBackSignal, ! this.oversoldThreshold, this.overboughtThreshold * coefficientForThresholdLevelComputationForMovingBackSignal, ! this.overboughtThreshold ); ! }catch{} returnValue = ( (currentStatusForCurrentPositions == PVOPositionsStatus.Overbought && this.positionsForOutOfSampleStatus == PVOPositionsStatus.Oversold) || (currentStatusForCurrentPositions == PVOPositionsStatus.Oversold && this.positionsForOutOfSampleStatus == PVOPositionsStatus.Overbought) ); ! if( (returnValue == false && ! currentDailyTime >= this.lastInefficiencyTime.AddMinutes(this.inefficiencyLengthInMinutes) ) || ! returnValue == true ) ! //positions are not moving back and the same n° of minutes as inefficiency length ! //has elapsed OR positions are moving back (the gap is closing) ! this.lastInefficiencyTime = new Time(0,0,0); //it forces a new research of an inefficiency return returnValue; } *************** *** 583,587 **** this.positionsForOutOfSampleStatus = PVOPositionsStatus.InTheMiddle; ! this.lastInefficiencyTime = new Time("00:00:00"); for(int i = 0; i<this.chosenPVOPositions.Length; i++) { --- 531,535 ---- this.positionsForOutOfSampleStatus = PVOPositionsStatus.InTheMiddle; ! //this.lastInefficiencyTime = new Time("00:00:00"); for(int i = 0; i<this.chosenPVOPositions.Length; i++) { *************** *** 607,615 **** #region newDateTimeEventHandler_updateStopLossAndTakeProfitConditions ! protected virtual void newDateTimeEventHandler_updateStopLossAndTakeProfitConditions() { //this.previousAccountValue has been set at opening positions this.stopLossConditionReached = false; this.takeProfitConditionReached = false; if(this.account.Portfolio.Count > 0) { --- 555,564 ---- #region newDateTimeEventHandler_updateStopLossAndTakeProfitConditions ! protected virtual void newDateTimeEventHandler_updateStopLossAndTakeProfitConditions(Time currentDailyTime) { //this.previousAccountValue has been set at opening positions this.stopLossConditionReached = false; this.takeProfitConditionReached = false; + this.lastProfitOrLossTime = new Time("00:00:00"); if(this.account.Portfolio.Count > 0) { *************** *** 623,627 **** { this.stopLossConditionReached = true; ! this.takeProfitConditionReached = false; } else if (!double.IsInfinity(portfolioGainOrLoss) && --- 572,576 ---- { this.stopLossConditionReached = true; ! this.lastProfitOrLossTime = currentDailyTime; } else if (!double.IsInfinity(portfolioGainOrLoss) && *************** *** 629,634 **** { - this.stopLossConditionReached = false; this.takeProfitConditionReached = true; } } --- 578,583 ---- { this.takeProfitConditionReached = true; + this.lastProfitOrLossTime = currentDailyTime; } } *************** *** 644,663 **** { Time currentTime = new Time( dateTime ); ! this.newDateTimeEventHandler_updateStopLossAndTakeProfitConditions(); this.newDateTimeEventHandler_closePositions(currentTime); ! ! if( currentTime < getLastEventTimeWithCachedBars() && currentTime >= ! getFirstEventTimeWithCachedBars().AddMinutes(inefficiencyLengthInMinutes) && ! this.chosenPVOPositions != null && this.positionsForOutOfSample == null ) ! //it's possible to compute inefficiency and optimization has been done and no inefficiency ! //has been found this.newDateTimeEventHandler_setPositionsAndStatus(currentTime); ! if( currentTime == ! this.lastInefficiencyTime.AddMinutes(this.minutesFromLastInefficiencyTimeToWaitBeforeOpening) && ! this.newDateTimeEventHandler_inefficiencyIsMovingBack(currentTime) ) ! //it's time for checking if inefficiency is moving back and the last inefficiency found is ! //moving back this.newDateTimeEventHandler_openPositions(currentTime); --- 593,614 ---- { Time currentTime = new Time( dateTime ); ! this.newDateTimeEventHandler_updateStopLossAndTakeProfitConditions(currentTime); this.newDateTimeEventHandler_closePositions(currentTime); ! if( this.account.Portfolio.Count == 0 && ! this.chosenPVOPositions != null && ! this.lastInefficiencyTime == new Time(0,0,0) && ! currentTime < getLastEventTimeWithCachedBars() && currentTime >= ! getFirstEventTimeWithCachedBars().AddMinutes(inefficiencyLengthInMinutes) ) ! //portfolio empty, optimization done, no inefficiency found, time OK this.newDateTimeEventHandler_setPositionsAndStatus(currentTime); ! if( this.account.Portfolio.Count == 0 && ! currentTime >= ! this.lastInefficiencyTime.AddMinutes(this.minutesFromLastInefficiencyTimeToWaitBeforeOpening) ! && ! this.newDateTimeEventHandler_inefficiencyIsMovingBack(currentTime) ! ) ! //it's time for starting checking if the last inefficiency found is moving back this.newDateTimeEventHandler_openPositions(currentTime); *************** *** 685,690 **** EligibleTickers eligibles = this.eligiblesSelector.GetEligibleTickers(history); ! this.updateReturnsManager(history.FirstDateTime, ! history.LastDateTime); if( ( this.eligiblesSelector is DummyEligibleSelector && this.inSampleChooser != null ) || --- 636,641 ---- EligibleTickers eligibles = this.eligiblesSelector.GetEligibleTickers(history); ! this.updateReturnsManager(Time.GetDateTimeFromMerge(history.FirstDateTime, this.openingTimesForAvailableBars[0]), ! Time.GetDateTimeFromMerge(history.LastDateTime, this.openingTimesForAvailableBars[this.openingTimesForAvailableBars.Count - 1])); if( ( this.eligiblesSelector is DummyEligibleSelector && this.inSampleChooser != null ) || *************** *** 695,704 **** this.updateTestingPositions_updateThresholds(); this.logOptimizationInfo(eligibles); - // this.optimalPositionsHaveBeenUpdated = true; } - // else - // { - // this.optimalPositionsHaveBeenUpdated = false; - // } } --- 646,650 ---- *************** *** 722,736 **** DateTime dateTime ) { - //OLD - numDaysBetweenEachOptimization --> market days - // if( this.account.Transactions.Count <= 1 || - // (this.numDaysElapsedSinceLastOptimization == - // this.numDaysBetweenEachOptimization) ) - //num days without optimization has elapsed or - //no transaction, except for adding cash, has been executed - //NEW - numDaysBetweenEachOptimization --> calendar days if ( this.optimalTestingPositionsAreToBeUpdated() ) { this.updateTestingPositions( dateTime ); - //sets tickers to be chosen next time this.lastOptimizationDateTime = this.now(); } --- 668,674 ---- *************** *** 744,752 **** protected virtual void updateReturnsManager(DateTime firstDateTime, ! DateTime lastDayDateTime) { ReturnIntervals returnIntervals = ! new DailyOpenToCloseIntervals( firstDateTime, lastDayDateTime, this.benchmark.Ticker ); if( this.inSampleChooser is PVOCorrelationChooser ) { --- 682,696 ---- protected virtual void updateReturnsManager(DateTime firstDateTime, ! DateTime lastDateTime) { ReturnIntervals returnIntervals = ! new DailyOpenToCloseIntervals( firstDateTime, lastDateTime, this.benchmark.Ticker ); + if(this.inSampleChooser is PVOIntradayCorrelationChooser) + returnIntervals = + new IntradayIntervals(firstDateTime, lastDateTime, + ((PVOIntradayCorrelationChooser)this.inSampleChooser).ReturnIntervalLengthInMinutes, + this.benchmark.Ticker); + if( this.inSampleChooser is PVOCorrelationChooser ) { *************** *** 754,779 **** { case IntervalsType.CloseToCloseIntervals: ! returnIntervals = new CloseToCloseIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.OpenToOpenIntervals: ! returnIntervals = new OpenToOpenIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.CloseToOpenIntervals: ! returnIntervals = new CloseToOpenIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker); break; case IntervalsType.OpenToCloseIntervals: ! returnIntervals = new DailyOpenToCloseIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker ); break; case IntervalsType.OpenToCloseCloseToOpenIntervals: returnIntervals = new OpenToCloseCloseToOpenIntervals( ! firstDateTime, lastDayDateTime, this.benchmark.Ticker); break; default: // it should never be reached ! returnIntervals = new DailyOpenToCloseIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker ); break; --- 698,723 ---- { case IntervalsType.CloseToCloseIntervals: ! returnIntervals = new CloseToCloseIntervals(firstDateTime, lastDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.OpenToOpenIntervals: ! returnIntervals = new OpenToOpenIntervals(firstDateTime, lastDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.CloseToOpenIntervals: ! returnIntervals = new CloseToOpenIntervals(firstDateTime, lastDateTime, this.benchmark.Ticker); break; case IntervalsType.OpenToCloseIntervals: ! returnIntervals = new DailyOpenToCloseIntervals(firstDateTime, lastDateTime, this.benchmark.Ticker ); break; case IntervalsType.OpenToCloseCloseToOpenIntervals: returnIntervals = new OpenToCloseCloseToOpenIntervals( ! firstDateTime, lastDateTime, this.benchmark.Ticker); break; default: // it should never be reached ! returnIntervals = new DailyOpenToCloseIntervals(firstDateTime, lastDateTime, this.benchmark.Ticker ); break; *************** *** 783,787 **** this.returnsManager = new ReturnsManager( returnIntervals , this.historicalMarketValueProviderForInSample); - } --- 727,730 ---- Index: PVOStrategyIntradayMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOStrategyIntradayMain.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PVOStrategyIntradayMain.cs 12 Jan 2009 18:11:01 -0000 1.3 --- PVOStrategyIntradayMain.cs 13 Mar 2009 15:12:01 -0000 1.4 *************** *** 64,70 **** private HistoricalMarketValueProvider historicalMarketValueProviderForInSample; private HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample; private double inefficiencyLengthInMinutes; private double maxOpeningLengthInMinutes; ! private double minutesFromLastInefficiencyTimeToWaitBeforeOpening; private Timer timerForBackTester; private DateTime firstDateTime; --- 64,73 ---- private HistoricalMarketValueProvider historicalMarketValueProviderForInSample; private HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample; + private HistoricalMarketValueProvider historicalMarketValueProviderForTheBackTester; private double inefficiencyLengthInMinutes; private double maxOpeningLengthInMinutes; ! private double minutesFromLastInefficiencyToWaitBeforeOpening; ! private double minutesFromLastLossOrProfitToWaitBeforeClosing; ! private int stepInMinutesForTimer; private Timer timerForBackTester; private DateTime firstDateTime; *************** *** 74,91 **** public PVOStrategyIntradayMain() { ! //this.benchmark = new Benchmark( "^GSPC" ); ! this.inefficiencyLengthInMinutes = 120; ! this.minutesFromLastInefficiencyTimeToWaitBeforeOpening = 30; ! this.maxOpeningLengthInMinutes = 120; ! ! this.firstDateTime = new DateTime( 2006 , 1 , 1 ); ! this.lastDateTime = new DateTime( 2007 , 12, 31 ); this.intervalFrameInSeconds = 60; ! this.benchmark = new Benchmark( "MSFT" ); ! this.historicalMarketValueProviderForInSample = ! new HistoricalAdjustedQuoteProvider(); this.historicalMarketValueProviderForOutOfSample = this.getHistoricalBarProvider(); ! this.timerForBackTester = new IndexBasedHistoricalTimer(this.benchmark.Ticker, this.firstDateTime, --- 77,109 ---- public PVOStrategyIntradayMain() { ! this.inefficiencyLengthInMinutes = 30; ! this.maxOpeningLengthInMinutes = 240; ! this.minutesFromLastInefficiencyToWaitBeforeOpening = 1; ! this.minutesFromLastLossOrProfitToWaitBeforeClosing = 0; ! this.stepInMinutesForTimer = 1; this.intervalFrameInSeconds = 60; ! ! this.firstDateTime = new DateTime( 2006 , 2 , 1 ); ! this.lastDateTime = new DateTime( 2006 , 12, 31 ); ! ! this.benchmark = new Benchmark( "CCE" ); ! this.historicalMarketValueProviderForOutOfSample = this.getHistoricalBarProvider(); ! ! this.historicalMarketValueProviderForInSample = ! // new HistoricalAdjustedQuoteProvider(); ! new HistoricalBarInterpolatingProvider( this.getBarCache() ); ! ! this.historicalMarketValueProviderForTheBackTester = ! // new HistoricalBarProvider( ! // new SimpleBarCache( intervalFrameInSeconds, ! // BarComponent.Open ) ); ! // new HistoricalBarProvider( ! // new DailyBarCache( intervalFrameInSeconds, ! // this.getDailyTimes() ) ); ! this.historicalMarketValueProviderForOutOfSample; ! ! this.timerForBackTester = new IndexBasedHistoricalTimer(this.benchmark.Ticker, this.firstDateTime, *************** *** 93,104 **** this.getDailyTimes(), this.intervalFrameInSeconds); - // definition for the Fitness Evaluator - // IEquityEvaluator equityEvaluator = new SharpeRatio(); } protected override IEligiblesSelector getEligiblesSelector() { ! int maxNumberOfMostLiquidTickersToBeChosen = 100; ! int maxNumberOfEligiblesToBeChosen = 50; string tickersGroupId = "SP500"; --- 111,120 ---- this.getDailyTimes(), this.intervalFrameInSeconds); } protected override IEligiblesSelector getEligiblesSelector() { ! ! int maxNumberOfEligiblesToBeChosen = 100; string tickersGroupId = "SP500"; *************** *** 106,113 **** bool temporizedGroup = true; int numDaysForAverageRawOpenPriceComputation = 10; ! double minPrice = 25.0; ! double maxPrice = 500.0; ! ! int numDaysForVolatility = 15; // IEligiblesSelector eligiblesSelector = --- 122,131 ---- bool temporizedGroup = true; int numDaysForAverageRawOpenPriceComputation = 10; ! double minPrice = 30; ! double maxPrice = 300; ! ! int maxNumberOfMostLiquidTickersToBeChosen = 150; ! int numDaysForVolatility = 10; ! int minimumNumberOfMinutelyBarsForEachDayForInSample = 20; // IEligiblesSelector eligiblesSelector = *************** *** 119,130 **** // this.benchmark.Ticker ); // LAST GOOD IEligiblesSelector eligiblesSelector = ! new ByPriceMostLiquidLessVolatileOTCAlwaysQuoted( ! tickersGroupId , temporizedGroup , maxNumberOfEligiblesToBeChosen , ! maxNumberOfMostLiquidTickersToBeChosen , ! numDaysForAverageRawOpenPriceComputation , ! numDaysForVolatility , ! minPrice , maxPrice ); // IEligiblesSelector eligiblesSelector = // new ByPriceMostLiquidAlwaysQuoted( --- 137,157 ---- // this.benchmark.Ticker ); // LAST GOOD + // IEligiblesSelector eligiblesSelector = + // new ByPriceMostLiquidLessVolatileOTCAlwaysQuoted( + // tickersGroupId , temporizedGroup , + // maxNumberOfEligiblesToBeChosen , + // maxNumberOfMostLiquidTickersToBeChosen , + // numDaysForAverageRawOpenPriceComputation , + // numDaysForVolatility , + // minPrice , maxPrice ); + IEligiblesSelector eligiblesSelector = ! new ByPriceMostLiquidAlwaysIntradayQuoted( ! tickersGroupId , this.benchmark, temporizedGroup , maxNumberOfEligiblesToBeChosen , ! numDaysForAverageRawOpenPriceComputation , ! minPrice , maxPrice, ! minimumNumberOfMinutelyBarsForEachDayForInSample ); ! // IEligiblesSelector eligiblesSelector = // new ByPriceMostLiquidAlwaysQuoted( *************** *** 161,168 **** double maxCorrelationAllowed = 0.96; int numberOfBestTestingPositionsToBeReturned = 50; ! // numberOfBestTestingPositionsToBeReturned = 50; bool balancedWeightsOnVolatilityBase = true; ! float minimumAbsoluteReturnValue = 0.000001f; float maximumAbsoluteReturnValue = 100000f; //correlation is computed only for returns //between minimum and maximum --- 188,196 ---- double maxCorrelationAllowed = 0.96; int numberOfBestTestingPositionsToBeReturned = 50; ! numberOfBestTestingPositionsToBeReturned = 50; bool balancedWeightsOnVolatilityBase = true; ! float minimumAbsoluteReturnValue = 0.00005f; float maximumAbsoluteReturnValue = 100000f; + int returnIntervalLengthInMinutesForCorrelationProvider = 120; //correlation is computed only for returns //between minimum and maximum *************** *** 176,191 **** // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, this.benchmark.Ticker); IInSampleChooser inSampleChooser = ! new PVO_CTCCorrelationChooser(numberOfBestTestingPositionsToBeReturned, ! 1 , maxCorrelationAllowed , balancedWeightsOnVolatilityBase, minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, this.benchmark.Ticker); // //office // inSampleChooser = // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2008_08_06_16_57_34_PVO_OTC_from_2003_06_01_to_2008_04_28_annlRtrn_3,34_maxDD_11,36\2008_08_06_16_57_34_PVO_OTC_from_2003_06_01_to_2008_04_28_annlRtrn_3,34_maxDD_11,36.qpL", // numberOfBestTestingPositionsToBeReturned); //home // inSampleChooser = // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2009_01_07_18_51_09_PVOIntraday_from_2006_01_01_to_2007_12_31_annlRtrn_15.67_maxDD_2.91\2009_01_07_18_51_09_PVOIntraday_from_2006_01_01_to_2007_12_31_annlRtrn_15.67_maxDD_2.91.qpL", // numberOfBestTestingPositionsToBeReturned); return inSampleChooser; --- 204,224 ---- // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, this.benchmark.Ticker); IInSampleChooser inSampleChooser = ! // new PVO_CTCCorrelationChooser(numberOfBestTestingPositionsToBeReturned, ! // 1 , maxCorrelationAllowed , balancedWeightsOnVolatilityBase, ! // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, this.benchmark.Ticker); ! new PVOIntradayCorrelationChooser(numberOfBestTestingPositionsToBeReturned, ! returnIntervalLengthInMinutesForCorrelationProvider , ! maxCorrelationAllowed , balancedWeightsOnVolatilityBase, minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, this.benchmark.Ticker); + // //office // inSampleChooser = // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2009_01_05_13_40_28_PVOIntraday_from_2006_01_01_to_2007_12_31_annlRtrn_17,84_maxDD_4,52\2009_01_05_13_40_28_PVOIntraday_from_2006_01_01_to_2007_12_31_annlRtrn_17,84_maxDD_4,52.qpL", // numberOfBestTestingPositionsToBeReturned); //home // inSampleChooser = // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2009_02_17_23_17_03_PVOIntraday_from_2006_01_01_to_2007_12_31_annlRtrn_24.44_maxDD_3.05\2009_02_17_23_17_03_PVOIntraday_from_2006_01_01_to_2007_12_31_annlRtrn_24.44_maxDD_3.05.qpL", // numberOfBestTestingPositionsToBeReturned); return inSampleChooser; *************** *** 195,207 **** { //int inSampleDays = 90; ! int inSampleDays = 120; ! int numDaysBetweenEachOptimization = 5; int minNumOfEligiblesForValidOptimization = 20; ! double oversoldThreshold = 0.0055; ! double overboughtThreshold = 0.0055; ! double oversoldThresholdMAX = 0.015; ! double overboughtThresholdMAX = 0.015; ! double stopLoss = 0.01; ! double takeProfit = 0.0045; IStrategyForBacktester strategyForBacktester --- 228,240 ---- { //int inSampleDays = 90; ! int inSampleDays = 30; ! int numDaysBetweenEachOptimization = 4; int minNumOfEligiblesForValidOptimization = 20; ! double oversoldThreshold = 0.005;//0.006 ! double overboughtThreshold = 0.005;//0.006 ! double oversoldThresholdMAX = 0.025; ! double overboughtThresholdMAX = 0.025; ! double stopLoss = 0.02; ! double takeProfit = 0.0025;//0.0045 IStrategyForBacktester strategyForBacktester *************** *** 217,222 **** historicalMarketValueProviderForInSample, historicalMarketValueProviderForOutOfSample, ! inefficiencyLengthInMinutes , ! this.minutesFromLastInefficiencyTimeToWaitBeforeOpening, maxOpeningLengthInMinutes, this.getDailyTimes(), stopLoss , takeProfit ); --- 250,255 ---- historicalMarketValueProviderForInSample, historicalMarketValueProviderForOutOfSample, ! inefficiencyLengthInMinutes , minutesFromLastInefficiencyToWaitBeforeOpening, ! this.minutesFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMinutes, this.getDailyTimes(), stopLoss , takeProfit ); *************** *** 228,246 **** private List<Time> getDailyTimes() { ! List<Time> dailyTimes = new List<Time>(); ! dailyTimes.Add( new Time("10:00:00") ); ! dailyTimes.Add( new Time("10:30:00") ); ! dailyTimes.Add( new Time("11:00:00") ); ! dailyTimes.Add( new Time("11:30:00") ); ! dailyTimes.Add( new Time("12:00:00") ); ! dailyTimes.Add( new Time("12:30:00") ); ! dailyTimes.Add( new Time("13:00:00") ); ! dailyTimes.Add( new Time("13:30:00") ); ! dailyTimes.Add(new Time("14:00:00") ); ! dailyTimes.Add(new Time("14:30:00") ); ! dailyTimes.Add(new Time("15:00:00") ); ! dailyTimes.Add(new Time("15:30:00") ); ! dailyTimes.Add(new Time("16:00:00") ); ! return dailyTimes; } private IBarCache getBarCache() --- 261,267 ---- private List<Time> getDailyTimes() { ! return Time.GetIntermediateTimes(new Time("09:45:00"), ! new Time("16:00:00"), ! this.stepInMinutesForTimer); } private IBarCache getBarCache() *************** *** 270,283 **** // new InteractiveBrokerAccountProvider(fixedPercentageSlippage); double cashToStart = 25000; ! double maxRunningHours = 5; ! HistoricalMarketValueProvider quoteProviderForBackTester = ! this.historicalMarketValueProviderForOutOfSample; ! // quoteProviderForBackTester = ! // new HistoricalRawQuoteProvider(); EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( backTestId , this.timerForBackTester, this.strategyForBacktester , ! quoteProviderForBackTester , accountProvider , firstDateTime , lastDateTime , this.benchmark , cashToStart , maxRunningHours ); --- 291,300 ---- // new InteractiveBrokerAccountProvider(fixedPercentageSlippage); double cashToStart = 25000; ! double maxRunningHours = 15; EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( backTestId , this.timerForBackTester, this.strategyForBacktester , ! this.historicalMarketValueProviderForTheBackTester , accountProvider , firstDateTime , lastDateTime , this.benchmark , cashToStart , maxRunningHours ); |