quantproject-developers Mailing List for QuantProject (Page 15)
Brought to you by:
glauco_1
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(7) |
Nov
(103) |
Dec
(67) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(52) |
Feb
(9) |
Mar
(69) |
Apr
(53) |
May
(80) |
Jun
(23) |
Jul
(24) |
Aug
(112) |
Sep
(9) |
Oct
|
Nov
(58) |
Dec
(93) |
| 2005 |
Jan
(90) |
Feb
(93) |
Mar
(61) |
Apr
(56) |
May
(37) |
Jun
(61) |
Jul
(55) |
Aug
(68) |
Sep
(25) |
Oct
(46) |
Nov
(41) |
Dec
(37) |
| 2006 |
Jan
(33) |
Feb
(7) |
Mar
(19) |
Apr
(27) |
May
(73) |
Jun
(49) |
Jul
(83) |
Aug
(66) |
Sep
(45) |
Oct
(16) |
Nov
(15) |
Dec
(7) |
| 2007 |
Jan
(14) |
Feb
(33) |
Mar
|
Apr
(21) |
May
|
Jun
(34) |
Jul
(18) |
Aug
(100) |
Sep
(39) |
Oct
(55) |
Nov
(12) |
Dec
(2) |
| 2008 |
Jan
(120) |
Feb
(133) |
Mar
(129) |
Apr
(104) |
May
(42) |
Jun
(2) |
Jul
(52) |
Aug
(99) |
Sep
(134) |
Oct
|
Nov
(137) |
Dec
(48) |
| 2009 |
Jan
(48) |
Feb
(55) |
Mar
(61) |
Apr
(3) |
May
(2) |
Jun
(1) |
Jul
|
Aug
(51) |
Sep
|
Oct
(7) |
Nov
|
Dec
|
| 2010 |
Jan
(7) |
Feb
(1) |
Mar
(145) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
| 2011 |
Jan
(78) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(88) |
Sep
(6) |
Oct
(1) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Glauco S. <gla...@us...> - 2010-01-31 18:57:52
|
Update of /cvsroot/quantproject/QuantProject/t5_Testing In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv11038 Added Files: AssemblyInfo.cs QPTesting.csproj QPTesting.sln Log Message: A new solution is added, for unit testing --- NEW FILE: AssemblyInfo.cs --- #region Using directives using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; #endregion // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("QuantTesting")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("QuantTesting")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // This sets the default COM visibility of types in the assembly to invisible. // If you need to expose a type to COM, use [ComVisible(true)] on that type. [assembly: ComVisible(false)] // The assembly version has following format : // // Major.Minor.Build.Revision // // You can specify all the values or you can use the default the Revision and // Build Numbers by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")] --- NEW FILE: QPTesting.csproj --- (This appears to be a binary file; contents omitted.) --- NEW FILE: QPTesting.sln --- (This appears to be a binary file; contents omitted.) |
|
From: Glauco S. <gla...@us...> - 2010-01-31 18:56:32
|
Update of /cvsroot/quantproject/QuantProject/t5_Testing In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv10824/t5_Testing Log Message: Directory /cvsroot/quantproject/QuantProject/t5_Testing added to the repository |
|
From: Glauco S. <gla...@us...> - 2010-01-03 20:09:58
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv32678/Downloader Added Files: app.config Log Message: Updated version --- NEW FILE: app.config --- <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v2.0.50727" /> </startup> <appSettings> <add key="AccountsArchive" value="C:\\Documents and Settings\\Marco\\Documenti\\ProgettiOpenSource\\Quant\\SavedAccounts\\" /> <add key="ReportsArchive" value="C:\\Documents and Settings\\Marco\\Documenti\\ProgettiOpenSource\\Quant\\SavedReports\\" /> <add key="TransactionsArchive" value="C:\\Documents and Settings\\Marco\\Documenti\\ProgettiOpenSource\\Quant\\SavedTransactions\\" /> <add key="GenomesArchive" value="C:\\Documents and Settings\\Marco\\Documenti\\ProgettiOpenSource\\Quant\\SavedGenomes\\" /> <add key="GenericArchive" value="C:\\Documents and Settings\\Marco\\Documenti\\ProgettiOpenSource\\Quant\\GenericArchive\\" /> <add key="dbType" value="MySQL" /> <add key="mySqlConnectionString" value="Database=quantproject;Data Source=localhost;User Id=root;Password=1111" /> </appSettings> </configuration> |
|
From: Glauco S. <gla...@us...> - 2010-01-03 20:09:43
|
Update of /cvsroot/quantproject/QuantDownloader In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv32649 Removed Files: app.config Log Message: Obsolete version --- app.config DELETED --- |
|
From: Marco M. <mi...@us...> - 2009-10-30 23:14:36
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/OTC/OTC_Intraday In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11220/TickerSelectionTesting/OTC/OTC_Intraday Modified Files: OTCIntradayLogItem.cs OTCIntradayMain.cs OTCIntradayStrategy.cs Log Message: Updated old script files for the OTC strategy Index: OTCIntradayStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/OTC/OTC_Intraday/OTCIntradayStrategy.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OTCIntradayStrategy.cs 31 Aug 2009 20:40:30 -0000 1.1 --- OTCIntradayStrategy.cs 30 Oct 2009 23:14:23 -0000 1.2 *************** *** 119,122 **** --- 119,123 ---- protected double stopLoss; protected double takeProfit; + protected object[] daysForPlayingTheStrategy; private string description_GetDescriptionForChooser() *************** *** 174,178 **** double numberOfMaxStdDeviationForOpeningPositions, IInSampleFitnessDistributionEstimator estimator, ! int sampleLength) { this.eligiblesSelector = eligiblesSelector; --- 175,180 ---- double numberOfMaxStdDeviationForOpeningPositions, IInSampleFitnessDistributionEstimator estimator, ! int sampleLength, ! object[] daysForPlayingTheStrategy) { this.eligiblesSelector = eligiblesSelector; *************** *** 202,205 **** --- 204,208 ---- this.estimator = estimator; this.sampleLength = sampleLength; + this.daysForPlayingTheStrategy = daysForPlayingTheStrategy; } *************** *** 224,228 **** double numberOfMaxStdDeviationForOpeningPositions, IInSampleFitnessDistributionEstimator estimator, ! int sampleLength) { --- 227,232 ---- double numberOfMaxStdDeviationForOpeningPositions, IInSampleFitnessDistributionEstimator estimator, ! int sampleLength, ! object[] daysForPlayingTheStrategy) { *************** *** 245,249 **** numberOfMinimumStdDeviationForOpeningPositions, numberOfMaxStdDeviationForOpeningPositions, ! estimator, sampleLength); } --- 249,254 ---- numberOfMinimumStdDeviationForOpeningPositions, numberOfMaxStdDeviationForOpeningPositions, ! estimator, sampleLength, ! daysForPlayingTheStrategy); } *************** *** 260,264 **** double numberOfMaxStdDeviationForOpeningPositions, IInSampleFitnessDistributionEstimator estimator, ! int sampleLength) { --- 265,269 ---- double numberOfMaxStdDeviationForOpeningPositions, IInSampleFitnessDistributionEstimator estimator, ! int sampleLength, object[] daysForPlayingTheStrategy) { *************** *** 280,284 **** numberOfMinimumStdDeviationForOpeningPositions, numberOfMaxStdDeviationForOpeningPositions, ! estimator, sampleLength); } private bool allTickersAreExchanged(DateTime dateTime, --- 285,289 ---- numberOfMinimumStdDeviationForOpeningPositions, numberOfMaxStdDeviationForOpeningPositions, ! estimator, sampleLength, daysForPlayingTheStrategy); } private bool allTickersAreExchanged(DateTime dateTime, *************** *** 345,348 **** --- 350,367 ---- #region newDateTimeEventHandler_openPositions + private bool newDateTimeEventHandler_openPositions_isTheRightDay() + { + bool returnValue = false; + for(int i = 0; i<this.daysForPlayingTheStrategy.Length; i++) + { + if(this.daysForPlayingTheStrategy[i] != null && + this.now().DayOfWeek == (DayOfWeek)this.daysForPlayingTheStrategy[i]) + { + returnValue = true; + i = this.daysForPlayingTheStrategy.Length; + } + } + return returnValue; + } private bool newDateTimeEventHandler_openPositions_bestFitnessIsSignificantlyHigh() { *************** *** 371,376 **** if( this.chosenOTCPositions != null && this.allTickersAreExchanged( this.now(), this.chosenOTCPositions[idxForBestPositionsCompatibleWithPortfolioType].WeightedPositions.SignedTickers.Tickers) ! && ! this.newDateTimeEventHandler_openPositions_bestFitnessIsSignificantlyHigh() ) // && // this.allTickersAreExchangedInTheLastFiveMinutelyBars( this.now(), this.chosenOTCPositions[idxForBestPositionsCompatibleWithPortfolioType].WeightedPositions.SignedTickers.Tickers ) --- 390,397 ---- if( this.chosenOTCPositions != null && this.allTickersAreExchanged( this.now(), this.chosenOTCPositions[idxForBestPositionsCompatibleWithPortfolioType].WeightedPositions.SignedTickers.Tickers) ! // && ! // this.newDateTimeEventHandler_openPositions_bestFitnessIsSignificantlyHigh() ! && this.newDateTimeEventHandler_openPositions_isTheRightDay() ! ) // && // this.allTickersAreExchangedInTheLastFiveMinutelyBars( this.now(), this.chosenOTCPositions[idxForBestPositionsCompatibleWithPortfolioType].WeightedPositions.SignedTickers.Tickers ) Index: OTCIntradayMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/OTC/OTC_Intraday/OTCIntradayMain.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OTCIntradayMain.cs 31 Aug 2009 20:40:30 -0000 1.1 --- OTCIntradayMain.cs 30 Oct 2009 23:14:23 -0000 1.2 *************** *** 92,96 **** public OTCIntradayMain() { ! this.numberOfPortfolioPositions = 2; // this.benchmark = new Benchmark( "CCE" ); this.portfolioType = PortfolioType.ShortAndLong;//filter for out of sample --- 92,96 ---- public OTCIntradayMain() { ! this.numberOfPortfolioPositions = 3; // this.benchmark = new Benchmark( "CCE" ); this.portfolioType = PortfolioType.ShortAndLong;//filter for out of sample *************** *** 99,103 **** this.benchmark = new Benchmark( "ENI.MI" ); this.firstDateTime = new DateTime( 2000 , 1 , 1 ); ! this.lastDateTime = new DateTime( 2009 , 8, 27 ); //this.stepInMinutesForTimer = 1; this.intervalFrameInSeconds = 60; --- 99,103 ---- this.benchmark = new Benchmark( "ENI.MI" ); this.firstDateTime = new DateTime( 2000 , 1 , 1 ); ! this.lastDateTime = new DateTime( 2009 , 8, 15 ); //this.stepInMinutesForTimer = 1; this.intervalFrameInSeconds = 60; *************** *** 158,163 **** bool temporizedGroup = true; int numDaysForAverageRawOpenPriceComputation = 10; ! double minPrice = 0.10; ! double maxPrice = 2000; // int maxNumberOfMostLiquidTickersToBeChosen = 150; --- 158,163 ---- bool temporizedGroup = true; int numDaysForAverageRawOpenPriceComputation = 10; ! double minPrice = 4; ! double maxPrice = 200; // int maxNumberOfMostLiquidTickersToBeChosen = 150; *************** *** 211,223 **** // int numberOfBestTestingPositionsToBeReturned = // (int)combinations.TotalNumberOfCombinations; ! int numberOfBestTestingPositionsToBeReturned = 20; // parameters for the genetic optimizer ! // double crossoverRate = 0.85; ! // double mutationRate = 0.02; ! // double elitismRate = 0.001; ! // int populationSizeForGeneticOptimizer = 5000; ! // int generationNumberForGeneticOptimizer = 0; ! // int seedForRandomGenerator = ! // QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; IDecoderForTestingPositions decoderForTestingPositions = --- 211,223 ---- // int numberOfBestTestingPositionsToBeReturned = // (int)combinations.TotalNumberOfCombinations; ! int numberOfBestTestingPositionsToBeReturned = 50; // parameters for the genetic optimizer ! double crossoverRate = 0.85; ! double mutationRate = 0.02; ! double elitismRate = 0.001; ! int populationSizeForGeneticOptimizer = 10000; ! int generationNumberForGeneticOptimizer = 30; ! int seedForRandomGenerator = ! QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; IDecoderForTestingPositions decoderForTestingPositions = *************** *** 233,237 **** // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, this.benchmark.Ticker); ! // IInSampleChooser inSampleChooser = // new OTCEndOfDayGeneticChooser(this.numberOfPortfolioPositions, numberOfBestTestingPositionsToBeReturned, // benchmark, decoderForTestingPositions , --- 233,238 ---- // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue, this.benchmark.Ticker); ! ADT.ConstantsProvider.AmountOfVariableWeightToBeAssignedToTickers = 0.40; ! IInSampleChooser inSampleChooser = // new OTCEndOfDayGeneticChooser(this.numberOfPortfolioPositions, numberOfBestTestingPositionsToBeReturned, // benchmark, decoderForTestingPositions , *************** *** 241,250 **** // mutationRate, elitismRate , populationSizeForGeneticOptimizer, // generationNumberForGeneticOptimizer, seedForRandomGenerator); ! IInSampleChooser inSampleChooser = ! new OTCEndOfDayBruteForceChooser(this.portfolioType, ! this.numberOfPortfolioPositions, ! numberOfBestTestingPositionsToBeReturned, ! this.benchmark, decoderForTestingPositions , fitnessEvaluator, ! historicalMarketValueProviderForInSample); // //office // inSampleChooser = --- 242,259 ---- // mutationRate, elitismRate , populationSizeForGeneticOptimizer, // generationNumberForGeneticOptimizer, seedForRandomGenerator); ! new OTCEndOfDayGeneticChooserWithWeights(this.numberOfPortfolioPositions, numberOfBestTestingPositionsToBeReturned, ! benchmark, ! this.genomeManagerType , ! fitnessEvaluator , ! historicalMarketValueProviderForInSample, crossoverRate, ! mutationRate, elitismRate , populationSizeForGeneticOptimizer, ! generationNumberForGeneticOptimizer, seedForRandomGenerator); ! ! // IInSampleChooser inSampleChooser = ! // new OTCEndOfDayBruteForceChooser(this.portfolioType, ! // this.numberOfPortfolioPositions, ! // numberOfBestTestingPositionsToBeReturned, ! // this.benchmark, decoderForTestingPositions , fitnessEvaluator, ! // historicalMarketValueProviderForInSample); // //office // inSampleChooser = *************** *** 265,280 **** { //int inSampleDays = 90; ! int inSampleDays = 45; ! int numDaysBetweenEachOptimization = 1; ! int numDaysBeforeCurrentDateForRetrievingInSampleData = 0; int minNumOfEligiblesForValidOptimization = 10; ! int sampleLengthForFitnessDistributionEstimation = 100; double minimumNumberOfStdDevForSignificantFitness = 0.0; ! double maximumNumberOfStdDevForSignificantFitness = 8.0; ! IInSampleFitnessDistributionEstimator estimator = new BasicInSampleFitnessDistributionEstimator(); GeneticChooser geneticChooserForEstimator = ! new OTCEndOfDayGeneticChooser(this.numberOfPortfolioPositions, 50, ! this.benchmark, new BasicDecoderForOTCPositions(), this.genomeManagerType , new OTCCTOFitnessEvaluator( new SharpeRatio() ) , --- 274,292 ---- { //int inSampleDays = 90; ! int inSampleDays = 90; ! int numDaysBetweenEachOptimization = 5; ! int numDaysBeforeCurrentDateForRetrievingInSampleData = 1; int minNumOfEligiblesForValidOptimization = 10; ! //disabilitato il controllo della fitness double minimumNumberOfStdDevForSignificantFitness = 0.0; ! double maximumNumberOfStdDevForSignificantFitness = 0.0; ! int sampleLengthForFitnessDistributionEstimation = 150; ! //disabilitato il controllo della fitness ! ! IInSampleFitnessDistributionEstimator estimator = new BasicInSampleFitnessDistributionEstimator(); GeneticChooser geneticChooserForEstimator = ! new OTCEndOfDayGeneticChooser(this.numberOfPortfolioPositions, 50, ! this.benchmark, new BasicDecoderForOTCPositions(), this.genomeManagerType , new OTCCTOFitnessEvaluator( new SharpeRatio() ) , *************** *** 283,287 **** double stopLoss = 0.015; double takeProfit = 0.03; ! IStrategyForBacktester strategyForBacktester // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , --- 295,301 ---- double stopLoss = 0.015; double takeProfit = 0.03; ! object[] daysForPlayingTheStrategy = ! new object[5]{ DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, ! DayOfWeek.Thursday, DayOfWeek.Friday}; IStrategyForBacktester strategyForBacktester // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , *************** *** 304,311 **** maximumNumberOfStdDevForSignificantFitness, estimator, ! sampleLengthForFitnessDistributionEstimation); ! ((OTCIntradayStrategy)strategyForBacktester).FindPositionsForToday( ! new DateTime(2009,8,31), new DateTime(2009,8,28) ); return strategyForBacktester; --- 318,325 ---- maximumNumberOfStdDevForSignificantFitness, estimator, ! sampleLengthForFitnessDistributionEstimation, daysForPlayingTheStrategy); ! // ((OTCIntradayStrategy)strategyForBacktester).FindPositionsForToday( ! // new DateTime(2009,9,1), new DateTime(2009,8,28) ); return strategyForBacktester; Index: OTCIntradayLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/OTC/OTC_Intraday/OTCIntradayLogItem.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OTCIntradayLogItem.cs 31 Aug 2009 20:40:30 -0000 1.1 --- OTCIntradayLogItem.cs 30 Oct 2009 23:14:23 -0000 1.2 *************** *** 145,150 **** // numDaysForOscillatingPeriodForOutOfSample * 24 *60, // new MarketDateTimeManager(benchmark, firstDateTime, lastDateTime, 60) ); OTCIntradayStrategy strategy = ! new OTCIntradayStrategy(eligiblesSelector, positionsToTest, benchmark, historicalQuoteProviderForInSampleChooser, --- 145,154 ---- // numDaysForOscillatingPeriodForOutOfSample * 24 *60, // new MarketDateTimeManager(benchmark, firstDateTime, lastDateTime, 60) ); + + object[] days = new object[5]{DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, + DayOfWeek.Thursday, DayOfWeek.Friday}; + OTCIntradayStrategy strategy = ! new OTCIntradayStrategy(eligiblesSelector, positionsToTest, benchmark, historicalQuoteProviderForInSampleChooser, *************** *** 152,156 **** Time.GetIntermediateTimes(new Time("09:30:00"), new Time("16:00:00"), 1 ), ! 0.5, 0.5, PortfolioType.ShortAndLong, null, 2, 3, null, 100); QuantProject.Business.Timing.Timer timer = --- 156,160 ---- Time.GetIntermediateTimes(new Time("09:30:00"), new Time("16:00:00"), 1 ), ! 0.5, 0.5, PortfolioType.ShortAndLong, null, 2, 3, null, 100, days); QuantProject.Business.Timing.Timer timer = |
|
From: Marco M. <mi...@us...> - 2009-10-30 23:13:55
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11077 Modified Files: Scripts_SD.csproj Log Message: Added files for the OTC strategy (for managing weights, mainly) Index: Scripts_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts_SD.csproj,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** Scripts_SD.csproj 31 Aug 2009 21:05:29 -0000 1.41 --- Scripts_SD.csproj 30 Oct 2009 23:13:43 -0000 1.42 *************** *** 117,120 **** --- 117,121 ---- <Compile Include="TickerSelectionTesting\GenomeManagerForEfficientPortfolio.cs" /> <Compile Include="TickerSelectionTesting\OTC\Decoding\BasicDecoderForOTCPositions.cs" /> + <Compile Include="TickerSelectionTesting\OTC\Decoding\DecoderForOTCPositionsWithWeights.cs" /> <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\BruteForce\OTCEndOfDayBruteForceOptimizableParametersManager.cs" /> <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\BruteForce\OTCEndOfDayBruteForceChooser.cs" /> *************** *** 122,127 **** --- 123,130 ---- <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\BruteForce\OTCOnlyShortEndOfDayBruteForceOptimizableParametersManager.cs" /> <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\GenomeManagerForOTC_EndOfDay.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\GenomeManagerForWeightedOTC_EndOfDay.cs" /> <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\OTCCTOFitnessEvaluator.cs" /> <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\OTCEndOfDayGeneticChooser.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\OTCEndOfDayGeneticChooserWithWeights.cs" /> <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\OTCFitnessEvaluator.cs" /> <Compile Include="TickerSelectionTesting\OTC\OTCPositions.cs" /> |
|
From: Marco M. <mi...@us...> - 2009-10-30 23:13:32
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/OTC/InSampleChoosers/Genetic In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11047/TickerSelectionTesting/OTC/InSampleChoosers/Genetic Added Files: GenomeManagerForWeightedOTC_EndOfDay.cs OTCEndOfDayGeneticChooserWithWeights.cs Log Message: Added files for the OTC strategy (for managing weights, mainly) --- NEW FILE: OTCEndOfDayGeneticChooserWithWeights.cs --- /* QuantProject - Quantitative Finance Library OTCEndOfDayGeneticChooserWithWeights.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Strategies; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Optimizing.GenomeManagers; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.OTC.InSampleChoosers.Genetic { /// <summary> /// In sample genetic analyzer for the Open to Close strategy /// using EOD data and optimizing weights /// </summary> [Serializable] public class OTCEndOfDayGeneticChooserWithWeights : OTCEndOfDayGeneticChooser { public OTCEndOfDayGeneticChooserWithWeights( int numberOfPortfolioPositions , int numberOfBestTestingPositionsToBeReturned , Benchmark benchmark , GenomeManagerType genomeManagerType , IFitnessEvaluator fitnessEvaluator , HistoricalMarketValueProvider historicalMarketValueProvider , double crossoverRate , double mutationRate , double elitismRate , int populationSizeForGeneticOptimizer , int generationNumberForGeneticOptimizer , int seedForRandomGenerator) : base(numberOfPortfolioPositions, numberOfBestTestingPositionsToBeReturned, benchmark , new DecoderForOTCPositionsWithWeights(), genomeManagerType, fitnessEvaluator , historicalMarketValueProvider , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , seedForRandomGenerator ) { } public override IGenomeManager GetGenomeManager(EligibleTickers eligibleTickers , ReturnsManager returnsManager) { return new GenomeManagerForWeightedOTC_EndOfDay(eligibleTickers, this.numberOfPortfolioPositions, this.decoderForTestingPositions, this.fitnessEvaluator, this.genomeManagerType , returnsManager, this.seedForRandomGenerator); } } } --- NEW FILE: GenomeManagerForWeightedOTC_EndOfDay.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerForWeightedOTC_EndOfDay.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Business.DataProviders; using QuantProject.Business.Timing; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.GenomeManagers; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.OTC.InSampleChoosers.Genetic { /// <summary> /// Implements what needed to use the Genetic Optimizer /// for finding the portfolio with weights that best suites /// the Open To Close strategy using EOD data /// </summary> [Serializable] public class GenomeManagerForWeightedOTC_EndOfDay : GenomeManagerForOTC_EndOfDay { public GenomeManagerForWeightedOTC_EndOfDay(EligibleTickers eligibleTickers, int numberOfTickersInPortfolio, IDecoderForTestingPositions decoderForTestingPositions, IFitnessEvaluator fitnessEvaluator, GenomeManagerType genomeManagerType, ReturnsManager returnsManager, int seedForRandomGenerator) : base(eligibleTickers, numberOfTickersInPortfolio, decoderForTestingPositions, fitnessEvaluator, genomeManagerType, returnsManager, seedForRandomGenerator) { this.genomeSize = 2* numberOfTickersInPortfolio; } } } |
|
From: Marco M. <mi...@us...> - 2009-10-30 23:13:30
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/OTC/Decoding In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11047/TickerSelectionTesting/OTC/Decoding Added Files: DecoderForOTCPositionsWithWeights.cs Log Message: Added files for the OTC strategy (for managing weights, mainly) --- NEW FILE: DecoderForOTCPositionsWithWeights.cs --- /* QuantProject - Quantitative Finance Library DecoderForOTCPositionsWithWeights.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Collections; using QuantProject.ADT.Optimizing.Decoding; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Optimizing.Decoding; namespace QuantProject.Scripts.TickerSelectionTesting.OTC { /// <summary> /// Decodes optimization candidates to a /// OTCPositions with weights /// </summary> [Serializable] public class DecoderForOTCPositionsWithWeights : DecoderForTestingPositionsWithWeights { public DecoderForOTCPositionsWithWeights() : base() { } protected override TestingPositions getMeaningForUndecodable() { return new OTCPositions(); } protected override TestingPositions decodeDecodable() { SignedTickers signedTickers = this.decodeSignedTickers(); OTCPositions otcPositions = new OTCPositions( new WeightedPositions( this.getUnsignedWeights(signedTickers), signedTickers) ); return otcPositions; } protected override string getDescription() { return "OTC_Dcdr_WithWghts"; } } } |
|
From: Marco M. <mi...@us...> - 2009-10-30 23:09:40
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv10618 Modified Files: Business_SD.csproj Log Message: Added DecoderForTestingPositionsWithWeights Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** Business_SD.csproj 31 Aug 2009 21:05:29 -0000 1.40 --- Business_SD.csproj 30 Oct 2009 23:09:23 -0000 1.41 *************** *** 116,119 **** --- 116,120 ---- <Compile Include="a2_Strategies\Optimizing\Decoding\DecoderForBalancedWeightedPositions.cs" /> <Compile Include="a2_Strategies\Optimizing\Decoding\DecoderForTestingPositionsWithBalancedWeights.cs" /> + <Compile Include="a2_Strategies\Optimizing\Decoding\DecoderForTestingPositionsWithWeights.cs" /> <Compile Include="a2_Strategies\Optimizing\Decoding\IDecoderForTestingPositions.cs" /> <Compile Include="a2_Strategies\Optimizing\Decoding\IDecoderForWeightedPositions.cs" /> |
|
From: Marco M. <mi...@us...> - 2009-10-30 23:09:33
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv10618/a2_Strategies/Optimizing/Decoding Added Files: DecoderForTestingPositionsWithWeights.cs Log Message: Added DecoderForTestingPositionsWithWeights --- NEW FILE: DecoderForTestingPositionsWithWeights.cs --- /* QuantProject - Quantitative Finance Library DecoderForTestingPositionsWithWeights.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT; using QuantProject.Business.Strategies; namespace QuantProject.Business.Strategies.Optimizing.Decoding { /// <summary> /// Decodes optimization candidates to a /// TestingPositions /// In this implementation, weights are computed through encoded values, /// that should be optimized by a given optimizer /// </summary> [Serializable] public abstract class DecoderForTestingPositionsWithWeights : BasicDecoderForTestingPositions { protected int[] weightsRelatedGeneValues; public DecoderForTestingPositionsWithWeights() : base() { } //this method sets weightsRelatedGeneValues too protected override void setTickerRelatedGeneValues() { this.tickerRelatedGeneValues = new int[this.encoded.Length/2]; this.weightsRelatedGeneValues = new int[this.encoded.Length/2]; int idxForTickerRelatedGeneValues = 0; int idxForWeightsRelatedGeneValues = 0; for(int i = 0; i< this.encoded.Length; i++) { if(i%2 == 0) // position of current encoded is even { this.weightsRelatedGeneValues[idxForWeightsRelatedGeneValues] = this.encoded[i]; idxForWeightsRelatedGeneValues++; } else // position of current encoded is odd { this.tickerRelatedGeneValues[idxForTickerRelatedGeneValues] = this.encoded[i]; idxForTickerRelatedGeneValues++; } } } protected double getWeight( int idxInGenes ) { double weight = 0.0; double totVariableWeight = ConstantsProvider.AmountOfVariableWeightToBeAssignedToTickers; double minWeight = ( 1.0 - totVariableWeight ) / weightsRelatedGeneValues.Length; double totalOfValuesForWeights = 0.0; for(int j = 0; j < weightsRelatedGeneValues.Length; j++) // ticker's weight is contained in weightsRelatedGeneValues // totalOfValuesForWeights can't be equal to 0 ! totalOfValuesForWeights += ( Math.Abs(weightsRelatedGeneValues[j]) + 1.0 ); double freeWeight = ( Math.Abs(weightsRelatedGeneValues[idxInGenes]) + 1.0 ) / totalOfValuesForWeights; weight = minWeight + freeWeight * totVariableWeight; return weight; } protected override double[] getWeights(SignedTickers signedTickers) { double[] weights = new double[this.weightsRelatedGeneValues.Length]; double coefficient; for(int i = 0; i<weights.Length; i++) { if(signedTickers[i].IsLong) coefficient = 1.0; else//is Short coefficient = -1.0; weights[i] = coefficient * this.getWeight( i ); } return weights; } protected override double[] getUnsignedWeights(SignedTickers signedTickers) { double[] weights = this.getWeights( signedTickers ); for(int i = 0; i<weights.Length; i++) { weights[i] = Math.Abs(weights[i]); } return weights; } protected override string getDescription() { return "bscTstngPstnsWthWgths"; } } } |
|
From: Glauco S. <gla...@us...> - 2009-10-01 19:16:32
|
Update of /cvsroot/quantproject/QuantProject/b91_QuantProject In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv5199/b91_QuantProject Modified Files: Main.cs Log Message: The main has been reset so that the Run command runs a script Index: Main.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b91_QuantProject/Main.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Main.cs 7 Mar 2009 04:15:29 -0000 1.23 --- Main.cs 1 Oct 2009 19:16:23 -0000 1.24 *************** *** 475,482 **** // new FixedLengthTwoPhasesMain().Run(); ! new PairsTradingSerializedReportViewer().Run(); // new PairsTradingMain().Run(); ! // new RunOneRank().Run(); //new RunEfficientCTCPorfolio("Test",400,5,90,10,10000, // "^SPX", --- 475,482 ---- // new FixedLengthTwoPhasesMain().Run(); ! // new PairsTradingSerializedReportViewer().Run(); // new PairsTradingMain().Run(); ! new RunOneRank().Run(); //new RunEfficientCTCPorfolio("Test",400,5,90,10,10000, // "^SPX", |
|
From: Marco M. <mi...@us...> - 2009-08-31 21:05:46
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv24175/b7_Scripts Modified Files: Scripts_SD.csproj Log Message: Update SD project's files Index: Scripts_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts_SD.csproj,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** Scripts_SD.csproj 16 Mar 2009 22:32:14 -0000 1.40 --- Scripts_SD.csproj 31 Aug 2009 21:05:29 -0000 1.41 *************** *** 54,57 **** --- 54,58 ---- <Compile Include="General\Logging\DummyTesterForTestingPositions.cs" /> <Compile Include="General\Reporting\BackTesterReportViewer.cs" /> + <Compile Include="General\Strategies\Optimizing\FitnessEvaluation\DummyRandomFitnessEvaluator.cs" /> <Compile Include="General\Strategies\SimpleStrategy.cs" /> <Compile Include="MyTradingSystem.cs" /> *************** *** 68,73 **** --- 69,81 ---- <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\RunBiasedPVO_OTC.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\Decoding\BasicDecoderForPVOPositions.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\EntryConditions\AlwaysTrueEntryCondition.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\EntryConditions\IEntryCondition.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\EntryConditions\InefficiencyMovingBackEntryCondition.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\EntryConditions\PreviousPeriodsWereEfficientEntryCondition.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\EntryConditions\PriceRatioEntryCondition.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\FitnessEvaluators\PVOFitnessEvaluator.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\GenomeManagerPVO_OTC.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PriceRatioChooser\PriceRatio.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PriceRatioChooser\PVOLessVolatilePriceRatioChooser.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOChooserFromSavedBackTestLog.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOCorrelationChooser.cs" /> *************** *** 80,83 **** --- 88,93 ---- <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_OTCCTOCorrelationChooser.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_OTOCorrelationChooser.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenericMain.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenericStrategy.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenomeManager.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOLogItem.cs" /> *************** *** 106,109 **** --- 116,132 ---- <Compile Include="TickerSelectionTesting\GenomeManagerForEfficientCTOPortfolio.cs" /> <Compile Include="TickerSelectionTesting\GenomeManagerForEfficientPortfolio.cs" /> + <Compile Include="TickerSelectionTesting\OTC\Decoding\BasicDecoderForOTCPositions.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\BruteForce\OTCEndOfDayBruteForceOptimizableParametersManager.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\BruteForce\OTCEndOfDayBruteForceChooser.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\BruteForce\OTCOnlyLongEndOfDayBruteForceOptimizableParametersManager.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\BruteForce\OTCOnlyShortEndOfDayBruteForceOptimizableParametersManager.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\GenomeManagerForOTC_EndOfDay.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\OTCCTOFitnessEvaluator.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\OTCEndOfDayGeneticChooser.cs" /> + <Compile Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic\OTCFitnessEvaluator.cs" /> + <Compile Include="TickerSelectionTesting\OTC\OTCPositions.cs" /> + <Compile Include="TickerSelectionTesting\OTC\OTC_Intraday\OTCIntradayMain.cs" /> + <Compile Include="TickerSelectionTesting\OTC\OTC_Intraday\OTCIntradayStrategy.cs" /> + <Compile Include="TickerSelectionTesting\OTC\OTC_Intraday\OTCIntradayLogItem.cs" /> <Compile Include="TickerSelectionTesting\RunEfficientCTCPortfolio.cs" /> <Compile Include="TickerSelectionTesting\RunEfficientCTOPortfolio.cs" /> *************** *** 293,297 **** --- 316,323 ---- <Folder Include="EvaluatingOptimizationTechnique\EfficientPortfolio\" /> <Folder Include="General\Strategies" /> + <Folder Include="General\Strategies\Optimizing" /> + <Folder Include="General\Strategies\Optimizing\FitnessEvaluation" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\ExtremeCounterTrend" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\EntryConditions" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\Decoding" /> <Folder Include="General" /> *************** *** 300,305 **** --- 326,338 ---- <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\FitnessEvaluators" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PriceRatioChooser" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO" /> + <Folder Include="TickerSelectionTesting\OTC" /> + <Folder Include="TickerSelectionTesting\OTC\Decoding" /> + <Folder Include="TickerSelectionTesting\OTC\InSampleChoosers\BruteForce" /> + <Folder Include="TickerSelectionTesting\OTC\OTC_Intraday" /> + <Folder Include="TickerSelectionTesting\OTC\InSampleChoosers" /> + <Folder Include="TickerSelectionTesting\OTC\InSampleChoosers\Genetic" /> <Folder Include="TickerSelectionTesting\SimpleSelection\" /> <Folder Include="WalkForwardTesting\FixedLengthTwoPhases" /> |
|
From: Marco M. <mi...@us...> - 2009-08-31 21:05:40
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv24175/b4_Business Modified Files: Business_SD.csproj Log Message: Update SD project's files Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Business_SD.csproj 4 Apr 2009 15:48:28 -0000 1.39 --- Business_SD.csproj 31 Aug 2009 21:05:29 -0000 1.40 *************** *** 48,51 **** --- 48,54 ---- <Compile Include="a05_Timing\IndexBasedHistoricalTimer.cs" /> <Compile Include="a05_Timing\Timer.cs" /> + <Compile Include="a05_Timing\TimingManagement\MarketDaysManager.cs" /> + <Compile Include="a05_Timing\TimingManagement\MarketIntervalsManager.cs" /> + <Compile Include="a05_Timing\TimingManagement\MarketMinutesManager.cs" /> <Compile Include="a07_DataProviders\HistoricalAdjustedBarProvider.cs" /> <Compile Include="a07_DataProviders\HistoricalBarInterpolatingProvider.cs" /> *************** *** 60,63 **** --- 63,68 ---- <Compile Include="a1_Financial\a2_Accounting\AccountProviding\InteractiveBrokerAccountProvider.cs" /> <Compile Include="a1_Financial\a2_Accounting\AccountProviding\SimpleAccountProvider.cs" /> + <Compile Include="a1_Financial\a2_Accounting\Commissions\FixedCommission.cs" /> + <Compile Include="a1_Financial\a2_Accounting\Commissions\FixedCommissionManager.cs" /> <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\DateTimeSelectorsForEquityLine\IDateTimeSelectorForEquityLine.cs" /> <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\DateTimeSelectorsForEquityLine\SelectorForMaketClose.cs" /> *************** *** 76,79 **** --- 81,85 ---- <Compile Include="a2_Strategies\BasicStrategyForBacktester.cs" /> <Compile Include="a2_Strategies\Benchmark.cs" /> + <Compile Include="a2_Strategies\Eligibles\ByPriceLessLiquidAlwaysIntradayQuoted.cs" /> <Compile Include="a2_Strategies\Eligibles\ByPriceLessVolatileOTCAlwaysQuoted.cs" /> <Compile Include="a2_Strategies\Eligibles\ByPriceMostLiquidAlwaysIntradayQuoted.cs" /> *************** *** 97,100 **** --- 103,108 ---- <Compile Include="a2_Strategies\InSample\GeneticChooser.cs" /> <Compile Include="a2_Strategies\InSample\IInSampleChooser.cs" /> + <Compile Include="a2_Strategies\InSample\InSampleFitnessDistributionEstimation\BasicInSampleFitnessDistributionEstimator.cs" /> + <Compile Include="a2_Strategies\InSample\InSampleFitnessDistributionEstimation\IInSampleFitnessDistributionEstimator.cs" /> <Compile Include="a2_Strategies\IStrategy.cs" /> <Compile Include="a2_Strategies\IStrategyForBacktester.cs" /> *************** *** 137,140 **** --- 145,149 ---- <Compile Include="a2_Strategies\TickersRelationships\OpenToCloseCorrelationProvider.cs" /> <Compile Include="a2_Strategies\TickersRelationships\OpenToOpenCorrelationProvider.cs" /> + <Compile Include="a2_Strategies\TickersRelationships\PriceRatioProvider.cs" /> <Compile Include="a2_Strategies\TickersRelationships\TickersPearsonCorrelation.cs" /> <Compile Include="a4_Scripting\IExecutable.cs" /> *************** *** 253,260 **** --- 262,271 ---- <Name>b3_Data</Name> </ProjectReference> + <Folder Include="a05_Timing\TimingManagement" /> <Folder Include="a1_Financial\a2_Accounting\AccountProviding" /> <Folder Include="a1_Financial\a2_Accounting\h5_Reporting\DateTimeSelectorsForEquityLine" /> <Folder Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows" /> <Folder Include="a2_Strategies\EndOfDayStrategies" /> + <Folder Include="a2_Strategies\InSample\InSampleFitnessDistributionEstimation" /> <Folder Include="a2_Strategies\Optimizing\BruteForce" /> <Folder Include="a2_Strategies\Optimizing\FitnessEvaluation" /> |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PriceRatioChooser In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv23891/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PriceRatioChooser Added Files: PVOLessVolatilePriceRatioChooser.cs Log Message: Added files for the PVO strategy --- NEW FILE: PVOLessVolatilePriceRatioChooser.cs --- /* QuantProject - Quantitative Finance Library PVOLessVolatilePriceRatioChooser.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Messaging; using QuantProject.Business.Timing; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.OutOfSample; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers.PriceRatioChooser { /// <summary> /// PVOLessVolatilePriceRatioChooser to be used for /// in sample optimization /// By means of price ratio analysis, the AnalyzeInSample method returns the /// requested number of PVOPositions (positions for the PVO strategy) /// </summary> [Serializable] public class PVOLessVolatilePriceRatioChooser : IInSampleChooser { public event NewProgressEventHandler NewProgress; public event NewMessageEventHandler NewMessage; private string[] tickers; private PriceRatio[] priceRatios; private int numberOfBestTestingPositionsToBeReturned; private bool balancedWeightsOnVolatilityBase; public virtual string Description { get { string description = "PVOLessVolatilePriceRatioChooser_" + "NumOfTickersReturned:\n" + this.numberOfBestTestingPositionsToBeReturned.ToString(); return description; } } /// <summary> /// PVOLessVolatilePriceRatioChooser to be used for /// in sample optimization /// </summary> /// <param name="numberOfBestTestingPositionsToBeReturned"> /// The number of PVOPositions that the /// AnalyzeInSample method will return /// </param> public PVOLessVolatilePriceRatioChooser(int numberOfBestTestingPositionsToBeReturned, bool balancedWeightsOnVolatilityBase) { this.numberOfBestTestingPositionsToBeReturned = numberOfBestTestingPositionsToBeReturned; this.balancedWeightsOnVolatilityBase = balancedWeightsOnVolatilityBase; } #region AnalyzeInSample private void analyzeInSample_checkParameters( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { if ( eligibleTickers.Count < 2 ) throw new Exception( "Eligible tickers contains " + "only " + eligibleTickers.Count + " elements, while Price Ratio computation requires at least 2 elements"); } private double setTickersAndPriceRatios_setPriceRatios_getPriceRatioAverage(int indexOfFirstTicker, int indexOfSecondTicker, DateTime firstDate, DateTime lastDate) { double returnValue = PriceRatioProvider.GetPriceRatioAverage(this.tickers[indexOfFirstTicker], this.tickers[indexOfSecondTicker], firstDate, lastDate); return returnValue; } private double setTickersAndPriceRatios_setPriceRatios_getPriceRatioAbsoluteStandardDeviation(int indexOfFirstTicker, int indexOfSecondTicker, DateTime firstDate, DateTime lastDate) { double returnValue = PriceRatioProvider.GetPriceRatioStandardDeviation(this.tickers[indexOfFirstTicker], this.tickers[indexOfSecondTicker], firstDate, lastDate); return returnValue; } private void setTickersAndPriceRatios_setPriceRatios(DateTime firstDate, DateTime lastDate) { int n = this.tickers.Length; //combinations without repetitions: //n_fatt /( k_fatt * (n-k)_fatt ): when k = 2, // it can be reduced to this simple formula: int numOfCombinationTwoByTwo = n * (n - 1) / 2; this.priceRatios = new PriceRatio[numOfCombinationTwoByTwo]; int index = 0; for (int i = 0; i < this.tickers.Length; i++) for (int j = i + 1; j < this.tickers.Length; j++) { try{ this.priceRatios[index] = new PriceRatio( this.tickers[i], this.tickers[j], this.setTickersAndPriceRatios_setPriceRatios_getPriceRatioAverage( i , j, firstDate, lastDate), this.setTickersAndPriceRatios_setPriceRatios_getPriceRatioAbsoluteStandardDeviation( i , j, firstDate, lastDate) ); } catch(Exception ex) { string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + ""; } index++; } Array.Sort(this.priceRatios); } protected void setTickersAndPriceRatios(EligibleTickers eligibleTickers , ReturnsManager returnsManager) { DateTime firstDate = HistoricalEndOfDayTimer.GetMarketClose(returnsManager.ReturnIntervals[0].Begin); DateTime lastDate = HistoricalEndOfDayTimer.GetMarketClose(returnsManager.ReturnIntervals.LastDateTime); this.tickers = eligibleTickers.Tickers; this.setTickersAndPriceRatios_setPriceRatios(firstDate, lastDate); } protected PVOPositions getTestingPositions(SignedTickers signedTickers, ReturnsManager returnsManager) { WeightedPositions weightedPositions; if(this.balancedWeightsOnVolatilityBase == true) weightedPositions = new WeightedPositions(WeightedPositions.GetBalancedWeights(signedTickers, returnsManager), signedTickers.Tickers); else//just equal weights weightedPositions = new WeightedPositions(signedTickers); return new PVOPositions( weightedPositions, 0.0, 0.0, 0 ); } private TestingPositions[] getBestTestingPositionsInSample( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { this.setTickersAndPriceRatios(eligibleTickers , returnsManager); TestingPositions[] bestTestingPositions = new TestingPositions[this.numberOfBestTestingPositionsToBeReturned]; int addedTestingPositions = 0; int counter = 0; while(addedTestingPositions < this.numberOfBestTestingPositionsToBeReturned && counter < priceRatios.Length) { SignedTickers signedTickers = new SignedTickers("-"+priceRatios[ counter ].FirstTicker + ";" + priceRatios[ counter ].SecondTicker); bestTestingPositions[addedTestingPositions] = this.getTestingPositions(signedTickers, returnsManager); ((PVOPositions)bestTestingPositions[addedTestingPositions]).FitnessInSample = priceRatios[ counter ].RelativeStandardDeviation; addedTestingPositions++; counter++; } return bestTestingPositions; } /// <summary> /// Returns the best TestingPositions with respect to the in sample data /// </summary> /// <param name="eligibleTickers"></param> /// <returns></returns> public object AnalyzeInSample( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { if ( this.NewMessage != null ) this.NewMessage( this , new NewMessageEventArgs( "New Price Ratio Analysis" ) ); if ( this.NewProgress != null ) this.NewProgress( this , new NewProgressEventArgs( 1 , 1 ) ); this.analyzeInSample_checkParameters( eligibleTickers , returnsManager ); TestingPositions[] bestTestingPositionsInSample = this.getBestTestingPositionsInSample( eligibleTickers , returnsManager ); return bestTestingPositionsInSample; } #endregion } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 21:03:57
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv23891/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Added Files: PVOGenericMain.cs PVOGenericStrategy.cs Log Message: Added files for the PVO strategy --- NEW FILE: PVOGenericStrategy.cs --- /* QuantProject - Quantitative Finance Library PVOGenericStrategy.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using System.Collections.Generic; using QuantProject.ADT; using QuantProject.ADT.Histories; using QuantProject.ADT.Messaging; using QuantProject.ADT.Timing; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Business.Timing.TimingManagement; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Data; using QuantProject.Data.DataProviders; using QuantProject.Data.DataProviders.Bars.Caching; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.EntryConditions; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// This class contains the core strategy for the Portfolio Value /// Oscillator /// </summary> [Serializable] public class PVOGenericStrategy : IStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; public event NewMessageEventHandler NewMessage; //initialized by the constructor protected int inSampleDays; protected int numDaysBetweenEachOptimization; protected IInSampleChooser inSampleChooser; protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; protected HistoricalMarketValueProvider historicalMarketValueProviderForInSample; protected HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample; protected double oversoldThreshold; protected double overboughtThreshold; protected double oversoldThresholdMAX; protected double overboughtThresholdMAX; //initialized after constructor's call protected int numDaysElapsedSinceLastOptimization; protected ReturnsManager returnsManager; protected TestingPositions[] chosenPVOPositions; //chosen in sample: these are the eligible positions for out //of sample testing protected PVOPositions positionsForOutOfSample; protected PVOPositionsStatus positionsForOutOfSampleStatus; protected DateTime lastOptimizationDateTime; protected Account account; public Account Account { get { return this.account; } set { this.account = value; } } private int minimumNumberOfEligiblesForValidOptimization; protected bool stopLossConditionReached; protected bool takeProfitConditionReached; protected double inefficiencyLengthInMarketIntervals; protected int numberOfPreviousEfficientPeriods; protected int numberOfDaysForPriceRatioAnalysis; protected double numberOfStdDeviationForSignificantPriceRatioMovements; protected double maxOpeningLengthInMarketIntervals; protected double marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening; protected double marketIntervalsFromLastLossOrProfitToWaitBeforeClosing; protected DateTime lastEntryDateTime; protected DateTime lastProfitOrLossDateTime; protected DateTime lastInefficiencyDateTime; protected List<Time> openingTimesForAvailableBars; protected double currentAccountValue; protected double previousAccountValue; protected double stopLoss; protected double takeProfit; protected double leverage; protected bool openOnlyLongPositions; protected List<IEntryCondition> entryConditions; protected bool allEntryConditionsHaveToBeSatisfied; private MarketIntervalsManager marketIntervalsManagerForOutOfSample; private string description_GetDescriptionForChooser() { if(this.inSampleChooser == null) return "ConstantChooser"; else return this.inSampleChooser.Description; } public string Description { get { string description = "PVO_Intraday\n" + "Tickers_" + "2\n" + "_inSampleDays_" + this.inSampleDays.ToString() + "\n" + this.eligiblesSelector.Description + "\n" + "oversoldThreshold_" + this.oversoldThreshold.ToString() + "\n" + "overboughtThreshold_" + this.overboughtThreshold.ToString() + "\n" + this.description_GetDescriptionForChooser() + "\n" + "Optimization each " + this.numDaysBetweenEachOptimization.ToString() + " days"; return description; } } public bool StopBacktestIfMaxRunningHoursHasBeenReached { get { return true; } } private void pvoStrategyIntraday_checkTimeParameters() { ;// to do } private void pvoGenericStrategy(IEligiblesSelector eligiblesSelector, int minimumNumberOfEligiblesForValidOptimization, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, double oversoldThresholdMAX, double overboughtThresholdMAX, HistoricalMarketValueProvider historicalMarketValueProviderForInSample, HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMarketIntervals, int numberOfPreviousEfficientPeriods, int numberOfDaysForPriceRatioAnalysis, double numberOfStdDeviationForSignificantPriceRatioMovements, double marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening, double marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMarketIntervals, List<Time> openingTimesForAvailableBars, double stopLoss, double takeProfit, double leverage, bool openOnlyLongPositions, List<IEntryCondition> entryConditions, bool allEntryConditionsHaveToBeSatisfied, MarketIntervalsManager marketIntervalsManagerForOutOfSample) { this.eligiblesSelector = eligiblesSelector; this.minimumNumberOfEligiblesForValidOptimization = minimumNumberOfEligiblesForValidOptimization; this.inSampleDays = inSampleDays; this.benchmark = benchmark; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.oversoldThreshold = oversoldThreshold; this.overboughtThreshold = overboughtThreshold; this.oversoldThresholdMAX = oversoldThresholdMAX; this.overboughtThresholdMAX = overboughtThresholdMAX; this.historicalMarketValueProviderForInSample = historicalMarketValueProviderForInSample; this.historicalMarketValueProviderForOutOfSample = historicalMarketValueProviderForOutOfSample; this.inefficiencyLengthInMarketIntervals = inefficiencyLengthInMarketIntervals; this.numberOfPreviousEfficientPeriods = numberOfPreviousEfficientPeriods; this.numberOfDaysForPriceRatioAnalysis = numberOfDaysForPriceRatioAnalysis; this.numberOfStdDeviationForSignificantPriceRatioMovements = numberOfStdDeviationForSignificantPriceRatioMovements; this.marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening = marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening; this.marketIntervalsFromLastLossOrProfitToWaitBeforeClosing = marketIntervalsFromLastLossOrProfitToWaitBeforeClosing; this.maxOpeningLengthInMarketIntervals = maxOpeningLengthInMarketIntervals; this.openingTimesForAvailableBars = openingTimesForAvailableBars; this.stopLoss = stopLoss; this.takeProfit = takeProfit; this.leverage = leverage; this.lastOptimizationDateTime = DateTime.MinValue; this.pvoStrategyIntraday_checkTimeParameters(); this.lastEntryDateTime = new DateTime(1900,1,1,0,0,0); this.lastInefficiencyDateTime = new DateTime(1900,1,1,0,0,0); this.lastProfitOrLossDateTime = new DateTime(1900,1,1,0,0,0); this.openOnlyLongPositions = openOnlyLongPositions; this.entryConditions = entryConditions; this.allEntryConditionsHaveToBeSatisfied = allEntryConditionsHaveToBeSatisfied; this.marketIntervalsManagerForOutOfSample = marketIntervalsManagerForOutOfSample; } public PVOGenericStrategy(IEligiblesSelector eligiblesSelector, int minimumNumberOfEligiblesForValidOptimization, IInSampleChooser inSampleChooser, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, double oversoldThresholdMAX, double overboughtThresholdMAX, HistoricalMarketValueProvider historicalMarketValueProviderForInSample, HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMarketIntervals, int numberOfPreviousEfficientPeriods, int numberOfDaysForPriceRatioAnalysis, double numberOfStdDeviationForSignificantPriceRatioMovements, double marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening, double marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMarketIntervals, List<Time> openingTimesForAvailableBars, double stopLoss, double takeProfit, double leverage, bool openOnlyLongPositions, List<IEntryCondition> entryConditions, bool allEntryConditionsHaveToBeSatisfied, MarketIntervalsManager marketIntervalsManager) { this.pvoGenericStrategy(eligiblesSelector, minimumNumberOfEligiblesForValidOptimization, inSampleDays , benchmark , numDaysBetweenEachOptimization , oversoldThreshold, overboughtThreshold, oversoldThresholdMAX, overboughtThresholdMAX, historicalMarketValueProviderForInSample, historicalMarketValueProviderForOutOfSample, inefficiencyLengthInMarketIntervals, numberOfPreviousEfficientPeriods, numberOfDaysForPriceRatioAnalysis, numberOfStdDeviationForSignificantPriceRatioMovements, marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening, marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMarketIntervals, openingTimesForAvailableBars, stopLoss, takeProfit, leverage, openOnlyLongPositions, entryConditions, allEntryConditionsHaveToBeSatisfied, marketIntervalsManager); this.inSampleChooser = inSampleChooser; } public PVOGenericStrategy(IEligiblesSelector eligiblesSelector, int minimumNumberOfEligiblesForValidOptimization, IInSampleChooser inSampleChooser, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, HistoricalMarketValueProvider historicalMarketValueProviderForInSample, HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMarketIntervals, int numberOfPreviousEfficientPeriods, int numberOfDaysForPriceRatioAnalysis, double numberOfStdDeviationForSignificantPriceRatioMovements, double marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening, double marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMarketIntervals, List<Time> openingTimesForAvailableBars, double stopLoss, double takeProfit, double leverage, bool openOnlyLongPositions, List<IEntryCondition> entryConditions, bool allEntryConditionsHaveToBeSatisfied, MarketIntervalsManager marketIntervalsManager) { this.pvoGenericStrategy(eligiblesSelector, minimumNumberOfEligiblesForValidOptimization, inSampleDays , benchmark , numDaysBetweenEachOptimization , oversoldThreshold, overboughtThreshold, double.MaxValue, double.MaxValue, historicalMarketValueProviderForInSample, historicalMarketValueProviderForOutOfSample, inefficiencyLengthInMarketIntervals, numberOfPreviousEfficientPeriods, numberOfDaysForPriceRatioAnalysis, numberOfStdDeviationForSignificantPriceRatioMovements, marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening, marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMarketIntervals, openingTimesForAvailableBars, stopLoss, takeProfit, leverage, openOnlyLongPositions, entryConditions, allEntryConditionsHaveToBeSatisfied, marketIntervalsManager); this.inSampleChooser = inSampleChooser; } public PVOGenericStrategy(IEligiblesSelector eligiblesSelector, int minimumNumberOfEligiblesForValidOptimization, TestingPositions[] chosenPVOPositions, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, double oversoldThresholdMAX, double overboughtThresholdMAX, HistoricalMarketValueProvider historicalMarketValueProviderForInSample, HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMarketIntervals, int numberOfPreviousEfficientPeriods, int numberOfDaysForPriceRatioAnalysis, double numberOfStdDeviationForSignificantPriceRatioMovements, double marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening, double marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMarketIntervals, List<Time> openingTimesForAvailableBars, double stopLoss, double takeProfit, double leverage, bool openOnlyLongPositions, List<IEntryCondition> entryConditions, bool allEntryConditionsHaveToBeSatisfied, MarketIntervalsManager marketIntervalsManager) { this.pvoGenericStrategy(eligiblesSelector, minimumNumberOfEligiblesForValidOptimization, inSampleDays , benchmark , numDaysBetweenEachOptimization , oversoldThreshold, overboughtThreshold, oversoldThresholdMAX, overboughtThresholdMAX, historicalMarketValueProviderForInSample, historicalMarketValueProviderForOutOfSample, inefficiencyLengthInMarketIntervals, numberOfPreviousEfficientPeriods, numberOfDaysForPriceRatioAnalysis, numberOfStdDeviationForSignificantPriceRatioMovements, marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening, marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMarketIntervals, openingTimesForAvailableBars, stopLoss, takeProfit, leverage, openOnlyLongPositions, entryConditions, allEntryConditionsHaveToBeSatisfied, marketIntervalsManager); this.chosenPVOPositions = chosenPVOPositions; } public PVOGenericStrategy(IEligiblesSelector eligiblesSelector, int minimumNumberOfEligiblesForValidOptimization, TestingPositions[] chosenPVOPositions, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, HistoricalMarketValueProvider historicalMarketValueProviderForInSample, HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample, double inefficiencyLengthInMarketIntervals, int numberOfPreviousEfficientPeriods, int numberOfDaysForPriceRatioAnalysis, double numberOfStdDeviationForSignificantPriceRatioMovements, double marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening, double marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, double maxOpeningLengthInMarketIntervals, List<Time> openingTimesForAvailableBars, double stopLoss, double takeProfit, double leverage, bool openOnlyLongPositions, List<IEntryCondition> entryConditions, bool allEntryConditionsHaveToBeSatisfied, MarketIntervalsManager marketIntervalsManager) { this.pvoGenericStrategy(eligiblesSelector, minimumNumberOfEligiblesForValidOptimization, inSampleDays , benchmark , numDaysBetweenEachOptimization , oversoldThreshold, overboughtThreshold, double.MaxValue, double.MaxValue, historicalMarketValueProviderForInSample, historicalMarketValueProviderForOutOfSample, inefficiencyLengthInMarketIntervals, numberOfPreviousEfficientPeriods, numberOfDaysForPriceRatioAnalysis, numberOfStdDeviationForSignificantPriceRatioMovements, marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening, marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMarketIntervals, openingTimesForAvailableBars, stopLoss, takeProfit, leverage, openOnlyLongPositions, entryConditions, allEntryConditionsHaveToBeSatisfied, marketIntervalsManager); this.chosenPVOPositions = chosenPVOPositions; } private bool allTickersAreExchanged(DateTime dateTime, string[] tickers) { bool returnValue = true; try{ for( int i = 0; i < tickers.Length; i++ ) { if(!this.historicalMarketValueProviderForOutOfSample.WasExchanged( tickers[i], dateTime ) ) { returnValue = false; i = tickers.Length; //exit from for } } } catch(Exception ex){ string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + ""; returnValue = false; } return returnValue; } #region newDateTimeEventHandler_closePositions private void newDateTimeEventHandler_closePositions(DateTime currentTime) { bool positionsHaveBeenOpenedEnough = false; bool isTimeToProfitOrToStopALoss = false; try{ positionsHaveBeenOpenedEnough = (this.account.Portfolio.Count > 0 && this.marketIntervalsManagerForOutOfSample.AddMarketIntervals(this.lastEntryDateTime, (int)this.maxOpeningLengthInMarketIntervals ) <= currentTime ); isTimeToProfitOrToStopALoss = this.account.Portfolio.Count > 0 && (this.takeProfitConditionReached || this.stopLossConditionReached) && (marketIntervalsManagerForOutOfSample.AddMarketIntervals(lastProfitOrLossDateTime, (int)marketIntervalsFromLastLossOrProfitToWaitBeforeClosing) == currentTime ); } catch{} if( (positionsHaveBeenOpenedEnough || isTimeToProfitOrToStopALoss ) && allTickersAreExchanged( this.now(), AccountManager.GetTickersInOpenedPositions(this.account) ) ) { AccountManager.ClosePositions( this.account ); this.currentAccountValue = 0.0; this.previousAccountValue = 0.0; this.lastEntryDateTime = new DateTime(1900,1,1,0,0,0); this.lastInefficiencyDateTime = new DateTime(1900,1,1,0,0,0); this.lastProfitOrLossDateTime = new DateTime(1900,1,1,0,0,0); this.takeProfitConditionReached = false; this.stopLossConditionReached = false; } } #endregion newDateTimeEventHandler_closePositions #region newDateTimeEventHandler_openPositions private void newDateTimeEventHandler_openPositions(DateTime currentDateTime) { DateTime maxDateTimeForClose; try{ maxDateTimeForClose = marketIntervalsManagerForOutOfSample.AddMarketIntervals(currentDateTime, (int)maxOpeningLengthInMarketIntervals); } catch{ return; } if( this.account.Portfolio.Count == 0 && this.positionsForOutOfSample != null && this.allTickersAreExchanged( currentDateTime, this.positionsForOutOfSample.WeightedPositions.SignedTickers.Tickers ) && this.allTickersAreExchanged( maxDateTimeForClose, this.positionsForOutOfSample.WeightedPositions.SignedTickers.Tickers ) ) { switch (this.positionsForOutOfSampleStatus) { case PVOPositionsStatus.Overbought: { #region manage Overbought case this.positionsForOutOfSample.WeightedPositions.Reverse(); try { AccountManager.OpenPositions( this.positionsForOutOfSample.WeightedPositions, this.account, 10000, this.leverage ); this.lastEntryDateTime = currentDateTime; this.previousAccountValue = this.account.GetMarketValue(); } catch(Exception ex) { string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + ""; } finally { this.positionsForOutOfSample.WeightedPositions.Reverse(); } #endregion break; } case PVOPositionsStatus.Oversold: { #region manage Oversold case try { AccountManager.OpenPositions( this.positionsForOutOfSample.WeightedPositions, this.account, 10000, this.leverage ); this.lastEntryDateTime = currentDateTime; this.previousAccountValue = this.account.GetMarketValue(); } catch(Exception ex) { string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + ""; } #endregion oversold case break; } case PVOPositionsStatus.InTheMiddle://that is { //pvoPositionsForOutOfSample has not been set break; } default: { //it should never been reached break; } } } } #endregion newDateTimeEventHandler_openPositions #region newDateTimeEventHandler_updateStatus private void newDateTimeEventHandler_setPositionsAndStatus() { DateTime currentDateTime = this.now(); DateTime beginOfOscillatingPeriod = marketIntervalsManagerForOutOfSample.AddMarketIntervals(currentDateTime, (int)-inefficiencyLengthInMarketIntervals); DateTime endOfOscillatingPeriod = currentDateTime; this.positionsForOutOfSampleStatus = PVOPositionsStatus.InTheMiddle; for(int i = 0; i<this.chosenPVOPositions.Length; i++) { if(this.chosenPVOPositions[i] != null) try{ this.positionsForOutOfSampleStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, endOfOscillatingPeriod, this.benchmark.Ticker, this.historicalMarketValueProviderForOutOfSample, this.oversoldThresholdMAX, this.overboughtThresholdMAX); }catch(Exception ex){string str = ex.ToString();} if(this.positionsForOutOfSampleStatus == PVOPositionsStatus.Oversold || this.positionsForOutOfSampleStatus == PVOPositionsStatus.Overbought ) { this.positionsForOutOfSample = (PVOPositions)this.chosenPVOPositions[i]; this.lastInefficiencyDateTime = currentDateTime; this.positionsForOutOfSample.StatusAtLastInefficiencyTime = this.positionsForOutOfSampleStatus; this.positionsForOutOfSample.LastInefficiencyDateTime = this.lastInefficiencyDateTime; i = this.chosenPVOPositions.Length;//exit from for } } } #endregion newDateTimeEventHandler_updateStatus #region newDateTimeEventHandler_updateStopLossAndTakeProfitConditions protected virtual void newDateTimeEventHandler_updateStopLossAndTakeProfitConditions(DateTime currentDateTime) { //this.previousAccountValue has been set at opening positions if( this.account.Portfolio.Count > 0 && this.takeProfitConditionReached == false && this.stopLossConditionReached == false && this.lastProfitOrLossDateTime == new DateTime(1900,1,1,0,0,0) ) { try{ this.currentAccountValue = this.account.GetMarketValue(); double portfolioGainOrLoss = (this.currentAccountValue - this.previousAccountValue) /this.previousAccountValue; if(!double.IsInfinity(portfolioGainOrLoss) && portfolioGainOrLoss <= -this.stopLoss ) { this.stopLossConditionReached = true; this.lastProfitOrLossDateTime = currentDateTime; } else if (!double.IsInfinity(portfolioGainOrLoss) && portfolioGainOrLoss >= this.takeProfit ) { this.takeProfitConditionReached = true; this.lastProfitOrLossDateTime = currentDateTime; } } catch(Exception ex) {string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + "";} } } #endregion newDateTimeEventHandler_updateStopLossAndTakeProfitConditions private void newDateTimeEventHandler_resetForNewResearch(bool areEntryConditionsSatisfied, DateTime currentDateTime) { try{ if( currentDateTime > marketIntervalsManagerForOutOfSample.AddMarketIntervals(lastInefficiencyDateTime, (int)this.maxOpeningLengthInMarketIntervals) || areEntryConditionsSatisfied == true ) this.lastInefficiencyDateTime = new DateTime(1900,1,1,0,0,0); //it forces a new research of an inefficiency } catch(Exception ex) { string s = ex.ToString(); } } private bool areEntryConditionsSatisfied_checkCondition(DateTime currentDateTime, int conditionIndex) { bool returnValue = false; try{ if( this.entryConditions[conditionIndex].IsConditionSatisfiedByGivenPVOPositions(currentDateTime, this.positionsForOutOfSample) ) returnValue = true; } catch(Exception ex) { string s = ex.ToString(); } return returnValue; } private bool areEntryConditionsSatisfied(DateTime currentDateTime) { bool returnValue = true; if( this.allEntryConditionsHaveToBeSatisfied ) { for(int i = 0; i<this.entryConditions.Count; i++) if( ! this.areEntryConditionsSatisfied_checkCondition( currentDateTime, i ) ) { returnValue = false; i = this.entryConditions.Count;//returnValue == false -> exit } } else // !this.allEntryConditionsHaveToBeSatisfied { for(int i = 0; i<this.entryConditions.Count; i++) if( this.areEntryConditionsSatisfied_checkCondition( currentDateTime, i ) ) i = this.entryConditions.Count;//returnValue == true -> exit } return returnValue; } private bool newDateTimeEventHandler_dateTimeIsInRange(DateTime dateTime) { bool returnValue = false; try{ DateTime maxDate = this.marketIntervalsManagerForOutOfSample.AddMarketIntervals(dateTime, (int)this.maxOpeningLengthInMarketIntervals ); DateTime beginningOfPreviousEfficientPeriods = this.marketIntervalsManagerForOutOfSample.AddMarketIntervals(dateTime, -(int)inefficiencyLengthInMarketIntervals - (int)inefficiencyLengthInMarketIntervals * this.numberOfPreviousEfficientPeriods); returnValue = true; //if the two previous assignements can be done, dateTime is in range } catch{} return returnValue; } public virtual void NewDateTimeEventHandler( Object sender , DateTime dateTime ) { this.newDateTimeEventHandler_updateStopLossAndTakeProfitConditions(dateTime); this.newDateTimeEventHandler_closePositions(dateTime); if( this.account.Portfolio.Count == 0 && this.chosenPVOPositions != null && this.lastInefficiencyDateTime == new DateTime(1900,1,1,0,0,0) && this.newDateTimeEventHandler_dateTimeIsInRange(dateTime) ) //portfolio empty, optimization done, no inefficiency found (or found but not deployed), time OK this.newDateTimeEventHandler_setPositionsAndStatus(); bool areEntryConditionsSatisfied = this.areEntryConditionsSatisfied(dateTime); if( this.account.Portfolio.Count == 0 && this.lastInefficiencyDateTime != new DateTime(1900,1,1,0,0,0) && dateTime >= marketIntervalsManagerForOutOfSample.AddMarketIntervals( lastInefficiencyDateTime, (int)marketIntervalsFromLastInefficiencyTimeToWaitBeforeOpening ) && areEntryConditionsSatisfied ) this.newDateTimeEventHandler_openPositions(dateTime); this.newDateTimeEventHandler_resetForNewResearch(areEntryConditionsSatisfied, dateTime); this.newDateTimeEventHandler_updateTestingPositions( dateTime ); //one hour after market close // if( new Time(dateTime) == new Time("17:00:00") ) //it's time for new optimization, if the case // { // this.newDateTimeEventHandler_updateTestingPositions( dateTime ); // this.positionsForOutOfSample = null; // this.positionsForOutOfSampleStatus = PVOPositionsStatus.InTheMiddle; // this.lastInefficiencyDateTime = new DateTime(1900,1,1,0,0,0); // } } #region UpdateTestingPositions protected void updateTestingPositions(DateTime currentDateTime) { History history = this.benchmark.GetEndOfDayHistory( HistoricalEndOfDayTimer.GetMarketOpen( currentDateTime.AddDays( -this.inSampleDays ) ) , HistoricalEndOfDayTimer.GetMarketClose( currentDateTime ) ); EligibleTickers eligibles = this.eligiblesSelector.GetEligibleTickers(history); //To be changed how the returns manager is updated? 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 ) || ( eligibles.Count > this.minimumNumberOfEligiblesForValidOptimization && this.inSampleChooser != null ) ) { this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager); this.updateTestingPositions_updateThresholds(); this.logOptimizationInfo(eligibles); } } private bool optimalTestingPositionsAreToBeUpdated() { bool areToBeUpdated = false; if(this.inSampleChooser != null) { DateTime dateTimeForNextOptimization = this.lastOptimizationDateTime.AddDays( this.numDaysBetweenEachOptimization ); areToBeUpdated = ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ( this.now() >= dateTimeForNextOptimization ) ); } return areToBeUpdated; } private void newDateTimeEventHandler_updateTestingPositions( DateTime dateTime ) { if ( this.optimalTestingPositionsAreToBeUpdated() ) { this.updateTestingPositions( dateTime ); this.lastOptimizationDateTime = this.now(); this.positionsForOutOfSample = null; this.positionsForOutOfSampleStatus = PVOPositionsStatus.InTheMiddle; this.lastInefficiencyDateTime = new DateTime(1900,1,1,0,0,0); } } #endregion UpdateTestingPositions private DateTime now() { return this.account.Timer.GetCurrentDateTime(); } 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 ) { switch ( ((PVOCorrelationChooser)this.inSampleChooser).IntervalsType ) { 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; } } this.returnsManager = new ReturnsManager( returnIntervals , this.historicalMarketValueProviderForInSample); } 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 ) { PVO_OTCLogItem logItem = new PVO_OTCLogItem( this.now() , this.inSampleDays ); logItem.BestPVOPositionsInSample = this.chosenPVOPositions; logItem.NumberOfEligibleTickers = eligibleTickers.Count; logItem.FitnessOfFirst = this.chosenPVOPositions[0].FitnessInSample; logItem.FitnessOfLast = this.getLogItem_getFitnessOfLast(); // logItem.GenerationOfFirst = // ((IGeneticallyOptimizable)this.chosenPVOPositions[0]).Generation; // logItem.GenerationOfLast = // ((IGeneticallyOptimizable)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).Generation; logItem.ThresholdsOfFirst = ((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; } private void raiseNewLogItem( EligibleTickers eligibleTickers ) { PVO_OTCLogItem logItem = this.getLogItem( eligibleTickers ); NewLogItemEventArgs newLogItemEventArgs = new NewLogItemEventArgs( logItem ); this.NewLogItem( this , newLogItemEventArgs ); } private void notifyMessage( EligibleTickers eligibleTickers ) { string message = "Number of Eligible tickers (eligible selector: " + this.eligiblesSelector.Description + "): " + eligibleTickers.Count; NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if ( this.NewMessage != null ) this.NewMessage( this , newMessageEventArgs ); } private void logOptimizationInfo( EligibleTickers eligibleTickers ) { // if(eligibleTickers.Count > 0) try{ this.raiseNewLogItem( eligibleTickers ); } catch{} this.notifyMessage( eligibleTickers ); } private void updateTestingPositions_updateThresholds() { 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; } } } } } --- NEW FILE: PVOGenericMain.cs --- /* QuantProject - Quantitative Finance Library PVOGenericMain.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.Collections.Generic; using System.IO; using QuantProject.ADT; using QuantProject.ADT.FileManaging; using QuantProject.ADT.Timing; using QuantProject.Business.DataProviders; using QuantProject.Data.DataProviders.Bars.Caching; using QuantProject.Business.Strategies; using QuantProject.Business.Financial.Accounting.AccountProviding; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; using QuantProject.Business.Timing.TimingManagement; using QuantProject.Presentation; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.Decoding; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.FitnessEvaluators; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.EntryConditions; using QuantProject.Scripts.General; using QuantProject.Scripts.General.Logging; using QuantProject.Scripts.General.Reporting; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Entry point for the PVOGenericMain. If any strategy /// parameter had to be changed, this is the place where it should /// be done /// </summary> public class PVOGenericMain : BasicScriptForBacktesting { private Benchmark benchmark; private HistoricalMarketValueProvider historicalMarketValueProviderForInSample; private HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample; private HistoricalMarketValueProvider historicalMarketValueProviderForTheBackTester; private double inefficiencyLengthInMarketIntervals; private int numberOfPreviousEfficientPeriods; private int numberOfDaysForPriceRatioAnalysis; private double numberOfStdDeviationForSignificantPriceRatioMovements; private double maxOpeningLengthInMarketIntervals; private double marketIntervalsFromLastInefficiencyToWaitBeforeOpening; private double marketIntervalsFromLastLossOrProfitToWaitBeforeClosing; private int stepInMinutesForTimer; private Timer timerForBackTester; private DateTime firstDateTime; private DateTime lastDateTime; private int intervalFrameInSeconds; private MarketIntervalsManager marketIntervalsManagerForOutOfSample; public PVOGenericMain() { this.inefficiencyLengthInMarketIntervals = 30; this.numberOfPreviousEfficientPeriods = 1; this.numberOfDaysForPriceRatioAnalysis = 90; this.numberOfStdDeviationForSignificantPriceRatioMovements = 0.0; this.maxOpeningLengthInMarketIntervals = 1800; this.marketIntervalsFromLastInefficiencyToWaitBeforeOpening = 1; this.marketIntervalsFromLastLossOrProfitToWaitBeforeClosing = 0; this.stepInMinutesForTimer = 1; this.intervalFrameInSeconds = 60; this.firstDateTime = new DateTime( 2006 , 1, 1 ); this.lastDateTime = new DateTime( 2006 , 12, 31 ); this.benchmark = new Benchmark( "CCE" ); this.marketIntervalsManagerForOutOfSample = new MarketMinutesManager(this.benchmark, this.firstDateTime, this.lastDateTime); // new MarketDaysManager(this.benchmark, this.firstDateTime, // this.lastDateTime, new Time("16:00:00")); this.historicalMarketValueProviderForOutOfSample = this.getHistoricalBarProvider(); // new HistoricalAdjustedQuoteProvider(); this.historicalMarketValueProviderForInSample = // this.historicalMarketValueProviderForOutOfSample; 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, this.lastDateTime , this.getDailyTimes(), this.intervalFrameInSeconds); // new IndexBasedEndOfDayTimer( this.firstDateTime, // this.lastDateTime, // this.benchmark.Ticker ); } protected override IEligiblesSelector getEligiblesSelector() { int maxNumberOfEligiblesToBeChosen = 100; // int numOfTopRowsToDeleteFromSelectorByLiquidity = 0; string tickersGroupId = "SP500"; bool temporizedGroup = true; int numDaysForAverageRawOpenPriceComputation = 10; double minPrice = 15; double maxPrice = 1500; // int maxNumberOfMostLiquidTickersToBeChosen = 150; // int numDaysForVolatility = 10; // int minimumNumberOfMinutelyBarsForEachDayForInSample = 100; // IEligiblesSelector eligiblesSelector = // new ByPriceMostLiquidQuotedAtEachDateTime( // tickersGroupId , temporizedGroup , // maxNumberOfEligiblesToBeChosen , // numDaysForAverageRawOpenPriceComputation , // minPrice , maxPrice, intervalFrameInSeconds , // 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 , // numOfTopRowsToDeleteFromSelectorByLiquidity, // numDaysForAverageRawOpenPriceComputation , // minPrice , maxPrice, // minimumNumberOfMinutelyBarsForEachDayForInSample ); // new ByPriceLessLiquidAlwaysIntradayQuoted( // tickersGroupId , this.benchmark, temporizedGroup , // maxNumberOfEligiblesToBeChosen , // numOfTopRowsToDeleteFromSelectorByLiquidity, // numDaysForAverageRawOpenPriceComputation , // minPrice , maxPrice, // minimumNumberOfMinutelyBarsForEachDayForInSample ); 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; bool balancedWeightsOnVolatilityBase = true; float minimumAbsoluteReturnValue = 0.00005f; float maximumAbsoluteReturnValue = 100000f; // int returnIntervalLengthInMinutesForCorrelationProvider = 120; //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); IInSampleChooser inSampleChooser = new PVO_CTCCorrelationChooser(numberOfBestTestingPositionsToBeReturned, 2 , 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_03_31_0_34_14_PVOIntraday_from_2006_03_01_to_2007_03_01_annlRtrn_35.76_maxDD_2.34\2009_03_31_0_34_14_PVOIntraday_from_2006_03_01_to_2007_03_01_annlRtrn_35.76_maxDD_2.34.qpL", // numberOfBestTestingPositionsToBeReturned); return inSampleChooser; } protected override IStrategyForBacktester getStrategyForBacktester() { //int inSampleDays = 90; int inSampleDays = 180; int numDaysBetweenEachOptimization = 10; int minNumOfEligiblesForValidOptimization = 20; double oversoldThreshold = 0.008;//0.006 double overboughtThreshold = 0.008;//0.006 double oversoldThresholdMAX = 0.03; double overboughtThresholdMAX = 0.03; double stopLoss = 0.005; double takeProfit = 0.005; double leverage = 1.0; bool openOnlyLongPositions = false; List<IEntryCondition> entryConditions = new List<IEntryCondition>(); IEntryCondition previousPeriodEfficientEntryCondition = // new AlwaysTrueEntryCondition(); // new PriceRatioEntryCondition(45, this.historicalQuoteProvider, 1.0); new PreviousPeriodsWereEfficientEntryCondition(this.numberOfPreviousEfficientPeriods, this.historicalMarketValueProviderForOutOfSample, this.inefficiencyLengthInMarketIntervals, this.marketIntervalsManagerForOutOfSample); IEntryCondition priceRatioEntryCondition = new PriceRatioEntryCondition(this.numberOfDaysForPriceRatioAnalysis, this.historicalMarketValueProviderForOutOfSample, 1.5); IEntryCondition inefficiencyMovingBackEntryCondition = new InefficiencyMovingBackEntryCondition(0.2, this.historicalMarketValueProviderForOutOfSample, this.benchmark); // entryConditions.Add(previousPeriodEfficientEntryCondition); // entryConditions.Add(priceRatioEntryCondition); entryConditions.Add(inefficiencyMovingBackEntryCondition); bool allEntryConditionsHaveToBeTrue = true; IStrategyForBacktester strategyForBacktester // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , // inSampleDays , benchmark , numDaysBetweenEachOptimization , // oversoldThreshold , overboughtThreshold , historicalQuoteProvider); // = new PVOGenericStrategy(eligiblesSelector , minNumOfEligiblesForValidOptimization, inSampleChooser , inSampleDays , benchmark , numDaysBetweenEachOptimization , oversoldThreshold , overboughtThreshold , oversoldThresholdMAX , overboughtThresholdMAX , historicalMarketValueProviderForInSample, historicalMarketValueProviderForOutOfSample, inefficiencyLengthInMarketIntervals , numberOfPreviousEfficientPeriods, numberOfDaysForPriceRatioAnalysis, numberOfStdDeviationForSignificantPriceRatioMovements, marketIntervalsFromLastInefficiencyToWaitBeforeOpening, marketIntervalsFromLastLossOrProfitToWaitBeforeClosing, maxOpeningLengthInMarketIntervals, this.getDailyTimes(), stopLoss , takeProfit , leverage, openOnlyLongPositions, entryConditions, allEntryConditionsHaveToBeTrue, this.marketIntervalsManagerForOutOfSample); return strategyForBacktester; } #region getHistoricalBarProvider #region getBarCache private List<Time> getDailyTimes() { return Time.GetIntermediateTimes(new Time("09:45:00"), new Time("16:00:00"), this.stepInMinutesForTimer); } private IBarCache getBarCache() { List<Time> dailyTimes = this.getDailyTimes(); IBarCache barCache = new DailyBarCache( this.intervalFrameInSeconds , dailyTimes ); return barCache; } #endregion getBarCache private HistoricalMarketValueProvider getHistoricalBarProvider() { IBarCache barCache = getBarCache(); HistoricalMarketValueProviderWithQuoteBackupOnClose historicalBarProvider; HistoricalAdjustedQuoteProvider histAdjQuoteProvider = new HistoricalAdjustedQuoteProvider(); HistoricalAdjustedBarProvider historicalAdjustedBarProvider = new HistoricalAdjustedBarProvider( new HistoricalBarProvider( barCache ), new HistoricalRawQuoteProvider(), histAdjQuoteProvider ); historicalBarProvider = new HistoricalMarketValueProviderWithQuoteBackupOnClose(historicalAdjustedBarProvider, histAdjQuoteProvider); return historicalBarProvider; } #endregion getHistoricalBarProvider protected override EndOfDayStrategyBackTester getEndOfDayStrategyBackTester() { string backTestId = "PVOGeneric"; IAccountProvider accountProvider; accountProvider = // new InteractiveBrokerAccountProvider(); new SimpleAccountProvider(); double cashToStart = 25000; double maxRunningHours = 24; EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( backTestId , this.timerForBackTester, this.strategyForBacktester , this.historicalMarketValueProviderForTheBackTester , accountProvider , firstDateTime , lastDateTime , this.benchmark , cashToStart , maxRunningHours ); return endOfDayStrategyBackTester; } protected override string getCustomSmallTextForFolderName() { return "PVOGeneric"; } protected override string getPathForTheMainFolderWhereScriptsResultsAreToBeSaved() { string pathForTheMainFolderWhereScriptsResultsAreToBeSaved = System.Configuration.ConfigurationManager.AppSettings["LogArchive"]; return pathForTheMainFolderWhereScriptsResultsAreToBeSaved; } protected override string getFullPathFileNameForMain() { string returnValue; string fullPathFileNameForMainAtHome = @"C:\Quant\QuantProject\b7_Scripts\TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenericMain.cs"; if( File.Exists(fullPathFileNameForMainAtHome) ) returnValue = fullPathFileNameForMainAtHome; else returnValue = @"C:\Utente\MarcoVarie\Vari\qP\QuantProject\b7_Scripts\TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenericMain.cs"; return returnValue; } } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 21:00:50
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PriceRatioChooser In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv23511/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PriceRatioChooser Added Files: PriceRatio.cs Log Message: Added PriceRatio, a struct used for the storage of price ratio info between two tickers --- NEW FILE: PriceRatio.cs --- /* QuantProject - Quantitative Finance Library PriceRatio.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.Timing; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers.PriceRatioChooser { /// <summary> /// Struct used for the storage of price ratio info /// </summary> [Serializable] public struct PriceRatio : IComparable { private string firstTicker; public string FirstTicker { get { return this.firstTicker; } } private string secondTicker; public string SecondTicker { get { return this.secondTicker; } } private double average; public double Average { get { return this.average; } set { this.average = value; } } private double absoluteStandardDeviation; public double AbsoluteStandardDeviation { get { return this.absoluteStandardDeviation; } set { this.absoluteStandardDeviation = value; } } public double RelativeStandardDeviation { get { return this.AbsoluteStandardDeviation / this.Average; } } public PriceRatio( string firstTicker, string secondTicker, double average, double absoluteStandardDeviation) { this.firstTicker = firstTicker; this.secondTicker = secondTicker; this.average = average; this.absoluteStandardDeviation = absoluteStandardDeviation; } public int CompareTo(object priceRatioToBeCompared) { int returnValue = 1; PriceRatio toBeCompared = (PriceRatio)priceRatioToBeCompared; if( this.RelativeStandardDeviation < toBeCompared.RelativeStandardDeviation) returnValue = - 1; else if (this.RelativeStandardDeviation == toBeCompared.RelativeStandardDeviation) returnValue = 0; // else if (this.RelativeStandardDeviation > toBeCompared.RelativeStandardDeviation) // returnValue = 1; return returnValue; } } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 20:59:03
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/TickersRelationships In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv23169/b4_Business/a2_Strategies/TickersRelationships Added Files: PriceRatioProvider.cs Log Message: Added PriceRatioProvider, a class that provides static methods concerning the price ratios between tickers --- NEW FILE: PriceRatioProvider.cs --- /* QuantProject - Quantitative Finance Library PriceRatioProvider.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT.Histories; using QuantProject.ADT.Timing; using QuantProject.Data.DataProviders.Quotes; using QuantProject.ADT.Statistics; using QuantProject.Business.DataProviders; namespace QuantProject.Business.Strategies.TickersRelationships { /// <summary> /// Class that provides methods concerning /// the price ratios between tickers /// </summary> [Serializable] public class PriceRatioProvider { private static string firstTicker; private static string secondTicker; private static DateTime startDateTime; private static DateTime endDateTime; private static double[] firstTickerPrices; private static double[] secondTickerPrices; private static double[] pricesRatios; private static double priceRatioAverage; private static double priceRatioStandardDeviation; // private string[] tickers; // private int numOfCombinationTwoByTwo; // private DateTime firstDateTime; // private DateTime lastDateTime; private static void getPriceRatioAverage_setPriceRatioAverage(string firstTicker, string secondTicker, DateTime startDateTime, DateTime lastDateTime) { setPricesAndPricesRatios( firstTicker, secondTicker, startDateTime, lastDateTime ); priceRatioAverage = BasicFunctions.SimpleAverage(pricesRatios); } /// <summary> /// the price ratio is computed by the following formula: /// firstTickerPrice / secondTickerPrice /// </summary> public static double GetPriceRatioAverage( string firstTicker, string secondTicker, DateTime startDateTime, DateTime lastDateTime ) { getPriceRatioAverage_setPriceRatioAverage(firstTicker, secondTicker, startDateTime, lastDateTime); return priceRatioAverage; } private static void getPriceRatioStandardDeviation_setPriceRatioStandardDeviation(string firstTicker, string secondTicker, DateTime startDateTime, DateTime lastDateTime) { setPricesAndPricesRatios( firstTicker, secondTicker, startDateTime, lastDateTime ); priceRatioStandardDeviation = BasicFunctions.StdDev(pricesRatios); } /// <summary> /// the price ratio is computed by the following formula: /// firstTickerPrice / secondTickerPrice /// </summary> public static double GetPriceRatioStandardDeviation( string firstTicker, string secondTicker, DateTime startDateTime, DateTime lastDateTime ) { getPriceRatioStandardDeviation_setPriceRatioStandardDeviation(firstTicker, secondTicker, startDateTime, lastDateTime); return priceRatioStandardDeviation; } /// <summary> /// Creates the Price Ratio provider /// </summary> public PriceRatioProvider( // string[] tickersToAnalyze, // DateTime startDate, DateTime endDate ) { // this.tickers = tickersToAnalyze; // int n = this.tickers.Length; // //combinations without repetitions: // //n_fatt /( k_fatt * (n-k)_fatt ): when k = 2, // // it can be reduced to this simple formula: // this.numOfCombinationTwoByTwo = n * (n - 1) / 2; } #region setPricesAndPricesRatios private static void setPricesAndPricesRatios_set_setAdjustedCloseEndOfDayPrices() { try{ History firstTickerAdjCloseHistory = HistoricalQuotesProvider.GetAdjustedCloseHistory(firstTicker, startDateTime, endDateTime); History secondTickerAdjCloseHistory = HistoricalQuotesProvider.GetAdjustedCloseHistory(secondTicker, startDateTime, endDateTime); History secondTickerAdjCloseHistoryWithDatesCommonToFirst = secondTickerAdjCloseHistory.Select(firstTickerAdjCloseHistory); firstTickerPrices = new double[firstTickerAdjCloseHistory.Count]; secondTickerPrices = new double[secondTickerAdjCloseHistoryWithDatesCommonToFirst.Count]; for(int i = 0; i < firstTickerAdjCloseHistory.Count; i++) { firstTickerPrices[i] = (double)firstTickerAdjCloseHistory[firstTickerAdjCloseHistory.GetKey(i)]; secondTickerPrices[i] = (double)secondTickerAdjCloseHistoryWithDatesCommonToFirst[secondTickerAdjCloseHistoryWithDatesCommonToFirst.GetKey(i)]; } } catch(Exception ex) { string s = ex.ToString(); } } private static void setPricesAndPricesRatios_set() { setPricesAndPricesRatios_set_setAdjustedCloseEndOfDayPrices(); if(firstTickerPrices == null || secondTickerPrices == null || firstTickerPrices.Length == 0 || secondTickerPrices.Length == 0) throw new Exception("At least a ticker has not available prices for the given period"); if(firstTickerPrices.Length != secondTickerPrices.Length) throw new Exception("Tickers have not the same number of prices"); } private static void setPricesAndPricesRatios_setStaticMembers(string firstTicker, string secondTicker, DateTime startDateTime, DateTime lastDateTime) { priceRatioAverage = double.MinValue; priceRatioStandardDeviation = double.MinValue; PriceRatioProvider.startDateTime = startDateTime; PriceRatioProvider.endDateTime = lastDateTime; PriceRatioProvider.firstTicker = firstTicker; PriceRatioProvider.secondTicker = secondTicker; } private static void setPricesAndPricesRatios(string firstTicker, string secondTicker, DateTime startDateTime, DateTime lastDateTime) { if( firstTicker != PriceRatioProvider.firstTicker || secondTicker != PriceRatioProvider.secondTicker || startDateTime != PriceRatioProvider.startDateTime || lastDateTime != PriceRatioProvider.endDateTime ) { setPricesAndPricesRatios_setStaticMembers(firstTicker, secondTicker, startDateTime, lastDateTime); setPricesAndPricesRatios_set(); pricesRatios = new double[firstTickerPrices.Length]; for( int i = 0; i < pricesRatios.Length; i++ ) pricesRatios[i] = firstTickerPrices[i] / secondTickerPrices[i]; } } #endregion setPricesAndPricesRatios } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 20:56:38
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/Commissions In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22782/b4_Business/a1_Financial/a2_Accounting/Commissions Added Files: FixedCommission.cs FixedCommissionManager.cs Log Message: Added FixedCommission and FixedCommissionManager, for management of fixed commissions --- NEW FILE: FixedCommission.cs --- /* QuantProject - Quantitative Finance Library FixedCommission.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Business.Financial.Accounting.Commissions { /// <summary> /// Fixed commission. /// </summary> [Serializable] public class FixedCommission : Commission { double fixedCommission; public override double Value { get { double returnValue; if ( ( this.transaction.Type == TransactionType.AddCash ) || ( this.transaction.Type == TransactionType.Withdraw ) ) returnValue = 0.0; else returnValue = this.fixedCommission; return returnValue; } } public FixedCommission( Transaction transaction, double fixedCommission ) : base( transaction ) { this.fixedCommission = fixedCommission; } } } --- NEW FILE: FixedCommissionManager.cs --- /* QuantProject - Quantitative Finance Library FixedCommissionManager.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Business.Financial.Accounting.Commissions { /// <summary> /// Commission Manager for fixed value commissions. /// </summary> [Serializable] public class FixedCommissionManager : ICommissionManager { double fixedCommission; public FixedCommissionManager(double fixedCommission) { this.fixedCommission = fixedCommission; } public Commission GetCommission( Transaction transaction ) { return new FixedCommission( transaction, this.fixedCommission ); } } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 20:55:32
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22651/b4_Business/a2_Strategies/Eligibles Added Files: ByPriceLessLiquidAlwaysIntradayQuoted.cs Log Message: Added new eligiblesSelector ByPriceLessLiquidAlwaysIntradayQuoted --- NEW FILE: ByPriceLessLiquidAlwaysIntradayQuoted.cs --- /* QuantProject - Quantitative Finance Library ByPriceLessLiquidAlwaysIntradayQuoted.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using QuantProject.ADT.Histories; using QuantProject.ADT.Messaging; using QuantProject.Data.Selectors; namespace QuantProject.Business.Strategies.Eligibles { /// <summary> /// Implements IEligiblesSelector for selecting a given max number of tickers through /// the following step-by-step selecting process: /// -step 1: all tickers belonging to a given group /// are selected (the group can be "temporized": that is tickers /// are returned depending on the time the selection is requested: /// the group SP 500 should be like that); /// -step 2: from tickers selected by step 1, the less liquid /// are selected (not more than a given max number); /// -step 3: from tickers selected by step 2, the ones that are /// always intraday quoted (the ones that have at least /// the given number of 60seconds-bars for each market day) are selected /// (not more than a given max number); /// </summary> [Serializable] public class ByPriceLessLiquidAlwaysIntradayQuoted : IEligiblesSelector { public event NewMessageEventHandler NewMessage; private bool temporizedGroup; private string tickersGroupID; private Benchmark benchmark; private int maxNumberOfEligibleTickersToBeChosen; private int numberOfTopRowsToDeleteFromLiquidSelector; private int numOfDaysForAverageOpenRawPriceComputation; private double minPrice; private double maxPrice; private int minimumNumberOfBars; public string Description { get{ return "From_" + this.tickersGroupID + " (temporized: " + this.temporizedGroup.ToString() + ")\n" + "MaxNumOfEligibles_" + this.maxNumberOfEligibleTickersToBeChosen.ToString() + "\n" + "AverageRawOpenPriceRange(computed for the last " + this.numOfDaysForAverageOpenRawPriceComputation.ToString() + "):\n" + "From_" + this.minPrice + "_to_" + this.maxPrice + "\n" + "Less Liquid and Always intraday quoted at each market day (MSFT) for the in sample time frame"; } } public ByPriceLessLiquidAlwaysIntradayQuoted( string tickersGroupID , Benchmark benchmark, bool temporizedGroup, int maxNumberOfEligibleTickersToBeChosen, int numberOfTopRowsToDeleteFromLiquidSelector, int numOfDaysForAverageOpenRawPriceComputation, double minPrice, double maxPrice, int minimumNumberOfBars) { this.temporizedGroup = temporizedGroup; this.tickersGroupID = tickersGroupID; this.benchmark = benchmark; this.maxNumberOfEligibleTickersToBeChosen = maxNumberOfEligibleTickersToBeChosen; this.numberOfTopRowsToDeleteFromLiquidSelector = numberOfTopRowsToDeleteFromLiquidSelector; this.numOfDaysForAverageOpenRawPriceComputation = numOfDaysForAverageOpenRawPriceComputation; this.minPrice = minPrice; this.maxPrice = maxPrice; this.minimumNumberOfBars = minimumNumberOfBars; } private EligibleTickers getEligibleTickers_actually( History history ) { DateTime currentDate = history.LastDateTime; SelectorByGroup group; if(this.temporizedGroup) //the group is "temporized": returned set of tickers // depend on time group = new SelectorByGroup(this.tickersGroupID, currentDate); else//the group is not temporized group = new SelectorByGroup(this.tickersGroupID); DataTable tickersFromGroup = group.GetTableOfSelectedTickers(); int numOfTickersInGroupAtCurrentDate = tickersFromGroup.Rows.Count; SelectorByAverageRawOpenPrice byPrice = new SelectorByAverageRawOpenPrice(tickersFromGroup,false, currentDate.AddDays(-this.numOfDaysForAverageOpenRawPriceComputation), currentDate, numOfTickersInGroupAtCurrentDate, this.minPrice,this.maxPrice, 0.00001, double.MaxValue); DataTable dataTableByPrice = byPrice.GetTableOfSelectedTickers(); SelectorByLiquidity mostLiquidSelector = new SelectorByLiquidity( dataTableByPrice , true, history.FirstDateTime, currentDate, this.maxNumberOfEligibleTickersToBeChosen, this.numberOfTopRowsToDeleteFromLiquidSelector); DataTable dataTableMostLiquid = mostLiquidSelector.GetTableOfSelectedTickers(); // DataSet dataSet = new DataSet(); // dataSet.Tables.Add( dataTableMostLiquid ); // dataSet.WriteXml( "c:\\qpReports\\pairsTrading\\eligiblesCon_ByPriceMostLiquidAlwaysQuoted.xml" ); SelectorByIntradayQuotationAtEachMarketDay quotedAtEachMarketDayFromLastSelection = new SelectorByIntradayQuotationAtEachMarketDay( dataTableMostLiquid , history.FirstDateTime, currentDate, minimumNumberOfBars, this.maxNumberOfEligibleTickersToBeChosen, this.benchmark.Ticker); DataTable dataTableToBeReturned = quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers(); return new EligibleTickers( dataTableToBeReturned ); } private void getEligibleTickers_sendNewMessage( EligibleTickers eligibleTickers ) { string message = "Number of Eligible tickers: " + eligibleTickers.Count; NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if(this.NewMessage != null) this.NewMessage( this , newMessageEventArgs ); } /// <summary> /// Returns the eligible tickers /// </summary> /// <returns></returns> public EligibleTickers GetEligibleTickers( History history ) { EligibleTickers eligibleTickers = this.getEligibleTickers_actually( history ); this.getEligibleTickers_sendNewMessage( eligibleTickers ); return eligibleTickers; } } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 20:53:24
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/TimingManagement In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22452 Added Files: MarketMinutesManager.cs Log Message: Added MarketDaysManager inhereting by the abstract class MarketIntervalsManager --- NEW FILE: MarketMinutesManager.cs --- /* QuantProject - Quantitative Finance Library MarketMinutesManager.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using QuantProject.Data.DataTables; using QuantProject.Business.Strategies; using QuantProject.ADT; using QuantProject.ADT.Histories; namespace QuantProject.Business.Timing.TimingManagement { /// <summary> /// Class to be used for managing market date times /// provided by a given benchmark /// </summary> [Serializable] public class MarketMinutesManager : MarketIntervalsManager { /// <summary> /// Creates a MarketMinutesManager, for managing /// operations on the date times a given benchmark /// was quoted at /// </summary> /// <param name="benchmark"></param> /// <param name="firstDateTime"></param> /// <param name="lastDateTime"></param> /// <param name="intervalFrameInSeconds">Length in seconds between each Date Time</param> public MarketMinutesManager(Benchmark benchmark, DateTime firstDateTime, DateTime lastDateTime) : base(benchmark, firstDateTime, lastDateTime) { } protected override List<DateTime> getDateTimesHistory() { History history = Bars.GetMarketDateTimes(this.benchmark.Ticker, this.firstDateTime, this.lastDateTime, 60); return history.DateTimes; } } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 20:52:50
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/TimingManagement In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22405 Added Files: MarketDaysManager.cs Log Message: Added MarketDaysManager implementing MarketIntervalsManager --- NEW FILE: MarketDaysManager.cs --- /* QuantProject - Quantitative Finance Library MarketDaysManager.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using QuantProject.Data.DataTables; using QuantProject.Business.Strategies; using QuantProject.ADT; using QuantProject.ADT.Timing; using QuantProject.ADT.Histories; namespace QuantProject.Business.Timing.TimingManagement { /// <summary> /// Class to be used for managing market date times /// provided by a given benchmark /// </summary> [Serializable] public class MarketDaysManager : MarketIntervalsManager { private Time timeOfDay; /// <summary> /// Creates a MarketDayManager, for managing /// operations on the date times a given benchmark /// was quoted at /// </summary> /// <param name="benchmark"></param> /// <param name="firstDateTime"></param> /// <param name="lastDateTime"></param> public MarketDaysManager(Benchmark benchmark, DateTime firstDateTime, DateTime lastDateTime, Time timeOfDay) : base(benchmark, firstDateTime, lastDateTime) { this.timeOfDay = timeOfDay; } protected override List<DateTime> getDateTimesHistory() { History history = Quotes.GetMarketDays(this.benchmark.Ticker, this.firstDateTime, this.lastDateTime); for(int i = 0; i < history.Count; i++) history.SetByIndex(i, Time.GetDateTimeFromMerge((DateTime)history.GetByIndex(i), this.timeOfDay)); return history.DateTimes; } } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 20:51:15
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/TimingManagement In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22219 Added Files: MarketIntervalsManager.cs Log Message: Added MarketIntervalsManager, an abstract class to be used for managing market intervals provided by a given benchmark --- NEW FILE: MarketIntervalsManager.cs --- /* QuantProject - Quantitative Finance Library MarketIntervalsManager.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using QuantProject.Data.DataTables; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.ADT; using QuantProject.ADT.Histories; namespace QuantProject.Business.Timing.TimingManagement { /// <summary> /// Class to be used for managing market intervals /// provided by a given benchmark /// </summary> [Serializable] public abstract class MarketIntervalsManager { protected Benchmark benchmark; protected List<DateTime> marketDateTimesForBenchmark; protected DateTime firstDateTime; protected DateTime lastDateTime; public Benchmark Benchmark { get { return this.benchmark; } } /// <summary> /// Creates a MarketIntervalsManager, for managing /// operations on the date times a given benchmark /// was quoted at /// </summary> /// <param name="benchmark"></param> /// <param name="firstDateTime"></param> /// <param name="lastDateTime"></param> public MarketIntervalsManager(Benchmark benchmark, DateTime firstDateTime, DateTime lastDateTime) { this.benchmark = benchmark; this.firstDateTime = firstDateTime; this.lastDateTime = lastDateTime; } protected abstract List<DateTime> getDateTimesHistory(); private int addMarketIntervals_getIndexOfStartingDateTime( DateTime startingDateTime, int marketIntervalsToAdd ) { int returnValue; if( this.marketDateTimesForBenchmark.Contains( startingDateTime ) ) returnValue = this.marketDateTimesForBenchmark.IndexOf( startingDateTime ); else throw new Exception("The benchmark '" + this.benchmark.Ticker + "' is not quoted at the given startingDateTime '" + startingDateTime.ToShortDateString() + " " + startingDateTime.ToShortTimeString() + "'!"); return returnValue; } // public ReturnIntervals GetReturnIntervals(DateTime firstDateTime, // DateTime lastDateTime, // int numberOfMarketIntervalsForEachReturnInterval) // { // if( this.marketDateTimesForBenchmark == null ) // this.marketDateTimesForBenchmark = this.getDateTimesHistory(); // ReturnIntervals returnValue = new ReturnIntervals(); // foreach(DateTime dateTime in this.marketDateTimesForBenchmark) // if(dateTime >= firstDateTime && dateTime <= lastDateTime) // returnValue.Add(dateTime, dateTime); // // return returnValue; // } public DateTime AddMarketIntervals(DateTime startingDateTime, int marketIntervalsToAdd) { if(this.marketDateTimesForBenchmark == null) this.marketDateTimesForBenchmark = this.getDateTimesHistory(); if(this.marketDateTimesForBenchmark.Count == 0) throw new Exception("The given benchmark is not quoted at no " + "date time between firstDateTime and lastDateTime"); DateTime returnValue; int indexForStartingDateTime = this.addMarketIntervals_getIndexOfStartingDateTime( startingDateTime, marketIntervalsToAdd ); int indexOfReturnValue = indexForStartingDateTime + marketIntervalsToAdd; if ( indexOfReturnValue < 0 || indexOfReturnValue >= this.marketDateTimesForBenchmark.Count ) throw new OutOfRangeException("parameter marketPeriodsToAdd", -indexForStartingDateTime, this.marketDateTimesForBenchmark.Count - marketIntervalsToAdd - 1); else returnValue = this.marketDateTimesForBenchmark[ indexOfReturnValue ]; return returnValue; } } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 20:48:32
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/TimingManagement In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv21913/TimingManagement Log Message: Directory /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/TimingManagement added to the repository |
|
From: Marco M. <mi...@us...> - 2009-08-31 20:40:42
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/OTC/InSampleChoosers/BruteForce In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20871/InSampleChoosers/BruteForce Added Files: OTCEndOfDayBruteForceChooser.cs OTCEndOfDayBruteForceOptimizableParametersManager.cs OTCOnlyLongEndOfDayBruteForceOptimizableParametersManager.cs OTCOnlyShortEndOfDayBruteForceOptimizableParametersManager.cs Log Message: Added script files for the implementation of the OTC strategy --- NEW FILE: OTCEndOfDayBruteForceOptimizableParametersManager.cs --- /* QuantProject - Quantitative Finance Library OTCEndOfDayBruteForceOptimizableParametersManager.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.ADT.Statistics.Combinatorial; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.BruteForce; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.OTC.InSampleChoosers.BruteForce { /// <summary> /// BruteForceOptimizableParametersManager to be used by the OTC intraday strategy. /// </summary> [Serializable] public class OTCEndOfDayBruteForceOptimizableParametersManager : CombinationBasedBruteForceOptimizableParametersManager { private EligibleTickers eligibleTickers; private int numberOfPositions; private IDecoderForTestingPositions decoderForTestingPositions; private IFitnessEvaluator fitnessEvaluator; private ReturnsManager returnsManager; public OTCEndOfDayBruteForceOptimizableParametersManager( EligibleTickers eligibleTickers , int numberOfPositions , IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , ReturnsManager returnsManager ) : base( new Combination( - eligibleTickers.Count , eligibleTickers.Count - 1 , numberOfPositions ) ) { this.eligibleTickers = eligibleTickers; this.numberOfPositions = numberOfPositions; this.decoderForTestingPositions = decoderForTestingPositions; this.fitnessEvaluator = fitnessEvaluator; this.returnsManager = returnsManager; } public override object Decode( BruteForceOptimizableParameters bruteForceOptimizableParameters ) { return this.decoderForTestingPositions.Decode( bruteForceOptimizableParameters.GetValues() , this.eligibleTickers , this.returnsManager ); } public override double GetFitnessValue( BruteForceOptimizableParameters bruteForceOptimizableParameters ) { object meaning = this.Decode( bruteForceOptimizableParameters ); double fitnessValue = this.fitnessEvaluator.GetFitnessValue( meaning , this.returnsManager ); return fitnessValue; } #region AreEquivalentAsTopBestParameters private void areEquivalentAsTopBestParameters_checkParameters( BruteForceOptimizableParameters bruteForceOptimizableParameters1 , BruteForceOptimizableParameters bruteForceOptimizableParameters2 ) { if ( !(bruteForceOptimizableParameters1.Meaning is TestingPositions) ) throw new Exception( "The first parameter is expected " + "to represent a TestingPositions!" ); if ( !(bruteForceOptimizableParameters2.Meaning is TestingPositions) ) throw new Exception( "The second parameter is expected " + "to represent a TestingPositions!" ); } public override bool AreEquivalentAsTopBestParameters( BruteForceOptimizableParameters bruteForceOptimizableParameters1 , BruteForceOptimizableParameters bruteForceOptimizableParameters2 ) { this.areEquivalentAsTopBestParameters_checkParameters( bruteForceOptimizableParameters1 , bruteForceOptimizableParameters2 ); bool areEquivalentAsTopBestParameters = ((TestingPositions)bruteForceOptimizableParameters1.Meaning ).HashCode == ((TestingPositions)bruteForceOptimizableParameters2.Meaning ).HashCode; return areEquivalentAsTopBestParameters; } #endregion AreEquivalentAsTopBestParameters } } --- NEW FILE: OTCEndOfDayBruteForceChooser.cs --- /* QuantProject - Quantitative Finance Library OTCEndOfDayBruteForceChooser.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.Business.Strategies; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Optimizing.GenomeManagers; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.OTC.InSampleChoosers.BruteForce { /// <summary> /// brute force IInSampleChooser with End Of Day data for the OTC strategy /// </summary> [Serializable] public class OTCEndOfDayBruteForceChooser : BruteForceChooser { private int numberOfPortfolioPositions; private PortfolioType portfolioType; public OTCEndOfDayBruteForceChooser( PortfolioType portfolioType, int numberOfPortfolioPositions , int numberOfBestTestingPositionsToBeReturned , Benchmark benchmark , IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , HistoricalMarketValueProvider historicalMarketValueProvider) : base ( numberOfBestTestingPositionsToBeReturned , decoderForTestingPositions , fitnessEvaluator ) { this.portfolioType = portfolioType; this.numberOfPortfolioPositions = numberOfPortfolioPositions; } protected override IBruteForceOptimizableParametersManager getBruteForceOptimizableParametersManager( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { IBruteForceOptimizableParametersManager parametersManager; if(this.portfolioType == PortfolioType.OnlyLong) parametersManager = new OTCOnlyLongEndOfDayBruteForceOptimizableParametersManager( eligibleTickers , this.numberOfPortfolioPositions , this.decoderForTestingPositions , this.fitnessEvaluator , returnsManager ); else if(this.portfolioType == PortfolioType.OnlyShort) parametersManager = new OTCOnlyShortEndOfDayBruteForceOptimizableParametersManager( eligibleTickers , this.numberOfPortfolioPositions , this.decoderForTestingPositions , this.fitnessEvaluator , returnsManager ); else//short and long or only mixed portfolio types parametersManager = new OTCEndOfDayBruteForceOptimizableParametersManager( eligibleTickers , this.numberOfPortfolioPositions , this.decoderForTestingPositions , this.fitnessEvaluator , returnsManager ); return parametersManager; } } } --- NEW FILE: OTCOnlyLongEndOfDayBruteForceOptimizableParametersManager.cs --- /* QuantProject - Quantitative Finance Library OTCOnlyLongEndOfDayBruteForceOptimizableParametersManager.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.ADT.Statistics.Combinatorial; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.BruteForce; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.OTC.InSampleChoosers.BruteForce { /// <summary> /// BruteForceOptimizableParametersManager to be used by the OTC intraday strategy. /// </summary> [Serializable] public class OTCOnlyLongEndOfDayBruteForceOptimizableParametersManager : CombinationBasedBruteForceOptimizableParametersManager { private EligibleTickers eligibleTickers; private int numberOfPositions; private IDecoderForTestingPositions decoderForTestingPositions; private IFitnessEvaluator fitnessEvaluator; private ReturnsManager returnsManager; public OTCOnlyLongEndOfDayBruteForceOptimizableParametersManager( EligibleTickers eligibleTickers , int numberOfPositions , IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , ReturnsManager returnsManager ) : base( new Combination( 0 , eligibleTickers.Count - 1 , numberOfPositions ) ) { this.eligibleTickers = eligibleTickers; this.numberOfPositions = numberOfPositions; this.decoderForTestingPositions = decoderForTestingPositions; this.fitnessEvaluator = fitnessEvaluator; this.returnsManager = returnsManager; } public override object Decode( BruteForceOptimizableParameters bruteForceOptimizableParameters ) { return this.decoderForTestingPositions.Decode( bruteForceOptimizableParameters.GetValues() , this.eligibleTickers , this.returnsManager ); } public override double GetFitnessValue( BruteForceOptimizableParameters bruteForceOptimizableParameters ) { object meaning = this.Decode( bruteForceOptimizableParameters ); double fitnessValue = this.fitnessEvaluator.GetFitnessValue( meaning , this.returnsManager ); return fitnessValue; } #region AreEquivalentAsTopBestParameters private void areEquivalentAsTopBestParameters_checkParameters( BruteForceOptimizableParameters bruteForceOptimizableParameters1 , BruteForceOptimizableParameters bruteForceOptimizableParameters2 ) { if ( !(bruteForceOptimizableParameters1.Meaning is TestingPositions) ) throw new Exception( "The first parameter is expected " + "to represent a TestingPositions!" ); if ( !(bruteForceOptimizableParameters2.Meaning is TestingPositions) ) throw new Exception( "The second parameter is expected " + "to represent a TestingPositions!" ); } public override bool AreEquivalentAsTopBestParameters( BruteForceOptimizableParameters bruteForceOptimizableParameters1 , BruteForceOptimizableParameters bruteForceOptimizableParameters2 ) { this.areEquivalentAsTopBestParameters_checkParameters( bruteForceOptimizableParameters1 , bruteForceOptimizableParameters2 ); bool areEquivalentAsTopBestParameters = ((TestingPositions)bruteForceOptimizableParameters1.Meaning ).HashCode == ((TestingPositions)bruteForceOptimizableParameters2.Meaning ).HashCode; return areEquivalentAsTopBestParameters; } #endregion AreEquivalentAsTopBestParameters } } --- NEW FILE: OTCOnlyShortEndOfDayBruteForceOptimizableParametersManager.cs --- /* QuantProject - Quantitative Finance Library OTCOnlyShortEndOfDayBruteForceOptimizableParametersManager.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.ADT.Statistics.Combinatorial; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.BruteForce; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.OTC.InSampleChoosers.BruteForce { /// <summary> /// BruteForceOptimizableParametersManager to be used by the OTC intraday strategy. /// </summary> [Serializable] public class OTCOnlyShortEndOfDayBruteForceOptimizableParametersManager : CombinationBasedBruteForceOptimizableParametersManager { private EligibleTickers eligibleTickers; private int numberOfPositions; private IDecoderForTestingPositions decoderForTestingPositions; private IFitnessEvaluator fitnessEvaluator; private ReturnsManager returnsManager; public OTCOnlyShortEndOfDayBruteForceOptimizableParametersManager( EligibleTickers eligibleTickers , int numberOfPositions , IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , ReturnsManager returnsManager ) : base( new Combination( - eligibleTickers.Count, - 1 , numberOfPositions ) ) { this.eligibleTickers = eligibleTickers; this.numberOfPositions = numberOfPositions; this.decoderForTestingPositions = decoderForTestingPositions; this.fitnessEvaluator = fitnessEvaluator; this.returnsManager = returnsManager; } public override object Decode( BruteForceOptimizableParameters bruteForceOptimizableParameters ) { return this.decoderForTestingPositions.Decode( bruteForceOptimizableParameters.GetValues() , this.eligibleTickers , this.returnsManager ); } public override double GetFitnessValue( BruteForceOptimizableParameters bruteForceOptimizableParameters ) { object meaning = this.Decode( bruteForceOptimizableParameters ); double fitnessValue = this.fitnessEvaluator.GetFitnessValue( meaning , this.returnsManager ); return fitnessValue; } #region AreEquivalentAsTopBestParameters private void areEquivalentAsTopBestParameters_checkParameters( BruteForceOptimizableParameters bruteForceOptimizableParameters1 , BruteForceOptimizableParameters bruteForceOptimizableParameters2 ) { if ( !(bruteForceOptimizableParameters1.Meaning is TestingPositions) ) throw new Exception( "The first parameter is expected " + "to represent a TestingPositions!" ); if ( !(bruteForceOptimizableParameters2.Meaning is TestingPositions) ) throw new Exception( "The second parameter is expected " + "to represent a TestingPositions!" ); } public override bool AreEquivalentAsTopBestParameters( BruteForceOptimizableParameters bruteForceOptimizableParameters1 , BruteForceOptimizableParameters bruteForceOptimizableParameters2 ) { this.areEquivalentAsTopBestParameters_checkParameters( bruteForceOptimizableParameters1 , bruteForceOptimizableParameters2 ); bool areEquivalentAsTopBestParameters = ((TestingPositions)bruteForceOptimizableParameters1.Meaning ).HashCode == ((TestingPositions)bruteForceOptimizableParameters2.Meaning ).HashCode; return areEquivalentAsTopBestParameters; } #endregion AreEquivalentAsTopBestParameters } } |
|
From: Marco M. <mi...@us...> - 2009-08-31 20:40:41
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/OTC In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20871 Added Files: OTCPositions.cs Log Message: Added script files for the implementation of the OTC strategy --- NEW FILE: OTCPositions.cs --- /* QuantProject - Quantitative Finance Library OTCPositions.cs Copyright (C) 2009 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Timing; using QuantProject.Business.DataProviders; namespace QuantProject.Scripts.TickerSelectionTesting.OTC { /// <summary> /// This is the class representing a TestingPositions for the /// Open To Close strategy /// </summary> [Serializable] public class OTCPositions : TestingPositions, IGeneticallyOptimizable { private int generation; //explicit interface implementation //the property can be used only by a interface //instance or through a cast to the interface int IGeneticallyOptimizable.Generation { get{return this.generation;} set{this.generation = value;} } public OTCPositions Copy() { return new OTCPositions( this.WeightedPositions, this.generation ); } // creates an empty TestingPositions: to be used to give a meaning with // OTCPositions type to undecodables public OTCPositions() : base() { } public OTCPositions(WeightedPositions weightedPositions, int generation) : base(weightedPositions) { this.generation = generation; } public OTCPositions(WeightedPositions weightedPositions) : base(weightedPositions) { this.generation = -1; } } } |