[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging TesterFo
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2009-02-28 18:45:14
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv30075/b7_Scripts/WalkForwardTesting/PairsTrading/Logging Modified Files: TesterForPairsTradingTestingPositions.cs Log Message: This class has been changed to test ticker couples intraday (to be further improved) Index: TesterForPairsTradingTestingPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging/TesterForPairsTradingTestingPositions.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TesterForPairsTradingTestingPositions.cs 12 Nov 2008 20:44:38 -0000 1.6 --- TesterForPairsTradingTestingPositions.cs 28 Feb 2009 18:45:06 -0000 1.7 *************** *** 3,7 **** TesterForPairsTradingTestingPositions.cs ! Copyright (C) 2008 Glauco Siliprandi --- 3,7 ---- TesterForPairsTradingTestingPositions.cs ! Copyright (C) 2009 Glauco Siliprandi *************** *** 24,27 **** --- 24,29 ---- using System.Drawing; + using QuantProject.ADT.Histories; + using QuantProject.Data.DataProviders.Bars.Caching; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting.AccountProviding; *************** *** 33,36 **** --- 35,39 ---- using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; + using QuantProject.Presentation; using QuantProject.Presentation.Reporting.WindowsForm; using QuantProject.Scripts.General.Strategies; *************** *** 48,51 **** --- 51,56 ---- private DateTime dateTimeWhenThisObjectWasLogged; + private HistoricalMarketValueProvider historicalMarketValueProvider; + /// <summary> /// Generation when the TestingPositions object has been created *************** *** 79,84 **** this.testingPositions = (PairsTradingTestingPositions)testingPositions; this.numberOfInSampleDays = numberOfInSampleDays; ! this.dateTimeWhenThisObjectWasLogged = ! dateTimeWhenThisObjectWasLogged; } private void checkParameters( TestingPositions testingPositions ) --- 84,88 ---- this.testingPositions = (PairsTradingTestingPositions)testingPositions; this.numberOfInSampleDays = numberOfInSampleDays; ! this.dateTimeWhenThisObjectWasLogged = dateTimeWhenThisObjectWasLogged; } private void checkParameters( TestingPositions testingPositions ) *************** *** 89,202 **** "PairsTradingTestingPositions!" ); } ! #region Run ! private AccountReport getAccountReport( ! WeightedPositions weightedPositions , ! IIntervalsSelector intervalsSelector , ! HistoricalMarketValueProvider historicalMarketValueProvider , ! Benchmark benchmark , ! double cashToStart ) { - SimpleStrategy simpleStrategy = - new SimpleStrategy( weightedPositions , - intervalsSelector , historicalMarketValueProvider ); - IAccountProvider accountProvider = - new SimpleAccountProvider(); - DateTime firstDateTime = ! this.dateTimeWhenThisObjectWasLogged.AddDays( ! - this.numberOfInSampleDays ); DateTime lastDateTime = ! this.dateTimeWhenThisObjectWasLogged; ! double maxRunningHours = 0.3; ! EndOfDayStrategyBackTester endOfDayStrategyBackTester = ! new EndOfDayStrategyBackTester( ! "SinglePosition" , ! new QuantProject.Business.Timing.IndexBasedEndOfDayTimer( ! HistoricalEndOfDayTimer.GetMarketOpen( firstDateTime ) , ! benchmark.Ticker ) , ! simpleStrategy , ! historicalMarketValueProvider , accountProvider , ! firstDateTime , lastDateTime , ! benchmark , cashToStart , maxRunningHours ); ! ! // simpleStrategy.Account = endOfDayStrategyBackTester.Account; ! ! endOfDayStrategyBackTester.Run(); ! return endOfDayStrategyBackTester.AccountReport; } ! private double getWeightedPositions_getWeight( ! WeightedPosition weightedPosition ) { ! double weight = 1; ! if ( weightedPosition.IsShort ) ! // the current WeightedPosition is short in the couple correlation ! weight = -1; ! return weight; } ! private WeightedPositions getWeightedPositions( ! WeightedPosition weightedPosition ) { ! // double[] weights = { 1 }; ! double[] weights = { this.getWeightedPositions_getWeight( weightedPosition ) }; ! string[] tickers = { weightedPosition.Ticker }; ! WeightedPositions weightedPositions = ! new WeightedPositions( weights , tickers ); ! return weightedPositions; } public void Run() { ! // string backTestId = "SimplePairsTrading"; ! // double cashToStart = 30000; ! ! Benchmark benchmark = new Benchmark( "MSFT" ); ! ! HistoricalMarketValueProvider historicalMarketValueProvider = ! new HistoricalAdjustedQuoteProvider(); ! ! // IInSampleChooser inSampleChooser = ! // (IInSampleChooser)new ConstantWeightedPositionsChooser( ! // this.BestWeightedPositionsInSample ); ! ! IIntervalsSelector intervalsSelector = ! new OddIntervalsSelector( 1 , 1 , benchmark ); ! IEligiblesSelector eligiblesSelector = new DummyEligibleSelector(); ! ! WeightedPositions weightedPositions = ! this.testingPositions.WeightedPositions; ! ! WeightedPositions firstPosition = ! this.getWeightedPositions( weightedPositions[ 0 ] ); ! WeightedPositions secondPosition = ! this.getWeightedPositions( weightedPositions[ 1 ] ); ! AccountReport accountReportForFirstPosition = ! this.getAccountReport( firstPosition , intervalsSelector , ! historicalMarketValueProvider , ! benchmark , 30000 ); ! AccountReport accountReportForSecondPosition = ! this.getAccountReport( secondPosition , intervalsSelector , ! historicalMarketValueProvider , ! benchmark , ! Math.Abs( 30000 * weightedPositions[ 1 ].Weight / ! weightedPositions[ 0 ].Weight ) ); ! ! Report report = ! new Report( accountReportForFirstPosition , false ); ! DateTime lastDateTimeForReport = ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! accountReportForFirstPosition.EquityLine.LastDateTime ); ! // new EndOfDayDateTime( ! // accountReportForFirstPosition.EquityLine.LastDateTime , ! // EndOfDaySpecificTime.OneHourAfterMarketClose ); ! ! // report.Create( "PearsonDebug" , 1 , ! // lastEndOfDayDateTimeForReport , ! // benchmark.Ticker , false ); ! report.AddEquityLine( accountReportForSecondPosition.EquityLine , ! Color.Brown ); ! report.ShowDialog(); } #endregion Run } } --- 93,172 ---- "PairsTradingTestingPositions!" ); } ! #region Run ! ! #region getHistory ! ! #region addItemsToHistory ! private DateTime getFirstDateTime() { DateTime firstDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( ! this.dateTimeWhenThisObjectWasLogged.AddDays( 1 ) ); ! return firstDateTime; ! } ! private DateTime getLastDateTime() ! { ! DateTime firstDateTime = this.getFirstDateTime(); DateTime lastDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( firstDateTime ); ! return lastDateTime; } ! private void addItemToHistory( ! WeightedPosition weightedPosition , DateTime dateTime , History history ) { ! try ! { ! double marketValue = this.historicalMarketValueProvider.GetMarketValue( ! weightedPosition.Ticker , dateTime ); ! history.Add( dateTime , marketValue ); ! } ! catch( TickerNotExchangedException tickerNotExchangedException ) ! { ! string toAvoidWarning = tickerNotExchangedException.Message; ! } } ! private void addItemsToHistory( WeightedPosition weightedPosition , History history ) { ! DateTime currentDateTime = this.getFirstDateTime(); ! DateTime lastDateTime = this.getLastDateTime(); ! while ( currentDateTime <= lastDateTime ) ! { ! this.addItemToHistory( weightedPosition , currentDateTime , history ); ! currentDateTime = currentDateTime.AddMinutes( 1 ); ! } ! } ! #endregion addItemsToHistory ! ! private History getHistory( WeightedPosition weightedPosition ) ! { ! History history = new History(); ! this.addItemsToHistory( weightedPosition , history ); ! return history; ! } ! #endregion getHistory ! ! private void showHistoriesPlots( ! History historyForFirstPosition , History historyForSecondPosition ) ! { ! HistoriesViewer historiesViewer = new HistoriesViewer(); ! historiesViewer.Add( historyForFirstPosition , Color.Green ); ! historiesViewer.Add( historyForSecondPosition , Color.Red ); ! historiesViewer.ShowDialog(); } + public void Run() { ! this.historicalMarketValueProvider = new HistoricalBarProvider( ! new SimpleBarCache( 60 ) ); ! History historyForFirstPosition = this.getHistory( ! this.testingPositions.WeightedPositions[ 0 ] ); ! History historyForSecondPosition = this.getHistory( ! this.testingPositions.WeightedPositions[ 1 ] ); ! this.showHistoriesPlots( historyForFirstPosition , historyForSecondPosition ); } #endregion Run + } } |