[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSample
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-04-10 23:16:36
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/BruteForce In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23248/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/BruteForce Modified Files: PairsTradingBruteForceOptimizableParametersManager.cs Log Message: AreEquivalentAsTopBestParameters() now considers equivalent two TestingPositions if their fitness is very similar. Infact, if two TestingPositions (a,b) and (c,d) have the same fitness, but different tickers (a!=b), probably a and b represent the same security X (probably, X's ticker changed from a to b or viceversa and the database contains historical quotes for both a and b); in such a case (a,b) and (c,d) are equivalent and the second one is to be dropped down Index: PairsTradingBruteForceOptimizableParametersManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/BruteForce/PairsTradingBruteForceOptimizableParametersManager.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PairsTradingBruteForceOptimizableParametersManager.cs 30 Mar 2008 15:28:13 -0000 1.1 --- PairsTradingBruteForceOptimizableParametersManager.cs 10 Apr 2008 23:16:31 -0000 1.2 *************** *** 23,26 **** --- 23,27 ---- using System; + using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.BruteForce; *************** *** 60,87 **** #region AreEquivalentAsTopBestParameters private void areEquivalentAsTopBestParameters_checkParameters( ! object meaning1 , object meaning2 ) { ! if ( !(meaning1 is TestingPositions) ) throw new Exception( "The first parameter is expected " + ! "to be a TestingPositions!" ); ! if ( !(meaning2 is TestingPositions) ) throw new Exception( "The second parameter is expected " + ! "to be a TestingPositions!" ); } /// Two TestingPositions are considered equivalent as TopBestPositions /// (and only one is kept among them) iif they have the same tickers /// (consider that if two WeightedPosition are highly correlated, the ! /// two opposite WeightedPosition are highly correlated too) public override bool AreEquivalentAsTopBestParameters( ! object meaning1 , object meaning2 ) { this.areEquivalentAsTopBestParameters_checkParameters( ! meaning1 , meaning2 ); ! string hashCodeForMeaning1 = ! ((TestingPositions)meaning1).HashCodeForTickerComposition; ! string hashCodeForMeaning2 = ! ((TestingPositions)meaning2).HashCodeForTickerComposition; bool areEquivalentAsTopBestParameters = ! ( hashCodeForMeaning1 == hashCodeForMeaning2 ); return areEquivalentAsTopBestParameters; } --- 61,129 ---- #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!" ); ! } ! private bool haveTheSameTickers( ! TestingPositions testingPositions1 , ! TestingPositions testingPositions2 ) ! { ! string hashCodeForMeaning1 = ! testingPositions1.HashCodeForTickerComposition; ! string hashCodeForMeaning2 = ! testingPositions2.HashCodeForTickerComposition; ! bool areEquivalentAsTopBestParameters = ! ( hashCodeForMeaning1 == hashCodeForMeaning2 ); ! return areEquivalentAsTopBestParameters; ! } ! private bool haveTheSameFitness( ! BruteForceOptimizableParameters bruteForceOptimizableParameters1 , ! BruteForceOptimizableParameters bruteForceOptimizableParameters2 ) ! { ! double fitness1 = bruteForceOptimizableParameters1.Fitness; ! double fitness2 = bruteForceOptimizableParameters2.Fitness; ! double percDifference = Math.Abs( ! fitness1 / fitness2 - 1 ); ! bool areEquivalentAsTopBestParameters = ! ( percDifference < 0.00001 ); ! // if ( areEquivalentAsTopBestParameters ) ! // { ! // string forBreakpoint = ""; ! // forBreakpoint = forBreakpoint + "a"; ! // } ! return areEquivalentAsTopBestParameters; } /// Two TestingPositions are considered equivalent as TopBestPositions /// (and only one is kept among them) iif they have the same tickers /// (consider that if two WeightedPosition are highly correlated, the ! /// two opposite WeightedPosition are highly correlated too) or ! /// if they have the same fitness (in this second case, probably ! /// two tickers represent the same security and thus are equivalent) public override bool AreEquivalentAsTopBestParameters( ! BruteForceOptimizableParameters bruteForceOptimizableParameters1 , ! BruteForceOptimizableParameters bruteForceOptimizableParameters2 ) { this.areEquivalentAsTopBestParameters_checkParameters( ! bruteForceOptimizableParameters1 , bruteForceOptimizableParameters2 ); ! ! // if two TestingPositions (a,b) and (c,d) have the same fitness, ! // but different tickers (a!=b), probably a and b represent ! // the same security X (probably, X's ticker changed from a to b ! // or viceversa and the database contains historical quotes for ! // both a and b); in such a case (a,b) and (c,d) are equivalent ! // and the second one is to be dropped down bool areEquivalentAsTopBestParameters = ! this.haveTheSameTickers( ! ((TestingPositions)bruteForceOptimizableParameters1.Meaning ) , ! ((TestingPositions)bruteForceOptimizableParameters2.Meaning) ) || ! this.haveTheSameFitness( ! bruteForceOptimizableParameters1 , ! bruteForceOptimizableParameters2 ); return areEquivalentAsTopBestParameters; } |