[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2008-08-15 04:53:05
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19183/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVO_OTCLogItem.cs PVO_OTCMain.cs PVO_OTCStrategy.cs PVO_OTCStrategyLessCorrelated.cs PVOLogItem.cs PVOMain.cs PVOPositions.cs PVOPositionsStatus.cs PVOStrategy.cs Log Message: Minor changes for the some files implementing the PVO strategy Index: PVOStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOStrategy.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PVOStrategy.cs 8 Apr 2008 21:59:09 -0000 1.4 --- PVOStrategy.cs 14 Aug 2008 23:28:06 -0000 1.5 *************** *** 92,96 **** protected double currentAccountValue; protected double previousAccountValue; ! private string description_GetDescriptionForChooser() { --- 92,100 ---- protected double currentAccountValue; protected double previousAccountValue; ! protected double oversoldThreshold; ! protected double overboughtThreshold; ! protected double oversoldThresholdMAX; ! protected double overboughtThresholdMAX; ! private string description_GetDescriptionForChooser() { *************** *** 129,132 **** --- 133,140 ---- Benchmark benchmark, int numDaysBetweenEachOptimization, + double oversoldThreshold, + double overboughtThreshold, + double oversoldThresholdMAX, + double overboughtThresholdMAX, HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, *************** *** 142,146 **** this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.minimumAcceptableGain = minimumAcceptableGain; ! this.stopLossConditionReached = false; this.currentAccountValue = 0.0; --- 150,157 ---- this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.minimumAcceptableGain = minimumAcceptableGain; ! this.oversoldThreshold = oversoldThreshold; ! this.overboughtThreshold = overboughtThreshold; ! this.oversoldThresholdMAX = oversoldThresholdMAX; ! this.overboughtThresholdMAX = overboughtThresholdMAX; this.stopLossConditionReached = false; this.currentAccountValue = 0.0; *************** *** 157,160 **** --- 168,175 ---- Benchmark benchmark, int numDaysBetweenEachOptimization, + double oversoldThreshold, + double overboughtThreshold, + double oversoldThresholdMAX, + double overboughtThresholdMAX, HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, *************** *** 164,167 **** --- 179,184 ---- this.pvoStrategy(eligiblesSelector, inSampleDays , numDaysForOscillatingPeriod , numberOfTickersToBeChosen , benchmark , numDaysBetweenEachOptimization , + oversoldThreshold, overboughtThreshold, + oversoldThresholdMAX, overboughtThresholdMAX, historicalQuoteProvider , maxAcceptableCloseToCloseDrawdown , minimumAcceptableGain ); *************** *** 170,173 **** --- 187,213 ---- public PVOStrategy(IEligiblesSelector eligiblesSelector, + IInSampleChooser inSampleChooser, + int inSampleDays, + int numDaysForOscillatingPeriod, + int numberOfTickersToBeChosen, + Benchmark benchmark, + int numDaysBetweenEachOptimization, + double oversoldThreshold, + double overboughtThreshold, + HistoricalQuoteProvider historicalQuoteProvider, + double maxAcceptableCloseToCloseDrawdown, + double minimumAcceptableGain) + + { + this.pvoStrategy(eligiblesSelector, inSampleDays , numDaysForOscillatingPeriod , + numberOfTickersToBeChosen , benchmark , numDaysBetweenEachOptimization , + oversoldThreshold, overboughtThreshold, + double.MaxValue, double.MaxValue, + historicalQuoteProvider , maxAcceptableCloseToCloseDrawdown , + minimumAcceptableGain ); + this.inSampleChooser = inSampleChooser; + } + + public PVOStrategy(IEligiblesSelector eligiblesSelector, TestingPositions[] chosenPVOPositions, int inSampleDays, *************** *** 176,179 **** --- 216,223 ---- Benchmark benchmark, int numDaysBetweenEachOptimization, + double oversoldThreshold, + double overboughtThreshold, + double oversoldThresholdMAX, + double overboughtThresholdMAX, HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, *************** *** 183,186 **** --- 227,255 ---- this.pvoStrategy(eligiblesSelector, inSampleDays , numDaysForOscillatingPeriod , numberOfTickersToBeChosen , benchmark , numDaysBetweenEachOptimization , + oversoldThreshold, overboughtThreshold, + oversoldThresholdMAX, overboughtThresholdMAX, + historicalQuoteProvider , maxAcceptableCloseToCloseDrawdown , + minimumAcceptableGain ); + this.chosenPVOPositions = chosenPVOPositions; + } + + public PVOStrategy(IEligiblesSelector eligiblesSelector, + TestingPositions[] chosenPVOPositions, + int inSampleDays, + int numDaysForOscillatingPeriod, + int numberOfTickersToBeChosen, + Benchmark benchmark, + int numDaysBetweenEachOptimization, + double oversoldThreshold, + double overboughtThreshold, + HistoricalQuoteProvider historicalQuoteProvider, + double maxAcceptableCloseToCloseDrawdown, + double minimumAcceptableGain) + + { + this.pvoStrategy(eligiblesSelector, inSampleDays , numDaysForOscillatingPeriod , + numberOfTickersToBeChosen , benchmark , numDaysBetweenEachOptimization , + oversoldThreshold, overboughtThreshold, + double.MaxValue , double.MaxValue , historicalQuoteProvider , maxAcceptableCloseToCloseDrawdown , minimumAcceptableGain ); *************** *** 233,237 **** EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus pvoPositionsStatus = ! this.pvoPositionsForOutOfSample.GetStatus(beginOfOscillatingPeriod, today , this.benchmark.Ticker, this.historicalQuoteProvider); if(pvoPositionsStatus == PVOPositionsStatus.Overbought && this.portfolioHasBeenOversold) --- 302,307 ---- EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus pvoPositionsStatus = ! this.pvoPositionsForOutOfSample.GetStatus(beginOfOscillatingPeriod, today , this.benchmark.Ticker, this.historicalQuoteProvider, ! double.MaxValue, double.MaxValue); if(pvoPositionsStatus == PVOPositionsStatus.Overbought && this.portfolioHasBeenOversold) *************** *** 258,262 **** currentStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, ! this.benchmark.Ticker, this.historicalQuoteProvider); if(currentStatus == PVOPositionsStatus.Oversold || currentStatus == PVOPositionsStatus.Overbought ) --- 328,333 ---- currentStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, ! this.benchmark.Ticker, this.historicalQuoteProvider, ! double.MaxValue, double.MaxValue); if(currentStatus == PVOPositionsStatus.Oversold || currentStatus == PVOPositionsStatus.Overbought ) *************** *** 363,367 **** try{ this.marketCloseEventHandler_updateStopLossAndTakeProfitConditions(); ! this.marketCloseEventHandler_closePositionsIfNeeded(); if( this.chosenPVOPositions != null ) //PVOPositions have been chosen by the chooser --- 434,438 ---- try{ this.marketCloseEventHandler_updateStopLossAndTakeProfitConditions(); ! //this.marketCloseEventHandler_closePositionsIfNeeded(); if( this.chosenPVOPositions != null ) //PVOPositions have been chosen by the chooser *************** *** 371,375 **** //positions are opened only if thresholds are reached else//there are some opened positions ! this.marketCloseEventHandler_reverseIfNeeded((IndexBasedEndOfDayTimer)sender); } } --- 442,447 ---- //positions are opened only if thresholds are reached else//there are some opened positions ! this.marketCloseEventHandler_closePositionsIfNeeded(); ! //this.marketCloseEventHandler_reverseIfNeeded((IndexBasedEndOfDayTimer)sender); } } *************** *** 436,439 **** --- 508,521 ---- this.NewMessage( this , newMessageEventArgs ); } + private void updateTestingPositions_updateThresholds() + { + for(int i = 0; i<this.chosenPVOPositions.Length; i++) + { + ((PVOPositions)this.chosenPVOPositions[i]).OversoldThreshold = + this.oversoldThreshold; + ((PVOPositions)this.chosenPVOPositions[i]).OverboughtThreshold = + this.overboughtThreshold; + } + } private void logOptimizationInfo( EligibleTickers eligibleTickers ) { *************** *** 456,459 **** --- 538,542 ---- if(this.inSampleChooser != null) this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager ); + this.updateTestingPositions_updateThresholds(); this.logOptimizationInfo(eligibles); } Index: PVO_OTCLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCLogItem.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PVO_OTCLogItem.cs 26 Apr 2008 09:52:44 -0000 1.3 --- PVO_OTCLogItem.cs 14 Aug 2008 23:28:06 -0000 1.4 *************** *** 84,88 **** positionsToTest = this.bestPVOPositionsInSample; PVO_OTCStrategy strategy = ! new PVO_OTCStrategy(eligiblesSelector, positionsToTest, inSampleDays, benchmark , --- 84,88 ---- positionsToTest = this.bestPVOPositionsInSample; PVO_OTCStrategy strategy = ! new PVO_OTCStrategy(eligiblesSelector, 1, positionsToTest, inSampleDays, benchmark , Index: PVO_OTCMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCMain.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PVO_OTCMain.cs 26 Apr 2008 09:53:54 -0000 1.5 --- PVO_OTCMain.cs 14 Aug 2008 23:28:06 -0000 1.6 *************** *** 63,67 **** public PVO_OTCMain() { ! this.benchmark = new Benchmark( "BMC" ); this.historicalQuoteProvider = --- 63,67 ---- public PVO_OTCMain() { ! this.benchmark = new Benchmark( "^GSPC" ); this.historicalQuoteProvider = *************** *** 74,87 **** protected override IEligiblesSelector getEligiblesSelector() { - int maxNumberOfEligiblesToBeChosen = 100; string tickersGroupId = "SP500"; - // uncomment the following line for a faster script - //tickersGroupId = "fastTest"; - - // this.eligiblesSelector = - // new MostLiquidAndLessVolatile( - // tickersGroupId , - // maxNumberOfEligiblesToBeChosen ); bool temporizedGroup = true; --- 74,81 ---- protected override IEligiblesSelector getEligiblesSelector() { + int maxNumberOfEligiblesToBeChosen = 100; + string tickersGroupId = "SP500"; bool temporizedGroup = true; *************** *** 90,93 **** --- 84,97 ---- double maxPrice = 75; + int maxNumberOfMostLiquidTickersToBeChosen = 150; + int numDaysForVolatility = 10; + IEligiblesSelector eligiblesSelector = + new ByPriceMostLiquidLessVolatileOTCAlwaysQuoted( + tickersGroupId , temporizedGroup , + maxNumberOfEligiblesToBeChosen , + maxNumberOfMostLiquidTickersToBeChosen , + numDaysForAverageRawOpenPriceComputation , + numDaysForVolatility , + minPrice , maxPrice ); // IEligiblesSelector eligiblesSelector = // new ByPriceMostLiquidAlwaysQuoted( *************** *** 96,108 **** // numDaysForAverageRawOpenPriceComputation , // minPrice , maxPrice ); ! IEligiblesSelector eligiblesSelector = ! new ByPriceLessVolatileOTCAlwaysQuoted( ! tickersGroupId , temporizedGroup , ! maxNumberOfEligiblesToBeChosen , ! numDaysForAverageRawOpenPriceComputation , ! minPrice , maxPrice ); // eligiblesSelector = // new DummyEligibleSelector(); ! return eligiblesSelector; } --- 100,112 ---- // numDaysForAverageRawOpenPriceComputation , // minPrice , maxPrice ); ! // IEligiblesSelector eligiblesSelector = ! // new ByPriceLessVolatileOTCAlwaysQuoted( ! // tickersGroupId , temporizedGroup , ! // maxNumberOfEligiblesToBeChosen , ! // numDaysForAverageRawOpenPriceComputation , ! // minPrice , maxPrice ); // eligiblesSelector = // new DummyEligibleSelector(); ! // return eligiblesSelector; } *************** *** 123,128 **** double maxCorrelationAllowed = 0.96; ! int numberOfBestTestingPositionsToBeReturned = 200; ! numberOfBestTestingPositionsToBeReturned = 200; bool balancedWeightsOnVolatilityBase = true; float minimumAbsoluteReturnValue = 0.000001f; --- 127,132 ---- double maxCorrelationAllowed = 0.96; ! int numberOfBestTestingPositionsToBeReturned = 100; ! numberOfBestTestingPositionsToBeReturned = 100; bool balancedWeightsOnVolatilityBase = true; float minimumAbsoluteReturnValue = 0.000001f; *************** *** 130,150 **** //correlation is computed only for returns //between minimum and maximum - IInSampleChooser inSampleChooser = - new PVO_OTCCorrelationChooser(numberOfBestTestingPositionsToBeReturned, - maxCorrelationAllowed , balancedWeightsOnVolatilityBase, - minimumAbsoluteReturnValue , maximumAbsoluteReturnValue); // IInSampleChooser inSampleChooser = ! // new PVO_OTCCTOCorrelationChooser(numberOfBestTestingPositionsToBeReturned, // maxCorrelationAllowed , balancedWeightsOnVolatilityBase, ! // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue); // //office // inSampleChooser = // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2008_04_14_18_21_45_PVO_OTC_from_2001_01_01_to_2004_12_31_annlRtrn_182,80_maxDD_8,57\2008_04_14_18_21_45_PVO_OTC_from_2001_01_01_to_2004_12_31_annlRtrn_182,80_maxDD_8,57.qpL", // numberOfBestTestingPositionsToBeReturned); //home // inSampleChooser = // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2008_04_13_12_03_16_PVO_OTC_from_2001_01_01_to_2004_12_31_annlRtrn_183.39_maxDD_8.71\2008_04_13_12_03_16_PVO_OTC_from_2001_01_01_to_2004_12_31_annlRtrn_183.39_maxDD_8.71.qpL", // numberOfBestTestingPositionsToBeReturned); return inSampleChooser; --- 134,154 ---- //correlation is computed only for returns //between minimum and maximum // IInSampleChooser inSampleChooser = ! // new PVO_OTCCorrelationChooser(numberOfBestTestingPositionsToBeReturned, // maxCorrelationAllowed , balancedWeightsOnVolatilityBase, ! // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, this.benchmark.Ticker); ! IInSampleChooser inSampleChooser = ! new PVO_OTCCTOCorrelationChooser(numberOfBestTestingPositionsToBeReturned, ! 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\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; *************** *** 153,163 **** protected override IEndOfDayStrategyForBacktester getEndOfDayStrategy() { ! int inSampleDays = 180; // uncomment the following line for a faster script //inSampleDays = 50; ! int numDaysBetweenEachOptimization = 5; int numOfClosingsBeforeExit = 0; ! double oversoldThreshold = 0.01; ! double overboughtThreshold = 0.01; IEndOfDayStrategyForBacktester endOfDayStrategy // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , --- 157,170 ---- protected override IEndOfDayStrategyForBacktester getEndOfDayStrategy() { ! int inSampleDays = 25; // uncomment the following line for a faster script //inSampleDays = 50; ! int numDaysBetweenEachOptimization = 1; int numOfClosingsBeforeExit = 0; ! int minNumOfEligiblesForValidOptimization = 20; ! double oversoldThreshold = 0.0025; ! double overboughtThreshold = 0.0025; ! double oversoldThresholdMAX = 0.05; ! double overboughtThresholdMAX = 0.05; IEndOfDayStrategyForBacktester endOfDayStrategy // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , *************** *** 165,171 **** // oversoldThreshold , overboughtThreshold , historicalQuoteProvider); // ! = new PVO_OTCStrategy(eligiblesSelector ,inSampleChooser , inSampleDays , benchmark , numDaysBetweenEachOptimization , ! numOfClosingsBeforeExit, oversoldThreshold , overboughtThreshold , historicalQuoteProvider); return endOfDayStrategy; } --- 172,180 ---- // oversoldThreshold , overboughtThreshold , historicalQuoteProvider); // ! = new PVO_OTCStrategy(eligiblesSelector , ! minNumOfEligiblesForValidOptimization, inSampleChooser , inSampleDays , benchmark , numDaysBetweenEachOptimization , ! numOfClosingsBeforeExit, oversoldThreshold , overboughtThreshold , ! oversoldThresholdMAX , overboughtThresholdMAX , historicalQuoteProvider); return endOfDayStrategy; } *************** *** 173,181 **** { string backTestId = "PVO_OTC"; ! IAccountProvider accountProvider = new SimpleAccountProvider(); ! double cashToStart = 30000; ! DateTime firstDateTime = new DateTime( 2001 , 1 , 1 ); ! DateTime lastDateTime = new DateTime( 2004 , 12, 31 ); double maxRunningHours = 10; HistoricalQuoteProvider quoteProviderForBackTester = --- 182,194 ---- { string backTestId = "PVO_OTC"; ! IAccountProvider accountProvider; ! accountProvider = new SimpleAccountProvider(); ! // double fixedPercentageSlippage = 0.05; ! // accountProvider = ! // new InteractiveBrokerAccountProvider(fixedPercentageSlippage); ! double cashToStart = 25000; ! DateTime firstDateTime = new DateTime( 2004 , 1 , 1 ); ! DateTime lastDateTime = new DateTime( 2008 , 4, 28 ); double maxRunningHours = 10; HistoricalQuoteProvider quoteProviderForBackTester = Index: PVOLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOLogItem.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PVOLogItem.cs 8 Apr 2008 21:55:33 -0000 1.3 --- PVOLogItem.cs 14 Aug 2008 23:28:06 -0000 1.4 *************** *** 191,194 **** --- 191,196 ---- numberOfPortfolioPositions , benchmark , int.MaxValue , + ((PVOPositions)positionsToTest[0]).OversoldThreshold, + ((PVOPositions)positionsToTest[0]).OverboughtThreshold, historicalQuoteProviderForStrategy , maxAcceptableCloseToCloseDrawdown , minimumAcceptableGain ); Index: PVOPositionsStatus.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOPositionsStatus.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVOPositionsStatus.cs 9 Mar 2008 22:49:24 -0000 1.1 --- PVOPositionsStatus.cs 14 Aug 2008 23:28:06 -0000 1.2 *************** *** 35,39 **** InTheMiddle, Overbought, ! TooDistantFromThresholds } } --- 35,39 ---- InTheMiddle, Overbought, ! OverMaximumThresholds } } Index: PVO_OTCStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCStrategy.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PVO_OTCStrategy.cs 26 Apr 2008 09:51:23 -0000 1.4 --- PVO_OTCStrategy.cs 14 Aug 2008 23:28:06 -0000 1.5 *************** *** 71,74 **** --- 71,76 ---- protected double oversoldThreshold; protected double overboughtThreshold; + protected double oversoldThresholdMAX; + protected double overboughtThresholdMAX; //initialized after constructor's call protected int numDaysElapsedSinceLastOptimization; *************** *** 88,91 **** --- 90,95 ---- private int numOfClosingsToCrossBeforeExit; private int numOfClosingsWithOpenPositions; + private int minimumNumberOfEligiblesForValidOptimization; + private bool optimalPositionsHaveBeenUpdated; private string description_GetDescriptionForChooser() *************** *** 123,127 **** private void pvo_otcStrategy(IEligiblesSelector eligiblesSelector, ! int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, --- 127,132 ---- private void pvo_otcStrategy(IEligiblesSelector eligiblesSelector, ! int minimumNumberOfEligiblesForValidOptimization, ! int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, *************** *** 129,136 **** --- 134,145 ---- double oversoldThreshold, double overboughtThreshold, + double oversoldThresholdMAX, + double overboughtThresholdMAX, HistoricalQuoteProvider historicalQuoteProvider) { this.numOfClosingsWithOpenPositions = 0; this.eligiblesSelector = eligiblesSelector; + this.minimumNumberOfEligiblesForValidOptimization = + minimumNumberOfEligiblesForValidOptimization; this.inSampleDays = inSampleDays; this.benchmark = benchmark; *************** *** 139,146 **** --- 148,159 ---- this.oversoldThreshold = oversoldThreshold; this.overboughtThreshold = overboughtThreshold; + this.oversoldThresholdMAX = oversoldThresholdMAX; + this.overboughtThresholdMAX = overboughtThresholdMAX; this.historicalQuoteProvider = historicalQuoteProvider; + this.optimalPositionsHaveBeenUpdated = false; } public PVO_OTCStrategy(IEligiblesSelector eligiblesSelector, + int minimumNumberOfEligiblesForValidOptimization, IInSampleChooser inSampleChooser, int inSampleDays, *************** *** 150,163 **** double oversoldThreshold, double overboughtThreshold, HistoricalQuoteProvider historicalQuoteProvider) { ! this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , numOfClosingsToCrossBeforeExit, oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.inSampleChooser = inSampleChooser; } - public PVO_OTCStrategy(IEligiblesSelector eligiblesSelector, TestingPositions[] chosenPVOPositions, int inSampleDays, --- 163,200 ---- double oversoldThreshold, double overboughtThreshold, + double oversoldThresholdMAX, + double overboughtThresholdMAX, HistoricalQuoteProvider historicalQuoteProvider) { ! this.pvo_otcStrategy(eligiblesSelector, minimumNumberOfEligiblesForValidOptimization, ! inSampleDays , benchmark , numDaysBetweenEachOptimization , numOfClosingsToCrossBeforeExit, oversoldThreshold, overboughtThreshold, + oversoldThresholdMAX, overboughtThresholdMAX, + historicalQuoteProvider); + this.inSampleChooser = inSampleChooser; + } + + public PVO_OTCStrategy(IEligiblesSelector eligiblesSelector, + int minimumNumberOfEligiblesForValidOptimization, + IInSampleChooser inSampleChooser, + int inSampleDays, + Benchmark benchmark, + int numDaysBetweenEachOptimization, + int numOfClosingsToCrossBeforeExit, + double oversoldThreshold, + double overboughtThreshold, + HistoricalQuoteProvider historicalQuoteProvider) + + { + this.pvo_otcStrategy(eligiblesSelector, minimumNumberOfEligiblesForValidOptimization, + inSampleDays , benchmark , numDaysBetweenEachOptimization , + numOfClosingsToCrossBeforeExit, oversoldThreshold, overboughtThreshold, + double.MaxValue, double.MaxValue, historicalQuoteProvider); this.inSampleChooser = inSampleChooser; } public PVO_OTCStrategy(IEligiblesSelector eligiblesSelector, + int minimumNumberOfEligiblesForValidOptimization, TestingPositions[] chosenPVOPositions, int inSampleDays, *************** *** 167,177 **** double oversoldThreshold, double overboughtThreshold, HistoricalQuoteProvider historicalQuoteProvider) { ! this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , ! numOfClosingsToCrossBeforeExit, oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.chosenPVOPositions = chosenPVOPositions; } #region MarketOpenEventHandler --- 204,241 ---- double oversoldThreshold, double overboughtThreshold, + double oversoldThresholdMAX, + double overboughtThresholdMAX, HistoricalQuoteProvider historicalQuoteProvider) { ! this.pvo_otcStrategy(eligiblesSelector, minimumNumberOfEligiblesForValidOptimization, ! inSampleDays , benchmark , numDaysBetweenEachOptimization , ! numOfClosingsToCrossBeforeExit, ! oversoldThreshold, overboughtThreshold, ! oversoldThresholdMAX, overboughtThresholdMAX, ! historicalQuoteProvider); this.chosenPVOPositions = chosenPVOPositions; } + public PVO_OTCStrategy(IEligiblesSelector eligiblesSelector, + int minimumNumberOfEligiblesForValidOptimization, + TestingPositions[] chosenPVOPositions, + int inSampleDays, + Benchmark benchmark, + int numDaysBetweenEachOptimization, + int numOfClosingsToCrossBeforeExit, + double oversoldThreshold, + double overboughtThreshold, + HistoricalQuoteProvider historicalQuoteProvider) + + { + this.pvo_otcStrategy(eligiblesSelector, minimumNumberOfEligiblesForValidOptimization, + inSampleDays , benchmark , numDaysBetweenEachOptimization , + numOfClosingsToCrossBeforeExit, + oversoldThreshold, overboughtThreshold, + double.MaxValue, double.MaxValue, + historicalQuoteProvider); + this.chosenPVOPositions = chosenPVOPositions; + } + #region MarketOpenEventHandler *************** *** 195,199 **** currentStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, ! this.benchmark.Ticker, this.historicalQuoteProvider); if(currentStatus == PVOPositionsStatus.Oversold || currentStatus == PVOPositionsStatus.Overbought ) --- 259,264 ---- currentStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, ! this.benchmark.Ticker, this.historicalQuoteProvider, ! this.oversoldThresholdMAX, this.overboughtThresholdMAX); if(currentStatus == PVOPositionsStatus.Oversold || currentStatus == PVOPositionsStatus.Overbought ) *************** *** 257,263 **** { if ( this.account.Portfolio.Count == 0 && ! this.chosenPVOPositions != null ) //portfolio is empty and optimization has ! //been already launched { try{ --- 322,329 ---- { if ( this.account.Portfolio.Count == 0 && ! this.chosenPVOPositions != null && ! this.optimalPositionsHaveBeenUpdated == true) //portfolio is empty and optimization has ! //been already successfully launched { try{ *************** *** 308,322 **** switch ( ((PVOCorrelationChooser)this.inSampleChooser).IntervalsType ) { ! case IntervalsType.CloseToCloseIntervals_OneDay: ! returnIntervals = new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker, 1); ! break; ! case IntervalsType.CloseToCloseIntervals_TwoDays: returnIntervals = new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker, 2); break; ! case IntervalsType.CloseToCloseIntervals_FiveDays: ! returnIntervals = new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker, 5); break; case IntervalsType.CloseToOpenIntervals: --- 374,384 ---- switch ( ((PVOCorrelationChooser)this.inSampleChooser).IntervalsType ) { ! case IntervalsType.CloseToCloseIntervals: returnIntervals = new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; ! case IntervalsType.OpenToOpenIntervals: ! returnIntervals = new OpenToOpenIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.CloseToOpenIntervals: *************** *** 324,328 **** this.benchmark.Ticker); break; ! case IntervalsType.DailyOpenToCloseIntervals: returnIntervals = new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ); --- 386,390 ---- this.benchmark.Ticker); break; ! case IntervalsType.OpenToCloseIntervals: returnIntervals = new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ); *************** *** 344,348 **** } ! private PVO_OTCLogItem getLogItem( EligibleTickers eligibleTickers ) { --- 406,437 ---- } ! ! private double getLogItem_getFitnessOfLast() ! { ! double returnValue = 0.0; ! for(int i = 1; i<=this.chosenPVOPositions.Length; i++) ! { ! if(this.chosenPVOPositions[this.chosenPVOPositions.Length - i] != null) ! { ! returnValue = this.chosenPVOPositions[this.chosenPVOPositions.Length - i].FitnessInSample; ! i = this.chosenPVOPositions.Length + 1; //exit from for ! } ! } ! return returnValue; ! } ! private string getLogItem_getHashCodeForTickerCompositionForLast() ! { ! string returnValue = "not set"; ! for(int i = 1; i<=this.chosenPVOPositions.Length; i++) ! { ! if(this.chosenPVOPositions[this.chosenPVOPositions.Length - i] != null) ! { ! returnValue = this.chosenPVOPositions[this.chosenPVOPositions.Length - i].HashCodeForTickerComposition; ! i = this.chosenPVOPositions.Length + 1; //exit from for ! } ! } ! return returnValue; ! } ! private PVO_OTCLogItem getLogItem( EligibleTickers eligibleTickers ) { *************** *** 355,360 **** logItem.FitnessOfFirst = this.chosenPVOPositions[0].FitnessInSample; ! logItem.FitnessOfLast = ! this.chosenPVOPositions[this.chosenPVOPositions.Length - 1].FitnessInSample; // logItem.GenerationOfFirst = // ((IGeneticallyOptimizable)this.chosenPVOPositions[0]).Generation; --- 444,449 ---- logItem.FitnessOfFirst = this.chosenPVOPositions[0].FitnessInSample; ! logItem.FitnessOfLast = this.getLogItem_getFitnessOfLast(); ! // logItem.GenerationOfFirst = // ((IGeneticallyOptimizable)this.chosenPVOPositions[0]).Generation; *************** *** 364,374 **** ((PVOPositions)this.chosenPVOPositions[0]).OversoldThreshold.ToString() + ";" + ((PVOPositions)this.chosenPVOPositions[0]).OverboughtThreshold.ToString(); ! logItem.ThresholdsOfLast = ! ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OversoldThreshold.ToString() + ";" + ! ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OverboughtThreshold.ToString(); logItem.TickersOfFirst = this.chosenPVOPositions[0].HashCodeForTickerComposition; ! logItem.TickersOfLast = ! this.chosenPVOPositions[this.chosenPVOPositions.Length - 1].HashCodeForTickerComposition; return logItem; } --- 453,463 ---- ((PVOPositions)this.chosenPVOPositions[0]).OversoldThreshold.ToString() + ";" + ((PVOPositions)this.chosenPVOPositions[0]).OverboughtThreshold.ToString(); ! logItem.ThresholdsOfLast = logItem.ThresholdsOfFirst; ! // ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OversoldThreshold.ToString() + ";" + ! // ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OverboughtThreshold.ToString(); logItem.TickersOfFirst = this.chosenPVOPositions[0].HashCodeForTickerComposition; ! logItem.TickersOfLast = this.getLogItem_getHashCodeForTickerCompositionForLast(); ! return logItem; } *************** *** 392,396 **** private void logOptimizationInfo( EligibleTickers eligibleTickers ) { ! this.raiseNewLogItem( eligibleTickers ); this.notifyMessage( eligibleTickers ); } --- 481,487 ---- private void logOptimizationInfo( EligibleTickers eligibleTickers ) { ! if(eligibleTickers.Count > 0) ! this.raiseNewLogItem( eligibleTickers ); ! this.notifyMessage( eligibleTickers ); } *************** *** 400,407 **** for(int i = 0; i<this.chosenPVOPositions.Length; i++) { ! ((PVOPositions)this.chosenPVOPositions[i]).OversoldThreshold = ! this.oversoldThreshold; ! ((PVOPositions)this.chosenPVOPositions[i]).OverboughtThreshold = ! this.overboughtThreshold; } } --- 491,501 ---- for(int i = 0; i<this.chosenPVOPositions.Length; i++) { ! if(this.chosenPVOPositions[i] != null) ! { ! ((PVOPositions)this.chosenPVOPositions[i]).OversoldThreshold = ! this.oversoldThreshold; ! ((PVOPositions)this.chosenPVOPositions[i]).OverboughtThreshold = ! this.overboughtThreshold; ! } } } *************** *** 419,427 **** this.updateReturnsManager(endOfDayHistory.FirstEndOfDayDateTime, endOfDayHistory.LastEndOfDayDateTime); ! if(this.inSampleChooser != null) this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager); ! this.updateTestingPositions_updateThresholds(); ! this.logOptimizationInfo(eligibles); ! } private bool optimalTestingPositionsAreToBeUpdated() --- 513,531 ---- this.updateReturnsManager(endOfDayHistory.FirstEndOfDayDateTime, endOfDayHistory.LastEndOfDayDateTime); ! if( ( this.eligiblesSelector is DummyEligibleSelector && ! this.inSampleChooser != null ) || ! ( eligibles.Count > this.minimumNumberOfEligiblesForValidOptimization && ! this.inSampleChooser != null ) ) ! { this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager); ! this.updateTestingPositions_updateThresholds(); ! this.logOptimizationInfo(eligibles); ! this.optimalPositionsHaveBeenUpdated = true; ! } ! else ! { ! this.optimalPositionsHaveBeenUpdated = false; ! } ! } private bool optimalTestingPositionsAreToBeUpdated() Index: PVOMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOMain.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PVOMain.cs 8 Apr 2008 22:00:01 -0000 1.4 --- PVOMain.cs 14 Aug 2008 23:28:06 -0000 1.5 *************** *** 44,47 **** --- 44,48 ---- using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.Decoding; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.FitnessEvaluators; + using QuantProject.Scripts.General; using QuantProject.Scripts.General.Logging; using QuantProject.Scripts.General.Reporting; *************** *** 55,238 **** /// be done /// </summary> ! public class PVOMain { ! private string strategyIdentifier; ! private string fileNameWithoutExt; ! private string dirNameWhereToSaveResults; ! ! public PVOMain() ! { ! this.strategyIdentifier = "PVO"; ! } ! private void setFileNamesAndDirectory(EndOfDayStrategyBackTester endOfDayStrategyBackTester) { ! if(this.fileNameWithoutExt == null) ! { ! this.fileNameWithoutExt = this.strategyIdentifier + "_" + ! DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Second.ToString().PadLeft(2,'0'); ! this.dirNameWhereToSaveResults = System.Configuration.ConfigurationSettings.AppSettings["LogArchive"] + ! "\\" + fileNameWithoutExt + "\\"; ! ! if( !Directory.Exists(dirNameWhereToSaveResults) ) ! Directory.CreateDirectory(dirNameWhereToSaveResults); ! } } ! ! #region Run ! private MessageManager setMessageManager( ! IEligiblesSelector eligiblesSelector , ! IInSampleChooser inSampleChooser , ! IEndOfDayStrategy endOfDayStrategy , ! EndOfDayStrategyBackTester endOfDayStrategyBackTester ) { - this.setFileNamesAndDirectory(endOfDayStrategyBackTester); ! string fullPathFileNameForMessagesLog = dirNameWhereToSaveResults + ! this.fileNameWithoutExt + ! "LogMessages.txt"; ! MessageManager messageManager = ! new MessageManager( fullPathFileNameForMessagesLog ); ! messageManager.Monitor( eligiblesSelector ); ! messageManager.Monitor( inSampleChooser ); ! // messageManager.Monitor( endOfDayStrategy ); ! messageManager.Monitor( endOfDayStrategyBackTester ); ! return messageManager; ! } ! //Saves (in silent mode): ! //- a log file where the In Sample Analysis are ! // stored; ! //- a report; ! //- a txt file with a full description of the ! // strategy's features ! private void saveScriptResults( EndOfDayStrategyBackTester endOfDayStrategyBackTester ) { ! this.setFileNamesAndDirectory(endOfDayStrategyBackTester); ! string fullPathFileNameForLog = dirNameWhereToSaveResults + ! this.fileNameWithoutExt + ".qpL"; ! string fullPathFileNameForReport = dirNameWhereToSaveResults + ! this.fileNameWithoutExt + ".qpR"; ! string fullPathFileNameForParametersLog = dirNameWhereToSaveResults + ! this.fileNameWithoutExt + "_Parameters.txt"; ! ObjectArchiver.Archive(endOfDayStrategyBackTester.Log, ! fullPathFileNameForLog); ! ObjectArchiver.Archive(endOfDayStrategyBackTester.AccountReport, ! fullPathFileNameForReport); ! StreamWriter w = File.AppendText(fullPathFileNameForParametersLog); ! w.WriteLine ("\n---\r\n"); ! w.WriteLine ( endOfDayStrategyBackTester.Description ); ! w.WriteLine ("\n---\r\n"); ! w.Flush(); ! w.Close(); ! } ! public void Run() { ! //general ! DateTime firstDateTime = new DateTime( 2000 , 6 , 1 ); ! DateTime lastDateTime = new DateTime( 2001 , 6 , 1 ); ! double maxRunningHours = 5; ! Benchmark benchmark = new Benchmark( "^GSPC" ); ! // definition for the Fitness Evaluator (for ! // objects that use it) ! IEquityEvaluator equityEvaluator = new SharpeRatio(); ! //cash and portfolio type ! double cashToStart = 30000; ! int numberOfPortfolioPositions = 4; ! ! // parameters for the in sample Chooser ! // double crossoverRate = 0.85; ! // double mutationRate = 0.02; ! // double elitismRate = 0.001; ! // int populationSizeForGeneticOptimizer = 500; ! // int generationNumberForGeneticOptimizer = 10; ! int numberOfBestTestingPositionsToBeReturnedInSample = 5; ! int seedForRandomGenerator = ! QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; ! int numDaysBetweenEachOptimization = 15; ! // int minLevelForOversoldThreshold = 50; ! // int maxLevelForOversoldThreshold = 100; ! // int minLevelForOverboughtThreshold = 50; ! // int maxLevelForOverboughtThreshold = 100; ! int divisorForThresholdComputation = 10000; ! int numDaysForOscillatingPeriodForChooser = 1; //for genetic optimization ! bool symmetricalThresholds = true; ! // bool overboughtMoreThanOversoldForFixedPortfolio = false; ! double maxAcceptableCloseToCloseDrawdown = 0.03; ! double minimumAcceptableGain = 0.008; ! IDecoderForTestingPositions decoderForTestingPositions ! = new BasicDecoderForPVOPositions(symmetricalThresholds, divisorForThresholdComputation , ! numDaysForOscillatingPeriodForChooser); ! IFitnessEvaluator fitnessEvaluator = ! new PVOFitnessEvaluator( equityEvaluator ); ! HistoricalQuoteProvider historicalQuoteProviderForBackTester, ! historicalQuoteProviderForInSampleChooser, ! historicalQuoteProviderForStrategy; ! historicalQuoteProviderForBackTester = new HistoricalAdjustedQuoteProvider(); - historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester; - historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser; - - // IInSampleChooser inSampleChooser = - // new PVOGeneticChooser(numDaysForOscillatingPeriodForChooser , - // numberOfPortfolioPositions , numberOfBestTestingPositionsToBeReturnedInSample, - // benchmark, decoderForTestingPositions , fitnessEvaluator , - // historicalQuoteProviderForInSampleChooser , - // crossoverRate , mutationRate , elitismRate , - // populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , - // seedForRandomGenerator , minLevelForOversoldThreshold , - // maxLevelForOversoldThreshold , minLevelForOverboughtThreshold , - // maxLevelForOverboughtThreshold , divisorForThresholdComputation , - // symmetricalThresholds , overboughtMoreThanOversoldForFixedPortfolio ); - double maxCorrelationValue = 0.96; - bool balancedWeights = false; - IInSampleChooser inSampleChooser = - new PVO_CTCCorrelationChooser(numberOfBestTestingPositionsToBeReturnedInSample, - numDaysForOscillatingPeriodForChooser, - maxCorrelationValue, balancedWeights); - //parameters for eligiblesSelector - bool temporizedGroup = true; - double minRawOpenPrice = 25; - double maxRawOpenPrice = 500; - int numDaysForAverageOpenRawPrice = 20; - string tickersGroupId = "SP500"; - int maxNumberOfEligiblesToBeChosen = 100; - IEligiblesSelector eligiblesSelector = - new ByPriceMostLiquidAlwaysQuoted( - tickersGroupId , temporizedGroup, maxNumberOfEligiblesToBeChosen, - numDaysForAverageOpenRawPrice , - minRawOpenPrice , maxRawOpenPrice ); - //strategyParameters - int inSampleDays = 120; - int numDaysForOscillatingPeriodForOutOfSampleChoosing = - numDaysForOscillatingPeriodForChooser; - PVOStrategy strategy = - new PVOStrategy(eligiblesSelector, - inSampleChooser, inSampleDays, - numDaysForOscillatingPeriodForOutOfSampleChoosing, - numberOfPortfolioPositions , benchmark , - numDaysBetweenEachOptimization , - historicalQuoteProviderForStrategy , - maxAcceptableCloseToCloseDrawdown , minimumAcceptableGain ); - EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! this.strategyIdentifier , strategy , ! historicalQuoteProviderForBackTester , ! new SimpleAccountProvider(), firstDateTime , ! lastDateTime , benchmark , cashToStart , maxRunningHours ); ! MessageManager messageManager = this.setMessageManager( ! eligiblesSelector , inSampleChooser , ! strategy , endOfDayStrategyBackTester ); ! endOfDayStrategyBackTester.Run(); ! this.saveScriptResults(endOfDayStrategyBackTester); } ! #endregion Run ! } } --- 56,238 ---- /// be done /// </summary> ! public class PVOMain : BasicScriptForBacktesting { ! private Benchmark benchmark; ! private HistoricalQuoteProvider historicalQuoteProvider; ! public PVOMain() { ! this.benchmark = new Benchmark( "BMC" ); ! ! this.historicalQuoteProvider = ! new HistoricalAdjustedQuoteProvider(); ! ! // definition for the Fitness Evaluator ! // IEquityEvaluator equityEvaluator = new SharpeRatio(); } ! ! protected override IEligiblesSelector getEligiblesSelector() { ! int maxNumberOfEligiblesToBeChosen = 100; ! ! string tickersGroupId = "SP500"; ! bool temporizedGroup = true; ! int numDaysForAverageRawOpenPriceComputation = 10; ! double minPrice = 30; ! double maxPrice = 75; ! ! int maxNumberOfMostLiquidTickersToBeChosen = 150; ! int numDaysForVolatility = 10; ! IEligiblesSelector eligiblesSelector = ! new ByPriceMostLiquidLessVolatileCTCAlwaysQuoted( ! tickersGroupId , temporizedGroup , ! maxNumberOfEligiblesToBeChosen , ! maxNumberOfMostLiquidTickersToBeChosen , ! numDaysForAverageRawOpenPriceComputation , ! numDaysForVolatility , ! minPrice , maxPrice ); ! // IEligiblesSelector eligiblesSelector = ! // new ByPriceMostLiquidAlwaysQuoted( ! // tickersGroupId , temporizedGroup , ! // maxNumberOfEligiblesToBeChosen , ! // numDaysForAverageRawOpenPriceComputation , ! // minPrice , maxPrice ); ! // IEligiblesSelector eligiblesSelector = ! // new ByPriceLessVolatileOTCAlwaysQuoted( ! // tickersGroupId , temporizedGroup , ! // maxNumberOfEligiblesToBeChosen , ! // numDaysForAverageRawOpenPriceComputation , ! // minPrice , maxPrice ); ! eligiblesSelector = ! new DummyEligibleSelector(); ! // ! return eligiblesSelector; ! } ! ! protected override IInSampleChooser getInSampleChooser() { ! // parameters for the genetic optimizer ! // double crossoverRate = 0.85; ! // double mutationRate = 0.02; ! // double elitismRate = 0.001; ! // int populationSizeForGeneticOptimizer = 3000; ! // int generationNumberForGeneticOptimizer = 4; ! // int seedForRandomGenerator = ! // QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; ! // IDecoderForTestingPositions decoderForWeightedPositions = ! // new DecoderForPairsTradingTestingPositionsWithBalancedWeights(); ! ! double maxCorrelationAllowed = 0.96; ! int numberOfBestTestingPositionsToBeReturned = 50; ! numberOfBestTestingPositionsToBeReturned = 10; ! bool balancedWeightsOnVolatilityBase = true; ! float minimumAbsoluteReturnValue = 0.000001f; ! float maximumAbsoluteReturnValue = 100000f; ! int closeToCloseIntervalLengthForCorrelation = 2; ! //correlation is computed only for returns ! //between minimum and maximum ! IInSampleChooser inSampleChooser = ! // new PVO_CTCCorrelationChooser(numberOfBestTestingPositionsToBeReturned, ! // closeToCloseIntervalLengthForCorrelation , maxCorrelationAllowed , balancedWeightsOnVolatilityBase, ! // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, this.benchmark.Ticker ); ! new PVO_CTCStrongCorrelationChooser(numberOfBestTestingPositionsToBeReturned, ! maxCorrelationAllowed , minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, ! balancedWeightsOnVolatilityBase, this.benchmark.Ticker ); ! // IInSampleChooser inSampleChooser = ! // new PVO_OTCCTOCorrelationChooser(numberOfBestTestingPositionsToBeReturned, ! // maxCorrelationAllowed , balancedWeightsOnVolatilityBase, ! // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue); ! // //office ! // inSampleChooser = ! // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2008_05_23_15_46_38_PVO_CTC_from_2001_01_01_to_2001_12_31_annlRtrn_8,61_maxDD_17,21\2008_05_23_15_46_38_PVO_CTC_from_2001_01_01_to_2001_12_31_annlRtrn_8,61_maxDD_17,21.qpL", ! // numberOfBestTestingPositionsToBeReturned); ! //home ! inSampleChooser = ! new PVOChooserFromSavedBackTestLog( ! @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2008_06_03_18_33_29_PVO_CTC_from_2001_01_01_to_2004_12_31_annlRtrn_4.72_maxDD_13.57\2008_06_03_18_33_29_PVO_CTC_from_2001_01_01_to_2004_12_31_annlRtrn_4.72_maxDD_13.57.qpL", ! numberOfBestTestingPositionsToBeReturned); ! return inSampleChooser; ! } ! ! protected override IEndOfDayStrategyForBacktester getEndOfDayStrategy() { ! int inSampleDays = 180; ! // uncomment the following line for a faster script ! //inSampleDays = 50; ! int numDaysBetweenEachOptimization = 5; ! double oversoldThreshold = 0.002; ! double overboughtThreshold = 0.002; ! double oversoldThresholdMAX = 0.02; ! double overboughtThresholdMAX = 0.02; ! double maxAcceptableDrawDown = 0.01; ! double minimumAcceptableGain = 0.002; ! int closeToCloseIntervalLength = 1; ! IEndOfDayStrategyForBacktester endOfDayStrategy ! // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , ! // inSampleDays , benchmark , numDaysBetweenEachOptimization , ! // oversoldThreshold , overboughtThreshold , historicalQuoteProvider); ! // ! = new PVOStrategy(eligiblesSelector , inSampleChooser , ! inSampleDays , closeToCloseIntervalLength , 2 , benchmark , numDaysBetweenEachOptimization , ! oversoldThreshold , overboughtThreshold , ! oversoldThresholdMAX , overboughtThresholdMAX , historicalQuoteProvider, ! maxAcceptableDrawDown, minimumAcceptableGain ); ! return endOfDayStrategy; ! } ! protected override EndOfDayStrategyBackTester getEndOfDayStrategyBackTester() ! { ! string backTestId = "PVO_CTC"; ! IAccountProvider accountProvider; ! accountProvider = new SimpleAccountProvider(); ! // double fixedPercentageSlippage = 0.05; ! // accountProvider = ! // new InteractiveBrokerAccountProvider(fixedPercentageSlippage); ! double cashToStart = 25000; ! ! DateTime firstDateTime = new DateTime( 2001 , 1 , 1 ); ! DateTime lastDateTime = new DateTime( 2004 , 12, 31 ); ! double maxRunningHours = 8; ! HistoricalQuoteProvider quoteProviderForBackTester = ! this.historicalQuoteProvider; ! quoteProviderForBackTester = new HistoricalAdjustedQuoteProvider(); EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.endOfDayStrategy , ! quoteProviderForBackTester , accountProvider , ! firstDateTime , lastDateTime , ! this.benchmark , cashToStart , maxRunningHours ); ! return endOfDayStrategyBackTester; ! } ! protected override string getPathForTheMainFolderWhereScriptsResultsAreToBeSaved() ! { ! string pathForTheMainFolderWhereScriptsResultsAreToBeSaved = ! System.Configuration.ConfigurationSettings.AppSettings["LogArchive"]; ! return pathForTheMainFolderWhereScriptsResultsAreToBeSaved; } ! protected override string getCustomSmallTextForFolderName() ! { ! return "PVO_CTC"; ! } ! ! protected override string getFullPathFileNameForMain() ! { ! string returnValue; ! string fullPathFileNameForMainAtHome = ! @"C:\Quant\QuantProject\b7_Scripts\TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOMain.cs"; ! if( File.Exists(fullPathFileNameForMainAtHome) ) ! returnValue = fullPathFileNameForMainAtHome; ! else ! returnValue = ! @"C:\Utente\MarcoVarie\Vari\qP\QuantProject\b7_Scripts\TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOMain.cs"; ! ! return returnValue; ! } } } Index: PVOPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOPositions.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PVOPositions.cs 20 Apr 2008 17:21:28 -0000 1.2 --- PVOPositions.cs 14 Aug 2008 23:28:06 -0000 1.3 *************** *** 59,63 **** set{this.overboughtThreshold = value;} } ! public int NumDaysForOscillatingPeriod { get{return this.numDaysForOscillatingPeriod;} --- 59,63 ---- set{this.overboughtThreshold = value;} } ! public int NumDaysForOscillatingPeriod { get{return this.numDaysForOscillatingPeriod;} *************** *** 75,80 **** public PVOPositions Copy() { ! return new PVOPositions(this.WeightedPositions,this.OversoldThreshold, ! this.overboughtThreshold, this.numDaysForOscillatingPeriod); } --- 75,82 ---- public PVOPositions Copy() { ! return new PVOPositions(this.WeightedPositions, ! this.OversoldThreshold, ! this.overboughtThreshold, ! this.numDaysForOscillatingPeriod); } *************** *** 126,130 **** string benchmark, HistoricalQuoteProvider quoteProvider, ! double maxCoefficientOfCrossingThresholds) { PVOPositionsStatus returnValue; --- 128,133 ---- string benchmark, HistoricalQuoteProvider quoteProvider, ! double maxOversoldThreshold, ! double maxOverboughtThreshold) { PVOPositionsStatus returnValue; *************** *** 134,145 **** quoteProvider); if(oscillatingPeriodReturn >= this.overboughtThreshold && ! oscillatingPeriodReturn <= maxCoefficientOfCrossingThresholds*this.overboughtThreshold) returnValue = PVOPositionsStatus.Overbought; else if(oscillatingPeriodReturn <= -this.oversoldThreshold && ! Math.Abs(oscillatingPeriodReturn)<=maxCoefficientOfCrossingThresholds*this.oversoldThreshold) returnValue = PVOPositionsStatus.Oversold; ! else if ( Math.Abs(oscillatingPeriodReturn) > maxCoefficientOfCrossingThresholds*this.oversoldThreshold || ! oscillatingPeriodReturn > maxCoefficientOfCrossingThresholds*this.overboughtThreshold ) ! returnValue = PVOPositionsStatus.TooDistantFromThresholds; else returnValue = PVOPositionsStatus.InTheMiddle; --- 137,148 ---- quoteProvider); if(oscillatingPeriodReturn >= this.overboughtThreshold && ! oscillatingPeriodReturn <= maxOverboughtThreshold) returnValue = PVOPositionsStatus.Overbought; else if(oscillatingPeriodReturn <= -this.oversoldThreshold && ! Math.Abs(oscillatingPeriodReturn) <= maxOversoldThreshold) returnValue = PVOPositionsStatus.Oversold; ! else if ( Math.Abs(oscillatingPeriodReturn) > maxOversoldThreshold || ! oscillatingPeriodReturn > maxOverboughtThreshold ) ! returnValue = PVOPositionsStatus.OverMaximumThresholds; else returnValue = PVOPositionsStatus.InTheMiddle; *************** *** 148,162 **** } - public PVOPositionsStatus GetStatus(EndOfDayDateTime beginOfPeriod, - EndOfDayDateTime endOfPeriod, - string benchmark, - HistoricalQuoteProvider quoteProvider) - { - return this.GetStatus(beginOfPeriod, endOfPeriod , - benchmark, quoteProvider, 10000.0); - //a very high maxCoefficientOfCrossingThresholds is given: - //so the status TooDistantFromThresholds should never been reached - } - public bool AreAllTickersMovingTogetherUpOrDown(EndOfDayDateTime beginOfPeriod, EndOfDayDateTime endOfPeriod, --- 151,154 ---- Index: PVO_OTCStrategyLessCorrelated.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCStrategyLessCorrelated.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVO_OTCStrategyLessCorrelated.cs 26 Apr 2008 09:13:11 -0000 1.1 --- PVO_OTCStrategyLessCorrelated.cs 14 Aug 2008 23:28:06 -0000 1.2 *************** *** 187,191 **** currentStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, ! this.benchmark.Ticker, this.historicalQuoteProvider); if(currentStatus == PVOPositionsStatus.Oversold || currentStatus == PVOPositionsStatus.Overbought ) --- 187,192 ---- currentStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, ! this.benchmark.Ticker, this.historicalQuoteProvider, ! double.MaxValue, double.MaxValue); if(currentStatus == PVOPositionsStatus.Oversold || currentStatus == PVOPositionsStatus.Overbought ) |