[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoose
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2009-02-28 18:38:11
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22608/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers Modified Files: OutOfSampleChooserForAlreadyClosing.cs Log Message: Chooses two positions that seem to be an arbitrage opportunity. The measured inefficiency must be seen to have narrowed now, before giving the entry signal. Among the eligible couples, a couple is discarded if any of the two tickers have had a either split, or dividend, or any other event that may have caused an overnight price adjustment Index: OutOfSampleChooserForAlreadyClosing.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers/OutOfSampleChooserForAlreadyClosing.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OutOfSampleChooserForAlreadyClosing.cs 18 Feb 2009 20:05:33 -0000 1.1 --- OutOfSampleChooserForAlreadyClosing.cs 28 Feb 2009 18:38:05 -0000 1.2 *************** *** 3,7 **** OutOfSampleChooserForAlreadyClosing.cs ! Copyright (C) 2008 Glauco Siliprandi --- 3,7 ---- OutOfSampleChooserForAlreadyClosing.cs ! Copyright (C) 2009 Glauco Siliprandi *************** *** 23,28 **** --- 23,32 ---- using System; + using QuantProject.ADT.Timing; + using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.ReturnsManagement; + using QuantProject.Business.Strategies.ReturnsManagement.Time; + using QuantProject.Business.Timing; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading *************** *** 30,34 **** /// <summary> /// Chooses two positions that seem to be an arbitrage opportunity. ! /// Among the eligible couples, a couple is discard if any of the two tickers /// have had a either split, or dividend, or any other event that may /// have caused an overnight price adjustment --- 34,40 ---- /// <summary> /// Chooses two positions that seem to be an arbitrage opportunity. ! /// The measured inefficiency must be seen to have narrowed now, before ! /// giving the entry signal. ! /// Among the eligible couples, a couple is discarded if any of the two tickers /// have had a either split, or dividend, or any other event that may /// have caused an overnight price adjustment *************** *** 38,42 **** OutOfSampleChooserForSingleLongAndShort { ! private int numberOfConsecutiveMinutesToSayTheInefficiencyIsClosing; public OutOfSampleChooserForAlreadyClosing( --- 44,50 ---- OutOfSampleChooserForSingleLongAndShort { ! private IInefficiencyCorrectionDetector inefficiencyCorrectionDetector; ! ! private PriceAdjustmentDetector adjustmentDetector; public OutOfSampleChooserForAlreadyClosing( *************** *** 45,50 **** double minThresholdForGoingShort , double maxThresholdForGoingShort , ! int numberOfConsecutiveMinutesToSayTheInefficiencyIsClosing ) : base( minThresholdForGoingLong , maxThresholdForGoingLong , --- 53,59 ---- double minThresholdForGoingShort , double maxThresholdForGoingShort , ! IInefficiencyCorrectionDetector inefficiencyCorrectionDetector ) : base( + new Time( 1 , 0 , 0 ) , // dummy parameter, not used by this derived class minThresholdForGoingLong , maxThresholdForGoingLong , *************** *** 52,97 **** maxThresholdForGoingShort ) { ! this.numberOfConsecutiveMinutesToSayTheInefficiencyIsClosing = ! numberOfConsecutiveMinutesToSayTheInefficiencyIsClosing; } #region getPositionsFromCandidate ! #region hasThePriceBeenAdjustedLastNight ! private bool hasThePriceBeenAdjustedLastNight( WeightedPositions candidate ) { ! // qui!!! ! return false; } ! #endregion hasThePriceBeenAdjustedLastNight #region getWeightedPositionsFromCandidateWithoutAdjustment private WeightedPositions getWeightedPositionsFromCandidateWithoutAdjustment( ! ReturnsManager returnsManagerForLastSecondPhaseInterval , WeightedPositions candidate ) { ! // qui!!!! ! // vedi OutOfSampleChooser.getWeightedPositionsFromCandidate(), ! // testa l'inefficienza allo stesso modo, ma poi aggiungi il test ! // per vedere se c'e' l'inizio di chiusura; devi considerare ! // il passaggio dei tempi: probabilmente ti converra' modificare ! // OutOfSampleChooserForSingleLongAndShort e passargli ! // firstTimeToTestInefficiency nel costruttore per poi modificare ! // OutOfSampleChooser.GetPositionsToBeOpened() togliendo i ! // parametri firstDateTimeToTestInefficiency e dateTimeToClosePositions ! // qui!!! ! return candidate; } #endregion getWeightedPositionsFromCandidateWithoutAdjustment ! protected override WeightedPositions getWeightedPositionsFromCandidate( ReturnsManager returnsManagerForLastSecondPhaseInterval , WeightedPositions candidate ) { WeightedPositions weightedPositionsFromCandidate = null; ! if ( !this.hasThePriceBeenAdjustedLastNight( candidate ) ) weightedPositionsFromCandidate = this.getWeightedPositionsFromCandidateWithoutAdjustment( ! returnsManagerForLastSecondPhaseInterval , candidate ); return weightedPositionsFromCandidate; } --- 61,145 ---- maxThresholdForGoingShort ) { ! this.inefficiencyCorrectionDetector = inefficiencyCorrectionDetector; ! ! this.adjustmentDetector = new PriceAdjustmentDetector(); ! } ! ! protected override DateTime getFirstDateTimeToTestInefficiency(DateTime currentDateTime) ! { ! DateTime yesterdayAtCurrentTime = currentDateTime.AddDays( -1 ); ! DateTime yesterdayAtClose = HistoricalEndOfDayTimer.GetMarketClose( ! yesterdayAtCurrentTime ).AddMinutes( - 1 ); // I'm subtracting 1 minute ! // because the bar for 15.59 is there much more often ! // and I believe that bar open value to be really ! // next to the official close ! return yesterdayAtClose; } #region getPositionsFromCandidate ! #region hasThePriceBeenAdjustedWithinTheInterval ! ! // private double getAdjustedCloseToCloseReturn( string ticker , ReturnInterval returnInterval ) ! // { ! // ReturnsManager returnManager = new ReturnsManager( ! // returnIntervals , this.historicalAdjustedQuoteProvider ! // ! // } ! ! private bool doWeKnowThePriceHasNotBeenAdjustedWithinTheInterval( ! WeightedPositions candidate , ReturnInterval returnInterval ) { ! bool doWeKnowNotAdjusted = false; ! try ! { ! doWeKnowNotAdjusted = ! ( ! ( !this.adjustmentDetector.HasThePriceBeenAdjusted( ! candidate[ 0 ].Ticker , returnInterval.Begin , returnInterval.End ) ) ! && ! ( !this.adjustmentDetector.HasThePriceBeenAdjusted( ! candidate[ 1 ].Ticker , returnInterval.Begin , returnInterval.End ) ) ! ); ! } ! catch( TickerNotExchangedException tickerNotExchangedException ) ! { ! string toAvoidCompileWarning = tickerNotExchangedException.Message; ! } ! return doWeKnowNotAdjusted; } ! #endregion hasThePriceBeenAdjustedWithinTheInterval #region getWeightedPositionsFromCandidateWithoutAdjustment private WeightedPositions getWeightedPositionsFromCandidateWithoutAdjustment( ! DateTime currentDateTime , ! ReturnsManager returnsManagerToTestInefficiency , WeightedPositions candidate ) { ! WeightedPositions weightedPositions = base.getWeightedPositionsIfThereIsInefficiency( ! currentDateTime , returnsManagerToTestInefficiency , candidate ); ! if ( ( weightedPositions != null ) && ! this.inefficiencyCorrectionDetector.IsInefficiencyCorrectionHappening( ! currentDateTime , ! returnsManagerToTestInefficiency.ReturnIntervals[ 0 ] , ! weightedPositions ) ) ! // the candidate is inefficient but the gap is closing ! weightedPositions = candidate; ! return weightedPositions; } #endregion getWeightedPositionsFromCandidateWithoutAdjustment ! protected override WeightedPositions getWeightedPositionsIfThereIsInefficiency( ! DateTime currentDateTime , ReturnsManager returnsManagerForLastSecondPhaseInterval , WeightedPositions candidate ) { WeightedPositions weightedPositionsFromCandidate = null; ! if ( this.doWeKnowThePriceHasNotBeenAdjustedWithinTheInterval( ! candidate , ! returnsManagerForLastSecondPhaseInterval.ReturnIntervals[ 0 ] ) ) weightedPositionsFromCandidate = this.getWeightedPositionsFromCandidateWithoutAdjustment( ! currentDateTime , returnsManagerForLastSecondPhaseInterval , candidate ); return weightedPositionsFromCandidate; } |