[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging PairsTra
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-03-13 19:41:01
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17881/b7_Scripts/WalkForwardTesting/PairsTrading/Logging Modified Files: PairsTradingLogItem.cs Log Message: The Run() method has been changed, so that an ExecutablesListViewer is used, now Index: PairsTradingLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging/PairsTradingLogItem.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PairsTradingLogItem.cs 6 Mar 2008 20:18:40 -0000 1.2 --- PairsTradingLogItem.cs 13 Mar 2008 19:40:24 -0000 1.3 *************** *** 22,29 **** using System; - using System.Drawing; - using QuantProject.Business.DataProviders; - using QuantProject.Business.Financial.Accounting.Reporting; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; --- 22,26 ---- *************** *** 31,38 **** using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.OutOfSample; - using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; ! using QuantProject.Presentation.Reporting.WindowsForm; ! using QuantProject.Scripts.General.Reporting; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading --- 28,35 ---- using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Timing; ! using QuantProject.Presentation; ! //using QuantProject.Presentation.Reporting.WindowsForm; ! //using QuantProject.Scripts.General.Reporting; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading *************** *** 44,48 **** public class PairsTradingLogItem : LogItem { ! private TestingPositions[] bestTestingPositionsInSample; private int numberOfEligibleTickers; --- 41,47 ---- public class PairsTradingLogItem : LogItem { ! private TesterForPairsTradingTestingPositions[] ! testersForBestTestingPositionsInSample; ! private int numberOfInSampleDays; private int numberOfEligibleTickers; *************** *** 68,164 **** } public PairsTradingLogItem( ! EndOfDayDateTime endOfDayDateTime , TestingPositions[] bestTestingPositionsInSample , int numberOfEligibleTickers ) ! : base( endOfDayDateTime ) { this.numberOfEligibleTickers = int.MinValue; ! this.bestTestingPositionsInSample = bestTestingPositionsInSample; this.numberOfEligibleTickers = numberOfEligibleTickers; } ! private AccountReport getAccountReport( ! WeightedPositions weightedPositions , ! IIntervalsSelector intervalsSelector , ! IHistoricalQuoteProvider historicalQuoteProvider , ! Benchmark benchmark , ! double cashToStart ) { ! SimpleStrategy simpleStrategy = ! new SimpleStrategy( weightedPositions , ! intervalsSelector , historicalQuoteProvider ); ! ! DateTime firstDateTime = this.simulatedCreationTime.DateTime.AddDays( -90 ); ! DateTime lastDateTime = this.simulatedCreationTime.DateTime; ! double maxRunningHours = 0.3; ! EndOfDayStrategyBackTester endOfDayStrategyBackTester = ! new EndOfDayStrategyBackTester( ! "SinglePosition" , simpleStrategy , ! historicalQuoteProvider , firstDateTime , ! lastDateTime , benchmark , cashToStart , maxRunningHours ); ! ! simpleStrategy.Account = endOfDayStrategyBackTester.Account; ! ! endOfDayStrategyBackTester.Run(); ! return endOfDayStrategyBackTester.AccountReport; } ! private WeightedPositions getWeightedPositions( ! WeightedPosition weightedPosition ) { ! double[] weights = { 1 }; ! string[] tickers = { weightedPosition.Ticker }; ! WeightedPositions weightedPositions = ! new WeightedPositions( weights , tickers ); ! return weightedPositions; } public override void Run() { ! // string backTestId = "SimplePairsTrading"; ! // double cashToStart = 30000; ! ! Benchmark benchmark = new Benchmark( "MSFT" ); ! ! IHistoricalQuoteProvider historicalQuoteProvider = ! new HistoricalAdjustedQuoteProvider(); ! ! // IInSampleChooser inSampleChooser = ! // (IInSampleChooser)new ConstantWeightedPositionsChooser( ! // this.BestWeightedPositionsInSample ); ! ! IIntervalsSelector intervalsSelector = ! new OddIntervalsSelector( 1 , 1 , benchmark ); ! IEligiblesSelector eligiblesSelector = new DummyEligibleSelector(); ! ! WeightedPositions weightedPositions = ! this.bestTestingPositionsInSample[ 0 ].WeightedPositions; ! ! WeightedPositions firstPosition = ! this.getWeightedPositions( weightedPositions[ 0 ] ); ! WeightedPositions secondPosition = ! this.getWeightedPositions( weightedPositions[ 1 ] ); ! AccountReport accountReportForFirstPosition = ! this.getAccountReport( firstPosition , intervalsSelector , ! historicalQuoteProvider , ! benchmark , 30000 ); ! AccountReport accountReportForSecondPosition = ! this.getAccountReport( secondPosition , intervalsSelector , ! historicalQuoteProvider , ! benchmark , ! 30000 * weightedPositions[ 1 ].Weight / ! weightedPositions[ 0 ].Weight ); ! ! Report report = ! new Report( accountReportForFirstPosition , false ); ! EndOfDayDateTime lastEndOfDayDateTimeForReport = ! new EndOfDayDateTime( ! accountReportForFirstPosition.EquityLine.LastDateTime , ! EndOfDaySpecificTime.OneHourAfterMarketClose ); ! ! // report.Create( "PearsonDebug" , 1 , ! // lastEndOfDayDateTimeForReport , ! // benchmark.Ticker , false ); ! report.AddEquityLine( accountReportForSecondPosition.EquityLine , ! Color.Brown ); ! report.ShowDialog(); } } --- 67,221 ---- } + /// <summary> + /// Log item for the Pairs Trading strategy + /// </summary> + /// <param name="endOfDayDateTime"></param> + /// <param name="bestTestingPositionsInSample"></param> + /// <param name="numInSampleDays">number of days used for + /// in sample optimization</param> + /// <param name="numberOfEligibleTickers"></param> public PairsTradingLogItem( ! EndOfDayDateTime now , TestingPositions[] bestTestingPositionsInSample , + int numberOfInSampleDays , int numberOfEligibleTickers ) ! : base( now ) { this.numberOfEligibleTickers = int.MinValue; ! // this.bestTestingPositionsInSample = bestTestingPositionsInSample; ! this.numberOfInSampleDays = numberOfInSampleDays; this.numberOfEligibleTickers = numberOfEligibleTickers; + this.setTestersForPairstTradingTestingPositions( + bestTestingPositionsInSample , + now ); } ! ! #region setTestersForPairstTradingTestingPositions ! private void setTestersForPairstTradingTestingPositions_checkParameters( ! TestingPositions testingPositions ) { ! if ( ! ( testingPositions is PairsTradingTestingPositions ) ) ! throw new Exception( ! "TestingPositions are all expected to be " + ! "PairsTradingTestingPositions. The current TestingPositions " + ! "is not a PairsTradingTestingPositions instead!" ); } ! private void setTesterForPairstTradingTestingPositions( ! int currentIndex , ! TestingPositions testingPositions , ! EndOfDayDateTime now ) { ! this.setTestersForPairstTradingTestingPositions_checkParameters( ! testingPositions ); ! this.testersForBestTestingPositionsInSample[ currentIndex ] = ! new TesterForPairsTradingTestingPositions( ! testingPositions , ! this.numberOfInSampleDays , ! now ); ! } ! private void setTestersForPairstTradingTestingPositions( ! TestingPositions[] bestTestingPositionsInSample , ! EndOfDayDateTime now ) ! { ! this.testersForBestTestingPositionsInSample = ! new TesterForPairsTradingTestingPositions[ ! bestTestingPositionsInSample.Length ]; ! for ( int i = 0 ; i < bestTestingPositionsInSample.Length - 1 ; i++ ) ! this.setTesterForPairstTradingTestingPositions( ! i , ! bestTestingPositionsInSample[ i ] , ! now ); } + #endregion setTestersForPairstTradingTestingPositions + // private AccountReport getAccountReport( + // WeightedPositions weightedPositions , + // IIntervalsSelector intervalsSelector , + // IHistoricalQuoteProvider historicalQuoteProvider , + // Benchmark benchmark , + // double cashToStart ) + // { + // SimpleStrategy simpleStrategy = + // new SimpleStrategy( weightedPositions , + // intervalsSelector , historicalQuoteProvider ); + // + // DateTime firstDateTime = this.simulatedCreationTime.DateTime.AddDays( -90 ); + // DateTime lastDateTime = this.simulatedCreationTime.DateTime; + // double maxRunningHours = 0.3; + // EndOfDayStrategyBackTester endOfDayStrategyBackTester = + // new EndOfDayStrategyBackTester( + // "SinglePosition" , simpleStrategy , + // historicalQuoteProvider , firstDateTime , + // lastDateTime , benchmark , cashToStart , maxRunningHours ); + // + // simpleStrategy.Account = endOfDayStrategyBackTester.Account; + // + // endOfDayStrategyBackTester.Run(); + // return endOfDayStrategyBackTester.AccountReport; + // } + // private WeightedPositions getWeightedPositions( + // WeightedPosition weightedPosition ) + // { + // double[] weights = { 1 }; + // string[] tickers = { weightedPosition.Ticker }; + // WeightedPositions weightedPositions = + // new WeightedPositions( weights , tickers ); + // return weightedPositions; + // } + // public void Run3() + // { + //// string backTestId = "SimplePairsTrading"; + //// double cashToStart = 30000; + // + // Benchmark benchmark = new Benchmark( "MSFT" ); + // + // IHistoricalQuoteProvider historicalQuoteProvider = + // new HistoricalAdjustedQuoteProvider(); + // + //// IInSampleChooser inSampleChooser = + //// (IInSampleChooser)new ConstantWeightedPositionsChooser( + //// this.BestWeightedPositionsInSample ); + // + // IIntervalsSelector intervalsSelector = + // new OddIntervalsSelector( 1 , 1 , benchmark ); + // IEligiblesSelector eligiblesSelector = new DummyEligibleSelector(); + // + // WeightedPositions weightedPositions = + // this.bestTestingPositionsInSample[ 0 ].WeightedPositions; + // + // WeightedPositions firstPosition = + // this.getWeightedPositions( weightedPositions[ 0 ] ); + // WeightedPositions secondPosition = + // this.getWeightedPositions( weightedPositions[ 1 ] ); + // AccountReport accountReportForFirstPosition = + // this.getAccountReport( firstPosition , intervalsSelector , + // historicalQuoteProvider , + // benchmark , 30000 ); + // AccountReport accountReportForSecondPosition = + // this.getAccountReport( secondPosition , intervalsSelector , + // historicalQuoteProvider , + // benchmark , + // 30000 * weightedPositions[ 1 ].Weight / + // weightedPositions[ 0 ].Weight ); + // + // Report report = + // new Report( accountReportForFirstPosition , false ); + // EndOfDayDateTime lastEndOfDayDateTimeForReport = + // new EndOfDayDateTime( + // accountReportForFirstPosition.EquityLine.LastDateTime , + // EndOfDaySpecificTime.OneHourAfterMarketClose ); + // + //// report.Create( "PearsonDebug" , 1 , + //// lastEndOfDayDateTimeForReport , + //// benchmark.Ticker , false ); + // report.AddEquityLine( accountReportForSecondPosition.EquityLine , + // Color.Brown ); + // report.ShowDialog(); + // } public override void Run() { ! QuantProject.Presentation.ExecutablesListViewer executablesListViewer = ! new ExecutablesListViewer( ! this.testersForBestTestingPositionsInSample ); ! executablesListViewer.Show(); } } |