quantproject-developers Mailing List for QuantProject (Page 32)
Brought to you by:
glauco_1
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(7) |
Nov
(103) |
Dec
(67) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(52) |
Feb
(9) |
Mar
(69) |
Apr
(53) |
May
(80) |
Jun
(23) |
Jul
(24) |
Aug
(112) |
Sep
(9) |
Oct
|
Nov
(58) |
Dec
(93) |
| 2005 |
Jan
(90) |
Feb
(93) |
Mar
(61) |
Apr
(56) |
May
(37) |
Jun
(61) |
Jul
(55) |
Aug
(68) |
Sep
(25) |
Oct
(46) |
Nov
(41) |
Dec
(37) |
| 2006 |
Jan
(33) |
Feb
(7) |
Mar
(19) |
Apr
(27) |
May
(73) |
Jun
(49) |
Jul
(83) |
Aug
(66) |
Sep
(45) |
Oct
(16) |
Nov
(15) |
Dec
(7) |
| 2007 |
Jan
(14) |
Feb
(33) |
Mar
|
Apr
(21) |
May
|
Jun
(34) |
Jul
(18) |
Aug
(100) |
Sep
(39) |
Oct
(55) |
Nov
(12) |
Dec
(2) |
| 2008 |
Jan
(120) |
Feb
(133) |
Mar
(129) |
Apr
(104) |
May
(42) |
Jun
(2) |
Jul
(52) |
Aug
(99) |
Sep
(134) |
Oct
|
Nov
(137) |
Dec
(48) |
| 2009 |
Jan
(48) |
Feb
(55) |
Mar
(61) |
Apr
(3) |
May
(2) |
Jun
(1) |
Jul
|
Aug
(51) |
Sep
|
Oct
(7) |
Nov
|
Dec
|
| 2010 |
Jan
(7) |
Feb
(1) |
Mar
(145) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
| 2011 |
Jan
(78) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(88) |
Sep
(6) |
Oct
(1) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:21:51
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18913/Strategies Modified Files: PairsTradingStrategy.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: PairsTradingStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies/PairsTradingStrategy.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PairsTradingStrategy.cs 17 May 2008 18:06:22 -0000 1.4 --- PairsTradingStrategy.cs 29 Sep 2008 21:21:35 -0000 1.5 *************** *** 40,47 **** /// Pairs Trading strategy with in sample optimizations /// </summary> public class PairsTradingStrategy : SymmetricEndOfDayStrategyForBacktester { ! private IHistoricalQuoteProvider ! historicalQuoteProviderForChosingPositionsOutOfSample; private OutOfSampleChooser outOfSampleChooser; --- 40,48 ---- /// Pairs Trading strategy with in sample optimizations /// </summary> + [Serializable] public class PairsTradingStrategy : SymmetricEndOfDayStrategyForBacktester { ! private HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample; private OutOfSampleChooser outOfSampleChooser; *************** *** 53,59 **** IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , ! IHistoricalQuoteProvider historicalQuoteProviderForInSample , ! IHistoricalQuoteProvider ! historicalQuoteProviderForChosingPositionsOutOfSample , OutOfSampleChooser outOfSampleChooser ) : base( --- 54,60 ---- IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , ! HistoricalMarketValueProvider historicalMarketValueProviderForInSample , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample , OutOfSampleChooser outOfSampleChooser ) : base( *************** *** 64,71 **** eligiblesSelector , inSampleChooser , ! historicalQuoteProviderForInSample ) { ! this.historicalQuoteProviderForChosingPositionsOutOfSample = ! historicalQuoteProviderForChosingPositionsOutOfSample; this.outOfSampleChooser = outOfSampleChooser; } --- 65,72 ---- eligiblesSelector , inSampleChooser , ! historicalMarketValueProviderForInSample ) { ! this.historicalMarketValueProviderForChosingPositionsOutOfSample = ! historicalMarketValueProviderForChosingPositionsOutOfSample; this.outOfSampleChooser = outOfSampleChooser; } *************** *** 94,98 **** ReturnInterval secondLastReturnInterval = this.getSecondLastReturnInterval(); ! areToBeClosed = this.now().IsEqualTo( secondLastReturnInterval.End ); } return ( areToBeClosed ); --- 95,99 ---- ReturnInterval secondLastReturnInterval = this.getSecondLastReturnInterval(); ! areToBeClosed = ( this.now() == secondLastReturnInterval.End ); } return ( areToBeClosed ); *************** *** 103,108 **** { bool beginsTheLastInterval = ! ( this.now().IsEqualTo( ! this.lastIntervalAppended().Begin ) ); return ( beginsTheLastInterval ); } --- 104,109 ---- { bool beginsTheLastInterval = ! ( this.now() == ! this.lastIntervalAppended().Begin ); return ( beginsTheLastInterval ); } *************** *** 114,118 **** this.bestTestingPositionsInSample , this.returnIntervals , ! this.historicalQuoteProviderForChosingPositionsOutOfSample , this.inSampleReturnsManager ); return weightedPositions; --- 115,119 ---- this.bestTestingPositionsInSample , this.returnIntervals , ! this.historicalMarketValueProviderForChosingPositionsOutOfSample , this.inSampleReturnsManager ); return weightedPositions; |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:21:50
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18913 Modified Files: PairsTradingMain.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: PairsTradingMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/PairsTradingMain.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** PairsTradingMain.cs 16 Aug 2008 19:38:41 -0000 1.17 --- PairsTradingMain.cs 29 Sep 2008 21:21:34 -0000 1.18 *************** *** 53,61 **** { private Benchmark benchmark; ! private IHistoricalQuoteProvider historicalQuoteProviderForInSample; ! private IHistoricalQuoteProvider ! historicalQuoteProviderForChosingPositionsOutOfSample; ! private IHistoricalQuoteProvider ! historicalQuoteProviderForTheBacktesterAccount; --- 53,61 ---- { private Benchmark benchmark; ! private HistoricalMarketValueProvider historicalMarketValueProviderForInSample; ! private HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample; ! private HistoricalMarketValueProvider ! historicalMarketValueProviderForTheBacktesterAccount; *************** *** 64,76 **** this.benchmark = new Benchmark( "CCE" ); ! this.historicalQuoteProviderForInSample = new HistoricalRawQuoteProvider(); ! this.historicalQuoteProviderForChosingPositionsOutOfSample = new HistoricalAdjustedQuoteProvider(); // this.historicalQuoteProviderForChosingPositionsOutOfSample = // new HistoricalRawQuoteProvider(); ! this.historicalQuoteProviderForTheBacktesterAccount = new HistoricalRawQuoteProvider(); // this.historicalQuoteProviderForTheBacktesterAccount = --- 64,76 ---- this.benchmark = new Benchmark( "CCE" ); ! this.historicalMarketValueProviderForInSample = new HistoricalRawQuoteProvider(); ! this.historicalMarketValueProviderForChosingPositionsOutOfSample = new HistoricalAdjustedQuoteProvider(); // this.historicalQuoteProviderForChosingPositionsOutOfSample = // new HistoricalRawQuoteProvider(); ! this.historicalMarketValueProviderForTheBacktesterAccount = new HistoricalRawQuoteProvider(); // this.historicalQuoteProviderForTheBacktesterAccount = *************** *** 140,144 **** this.benchmark , decoderForWeightedPositions , fitnessEvaluator , ! this.historicalQuoteProviderForInSample , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , --- 140,144 ---- this.benchmark , decoderForWeightedPositions , fitnessEvaluator , ! this.historicalMarketValueProviderForInSample , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , *************** *** 163,167 **** } ! protected override IEndOfDayStrategyForBacktester getEndOfDayStrategy() { int inSampleDays = 180; --- 163,167 ---- } ! protected override IStrategyForBacktester getStrategyForBacktester() { int inSampleDays = 180; *************** *** 192,202 **** // 2 , 0.006 , 0.99 , 0.006 , 0.99 ); ! IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = new PairsTradingStrategy( 7 , inSampleDays , intervalsSelectorForInSample , intervalsSelectorForOutOfSample , eligiblesSelector , inSampleChooser , ! this.historicalQuoteProviderForInSample , ! this.historicalQuoteProviderForChosingPositionsOutOfSample , outOfSampleChooser ); // IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = --- 192,202 ---- // 2 , 0.006 , 0.99 , 0.006 , 0.99 ); ! IStrategyForBacktester strategyForBacktester = new PairsTradingStrategy( 7 , inSampleDays , intervalsSelectorForInSample , intervalsSelectorForOutOfSample , eligiblesSelector , inSampleChooser , ! this.historicalMarketValueProviderForInSample , ! this.historicalMarketValueProviderForChosingPositionsOutOfSample , outOfSampleChooser ); // IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = *************** *** 214,218 **** // this.historicalQuoteProviderForChosingPositionsOutOfSample , // 0.006 , 0.02 , 0.006 , 0.02 ); ! return endOfDayStrategyForBacktester; } protected override EndOfDayStrategyBackTester --- 214,218 ---- // this.historicalQuoteProviderForChosingPositionsOutOfSample , // 0.006 , 0.02 , 0.006 , 0.02 ); ! return strategyForBacktester; } protected override EndOfDayStrategyBackTester *************** *** 228,240 **** // uncomment the following two lines for a faster script ! // firstDateTime = new DateTime( 2007 , 1 , 1 ); ! // lastDateTime = new DateTime( 2007 , 1 , 31 ); ! double maxRunningHours = 1; EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.endOfDayStrategy , ! this.historicalQuoteProviderForTheBacktesterAccount , accountProvider , firstDateTime , lastDateTime , --- 228,240 ---- // uncomment the following two lines for a faster script ! firstDateTime = new DateTime( 2002 , 1 , 1 ); ! lastDateTime = new DateTime( 2007 , 6 , 30 ); ! double maxRunningHours = 0.05; EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.strategyForBacktester , ! this.historicalMarketValueProviderForTheBacktesterAccount , accountProvider , firstDateTime , lastDateTime , |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:21:44
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/ReportDebugger In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18875/ReportDebugger Modified Files: WFMultiOneRankDebugInSample.cs WFMultiOneRankRunInSampleDebug.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WFMultiOneRankDebugInSample.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/ReportDebugger/WFMultiOneRankDebugInSample.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFMultiOneRankDebugInSample.cs 16 Aug 2008 19:40:55 -0000 1.3 --- WFMultiOneRankDebugInSample.cs 29 Sep 2008 21:21:25 -0000 1.4 *************** *** 3,7 **** WFMultiOneRankDebugInSample.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- WFMultiOneRankDebugInSample.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 41,45 **** private string benchmark; ! private IHistoricalQuoteProvider historicalQuoteProvider; private IndexBasedEndOfDayTimer endOfDayTimer; private Account account; --- 41,45 ---- private string benchmark; ! private HistoricalMarketValueProvider historicalMarketValueProvider; private IndexBasedEndOfDayTimer endOfDayTimer; private Account account; *************** *** 48,53 **** public WFMultiOneRankDebugInSample( string[] signedTickers , ! DateTime firstDateTime , DateTime lastDateTime , ! string benchmark ) { this.signedTickers = signedTickers; --- 48,53 ---- public WFMultiOneRankDebugInSample( string[] signedTickers , ! DateTime firstDateTime , DateTime lastDateTime , ! string benchmark ) { this.signedTickers = signedTickers; *************** *** 59,63 **** // this.startDateTime = this.dateTime.AddDays( // -this.numberDaysForInSampleOptimization - 1 ); ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } --- 59,63 ---- // this.startDateTime = this.dateTime.AddDays( // -this.numberDaysForInSampleOptimization - 1 ); ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); } *************** *** 67,81 **** this.endOfDayTimer = new IndexBasedEndOfDayTimer( ! new EndOfDayDateTime( this.firstDateTime , ! EndOfDaySpecificTime.MarketOpen ), this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WFMultiOneRankDebugInSample" , ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ) ); } private void run_initializeEndOfDayTimerHandler() --- 67,83 ---- this.endOfDayTimer = new IndexBasedEndOfDayTimer( ! HistoricalEndOfDayTimer.GetMarketOpen( this.firstDateTime ) , ! // new EndOfDayDateTime( this.firstDateTime , ! // EndOfDaySpecificTime.MarketOpen ), ! this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WFMultiOneRankDebugInSample" , ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider ) ); } private void run_initializeEndOfDayTimerHandler() *************** *** 83,90 **** this.endOfDayTimerHandler = new WFMultiOneRankDebugEndOfDayTimerHandler( ! this.account , this.signedTickers ); } public void marketOpenEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Transactions.Count == 0 ) --- 85,92 ---- this.endOfDayTimerHandler = new WFMultiOneRankDebugEndOfDayTimerHandler( ! this.account , this.signedTickers ); } public void marketOpenEventHandler( Object sender , ! DateTime dateTime ) { if ( this.account.Transactions.Count == 0 ) *************** *** 92,108 **** } public void oneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if ( ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime > ! this.lastDateTime ) { // the simulation has reached the ending date ! this.account.EndOfDayTimer.Stop(); ! Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "WFT One Rank" , 1 , ! new EndOfDayDateTime( this.lastDateTime , EndOfDaySpecificTime.OneHourAfterMarketClose ) , "^SPX" ); report.Show(); } } public void Run() { --- 94,126 ---- } public void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! if ( ( ( Timer )sender ).GetCurrentDateTime() > ! this.lastDateTime ) { // the simulation has reached the ending date ! this.account.Timer.Stop(); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "WFT One Rank" , 1 , ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! this.lastDateTime ) , ! // new EndOfDayDateTime( this.lastDateTime , EndOfDaySpecificTime.OneHourAfterMarketClose ) , ! "^SPX" ); report.Show(); } } + + private void newDateTimeEventHandler( + Object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + this.marketOpenEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + // this.marketCloseEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + } + public void Run() { *************** *** 110,121 **** run_initializeAccount(); run_initializeEndOfDayTimerHandler(); ! this.endOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( this.marketOpenEventHandler ); ! this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! new FiveMinutesBeforeMarketCloseEventHandler( ! this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.oneHourAfterMarketCloseEventHandler ); this.endOfDayTimer.Start(); } --- 128,145 ---- run_initializeAccount(); run_initializeEndOfDayTimerHandler(); ! ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( this.marketOpenEventHandler ); ! // this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! // new FiveMinutesBeforeMarketCloseEventHandler( ! // this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.oneHourAfterMarketCloseEventHandler ); this.endOfDayTimer.Start(); } Index: WFMultiOneRankRunInSampleDebug.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/ReportDebugger/WFMultiOneRankRunInSampleDebug.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WFMultiOneRankRunInSampleDebug.cs 11 Dec 2005 17:51:48 -0000 1.1 --- WFMultiOneRankRunInSampleDebug.cs 29 Sep 2008 21:21:25 -0000 1.2 *************** *** 3,7 **** WFMultiOneRankRunInSampleDebug.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- WFMultiOneRankRunInSampleDebug.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 51,74 **** TransactionHistory transactionHistory = ( TransactionHistory )visualObjectArchiver.Load( ! "Load transactions" , "qPt" , "Load transactions" ); DateTime lastDateTime = ((DateTime)transactionHistory.GetKey( ! transactionHistory.Count - 1 ) ); RebuildableAccount account = new RebuildableAccount( "FromSerializedTransactions" ); account.Add( transactionHistory ); Report report = new Report( account , ! new HistoricalAdjustedQuoteProvider() ); ! report.Create( "WFT One Rank" , 1 , ! new EndOfDayDateTime( ! lastDateTime , ! EndOfDaySpecificTime.OneHourAfterMarketClose ) , "^SPX" ); WFMultiOneRankReportDebugger wFMultiOneRankReportDebugger = new WFMultiOneRankReportDebugger( 6 , ! 120 , "^SPX" ); report.TransactionGrid.MouseUp += new MouseEventHandler( ! wFMultiOneRankReportDebugger.MouseClickEventHandler ); report.Show(); } --- 51,77 ---- TransactionHistory transactionHistory = ( TransactionHistory )visualObjectArchiver.Load( ! "Load transactions" , "qPt" , "Load transactions" ); DateTime lastDateTime = ((DateTime)transactionHistory.GetKey( ! transactionHistory.Count - 1 ) ); RebuildableAccount account = new RebuildableAccount( "FromSerializedTransactions" ); account.Add( transactionHistory ); Report report = new Report( account , ! new HistoricalAdjustedQuoteProvider() ); ! report.Create( ! "WFT One Rank" , 1 , ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! lastDateTime ) , ! // new EndOfDayDateTime( ! // lastDateTime , ! // EndOfDaySpecificTime.OneHourAfterMarketClose ) , "^SPX" ); WFMultiOneRankReportDebugger wFMultiOneRankReportDebugger = new WFMultiOneRankReportDebugger( 6 , ! 120 , "^SPX" ); report.TransactionGrid.MouseUp += new MouseEventHandler( ! wFMultiOneRankReportDebugger.MouseClickEventHandler ); report.Show(); } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:21:43
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18316 Modified Files: RunWalkForwardLag.cs WFLagChosenTickers.cs WFLagEligibleTickers.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WFLagEligibleTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagEligibleTickers.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WFLagEligibleTickers.cs 18 Feb 2007 01:02:24 -0000 1.5 --- WFLagEligibleTickers.cs 29 Sep 2008 21:20:52 -0000 1.6 *************** *** 38,42 **** private int numberEligibleTickersToBeChosen; private int numberDaysForPerformanceCalculation; ! private IEndOfDayTimer endOfDayTimer; private DataTable eligibleTickers; --- 38,42 ---- private int numberEligibleTickersToBeChosen; private int numberDaysForPerformanceCalculation; ! private Timer endOfDayTimer; private DataTable eligibleTickers; *************** *** 56,60 **** int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! IEndOfDayTimer endOfDayTimer ) { this.checkParametersForWFLagEligibleTickers( tickerGroupID , benchmark , --- 56,60 ---- int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! Timer endOfDayTimer ) { this.checkParametersForWFLagEligibleTickers( tickerGroupID , benchmark , *************** *** 73,77 **** int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! IEndOfDayTimer endOfDayTimer ) { if ( numberDaysForPerformanceCalculation <= 0 ) --- 73,77 ---- int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! Timer endOfDayTimer ) { if ( numberDaysForPerformanceCalculation <= 0 ) *************** *** 82,86 **** private DataTable setTickers_build_getSelectedTickers() { ! DateTime dateTime = this.endOfDayTimer.GetCurrentTime().DateTime; // SelectorByGroup selectorByGroup = // new SelectorByGroup( this.tickerGroupID , dateTime ); --- 82,86 ---- private DataTable setTickers_build_getSelectedTickers() { ! DateTime dateTime = this.endOfDayTimer.GetCurrentDateTime(); // SelectorByGroup selectorByGroup = // new SelectorByGroup( this.tickerGroupID , dateTime ); Index: RunWalkForwardLag.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/RunWalkForwardLag.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** RunWalkForwardLag.cs 19 Aug 2008 17:13:11 -0000 1.13 --- RunWalkForwardLag.cs 29 Sep 2008 21:20:51 -0000 1.14 *************** *** 3,7 **** RunWalkForwardLag.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- RunWalkForwardLag.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 59,69 **** private double maxRunningHours; ! private IHistoricalQuoteProvider historicalQuoteProvider; ! private IEndOfDayTimer endOfDayTimer; private DateTime startingTimeForScript; private Account account; private WFLagEndOfDayTimerHandler endOfDayTimerHandler; ! private WFLagLog wFLagLog; public event NewProgressEventHandler InSampleNewProgress; --- 59,69 ---- private double maxRunningHours; ! private HistoricalMarketValueProvider historicalMarketValueProvider; ! private Timer endOfDayTimer; private DateTime startingTimeForScript; private Account account; private WFLagEndOfDayTimerHandler endOfDayTimerHandler; ! private WFLagLog wFLagLog; public event NewProgressEventHandler InSampleNewProgress; *************** *** 94,121 **** this.wFLagLog = new WFLagLog( this.numberDaysForInSampleOptimization , ! this.benchmark ); } private void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } private void run_initializeEndOfDayTimer() { ! EndOfDayDateTime endOfDayDateTime = ! new EndOfDayDateTime( firstDateTime , ! EndOfDaySpecificTime.MarketOpen ); this.endOfDayTimer = ! new IndexBasedEndOfDayTimer( endOfDayDateTime , ! this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WalkForwardLag" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ) ); } private void run_initializeEndOfDayTimerHandler() --- 94,122 ---- this.wFLagLog = new WFLagLog( this.numberDaysForInSampleOptimization , ! this.benchmark ); } private void run_initializeHistoricalQuoteProvider() { ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); } private void run_initializeEndOfDayTimer() { ! DateTime dateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( firstDateTime ); ! // new EndOfDayDateTime( firstDateTime , ! // EndOfDaySpecificTime.MarketOpen ); this.endOfDayTimer = ! new IndexBasedEndOfDayTimer( dateTime , ! this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WalkForwardLag" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider ) ); } private void run_initializeEndOfDayTimerHandler() *************** *** 123,132 **** this.endOfDayTimerHandler = new WFLagEndOfDayTimerHandler( ! this.tickerGroupID , ! this.benchmark , ! this.numberEligibleTickers , ! this.wFLagWeightedPositionsChooser , ! this.numDaysBetweenEachOptimization , ! this.account ); } public static void WriteToTextLog( string message ) --- 124,133 ---- this.endOfDayTimerHandler = new WFLagEndOfDayTimerHandler( ! this.tickerGroupID , ! this.benchmark , ! this.numberEligibleTickers , ! this.wFLagWeightedPositionsChooser , ! this.numDaysBetweenEachOptimization , ! this.account ); } public static void WriteToTextLog( string message ) *************** *** 139,143 **** // FileMode.OpenOrCreate ); StreamWriter streamWriter = new StreamWriter( "WFLagLog.Txt" , ! true ); streamWriter.WriteLine( message ); streamWriter.Close(); --- 140,144 ---- // FileMode.OpenOrCreate ); StreamWriter streamWriter = new StreamWriter( "WFLagLog.Txt" , ! true ); streamWriter.WriteLine( message ); streamWriter.Close(); *************** *** 153,161 **** // when large populations are chosen // if ( eventArgs.CurrentProgress % 20 == 0 ) ! RunWalkForwardLag.WriteToTextLog( ! eventArgs.CurrentProgress.ToString() + " / " + ! eventArgs.Goal.ToString() + ! " - " + ! DateTime.Now.ToString() ); } private void run_initializeProgressHandlers() --- 154,162 ---- // when large populations are chosen // if ( eventArgs.CurrentProgress % 20 == 0 ) ! RunWalkForwardLag.WriteToTextLog( ! eventArgs.CurrentProgress.ToString() + " / " + ! eventArgs.Goal.ToString() + ! " - " + ! DateTime.Now.ToString() ); } private void run_initializeProgressHandlers() *************** *** 165,169 **** } public void marketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Transactions.Count == 0 ) --- 166,170 ---- } public void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if ( this.account.Transactions.Count == 0 ) *************** *** 172,179 **** #region marketCloseEventHandler private void marketCloseEventHandler_handleProgessBarForm( ! IEndOfDayTimer endOfDayTimer ) { string progress = "Current out of sample date:" + ! endOfDayTimer.GetCurrentTime().DateTime.ToString() + " - " + "First date:" + this.firstDateTime.ToString() + " - " + "Last date:" + this.lastDateTime.ToString(); --- 173,180 ---- #region marketCloseEventHandler private void marketCloseEventHandler_handleProgessBarForm( ! Timer endOfDayTimer ) { string progress = "Current out of sample date:" + ! endOfDayTimer.GetCurrentDateTime().ToString() + " - " + "First date:" + this.firstDateTime.ToString() + " - " + "Last date:" + this.lastDateTime.ToString(); *************** *** 210,214 **** this.wFLagWeightedPositionsChooser.NumberOfPortfolioPositions + "_" + "From_" + this.getShortStringForDateTime( ! (DateTime)this.account.Transactions.GetKey( 0 ) ) + "_" + "To_" + this.getShortStringForDateTime( currentTime ) + "_" + "inSample_" + this.numberDaysForInSampleOptimization.ToString() + "_" + --- 211,215 ---- this.wFLagWeightedPositionsChooser.NumberOfPortfolioPositions + "_" + "From_" + this.getShortStringForDateTime( ! (DateTime)this.account.Transactions.GetKey( 0 ) ) + "_" + "To_" + this.getShortStringForDateTime( currentTime ) + "_" + "inSample_" + this.numberDaysForInSampleOptimization.ToString() + "_" + *************** *** 224,240 **** new VisualObjectArchiver(); visualObjectArchiver.Save( this.wFLagLog , "qPWFLagLog" , ! this.getDefaultLogFileName( currentTime ) , defaultFolderPath ); } private void showReport( object sender ) { DateTime lastReportDateTime = this.lastDateTime; ! if ( ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime < ! lastReportDateTime ) lastReportDateTime = ! ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime; ! Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "Walk Forward Lag" , 1 , ! new EndOfDayDateTime( lastReportDateTime , ! EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark ); report.Show(); --- 225,244 ---- new VisualObjectArchiver(); visualObjectArchiver.Save( this.wFLagLog , "qPWFLagLog" , ! this.getDefaultLogFileName( currentTime ) , defaultFolderPath ); } private void showReport( object sender ) { DateTime lastReportDateTime = this.lastDateTime; ! if ( ( ( Timer )sender ).GetCurrentDateTime() < ! lastReportDateTime ) lastReportDateTime = ! ( ( Timer )sender ).GetCurrentDateTime(); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "Walk Forward Lag" , 1 , ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! lastReportDateTime ) , ! // new EndOfDayDateTime( lastReportDateTime , ! // EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark ); report.Show(); *************** *** 248,264 **** this.endOfDayTimerHandler.AreBestTickersToBeChosen(); return ! ( ( currentTime > this.lastDateTime ) || ! ( scriptTimeElapsed && areBestTickersToBeChosen ) ); } private void marketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { DateTime currentTime = ! ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime; if ( this.isTimeToStop( currentTime ) ) { // either the simulation has reached the ending date or // too much time elapsed since the simulation started ! this.account.EndOfDayTimer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , --- 252,268 ---- this.endOfDayTimerHandler.AreBestTickersToBeChosen(); return ! ( ( currentTime > this.lastDateTime ) || ! ( scriptTimeElapsed && areBestTickersToBeChosen ) ); } private void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { DateTime currentTime = ! ( ( Timer )sender ).GetCurrentDateTime(); if ( this.isTimeToStop( currentTime ) ) { // either the simulation has reached the ending date or // too much time elapsed since the simulation started ! this.account.Timer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , *************** *** 276,284 **** // the simulation has not reached the ending date, yet this.marketCloseEventHandler_handleProgessBarForm( ! ( IEndOfDayTimer )sender ); } #endregion private void newChosenPositionsEventHandler( object sender , ! WFLagNewChosenPositionsEventArgs eventArgs ) { // WFLagChosenPositions wFLagChosenPositions = --- 280,288 ---- // the simulation has not reached the ending date, yet this.marketCloseEventHandler_handleProgessBarForm( ! ( Timer )sender ); } #endregion private void newChosenPositionsEventHandler( object sender , ! WFLagNewChosenPositionsEventArgs eventArgs ) { // WFLagChosenPositions wFLagChosenPositions = *************** *** 287,306 **** this.wFLagLog.Add( eventArgs.WFLagLogItem ); } private void run_addEventHandlers() { ! this.endOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( this.marketOpenEventHandler ); ! this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! new FiveMinutesBeforeMarketCloseEventHandler( ! this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.marketCloseEventHandler ); this.endOfDayTimerHandler.NewChosenPositions += new NewChosenPositionsEventHandler( ! this.newChosenPositionsEventHandler ); } public override void Run() --- 291,321 ---- this.wFLagLog.Add( eventArgs.WFLagLogItem ); } + + private void newDateTimeEventHandler( object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + this.marketCloseEventHandler( sender , dateTime ); + } private void run_addEventHandlers() { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( this.marketOpenEventHandler ); ! // this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! // new FiveMinutesBeforeMarketCloseEventHandler( ! // this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.marketCloseEventHandler ); this.endOfDayTimerHandler.NewChosenPositions += new NewChosenPositionsEventHandler( ! this.newChosenPositionsEventHandler ); } public override void Run() Index: WFLagChosenTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagChosenTickers.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** WFLagChosenTickers.cs 19 Aug 2008 17:13:12 -0000 1.11 --- WFLagChosenTickers.cs 29 Sep 2008 21:20:52 -0000 1.12 *************** *** 48,52 **** protected int numberOfPositionsToBeChosen; protected int inSampleDays; ! protected IEndOfDayTimer endOfDayTimer; protected int generationNumberForGeneticOptimizer; protected int populationSizeForGeneticOptimizer; --- 48,52 ---- protected int numberOfPositionsToBeChosen; protected int inSampleDays; ! protected Timer endOfDayTimer; protected int generationNumberForGeneticOptimizer; protected int populationSizeForGeneticOptimizer; *************** *** 112,116 **** int numberOfPositionsToBeChosen , int inSampleDays , ! IEndOfDayTimer endOfDayTimer , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer , --- 112,116 ---- int numberOfPositionsToBeChosen , int inSampleDays , ! Timer endOfDayTimer , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer , *************** *** 167,174 **** { this.firstOptimizationDate = ! this.endOfDayTimer.GetCurrentTime().DateTime.AddDays( -( this.inSampleDays - 1 ) ); this.lastOptimizationDate = ! this.endOfDayTimer.GetCurrentTime().DateTime; WFLagGenomeManager genomeManager = --- 167,174 ---- { this.firstOptimizationDate = ! this.endOfDayTimer.GetCurrentDateTime().AddDays( -( this.inSampleDays - 1 ) ); this.lastOptimizationDate = ! this.endOfDayTimer.GetCurrentDateTime(); WFLagGenomeManager genomeManager = |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:21:35
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18335 Modified Files: RunWalkForwardMultiOneRank.cs WFMultiOneRankChosenTickers.cs WFMultiOneRankEligibleTickers.cs WFMultiOneRankEndOfDayTimerHandler.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WFMultiOneRankEndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/WFMultiOneRankEndOfDayTimerHandler.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WFMultiOneRankEndOfDayTimerHandler.cs 14 Mar 2006 14:47:52 -0000 1.4 --- WFMultiOneRankEndOfDayTimerHandler.cs 29 Sep 2008 21:20:54 -0000 1.5 *************** *** 3,7 **** WFMultiOneRankEndOfDayTimerHandler.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- WFMultiOneRankEndOfDayTimerHandler.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Collections; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Collections; *************** *** 38,42 **** /// This is the core strategy! /// </summary> ! public class WFMultiOneRankEndOfDayTimerHandler { private WFMultiOneRankEligibleTickers eligibleTickers; --- 38,43 ---- /// This is the core strategy! /// </summary> ! public class WFMultiOneRankEndOfDayTimerHandler : ! QuantProject.Business.Strategies.EndOfDayTimerHandler { private WFMultiOneRankEligibleTickers eligibleTickers; *************** *** 108,117 **** this.eligibleTickers = new WFMultiOneRankEligibleTickers( this.tickerGroupID , ! this.benchmark , ! numberEligibleTickers , inSampleWindowDays , ! this.account.EndOfDayTimer ); this.chosenTickers = new WFMultiOneRankChosenTickers( this.eligibleTickers , this.numberOfPositionsToBeChosen , ! this.inSampleWindowDays , this.account.EndOfDayTimer , this.generationNumberForGeneticOptimizer , this. populationSizeForGeneticOptimizer ); --- 109,118 ---- this.eligibleTickers = new WFMultiOneRankEligibleTickers( this.tickerGroupID , ! this.benchmark , ! numberEligibleTickers , inSampleWindowDays , ! this.account.Timer ); this.chosenTickers = new WFMultiOneRankChosenTickers( this.eligibleTickers , this.numberOfPositionsToBeChosen , ! this.inSampleWindowDays , this.account.Timer , this.generationNumberForGeneticOptimizer , this. populationSizeForGeneticOptimizer ); *************** *** 123,129 **** this.lastOptimizationDate = DateTime.MinValue; } ! private EndOfDayDateTime now() { ! return this.account.EndOfDayTimer.GetCurrentTime(); } private void bestPerformingNewProgress( --- 124,130 ---- this.lastOptimizationDate = DateTime.MinValue; } ! private DateTime now() { ! return this.account.Timer.GetCurrentDateTime(); } private void bestPerformingNewProgress( *************** *** 136,142 **** bool returnValue = ( ( ( this.account.Portfolio.Count == 0 ) ! && ( ( this.lastOptimizationDate == DateTime.MinValue ) ) ) || ! ( this.now().DateTime >= ! this.lastOptimizationDate.AddDays( this.outOfSampleWindowDays ) ) ); return returnValue; } --- 137,143 ---- bool returnValue = ( ( ( this.account.Portfolio.Count == 0 ) ! && ( ( this.lastOptimizationDate == DateTime.MinValue ) ) ) || ! ( this.now() >= ! this.lastOptimizationDate.AddDays( this.outOfSampleWindowDays ) ) ); return returnValue; } *************** *** 147,151 **** /// <param name="eventArgs"></param> public void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.areBestTickersToBeChosen() ) --- 148,152 ---- /// <param name="eventArgs"></param> public void OneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { if ( this.areBestTickersToBeChosen() ) *************** *** 157,167 **** this.eligibleTickers.SetTickers(); Console.WriteLine( "Number of Eligible tickers: " + ! this.eligibleTickers.EligibleTickers.Rows.Count ); this.chosenTickers.SetTickers( this.eligibleTickers ); ! this.lastOptimizationDate = this.now().DateTime; } // oneHourAfterMarketCloseEventHandler_orderChosenTickers( ( IEndOfDayTimer ) sender ); } // #endregion #region FiveMinutesBeforeMarketCloseEventHandler private string getTicker( string signedTicker ) --- 158,169 ---- this.eligibleTickers.SetTickers(); Console.WriteLine( "Number of Eligible tickers: " + ! this.eligibleTickers.EligibleTickers.Rows.Count ); this.chosenTickers.SetTickers( this.eligibleTickers ); ! this.lastOptimizationDate = this.now(); } // oneHourAfterMarketCloseEventHandler_orderChosenTickers( ( IEndOfDayTimer ) sender ); } // #endregion + #region FiveMinutesBeforeMarketCloseEventHandler private string getTicker( string signedTicker ) *************** *** 187,197 **** double todayMarketValueAtClose = this.account.DataStreamer.GetCurrentBid( ticker ); ! EndOfDayDateTime yesterdayAtClose = new ! EndOfDayDateTime( ! this.account.EndOfDayTimer.GetCurrentTime().DateTime.AddDays( - 1 ) , ! EndOfDaySpecificTime.MarketClose ); double yesterdayMarketValueAtClose = this.historicalAdjustedQuoteProvider.GetMarketValue( ! ticker , yesterdayAtClose ); double returnValue = ( todayMarketValueAtClose - yesterdayMarketValueAtClose ) / --- 189,201 ---- double todayMarketValueAtClose = this.account.DataStreamer.GetCurrentBid( ticker ); ! DateTime yesterdayAtClose = ! HistoricalEndOfDayTimer.GetMarketClose( ! this.account.Timer.GetCurrentDateTime().AddDays( - 1 ) ); ! // new EndOfDayDateTime( ! // this.account.EndOfDayTimer.GetCurrentTime().DateTime.AddDays( - 1 ) , ! // EndOfDaySpecificTime.MarketClose ); double yesterdayMarketValueAtClose = this.historicalAdjustedQuoteProvider.GetMarketValue( ! ticker , yesterdayAtClose ); double returnValue = ( todayMarketValueAtClose - yesterdayMarketValueAtClose ) / *************** *** 217,251 **** return totalReturn < 0; } ! private OrderType fiveMinutesBeforeMarketCloseEventHandler_openPosition_getOrderType( string signedTicker , bool isToReverse ) { OrderType orderType = OrderType.MarketBuy; if ( ( signedTicker.StartsWith( "-" ) && !isToReverse ) || ! ( !signedTicker.StartsWith( "-" ) && isToReverse ) ) orderType = OrderType.MarketSellShort; return orderType; } ! private void fiveMinutesBeforeMarketCloseEventHandler_openPosition( string signedTicker , bool isToReverse ) { string ticker = this.getTicker( signedTicker ); OrderType orderType = ! this.fiveMinutesBeforeMarketCloseEventHandler_openPosition_getOrderType( ! signedTicker , isToReverse ); double maxPositionValue = this.account.GetMarketValue() / this.numberOfPositionsToBeChosen; long sharesToBeTraded = OneRank.MaxBuyableShares( ticker , ! maxPositionValue , this.account.DataStreamer ); this.account.AddOrder( new Order( orderType , ! new Instrument( ticker ) , sharesToBeTraded ) ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_openPositions() { bool isToReverse = this.isToReverse(); foreach ( string signedTicker in this.chosenTickers.Keys ) ! this.fiveMinutesBeforeMarketCloseEventHandler_openPosition( signedTicker , isToReverse ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_closePosition( string ticker ) { --- 221,255 ---- return totalReturn < 0; } ! private OrderType marketCloseEventHandler_openPosition_getOrderType( string signedTicker , bool isToReverse ) { OrderType orderType = OrderType.MarketBuy; if ( ( signedTicker.StartsWith( "-" ) && !isToReverse ) || ! ( !signedTicker.StartsWith( "-" ) && isToReverse ) ) orderType = OrderType.MarketSellShort; return orderType; } ! private void marketCloseEventHandler_openPosition( string signedTicker , bool isToReverse ) { string ticker = this.getTicker( signedTicker ); OrderType orderType = ! this.marketCloseEventHandler_openPosition_getOrderType( ! signedTicker , isToReverse ); double maxPositionValue = this.account.GetMarketValue() / this.numberOfPositionsToBeChosen; long sharesToBeTraded = OneRank.MaxBuyableShares( ticker , ! maxPositionValue , this.account.DataStreamer ); this.account.AddOrder( new Order( orderType , ! new Instrument( ticker ) , sharesToBeTraded ) ); } ! private void marketCloseEventHandler_openPositions() { bool isToReverse = this.isToReverse(); foreach ( string signedTicker in this.chosenTickers.Keys ) ! this.marketCloseEventHandler_openPosition( signedTicker , isToReverse ); } ! private void marketCloseEventHandler_closePosition( string ticker ) { *************** *** 275,279 **** return todayReturnForPortfolioPositions < 0; } ! private void fiveMinutesBeforeMarketCloseEventHandler_closePositions_actually() { ArrayList tickers = new ArrayList(); --- 279,283 ---- return todayReturnForPortfolioPositions < 0; } ! private void marketCloseEventHandler_closePositions_actually() { ArrayList tickers = new ArrayList(); *************** *** 281,306 **** tickers.Add( ticker ); foreach ( string ticker in tickers ) ! fiveMinutesBeforeMarketCloseEventHandler_closePosition( ticker ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_closePositions() { if ( this.arePositionsToBeClosed() ) ! this.fiveMinutesBeforeMarketCloseEventHandler_closePositions_actually(); } ! public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Portfolio.Count == 0 ) ! fiveMinutesBeforeMarketCloseEventHandler_openPositions(); else { if ( this.arePositionsToBeClosed() ) { ! this.fiveMinutesBeforeMarketCloseEventHandler_closePositions(); ! this.fiveMinutesBeforeMarketCloseEventHandler_openPositions(); } } } #endregion } } --- 285,322 ---- tickers.Add( ticker ); foreach ( string ticker in tickers ) ! marketCloseEventHandler_closePosition( ticker ); } ! private void marketCloseEventHandler_closePositions() { if ( this.arePositionsToBeClosed() ) ! this.marketCloseEventHandler_closePositions_actually(); } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if ( this.account.Portfolio.Count == 0 ) ! marketCloseEventHandler_openPositions(); else { if ( this.arePositionsToBeClosed() ) { ! this.marketCloseEventHandler_closePositions(); ! this.marketCloseEventHandler_openPositions(); } } } #endregion + + protected override void marketOpenEventHandler( + Object sender , DateTime dateTime ) + { + ; + } + + protected override void oneHourAfterMarketCloseEventHandler( + Object sender , DateTime dateTime ) + { + ; + } } } Index: WFMultiOneRankEligibleTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/WFMultiOneRankEligibleTickers.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFMultiOneRankEligibleTickers.cs 19 Feb 2006 17:50:29 -0000 1.2 --- WFMultiOneRankEligibleTickers.cs 29 Sep 2008 21:20:54 -0000 1.3 *************** *** 38,42 **** private int numberEligibleTickersToBeChosen; private int numberDaysForPerformanceCalculation; ! private IEndOfDayTimer endOfDayTimer; private DataTable eligibleTickers; --- 38,42 ---- private int numberEligibleTickersToBeChosen; private int numberDaysForPerformanceCalculation; ! private Timer endOfDayTimer; private DataTable eligibleTickers; *************** *** 52,56 **** int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! IEndOfDayTimer endOfDayTimer ) { this.tickerGroupID = tickerGroupID; --- 52,56 ---- int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , ! Timer endOfDayTimer ) { this.tickerGroupID = tickerGroupID; *************** *** 65,69 **** private DataTable setTickers_build_getSelectedTickers() { ! DateTime dateTime = this.endOfDayTimer.GetCurrentTime().DateTime; // SelectorByGroup selectorByGroup = // new SelectorByGroup( "SP500" , dateTime ); --- 65,69 ---- private DataTable setTickers_build_getSelectedTickers() { ! DateTime dateTime = this.endOfDayTimer.GetCurrentDateTime(); // SelectorByGroup selectorByGroup = // new SelectorByGroup( "SP500" , dateTime ); Index: WFMultiOneRankChosenTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/WFMultiOneRankChosenTickers.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WFMultiOneRankChosenTickers.cs 12 Nov 2005 18:39:33 -0000 1.1 --- WFMultiOneRankChosenTickers.cs 29 Sep 2008 21:20:54 -0000 1.2 *************** *** 40,44 **** private int numberOfTickersInPortfolio; private int inSampleDays; ! private IEndOfDayTimer endOfDayTimer; private int generationNumberForGeneticOptimizer; private int populationSizeForGeneticOptimizer; --- 40,44 ---- private int numberOfTickersInPortfolio; private int inSampleDays; ! private Timer endOfDayTimer; private int generationNumberForGeneticOptimizer; private int populationSizeForGeneticOptimizer; *************** *** 50,54 **** int numberOfTickersInPortfolio , int inSampleDays , ! IEndOfDayTimer endOfDayTimer , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer --- 50,54 ---- int numberOfTickersInPortfolio , int inSampleDays , ! Timer endOfDayTimer , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer *************** *** 87,91 **** DateTime firstDate = ! this.endOfDayTimer.GetCurrentTime().DateTime.AddDays( -( this.inSampleDays - 1 ) ); --- 87,91 ---- DateTime firstDate = ! this.endOfDayTimer.GetCurrentDateTime().AddDays( -( this.inSampleDays - 1 ) ); *************** *** 94,98 **** eligibleTickers.EligibleTickers , firstDate , ! this.endOfDayTimer.GetCurrentTime().DateTime , this.numberOfTickersInPortfolio , 0.0 ); --- 94,98 ---- eligibleTickers.EligibleTickers , firstDate , ! this.endOfDayTimer.GetCurrentDateTime() , this.numberOfTickersInPortfolio , 0.0 ); Index: RunWalkForwardMultiOneRank.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/RunWalkForwardMultiOneRank.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RunWalkForwardMultiOneRank.cs 14 Mar 2006 14:51:12 -0000 1.4 --- RunWalkForwardMultiOneRank.cs 29 Sep 2008 21:20:54 -0000 1.5 *************** *** 3,7 **** RunWalkForwardOneRank.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- RunWalkForwardOneRank.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 51,56 **** public class RunWalkForwardMultiOneRank : Script { ! private IHistoricalQuoteProvider historicalQuoteProvider; ! private ReportTable reportTable; private string tickerGroupID; --- 51,56 ---- public class RunWalkForwardMultiOneRank : Script { ! private HistoricalMarketValueProvider historicalMarketValueProvider; ! private ReportTable reportTable; private string tickerGroupID; *************** *** 68,72 **** private WFMultiOneRankEndOfDayTimerHandler endOfDayTimerHandler; private Account account; ! private IEndOfDayTimer endOfDayTimer; private DateTime startingTimeForScript; --- 68,72 ---- private WFMultiOneRankEndOfDayTimerHandler endOfDayTimerHandler; private Account account; ! private QuantProject.Business.Timing.Timer endOfDayTimer; private DateTime startingTimeForScript; *************** *** 103,110 **** // public event NewProgressEventHandler OutOfSampleNewProgress; ! #region Run private void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); this.startingTimeForScript = DateTime.Now; --- 103,110 ---- // public event NewProgressEventHandler OutOfSampleNewProgress; ! #region Run private void run_initializeHistoricalQuoteProvider() { ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); this.startingTimeForScript = DateTime.Now; *************** *** 112,129 **** private void run_initializeEndOfDayTimer() { ! EndOfDayDateTime endOfDayDateTime = ! new EndOfDayDateTime( firstDateTime , ! EndOfDaySpecificTime.MarketOpen ); this.endOfDayTimer = ! new IndexBasedEndOfDayTimer( endOfDayDateTime , ! this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WalkForwardOneRank" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ) ); } private void run_initializeEndOfDayTimerHandler() --- 112,130 ---- private void run_initializeEndOfDayTimer() { ! DateTime dateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( this.firstDateTime ); ! // new EndOfDayDateTime( firstDateTime , ! // EndOfDaySpecificTime.MarketOpen ); this.endOfDayTimer = ! new IndexBasedEndOfDayTimer( dateTime , ! this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WalkForwardOneRank" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider ) ); } private void run_initializeEndOfDayTimerHandler() *************** *** 131,143 **** this.endOfDayTimerHandler = new WFMultiOneRankEndOfDayTimerHandler( ! this.tickerGroupID , ! this.benchmark , ! this.numberEligibleTickers , ! this.numberOfPortfolioPositions , ! this.numberDaysForInSampleOptimization , ! this.numDaysBetweenEachOptimization , ! this.account , ! this.generationNumberForGeneticOptimizer , ! this.populationSizeForGeneticOptimizer ); // this.endOfDayTimerHandler = new EndOfDayTimerHandler( 4 , 3 , 2 , 100 , 30 , // this.account ); --- 132,144 ---- this.endOfDayTimerHandler = new WFMultiOneRankEndOfDayTimerHandler( ! this.tickerGroupID , ! this.benchmark , ! this.numberEligibleTickers , ! this.numberOfPortfolioPositions , ! this.numberDaysForInSampleOptimization , ! this.numDaysBetweenEachOptimization , ! this.account , ! this.generationNumberForGeneticOptimizer , ! this.populationSizeForGeneticOptimizer ); // this.endOfDayTimerHandler = new EndOfDayTimerHandler( 4 , 3 , 2 , 100 , 30 , // this.account ); *************** *** 159,207 **** new InSampleNewProgressEventHandler( this.inSampleNewProgressEventHandler ); } #region oneHourAfterMarketCloseEventHandler private void oneHourAfterMarketCloseEventHandler_handleProgessBarForm( ! IEndOfDayTimer endOfDayTimer ) { string progress = "Current out of sample date:" + ! endOfDayTimer.GetCurrentTime().DateTime.ToString() + " - " + "First date:" + this.firstDateTime.ToString() + " - " + "Last date:" + this.lastDateTime.ToString(); Console.WriteLine( progress ); ! } ! public void marketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! if ( this.account.Transactions.Count == 0 ) ! this.account.AddCash( 30000 ); ! } ! public void oneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if ( ( ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime > ! this.lastDateTime ) || ! ( DateTime.Now >= ! this.startingTimeForScript.AddHours( this.maxRunningHours ) ) ) { // the simulation has reached the ending date ! this.account.EndOfDayTimer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , // @"C:\Documents and Settings\Glauco\Desktop\reports\final.qP" ); DateTime lastReportDateTime = this.lastDateTime; ! if ( ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime < ! lastReportDateTime ) lastReportDateTime = ! ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime; ! Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "WFT One Rank" , 1 , ! new EndOfDayDateTime( lastReportDateTime , ! EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark ); WFMultiOneRankReportDebugger wFMultiOneRankReportDebugger = new WFMultiOneRankReportDebugger( this.numberOfPortfolioPositions , ! this.numberDaysForInSampleOptimization , this.benchmark ); report.TransactionGrid.MouseUp += new MouseEventHandler( ! wFMultiOneRankReportDebugger.MouseClickEventHandler ); report.Show(); } --- 160,212 ---- new InSampleNewProgressEventHandler( this.inSampleNewProgressEventHandler ); } + + public void marketOpenEventHandler( + Object sender , DateTime sateTime ) + { + if ( this.account.Transactions.Count == 0 ) + this.account.AddCash( 30000 ); + } + #region oneHourAfterMarketCloseEventHandler private void oneHourAfterMarketCloseEventHandler_handleProgessBarForm( ! QuantProject.Business.Timing.Timer endOfDayTimer ) { string progress = "Current out of sample date:" + ! endOfDayTimer.GetCurrentDateTime().ToString() + " - " + "First date:" + this.firstDateTime.ToString() + " - " + "Last date:" + this.lastDateTime.ToString(); Console.WriteLine( progress ); ! } ! private void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! if ( ( ( ( QuantProject.Business.Timing.Timer )sender ).GetCurrentDateTime() > ! this.lastDateTime ) || ! ( DateTime.Now >= ! this.startingTimeForScript.AddHours( this.maxRunningHours ) ) ) { // the simulation has reached the ending date ! this.account.Timer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , // @"C:\Documents and Settings\Glauco\Desktop\reports\final.qP" ); DateTime lastReportDateTime = this.lastDateTime; ! if ( ( ( QuantProject.Business.Timing.Timer )sender ).GetCurrentDateTime() < ! lastReportDateTime ) lastReportDateTime = ! ( ( QuantProject.Business.Timing.Timer )sender ).GetCurrentDateTime(); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "WFT One Rank" , 1 , ! HistoricalEndOfDayTimer.GetMarketClose( lastReportDateTime ) , ! // new EndOfDayDateTime( lastReportDateTime , ! // EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark ); WFMultiOneRankReportDebugger wFMultiOneRankReportDebugger = new WFMultiOneRankReportDebugger( this.numberOfPortfolioPositions , ! this.numberDaysForInSampleOptimization , this.benchmark ); report.TransactionGrid.MouseUp += new MouseEventHandler( ! wFMultiOneRankReportDebugger.MouseClickEventHandler ); report.Show(); } *************** *** 209,228 **** // the simulation has not reached the ending date, yet this.oneHourAfterMarketCloseEventHandler_handleProgessBarForm( ! ( IEndOfDayTimer )sender ); } #endregion private void run_addEventHandlers() { ! this.endOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( this.marketOpenEventHandler ); ! this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! new FiveMinutesBeforeMarketCloseEventHandler( ! this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.oneHourAfterMarketCloseEventHandler ); } public override void Run() --- 214,251 ---- // the simulation has not reached the ending date, yet this.oneHourAfterMarketCloseEventHandler_handleProgessBarForm( ! ( QuantProject.Business.Timing.Timer )sender ); } #endregion + + private void newDateTimeEventHandler( + Object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + this.marketOpenEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + // this.marketCloseEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + } + + private void run_addEventHandlers() { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( this.marketOpenEventHandler ); ! // this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! // new FiveMinutesBeforeMarketCloseEventHandler( ! // this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.oneHourAfterMarketCloseEventHandler ); } public override void Run() *************** *** 238,242 **** this.endOfDayTimer.Start(); } ! #endregion } } --- 261,265 ---- this.endOfDayTimer.Start(); } ! #endregion } } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18260/OutOfSampleChoosers Modified Files: OutOfSampleChooserForExactNumberOfBestLongPositions.cs OutOfSampleChooserForSingleLongAndShort.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: OutOfSampleChooserForExactNumberOfBestLongPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers/OutOfSampleChooserForExactNumberOfBestLongPositions.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OutOfSampleChooserForExactNumberOfBestLongPositions.cs 11 May 2008 19:02:29 -0000 1.3 --- OutOfSampleChooserForExactNumberOfBestLongPositions.cs 29 Sep 2008 21:20:43 -0000 1.4 *************** *** 35,38 **** --- 35,39 ---- /// returned are those belonging to the highest correlated couples /// </summary> + [Serializable] public class OutOfSampleChooserForExactNumberOfBestLongPositions : OutOfSampleChooser Index: OutOfSampleChooserForSingleLongAndShort.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers/OutOfSampleChooserForSingleLongAndShort.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OutOfSampleChooserForSingleLongAndShort.cs 27 Apr 2008 17:43:31 -0000 1.1 --- OutOfSampleChooserForSingleLongAndShort.cs 29 Sep 2008 21:20:44 -0000 1.2 *************** *** 32,35 **** --- 32,36 ---- /// Selects a single couple with a long and a short position /// </summary> + [Serializable] public class OutOfSampleChooserForSingleLongAndShort : OutOfSampleChooser |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/BruteForce In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18316/WeightedPositionsChoosers/BruteForce Modified Files: WFLagBruteForceWeightedPositionsChooserForBalancedFixedPortfolioAndBalancedDriving.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WFLagBruteForceWeightedPositionsChooserForBalancedFixedPortfolioAndBalancedDriving.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/BruteForce/WFLagBruteForceWeightedPositionsChooserForBalancedFixedPortfolioAndBalancedDriving.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagBruteForceWeightedPositionsChooserForBalancedFixedPortfolioAndBalancedDriving.cs 26 Mar 2008 00:54:54 -0000 1.3 --- WFLagBruteForceWeightedPositionsChooserForBalancedFixedPortfolioAndBalancedDriving.cs 29 Sep 2008 21:20:52 -0000 1.4 *************** *** 3,7 **** WFLagBruteForceWeightedPositionsChooserForBalancedFixedPortfolioAndBalancedDriving.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- WFLagBruteForceWeightedPositionsChooserForBalancedFixedPortfolioAndBalancedDriving.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 93,99 **** // this chooser doesn't use a genetic optimizer // thus this property is meaningless for this chooser ! return -999; } ! } public string Benchmark { --- 93,99 ---- // this chooser doesn't use a genetic optimizer // thus this property is meaningless for this chooser ! return -999; } ! } public string Benchmark { *************** *** 144,148 **** string benchmark , IEquityEvaluator equityEvaluator ! ) { this.numberOfDrivingPositions = numberOfDrivingPositions; --- 144,148 ---- string benchmark , IEquityEvaluator equityEvaluator ! ) { this.numberOfDrivingPositions = numberOfDrivingPositions; *************** *** 181,188 **** // ( WFLagWeightedPositions )genomeManager.Decode( genome ); // this.setWeightedPositions( wFLagWeightedPositions ); ! //// this.drivingWeightedPositions = ! //// wFLagWeightedPositions.DrivingWeightedPositions; ! //// this.portfolioWeightedPositions = ! //// wFLagWeightedPositions.PortfolioWeightedPositions; // } // public virtual void setWeightedPositions_usingTheGeneticOptimizer( --- 181,188 ---- // ( WFLagWeightedPositions )genomeManager.Decode( genome ); // this.setWeightedPositions( wFLagWeightedPositions ); ! //// this.drivingWeightedPositions = ! //// wFLagWeightedPositions.DrivingWeightedPositions; ! //// this.portfolioWeightedPositions = ! //// wFLagWeightedPositions.PortfolioWeightedPositions; // } // public virtual void setWeightedPositions_usingTheGeneticOptimizer( *************** *** 195,199 **** // this.endOfDayTimer.GetCurrentTime().DateTime; // ! // WFLagGenomeManager genomeManager = // new WFLagGenomeManager( // eligibleTickers.EligibleTickers , --- 195,199 ---- // this.endOfDayTimer.GetCurrentTime().DateTime; // ! // WFLagGenomeManager genomeManager = // new WFLagGenomeManager( // eligibleTickers.EligibleTickers , *************** *** 243,247 **** // // WFLagBruteForceOptimizableParametersManager ! // wFLagBruteForceOptimizableItemManager= // new WFLagBruteForceOptimizableParametersManager( // eligibleTickers.EligibleTickers , --- 243,247 ---- // // WFLagBruteForceOptimizableParametersManager ! // wFLagBruteForceOptimizableItemManager= // new WFLagBruteForceOptimizableParametersManager( // eligibleTickers.EligibleTickers , *************** *** 275,313 **** #region setReturnsManager protected virtual ReturnIntervals getReturnIntervals( ! EndOfDayDateTime now ) { DateTime firstInSampleDateForDrivingPositions = ! now.DateTime.AddDays( ! -( this.NumberDaysForInSampleOptimization - 1 ) ); DateTime lastInSampleOptimizationDate = ! now.DateTime; ReturnIntervals returnIntervals = new CloseToCloseIntervals( ! new EndOfDayDateTime( firstInSampleDateForDrivingPositions , ! EndOfDaySpecificTime.MarketClose ) , ! new EndOfDayDateTime( lastInSampleOptimizationDate , ! EndOfDaySpecificTime.MarketClose ) , ! this.benchmark ); ! return returnIntervals; ! } ! private void setReturnsManager( EndOfDayDateTime now ) { ReturnIntervals returnIntervals = this.getReturnIntervals( now ); ! IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); this.returnsManager = new ReturnsManager( returnIntervals , ! historicalQuoteProvider ); } #endregion setReturnsManager protected virtual void setDecoder( ! WFLagEligibleTickers eligibleTickersForDrivingPositions , EndOfDayDateTime now ) { this.setReturnsManager( now ); this.wFLagDecoder = new WFLagDecoderForFixedPortfolioWithBalancedVolatilityAndDrivingWithBalancedVolatility( ! eligibleTickersForDrivingPositions , this.numberOfDrivingPositions , ! this.portfolioSignedTickers , returnsManager ); } #endregion setDecoder --- 275,317 ---- #region setReturnsManager protected virtual ReturnIntervals getReturnIntervals( ! DateTime now ) { DateTime firstInSampleDateForDrivingPositions = ! now.AddDays( ! -( this.NumberDaysForInSampleOptimization - 1 ) ); DateTime lastInSampleOptimizationDate = ! now; ReturnIntervals returnIntervals = new CloseToCloseIntervals( ! HistoricalEndOfDayTimer.GetMarketClose( ! firstInSampleDateForDrivingPositions ) , ! HistoricalEndOfDayTimer.GetMarketClose( ! lastInSampleOptimizationDate ) , ! // new EndOfDayDateTime( firstInSampleDateForDrivingPositions , ! // EndOfDaySpecificTime.MarketClose ) , ! // new EndOfDayDateTime( lastInSampleOptimizationDate , ! // EndOfDaySpecificTime.MarketClose ) , ! this.benchmark ); ! return returnIntervals; ! } ! private void setReturnsManager( DateTime now ) { ReturnIntervals returnIntervals = this.getReturnIntervals( now ); ! HistoricalMarketValueProvider historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); this.returnsManager = new ReturnsManager( returnIntervals , ! historicalMarketValueProvider ); } #endregion setReturnsManager protected virtual void setDecoder( ! WFLagEligibleTickers eligibleTickersForDrivingPositions , DateTime now ) { this.setReturnsManager( now ); this.wFLagDecoder = new WFLagDecoderForFixedPortfolioWithBalancedVolatilityAndDrivingWithBalancedVolatility( ! eligibleTickersForDrivingPositions , this.numberOfDrivingPositions , ! this.portfolioSignedTickers , returnsManager ); } #endregion setDecoder *************** *** 326,337 **** WFLagEligibleTickers eligibleTickers , string longPortfolioTicker , string shortPortfolioTicker , ! EndOfDayDateTime now ) { ! this.firstOptimizationDate = now.DateTime.AddDays( -( this.inSampleDays - 1 ) ); ! this.lastOptimizationDate = now.DateTime; // WFLagFixedPortfolioBruteForceOptimizableParametersManager ! // wFLagFixedPortfolioBruteForceOptimizableParametersManager= // new WFLagFixedPortfolioBruteForceOptimizableParametersManager( // eligibleTickers.EligibleTickers , --- 330,341 ---- WFLagEligibleTickers eligibleTickers , string longPortfolioTicker , string shortPortfolioTicker , ! DateTime now ) { ! this.firstOptimizationDate = now.AddDays( -( this.inSampleDays - 1 ) ); ! this.lastOptimizationDate = now; // WFLagFixedPortfolioBruteForceOptimizableParametersManager ! // wFLagFixedPortfolioBruteForceOptimizableParametersManager= // new WFLagFixedPortfolioBruteForceOptimizableParametersManager( // eligibleTickers.EligibleTickers , *************** *** 343,347 **** // // WFLagFixedPortfolioBruteForceOptParamManagerWithPortfolioNormalizedVolatility ! // wFLagFixedPortfolioBruteForceOptimizableParametersManager= // new WFLagFixedPortfolioBruteForceOptParamManagerWithNormalizedVolatility( // eligibleTickers.EligibleTickers , --- 347,351 ---- // // WFLagFixedPortfolioBruteForceOptParamManagerWithPortfolioNormalizedVolatility ! // wFLagFixedPortfolioBruteForceOptimizableParametersManager= // new WFLagFixedPortfolioBruteForceOptParamManagerWithNormalizedVolatility( // eligibleTickers.EligibleTickers , *************** *** 352,366 **** // this.numberOfDrivingPositions ); WFLagBruteForceOptimizableParametersManagerForBalancedFixedPortfolioAndBalancedDriving ! wFLagFixedPortfolioBruteForceOptimizableParametersManager= new WFLagBruteForceOptimizableParametersManagerForBalancedFixedPortfolioAndBalancedDriving( ! eligibleTickers.EligibleTickers , ! longPortfolioTicker , ! shortPortfolioTicker , ! this.firstOptimizationDate , ! this.lastOptimizationDate , ! this.numberOfDrivingPositions , ! this.wFLagDecoder , ! this.equityEvaluator , ! this.returnsManager ); BruteForceOptimizer bruteForceOptimizer = new BruteForceOptimizer( --- 356,370 ---- // this.numberOfDrivingPositions ); WFLagBruteForceOptimizableParametersManagerForBalancedFixedPortfolioAndBalancedDriving ! wFLagFixedPortfolioBruteForceOptimizableParametersManager= new WFLagBruteForceOptimizableParametersManagerForBalancedFixedPortfolioAndBalancedDriving( ! eligibleTickers.EligibleTickers , ! longPortfolioTicker , ! shortPortfolioTicker , ! this.firstOptimizationDate , ! this.lastOptimizationDate , ! this.numberOfDrivingPositions , ! this.wFLagDecoder , ! this.equityEvaluator , ! this.returnsManager ); BruteForceOptimizer bruteForceOptimizer = new BruteForceOptimizer( *************** *** 369,376 **** bruteForceOptimizer.NewProgress += new NewProgressEventHandler( ! this.newBruteForceOptimizerProgressEventHandler ); bruteForceOptimizer.Run( 10000 , ! wFLagFixedPortfolioBruteForceOptimizableParametersManager.TotalIterations ); BruteForceOptimizableParameters bestParameters = --- 373,380 ---- bruteForceOptimizer.NewProgress += new NewProgressEventHandler( ! this.newBruteForceOptimizerProgressEventHandler ); bruteForceOptimizer.Run( 10000 , ! wFLagFixedPortfolioBruteForceOptimizableParametersManager.TotalIterations ); BruteForceOptimizableParameters bestParameters = *************** *** 379,383 **** this.wFLagChosenPositions = ( WFLagWeightedPositions )wFLagFixedPortfolioBruteForceOptimizableParametersManager.Decode( ! bestParameters ); // this.setWeightedPositions( wFLagWeightedPositions ); --- 383,387 ---- this.wFLagChosenPositions = ( WFLagWeightedPositions )wFLagFixedPortfolioBruteForceOptimizableParametersManager.Decode( ! bestParameters ); // this.setWeightedPositions( wFLagWeightedPositions ); *************** *** 387,391 **** WFLagEligibleTickers eligibleTickersForDrivingPositions , WFLagEligibleTickers eligibleTickersForPortfolioPositions , ! EndOfDayDateTime now ) { this.setDecoder( eligibleTickersForDrivingPositions , now ); --- 391,395 ---- WFLagEligibleTickers eligibleTickersForDrivingPositions , WFLagEligibleTickers eligibleTickersForPortfolioPositions , ! DateTime now ) { this.setDecoder( eligibleTickersForDrivingPositions , now ); |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:21:24
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18316/WFLagDebugger/WFLagDebugPositions Modified Files: WFLagDebugPositions.cs WFLagDebugPositionsEndOfDayTimerHandler.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WFLagDebugPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions/WFLagDebugPositions.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** WFLagDebugPositions.cs 28 Oct 2007 19:16:07 -0000 1.6 --- WFLagDebugPositions.cs 29 Sep 2008 21:20:54 -0000 1.7 *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 91,105 **** this.endOfDayTimer = new IndexBasedEndOfDayTimer( ! new EndOfDayDateTime( this.preSampleFirstDateTime , ! EndOfDaySpecificTime.MarketOpen ), this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WFLagDebugPositions" , ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ) ); } private void run_initializeEndOfDayTimerHandler() --- 91,107 ---- this.endOfDayTimer = new IndexBasedEndOfDayTimer( ! HistoricalEndOfDayTimer.GetMarketOpen( this.preSampleFirstDateTime ) , ! // new EndOfDayDateTime( this.preSampleFirstDateTime , ! // EndOfDaySpecificTime.MarketOpen ), ! this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WFLagDebugPositions" , ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ) ); } private void run_initializeEndOfDayTimerHandler() *************** *** 107,118 **** this.endOfDayTimerHandler = new WFLagDebugPositionsEndOfDayTimerHandler( ! this.account , this.wFLagWeightedPositions ); } ! public void marketOpenEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Transactions.Count == 0 ) this.account.AddCash( 30000 ); } #region oneHourAfterMarketCloseEventHandler #region getEquityLineForSignedTickers --- 109,121 ---- this.endOfDayTimerHandler = new WFLagDebugPositionsEndOfDayTimerHandler( ! this.account , this.wFLagWeightedPositions ); } ! public void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if ( this.account.Transactions.Count == 0 ) this.account.AddCash( 30000 ); } + #region oneHourAfterMarketCloseEventHandler #region getEquityLineForSignedTickers *************** *** 124,128 **** /// <returns></returns> private Hashtable getVirtualQuantities( ICollection positions , ! DateTime dateTime ) { Hashtable virtualQuantities = new Hashtable(); --- 127,131 ---- /// <returns></returns> private Hashtable getVirtualQuantities( ICollection positions , ! DateTime dateTime ) { Hashtable virtualQuantities = new Hashtable(); *************** *** 133,141 **** SignedTicker signedTicker = new SignedTicker( stringForSignedTicker ); string ticker = signedTicker.Ticker; ! EndOfDayDateTime endOfDayDateTime = ! new EndOfDayDateTime( dateTime , EndOfDaySpecificTime.MarketClose ); double tickerQuote = this.historicalQuoteProvider.GetMarketValue( ! ticker , endOfDayDateTime ); double virtualQuantity = valueForEachPosition / tickerQuote; if ( signedTicker.IsShort ) --- 136,145 ---- SignedTicker signedTicker = new SignedTicker( stringForSignedTicker ); string ticker = signedTicker.Ticker; ! DateTime dateTimeOnClose = ! HistoricalEndOfDayTimer.GetMarketClose( dateTime ); ! // new EndOfDayDateTime( dateTime , EndOfDaySpecificTime.MarketClose ); double tickerQuote = this.historicalQuoteProvider.GetMarketValue( ! ticker , dateTimeOnClose ); double virtualQuantity = valueForEachPosition / tickerQuote; if ( signedTicker.IsShort ) *************** *** 151,155 **** cash / drivingTickerVirtualQuantities.Count; foreach ( double virtualQuantity in ! drivingTickerVirtualQuantities.Values ) { if ( virtualQuantity > 0 ) --- 155,159 ---- cash / drivingTickerVirtualQuantities.Count; foreach ( double virtualQuantity in ! drivingTickerVirtualQuantities.Values ) { if ( virtualQuantity > 0 ) *************** *** 163,175 **** } private double getPortfolioValueForSignedTickers( DateTime dateTime , ! Hashtable tickerVirtualQuantities ) { double portfolioValueForDrivingPositions = 0; foreach( string ticker in tickerVirtualQuantities.Keys ) { ! EndOfDayDateTime endOfDayDateTime = new EndOfDayDateTime( ! dateTime , EndOfDaySpecificTime.MarketClose ); double tickerQuote = this.historicalQuoteProvider.GetMarketValue( ! ticker , endOfDayDateTime ); double virtualQuantity = (double)tickerVirtualQuantities[ ticker ]; portfolioValueForDrivingPositions += virtualQuantity * tickerQuote; --- 167,182 ---- } private double getPortfolioValueForSignedTickers( DateTime dateTime , ! Hashtable tickerVirtualQuantities ) { double portfolioValueForDrivingPositions = 0; foreach( string ticker in tickerVirtualQuantities.Keys ) { ! DateTime dateTimeOnClose = ! HistoricalEndOfDayTimer.GetMarketClose( ! dateTime ); ! // new EndOfDayDateTime( ! // dateTime , EndOfDaySpecificTime.MarketClose ); double tickerQuote = this.historicalQuoteProvider.GetMarketValue( ! ticker , dateTimeOnClose ); double virtualQuantity = (double)tickerVirtualQuantities[ ticker ]; portfolioValueForDrivingPositions += virtualQuantity * tickerQuote; *************** *** 186,196 **** Hashtable virtualQuantities = this.getVirtualQuantities( signedTickers , ! (DateTime)equityLineForPortfolioPositions.GetKey( 0 ) ); ! double cash = this.getCash( virtualQuantities ); foreach( DateTime dateTime in ! equityLineForPortfolioPositions.Keys ) equityLineForSignedTickers.Add( dateTime , ! cash + this.getPortfolioValueForSignedTickers( dateTime , ! virtualQuantities ) ); return equityLineForSignedTickers; } --- 193,203 ---- Hashtable virtualQuantities = this.getVirtualQuantities( signedTickers , ! (DateTime)equityLineForPortfolioPositions.GetKey( 0 ) ); ! double cash = this.getCash( virtualQuantities ); foreach( DateTime dateTime in ! equityLineForPortfolioPositions.Keys ) equityLineForSignedTickers.Add( dateTime , ! cash + this.getPortfolioValueForSignedTickers( dateTime , ! virtualQuantities ) ); return equityLineForSignedTickers; } *************** *** 210,230 **** EquityLine equityLineForWeightedPositions = weightedPositions.GetVirtualEquityLine( ! 30000 , report.AccountReport.EquityLine ); report.AddEquityLine( equityLineForWeightedPositions , ! color ); } public void oneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if ( ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime > ! this.postSampleLastDateTime ) { // the simulation has reached the ending date ! this.account.EndOfDayTimer.Stop(); Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "WFLag debug positions" , 1 , ! new EndOfDayDateTime( this.postSampleLastDateTime , ! EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark , false ); // EquityLine equityLineForDrivingPositions = --- 217,240 ---- EquityLine equityLineForWeightedPositions = weightedPositions.GetVirtualEquityLine( ! 30000 , report.AccountReport.EquityLine ); report.AddEquityLine( equityLineForWeightedPositions , ! color ); } public void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! if ( ( ( Timer )sender ).GetCurrentDateTime() > ! this.postSampleLastDateTime ) { // the simulation has reached the ending date ! this.account.Timer.Stop(); Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( ! "WFLag debug positions" , 1 , ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( ! this.postSampleLastDateTime ) , ! // new EndOfDayDateTime( this.postSampleLastDateTime , ! // EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark , false ); // EquityLine equityLineForDrivingPositions = *************** *** 246,249 **** --- 256,271 ---- } #endregion + + private void newDateTimeEventHandler( + Object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + this.marketOpenEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + // this.marketCloseEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + } + public void Run() { *************** *** 252,263 **** run_initializeAccount(); run_initializeEndOfDayTimerHandler(); ! this.endOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( this.marketOpenEventHandler ); ! this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! new FiveMinutesBeforeMarketCloseEventHandler( ! this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.oneHourAfterMarketCloseEventHandler ); this.endOfDayTimer.Start(); } --- 274,289 ---- run_initializeAccount(); run_initializeEndOfDayTimerHandler(); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( this.marketOpenEventHandler ); ! // this.endOfDayTimer.FiveMinutesBeforeMarketClose += ! // new FiveMinutesBeforeMarketCloseEventHandler( ! // this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.oneHourAfterMarketCloseEventHandler ); this.endOfDayTimer.Start(); } Index: WFLagDebugPositionsEndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions/WFLagDebugPositionsEndOfDayTimerHandler.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagDebugPositionsEndOfDayTimerHandler.cs 28 Oct 2007 19:16:48 -0000 1.3 --- WFLagDebugPositionsEndOfDayTimerHandler.cs 29 Sep 2008 21:20:54 -0000 1.4 *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 35,39 **** /// Strategy to debug the log for the current positions /// </summary> ! public class WFLagDebugPositionsEndOfDayTimerHandler { private Account account; --- 35,39 ---- /// Strategy to debug the log for the current positions /// </summary> ! public class WFLagDebugPositionsEndOfDayTimerHandler : EndOfDayTimerHandler { private Account account; *************** *** 47,57 **** this.wFLagWeightedPositions = wFLagWeightedPositions; } ! #region FiveMinutesBeforeMarketCloseEventHandler private double todayTotalGainForLinearCombination() { double todayTotalGain = 0; ! DateTime today = this.account.EndOfDayTimer.GetCurrentTime().DateTime; foreach ( WeightedPosition weightedPosition in ! this.wFLagWeightedPositions.DrivingWeightedPositions.Values ) todayTotalGain += weightedPosition.GetCloseToCloseDailyReturn( today ); --- 47,58 ---- this.wFLagWeightedPositions = wFLagWeightedPositions; } ! ! #region marketCloseEventHandler private double todayTotalGainForLinearCombination() { double todayTotalGain = 0; ! DateTime today = this.account.Timer.GetCurrentDateTime(); foreach ( WeightedPosition weightedPosition in ! this.wFLagWeightedPositions.DrivingWeightedPositions.Values ) todayTotalGain += weightedPosition.GetCloseToCloseDailyReturn( today ); *************** *** 77,84 **** WeightedPosition weightedPosition = this.wFLagWeightedPositions.PortfolioWeightedPositions.GetWeightedPosition( ! firstAccountPosition.Instrument.Key ); bool isReversed = ( ( weightedPosition.IsLong && firstAccountPosition.IsShort ) || ! ( weightedPosition.IsShort && firstAccountPosition.IsLong ) ); // bool isReversed = // this.wFLagChosenPositions.PortfolioWeightedPositions.ContainsKey( --- 78,85 ---- WeightedPosition weightedPosition = this.wFLagWeightedPositions.PortfolioWeightedPositions.GetWeightedPosition( ! firstAccountPosition.Instrument.Key ); bool isReversed = ( ( weightedPosition.IsLong && firstAccountPosition.IsShort ) || ! ( weightedPosition.IsShort && firstAccountPosition.IsLong ) ); // bool isReversed = // this.wFLagChosenPositions.PortfolioWeightedPositions.ContainsKey( *************** *** 86,99 **** return isReversed; } ! private bool fiveMinutesBeforeMarketCloseEventHandler_arePositionsToBeClosed() { bool returnValue = ( this.account.Portfolio.Count > 0 ) && ( ( this.isDrivingPositionsTodayValueHigherThanYesterday() && ! this.isCurrentlyReversed() ) || ! ( !this.isDrivingPositionsTodayValueHigherThanYesterday() && ! !this.isCurrentlyReversed() ) ); return returnValue; } ! private void fiveMinutesBeforeMarketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); --- 87,100 ---- return isReversed; } ! private bool marketCloseEventHandler_arePositionsToBeClosed() { bool returnValue = ( this.account.Portfolio.Count > 0 ) && ( ( this.isDrivingPositionsTodayValueHigherThanYesterday() && ! this.isCurrentlyReversed() ) || ! ( !this.isDrivingPositionsTodayValueHigherThanYesterday() && ! !this.isCurrentlyReversed() ) ); return returnValue; } ! private void marketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); *************** *** 103,107 **** this.account.ClosePosition( ticker ); } ! private bool fiveMinutesBeforeMarketCloseEventHandler_arePositionsToBeOpened() { bool returnValue = ( this.account.Portfolio.Count == 0 ); --- 104,108 ---- this.account.ClosePosition( ticker ); } ! private bool marketCloseEventHandler_arePositionsToBeOpened() { bool returnValue = ( this.account.Portfolio.Count == 0 ); *************** *** 127,168 **** this.account.AddOrder( order ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_openThisPosition( WeightedPosition weightedPosition ) { this.openPosition( weightedPosition ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_openOppositePosition( WeightedPosition weightedPosition ) { ! this.fiveMinutesBeforeMarketCloseEventHandler_openThisPosition( weightedPosition.GetOppositeWeightedPosition() ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_openPosition( WeightedPosition weightedPosition ) { if ( this.isDrivingPositionsTodayValueHigherThanYesterday() ) ! fiveMinutesBeforeMarketCloseEventHandler_openThisPosition( weightedPosition ); else ! fiveMinutesBeforeMarketCloseEventHandler_openOppositePosition( weightedPosition ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_openPositions() { // this.chosenTickers.SetTickers( this.bestPerformingTickers , this.account ); foreach ( WeightedPosition weightedPosition in ! this.wFLagWeightedPositions.PortfolioWeightedPositions.Values ) ! this.fiveMinutesBeforeMarketCloseEventHandler_openPosition( weightedPosition ); } ! public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if ( this.fiveMinutesBeforeMarketCloseEventHandler_arePositionsToBeClosed() ) ! this.fiveMinutesBeforeMarketCloseEventHandler_closePositions(); ! if ( this.fiveMinutesBeforeMarketCloseEventHandler_arePositionsToBeOpened() ) ! fiveMinutesBeforeMarketCloseEventHandler_openPositions(); } #endregion } } --- 128,181 ---- this.account.AddOrder( order ); } ! private void marketCloseEventHandler_openThisPosition( WeightedPosition weightedPosition ) { this.openPosition( weightedPosition ); } ! private void marketCloseEventHandler_openOppositePosition( WeightedPosition weightedPosition ) { ! this.marketCloseEventHandler_openThisPosition( weightedPosition.GetOppositeWeightedPosition() ); } ! private void marketCloseEventHandler_openPosition( WeightedPosition weightedPosition ) { if ( this.isDrivingPositionsTodayValueHigherThanYesterday() ) ! this.marketCloseEventHandler_openThisPosition( weightedPosition ); else ! this.marketCloseEventHandler_openOppositePosition( weightedPosition ); } ! private void marketCloseEventHandler_openPositions() { // this.chosenTickers.SetTickers( this.bestPerformingTickers , this.account ); foreach ( WeightedPosition weightedPosition in ! this.wFLagWeightedPositions.PortfolioWeightedPositions.Values ) ! this.marketCloseEventHandler_openPosition( weightedPosition ); } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! if ( this.marketCloseEventHandler_arePositionsToBeClosed() ) ! this.marketCloseEventHandler_closePositions(); ! if ( this.marketCloseEventHandler_arePositionsToBeOpened() ) ! this.marketCloseEventHandler_openPositions(); } #endregion + + protected override void marketOpenEventHandler( + Object sender , DateTime dateTime ) + { + ; + } + + protected override void oneHourAfterMarketCloseEventHandler( + Object sender , DateTime dateTime ) + { + ; + } } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:21:22
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/ReportDebugger In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18335/ReportDebugger Modified Files: WFMultiOneRankDebugEndOfDayTimerHandler.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WFMultiOneRankDebugEndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/ReportDebugger/WFMultiOneRankDebugEndOfDayTimerHandler.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFMultiOneRankDebugEndOfDayTimerHandler.cs 27 Nov 2005 00:04:08 -0000 1.2 --- WFMultiOneRankDebugEndOfDayTimerHandler.cs 29 Sep 2008 21:20:55 -0000 1.3 *************** *** 3,7 **** WFMultiOneRankDebugEndOfDayTimerHandler.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- WFMultiOneRankDebugEndOfDayTimerHandler.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 35,39 **** /// Strategy to debug the in sample optimization /// </summary> ! public class WFMultiOneRankDebugEndOfDayTimerHandler { private Account account; --- 35,40 ---- /// Strategy to debug the in sample optimization /// </summary> ! public class WFMultiOneRankDebugEndOfDayTimerHandler : ! QuantProject.Business.Strategies.EndOfDayTimerHandler { private Account account; *************** *** 46,49 **** --- 47,51 ---- this.signedTickers = signedTickers; } + #region FiveMinutesBeforeMarketCloseEventHandler private string getTicker( string signedTicker ) *************** *** 75,79 **** this.account.ClosePosition( ticker ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); --- 77,81 ---- this.account.ClosePosition( ticker ); } ! private void marketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); *************** *** 90,100 **** double todayMarketValueAtClose = this.account.DataStreamer.GetCurrentBid( ticker ); ! EndOfDayDateTime yesterdayAtClose = new ! EndOfDayDateTime( ! this.account.EndOfDayTimer.GetCurrentTime().DateTime.AddDays( - 1 ) , ! EndOfDaySpecificTime.MarketClose ); double yesterdayMarketValueAtClose = historicalAdjustedQuoteProvider.GetMarketValue( ! ticker , yesterdayAtClose ); double returnForLongPosition = ( todayMarketValueAtClose / yesterdayMarketValueAtClose ) - 1; --- 92,104 ---- double todayMarketValueAtClose = this.account.DataStreamer.GetCurrentBid( ticker ); ! DateTime yesterdayAtClose = ! HistoricalEndOfDayTimer.GetMarketClose( ! this.account.Timer.GetCurrentDateTime().AddDays( - 1 ) ); ! // new EndOfDayDateTime( ! // this.account.EndOfDayTimer.GetCurrentTime().DateTime.AddDays( - 1 ) , ! // EndOfDaySpecificTime.MarketClose ); double yesterdayMarketValueAtClose = historicalAdjustedQuoteProvider.GetMarketValue( ! ticker , yesterdayAtClose ); double returnForLongPosition = ( todayMarketValueAtClose / yesterdayMarketValueAtClose ) - 1; *************** *** 126,132 **** OrderType orderType = this.getOrderType( signedTicker ); bool returnValue = ( ( ( orderType == ! OrderType.MarketBuy ) && ( positionType == PositionType.Short ) ) || ! ( orderType == OrderType.MarketSellShort ) && ! ( positionType == PositionType.Long ) ); return returnValue; } --- 130,136 ---- OrderType orderType = this.getOrderType( signedTicker ); bool returnValue = ( ( ( orderType == ! OrderType.MarketBuy ) && ( positionType == PositionType.Short ) ) || ! ( orderType == OrderType.MarketSellShort ) && ! ( positionType == PositionType.Long ) ); return returnValue; } *************** *** 134,138 **** { return this.isCurrentlyReversed( this.signedTickers[ 0 ] ); ! } private long getQuantity( string ticker ) { --- 138,142 ---- { return this.isCurrentlyReversed( this.signedTickers[ 0 ] ); ! } private long getQuantity( string ticker ) { *************** *** 150,154 **** long quantity = this.getQuantity( ticker ); Order order = new Order( orderType , new Instrument( ticker ) , ! quantity ); this.account.AddOrder( order ); } --- 154,158 ---- long quantity = this.getQuantity( ticker ); Order order = new Order( orderType , new Instrument( ticker ) , ! quantity ); this.account.AddOrder( order ); } *************** *** 157,161 **** { this.openPosition( this.getTicker( signedTicker ) , ! this.getOrderType( signedTicker ) ); } private void fiveMinutesBeforeMarketCloseEventHandler_openReversePosition( --- 161,165 ---- { this.openPosition( this.getTicker( signedTicker ) , ! this.getOrderType( signedTicker ) ); } private void fiveMinutesBeforeMarketCloseEventHandler_openReversePosition( *************** *** 175,179 **** signedTicker ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_openPositions() { // this.chosenTickers.SetTickers( this.bestPerformingTickers , this.account ); --- 179,183 ---- signedTicker ); } ! private void marketCloseEventHandler_openPositions() { // this.chosenTickers.SetTickers( this.bestPerformingTickers , this.account ); *************** *** 182,209 **** signedTicker ); } ! private bool fiveMinutesBeforeMarketCloseEventHandler_arePositionsToBeClosed() { bool returnValue = ( this.account.Portfolio.Count > 0 ) && ( ( this.isLinearCombinationTodayValueHigherThanYesterday() && ! this.isCurrentlyReversed() ) || ! ( !this.isLinearCombinationTodayValueHigherThanYesterday() && ! !this.isCurrentlyReversed() ) ); return returnValue; } ! private bool fiveMinutesBeforeMarketCloseEventHandler_arePositionsToBeOpened() { bool returnValue = ( this.account.Portfolio.Count == 0 ); return returnValue; } ! public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if ( this.fiveMinutesBeforeMarketCloseEventHandler_arePositionsToBeClosed() ) ! this.fiveMinutesBeforeMarketCloseEventHandler_closePositions(); ! if ( this.fiveMinutesBeforeMarketCloseEventHandler_arePositionsToBeOpened() ) ! fiveMinutesBeforeMarketCloseEventHandler_openPositions(); } #endregion } } --- 186,225 ---- signedTicker ); } ! private bool marketCloseEventHandler_arePositionsToBeClosed() { bool returnValue = ( this.account.Portfolio.Count > 0 ) && ( ( this.isLinearCombinationTodayValueHigherThanYesterday() && ! this.isCurrentlyReversed() ) || ! ( !this.isLinearCombinationTodayValueHigherThanYesterday() && ! !this.isCurrentlyReversed() ) ); return returnValue; } ! private bool marketCloseEventHandler_arePositionsToBeOpened() { bool returnValue = ( this.account.Portfolio.Count == 0 ); return returnValue; } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! if ( this.marketCloseEventHandler_arePositionsToBeClosed() ) ! this.marketCloseEventHandler_closePositions(); ! if ( this.marketCloseEventHandler_arePositionsToBeOpened() ) ! marketCloseEventHandler_openPositions(); } #endregion + protected override void marketOpenEventHandler( + Object sender , DateTime dateTime ) + { + ; + } + + protected override void oneHourAfterMarketCloseEventHandler( + Object sender , DateTime dateTime ) + { + ; + } + } } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/BruteForce In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18260/InSample/InSampleChoosers/BruteForce Modified Files: PairsTradingBruteForceChooser.cs PairsTradingBruteForceOptimizableParametersManager.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: PairsTradingBruteForceChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/BruteForce/PairsTradingBruteForceChooser.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PairsTradingBruteForceChooser.cs 1 Apr 2008 21:31:27 -0000 1.2 --- PairsTradingBruteForceChooser.cs 29 Sep 2008 21:20:45 -0000 1.3 *************** *** 39,42 **** --- 39,43 ---- /// brute force IInSampleChooser for the pairs trading strategy /// </summary> + [Serializable] public class PairsTradingBruteForceChooser : BruteForceChooser { Index: PairsTradingBruteForceOptimizableParametersManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/BruteForce/PairsTradingBruteForceOptimizableParametersManager.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PairsTradingBruteForceOptimizableParametersManager.cs 20 Apr 2008 17:25:56 -0000 1.4 --- PairsTradingBruteForceOptimizableParametersManager.cs 29 Sep 2008 21:20:45 -0000 1.5 *************** *** 41,44 **** --- 41,45 ---- /// two opposite WeightedPosition are highly correlated too) /// </summary> + [Serializable] public class PairsTradingBruteForceOptimizableParametersManager : BruteForceOptimizableParametersManagerForBalancedVolatility |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:21:05
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/Genetic In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18260/InSample/InSampleChoosers/Genetic Modified Files: PairsTradingGeneticChooser.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: PairsTradingGeneticChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/Genetic/PairsTradingGeneticChooser.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PairsTradingGeneticChooser.cs 27 Feb 2008 21:16:20 -0000 1.1 --- PairsTradingGeneticChooser.cs 29 Sep 2008 21:20:46 -0000 1.2 *************** *** 39,42 **** --- 39,43 ---- /// genetic IInSampleChooser for the pairs trading strategy /// </summary> + [Serializable] public class PairsTradingGeneticChooser : GeneticChooser { *************** *** 46,50 **** IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , ! IHistoricalQuoteProvider historicalQuoteProvider , double crossoverRate , double mutationRate , double elitismRate , int populationSizeForGeneticOptimizer , --- 47,51 ---- IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , ! HistoricalMarketValueProvider historicalMarketValueProvider , double crossoverRate , double mutationRate , double elitismRate , int populationSizeForGeneticOptimizer , *************** *** 57,61 **** decoderForTestingPositions , fitnessEvaluator , ! historicalQuoteProvider , crossoverRate , mutationRate , --- 58,62 ---- decoderForTestingPositions , fitnessEvaluator , ! historicalMarketValueProvider , crossoverRate , mutationRate , |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:46
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16791/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO Modified Files: EndOfDayTimerHandlerBiasedPVO.cs EndOfDayTimerHandlerBiasedPVO_OTC.cs RunBiasedPVO.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: EndOfDayTimerHandlerBiasedPVO_OTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/EndOfDayTimerHandlerBiasedPVO_OTC.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerBiasedPVO_OTC.cs 9 Mar 2008 22:40:51 -0000 1.2 --- EndOfDayTimerHandlerBiasedPVO_OTC.cs 29 Sep 2008 21:18:34 -0000 1.3 *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Data; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; using System.Data; *************** *** 49,249 **** { /// <summary> ! /// Implements MarketOpenEventHandler and MarketCloseEventHandler ! /// These handlers contain the core strategy for the Biased Portfolio Value ! /// Oscillator, using Open To Close returns ! /// </summary> ! [Serializable] ! public class EndOfDayTimerHandlerBiasedPVO_OTC : EndOfDayTimerHandlerBiasedPVO ! { ! ! public EndOfDayTimerHandlerBiasedPVO_OTC(string tickerGroupID, int numberOfEligibleTickers, ! double minPriceForTickersToBeChosen, ! double maxPriceForTickersToBeChosen, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! Account account, ! string pathOfFileContainingGenomes, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, ! int numOfDifferentGenomesToEvaluateOutOfSample, ! bool resetThresholdsBeforeCheckingOutOfSample, ! int numDaysForThresholdsReComputation, ! double numOfStdDevForThresholdsComputation, ! double maxCoefficientForDegreeComputationOfCrossingThreshold, ! bool buyOnlyPositionsThatAreMovingTogether, ! bool doNotOpenReversedPositionsThatHaveJustBeenClosed, ! int numDaysOfStayingOnTheMarket, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! int numDaysBetweenEachOptimization, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double minimumAcceptableGain): ! base(tickerGroupID, numberOfEligibleTickers, ! minPriceForTickersToBeChosen, ! maxPriceForTickersToBeChosen, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! account, ! pathOfFileContainingGenomes, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, ! numOfDifferentGenomesToEvaluateOutOfSample, ! resetThresholdsBeforeCheckingOutOfSample, ! numDaysForThresholdsReComputation, ! numOfStdDevForThresholdsComputation, ! maxCoefficientForDegreeComputationOfCrossingThreshold, ! buyOnlyPositionsThatAreMovingTogether, ! doNotOpenReversedPositionsThatHaveJustBeenClosed, ! 1, numDaysOfStayingOnTheMarket, ! minLevelForOversoldThreshold, ! maxLevelForOversoldThreshold, ! minLevelForOverboughtThreshold, ! maxLevelForOverboughtThreshold, ! divisorForThresholdComputation, ! symmetricalThresholds, ! overboughtMoreThanOversoldForFixedPortfolio, ! numDaysBetweenEachOptimization, ! portfolioType, maxAcceptableCloseToCloseDrawdown, ! minimumAcceptableGain) ! ! { ! } ! #region MarketOpen ! ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! if ( this.account.Portfolio.Count == 0 && ! this.weightedPositionsToEvaluateOutOfSample[0] != null ) ! //portfolio is empty and optimization has been already launched ! this.openPositions( (IndexBasedEndOfDayTimer)sender ); ! } ! ! protected override void openPositions_chooseGenome_resetThresholds(DateTime today) ! { for(int i = 0; i < this.weightedPositionsToEvaluateOutOfSample.Length; i++) ! { this.currentOversoldThreshold[i] = (double)this.maxLevelForOversoldThreshold/ (double)this.divisorForThresholdComputation; ! this.currentOverboughtThreshold[i] = (double)this.maxLevelForOverboughtThreshold/ (double)this.divisorForThresholdComputation; ! } ! // UPDATE WITH DailyOpenToCloseIntervals ! // ReturnsManager returnsManager = new ReturnsManager( ! // new CloseToOpenIntervals(new EndOfDayDateTime(today.AddDays(-this.numDaysForThresholdsReComputation), EndOfDaySpecificTime.MarketClose), // new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketOpen), // this.benchmark), // new HistoricalAdjustedQuoteProvider() ); ! // //double returnsAverage; ! // double returnsStdDev; ! // for(int i = 0; i < this.weightedPositionsToEvaluateOutOfSample.Length; i++) ! // { ! //// returnsAverage = BasicFunctions.GetSimpleAverage( ! //// this.weightedPositionsToEvaluateOutOfSample[i].GetReturns(returnsManager) ); // returnsStdDev = BasicFunctions.GetStdDev( ! // this.weightedPositionsToEvaluateOutOfSample[i].GetReturns(returnsManager) ); ! // this.currentOversoldThreshold[i] = -this.numOfStdDevForThresholdsComputation * returnsStdDev; ! // this.currentOverboughtThreshold[i] = this.numOfStdDevForThresholdsComputation * returnsStdDev; ! // } ! } ! //NEW IMPLEMENTATION of chooseBestGenome, now named chooseGenome ! //sets currentGenomeIndex with the first genome's index that crosses an overbought/oversold threshold with the ! //"acceptable" degree and sets currentWeightedPositionsGainOrLoss accordingly ! protected override void openPositions_chooseGenome(IndexBasedEndOfDayTimer timer) ! { ! DateTime today = timer.GetCurrentTime().DateTime; ! DateTime previousTradingDay = ! timer.GetPreviousDateTime(1); ! ReturnsManager returnsManager = new ReturnsManager( ! new CloseToOpenIntervals(new EndOfDayDateTime(previousTradingDay, EndOfDaySpecificTime.MarketClose), ! new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketOpen), ! this.benchmark), ! new HistoricalAdjustedQuoteProvider() ); ! if(this.resetThresholdsBeforeCheckingOutOfSample) ! this.openPositions_chooseGenome_resetThresholds(today); ! this.currentWeightedPositionsGainOrLoss = double.MinValue; ! double currentWeightedPositionsGainOrLoss_temp = double.MinValue; ! for(int i = 0; i < this.numOfDifferentGenomesToEvaluateOutOfSample; i++) ! { ! currentWeightedPositionsGainOrLoss_temp = ! this.getCurrentWeightedPositionsGainOrLoss( ! timer, returnsManager, i); if( currentWeightedPositionsGainOrLoss_temp != double.MinValue && ! ( this.buyOnlyPositionsThatAreMovingTogether == false || ! ( this.buyOnlyPositionsThatAreMovingTogether == true && ! this.areAllTickersMovingTogetherUpOrDown(timer, returnsManager, i) == true ) ) ) ! //currentWeightedPositionsGainOrLoss_temp has been properly computed and ! //only positions that are moving together can be bought ! { ! if( (currentWeightedPositionsGainOrLoss_temp >= this.currentOverboughtThreshold[i] && ! currentWeightedPositionsGainOrLoss_temp <= this.maxCoefficientForDegreeComputationOfCrossingThreshold * ! this.currentOverboughtThreshold[i] ) || ! (currentWeightedPositionsGainOrLoss_temp <= - this.currentOversoldThreshold[i] && ! Math.Abs(currentWeightedPositionsGainOrLoss_temp) <= this.maxCoefficientForDegreeComputationOfCrossingThreshold * ! this.currentOversoldThreshold[i] ) ) ! // if the current genome matches the requested criteria ! { this.currentGenomeIndex = i; this.currentWeightedPositionsGainOrLoss = currentWeightedPositionsGainOrLoss_temp; i = this.numOfDifferentGenomesToEvaluateOutOfSample; //exit from for ! } ! } ! } ! } ! #endregion ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! if(this.account.Portfolio.Count > 0) ! { ! this.lastWeightedPositionsClosed = AccountManager.GetWeightedPositions(this.account); AccountManager.ClosePositions(this.account); ! } ! } ! ! #region OneHourAfterMarketCloseEventHandler ! ! protected override void setTickers(DateTime currentDate, ! bool setGenomeCounter) ! { ! DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! this.iGenomeManager = ! new GenomeManagerPVO_OTC(setOfTickersToBeOptimized, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfTickersToBeChosen, ! this.minLevelForOversoldThreshold, ! this.maxLevelForOversoldThreshold, ! this.minLevelForOverboughtThreshold, ! this.maxLevelForOverboughtThreshold, ! this.divisorForThresholdComputation, ! this.symmetricalThresholds, ! this.overboughtMoreThanOversoldForFixedPortfolio, ! this.portfolioType, this.benchmark); ! GeneticOptimizer GO = new GeneticOptimizer(this.iGenomeManager, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer, ! this.seedForRandomGenerator); ! // if(setGenomeCounter) ! // this.genomeCounter = new GenomeCounter(GO); ! GO.MutationRate = 0.1; ! GO.CrossoverRate = 0.85; ! GO.Run(false); ! ! this.setTickers_updateTickersWeightsAndThresholdsAndAddGenomesForLog(GO, setOfTickersToBeOptimized.Rows.Count); ! ! } ! ! ! #endregion ! } } --- 49,252 ---- { /// <summary> ! /// Implements MarketOpenEventHandler and MarketCloseEventHandler ! /// These handlers contain the core strategy for the Biased Portfolio Value ! /// Oscillator, using Open To Close returns ! /// </summary> ! [Serializable] ! public class EndOfDayTimerHandlerBiasedPVO_OTC : EndOfDayTimerHandlerBiasedPVO ! { ! ! public EndOfDayTimerHandlerBiasedPVO_OTC(string tickerGroupID, int numberOfEligibleTickers, ! double minPriceForTickersToBeChosen, ! double maxPriceForTickersToBeChosen, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! Account account, ! string pathOfFileContainingGenomes, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, ! int numOfDifferentGenomesToEvaluateOutOfSample, ! bool resetThresholdsBeforeCheckingOutOfSample, ! int numDaysForThresholdsReComputation, ! double numOfStdDevForThresholdsComputation, ! double maxCoefficientForDegreeComputationOfCrossingThreshold, ! bool buyOnlyPositionsThatAreMovingTogether, ! bool doNotOpenReversedPositionsThatHaveJustBeenClosed, ! int numDaysOfStayingOnTheMarket, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! int numDaysBetweenEachOptimization, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double minimumAcceptableGain): ! base(tickerGroupID, numberOfEligibleTickers, ! minPriceForTickersToBeChosen, ! maxPriceForTickersToBeChosen, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! account, ! pathOfFileContainingGenomes, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, ! numOfDifferentGenomesToEvaluateOutOfSample, ! resetThresholdsBeforeCheckingOutOfSample, ! numDaysForThresholdsReComputation, ! numOfStdDevForThresholdsComputation, ! maxCoefficientForDegreeComputationOfCrossingThreshold, ! buyOnlyPositionsThatAreMovingTogether, ! doNotOpenReversedPositionsThatHaveJustBeenClosed, ! 1, numDaysOfStayingOnTheMarket, ! minLevelForOversoldThreshold, ! maxLevelForOversoldThreshold, ! minLevelForOverboughtThreshold, ! maxLevelForOverboughtThreshold, ! divisorForThresholdComputation, ! symmetricalThresholds, ! overboughtMoreThanOversoldForFixedPortfolio, ! numDaysBetweenEachOptimization, ! portfolioType, maxAcceptableCloseToCloseDrawdown, ! minimumAcceptableGain) ! { ! ! } ! #region MarketOpen ! ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) ! { ! if ( this.account.Portfolio.Count == 0 && ! this.weightedPositionsToEvaluateOutOfSample[0] != null ) ! //portfolio is empty and optimization has been already launched ! this.openPositions( (IndexBasedEndOfDayTimer)sender ); ! } ! ! protected override void openPositions_chooseGenome_resetThresholds(DateTime today) ! { for(int i = 0; i < this.weightedPositionsToEvaluateOutOfSample.Length; i++) ! { this.currentOversoldThreshold[i] = (double)this.maxLevelForOversoldThreshold/ (double)this.divisorForThresholdComputation; ! this.currentOverboughtThreshold[i] = (double)this.maxLevelForOverboughtThreshold/ (double)this.divisorForThresholdComputation; ! } ! // UPDATE WITH DailyOpenToCloseIntervals ! // ReturnsManager returnsManager = new ReturnsManager( ! // new CloseToOpenIntervals(new EndOfDayDateTime(today.AddDays(-this.numDaysForThresholdsReComputation), EndOfDaySpecificTime.MarketClose), // new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketOpen), // this.benchmark), // new HistoricalAdjustedQuoteProvider() ); ! // //double returnsAverage; ! // double returnsStdDev; ! // for(int i = 0; i < this.weightedPositionsToEvaluateOutOfSample.Length; i++) ! // { ! //// returnsAverage = BasicFunctions.GetSimpleAverage( ! //// this.weightedPositionsToEvaluateOutOfSample[i].GetReturns(returnsManager) ); // returnsStdDev = BasicFunctions.GetStdDev( ! // this.weightedPositionsToEvaluateOutOfSample[i].GetReturns(returnsManager) ); ! // this.currentOversoldThreshold[i] = -this.numOfStdDevForThresholdsComputation * returnsStdDev; ! // this.currentOverboughtThreshold[i] = this.numOfStdDevForThresholdsComputation * returnsStdDev; ! // } ! } ! //NEW IMPLEMENTATION of chooseBestGenome, now named chooseGenome ! //sets currentGenomeIndex with the first genome's index that crosses an overbought/oversold threshold with the ! //"acceptable" degree and sets currentWeightedPositionsGainOrLoss accordingly ! protected override void openPositions_chooseGenome(IndexBasedEndOfDayTimer timer) ! { ! DateTime today = timer.GetCurrentDateTime(); ! DateTime previousTradingDay = ! timer.GetPreviousDateTime(1); ! ReturnsManager returnsManager = new ReturnsManager( ! new CloseToOpenIntervals( ! HistoricalEndOfDayTimer.GetMarketClose( previousTradingDay ) , ! HistoricalEndOfDayTimer.GetMarketOpen( today ) , ! // new EndOfDayDateTime(previousTradingDay, EndOfDaySpecificTime.MarketClose), ! // new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketOpen), ! this.benchmark), ! new HistoricalAdjustedQuoteProvider() ); ! if(this.resetThresholdsBeforeCheckingOutOfSample) ! this.openPositions_chooseGenome_resetThresholds(today); ! this.currentWeightedPositionsGainOrLoss = double.MinValue; ! double currentWeightedPositionsGainOrLoss_temp = double.MinValue; ! for(int i = 0; i < this.numOfDifferentGenomesToEvaluateOutOfSample; i++) ! { ! currentWeightedPositionsGainOrLoss_temp = ! this.getCurrentWeightedPositionsGainOrLoss( ! timer, returnsManager, i); if( currentWeightedPositionsGainOrLoss_temp != double.MinValue && ! ( this.buyOnlyPositionsThatAreMovingTogether == false || ! ( this.buyOnlyPositionsThatAreMovingTogether == true && ! this.areAllTickersMovingTogetherUpOrDown(timer, returnsManager, i) == true ) ) ) ! //currentWeightedPositionsGainOrLoss_temp has been properly computed and ! //only positions that are moving together can be bought ! { ! if( (currentWeightedPositionsGainOrLoss_temp >= this.currentOverboughtThreshold[i] && ! currentWeightedPositionsGainOrLoss_temp <= this.maxCoefficientForDegreeComputationOfCrossingThreshold * ! this.currentOverboughtThreshold[i] ) || ! (currentWeightedPositionsGainOrLoss_temp <= - this.currentOversoldThreshold[i] && ! Math.Abs(currentWeightedPositionsGainOrLoss_temp) <= this.maxCoefficientForDegreeComputationOfCrossingThreshold * ! this.currentOversoldThreshold[i] ) ) ! // if the current genome matches the requested criteria ! { this.currentGenomeIndex = i; this.currentWeightedPositionsGainOrLoss = currentWeightedPositionsGainOrLoss_temp; i = this.numOfDifferentGenomesToEvaluateOutOfSample; //exit from for ! } ! } ! } ! } ! #endregion ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) ! { ! if(this.account.Portfolio.Count > 0) ! { ! this.lastWeightedPositionsClosed = AccountManager.GetWeightedPositions(this.account); AccountManager.ClosePositions(this.account); ! } ! } ! ! #region OneHourAfterMarketCloseEventHandler ! ! protected override void setTickers(DateTime currentDate, ! bool setGenomeCounter) ! { ! DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! this.iGenomeManager = ! new GenomeManagerPVO_OTC(setOfTickersToBeOptimized, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfTickersToBeChosen, ! this.minLevelForOversoldThreshold, ! this.maxLevelForOversoldThreshold, ! this.minLevelForOverboughtThreshold, ! this.maxLevelForOverboughtThreshold, ! this.divisorForThresholdComputation, ! this.symmetricalThresholds, ! this.overboughtMoreThanOversoldForFixedPortfolio, ! this.portfolioType, this.benchmark); ! GeneticOptimizer GO = new GeneticOptimizer(this.iGenomeManager, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer, ! this.seedForRandomGenerator); ! // if(setGenomeCounter) ! // this.genomeCounter = new GenomeCounter(GO); ! GO.MutationRate = 0.1; ! GO.CrossoverRate = 0.85; ! GO.Run(false); ! ! this.setTickers_updateTickersWeightsAndThresholdsAndAddGenomesForLog(GO, setOfTickersToBeOptimized.Rows.Count); ! ! } ! ! ! #endregion ! } } Index: RunBiasedPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/RunBiasedPVO.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RunBiasedPVO.cs 19 Aug 2008 17:13:03 -0000 1.5 --- RunBiasedPVO.cs 29 Sep 2008 21:18:34 -0000 1.6 *************** *** 196,201 **** w.Write("\r\nOptimization each (num of days): {0}\r", this.numDaysBetweenEachOptimization.ToString()); w.Write("\r\nBenchmark: {0}\r", this.benchmark); ! w.Write("\r\nStart date: {0}\r", this.startDateTime.DateTime.ToLongDateString()); ! w.Write("\r\nEnd date: {0}\r", this.endDateTime.DateTime.ToLongDateString()); w.Write("\r\nNum of genomes to check out of sample: {0}\r", this.numOfDifferentGenomesToEvaluateOutOfSample.ToString()); w.Write("\r\nReset thresholds out of sample: {0}\r", this.resetThresholdsBeforeCheckingOutOfSample.ToString()); --- 196,201 ---- w.Write("\r\nOptimization each (num of days): {0}\r", this.numDaysBetweenEachOptimization.ToString()); w.Write("\r\nBenchmark: {0}\r", this.benchmark); ! w.Write("\r\nStart date: {0}\r", this.startDateTime.ToLongDateString()); ! w.Write("\r\nEnd date: {0}\r", this.endDateTime.ToLongDateString()); w.Write("\r\nNum of genomes to check out of sample: {0}\r", this.numOfDifferentGenomesToEvaluateOutOfSample.ToString()); w.Write("\r\nReset thresholds out of sample: {0}\r", this.resetThresholdsBeforeCheckingOutOfSample.ToString()); *************** *** 262,266 **** this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); --- 262,266 ---- this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentDateTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); Index: EndOfDayTimerHandlerBiasedPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/EndOfDayTimerHandlerBiasedPVO.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** EndOfDayTimerHandlerBiasedPVO.cs 19 Aug 2008 17:11:26 -0000 1.6 --- EndOfDayTimerHandlerBiasedPVO.cs 29 Sep 2008 21:18:34 -0000 1.7 *************** *** 142,147 **** //to avoid handlers in inherited classes ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; --- 142,147 ---- //to avoid handlers in inherited classes ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { ; *************** *** 224,235 **** protected virtual void openPositions_chooseGenome(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentTime().DateTime; DateTime firstMarketDayForOscillatingPeriod = timer.GetPreviousDateTime(this.numDaysForOscillatingPeriod); ReturnsManager returnsManager = new ReturnsManager( ! new CloseToCloseIntervals(new EndOfDayDateTime(firstMarketDayForOscillatingPeriod, EndOfDaySpecificTime.MarketClose), ! new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketClose), ! this.benchmark, ! this.numDaysForOscillatingPeriod), new HistoricalAdjustedQuoteProvider() ); if(this.resetThresholdsBeforeCheckingOutOfSample) --- 224,239 ---- protected virtual void openPositions_chooseGenome(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentDateTime(); DateTime firstMarketDayForOscillatingPeriod = timer.GetPreviousDateTime(this.numDaysForOscillatingPeriod); ReturnsManager returnsManager = new ReturnsManager( ! new CloseToCloseIntervals( ! HistoricalEndOfDayTimer.GetMarketClose( ! firstMarketDayForOscillatingPeriod ) , ! HistoricalEndOfDayTimer.GetMarketClose( today ) , ! // new EndOfDayDateTime(firstMarketDayForOscillatingPeriod, EndOfDaySpecificTime.MarketClose), ! // new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketClose), ! this.benchmark, ! this.numDaysForOscillatingPeriod), new HistoricalAdjustedQuoteProvider() ); if(this.resetThresholdsBeforeCheckingOutOfSample) *************** *** 401,405 **** { bool returnValue; ! DateTime currentTime = timer.GetCurrentTime().DateTime; DateTime firstDateOfOscillatingPeriod = timer.GetPreviousDateTime(this.numDaysForOscillatingPeriod); --- 405,409 ---- { bool returnValue; ! DateTime currentTime = timer.GetCurrentDateTime(); DateTime firstDateOfOscillatingPeriod = timer.GetPreviousDateTime(this.numDaysForOscillatingPeriod); *************** *** 424,429 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) --- 428,433 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.account.Portfolio.Count > 0) *************** *** 603,610 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.seedForRandomGenerator++; this.numDaysElapsedSinceLastOptimization++; --- 607,614 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! this.lastCloseDate = dateTime; this.seedForRandomGenerator++; this.numDaysElapsedSinceLastOptimization++; *************** *** 615,622 **** if(this.pathOfFileContainingGenomes == null) //tickers have to be set by a new optimization process (in sample) ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Close event else//this.pathOfFileContainingGenomes != null ! this.setTickersFromFile(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //set tickers from file this.numDaysElapsedSinceLastOptimization = 0; --- 619,626 ---- if(this.pathOfFileContainingGenomes == null) //tickers have to be set by a new optimization process (in sample) ! this.setTickers(dateTime, false); //sets tickers to be chosen next Market Close event else//this.pathOfFileContainingGenomes != null ! this.setTickersFromFile(dateTime); //set tickers from file this.numDaysElapsedSinceLastOptimization = 0; *************** *** 625,629 **** #endregion - } } --- 629,632 ---- |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:42
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18211/WalkForwardTest Modified Files: RunWalkForwardLinearCombination.cs WalkForwardOpenToCloseDailyStrategy.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: WalkForwardOpenToCloseDailyStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest/WalkForwardOpenToCloseDailyStrategy.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** WalkForwardOpenToCloseDailyStrategy.cs 12 Mar 2008 22:09:59 -0000 1.8 --- WalkForwardOpenToCloseDailyStrategy.cs 29 Sep 2008 21:20:25 -0000 1.9 *************** *** 3,7 **** WalkForwardOpenToCloseDailyStrategy.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- WalkForwardOpenToCloseDailyStrategy.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 40,46 **** /// </summary> [Serializable] ! public class WalkForwardOpenToCloseDailyStrategy : IEndOfDayStrategy { ! private Account account; private string tickerGroupID; private int numDaysForInSampleOptimization; --- 40,46 ---- /// </summary> [Serializable] ! public class WalkForwardOpenToCloseDailyStrategy : EndOfDayStrategy { ! // private Account account; private string tickerGroupID; private int numDaysForInSampleOptimization; *************** *** 58,66 **** private OptimizationOutput optimizationOutput; ! public Account Account ! { ! get { return this.account; } ! set { this.account = value; } ! } /// best genomes, one for each optimization process --- 58,66 ---- private OptimizationOutput optimizationOutput; ! // public Account Account ! // { ! // get { return this.account; } ! // set { this.account = value; } ! // } /// best genomes, one for each optimization process *************** *** 71,80 **** public WalkForwardOpenToCloseDailyStrategy( Account account , ! string tickerGroupID , int numDaysForInSampleOptimization , ! int numberOfEligibleTickers , ! int numberOfTickersToBeChosen , string benchmark , ! double targetReturn , PortfolioType portfolioType , ! int populationSizeForGeneticOptimizer , ! int generationNumberForGeneticOptimizer ) { this.account = account; --- 71,80 ---- public WalkForwardOpenToCloseDailyStrategy( Account account , ! string tickerGroupID , int numDaysForInSampleOptimization , ! int numberOfEligibleTickers , ! int numberOfTickersToBeChosen , string benchmark , ! double targetReturn , PortfolioType portfolioType , ! int populationSizeForGeneticOptimizer , ! int generationNumberForGeneticOptimizer ) { this.account = account; *************** *** 107,111 **** long quantity = marketOpenEventHandler_addOrder_getQuantity( ticker ); Order order = new Order( orderType , new Instrument( ticker ) , ! quantity ); this.account.AddOrder( order ); } --- 107,111 ---- long quantity = marketOpenEventHandler_addOrder_getQuantity( ticker ); Order order = new Order( orderType , new Instrument( ticker ) , ! quantity ); this.account.AddOrder( order ); } *************** *** 114,129 **** if ( this.signedTickersFromLastOptimization != null ) foreach ( string signedTicker in this.signedTickersFromLastOptimization ) ! marketOpenEventHandler_addOrder( signedTicker ); } ! public void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( ( this.account.CashAmount == 0 ) && ! ( this.account.Transactions.Count == 0 ) ) // cash has not been added yet this.account.AddCash( 30000 ); marketOpenEventHandler_addOrders(); } ! private void fiveMinutesBeforeMarketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); --- 114,129 ---- if ( this.signedTickersFromLastOptimization != null ) foreach ( string signedTicker in this.signedTickersFromLastOptimization ) ! marketOpenEventHandler_addOrder( signedTicker ); } ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if ( ( this.account.CashAmount == 0 ) && ! ( this.account.Transactions.Count == 0 ) ) // cash has not been added yet this.account.AddCash( 30000 ); marketOpenEventHandler_addOrders(); } ! private void marketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); *************** *** 133,146 **** this.account.ClosePosition( ticker ); } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! this.fiveMinutesBeforeMarketCloseEventHandler_closePositions(); } - public void MarketCloseEventHandler( Object sender , - EndOfDayTimingEventArgs endOfDayTimingEventArgs) - { - } protected DataTable getSetOfTickersToBeOptimized( DateTime optimizationFirstDate , DateTime optimizationLastDate ) --- 133,142 ---- this.account.ClosePosition( ticker ); } ! protected override void marketCloseEventHandler( Object sender , ! DateTime dateTime) { ! this.marketCloseEventHandler_closePositions(); } protected DataTable getSetOfTickersToBeOptimized( DateTime optimizationFirstDate , DateTime optimizationLastDate ) *************** *** 150,167 **** optimizationFirstDate , optimizationLastDate , this.numberOfEligibleTickers ); ! DataTable eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); // SelectorByGroup selectorByGroup = // new SelectorByGroup( "SP500" , optimizationLastDate ); // DataTable eligibleTickers = selectorByGroup.GetTableOfSelectedTickers(); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( eligibleTickers, ! false , optimizationFirstDate , ! optimizationLastDate , ! this.numberOfEligibleTickers, this.benchmark); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); } private void newGenerationEventHandler( object sender , ! NewGenerationEventArgs newGenerationEventArgs ) { Console.WriteLine( --- 146,163 ---- optimizationFirstDate , optimizationLastDate , this.numberOfEligibleTickers ); ! DataTable eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); // SelectorByGroup selectorByGroup = // new SelectorByGroup( "SP500" , optimizationLastDate ); // DataTable eligibleTickers = selectorByGroup.GetTableOfSelectedTickers(); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( eligibleTickers, ! false , optimizationFirstDate , ! optimizationLastDate , ! this.numberOfEligibleTickers, this.benchmark); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); } private void newGenerationEventHandler( object sender , ! NewGenerationEventArgs newGenerationEventArgs ) { Console.WriteLine( *************** *** 171,183 **** } private void addGenomeToBestGenomes( Genome genome, ! DateTime firstOptimizationDate , ! DateTime lastOptimizationDate ) { if( this.optimizationOutput == null) this.optimizationOutput = new OptimizationOutput(); ! this.optimizationOutput.Add( new GenomeRepresentation( genome , ! firstOptimizationDate , ! lastOptimizationDate ) ); } private void oneHourAfterMarketCloseEventHandler_set_signedTickersFromLastOptimization( --- 167,179 ---- } private void addGenomeToBestGenomes( Genome genome, ! DateTime firstOptimizationDate , ! DateTime lastOptimizationDate ) { if( this.optimizationOutput == null) this.optimizationOutput = new OptimizationOutput(); ! this.optimizationOutput.Add( new GenomeRepresentation( genome , ! firstOptimizationDate , ! lastOptimizationDate ) ); } private void oneHourAfterMarketCloseEventHandler_set_signedTickersFromLastOptimization( *************** *** 192,211 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized( optimizationFirstDate , ! optimizationLastDate ); Console.WriteLine( "Number of tickers to be optimized: " + ! setOfTickersToBeOptimized.Rows.Count.ToString() ); ! GenomeManagerForEfficientOTCPortfolio genManEfficientOTCPortfolio = new GenomeManagerForEfficientOTCPortfolio( ! setOfTickersToBeOptimized , ! currentDate.AddDays( -this.numDaysForInSampleOptimization + 1 ) , ! currentDate , ! this.numberOfTickersToBeChosen , ! this.targetReturn , ! this.portfolioType, ! this.benchmark); ! this.geneticOptimizer = new GeneticOptimizer(genManEfficientOTCPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); this.geneticOptimizer.NewGeneration += new NewGenerationEventHandler( this.newGenerationEventHandler ); --- 188,207 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized( optimizationFirstDate , ! optimizationLastDate ); Console.WriteLine( "Number of tickers to be optimized: " + ! setOfTickersToBeOptimized.Rows.Count.ToString() ); ! GenomeManagerForEfficientOTCPortfolio genManEfficientOTCPortfolio = new GenomeManagerForEfficientOTCPortfolio( ! setOfTickersToBeOptimized , ! currentDate.AddDays( -this.numDaysForInSampleOptimization + 1 ) , ! currentDate , ! this.numberOfTickersToBeChosen , ! this.targetReturn , ! this.portfolioType, ! this.benchmark); ! this.geneticOptimizer = new GeneticOptimizer(genManEfficientOTCPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); this.geneticOptimizer.NewGeneration += new NewGenerationEventHandler( this.newGenerationEventHandler ); *************** *** 220,239 **** ((GenomeMeaning)this.geneticOptimizer.BestGenome.Meaning).Tickers; this.addGenomeToBestGenomes( geneticOptimizer.BestGenome , ! optimizationFirstDate , optimizationLastDate ); } ! public void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! if ( endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.DayOfWeek == ! DayOfWeek.Friday ) // current day is Friday { Console.WriteLine( ! endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.ToString() + " - " + DateTime.Now.ToString() ); oneHourAfterMarketCloseEventHandler_set_signedTickersFromLastOptimization( ! endOfDayTimingEventArgs.EndOfDayDateTime.DateTime ); } } } } --- 216,246 ---- ((GenomeMeaning)this.geneticOptimizer.BestGenome.Meaning).Tickers; this.addGenomeToBestGenomes( geneticOptimizer.BestGenome , ! optimizationFirstDate , optimizationLastDate ); } ! protected override void oneHourAfterMarketCloseEventHandler( Object sender , ! DateTime dateTime) { ! if ( dateTime.DayOfWeek == ! DayOfWeek.Friday ) // current day is Friday { Console.WriteLine( ! dateTime.ToString() + " - " + DateTime.Now.ToString() ); oneHourAfterMarketCloseEventHandler_set_signedTickersFromLastOptimization( ! dateTime ); } } + + // public virtual void NewDateTimeEventHandler( + // Object sender , DateTime dateTime ) + // { + // if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + // this.marketOpenEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + // this.marketCloseEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + // this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + // } } } Index: RunWalkForwardLinearCombination.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest/RunWalkForwardLinearCombination.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RunWalkForwardLinearCombination.cs 27 Dec 2005 15:43:14 -0000 1.4 --- RunWalkForwardLinearCombination.cs 29 Sep 2008 21:20:24 -0000 1.5 *************** *** 3,7 **** RunWalkForwardLinearCombination.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- RunWalkForwardLinearCombination.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 58,62 **** private DateTime deadlineForScript; ! private IHistoricalQuoteProvider historicalQuoteProvider; private HistoricalEndOfDayTimer historicalEndOfDayTimer; private Account account; --- 58,62 ---- private DateTime deadlineForScript; ! private HistoricalMarketValueProvider historicalMarketValueProvider; private HistoricalEndOfDayTimer historicalEndOfDayTimer; private Account account; *************** *** 64,76 **** public RunWalkForwardLinearCombination(string tickerGroupID, ! int numDaysForInSampleOptimization , ! int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForLiquidity, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime firstDate, DateTime lastDate, double targetReturn, ! PortfolioType portfolioType , ! bool openToCloseDaily , ! double maxRunningHours ) { this.tickerGroupID = tickerGroupID; --- 64,76 ---- public RunWalkForwardLinearCombination(string tickerGroupID, ! int numDaysForInSampleOptimization , ! int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForLiquidity, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime firstDate, DateTime lastDate, double targetReturn, ! PortfolioType portfolioType , ! bool openToCloseDaily , ! double maxRunningHours ) { this.tickerGroupID = tickerGroupID; *************** *** 93,102 **** private void oneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if ( ( this.account.EndOfDayTimer.GetCurrentTime().DateTime >= ! this.lastDate ) || ! ( DateTime.Now > this.deadlineForScript ) ) ! this.account.EndOfDayTimer.Stop(); } --- 93,102 ---- private void oneHourAfterMarketCloseEventHandler( Object sender , ! DateTime dateTime ) { ! if ( ( this.account.Timer.GetCurrentDateTime() >= ! this.lastDate ) || ! ( DateTime.Now > this.deadlineForScript ) ) ! this.account.Timer.Stop(); } *************** *** 104,110 **** { if ( this.openToCloseDaily ) ! this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); else ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } private void run_setStrategy() --- 104,110 ---- { if ( this.openToCloseDaily ) ! this.historicalMarketValueProvider = new HistoricalRawQuoteProvider(); else ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); } private void run_setStrategy() *************** *** 113,123 **** this.endOfDayStrategy = new WalkForwardOpenToCloseDailyStrategy( ! this.account , this.tickerGroupID , ! this.numDaysForInSampleOptimization , ! this.numberOfEligibleTickers , ! this.numberOfTickersToBeChosen , ! this.benchmark , this.targetReturn , this.portfolioType , ! this.populationSizeForGeneticOptimizer , ! this.generationNumberForGeneticOptimizer ); // else // this.endOfDayStrategy = new OpenToCloseWeeklyStrategy( --- 113,123 ---- this.endOfDayStrategy = new WalkForwardOpenToCloseDailyStrategy( ! this.account , this.tickerGroupID , ! this.numDaysForInSampleOptimization , ! this.numberOfEligibleTickers , ! this.numberOfTickersToBeChosen , ! this.benchmark , this.targetReturn , this.portfolioType , ! this.populationSizeForGeneticOptimizer , ! this.generationNumberForGeneticOptimizer ); // else // this.endOfDayStrategy = new OpenToCloseWeeklyStrategy( *************** *** 128,159 **** this.historicalEndOfDayTimer = new IndexBasedEndOfDayTimer( ! new EndOfDayDateTime( this.firstDate , ! EndOfDaySpecificTime.MarketOpen ) , "MSFT" ); run_setHistoricalQuoteProvider(); this.account = new Account( "LinearCombination" , historicalEndOfDayTimer , ! new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) ); run_setStrategy(); // OneRank oneRank = new OneRank( account , // this.endDateTime ); ! this.historicalEndOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( ! this.endOfDayStrategy.MarketOpenEventHandler ); ! this.historicalEndOfDayTimer.FiveMinutesBeforeMarketClose += ! new FiveMinutesBeforeMarketCloseEventHandler( ! this.endOfDayStrategy.FiveMinutesBeforeMarketCloseEventHandler ); ! this.historicalEndOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayStrategy.OneHourAfterMarketCloseEventHandler ); ! this.historicalEndOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.oneHourAfterMarketCloseEventHandler ); ! this.account.EndOfDayTimer.Start(); ! Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "Linear Combination" , 1 , ! new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^SPX" ); // ObjectArchiver.Archive( report.AccountReport , --- 128,165 ---- this.historicalEndOfDayTimer = new IndexBasedEndOfDayTimer( ! HistoricalEndOfDayTimer.GetMarketOpen( this.firstDate ) , ! // new EndOfDayDateTime( this.firstDate , ! // EndOfDaySpecificTime.MarketOpen ) , ! "MSFT" ); run_setHistoricalQuoteProvider(); this.account = new Account( "LinearCombination" , historicalEndOfDayTimer , ! new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalMarketValueProvider ) ); run_setStrategy(); // OneRank oneRank = new OneRank( account , // this.endDateTime ); ! this.historicalEndOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayStrategy.NewDateTimeEventHandler ); ! // this.historicalEndOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( ! // this.endOfDayStrategy.MarketOpenEventHandler ); ! // this.historicalEndOfDayTimer.FiveMinutesBeforeMarketClose += ! // new FiveMinutesBeforeMarketCloseEventHandler( ! // this.endOfDayStrategy.FiveMinutesBeforeMarketCloseEventHandler ); ! // this.historicalEndOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayStrategy.OneHourAfterMarketCloseEventHandler ); ! // this.historicalEndOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.oneHourAfterMarketCloseEventHandler ); ! this.account.Timer.Start(); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "Linear Combination" , 1 , ! HistoricalEndOfDayTimer.GetMarketClose( this.lastDate ) , ! // new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^SPX" ); // ObjectArchiver.Archive( report.AccountReport , *************** *** 173,177 **** new VisualObjectArchiver(); visualObjectArchiver.Save( this.endOfDayStrategy.OptimizationOutput , ! "bgn" , title ); } } --- 179,183 ---- new VisualObjectArchiver(); visualObjectArchiver.Save( this.endOfDayStrategy.OptimizationOutput , ! "bgn" , title ); } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/MSFTwalkForward In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18225 Modified Files: TsMSFTwalkForward.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: TsMSFTwalkForward.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/MSFTwalkForward/TsMSFTwalkForward.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TsMSFTwalkForward.cs 29 Nov 2004 17:36:31 -0000 1.2 --- TsMSFTwalkForward.cs 29 Sep 2008 21:20:26 -0000 1.3 *************** *** 3,7 **** TsMSFTsimpleTest.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- TsMSFTsimpleTest.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 26,29 **** --- 26,30 ---- using QuantProject.ADT.Histories; using QuantProject.ADT.Optimizing; + using QuantProject.Data.DataProviders.Quotes; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; *************** *** 45,87 **** } ! private History microsoftCloseHistory; ! private History microsoftCloseHistorySMA; ! public override void InitializeData() ! { ! Parameter parameter = (Parameter) this.Parameters[ "SMAdays" ]; ! microsoftCloseHistory = QuoteCache.GetCloseHistory( "MSFT" ); ! microsoftCloseHistorySMA = microsoftCloseHistory.GetSimpleMovingAverage( (int) parameter.Value ); ! } ! public override Signals GetSignals( ExtendedDateTime extendedDateTime ) ! { ! Signals signals = new Signals(); ! if ( extendedDateTime.BarComponent == BarComponent.Close ) ! { ! Signal signal = new Signal(); ! if ( microsoftCloseHistory.Cross( microsoftCloseHistorySMA , ! extendedDateTime.DateTime ) ) ! { ! signal.Add( new Order( OrderType.MarketBuy , new Instrument( "MSFT" ) , 1 , ! new EndOfDayDateTime( new Instrument( "MSFT" ).GetNextMarketDay( extendedDateTime.DateTime ) , ! EndOfDaySpecificTime.MarketOpen ) ) ); ! signals.Add( signal ); ! } ! else ! { ! if ( microsoftCloseHistorySMA.Cross( microsoftCloseHistory , ! extendedDateTime.DateTime ) ) ! { ! signal.Add( new Order( OrderType.MarketSell , new Instrument( "MSFT" ) , 1 , ! new EndOfDayDateTime( ! new Instrument( "MSFT" ).GetNextMarketDay( extendedDateTime.DateTime ) , ! EndOfDaySpecificTime.MarketOpen ) ) ); ! signals.Add( signal ); ! } ! } ! } ! return signals; ! } } } --- 46,99 ---- } ! private History microsoftCloseHistory; ! private History microsoftCloseHistorySMA; ! public override void InitializeData() ! { ! Parameter parameter = (Parameter) this.Parameters[ "SMAdays" ]; ! microsoftCloseHistory = HistoricalQuotesProvider.GetCloseHistory( "MSFT" ); ! microsoftCloseHistorySMA = microsoftCloseHistory.GetSimpleMovingAverage( (int) parameter.Value ); ! } ! public override Signals GetSignals( DateTime dateTime ) ! { ! Signals signals = new Signals(); ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! // if ( dateTime.BarComponent == BarComponent.Close ) ! { ! Signal signal = new Signal(); ! if ( microsoftCloseHistory.Cross( microsoftCloseHistorySMA , ! dateTime ) ) ! { ! signal.Add( ! new Order( ! OrderType.MarketBuy , new Instrument( "MSFT" ) , 1 , ! HistoricalEndOfDayTimer.GetMarketOpen( ! new Instrument( "MSFT" ).GetNextMarketDay( ! dateTime ) ) ) ); ! // new EndOfDayDateTime( new Instrument( "MSFT" ).GetNextMarketDay( dateTime.DateTime ) , ! // EndOfDaySpecificTime.MarketOpen ) ) ); ! signals.Add( signal ); ! } ! else ! { ! if ( microsoftCloseHistorySMA.Cross( microsoftCloseHistory , ! dateTime ) ) ! { ! signal.Add( ! new Order( ! OrderType.MarketSell , new Instrument( "MSFT" ) , 1 , ! HistoricalEndOfDayTimer.GetMarketOpen( ! new Instrument( "MSFT" ).GetNextMarketDay( ! dateTime ) ) ) ); ! // new EndOfDayDateTime( ! // new Instrument( "MSFT" ).GetNextMarketDay( dateTime.DateTime ) , ! // EndOfDaySpecificTime.MarketOpen ) ) ); ! signals.Add( signal ); ! } ! } ! } ! return signals; ! } } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:34
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18157/Logging Modified Files: TesterForFLTPTestingPositions.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: TesterForFLTPTestingPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/Logging/TesterForFLTPTestingPositions.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TesterForFLTPTestingPositions.cs 16 Aug 2008 19:18:52 -0000 1.1 --- TesterForFLTPTestingPositions.cs 29 Sep 2008 21:20:14 -0000 1.2 *************** *** 46,50 **** private FLTPTestingPositions testingPositions; private int numberOfInSampleDays; ! private EndOfDayDateTime endOfDayDateTimeWhenThisObjectWasLogged; /// <summary> --- 46,50 ---- private FLTPTestingPositions testingPositions; private int numberOfInSampleDays; ! private DateTime dateTimeWhenThisObjectWasLogged; /// <summary> *************** *** 75,79 **** TestingPositions testingPositions , int numberOfInSampleDays , ! EndOfDayDateTime endOfDayDateTimeWhenThisObjectWasLogged ) { this.checkParameters( testingPositions ); --- 75,79 ---- TestingPositions testingPositions , int numberOfInSampleDays , ! DateTime dateTimeWhenThisObjectWasLogged ) { this.checkParameters( testingPositions ); *************** *** 81,86 **** (FLTPTestingPositions)testingPositions; this.numberOfInSampleDays = numberOfInSampleDays; ! this.endOfDayDateTimeWhenThisObjectWasLogged = ! endOfDayDateTimeWhenThisObjectWasLogged; } private void checkParameters( TestingPositions testingPositions ) --- 81,86 ---- (FLTPTestingPositions)testingPositions; this.numberOfInSampleDays = numberOfInSampleDays; ! this.dateTimeWhenThisObjectWasLogged = ! dateTimeWhenThisObjectWasLogged; } private void checkParameters( TestingPositions testingPositions ) *************** *** 96,100 **** WeightedPositions weightedPositions , IIntervalsSelector intervalsSelector , ! IHistoricalQuoteProvider historicalQuoteProvider , Benchmark benchmark , double cashToStart ) --- 96,100 ---- WeightedPositions weightedPositions , IIntervalsSelector intervalsSelector , ! HistoricalMarketValueProvider HistoricalMarketValueProvider , Benchmark benchmark , double cashToStart ) *************** *** 102,119 **** FLTPSimpleStrategy fLTPSimpleStrategy = new FLTPSimpleStrategy( weightedPositions , ! intervalsSelector , historicalQuoteProvider ); IAccountProvider accountProvider = new SimpleAccountProvider(); DateTime firstDateTime = ! this.endOfDayDateTimeWhenThisObjectWasLogged.DateTime.AddDays( - this.numberOfInSampleDays ); DateTime lastDateTime = ! this.endOfDayDateTimeWhenThisObjectWasLogged.DateTime; double maxRunningHours = 0.3; EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( "SimpleFLTP" , fLTPSimpleStrategy , ! historicalQuoteProvider , accountProvider , firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); --- 102,119 ---- FLTPSimpleStrategy fLTPSimpleStrategy = new FLTPSimpleStrategy( 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( "SimpleFLTP" , fLTPSimpleStrategy , ! HistoricalMarketValueProvider , accountProvider , firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); *************** *** 150,154 **** Benchmark benchmark = new Benchmark( "MSFT" ); ! IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); --- 150,154 ---- Benchmark benchmark = new Benchmark( "MSFT" ); ! HistoricalMarketValueProvider historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); *************** *** 171,175 **** AccountReport accountReport = this.getAccountReport( weightedPositions , intervalsSelector , ! historicalQuoteProvider , benchmark , 30000 ); --- 171,175 ---- AccountReport accountReport = this.getAccountReport( weightedPositions , intervalsSelector , ! historicalMarketValueProvider , benchmark , 30000 ); |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:29
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17673 Modified Files: RunTestOptimizedCTCPortfolio.cs RunTestOptimizedOTCPortfolio.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: RunTestOptimizedOTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunTestOptimizedOTCPortfolio.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunTestOptimizedOTCPortfolio.cs 7 Jan 2006 10:35:39 -0000 1.1 --- RunTestOptimizedOTCPortfolio.cs 29 Sep 2008 21:19:53 -0000 1.2 *************** *** 3,7 **** RunTestOptimizedOTCPorfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunTestOptimizedOTCPorfolio.cs ! Copyright (C) 2003 Marco Milletti *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 38,42 **** using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 38,42 ---- using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 51,121 **** /// </summary> [Serializable] ! public class RunTestOptimizedOTCPorfolio : RunEfficientOTCPortfolio { ! ! public RunTestOptimizedOTCPorfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime endDate, double targetReturn, ! PortfolioType portfolioType, double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! endDate.AddDays(-numDaysForOptimizationPeriod), endDate, targetReturn, ! portfolioType, maxRunningHours, ! numDaysBetweenEachOptimization) { ! //this.ScriptName = "TestOptimizedOTCPortfolio"; ! this.ScriptName = "TestOptimizedOTCWeightedPortfolio"; ! } ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCTest(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, ! this.numDaysBetweenEachOptimization); ! ! } ! ! public override void Run() ! { ! base.Run(); ! ((EndOfDayTimerHandlerOTCTest)this.endOfDayTimerHandler).Reset(); ! ! Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "TestOptimizationOpenToCloseEfficientPortfolio", 1 , ! new EndOfDayDateTime( this.endDateTime.DateTime , ! EndOfDaySpecificTime.MarketClose ) , ! this.benchmark ); ! report.Show(); ! report.Text = this.getGenomeCounterInfo(); ! } ! ! protected override void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) ! { ! if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! { ! this.endOfDayTimer.Stop(); ! } ! } ! ! ! } } --- 51,124 ---- /// </summary> [Serializable] ! public class RunTestOptimizedOTCPorfolio : RunEfficientOTCPortfolio { ! ! public RunTestOptimizedOTCPorfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime endDate, double targetReturn, ! PortfolioType portfolioType, double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! endDate.AddDays(-numDaysForOptimizationPeriod), endDate, targetReturn, ! portfolioType, maxRunningHours, ! numDaysBetweenEachOptimization) { ! //this.ScriptName = "TestOptimizedOTCPortfolio"; ! this.ScriptName = "TestOptimizedOTCWeightedPortfolio"; ! } ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCTest(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, ! this.numDaysBetweenEachOptimization); ! ! } ! ! public override void Run() ! { ! base.Run(); ! ((EndOfDayTimerHandlerOTCTest)this.endOfDayTimerHandler).Reset(); ! ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "TestOptimizationOpenToCloseEfficientPortfolio", 1 , ! HistoricalEndOfDayTimer.GetMarketClose( this.endDateTime ) , ! // new EndOfDayDateTime( this.endDateTime.DateTime , ! // EndOfDaySpecificTime.MarketClose ) , ! this.benchmark ); ! report.Show(); ! report.Text = this.getGenomeCounterInfo(); ! } ! ! protected override void checkDateForReport( ! Object sender , DateTime dateTime ) ! { ! if(dateTime>=this.endDateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! { ! this.endOfDayTimer.Stop(); ! } ! } ! ! ! } } Index: RunTestOptimizedCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunTestOptimizedCTCPortfolio.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RunTestOptimizedCTCPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.9 --- RunTestOptimizedCTCPortfolio.cs 29 Sep 2008 21:19:53 -0000 1.10 *************** *** 3,7 **** RunTestOptimizedCTCPortfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunTestOptimizedCTCPortfolio.cs ! Copyright (C) 2003 Marco Milletti *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 36,40 **** using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 36,40 ---- using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 48,52 **** /// <summary> /// Script to buy at close and sell at close ! /// after a specified number of market days /// the efficient portfolio /// The efficient portfolio's generation rules --- 48,52 ---- /// <summary> /// Script to buy at close and sell at close ! /// after a specified number of market days /// the efficient portfolio /// The efficient portfolio's generation rules *************** *** 60,130 **** public class RunTestOptimizedCTCPortfolio : RunEfficientCTCPortfolio { ! ! public RunTestOptimizedCTCPortfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime endDate, ! int numDaysOfPortfolioLife, int numDaysForReturnCalculation, ! int numDaysWithNoPositions, ! double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours, int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! endDate.AddDays(-numDaysForOptimizationPeriod), endDate, ! numDaysOfPortfolioLife, numDaysForReturnCalculation, ! numDaysWithNoPositions, ! targetReturn, ! portfolioType, maxAcceptableCloseToCloseDrawdown, ! maxRunningHours, numDaysBetweenEachOptimization) { ! this.ScriptName = "TestOptimizedCTCPortfolio"; ! } - - protected override void run_initializeEndOfDayTimerHandler() - { - this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTCTest(this.tickerGroupID, this.numberOfEligibleTickers, - this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, - this.account, - this.generationNumberForGeneticOptimizer, - this.populationSizeForGeneticOptimizer, this.benchmark, - this.numDayOfPortfolioLife, - this.numDaysForReturnCalculation, - this.numDaysWithNoPositions, - this.targetReturn, - this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, - this.numDaysBetweenEachOptimization); - } - - - public override void Run() - { - base.Run(); - ((EndOfDayTimerHandlerCTCTest)this.endOfDayTimerHandler).Reset(); - Report report = new Report( this.account , this.historicalQuoteProvider ); - report.Create( "TestOptimizationCTCPortfolio", 1 , - new EndOfDayDateTime( this.endDateTime.DateTime , - EndOfDaySpecificTime.MarketClose ) , - this.benchmark ); - report.Show(); - report.Text = this.getGenomeCounterInfo(); - } - - protected override void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) - { - if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || - DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) - //last date is reached by the timer or maxRunning hours - //are elapsed from the time script started - { - this.endOfDayTimer.Stop(); - } ! } ! } } --- 60,147 ---- public class RunTestOptimizedCTCPortfolio : RunEfficientCTCPortfolio { ! ! public RunTestOptimizedCTCPortfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime endDate, ! int numDaysOfPortfolioLife, int numDaysForReturnCalculation, ! int numDaysWithNoPositions, ! double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours, int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! endDate.AddDays(-numDaysForOptimizationPeriod), endDate, ! numDaysOfPortfolioLife, numDaysForReturnCalculation, ! numDaysWithNoPositions, ! targetReturn, ! portfolioType, maxAcceptableCloseToCloseDrawdown, ! maxRunningHours, numDaysBetweenEachOptimization) { ! this.ScriptName = "TestOptimizedCTCPortfolio"; ! ! } ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTCTest(this.tickerGroupID, this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, this.benchmark, ! this.numDayOfPortfolioLife, ! this.numDaysForReturnCalculation, ! this.numDaysWithNoPositions, ! this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, ! this.numDaysBetweenEachOptimization); ! } ! ! ! public override void Run() ! { ! base.Run(); ! ((EndOfDayTimerHandlerCTCTest)this.endOfDayTimerHandler).Reset(); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "TestOptimizationCTCPortfolio", 1 , ! HistoricalEndOfDayTimer.GetMarketClose( this.endDateTime ) , ! // new EndOfDayDateTime( this.endDateTime.DateTime , ! // EndOfDaySpecificTime.MarketClose ) , ! this.benchmark ); ! report.Show(); ! report.Text = this.getGenomeCounterInfo(); ! } ! ! // protected override void checkDateForReport( ! // Object sender , DateTime dateTime) ! // { ! // if(dateTime.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! // DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! // //last date is reached by the timer or maxRunning hours ! // //are elapsed from the time script started ! // { ! // this.endOfDayTimer.Stop(); ! // } ! // ! // } ! ! protected override void checkDateForReport( ! Object sender , DateTime dateTime) ! { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! { ! if( dateTime >= this.endDateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.endOfDayTimer.Stop(); ! } } ! } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:27
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17497/LinearCombination Modified Files: ImmediateTrendFollowerStrategy.cs LinearCombinationTest.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: LinearCombinationTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/LinearCombinationTest.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** LinearCombinationTest.cs 14 Jan 2008 23:41:44 -0000 1.13 --- LinearCombinationTest.cs 29 Sep 2008 21:19:30 -0000 1.14 *************** *** 3,7 **** LinearCombinationTest.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- LinearCombinationTest.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 40,44 **** /// <summary> /// Object to test a linear combination strategy on given positions, ! /// on a given period of time /// </summary> public class LinearCombinationTest --- 40,44 ---- /// <summary> /// Object to test a linear combination strategy on given positions, ! /// on a given period of time /// </summary> public class LinearCombinationTest *************** *** 48,70 **** private GenomeRepresentation[] genomeRepresentations; // private bool openToCloseDaily; ! private StrategyType strategyType; ! private int numDaysForOscillatorStrategy; ! private double stopLoss; ! private double takeProfit; private double oversoldThreshold; private double overboughtThreshold; private bool setDirectlyThresholdLevels; ! private IHistoricalQuoteProvider historicalQuoteProvider; private HistoricalEndOfDayTimer historicalEndOfDayTimer; private Account account; ! private IEndOfDayStrategy endOfDayStrategy; ! private PortfolioType portfolioType; private void linearCombinationTest_commonInitialization(DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType, int numDaysForOscillatorStrategy, ! double stopLoss, double takeProfit, ! double oversoldThreshold, double overboughtThreshold, bool setDirectlyThresholdLevels) { this.firstDate = firstDate; --- 48,70 ---- private GenomeRepresentation[] genomeRepresentations; // private bool openToCloseDaily; ! private StrategyType strategyType; ! private int numDaysForOscillatorStrategy; ! private double stopLoss; ! private double takeProfit; private double oversoldThreshold; private double overboughtThreshold; private bool setDirectlyThresholdLevels; ! private HistoricalMarketValueProvider historicalMarketValueProvider; private HistoricalEndOfDayTimer historicalEndOfDayTimer; private Account account; ! private IStrategy strategy; ! private PortfolioType portfolioType; private void linearCombinationTest_commonInitialization(DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType, int numDaysForOscillatorStrategy, ! double stopLoss, double takeProfit, ! double oversoldThreshold, double overboughtThreshold, bool setDirectlyThresholdLevels) { this.firstDate = firstDate; *************** *** 82,128 **** public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType) { this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, 0,0,0,0,0,false); ! } ! ! public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType, ! int numDaysForOscillatorStrategy) ! { this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! 0,0,0,0,false); ! } ! public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType, ! int numDaysForOscillatorStrategy, double stopLoss, double takeProfit) ! { this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! stopLoss, takeProfit, 0,0,false); ! } public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType, ! int numDaysForOscillatorStrategy, double stopLoss, double takeProfit, ! double oversoldThreshold, double overboughtThreshold, bool setDirectlyThresholdLevels) { this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! stopLoss, takeProfit, oversoldThreshold, overboughtThreshold, ! setDirectlyThresholdLevels); } ! private void oneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if ( this.account.EndOfDayTimer.GetCurrentTime().DateTime >= ! this.lastDate ) ! this.account.EndOfDayTimer.Stop(); } --- 82,128 ---- public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType) { this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, 0,0,0,0,0,false); ! } ! ! public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType, ! int numDaysForOscillatorStrategy) ! { this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! 0,0,0,0,false); ! } ! public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType, ! int numDaysForOscillatorStrategy, double stopLoss, double takeProfit) ! { this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! stopLoss, takeProfit, 0,0,false); ! } public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType, ! int numDaysForOscillatorStrategy, double stopLoss, double takeProfit, ! double oversoldThreshold, double overboughtThreshold, bool setDirectlyThresholdLevels) { this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! stopLoss, takeProfit, oversoldThreshold, overboughtThreshold, ! setDirectlyThresholdLevels); } ! private void oneHourAfterMarketCloseEventHandler( Object sender , ! DateTime dateTime ) { ! if ( this.account.Timer.GetCurrentDateTime() >= ! this.lastDate ) ! this.account.Timer.Stop(); } *************** *** 130,170 **** { if ( this.strategyType == StrategyType.OpenToCloseDaily ) ! this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); else ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } ! // private void run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy() ! // { ! // WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! // for(int i = 0; i<this.genomeRepresentations.Length;i++) ! // { ! // weightedPositions[i] = ! // new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! // new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! // ! // } ! // ! // this.endOfDayStrategy = new FixedLevelOscBiasedOTC_PVONoThresholdsStrategy( ! // this.account , weightedPositions, ! // this.genomeRepresentations.Length); ! // } ! // private void run_setStrategy_setBiasedPVONoThresholdsStrategy() ! // { // WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; // for(int i = 0; i<this.genomeRepresentations.Length;i++) // { ! // weightedPositions[i] = // new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), // new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! // // } ! // this.endOfDayStrategy = new FixedLevelOscillatorBiasedPVONoThresholdsStrategy( ! // this.account , weightedPositions, ! // this.genomeRepresentations.Length, ! // this.stopLoss, ! // this.takeProfit); ! // } private double run_setStrategy_setBiasedPVOStrategy_getOversoldThreshold(int i) --- 130,170 ---- { if ( this.strategyType == StrategyType.OpenToCloseDaily ) ! this.historicalMarketValueProvider = new HistoricalRawQuoteProvider(); else ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); } ! // private void run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy() ! // { ! // WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! // for(int i = 0; i<this.genomeRepresentations.Length;i++) ! // { ! // weightedPositions[i] = ! // new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! // new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! // ! // } ! // ! // this.endOfDayStrategy = new FixedLevelOscBiasedOTC_PVONoThresholdsStrategy( ! // this.account , weightedPositions, ! // this.genomeRepresentations.Length); ! // } ! // private void run_setStrategy_setBiasedPVONoThresholdsStrategy() ! // { // WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; // for(int i = 0; i<this.genomeRepresentations.Length;i++) // { ! // weightedPositions[i] = // new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), // new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! // // } ! // this.endOfDayStrategy = new FixedLevelOscillatorBiasedPVONoThresholdsStrategy( ! // this.account , weightedPositions, ! // this.genomeRepresentations.Length, ! // this.stopLoss, ! // this.takeProfit); ! // } private double run_setStrategy_setBiasedPVOStrategy_getOversoldThreshold(int i) *************** *** 193,275 **** WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; double[] oversoldThresholds = new double[this.genomeRepresentations.Length]; ! double[] overboughtThresholds = new double[this.genomeRepresentations.Length]; for(int i = 0; i<this.genomeRepresentations.Length;i++) { ! weightedPositions[i] = new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! new SignedTickers(this.genomeRepresentations[i].SignedTickers)); oversoldThresholds[i] = this.run_setStrategy_setBiasedPVOStrategy_getOversoldThreshold(i); overboughtThresholds[i] = this.run_setStrategy_setBiasedPVOStrategy_getOverboughtThreshold(i); } ! this.endOfDayStrategy = new FixedLevelOscillatorBiasedPVOStrategy( ! this.account , weightedPositions, ! oversoldThresholds, overboughtThresholds, ! overboughtThresholds.Length, ! this.numDaysForOscillatorStrategy,this.stopLoss, ! this.takeProfit); } private void run_setStrategy() { ! WeightedPositions weightedPositions = this.run_getWeightedPositions(this.genomeRepresentations[0]); switch (this.strategyType) ! { ! case StrategyType.OpenToCloseDaily: ! this.endOfDayStrategy = new OpenToCloseDailyStrategy( ! this.account , weightedPositions ); ! break; ! case StrategyType.OpenToCloseWeekly: ! this.endOfDayStrategy = new OpenToCloseWeeklyStrategy( ! this.account , weightedPositions ); ! break; ! case StrategyType.CloseToOpenDaily: ! this.endOfDayStrategy = new CloseToOpenDailyStrategy( ! this.account , weightedPositions ); ! break; ! ! case StrategyType.OpenToCloseCloseToOpenDaily: ! this.endOfDayStrategy = new OTC_CTODailyStrategy( ! this.account , weightedPositions); ! break; ! ! case StrategyType.FixedPeriodOscillator: ! this.endOfDayStrategy = new FixedPeriodOscillatorStrategy( ! this.account , weightedPositions, ! this.numDaysForOscillatorStrategy , ! this.numDaysForOscillatorStrategy ); ! break; ! ! case StrategyType.ExtremeCounterTrend: ! this.endOfDayStrategy = new ExtremeCounterTrendStrategy( ! this.account , weightedPositions, this.numDaysForOscillatorStrategy, ! this.portfolioType); ! break; ! ! case StrategyType.ImmediateTrendFollower: ! this.endOfDayStrategy = new ImmediateTrendFollowerStrategy( ! this.account , weightedPositions, this.numDaysForOscillatorStrategy ); ! break; ! ! case StrategyType.PortfolioValueOscillator: ! this.endOfDayStrategy = new FixedLevelOscillatorPVOStrategy( ! this.account , weightedPositions, ! this.genomeRepresentations[0].OversoldThreshold, this.genomeRepresentations[0].OverboughtThreshold, ! this.numDaysForOscillatorStrategy ); ! break; ! ! case StrategyType.PortfolioValueOscillatorBiased: ! this.run_setStrategy_setBiasedPVOStrategy(); ! break; ! ! // case StrategyType.PortfolioValueOscillatorBiasedNoThresholds: ! // this.run_setStrategy_setBiasedPVONoThresholdsStrategy(); ! // break; // ! // case StrategyType.OTC_PVOBiasedNoThresholds: ! // this.run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy(); ! // break; ! } } private string getDateString( DateTime dateTime ) --- 193,275 ---- WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; double[] oversoldThresholds = new double[this.genomeRepresentations.Length]; ! double[] overboughtThresholds = new double[this.genomeRepresentations.Length]; for(int i = 0; i<this.genomeRepresentations.Length;i++) { ! weightedPositions[i] = new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! new SignedTickers(this.genomeRepresentations[i].SignedTickers)); oversoldThresholds[i] = this.run_setStrategy_setBiasedPVOStrategy_getOversoldThreshold(i); overboughtThresholds[i] = this.run_setStrategy_setBiasedPVOStrategy_getOverboughtThreshold(i); } ! this.strategy = new FixedLevelOscillatorBiasedPVOStrategy( ! this.account , weightedPositions, ! oversoldThresholds, overboughtThresholds, ! overboughtThresholds.Length, ! this.numDaysForOscillatorStrategy,this.stopLoss, ! this.takeProfit); } private void run_setStrategy() { ! WeightedPositions weightedPositions = this.run_getWeightedPositions(this.genomeRepresentations[0]); switch (this.strategyType) ! { ! case StrategyType.OpenToCloseDaily: ! this.strategy = new OpenToCloseDailyStrategy( ! this.account , weightedPositions ); ! break; ! case StrategyType.OpenToCloseWeekly: ! this.strategy = new OpenToCloseWeeklyStrategy( ! this.account , weightedPositions ); ! break; ! case StrategyType.CloseToOpenDaily: ! this.strategy = new CloseToOpenDailyStrategy( ! this.account , weightedPositions ); ! break; ! ! case StrategyType.OpenToCloseCloseToOpenDaily: ! this.strategy = new OTC_CTODailyStrategy( ! this.account , weightedPositions); ! break; ! ! case StrategyType.FixedPeriodOscillator: ! this.strategy = new FixedPeriodOscillatorStrategy( ! this.account , weightedPositions, ! this.numDaysForOscillatorStrategy , ! this.numDaysForOscillatorStrategy ); ! break; ! ! case StrategyType.ExtremeCounterTrend: ! this.strategy = new ExtremeCounterTrendStrategy( ! this.account , weightedPositions, this.numDaysForOscillatorStrategy, ! this.portfolioType); ! break; ! ! case StrategyType.ImmediateTrendFollower: ! this.strategy = new ImmediateTrendFollowerStrategy( ! this.account , weightedPositions, this.numDaysForOscillatorStrategy ); ! break; ! ! case StrategyType.PortfolioValueOscillator: ! this.strategy = new FixedLevelOscillatorPVOStrategy( ! this.account , weightedPositions, ! this.genomeRepresentations[0].OversoldThreshold, this.genomeRepresentations[0].OverboughtThreshold, ! this.numDaysForOscillatorStrategy ); ! break; ! ! case StrategyType.PortfolioValueOscillatorBiased: ! this.run_setStrategy_setBiasedPVOStrategy(); ! break; ! ! // case StrategyType.PortfolioValueOscillatorBiasedNoThresholds: ! // this.run_setStrategy_setBiasedPVONoThresholdsStrategy(); ! // break; // ! // case StrategyType.OTC_PVOBiasedNoThresholds: ! // this.run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy(); ! // break; ! } } private string getDateString( DateTime dateTime ) *************** *** 287,386 **** " to " + this.getDateString( this.lastDate ) + " opt. in sample from " + this.getDateString( ! this.genomeRepresentations[0].FirstOptimizationDate ) + " to " + this.getDateString( ! this.genomeRepresentations[0].LastOptimizationDate ); return returnValue; } ! private void run_addEquityLineForWeightedPositions( ! WeightedPositions weightedPositions , Color color , Report report ) ! { ! EquityLine equityLineForWeightedPositions = ! weightedPositions.GetVirtualEquityLine( ! 15000 , report.AccountReport.EquityLine ); ! report.AddEquityLine( equityLineForWeightedPositions , ! color ); ! } ! private void run_addEquityLineForEachPositionInWeightedPositions( ! WeightedPositions weightedPositions , Color color , Report report ) ! { foreach(WeightedPosition position in weightedPositions.Values) { WeightedPositions wp = new WeightedPositions(new SignedTickers( ! position.Ticker)); EquityLine equityLineForWeightedPositions = ! wp.GetVirtualEquityLine( ! 15000 , report.AccountReport.EquityLine ); ! report.AddEquityLine( equityLineForWeightedPositions , ! color ); } ! } ! private WeightedPositions run_getWeightedPositions(GenomeRepresentation genomeRepresentation) ! ! { ! double[] normalizedWeights = ! GenomeRepresentation.GetWeightsArray(genomeRepresentation.WeightsForSignedTickers); ! string[] tickers = ! GenomeRepresentation.GetSignedTickers(genomeRepresentation.SignedTickers); ! for(int i = 0; i<tickers.Length; i++) ! { ! if(tickers[i].StartsWith("-")) ! { ! tickers[i] = SignedTicker.GetTicker(tickers[i]); ! normalizedWeights[i] = -1.0 * normalizedWeights[i]; ! } ! } ! return new WeightedPositions(normalizedWeights, tickers); ! } ! public void Run() { this.historicalEndOfDayTimer = new IndexBasedEndOfDayTimer( ! new EndOfDayDateTime( this.firstDate , ! EndOfDaySpecificTime.MarketOpen ) , "^GSPC" ); run_setHistoricalQuoteProvider(); this.account = new Account( "LinearCombination" , historicalEndOfDayTimer , ! new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) ); run_setStrategy(); // OneRank oneRank = new OneRank( account , // this.endDateTime ); ! this.historicalEndOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( ! this.endOfDayStrategy.MarketOpenEventHandler ); ! this.historicalEndOfDayTimer.FiveMinutesBeforeMarketClose += ! new FiveMinutesBeforeMarketCloseEventHandler( ! this.endOfDayStrategy.FiveMinutesBeforeMarketCloseEventHandler ); ! this.historicalEndOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.endOfDayStrategy.MarketCloseEventHandler ); ! this.historicalEndOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.oneHourAfterMarketCloseEventHandler ); ! this.account.EndOfDayTimer.Start(); ! Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "Linear Combination" , 1 , ! new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , ! "^GSPC"); ! foreach(GenomeRepresentation genomeRepresentation in this.genomeRepresentations) ! { ! WeightedPositions weightedPositions = this.run_getWeightedPositions( genomeRepresentation ); ! this.run_addEquityLineForWeightedPositions( ! weightedPositions, ! Color.Brown, ! report); ! this.run_addEquityLineForEachPositionInWeightedPositions( ! weightedPositions, ! Color.DimGray, ! report); ! ! } ! report.Text = this.run_getReportTitle(); report.Show(); } --- 287,392 ---- " to " + this.getDateString( this.lastDate ) + " opt. in sample from " + this.getDateString( ! this.genomeRepresentations[0].FirstOptimizationDate ) + " to " + this.getDateString( ! this.genomeRepresentations[0].LastOptimizationDate ); return returnValue; } ! private void run_addEquityLineForWeightedPositions( ! WeightedPositions weightedPositions , Color color , Report report ) ! { ! EquityLine equityLineForWeightedPositions = ! weightedPositions.GetVirtualEquityLine( ! 15000 , report.AccountReport.EquityLine ); ! report.AddEquityLine( equityLineForWeightedPositions , ! color ); ! } ! private void run_addEquityLineForEachPositionInWeightedPositions( ! WeightedPositions weightedPositions , Color color , Report report ) ! { foreach(WeightedPosition position in weightedPositions.Values) { WeightedPositions wp = new WeightedPositions(new SignedTickers( ! position.Ticker)); EquityLine equityLineForWeightedPositions = ! wp.GetVirtualEquityLine( ! 15000 , report.AccountReport.EquityLine ); ! report.AddEquityLine( equityLineForWeightedPositions , ! color ); } ! } ! private WeightedPositions run_getWeightedPositions(GenomeRepresentation genomeRepresentation) ! ! { ! double[] normalizedWeights = ! GenomeRepresentation.GetWeightsArray(genomeRepresentation.WeightsForSignedTickers); ! string[] tickers = ! GenomeRepresentation.GetSignedTickers(genomeRepresentation.SignedTickers); ! for(int i = 0; i<tickers.Length; i++) ! { ! if(tickers[i].StartsWith("-")) ! { ! tickers[i] = SignedTicker.GetTicker(tickers[i]); ! normalizedWeights[i] = -1.0 * normalizedWeights[i]; ! } ! } ! return new WeightedPositions(normalizedWeights, tickers); ! } ! public void Run() { this.historicalEndOfDayTimer = new IndexBasedEndOfDayTimer( ! HistoricalEndOfDayTimer.GetMarketOpen( this.firstDate ) , ! // new EndOfDayDateTime( this.firstDate , ! // EndOfDaySpecificTime.MarketOpen ) , ! "^GSPC" ); run_setHistoricalQuoteProvider(); this.account = new Account( "LinearCombination" , historicalEndOfDayTimer , ! new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalMarketValueProvider ) ); run_setStrategy(); // OneRank oneRank = new OneRank( account , // this.endDateTime ); ! this.historicalEndOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.strategy.NewDateTimeEventHandler ); ! // this.historicalEndOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( ! // this.strategy.MarketOpenEventHandler ); ! // this.historicalEndOfDayTimer.FiveMinutesBeforeMarketClose += ! // new FiveMinutesBeforeMarketCloseEventHandler( ! // this.strategy.FiveMinutesBeforeMarketCloseEventHandler ); ! // this.historicalEndOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.strategy.MarketCloseEventHandler ); ! // this.historicalEndOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.oneHourAfterMarketCloseEventHandler ); ! this.account.Timer.Start(); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "Linear Combination" , 1 , ! HistoricalEndOfDayTimer.GetMarketClose( this.lastDate ) , ! // new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , ! "^GSPC"); ! foreach(GenomeRepresentation genomeRepresentation in this.genomeRepresentations) ! { ! WeightedPositions weightedPositions = this.run_getWeightedPositions( genomeRepresentation ); ! this.run_addEquityLineForWeightedPositions( ! weightedPositions, ! Color.Brown, ! report); ! this.run_addEquityLineForEachPositionInWeightedPositions( ! weightedPositions, ! Color.DimGray, ! report); ! ! } ! report.Text = this.run_getReportTitle(); report.Show(); } Index: ImmediateTrendFollowerStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/ImmediateTrendFollowerStrategy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ImmediateTrendFollowerStrategy.cs 19 Aug 2008 17:11:29 -0000 1.3 --- ImmediateTrendFollowerStrategy.cs 29 Sep 2008 21:19:30 -0000 1.4 *************** *** 39,43 **** /// </summary> [Serializable] ! public class ImmediateTrendFollowerStrategy : EndOfDayTimerHandler, IEndOfDayStrategy { private int numDaysForReturnCalculation; --- 39,45 ---- /// </summary> [Serializable] ! public class ImmediateTrendFollowerStrategy : ! QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios.EndOfDayTimerHandler , ! IStrategy { private int numDaysForReturnCalculation; *************** *** 60,70 **** } ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } --- 62,72 ---- } ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { } ! public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime) { } *************** *** 113,118 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) --- 115,120 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.account.Portfolio.Count > 0) *************** *** 131,139 **** } ! public override void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } } } --- 133,152 ---- } ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime) { } + public virtual void NewTimeEventHandler( + Object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + this.marketOpenEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + this.marketCloseEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + } + } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:25
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17551 Modified Files: RunEfficientPortfolio.cs RunLastChosenPortfolioOutOfSample.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: RunEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientPortfolio.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** RunEfficientPortfolio.cs 19 Aug 2008 17:13:06 -0000 1.22 --- RunEfficientPortfolio.cs 29 Sep 2008 21:19:35 -0000 1.23 *************** *** 62,69 **** protected ReportTable reportTable; ! protected EndOfDayDateTime startDateTime; ! protected EndOfDayDateTime endDateTime; //protected int numIntervalDays;// number of days for the equity line graph ! protected IHistoricalQuoteProvider historicalQuoteProvider; --- 62,69 ---- protected ReportTable reportTable; ! protected DateTime startDateTime; ! protected DateTime endDateTime; //protected int numIntervalDays;// number of days for the equity line graph ! protected HistoricalMarketValueProvider historicalMarketValueProvider; *************** *** 74,78 **** protected Account account; ! protected IEndOfDayTimer endOfDayTimer; protected string benchmark; --- 74,78 ---- protected Account account; ! protected QuantProject.Business.Timing.Timer endOfDayTimer; protected string benchmark; *************** *** 103,107 **** public DateTime TimerLastDate { ! get{return this.endOfDayTimer.GetCurrentTime().DateTime ;} } --- 103,107 ---- public DateTime TimerLastDate { ! get{return this.endOfDayTimer.GetCurrentDateTime() ;} } *************** *** 112,119 **** { ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "EfficientGeneric"; --- 112,123 ---- { ! this.startDateTime = ! HistoricalEndOfDayTimer.GetFiveMinutesBeforeMarketClose( startDate ); ! // new EndOfDayDateTime( ! // startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( endDate ); ! // new EndOfDayDateTime( ! // endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "EfficientGeneric"; *************** *** 141,148 **** this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.reportTable = new ReportTable( "Summary_Reports" ); ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "EfficientGeneric"; --- 145,156 ---- this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.reportTable = new ReportTable( "Summary_Reports" ); ! this.startDateTime = ! HistoricalEndOfDayTimer.GetFiveMinutesBeforeMarketClose( startDate ); ! // new EndOfDayDateTime( ! // startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( endDate ); ! // new EndOfDayDateTime( ! // endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "EfficientGeneric"; *************** *** 181,187 **** this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider )); } --- 189,195 ---- this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider )); } *************** *** 202,212 **** } ! protected virtual void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.SaveScriptResults(); } --- 210,224 ---- } ! protected virtual void checkDateForReport( ! Object sender , DateTime dateTime) { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! { ! if( dateTime >= this.endDateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.SaveScriptResults(); ! } } *************** *** 239,243 **** //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); --- 251,255 ---- //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentDateTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); *************** *** 273,279 **** protected virtual void run_addEventHandlers() { ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); //in inherited classes'override method: --- 285,294 ---- protected virtual void run_addEventHandlers() { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.checkDateForReport ); ! ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); //in inherited classes'override method: Index: RunLastChosenPortfolioOutOfSample.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunLastChosenPortfolioOutOfSample.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunLastChosenPortfolioOutOfSample.cs 27 Jul 2005 22:30:56 -0000 1.3 --- RunLastChosenPortfolioOutOfSample.cs 29 Sep 2008 21:19:35 -0000 1.4 *************** *** 3,7 **** RunLastChosenPortfolioOutOfSample.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunLastChosenPortfolioOutOfSample.cs ! Copyright (C) 2003 Marco Milletti *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 40,44 **** using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 40,44 ---- using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 56,161 **** private string[] tickers; private PortfolioType typeOfPortfolio; ! public RunLastChosenPortfolioOutOfSample(string[] chosenTickers, ! PortfolioType typeOfPortfolio, string benchmark, ! DateTime startDate, ! DateTime endDate, ! double maxRunningHours): ! base(benchmark, ! startDate, ! endDate, ! typeOfPortfolio, ! maxRunningHours) { ! this.tickers = chosenTickers; ! this.typeOfPortfolio = typeOfPortfolio; ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.MarketOpen ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.MarketClose ); ! this.ScriptName = "LastChosenPortfolioOutOfSample"; ! } - #region Run - - protected override void run_initializeEndOfDayTimerHandler() - { - this.endOfDayTimerHandler = - new EndOfDayTimerHandlerLastChosenPortfolio(this.tickers, - this.typeOfPortfolio, - this.account, - this.benchmark, - this.startDateTime, - this.endDateTime); - } - - protected override void run_initializeEndOfDayTimer() - { - this.endOfDayTimer = - new HistoricalEndOfDayTimer(this.startDateTime); - } - - protected override void run_initializeHistoricalQuoteProvider() - { - this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); - - } - protected override void run_initializeAccount() - { - //default account with no commissions - this.account = new Account( this.scriptName , this.endOfDayTimer , - new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , - this.historicalQuoteProvider ) , - new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , - this.historicalQuoteProvider )); - - } - - protected override void run_addEventHandlers() - { - this.endOfDayTimer.MarketOpen += - new MarketOpenEventHandler( - this.endOfDayTimerHandler.MarketOpenEventHandler); - - this.endOfDayTimer.MarketClose += - new MarketCloseEventHandler( - this.endOfDayTimerHandler.MarketCloseEventHandler); - - this.endOfDayTimer.MarketClose += - new MarketCloseEventHandler( - this.checkDateForReport); - // - //this.endOfDayTimer.OneHourAfterMarketClose += - // new OneHourAfterMarketCloseEventHandler( - // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); - - } - - - public override void Run() - { - base.Run(); - Report report = new Report( this.account , this.historicalQuoteProvider ); - report.Create( "Run last chosen tickers out of sample", 1 , - new EndOfDayDateTime( this.endDateTime.DateTime , - EndOfDaySpecificTime.MarketClose ) , - "^SPX" ); - report.Show(); - } - - protected override void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) - { - if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || - DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) - //last date is reached by the timer or maxRunning hours - //are elapsed from the time script started - { - this.endOfDayTimer.Stop(); - } ! } ! ! #endregion ! } } --- 56,191 ---- private string[] tickers; private PortfolioType typeOfPortfolio; ! public RunLastChosenPortfolioOutOfSample(string[] chosenTickers, ! PortfolioType typeOfPortfolio, string benchmark, ! DateTime startDate, ! DateTime endDate, ! double maxRunningHours): ! base(benchmark, ! startDate, ! endDate, ! typeOfPortfolio, ! maxRunningHours) { ! this.tickers = chosenTickers; ! this.typeOfPortfolio = typeOfPortfolio; ! this.startDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( startDate ); ! // new EndOfDayDateTime( ! // startDate, EndOfDaySpecificTime.MarketOpen ); ! this.endDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( endDate ); ! // new EndOfDayDateTime( ! // endDate, EndOfDaySpecificTime.MarketClose ); ! this.ScriptName = "LastChosenPortfolioOutOfSample"; ! ! } ! #region Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = ! new EndOfDayTimerHandlerLastChosenPortfolio(this.tickers, ! this.typeOfPortfolio, ! this.account, ! this.benchmark, ! this.startDateTime, ! this.endDateTime); ! } ! ! protected override void run_initializeEndOfDayTimer() ! { ! this.endOfDayTimer = ! new HistoricalEndOfDayTimer(this.startDateTime); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); ! ! } ! protected override void run_initializeAccount() ! { ! //default account with no commissions ! this.account = new Account( this.scriptName , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider )); ! ! } ! ! private void newDateTimeEventHandler( object sender , DateTime dateTime ) ! { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! this.checkDateForReport( sender , dateTime ); } ! protected override void run_addEventHandlers() ! { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( ! // this.endOfDayTimerHandler.MarketOpenEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.endOfDayTimerHandler.MarketCloseEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); ! // ! //this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! ! } ! ! ! public override void Run() ! { ! base.Run(); ! Report report = new Report( this.account , this.historicalMarketValueProvider ); ! report.Create( ! "Run last chosen tickers out of sample", 1 , ! HistoricalEndOfDayTimer.GetMarketClose( this.endDateTime ) , ! // new EndOfDayDateTime( this.endDateTime.DateTime , ! // EndOfDaySpecificTime.MarketClose ) , ! "^SPX" ); ! report.Show(); ! } ! ! // protected override void checkDateForReport( ! // Object sender , DateTime dateTime) ! // { ! // if(dateTime.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! // DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! // //last date is reached by the timer or maxRunning hours ! // //are elapsed from the time script started ! // { ! // this.endOfDayTimer.Stop(); ! // } ! // ! // } ! ! protected override void checkDateForReport( ! Object sender , DateTime dateTime) ! { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! { ! if( dateTime >= this.endDateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.endOfDayTimer.Stop(); ! } ! } ! #endregion ! } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:23
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16680/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVO_OTCStrategy.cs PVO_OTCStrategyLessCorrelated.cs PVOLogItem.cs PVOMain.cs PVOPositions.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: PVOMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOMain.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PVOMain.cs 19 Aug 2008 17:13:00 -0000 1.6 --- PVOMain.cs 29 Sep 2008 21:18:13 -0000 1.7 *************** *** 59,63 **** { private Benchmark benchmark; ! private HistoricalQuoteProvider historicalQuoteProvider; public PVOMain() --- 59,63 ---- { private Benchmark benchmark; ! private HistoricalMarketValueProvider historicalQuoteProvider; public PVOMain() *************** *** 159,163 **** } ! protected override IEndOfDayStrategyForBacktester getEndOfDayStrategy() { int inSampleDays = 180; --- 159,163 ---- } ! protected override IStrategyForBacktester getStrategyForBacktester() { int inSampleDays = 180; *************** *** 172,176 **** double minimumAcceptableGain = 0.002; int closeToCloseIntervalLength = 1; ! IEndOfDayStrategyForBacktester endOfDayStrategy // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , // inSampleDays , benchmark , numDaysBetweenEachOptimization , --- 172,176 ---- double minimumAcceptableGain = 0.002; int closeToCloseIntervalLength = 1; ! IStrategyForBacktester strategyForBacktester // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , // inSampleDays , benchmark , numDaysBetweenEachOptimization , *************** *** 182,186 **** oversoldThresholdMAX , overboughtThresholdMAX , historicalQuoteProvider, maxAcceptableDrawDown, minimumAcceptableGain ); ! return endOfDayStrategy; } protected override EndOfDayStrategyBackTester getEndOfDayStrategyBackTester() --- 182,186 ---- oversoldThresholdMAX , overboughtThresholdMAX , historicalQuoteProvider, maxAcceptableDrawDown, minimumAcceptableGain ); ! return strategyForBacktester; } protected override EndOfDayStrategyBackTester getEndOfDayStrategyBackTester() *************** *** 197,201 **** DateTime lastDateTime = new DateTime( 2004 , 12, 31 ); double maxRunningHours = 8; ! HistoricalQuoteProvider quoteProviderForBackTester = this.historicalQuoteProvider; quoteProviderForBackTester = --- 197,201 ---- DateTime lastDateTime = new DateTime( 2004 , 12, 31 ); double maxRunningHours = 8; ! HistoricalMarketValueProvider quoteProviderForBackTester = this.historicalQuoteProvider; quoteProviderForBackTester = *************** *** 203,207 **** EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.endOfDayStrategy , quoteProviderForBackTester , accountProvider , firstDateTime , lastDateTime , --- 203,207 ---- EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.strategyForBacktester , quoteProviderForBackTester , accountProvider , firstDateTime , lastDateTime , Index: PVOPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOPositions.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PVOPositions.cs 14 Aug 2008 23:28:06 -0000 1.3 --- PVOPositions.cs 29 Sep 2008 21:18:13 -0000 1.4 *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 34,67 **** namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { ! /// <summary> ! /// This is the class representing a TestingPositions for the ! /// portfolio value oscillator strategy ! /// </summary> ! [Serializable] ! public class PVOPositions : TestingPositions, IGeneticallyOptimizable ! { ! private double oversoldThreshold; ! private double overboughtThreshold; ! private int numDaysForOscillatingPeriod; ! private int generation; ! private static ReturnsManager returnsManager; ! ! public double OversoldThreshold ! { ! get{return this.oversoldThreshold;} set{this.oversoldThreshold = value;} ! } ! public double OverboughtThreshold ! { ! get{return this.overboughtThreshold;} set{this.overboughtThreshold = value;} ! } ! public int NumDaysForOscillatingPeriod ! { ! get{return this.numDaysForOscillatingPeriod;} ! } ! //explicit interface implementation //the property can be used only by a interface --- 34,67 ---- namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { ! /// <summary> ! /// This is the class representing a TestingPositions for the ! /// portfolio value oscillator strategy ! /// </summary> ! [Serializable] ! public class PVOPositions : TestingPositions, IGeneticallyOptimizable ! { ! private double oversoldThreshold; ! private double overboughtThreshold; ! private int numDaysForOscillatingPeriod; ! private int generation; ! private static ReturnsManager returnsManager; ! ! public double OversoldThreshold ! { ! get{return this.oversoldThreshold;} set{this.oversoldThreshold = value;} ! } ! public double OverboughtThreshold ! { ! get{return this.overboughtThreshold;} set{this.overboughtThreshold = value;} ! } ! public int NumDaysForOscillatingPeriod ! { ! get{return this.numDaysForOscillatingPeriod;} ! } ! //explicit interface implementation //the property can be used only by a interface *************** *** 77,82 **** return new PVOPositions(this.WeightedPositions, this.OversoldThreshold, ! this.overboughtThreshold, ! this.numDaysForOscillatingPeriod); } --- 77,82 ---- return new PVOPositions(this.WeightedPositions, this.OversoldThreshold, ! this.overboughtThreshold, ! this.numDaysForOscillatingPeriod); } *************** *** 88,158 **** public PVOPositions(WeightedPositions weightedPositions, ! double oversoldThreshold, ! double overboughtThreshold, ! int numDaysForOscillatingPeriod) : ! base(weightedPositions) ! ! { ! this.oversoldThreshold = oversoldThreshold; ! this.overboughtThreshold = overboughtThreshold; ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.generation = -1; } ! private void setReturnsManager(EndOfDayDateTime beginOfPeriod, ! EndOfDayDateTime endOfPeriod, ! string benchmark, ! HistoricalQuoteProvider quoteProvider) { if(PVOPositions.returnsManager == null || PVOPositions.returnsManager.ReturnIntervals[0].Begin != beginOfPeriod || ! PVOPositions.returnsManager.ReturnIntervals[0].End != endOfPeriod) ! //if a returnsManager has not been set yet or a different one has to be set ! //for a different returnInterval ! PVOPositions.returnsManager = new ReturnsManager(new ReturnIntervals( ! new ReturnInterval( beginOfPeriod, endOfPeriod ) ) , ! quoteProvider ); } ! private double getOscillatingPeriodReturn(EndOfDayDateTime beginOfPeriod, ! EndOfDayDateTime endOfPeriod, ! string benchmark, ! HistoricalQuoteProvider quoteProvider) ! { ! this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); return this.WeightedPositions.GetReturn(0, PVOPositions.returnsManager); ! } ! public PVOPositionsStatus GetStatus(EndOfDayDateTime beginOfPeriod, ! EndOfDayDateTime endOfPeriod, string benchmark, ! HistoricalQuoteProvider quoteProvider, ! double maxOversoldThreshold, double maxOverboughtThreshold) ! { ! PVOPositionsStatus returnValue; double oscillatingPeriodReturn = double.NaN; ! oscillatingPeriodReturn = ! this.getOscillatingPeriodReturn(beginOfPeriod, endOfPeriod, benchmark, ! quoteProvider); ! if(oscillatingPeriodReturn >= this.overboughtThreshold && ! oscillatingPeriodReturn <= maxOverboughtThreshold) ! returnValue = PVOPositionsStatus.Overbought; ! else if(oscillatingPeriodReturn <= -this.oversoldThreshold && ! Math.Abs(oscillatingPeriodReturn) <= maxOversoldThreshold) ! returnValue = PVOPositionsStatus.Oversold; ! else if ( Math.Abs(oscillatingPeriodReturn) > maxOversoldThreshold || ! oscillatingPeriodReturn > maxOverboughtThreshold ) ! returnValue = PVOPositionsStatus.OverMaximumThresholds; ! else ! returnValue = PVOPositionsStatus.InTheMiddle; ! return returnValue; ! } ! public bool AreAllTickersMovingTogetherUpOrDown(EndOfDayDateTime beginOfPeriod, ! EndOfDayDateTime endOfPeriod, ! string benchmark, ! HistoricalQuoteProvider quoteProvider) { bool returnValue = true; --- 88,158 ---- public PVOPositions(WeightedPositions weightedPositions, ! double oversoldThreshold, ! double overboughtThreshold, ! int numDaysForOscillatingPeriod) : ! base(weightedPositions) ! ! { ! this.oversoldThreshold = oversoldThreshold; ! this.overboughtThreshold = overboughtThreshold; ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.generation = -1; } ! private void setReturnsManager(DateTime beginOfPeriod, ! DateTime endOfPeriod, ! string benchmark, ! HistoricalMarketValueProvider quoteProvider) { if(PVOPositions.returnsManager == null || PVOPositions.returnsManager.ReturnIntervals[0].Begin != beginOfPeriod || ! PVOPositions.returnsManager.ReturnIntervals[0].End != endOfPeriod) ! //if a returnsManager has not been set yet or a different one has to be set ! //for a different returnInterval ! PVOPositions.returnsManager = new ReturnsManager(new ReturnIntervals( ! new ReturnInterval( beginOfPeriod, endOfPeriod ) ) , ! quoteProvider ); } ! private double getOscillatingPeriodReturn(DateTime beginOfPeriod, ! DateTime endOfPeriod, ! string benchmark, ! HistoricalMarketValueProvider quoteProvider) ! { ! this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); return this.WeightedPositions.GetReturn(0, PVOPositions.returnsManager); ! } ! public PVOPositionsStatus GetStatus(DateTime beginOfPeriod, ! DateTime endOfPeriod, string benchmark, ! HistoricalMarketValueProvider quoteProvider, ! double maxOversoldThreshold, double maxOverboughtThreshold) ! { ! PVOPositionsStatus returnValue; double oscillatingPeriodReturn = double.NaN; ! oscillatingPeriodReturn = ! this.getOscillatingPeriodReturn(beginOfPeriod, endOfPeriod, benchmark, ! quoteProvider); ! if(oscillatingPeriodReturn >= this.overboughtThreshold && ! oscillatingPeriodReturn <= maxOverboughtThreshold) ! returnValue = PVOPositionsStatus.Overbought; ! else if(oscillatingPeriodReturn <= -this.oversoldThreshold && ! Math.Abs(oscillatingPeriodReturn) <= maxOversoldThreshold) ! returnValue = PVOPositionsStatus.Oversold; ! else if ( Math.Abs(oscillatingPeriodReturn) > maxOversoldThreshold || ! oscillatingPeriodReturn > maxOverboughtThreshold ) ! returnValue = PVOPositionsStatus.OverMaximumThresholds; ! else ! returnValue = PVOPositionsStatus.InTheMiddle; ! return returnValue; ! } ! public bool AreAllTickersMovingTogetherUpOrDown(DateTime beginOfPeriod, ! DateTime endOfPeriod, ! string benchmark, ! HistoricalMarketValueProvider quoteProvider) { bool returnValue = true; *************** *** 161,176 **** this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); for( int i = 0; ! signedTickers.Count > 1 && i < signedTickers.Count - 1 && returnValue == true; ! i++ ) { returnOfCurrentTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i ].Ticker, 0); returnOfNextTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i+1 ].Ticker, 0); if( (returnOfCurrentTicker > 0 && returnOfNextTicker < 0) || ! (returnOfCurrentTicker < 0 && returnOfNextTicker > 0) ) returnValue = false; ! } return returnValue; } ! } } --- 161,176 ---- this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); for( int i = 0; ! signedTickers.Count > 1 && i < signedTickers.Count - 1 && returnValue == true; ! i++ ) { returnOfCurrentTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i ].Ticker, 0); returnOfNextTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i+1 ].Ticker, 0); if( (returnOfCurrentTicker > 0 && returnOfNextTicker < 0) || ! (returnOfCurrentTicker < 0 && returnOfNextTicker > 0) ) returnValue = false; ! } return returnValue; } ! } } Index: PVO_OTCStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCStrategy.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PVO_OTCStrategy.cs 19 Aug 2008 17:13:00 -0000 1.6 --- PVO_OTCStrategy.cs 29 Sep 2008 21:18:13 -0000 1.7 *************** *** 25,28 **** --- 25,29 ---- using QuantProject.ADT; + using QuantProject.ADT.Histories; using QuantProject.ADT.Messaging; using QuantProject.Business.Financial.Accounting; *************** *** 57,61 **** /// </summary> [Serializable] ! public class PVO_OTCStrategy : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; --- 58,64 ---- /// </summary> [Serializable] ! public class PVO_OTCStrategy : ! QuantProject.Business.Strategies.EndOfDayTimerHandler , ! IStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; *************** *** 68,72 **** protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalQuoteProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; --- 71,75 ---- protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalMarketValueProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; *************** *** 136,140 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider) { this.numOfClosingsWithOpenPositions = 0; --- 139,143 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider) { this.numOfClosingsWithOpenPositions = 0; *************** *** 165,169 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 168,172 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 185,189 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 188,192 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 206,210 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 209,213 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 226,230 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 229,233 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 239,254 **** ! #region MarketOpenEventHandler ! protected virtual EndOfDayDateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], ! EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! EndOfDayDateTime today = timer.GetCurrentTime(); ! EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = --- 242,261 ---- ! #region marketOpenEventHandler ! protected virtual DateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! DateTime beginOfOscillatingPeriod = ! HistoricalEndOfDayTimer.GetMarketClose( ! (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"] ); ! return beginOfOscillatingPeriod; ! // return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], ! // EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentDateTime(); ! DateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = *************** *** 318,323 **** } ! public virtual void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Portfolio.Count == 0 && --- 325,330 ---- } ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if ( this.account.Portfolio.Count == 0 && *************** *** 340,355 **** public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } ! private EndOfDayDateTime now() { ! return this.account.EndOfDayTimer.GetCurrentTime(); } ! public virtual void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) --- 347,362 ---- public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { } ! private DateTime now() { ! return this.account.Timer.GetCurrentDateTime(); } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.account.Portfolio.Count > 0) *************** *** 364,374 **** } ! #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime) { ReturnIntervals returnIntervals = ! new DailyOpenToCloseIntervals( firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ); if( this.inSampleChooser is PVOCorrelationChooser ) --- 371,381 ---- } ! #region oneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(DateTime firstDateTime, ! DateTime lastDayDateTime) { ReturnIntervals returnIntervals = ! new DailyOpenToCloseIntervals( firstDateTime, lastDayDateTime, this.benchmark.Ticker ); if( this.inSampleChooser is PVOCorrelationChooser ) *************** *** 377,402 **** { case IntervalsType.CloseToCloseIntervals: ! returnIntervals = new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.OpenToOpenIntervals: ! returnIntervals = new OpenToOpenIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.CloseToOpenIntervals: ! returnIntervals = new CloseToOpenIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker); break; case IntervalsType.OpenToCloseIntervals: ! returnIntervals = new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ); break; case IntervalsType.OpenToCloseCloseToOpenIntervals: returnIntervals = new OpenToCloseCloseToOpenIntervals( ! firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker); break; default: // it should never be reached ! returnIntervals = new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ); break; --- 384,409 ---- { case IntervalsType.CloseToCloseIntervals: ! returnIntervals = new CloseToCloseIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.OpenToOpenIntervals: ! returnIntervals = new OpenToOpenIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker, ((PVOCorrelationChooser)this.inSampleChooser).ReturnIntervalLength); break; case IntervalsType.CloseToOpenIntervals: ! returnIntervals = new CloseToOpenIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker); break; case IntervalsType.OpenToCloseIntervals: ! returnIntervals = new DailyOpenToCloseIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker ); break; case IntervalsType.OpenToCloseCloseToOpenIntervals: returnIntervals = new OpenToCloseCloseToOpenIntervals( ! firstDateTime, lastDayDateTime, this.benchmark.Ticker); break; default: // it should never be reached ! returnIntervals = new DailyOpenToCloseIntervals(firstDateTime, lastDayDateTime, this.benchmark.Ticker ); break; *************** *** 505,518 **** protected virtual void updateTestingPositions(DateTime currentDate) { ! EndOfDayHistory endOfDayHistory = this.benchmark.GetEndOfDayHistory( ! new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! EndOfDaySpecificTime.MarketOpen), ! new EndOfDayDateTime(currentDate, ! EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = ! this.eligiblesSelector.GetEligibleTickers(endOfDayHistory); ! this.updateReturnsManager(endOfDayHistory.FirstEndOfDayDateTime, ! endOfDayHistory.LastEndOfDayDateTime); if( ( this.eligiblesSelector is DummyEligibleSelector && this.inSampleChooser != null ) || --- 512,529 ---- protected virtual void updateTestingPositions(DateTime currentDate) { ! History history = this.benchmark.GetEndOfDayHistory( ! HistoricalEndOfDayTimer.GetMarketOpen( ! currentDate.AddDays( -this.inSampleDays ) ) , ! HistoricalEndOfDayTimer.GetMarketClose( ! currentDate ) ); ! // new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! // EndOfDaySpecificTime.MarketOpen), ! // new EndOfDayDateTime(currentDate, ! // EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = ! this.eligiblesSelector.GetEligibleTickers(history); ! this.updateReturnsManager(history.FirstDateTime, ! history.LastDateTime); if( ( this.eligiblesSelector is DummyEligibleSelector && this.inSampleChooser != null ) || *************** *** 542,546 **** ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ! ( this.now().DateTime >= dateTimeForNextOptimization ) ); } return areToBeUpdated; --- 553,557 ---- ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ! ( this.now() >= dateTimeForNextOptimization ) ); } return areToBeUpdated; *************** *** 552,559 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public virtual void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.numDaysElapsedSinceLastOptimization++; //OLD - numDaysBetweenEachOptimization --> market days --- 563,570 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! this.lastCloseDate = dateTime; this.numDaysElapsedSinceLastOptimization++; //OLD - numDaysBetweenEachOptimization --> market days *************** *** 566,576 **** if ( this.optimalTestingPositionsAreToBeUpdated() ) { ! this.updateTestingPositions(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; ! this.lastOptimizationDateTime = this.now().DateTime; } } #endregion } } --- 577,598 ---- if ( this.optimalTestingPositionsAreToBeUpdated() ) { ! this.updateTestingPositions(dateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; ! this.lastOptimizationDateTime = this.now(); } } #endregion + + // public virtual void NewDateTimeEventHandler( + // Object sender , DateTime dateTime ) + // { + // if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + // this.marketOpenEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + // this.marketCloseEventHandler( sender , dateTime ); + // if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + // this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + // } } } Index: PVOLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOLogItem.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PVOLogItem.cs 14 Aug 2008 23:28:06 -0000 1.4 --- PVOLogItem.cs 29 Sep 2008 21:18:13 -0000 1.5 *************** *** 140,146 **** } ! public PVOLogItem(EndOfDayDateTime endOfDayDateTime, int numberOfInSampleDays) ! : base( endOfDayDateTime ) { this.numberOfInSampleDays = numberOfInSampleDays; --- 140,146 ---- } ! public PVOLogItem(DateTime dateTime, int numberOfInSampleDays) ! : base( dateTime ) { this.numberOfInSampleDays = numberOfInSampleDays; *************** *** 153,158 **** { //general ! DateTime firstDateTime = this.SimulatedCreationTime.DateTime.AddDays(-this.numberOfInSampleDays); ! DateTime lastDateTime = this.SimulatedCreationTime.DateTime; double maxRunningHours = 1; Benchmark benchmark = new Benchmark( "^GSPC" ); --- 153,158 ---- { //general ! DateTime firstDateTime = this.SimulatedCreationDateTime.AddDays(-this.numberOfInSampleDays); ! DateTime lastDateTime = this.SimulatedCreationDateTime; double maxRunningHours = 1; Benchmark benchmark = new Benchmark( "^GSPC" ); *************** *** 167,171 **** double maxAcceptableCloseToCloseDrawdown = 0.02; double minimumAcceptableGain = 0.007; ! HistoricalQuoteProvider historicalQuoteProviderForBackTester, historicalQuoteProviderForInSampleChooser, historicalQuoteProviderForStrategy; --- 167,171 ---- double maxAcceptableCloseToCloseDrawdown = 0.02; double minimumAcceptableGain = 0.007; ! HistoricalMarketValueProvider historicalQuoteProviderForBackTester, historicalQuoteProviderForInSampleChooser, historicalQuoteProviderForStrategy; *************** *** 211,215 **** int currentIndex , TestingPositions testingPositions , ! EndOfDayDateTime simulatedCreationTime ) { this.dummyTestersForBestTestingPositionsInSample[ currentIndex ] = --- 211,215 ---- int currentIndex , TestingPositions testingPositions , ! DateTime simulatedCreationDateTime ) { this.dummyTestersForBestTestingPositionsInSample[ currentIndex ] = *************** *** 217,221 **** testingPositions , this.numberOfInSampleDays , ! simulatedCreationTime ); } --- 217,221 ---- testingPositions , this.numberOfInSampleDays , ! simulatedCreationDateTime ); } *************** *** 228,232 **** i , BestPVOPositionsInSample[ i ] , ! this.SimulatedCreationTime ); } --- 228,232 ---- i , BestPVOPositionsInSample[ i ] , ! this.SimulatedCreationDateTime ); } Index: PVO_OTCStrategyLessCorrelated.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCStrategyLessCorrelated.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PVO_OTCStrategyLessCorrelated.cs 19 Aug 2008 17:13:00 -0000 1.3 --- PVO_OTCStrategyLessCorrelated.cs 29 Sep 2008 21:18:13 -0000 1.4 *************** *** 25,29 **** --- 25,31 ---- using QuantProject.ADT; + using QuantProject.ADT.Histories; using QuantProject.ADT.Messaging; + using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; *************** *** 44,48 **** using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; - using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; --- 46,49 ---- *************** *** 56,60 **** /// </summary> [Serializable] ! public class PVO_OTCStrategyLessCorrelated : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; --- 57,61 ---- /// </summary> [Serializable] ! public class PVO_OTCStrategyLessCorrelated : IStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; *************** *** 67,71 **** protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalQuoteProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; --- 68,72 ---- protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalMarketValueProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; *************** *** 125,129 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { this.eligiblesSelector = eligiblesSelector; --- 126,130 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { this.eligiblesSelector = eligiblesSelector; *************** *** 143,147 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 144,148 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 159,163 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider) { --- 160,164 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider) { *************** *** 169,182 **** #region MarketOpenEventHandler ! protected virtual EndOfDayDateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], ! EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! EndOfDayDateTime today = timer.GetCurrentTime(); ! EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = --- 170,188 ---- #region MarketOpenEventHandler ! protected virtual DateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! DateTime beginOfOscillatingPeriod = ! HistoricalEndOfDayTimer.GetMarketClose( ! (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"] ); ! return beginOfOscillatingPeriod; ! // ! // return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], ! // EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentDateTime(); ! DateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = *************** *** 246,251 **** } ! public virtual void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Portfolio.Count == 0 && --- 252,257 ---- } ! private void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if ( this.account.Portfolio.Count == 0 && *************** *** 266,282 **** #endregion ! public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } ! private EndOfDayDateTime now() { ! return this.account.EndOfDayTimer.GetCurrentTime(); } ! public virtual void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) --- 272,288 ---- #endregion ! private void fiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { } ! private DateTime now() { ! return this.account.Timer.GetCurrentDateTime(); } ! private void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.account.Portfolio.Count > 0) *************** *** 286,294 **** #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime) { this.returnsManager = ! new ReturnsManager( new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ) , this.historicalQuoteProvider); --- 292,300 ---- #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(DateTime firstDateTime, ! DateTime lastDateTime) { this.returnsManager = ! new ReturnsManager( new DailyOpenToCloseIntervals(firstDateTime, lastDateTime, this.benchmark.Ticker ) , this.historicalQuoteProvider); *************** *** 373,386 **** protected virtual void updateTestingPositions(DateTime currentDate) { ! EndOfDayHistory endOfDayHistory = this.benchmark.GetEndOfDayHistory( ! new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! EndOfDaySpecificTime.MarketOpen), ! new EndOfDayDateTime(currentDate, ! EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = ! this.eligiblesSelector.GetEligibleTickers(endOfDayHistory); ! this.updateReturnsManager(endOfDayHistory.FirstEndOfDayDateTime, ! endOfDayHistory.LastEndOfDayDateTime); if(this.inSampleChooser != null) this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager); --- 379,395 ---- protected virtual void updateTestingPositions(DateTime currentDate) { ! History history = this.benchmark.GetEndOfDayHistory( ! HistoricalEndOfDayTimer.GetMarketOpen( ! currentDate.AddDays(-this.inSampleDays) ) , ! HistoricalEndOfDayTimer.GetMarketClose( currentDate ) ); ! // new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! // EndOfDaySpecificTime.MarketOpen), ! // new EndOfDayDateTime(currentDate, ! // EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = ! this.eligiblesSelector.GetEligibleTickers(history); ! this.updateReturnsManager(history.FirstDateTime, ! history.LastDateTime); if(this.inSampleChooser != null) this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager); *************** *** 401,405 **** ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ! ( this.now().DateTime >= dateTimeForNextOptimization ) ); } return areToBeUpdated; --- 410,414 ---- ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ! ( this.now() >= dateTimeForNextOptimization ) ); } return areToBeUpdated; *************** *** 411,418 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public virtual void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.numDaysElapsedSinceLastOptimization++; //OLD - numDaysBetweenEachOptimization --> market days --- 420,427 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! private void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! this.lastCloseDate = dateTime; this.numDaysElapsedSinceLastOptimization++; //OLD - numDaysBetweenEachOptimization --> market days *************** *** 425,435 **** if ( this.optimalTestingPositionsAreToBeUpdated() ) { ! this.updateTestingPositions(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; ! this.lastOptimizationDateTime = this.now().DateTime; } } #endregion } } --- 434,455 ---- if ( this.optimalTestingPositionsAreToBeUpdated() ) { ! this.updateTestingPositions(dateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; ! this.lastOptimizationDateTime = this.now(); } } #endregion + + public virtual void NewDateTimeEventHandler( + Object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) + this.marketOpenEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + this.marketCloseEventHandler( sender , dateTime ); + if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) + this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); + } } } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17578/TrendFollowing/ImmediateTrendFollower Modified Files: EndOfDayTimerHandlerITF.cs GenomeManagerITF.cs RunImmediateTrendFollower.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: GenomeManagerITF.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower/GenomeManagerITF.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GenomeManagerITF.cs 14 Jan 2008 23:38:36 -0000 1.3 --- GenomeManagerITF.cs 29 Sep 2008 21:19:39 -0000 1.4 *************** *** 72,83 **** private void setReturnsManager() { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketClose); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); this.returnsManager = new ReturnsManager( new CloseToCloseIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, this.benchmark, this.numDaysForReturnCalculation) , --- 72,85 ---- private void setReturnsManager() { ! DateTime firstDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( firstQuoteDate ); ! // new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketClose); ! DateTime lastDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( lastQuoteDate ); ! // new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); this.returnsManager = new ReturnsManager( new CloseToCloseIntervals( ! firstDateTime, ! lastDateTime, this.benchmark, this.numDaysForReturnCalculation) , *************** *** 107,114 **** protected override float[] getStrategyReturns() { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketClose); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); float[] plainReturns = this.weightedPositionsFromGenome.GetReturns( this.returnsManager); --- 109,118 ---- protected override float[] getStrategyReturns() { ! DateTime firstDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( firstQuoteDate ); ! // new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketClose); ! DateTime lastDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( lastQuoteDate ); ! // new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); float[] plainReturns = this.weightedPositionsFromGenome.GetReturns( this.returnsManager); Index: EndOfDayTimerHandlerITF.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower/EndOfDayTimerHandlerITF.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** EndOfDayTimerHandlerITF.cs 19 Aug 2008 17:11:28 -0000 1.7 --- EndOfDayTimerHandlerITF.cs 29 Sep 2008 21:19:39 -0000 1.8 *************** *** 45,49 **** /// </summary> [Serializable] ! public class EndOfDayTimerHandlerITF : EndOfDayTimerHandler { private int numDaysForReturnCalculation; --- 45,50 ---- /// </summary> [Serializable] ! public class EndOfDayTimerHandlerITF : ! QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios.EndOfDayTimerHandler { private int numDaysForReturnCalculation; *************** *** 80,91 **** } ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } ! #region MarketCloseEventHandler ! protected void marketCloseEventHandler_updateStopLossCondition() { --- 81,91 ---- } ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { ; } ! #region marketCloseEventHandler protected void marketCloseEventHandler_updateStopLossCondition() { *************** *** 160,165 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //this.marketCloseEventHandler_updateStopLossCondition(); --- 160,165 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { //this.marketCloseEventHandler_updateStopLossCondition(); *************** *** 176,184 **** } ! #endregion ! ! #region OneHourAfterMarketCloseEventHandler ! protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { --- 176,182 ---- } ! #endregion marketCloseEventHandler ! #region oneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { *************** *** 276,283 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.seedForRandomGenerator++; this.numDaysElapsedSinceLastOptimization++; --- 274,281 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! this.lastCloseDate = dateTime; this.seedForRandomGenerator++; this.numDaysElapsedSinceLastOptimization++; *************** *** 287,291 **** //it is the first close (OLD IMPLEMENTATION) { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; --- 285,289 ---- //it is the first close (OLD IMPLEMENTATION) { ! this.setTickers(dateTime, false); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; *************** *** 293,297 **** } ! #endregion } } --- 291,295 ---- } ! #endregion oneHourAfterMarketCloseEventHandler } } Index: RunImmediateTrendFollower.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower/RunImmediateTrendFollower.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunImmediateTrendFollower.cs 19 Aug 2008 17:13:08 -0000 1.2 --- RunImmediateTrendFollower.cs 29 Sep 2008 21:19:39 -0000 1.3 *************** *** 95,115 **** protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.endOfDayTimerHandler.MarketCloseEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); } --- 95,120 ---- protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { ! ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.checkDateForReport ); ! ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.endOfDayTimerHandler.MarketCloseEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); ! // ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); } *************** *** 134,138 **** //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); --- 139,143 ---- //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentDateTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:21
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17551/TestingOTCTypes Modified Files: RunEfficientOTCTypes.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: RunEfficientOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/RunEfficientOTCTypes.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RunEfficientOTCTypes.cs 19 Aug 2008 17:13:05 -0000 1.9 --- RunEfficientOTCTypes.cs 29 Sep 2008 21:19:35 -0000 1.10 *************** *** 3,7 **** RunEfficientOTCTypes.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientOTCTypes.cs ! Copyright (C) 2003 Marco Milletti *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 38,42 **** using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 38,42 ---- using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 47,184 **** { ! /// <summary> /// Script to test OTC daily, OTC multiday and OTC - CTO ! /// all together with one optimization and 3 accounts (each for /// each type of strategy) /// </summary> ! [Serializable] ! public class RunEfficientOTCTypes : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! private Account[] accounts; ! ! public RunEfficientOTCTypes(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, double targetReturn, ! PortfolioType portfolioType, double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! this.ScriptName = "OTCTypes_SR_WithCoeffOnlyMutationPriceSel"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.accounts = new Account[4]; ! } ! ! #region auxiliary overriden methods for Run ! ! ! protected override void run_initializeAccount() ! { ! for(int i = 0; i<this.accounts.Length; i++) ! { ! this.accounts[i] = new Account( this.ScriptName, this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider )); ! } ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCTypes(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization, this.accounts); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! protected override void run_addEventHandlers() ! { ! this.endOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( ! this.endOfDayTimerHandler.MarketOpenEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.endOfDayTimerHandler.MarketCloseEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! } ! #endregion ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } ! public override void SaveScriptResults() ! { ! string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! "From"+ this.tickerGroupID+ "_" + ! this.numberOfEligibleTickers + ! "_OptDays" + this.numDaysForOptimizationPeriod + "_Portf" + ! this.numberOfTickersToBeChosen + "_GenNum" + ! this.generationNumberForGeneticOptimizer + ! "_PopSize" + this.populationSizeForGeneticOptimizer + ! Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveAccounts = ! System.Configuration.ConfigurationManager.AppSettings["AccountsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = ! System.Configuration.ConfigurationManager.AppSettings["GenomesArchive"] + ! "\\" + this.ScriptName + "\\"; ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); ! ! for(int i = 0; i<this.accounts.Length; i++) ! { ! ObjectArchiver.Archive(accounts[i], ! dirNameWhereToSaveAccounts + ! fileName + "#" + i.ToString() + ".qPa"); ! ObjectArchiver.Archive(this.accounts[i].Transactions, ! dirNameWhereToSaveTransactions + ! fileName + "#" + i.ToString() + ".qPt"); ! } ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! this.endOfDayTimer.Stop(); ! } } } --- 47,190 ---- { ! /// <summary> /// Script to test OTC daily, OTC multiday and OTC - CTO ! /// all together with one optimization and 3 accounts (each for /// each type of strategy) /// </summary> ! [Serializable] ! public class RunEfficientOTCTypes : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! private Account[] accounts; ! ! public RunEfficientOTCTypes(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, double targetReturn, ! PortfolioType portfolioType, double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! this.ScriptName = "OTCTypes_SR_WithCoeffOnlyMutationPriceSel"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.accounts = new Account[4]; ! } ! ! #region auxiliary overriden methods for Run ! ! ! protected override void run_initializeAccount() ! { ! for(int i = 0; i<this.accounts.Length; i++) ! { ! this.accounts[i] = new Account( this.ScriptName, this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider )); ! } ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCTypes(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization, this.accounts); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! protected override void run_addEventHandlers() ! { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.checkDateForReport ); ! ! ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( ! // this.endOfDayTimerHandler.MarketOpenEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.endOfDayTimerHandler.MarketCloseEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); ! // ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! } ! #endregion ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } ! public override void SaveScriptResults() ! { ! string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! "From"+ this.tickerGroupID+ "_" + ! this.numberOfEligibleTickers + ! "_OptDays" + this.numDaysForOptimizationPeriod + "_Portf" + ! this.numberOfTickersToBeChosen + "_GenNum" + ! this.generationNumberForGeneticOptimizer + ! "_PopSize" + this.populationSizeForGeneticOptimizer + ! Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveAccounts = ! System.Configuration.ConfigurationManager.AppSettings["AccountsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = ! System.Configuration.ConfigurationManager.AppSettings["GenomesArchive"] + ! "\\" + this.ScriptName + "\\"; ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); ! ! for(int i = 0; i<this.accounts.Length; i++) ! { ! ObjectArchiver.Archive(accounts[i], ! dirNameWhereToSaveAccounts + ! fileName + "#" + i.ToString() + ".qPa"); ! ObjectArchiver.Archive(this.accounts[i].Transactions, ! dirNameWhereToSaveTransactions + ! fileName + "#" + i.ToString() + ".qPt"); ! } ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! this.endOfDayTimer.Stop(); ! } } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:19
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17551/TestingOTCTypes/BruteForceOptimization Modified Files: RunEfficientOTCTypesBruteForce.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: RunEfficientOTCTypesBruteForce.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization/RunEfficientOTCTypesBruteForce.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunEfficientOTCTypesBruteForce.cs 19 Aug 2008 17:13:05 -0000 1.2 --- RunEfficientOTCTypesBruteForce.cs 29 Sep 2008 21:19:35 -0000 1.3 *************** *** 3,7 **** RunEfficientOTCTypesBruteForce.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientOTCTypesBruteForce.cs ! Copyright (C) 2003 Marco Milletti *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 39,43 **** using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; --- 39,43 ---- using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 48,174 **** { ! /// <summary> /// Script to test OTC daily, OTC multiday and OTC - CTO ! /// all together with one brute force optimization and 3 accounts (each for /// each type of strategy) /// </summary> ! [Serializable] ! public class RunEfficientOTCTypesBruteForce : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! private Account[] accounts; ! ! public RunEfficientOTCTypesBruteForce(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! string benchmark, ! DateTime startDate, DateTime endDate, ! double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! 1,100, benchmark, ! startDate, endDate, 0.0, ! PortfolioType.ShortAndLong, maxRunningHours) ! { ! this.ScriptName = "OTC_SR_PriceSelBruteForce"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.accounts = new Account[4]; ! } ! ! #region auxiliary overriden methods for Run ! ! ! protected override void run_initializeAccount() ! { ! for(int i = 0; i<this.accounts.Length; i++) ! { ! this.accounts[i] = new Account( this.ScriptName, this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider )); ! } ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCTypesBruteForce(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.benchmark, this.numDaysBetweenEachOptimization, ! this.accounts); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! protected override void run_addEventHandlers() ! { ! this.endOfDayTimer.MarketOpen += ! new MarketOpenEventHandler( ! this.endOfDayTimerHandler.MarketOpenEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.endOfDayTimerHandler.MarketCloseEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! } ! #endregion ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } ! public override void SaveScriptResults() ! { ! string fileName = "From"+this.numberOfEligibleTickers + ! "OptDays" + this.numDaysForOptimizationPeriod + "Portfolio" + ! this.numberOfTickersToBeChosen + "BruteForce"; ! string dirNameWhereToSaveAccounts = ! System.Configuration.ConfigurationManager.AppSettings["AccountsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = ! System.Configuration.ConfigurationManager.AppSettings["GenomesArchive"] + ! "\\" + this.ScriptName + "\\"; ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); ! ! for(int i = 0; i<this.accounts.Length; i++) ! { ! ObjectArchiver.Archive(accounts[i], ! dirNameWhereToSaveAccounts + ! fileName + "#" + i.ToString() + ".qPa"); ! ObjectArchiver.Archive(this.accounts[i].Transactions, ! dirNameWhereToSaveTransactions + ! fileName + "#" + i.ToString() + ".qPt"); ! } ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! this.endOfDayTimer.Stop(); ! } } } --- 48,185 ---- { ! /// <summary> /// Script to test OTC daily, OTC multiday and OTC - CTO ! /// all together with one brute force optimization and 3 accounts (each for /// each type of strategy) /// </summary> ! [Serializable] ! public class RunEfficientOTCTypesBruteForce : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! private Account[] accounts; ! ! public RunEfficientOTCTypesBruteForce(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! string benchmark, ! DateTime startDate, DateTime endDate, ! double maxRunningHours, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! 1,100, benchmark, ! startDate, endDate, 0.0, ! PortfolioType.ShortAndLong, maxRunningHours) ! { ! this.ScriptName = "OTC_SR_PriceSelBruteForce"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.accounts = new Account[4]; ! } ! ! #region auxiliary overriden methods for Run ! ! ! protected override void run_initializeAccount() ! { ! for(int i = 0; i<this.accounts.Length; i++) ! { ! this.accounts[i] = new Account( this.ScriptName, this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider )); ! } ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCTypesBruteForce(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.benchmark, this.numDaysBetweenEachOptimization, ! this.accounts); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! private void newDateTimeEventHandler( object sender , DateTime dateTime ) ! { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! this.checkDateForReport( sender , dateTime ); ! } ! ! protected override void run_addEventHandlers() ! { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! ! // this.endOfDayTimer.MarketOpen += ! // new MarketOpenEventHandler( ! // this.endOfDayTimerHandler.MarketOpenEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.endOfDayTimerHandler.MarketCloseEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); ! // ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! } ! #endregion ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } ! public override void SaveScriptResults() ! { ! string fileName = "From"+this.numberOfEligibleTickers + ! "OptDays" + this.numDaysForOptimizationPeriod + "Portfolio" + ! this.numberOfTickersToBeChosen + "BruteForce"; ! string dirNameWhereToSaveAccounts = ! System.Configuration.ConfigurationManager.AppSettings["AccountsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveTransactions = ! System.Configuration.ConfigurationManager.AppSettings["TransactionsArchive"] + ! "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveBestGenomes = ! System.Configuration.ConfigurationManager.AppSettings["GenomesArchive"] + ! "\\" + this.ScriptName + "\\"; ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); ! ! for(int i = 0; i<this.accounts.Length; i++) ! { ! ObjectArchiver.Archive(accounts[i], ! dirNameWhereToSaveAccounts + ! fileName + "#" + i.ToString() + ".qPa"); ! ObjectArchiver.Archive(this.accounts[i].Transactions, ! dirNameWhereToSaveTransactions + ! fileName + "#" + i.ToString() + ".qPt"); ! } ! OptimizationOutput optimizationOutput = new OptimizationOutput(); ! foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) ! optimizationOutput.Add(genomeRepresentation); ! ObjectArchiver.Archive(optimizationOutput, ! dirNameWhereToSaveBestGenomes + ! fileName + ".bgn"); ! this.endOfDayTimer.Stop(); ! } } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:17
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17626/PairsTrading/OutOfSampleChoosers Modified Files: OutOfSampleChooser.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: OutOfSampleChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers/OutOfSampleChooser.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OutOfSampleChooser.cs 27 Apr 2008 17:42:52 -0000 1.1 --- OutOfSampleChooser.cs 29 Sep 2008 21:19:47 -0000 1.2 *************** *** 38,41 **** --- 38,42 ---- /// this class selects the positions to be opened /// </summary> + [Serializable] public abstract class OutOfSampleChooser { *************** *** 75,79 **** #region getReturnsManagerForLastSecondPhaseInterval ! private EndOfDayDateTime getIntervalBeginForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals ) --- 76,80 ---- #region getReturnsManagerForLastSecondPhaseInterval ! private DateTime getIntervalBeginForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals ) *************** *** 86,90 **** return secondLastInterval.End; } ! private EndOfDayDateTime getIntervalEndForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals ) --- 87,91 ---- return secondLastInterval.End; } ! private DateTime getIntervalEndForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals ) *************** *** 96,103 **** ReturnIntervals outOfSampleReturnIntervals ) { ! EndOfDayDateTime intervalBegin = this.getIntervalBeginForLastSecondPhaseInterval( outOfSampleReturnIntervals ); ! EndOfDayDateTime intervalEnd = this.getIntervalEndForLastSecondPhaseInterval( outOfSampleReturnIntervals ); --- 97,104 ---- ReturnIntervals outOfSampleReturnIntervals ) { ! DateTime intervalBegin = this.getIntervalBeginForLastSecondPhaseInterval( outOfSampleReturnIntervals ); ! DateTime intervalEnd = this.getIntervalEndForLastSecondPhaseInterval( outOfSampleReturnIntervals ); *************** *** 119,123 **** private ReturnsManager getReturnsManagerForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals , ! IHistoricalQuoteProvider historicalQuoteProviderForChosingPositionsOutOfSample ) { ReturnIntervals returnIntervals = --- 120,125 ---- private ReturnsManager getReturnsManagerForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample ) { ReturnIntervals returnIntervals = *************** *** 129,133 **** ReturnsManager returnsManager = new ReturnsManager( returnIntervals , ! historicalQuoteProviderForChosingPositionsOutOfSample ); return returnsManager; } --- 131,135 ---- ReturnsManager returnsManager = new ReturnsManager( returnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); return returnsManager; } *************** *** 249,259 **** TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , ! IHistoricalQuoteProvider ! historicalQuoteProviderForChosingPositionsOutOfSample ) { ReturnsManager returnsManagerForLastSecondPhaseInterval = this.getReturnsManagerForLastSecondPhaseInterval( outOfSampleReturnIntervals , ! historicalQuoteProviderForChosingPositionsOutOfSample ); ArrayList inefficientCouples = this.getInefficientCouples( bestTestingPositionsInSample , --- 251,261 ---- TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample ) { ReturnsManager returnsManagerForLastSecondPhaseInterval = this.getReturnsManagerForLastSecondPhaseInterval( outOfSampleReturnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); ArrayList inefficientCouples = this.getInefficientCouples( bestTestingPositionsInSample , *************** *** 288,293 **** TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , ! IHistoricalQuoteProvider ! historicalQuoteProviderForChosingPositionsOutOfSample ) { ArrayList arrayListOfInefficientCouples = --- 290,295 ---- TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample ) { ArrayList arrayListOfInefficientCouples = *************** *** 295,299 **** bestTestingPositionsInSample , outOfSampleReturnIntervals , ! historicalQuoteProviderForChosingPositionsOutOfSample ); WeightedPositions[] inefficientCouples = this.getInefficientCouplesFromArrayList( arrayListOfInefficientCouples ); --- 297,301 ---- bestTestingPositionsInSample , outOfSampleReturnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); WeightedPositions[] inefficientCouples = this.getInefficientCouplesFromArrayList( arrayListOfInefficientCouples ); *************** *** 324,329 **** TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , ! IHistoricalQuoteProvider ! historicalQuoteProviderForChosingPositionsOutOfSample ) { WeightedPositions[] inefficientCouples = null; --- 326,331 ---- TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample ) { WeightedPositions[] inefficientCouples = null; *************** *** 334,338 **** bestTestingPositionsInSample , outOfSampleReturnIntervals , ! historicalQuoteProviderForChosingPositionsOutOfSample ); return inefficientCouples; --- 336,340 ---- bestTestingPositionsInSample , outOfSampleReturnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); return inefficientCouples; *************** *** 353,358 **** TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , ! IHistoricalQuoteProvider ! historicalQuoteProviderForChosingPositionsOutOfSample , ReturnsManager inSampleReturnsManager ) { --- 355,360 ---- TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , ! HistoricalMarketValueProvider ! historicalMarketValueProviderForChosingPositionsOutOfSample , ReturnsManager inSampleReturnsManager ) { *************** *** 362,366 **** bestTestingPositionsInSample , outOfSampleReturnIntervals , ! historicalQuoteProviderForChosingPositionsOutOfSample ); if ( inefficientCouples != null ) // at least an inefficient couple has been found --- 364,368 ---- bestTestingPositionsInSample , outOfSampleReturnIntervals , ! historicalMarketValueProviderForChosingPositionsOutOfSample ); if ( inefficientCouples != null ) // at least an inefficient couple has been found |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:16
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/BestAndWorst In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17462/TrendFollowing/BestAndWorst Modified Files: EndOfDayTimerHandlerBWFollower.cs RunBestAndWorstFollower.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: EndOfDayTimerHandlerBWFollower.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/BestAndWorst/EndOfDayTimerHandlerBWFollower.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerBWFollower.cs 19 Aug 2008 17:11:26 -0000 1.2 --- EndOfDayTimerHandlerBWFollower.cs 29 Sep 2008 21:19:23 -0000 1.3 *************** *** 43,47 **** /// </summary> [Serializable] ! public class EndOfDayTimerHandlerBWFollower { private string tickerGroupID; --- 43,47 ---- /// </summary> [Serializable] ! public class EndOfDayTimerHandlerBWFollower : EndOfDayTimerHandler { private string tickerGroupID; *************** *** 87,91 **** } ! #region MarketOpenEventHandler private void addOrderForTicker(string[] tickers, --- 87,91 ---- } ! #region marketOpenEventHandler private void addOrderForTicker(string[] tickers, *************** *** 161,166 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.orders.Count == 0 && this.account.Transactions.Count == 0) --- 161,166 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if(this.orders.Count == 0 && this.account.Transactions.Count == 0) *************** *** 179,183 **** #endregion ! #region MarketCloseEventHandler private void closePosition( string ticker ) --- 179,183 ---- #endregion ! #region marketCloseEventHandler private void closePosition( string ticker ) *************** *** 195,200 **** } ! public void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) --- 195,200 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.account.Portfolio.Count > 0) *************** *** 204,209 **** { this.closePositions(); ! this.OneHourAfterMarketCloseEventHandler(sender,endOfDayTimingEventArgs); ! this.MarketOpenEventHandler(sender, endOfDayTimingEventArgs); this.closesElapsedWithSomeOpenPosition = 0; } --- 204,209 ---- { this.closePositions(); ! this.oneHourAfterMarketCloseEventHandler(sender,dateTime); ! this.marketOpenEventHandler(sender, dateTime); this.closesElapsedWithSomeOpenPosition = 0; } *************** *** 213,218 **** if( ((IndexBasedEndOfDayTimer)sender).CurrentDateArrayPosition >= this.lengthInDaysForPerformance ) { ! this.OneHourAfterMarketCloseEventHandler(sender,endOfDayTimingEventArgs); ! this.MarketOpenEventHandler(sender, endOfDayTimingEventArgs); } } --- 213,218 ---- if( ((IndexBasedEndOfDayTimer)sender).CurrentDateArrayPosition >= this.lengthInDaysForPerformance ) { ! this.oneHourAfterMarketCloseEventHandler(sender,dateTime); ! this.marketOpenEventHandler(sender, dateTime); } } *************** *** 221,225 **** #endregion ! #region OneHourAfterMarketCloseEventHandler private void oneHourAfterMarketCloseEventHandler_clear() --- 221,225 ---- #endregion ! #region oneHourAfterMarketCloseEventHandler private void oneHourAfterMarketCloseEventHandler_clear() *************** *** 239,247 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.oneHourAfterMarketCloseEventHandler_clear(); ! DateTime currentDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; int currentDateArrayPositionInTimer = ((IndexBasedEndOfDayTimer)sender).CurrentDateArrayPosition; DateTime firstDateForPerformanceComputation = --- 239,247 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.oneHourAfterMarketCloseEventHandler_clear(); ! DateTime currentDate = dateTime; int currentDateArrayPositionInTimer = ((IndexBasedEndOfDayTimer)sender).CurrentDateArrayPosition; DateTime firstDateForPerformanceComputation = Index: RunBestAndWorstFollower.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/BestAndWorst/RunBestAndWorstFollower.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunBestAndWorstFollower.cs 19 Aug 2008 17:13:03 -0000 1.3 --- RunBestAndWorstFollower.cs 29 Sep 2008 21:19:23 -0000 1.4 *************** *** 19,23 **** along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; --- 19,23 ---- along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! */ using System; *************** *** 39,176 **** /// buying and shorting, accordingly, the l best tickers /// and the s worst tickers. ! /// For chosing the best and worst tickers just the /// previous close to close ratio is considered. ! /// The fundamental of the strategy should be the fact (to be verified ...) ! /// that great moves are confirmed the next days /// (just the reversal of simpleOHTest) /// At each close, open positions are closed. /// </summary> ! [Serializable] ! public class RunBestAndWorstFollower ! { ! private string scriptName; ! private string tickerGroupID; ! private string benchmark; ! private int numberOfEligibleTickers; private int lengthInDaysForPerformance; ! private int numOfBestTickers; ! private int numOfWorstTickers; ! private int numOfTickersForBuying; ! private int numOfTickersForShortSelling; ! private DateTime startDate; ! private DateTime endDate; ! private double maxRunningHours; ! private DateTime startingTimeForScript; ! private Account account; ! private IHistoricalQuoteProvider historicalQuoteProvider; ! private IEndOfDayTimer endOfDayTimer; ! public RunBestAndWorstFollower(string tickerGroupID, string benchmark, ! int numberOfEligibleTickers, int lengthInDaysForPerformance, ! int numOfBestTickers, ! int numOfWorstTickers, int numOfTickersForBuying, ! int numOfTickersForShortSelling, ! DateTime startDate, DateTime endDate, ! double maxRunningHours) ! { ! this.tickerGroupID = tickerGroupID; ! this.benchmark = benchmark; ! this.numberOfEligibleTickers = numberOfEligibleTickers; this.lengthInDaysForPerformance = lengthInDaysForPerformance; ! this.numOfBestTickers = numOfBestTickers; ! this.numOfWorstTickers = numOfWorstTickers; ! this.numOfTickersForBuying = numOfTickersForBuying; ! this.numOfTickersForShortSelling = numOfTickersForShortSelling; ! this.startDate = startDate; ! this.endDate = endDate; ! this.maxRunningHours = maxRunningHours; ! this.scriptName = "BWFollower"; ! // this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); ! this.endOfDayTimer = new IndexBasedEndOfDayTimer( ! new EndOfDayDateTime( this.startDate , ! EndOfDaySpecificTime.MarketOpen ) , this.benchmark ); ! } ! public void Run() ! { ! this.startingTimeForScript = DateTime.Now; ! this.account = new Account( "BestAndWorstFollower" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ) ); ! EndOfDayTimerHandlerBWFollower endOfDayTimerHandler = ! new EndOfDayTimerHandlerBWFollower(this.tickerGroupID, this.numberOfEligibleTickers, ! this.lengthInDaysForPerformance, this.numOfBestTickers, this.numOfWorstTickers, ! this.numOfTickersForBuying, this.numOfTickersForShortSelling, ! this.account, this.benchmark); ! // this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( ! // endOfDayTimerHandler.MarketOpenEventHandler ); ! this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( ! endOfDayTimerHandler.MarketCloseEventHandler ); ! this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( ! this.checkDateForReport); ! // this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( ! // endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! ! this.endOfDayTimer.Start(); ! } ! private void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) ! { ! if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDate || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.SaveScriptResults(); ! } ! private void checkDateForReport_createDirIfNotPresent(string dirPath) ! { ! if(!Directory.Exists(dirPath)) ! Directory.CreateDirectory(dirPath); ! } ! public void SaveScriptResults() ! { ! TimeSpan span; span = DateTime.Now.Subtract(this.startingTimeForScript); int secondsElapsed = span.Hours * 3600 + span.Minutes * 60 + span.Seconds; ! string fileName = ! "SecondsElapsed_" + secondsElapsed.ToString() + "_" + ! DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! this.scriptName + "_From_" + this.tickerGroupID + ! "_elig_" + this.numberOfEligibleTickers + ! "_best_" + this.numOfBestTickers + ! "_worst_" + this.numOfWorstTickers + ! "_Long_" + this.numOfTickersForBuying + ! "_Short_" + this.numOfTickersForShortSelling + "_lenInDays_" + this.lengthInDaysForPerformance; ! string dirNameWhereToSaveReports = ! System.Configuration.ConfigurationManager.AppSettings["ReportsArchive"] + ! "\\" + this.scriptName + "\\"; ! ! //default report with numIntervalDays = 1 ! AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), ! this.benchmark, ! // new HistoricalRawQuoteProvider() ); ! new HistoricalAdjustedQuoteProvider()); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".qPr"); ! ! this.endOfDayTimer.Stop(); ! } ! } } --- 39,183 ---- /// buying and shorting, accordingly, the l best tickers /// and the s worst tickers. ! /// For chosing the best and worst tickers just the /// previous close to close ratio is considered. ! /// The fundamental of the strategy should be the fact (to be verified ...) ! /// that great moves are confirmed the next days /// (just the reversal of simpleOHTest) /// At each close, open positions are closed. /// </summary> ! [Serializable] ! public class RunBestAndWorstFollower ! { ! private string scriptName; ! private string tickerGroupID; ! private string benchmark; ! private int numberOfEligibleTickers; private int lengthInDaysForPerformance; ! private int numOfBestTickers; ! private int numOfWorstTickers; ! private int numOfTickersForBuying; ! private int numOfTickersForShortSelling; ! private DateTime startDate; ! private DateTime endDate; ! private double maxRunningHours; ! private DateTime startingTimeForScript; ! private Account account; ! private HistoricalMarketValueProvider historicalMarketValueProvider; ! private Timer endOfDayTimer; ! public RunBestAndWorstFollower(string tickerGroupID, string benchmark, ! int numberOfEligibleTickers, int lengthInDaysForPerformance, ! int numOfBestTickers, ! int numOfWorstTickers, int numOfTickersForBuying, ! int numOfTickersForShortSelling, ! DateTime startDate, DateTime endDate, ! double maxRunningHours) ! { ! this.tickerGroupID = tickerGroupID; ! this.benchmark = benchmark; ! this.numberOfEligibleTickers = numberOfEligibleTickers; this.lengthInDaysForPerformance = lengthInDaysForPerformance; ! this.numOfBestTickers = numOfBestTickers; ! this.numOfWorstTickers = numOfWorstTickers; ! this.numOfTickersForBuying = numOfTickersForBuying; ! this.numOfTickersForShortSelling = numOfTickersForShortSelling; ! this.startDate = startDate; ! this.endDate = endDate; ! this.maxRunningHours = maxRunningHours; ! this.scriptName = "BWFollower"; ! // this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); ! this.endOfDayTimer = new IndexBasedEndOfDayTimer( ! HistoricalEndOfDayTimer.GetMarketOpen( this.startDate ) , ! // new EndOfDayDateTime( this.startDate , ! // EndOfDaySpecificTime.MarketOpen ) , ! this.benchmark ); ! } ! public void Run() ! { ! this.startingTimeForScript = DateTime.Now; ! this.account = new Account( "BestAndWorstFollower" , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider ) ); ! EndOfDayTimerHandlerBWFollower endOfDayTimerHandler = ! new EndOfDayTimerHandlerBWFollower(this.tickerGroupID, this.numberOfEligibleTickers, ! this.lengthInDaysForPerformance, this.numOfBestTickers, this.numOfWorstTickers, ! this.numOfTickersForBuying, this.numOfTickersForShortSelling, ! this.account, this.benchmark); ! // this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( ! // endOfDayTimerHandler.MarketOpenEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.checkDateForReport ); ! // this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( ! // endOfDayTimerHandler.MarketCloseEventHandler ); ! // ! // this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( ! // this.checkDateForReport); ! // this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( ! // endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); ! ! this.endOfDayTimer.Start(); ! } ! private void checkDateForReport(Object sender , DateTime dateTime) ! { ! if(dateTime>=this.endDate || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.SaveScriptResults(); ! } ! private void checkDateForReport_createDirIfNotPresent(string dirPath) ! { ! if(!Directory.Exists(dirPath)) ! Directory.CreateDirectory(dirPath); ! } ! public void SaveScriptResults() ! { ! TimeSpan span; span = DateTime.Now.Subtract(this.startingTimeForScript); int secondsElapsed = span.Hours * 3600 + span.Minutes * 60 + span.Seconds; ! string fileName = ! "SecondsElapsed_" + secondsElapsed.ToString() + "_" + ! DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! this.scriptName + "_From_" + this.tickerGroupID + ! "_elig_" + this.numberOfEligibleTickers + ! "_best_" + this.numOfBestTickers + ! "_worst_" + this.numOfWorstTickers + ! "_Long_" + this.numOfTickersForBuying + ! "_Short_" + this.numOfTickersForShortSelling + "_lenInDays_" + this.lengthInDaysForPerformance; ! string dirNameWhereToSaveReports = ! System.Configuration.ConfigurationManager.AppSettings["ReportsArchive"] + ! "\\" + this.scriptName + "\\"; ! ! //default report with numIntervalDays = 1 ! AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentDateTime(), ! this.benchmark, ! // new HistoricalRawQuoteProvider() ); ! new HistoricalAdjustedQuoteProvider()); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".qPr"); ! ! this.endOfDayTimer.Stop(); ! } ! } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:14
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17551/SimpleSelection Modified Files: RunSimpleSelection.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: RunSimpleSelection.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection/RunSimpleSelection.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunSimpleSelection.cs 19 Aug 2008 17:13:10 -0000 1.3 --- RunSimpleSelection.cs 29 Sep 2008 21:19:36 -0000 1.4 *************** *** 60,66 **** protected ReportTable reportTable; ! protected EndOfDayDateTime startDateTime; ! protected EndOfDayDateTime endDateTime; ! protected IHistoricalQuoteProvider historicalQuoteProvider; protected EndOfDayTimerHandlerSimpleSelection endOfDayTimerHandler; --- 60,66 ---- protected ReportTable reportTable; ! protected DateTime startDateTime; ! protected DateTime endDateTime; ! protected HistoricalMarketValueProvider historicalMarketValueProvider; protected EndOfDayTimerHandlerSimpleSelection endOfDayTimerHandler; *************** *** 68,72 **** protected Account account; ! protected IEndOfDayTimer endOfDayTimer; protected string benchmark; --- 68,72 ---- protected Account account; ! protected QuantProject.Business.Timing.Timer endOfDayTimer; protected string benchmark; *************** *** 96,100 **** public DateTime TimerLastDate { ! get{return this.endOfDayTimer.GetCurrentTime().DateTime ;} } --- 96,100 ---- public DateTime TimerLastDate { ! get{return this.endOfDayTimer.GetCurrentDateTime();} } *************** *** 105,112 **** { ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "SimpleTestGeneric"; --- 105,116 ---- { ! this.startDateTime = ! HistoricalEndOfDayTimer.GetFiveMinutesBeforeMarketClose( startDate ); ! // new EndOfDayDateTime( ! // startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( endDate ); ! // new EndOfDayDateTime( ! // endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "SimpleTestGeneric"; *************** *** 131,138 **** this.numDaysForOptimizationPeriod = numDaysForOptimizationPeriod; this.reportTable = new ReportTable( "Summary_Reports" ); ! this.startDateTime = new EndOfDayDateTime( ! startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = new EndOfDayDateTime( ! endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "SimpleTestGeneric"; --- 135,146 ---- this.numDaysForOptimizationPeriod = numDaysForOptimizationPeriod; this.reportTable = new ReportTable( "Summary_Reports" ); ! this.startDateTime = ! HistoricalEndOfDayTimer.GetFiveMinutesBeforeMarketClose( startDate ); ! // new EndOfDayDateTime( ! // startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); ! this.endDateTime = ! HistoricalEndOfDayTimer.GetOneHourAfterMarketClose( endDate ); ! // new EndOfDayDateTime( ! // endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "SimpleTestGeneric"; *************** *** 159,165 **** this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider )); } --- 167,173 ---- this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider )); } *************** *** 180,191 **** } ! protected virtual void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.SaveScriptResults(); } public virtual void SaveScriptResults() --- 188,214 ---- } ! // protected virtual void checkDateForReport( ! // Object sender , DateTime dateTime) ! // { ! // if(dateTime.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! // DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! // //last date is reached by the timer or maxRunning hours ! // //are elapsed from the time script started ! // this.SaveScriptResults(); ! // } ! ! protected virtual void checkDateForReport( ! Object sender , DateTime dateTime) { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! { ! if( dateTime >= this.endDateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) ! //last date is reached by the timer or maxRunning hours ! //are elapsed from the time script started ! this.SaveScriptResults(); ! } } + public virtual void SaveScriptResults() *************** *** 205,209 **** //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); --- 228,232 ---- //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentDateTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); *************** *** 229,237 **** //run_initializeProgressHandlers(); } protected virtual void run_addEventHandlers() { ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); //in inherited classes'override method: --- 252,270 ---- //run_initializeProgressHandlers(); } + + private void newDateTimeEventHandler( object sender , DateTime dateTime ) + { + if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) + this.checkDateForReport( sender , dateTime ); + } + protected virtual void run_addEventHandlers() { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); //in inherited classes'override method: |