[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv16997/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVOPositions.cs PVOStrategyIntraday.cs PVOStrategyIntradayMain.cs Log Message: Updated files for the PVO strategy intraday Index: PVOStrategyIntraday.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOStrategyIntraday.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PVOStrategyIntraday.cs 1 Jan 2009 13:44:57 -0000 1.2 --- PVOStrategyIntraday.cs 12 Jan 2009 18:11:01 -0000 1.3 *************** *** 103,107 **** --- 103,109 ---- protected double inefficiencyLengthInMinutes; protected double maxOpeningLengthInMinutes; + protected double minutesFromLastInefficiencyTimeToWaitBeforeOpening; protected Time lastEntryTime; + protected Time lastInefficiencyTime; protected List<Time> openingTimesForAvailableBars; protected double currentAccountValue; *************** *** 169,172 **** --- 171,175 ---- HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMinutes, + double minutesFromLastInefficiencyTimeToWaitBeforeOpening, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 186,189 **** --- 189,194 ---- this.historicalMarketValueProviderForOutOfSample = historicalMarketValueProviderForOutOfSample; this.inefficiencyLengthInMinutes = inefficiencyLengthInMinutes; + this.minutesFromLastInefficiencyTimeToWaitBeforeOpening = + minutesFromLastInefficiencyTimeToWaitBeforeOpening; this.maxOpeningLengthInMinutes = maxOpeningLengthInMinutes; this.openingTimesForAvailableBars = openingTimesForAvailableBars; *************** *** 194,197 **** --- 199,203 ---- this.pvoStrategyIntraday_checkTimeParameters(); this.lastEntryTime = new Time("00:00:00"); + this.lastInefficiencyTime = new Time("00:00:00"); // this.optimalPositionsHaveBeenUpdated = false; } *************** *** 210,213 **** --- 216,220 ---- HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMinutes, + double minutesFromLastInefficiencyTimeToWaitBeforeOpening, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 222,225 **** --- 229,233 ---- historicalMarketValueProviderForOutOfSample, inefficiencyLengthInMinutes, + minutesFromLastInefficiencyTimeToWaitBeforeOpening, maxOpeningLengthInMinutes, openingTimesForAvailableBars, *************** *** 239,242 **** --- 247,251 ---- HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMinutes, + double minutesFromLastInefficiencyTimeToWaitBeforeOpening, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 251,254 **** --- 260,264 ---- historicalMarketValueProviderForOutOfSample, inefficiencyLengthInMinutes, + minutesFromLastInefficiencyTimeToWaitBeforeOpening, maxOpeningLengthInMinutes, openingTimesForAvailableBars, *************** *** 269,272 **** --- 279,283 ---- HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMinutes, + double minutesFromLastInefficiencyTimeToWaitBeforeOpening, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 281,284 **** --- 292,296 ---- historicalMarketValueProviderForOutOfSample, inefficiencyLengthInMinutes, + minutesFromLastInefficiencyTimeToWaitBeforeOpening, maxOpeningLengthInMinutes, openingTimesForAvailableBars, *************** *** 297,300 **** --- 309,313 ---- HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMinutes, + double minutesFromLastInefficiencyTimeToWaitBeforeOpening, double maxOpeningLengthInMinutes, List<Time> openingTimesForAvailableBars, *************** *** 308,311 **** --- 321,325 ---- historicalMarketValueProviderForOutOfSample, inefficiencyLengthInMinutes, + minutesFromLastInefficiencyTimeToWaitBeforeOpening, maxOpeningLengthInMinutes, openingTimesForAvailableBars, *************** *** 452,455 **** --- 466,470 ---- AccountManager.ClosePositions( this.account ); this.lastEntryTime = new Time("00:00:00"); + this.lastInefficiencyTime = new Time("00:00:00"); } } *************** *** 522,526 **** } #endregion newDateTimeEventHandler_openPositions ! #region newDateTimeEventHandler_updateStatus private void newDateTimeEventHandler_setPositionsAndStatus(Time currentDailyTime) --- 537,576 ---- } #endregion newDateTimeEventHandler_openPositions ! ! #region newDateTimeEventHandler_inefficiencyIsMovingBack ! private bool newDateTimeEventHandler_inefficiencyIsMovingBack(Time currentDailyTime) ! { ! bool returnValue = false; ! DateTime beginOfOscillatingPeriod = ! Time.GetDateTimeFromMerge( this.now() , this.lastInefficiencyTime ); ! DateTime endOfOscillatingPeriod = ! Time.GetDateTimeFromMerge( this.now() , currentDailyTime ); ! PVOPositionsStatus currentStatusForCurrentPositions = ! PVOPositionsStatus.InTheMiddle; ! double coefficientForThresholdLevelComputationForMovingBackSignal = ! this.minutesFromLastInefficiencyTimeToWaitBeforeOpening/this.inefficiencyLengthInMinutes; ! if(this.positionsForOutOfSample != null) ! try{ ! currentStatusForCurrentPositions = ! this.positionsForOutOfSample.GetStatus( beginOfOscillatingPeriod, endOfOscillatingPeriod, ! 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; ! } ! ! ! #endregion newDateTimeEventHandler_inefficiencyIsMovingBack ! #region newDateTimeEventHandler_updateStatus private void newDateTimeEventHandler_setPositionsAndStatus(Time currentDailyTime) *************** *** 530,536 **** DateTime endOfOscillatingPeriod = Time.GetDateTimeFromMerge(this.now() , currentDailyTime); ! this.positionsForOutOfSample = null; this.positionsForOutOfSampleStatus = PVOPositionsStatus.InTheMiddle; for(int i = 0; i<this.chosenPVOPositions.Length; i++) { --- 580,587 ---- DateTime endOfOscillatingPeriod = Time.GetDateTimeFromMerge(this.now() , currentDailyTime); ! // this.positionsForOutOfSample = null; this.positionsForOutOfSampleStatus = PVOPositionsStatus.InTheMiddle; + this.lastInefficiencyTime = new Time("00:00:00"); for(int i = 0; i<this.chosenPVOPositions.Length; i++) { *************** *** 541,545 **** this.benchmark.Ticker, this.historicalMarketValueProviderForOutOfSample, this.oversoldThresholdMAX, this.overboughtThresholdMAX); ! }catch(Exception ex){string str = ex.ToString();} if(this.positionsForOutOfSampleStatus == PVOPositionsStatus.Oversold || --- 592,597 ---- this.benchmark.Ticker, this.historicalMarketValueProviderForOutOfSample, this.oversoldThresholdMAX, this.overboughtThresholdMAX); ! ! }catch(Exception ex){string str = ex.ToString();} if(this.positionsForOutOfSampleStatus == PVOPositionsStatus.Oversold || *************** *** 547,550 **** --- 599,603 ---- { this.positionsForOutOfSample = (PVOPositions)this.chosenPVOPositions[i]; + this.lastInefficiencyTime = currentDailyTime; i = this.chosenPVOPositions.Length;//exit from for } *************** *** 593,608 **** this.newDateTimeEventHandler_updateStopLossAndTakeProfitConditions(); this.newDateTimeEventHandler_closePositions(currentTime); if( currentTime < getLastEventTimeWithCachedBars() && currentTime >= getFirstEventTimeWithCachedBars().AddMinutes(inefficiencyLengthInMinutes) && ! this.chosenPVOPositions != null ) ! //it's possible to compute inefficiency and optimization ! //has been done ! { this.newDateTimeEventHandler_setPositionsAndStatus(currentTime); this.newDateTimeEventHandler_openPositions(currentTime); ! } if( currentTime == getLastEventTimeWithCachedBars() ) this.newDateTimeEventHandler_updateTestingPositions( dateTime ); } --- 646,674 ---- 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); ! if( currentTime == getLastEventTimeWithCachedBars() ) + //it's time for new optimization, if the case + { this.newDateTimeEventHandler_updateTestingPositions( dateTime ); + this.positionsForOutOfSample = null; + this.positionsForOutOfSampleStatus = PVOPositionsStatus.InTheMiddle; + this.lastInefficiencyTime = new Time(0,0,0); + } + } Index: PVOStrategyIntradayMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOStrategyIntradayMain.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PVOStrategyIntradayMain.cs 1 Jan 2009 13:44:57 -0000 1.2 --- PVOStrategyIntradayMain.cs 12 Jan 2009 18:11:01 -0000 1.3 *************** *** 66,69 **** --- 66,70 ---- private double inefficiencyLengthInMinutes; private double maxOpeningLengthInMinutes; + private double minutesFromLastInefficiencyTimeToWaitBeforeOpening; private Timer timerForBackTester; private DateTime firstDateTime; *************** *** 74,78 **** { //this.benchmark = new Benchmark( "^GSPC" ); ! this.inefficiencyLengthInMinutes = 30; this.maxOpeningLengthInMinutes = 120; --- 75,80 ---- { //this.benchmark = new Benchmark( "^GSPC" ); ! this.inefficiencyLengthInMinutes = 120; ! this.minutesFromLastInefficiencyTimeToWaitBeforeOpening = 30; this.maxOpeningLengthInMinutes = 120; *************** *** 97,102 **** protected override IEligiblesSelector getEligiblesSelector() { ! ! int maxNumberOfEligiblesToBeChosen = 100; string tickersGroupId = "SP500"; --- 99,104 ---- protected override IEligiblesSelector getEligiblesSelector() { ! int maxNumberOfMostLiquidTickersToBeChosen = 100; ! int maxNumberOfEligiblesToBeChosen = 50; string tickersGroupId = "SP500"; *************** *** 104,112 **** bool temporizedGroup = true; int numDaysForAverageRawOpenPriceComputation = 10; ! double minPrice = 30; ! double maxPrice = 75; ! ! int maxNumberOfMostLiquidTickersToBeChosen = 150; ! int numDaysForVolatility = 10; // IEligiblesSelector eligiblesSelector = --- 106,113 ---- bool temporizedGroup = true; int numDaysForAverageRawOpenPriceComputation = 10; ! double minPrice = 25.0; ! double maxPrice = 500.0; ! ! int numDaysForVolatility = 15; // IEligiblesSelector eligiblesSelector = *************** *** 117,121 **** // minPrice , maxPrice, intervalFrameInSeconds , // this.benchmark.Ticker ); ! // IEligiblesSelector eligiblesSelector = new ByPriceMostLiquidLessVolatileOTCAlwaysQuoted( --- 118,122 ---- // minPrice , maxPrice, intervalFrameInSeconds , // this.benchmark.Ticker ); ! // LAST GOOD IEligiblesSelector eligiblesSelector = new ByPriceMostLiquidLessVolatileOTCAlwaysQuoted( *************** *** 160,164 **** double maxCorrelationAllowed = 0.96; int numberOfBestTestingPositionsToBeReturned = 50; ! numberOfBestTestingPositionsToBeReturned = 50; bool balancedWeightsOnVolatilityBase = true; float minimumAbsoluteReturnValue = 0.000001f; --- 161,165 ---- double maxCorrelationAllowed = 0.96; int numberOfBestTestingPositionsToBeReturned = 50; ! // numberOfBestTestingPositionsToBeReturned = 50; bool balancedWeightsOnVolatilityBase = true; float minimumAbsoluteReturnValue = 0.000001f; *************** *** 186,190 **** // inSampleChooser = // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2008_05_04_18_54_45_PVO_OTC_from_2006_01_01_to_2008_04_28_annlRtrn_93.08_maxDD_5.18\2008_05_04_18_54_45_PVO_OTC_from_2006_01_01_to_2008_04_28_annlRtrn_93.08_maxDD_5.18.qpL", // numberOfBestTestingPositionsToBeReturned); return inSampleChooser; --- 187,191 ---- // 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; *************** *** 194,206 **** { //int inSampleDays = 90; ! int inSampleDays = 150; int numDaysBetweenEachOptimization = 5; int minNumOfEligiblesForValidOptimization = 20; ! double oversoldThreshold = 0.0065; ! double overboughtThreshold = 0.0065; ! double oversoldThresholdMAX = 0.02; ! double overboughtThresholdMAX = 0.02; ! double stopLoss = 0.02; ! double takeProfit = 0.005; IStrategyForBacktester strategyForBacktester --- 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 *************** *** 216,220 **** historicalMarketValueProviderForInSample, historicalMarketValueProviderForOutOfSample, ! inefficiencyLengthInMinutes , maxOpeningLengthInMinutes, this.getDailyTimes(), stopLoss , takeProfit ); return strategyForBacktester; --- 217,223 ---- historicalMarketValueProviderForInSample, historicalMarketValueProviderForOutOfSample, ! inefficiencyLengthInMinutes , ! this.minutesFromLastInefficiencyTimeToWaitBeforeOpening, ! maxOpeningLengthInMinutes, this.getDailyTimes(), stopLoss , takeProfit ); return strategyForBacktester; *************** *** 237,240 **** --- 240,244 ---- 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; Index: PVOPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOPositions.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PVOPositions.cs 29 Sep 2008 21:18:13 -0000 1.4 --- PVOPositions.cs 12 Jan 2009 18:11:01 -0000 1.5 *************** *** 128,132 **** --- 128,134 ---- string benchmark, HistoricalMarketValueProvider quoteProvider, + double oversoldThreshold, double maxOversoldThreshold, + double overboughtThreshold, double maxOverboughtThreshold) { *************** *** 136,143 **** this.getOscillatingPeriodReturn(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); ! if(oscillatingPeriodReturn >= this.overboughtThreshold && oscillatingPeriodReturn <= maxOverboughtThreshold) returnValue = PVOPositionsStatus.Overbought; ! else if(oscillatingPeriodReturn <= -this.oversoldThreshold && Math.Abs(oscillatingPeriodReturn) <= maxOversoldThreshold) returnValue = PVOPositionsStatus.Oversold; --- 138,145 ---- this.getOscillatingPeriodReturn(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); ! if(oscillatingPeriodReturn >= overboughtThreshold && oscillatingPeriodReturn <= maxOverboughtThreshold) returnValue = PVOPositionsStatus.Overbought; ! else if(oscillatingPeriodReturn <= -oversoldThreshold && Math.Abs(oscillatingPeriodReturn) <= maxOversoldThreshold) returnValue = PVOPositionsStatus.Oversold; *************** *** 151,154 **** --- 153,169 ---- } + public PVOPositionsStatus GetStatus(DateTime beginOfPeriod, + DateTime endOfPeriod, + string benchmark, + HistoricalMarketValueProvider quoteProvider, + double maxOversoldThreshold, + double maxOverboughtThreshold) + { + return this.GetStatus(beginOfPeriod, endOfPeriod, + benchmark, quoteProvider, + this.oversoldThreshold, maxOversoldThreshold, + this.overboughtThreshold, maxOverboughtThreshold ); + } + public bool AreAllTickersMovingTogetherUpOrDown(DateTime beginOfPeriod, DateTime endOfPeriod, |