[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample PairsTr
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-04-20 17:12:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv11076/b7_Scripts/WalkForwardTesting/PairsTrading/InSample Modified Files: PairsTradingFitnessEvaluator.cs Log Message: - fitness for meaningless candidates is now set to -1000d (it was set to -0.4 in the previous revision) - now the multipliers for the PearsonCorrelationCoefficient are either +1 or -1; in the previous revision, the positions' weights were used, instead Index: PairsTradingFitnessEvaluator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/PairsTradingFitnessEvaluator.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PairsTradingFitnessEvaluator.cs 13 Mar 2008 19:38:42 -0000 1.2 --- PairsTradingFitnessEvaluator.cs 20 Apr 2008 17:12:35 -0000 1.3 *************** *** 38,41 **** --- 38,43 ---- public class PairsTradingFitnessEvaluator : IFitnessEvaluator { + private const double fitnessForInvalidCandidate = -1000d; + private double maxCorrelationAllowed; *************** *** 67,70 **** --- 69,85 ---- "two positions!" ); } + /// <summary> + /// returns 1 if the weightedPosition is long, -1 if it is short. This + /// is used to compute the PearsonCorrelationCoefficient considering the + /// proper sign for returns + /// </summary> + /// <param name="weightedPosition"></param> + private double getMultiplierForReturns( WeightedPosition weightedPosition ) + { + double multiplierForReturns = 1; + if ( weightedPosition.IsShort ) + multiplierForReturns = -1; + return multiplierForReturns; + } private double getFitnessValue( WeightedPosition firstPosition , WeightedPosition secondPosition , *************** *** 76,81 **** returnsManager.GetReturns( secondPosition.Ticker ); double fitnessValue = BasicFunctions.PearsonCorrelationCoefficient( ! firstPosition.Weight , firstPositionReturns , ! secondPosition.Weight , secondPositionReturns ); return fitnessValue; } --- 91,98 ---- returnsManager.GetReturns( secondPosition.Ticker ); double fitnessValue = BasicFunctions.PearsonCorrelationCoefficient( ! this.getMultiplierForReturns( firstPosition ) , firstPositionReturns , ! this.getMultiplierForReturns( secondPosition ) , secondPositionReturns ); ! // double fitnessValue = BasicFunctions.PearsonCorrelationCoefficient( ! // firstPositionReturns , secondPositionReturns ); return fitnessValue; } *************** *** 99,103 **** // the current optimization's candidate contains // two genes that decode to the same tickers ! fitnessValue = -0.4; else // for the current optimization's candidate, --- 116,120 ---- // the current optimization's candidate contains // two genes that decode to the same tickers ! fitnessValue = fitnessForInvalidCandidate; else // for the current optimization's candidate, *************** *** 108,112 **** // the two positions are too correlated. They may represent // the same instrument ! fitnessValue = -0.4; } return fitnessValue; --- 125,129 ---- // the two positions are too correlated. They may represent // the same instrument ! fitnessValue = fitnessForInvalidCandidate; } return fitnessValue; |