[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging PairsTra
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-03-06 20:18:46
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3774/b7_Scripts/WalkForwardTesting/PairsTrading/Logging Modified Files: PairsTradingLogItem.cs Log Message: The Run method has been completely implemented, now Index: PairsTradingLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging/PairsTradingLogItem.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PairsTradingLogItem.cs 27 Feb 2008 21:16:53 -0000 1.1 --- PairsTradingLogItem.cs 6 Mar 2008 20:18:40 -0000 1.2 *************** *** 22,27 **** --- 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; *************** *** 31,34 **** --- 33,37 ---- using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; + using QuantProject.Presentation.Reporting.WindowsForm; using QuantProject.Scripts.General.Reporting; *************** *** 75,116 **** this.numberOfEligibleTickers = numberOfEligibleTickers; } public override void Run() { ! // string backTestId = "SimpleFLTP"; // double cashToStart = 30000; ! // ! // Benchmark benchmark = new Benchmark( "MSFT" ); ! // ! // IHistoricalQuoteProvider historicalQuoteProvider = ! // new HistoricalAdjustedQuoteProvider(); ! // // IInSampleChooser inSampleChooser = ! // (IInSampleChooser)new ConstantWeightedPositionsChooser( this.BestWeightedPositionsInSample ); ! // ! // IIntervalsSelector intervalsSelector = ! // new FixedLengthTwoPhasesIntervalsSelector( ! // 1 , 1 , benchmark ); ! // IEligiblesSelector eligiblesSelector = new DummyEligibleSelector(); ! // ! // FixedLengthTwoPhasesStrategy fixedLengthTwoPhasesStrategy = ! // new FixedLengthTwoPhasesStrategy( ! // this.BestWeightedPositionsInSample.Count , ! // 9999 , 9 , benchmark , intervalsSelector , ! // eligiblesSelector , inSampleChooser , historicalQuoteProvider ); ! // ! // DateTime firstDateTime = this.simulatedCreationTime.DateTime.AddDays( -90 ); ! // DateTime lastDateTime = this.simulatedCreationTime.DateTime; ! // double maxRunningHours = 0.3; ! // EndOfDayStrategyBackTester endOfDayStrategyBackTester = ! // new EndOfDayStrategyBackTester( ! // backTestId , fixedLengthTwoPhasesStrategy , ! // historicalQuoteProvider , firstDateTime , ! // lastDateTime , benchmark , cashToStart , maxRunningHours ); ! // ! // fixedLengthTwoPhasesStrategy.Account = endOfDayStrategyBackTester.Account; ! // ! // endOfDayStrategyBackTester.Run(); ! // BackTesterReportViewer.ShowReport( lastDateTime , ! // endOfDayStrategyBackTester ); } } --- 78,164 ---- 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(); } } |