[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination ImmediateTr
Brought to you by:
glauco_1
|
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 ); + } + } } |