[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies Pairs
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-05-17 18:06:26
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv15948/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies Modified Files: PairsTradingStrategy.cs Log Message: Some old, commented out code, has been removed Index: PairsTradingStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies/PairsTradingStrategy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PairsTradingStrategy.cs 11 May 2008 16:56:43 -0000 1.3 --- PairsTradingStrategy.cs 17 May 2008 18:06:22 -0000 1.4 *************** *** 42,53 **** public class PairsTradingStrategy : SymmetricEndOfDayStrategyForBacktester { - // private WeightedPositions positionsToBeOpened; - - // private double - // minThresholdForGoingLong, - // maxThresholdForGoingLong, - // minThresholdForGoingShort, - // maxThresholdForGoingShort; - private IHistoricalQuoteProvider historicalQuoteProviderForChosingPositionsOutOfSample; --- 42,45 ---- *************** *** 74,82 **** historicalQuoteProviderForInSample ) { - // this.minThresholdForGoingLong = minThresholdForGoingLong; - // this.maxThresholdForGoingLong = maxThresholdForGoingLong; - // this.minThresholdForGoingShort = minThresholdForGoingShort; - // this.maxThresholdForGoingShort = maxThresholdForGoingShort; - this.historicalQuoteProviderForChosingPositionsOutOfSample = historicalQuoteProviderForChosingPositionsOutOfSample; --- 66,69 ---- *************** *** 113,125 **** #endregion arePositionsToBeClosed - // protected override bool marketOpenEventHandler_arePositionsToBeOpened() - // { - // return this.arePositionsToBeOpened(); - // } - // protected override bool marketCloseEventHandler_arePositionsToBeOpened() - // { - // return this.arePositionsToBeOpened(); - // } - protected override bool arePositionsToBeOpened() { --- 100,103 ---- *************** *** 130,321 **** } - // #region getPositionsToBeOpened - // #region getReturnsManagerForLastSecondPhaseInterval - // private EndOfDayDateTime - // getIntervalBeginForLastSecondPhaseInterval() - // { - // // this method will be invoked only if (this.returnIntervals.Count >= 2) - // int secondLastIntervalIndex = - // this.returnIntervals.Count - 2; - // ReturnInterval secondLastInterval = - // this.returnIntervals[ secondLastIntervalIndex ]; - // return secondLastInterval.End; - // } - // private EndOfDayDateTime - // getIntervalEndForLastSecondPhaseInterval() - // { - // return this.lastIntervalAppended().Begin; - // } - // private ReturnInterval - // getReturnIntervalForLastSecondPhaseInterval() - // { - // EndOfDayDateTime intervalBegin = - // this.getIntervalBeginForLastSecondPhaseInterval(); - // EndOfDayDateTime intervalEnd = - // this.getIntervalEndForLastSecondPhaseInterval(); - // ReturnInterval returnIntervalForLastSecondPhaseInterval = - // new ReturnInterval( intervalBegin , intervalEnd ); - // return returnIntervalForLastSecondPhaseInterval; - // } - // private ReturnIntervals - // getReturnIntervalsForLastSecondPhaseInterval() - // { - // ReturnInterval returnIntervalForLastSecondPhaseInterval = - // this.getReturnIntervalForLastSecondPhaseInterval(); - // ReturnIntervals returnIntervalsForLastSecondPhaseInterval = - // new ReturnIntervals( returnIntervalForLastSecondPhaseInterval ); - // return returnIntervalsForLastSecondPhaseInterval; - // } - // private ReturnsManager getReturnsManagerForLastSecondPhaseInterval() - // { - // ReturnIntervals returnIntervals = - // this.getReturnIntervalsForLastSecondPhaseInterval(); - //// ReturnsManager returnsManager = - //// new ReturnsManager( returnIntervals , - //// this.historicalAdjustedQuoteProvider ); - // ReturnsManager returnsManager = - // new ReturnsManager( returnIntervals , - // this.historicalQuoteProviderForChosingPositionsOutOfSample ); - // return returnsManager; - // } - // #endregion getReturnsManagerForLastSecondPhaseInterval - // private double getReturnForTheLastSecondPhaseInterval( - // ReturnsManager returnsManager , - // WeightedPositions weightedPositions ) - // { - // // returnsManager should contain a single ReturnInterval, and - // // this ReturnInterval should be the last second phase interval - // double returnForTheLastSecondPhaseInterval = - // weightedPositions.GetReturn( 0 , returnsManager ); - // return returnForTheLastSecondPhaseInterval; - // } - // - // /// <summary> - // /// Inverts one of the two positions - // /// </summary> - // /// <param name="weightedPositions"></param> - // /// <returns></returns> - // private WeightedPositions getCandidateForPortfolio( - // WeightedPositions weightedPositions ) - // { - // double[] weights = new double[ 2 ]; - // weights[ 0 ] = ((WeightedPosition)weightedPositions[ 0 ]).Weight; - // weights[ 1 ] = -((WeightedPosition)weightedPositions[ 1 ]).Weight; - // string[] tickers = new String[ 2 ]; - // tickers[ 0 ] = ((WeightedPosition)weightedPositions[ 0 ]).Ticker; - // tickers[ 1 ] = ((WeightedPosition)weightedPositions[ 1 ]).Ticker; - // WeightedPositions candidateForPortfolio = - // new WeightedPositions( weights , tickers ); - // return candidateForPortfolio; - // } - // // if the currentWeightedPositions' return satisfies the thresholds - // // then this method returns the WeightedPositions to be opened. - // // Otherwise (currentWeightedPositions' return does NOT - // // satisfy the thresholds) this method returns null - // private WeightedPositions - // getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( - // ReturnsManager returnsManager , - // WeightedPositions currentWeightedPositions ) - // { - // WeightedPositions weightedPositionsToBeOpened = null; - // try - // { - // double returnForTheLastSecondPhaseInterval = - // this.getReturnForTheLastSecondPhaseInterval( - // returnsManager , - // currentWeightedPositions ); - // if ( ( returnForTheLastSecondPhaseInterval >= - // this.minThresholdForGoingLong ) && - // ( returnForTheLastSecondPhaseInterval <= - // this.maxThresholdForGoingLong ) ) - // // it looks like there has been an inefficiency that - // // might be recovered, by going short - // weightedPositionsToBeOpened = currentWeightedPositions.Opposite; - // if ( ( -returnForTheLastSecondPhaseInterval >= - // this.minThresholdForGoingShort ) && - // ( -returnForTheLastSecondPhaseInterval <= - // this.maxThresholdForGoingShort ) ) - // // it looks like there has been an inefficiency that - // // might be recovered, by going long - // weightedPositionsToBeOpened = currentWeightedPositions; - // } - // catch( TickerNotExchangedException ex ) - // { - // string dummy = ex.Message; - // } - // return weightedPositionsToBeOpened; - // } - // private WeightedPositions - // getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( - // ReturnsManager returnsManager , - // int currentTestingPositionsIndex ) - // { - // WeightedPositions currentWeightedPositions = - // this.bestTestingPositionsInSample[ currentTestingPositionsIndex ].WeightedPositions; - // WeightedPositions candidateForPortfolio = - // this.getCandidateForPortfolio( currentWeightedPositions ); - // WeightedPositions weightedPositionsToBeOpended = - // this.getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( - // returnsManager , candidateForPortfolio ); - // return weightedPositionsToBeOpended; - // } - // protected WeightedPositions getPositionsToBeOpened( - // ReturnsManager returnsManager ) - // { - // WeightedPositions weightedPositionsToBeOpended = null; - // int currentTestingPositionsIndex = 0; - // while ( ( weightedPositionsToBeOpended == null ) - // && ( currentTestingPositionsIndex < this.bestTestingPositionsInSample.Length ) ) - // { - // weightedPositionsToBeOpended = - // this.getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( - // returnsManager , currentTestingPositionsIndex ); - // currentTestingPositionsIndex++; - // } - // return weightedPositionsToBeOpended; - // } - // private WeightedPositions - // getPositionsToBeOpened_withAtLeastASecondPhaseInterval_actually() - // { - // ReturnsManager returnsManager = - // this.getReturnsManagerForLastSecondPhaseInterval(); - // WeightedPositions weightedPositions = - // this.getPositionsToBeOpened( returnsManager ); - // return weightedPositions; - // } - // /// <summary> - // /// To be overriden if a subset of the positions has to be returned - // /// </summary> - // /// <param name="weightedPositions"></param> - // /// <returns></returns> - // protected virtual WeightedPositions selectWeightedPositions( - // WeightedPositions weightedPositions ) - // { - // return weightedPositions; - // } - // private WeightedPositions - // getPositionsToBeOpened_withAtLeastASecondPhaseInterval() - // { - // WeightedPositions weightedPositions = - // this.getPositionsToBeOpened_withAtLeastASecondPhaseInterval_actually(); - // WeightedPositions weightedPositionsToBeReturned = null; - // if ( weightedPositions != null ) - // // at least one of the BestTestingPositions shows an inefficiency - // // above the threshold - // weightedPositionsToBeReturned = - // selectWeightedPositions( weightedPositions ); - // return weightedPositionsToBeReturned; - // } - // protected override WeightedPositions getPositionsToBeOpened() - // { - // WeightedPositions weightedPositions = null; - // if ( this.returnIntervals.Count >= 2 ) - // // at least a second phase interval exists - // weightedPositions = - // this.getPositionsToBeOpened_withAtLeastASecondPhaseInterval(); - // return weightedPositions; - // } - // #endregion - protected override WeightedPositions getPositionsToBeOpened() { --- 108,111 ---- *************** *** 336,343 **** this.numDaysForInSampleOptimization , eligibleTickers.Count ); - // logItem.BestWeightedPositionsInSample = - // this.bestTestingPositionsInSample.WeightedPositions; - // logItem.NumberOfEligibleTickers = - // eligibleTickers.Count; return logItem; } --- 126,129 ---- |