quantproject-developers Mailing List for QuantProject (Page 33)
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:20:11
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17425 Modified Files: RunEfficientOTC_WorstAtNightPortfolio.cs RunEfficientOTCCTOPortfolio.cs RunEfficientOTCPortfolio.cs RunEfficientOTCPortfolioMultiday.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: RunEfficientOTCPortfolioMultiday.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientOTCPortfolioMultiday.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunEfficientOTCPortfolioMultiday.cs 29 Aug 2007 10:04:28 -0000 1.2 --- RunEfficientOTCPortfolioMultiday.cs 29 Sep 2008 21:19:16 -0000 1.3 *************** *** 3,7 **** RunEfficientOTCPorfolioMultiday.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientOTCPorfolioMultiday.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; *************** *** 46,50 **** { /// <summary> ! /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// The efficient portfolio's generation rules --- 46,50 ---- { /// <summary> ! /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// The efficient portfolio's generation rules *************** *** 53,81 **** /// - choose the most efficient portfolio among these tickers /// </summary> ! [Serializable] ! public class RunEfficientOTCPortfolioMultiday : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! public RunEfficientOTCPortfolioMultiday(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 numDaysPortfolioLife): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! this.ScriptName = "MultidayOpenCloseScripts_SharpeNoCoeff"; ! this.numDaysBetweenEachOptimization = numDaysPortfolioLife; ! } ! ! #region auxiliary overriden methods for Run ! ! /* delete remark delimitations for having ib commission protected override void run_initializeAccount() { --- 53,81 ---- /// - choose the most efficient portfolio among these tickers /// </summary> ! [Serializable] ! public class RunEfficientOTCPortfolioMultiday : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! public RunEfficientOTCPortfolioMultiday(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 numDaysPortfolioLife): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! this.ScriptName = "MultidayOpenCloseScripts_SharpeNoCoeff"; ! this.numDaysBetweenEachOptimization = numDaysPortfolioLife; ! } ! ! #region auxiliary overriden methods for Run ! ! /* delete remark delimitations for having ib commission protected override void run_initializeAccount() { *************** *** 87,138 **** } ! */ ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCMultiday(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization); ! } ! ! 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(); ! } } } --- 87,143 ---- } ! */ ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCMultiday(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization); ! } ! ! 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(); ! } } } Index: RunEfficientOTC_WorstAtNightPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientOTC_WorstAtNightPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunEfficientOTC_WorstAtNightPortfolio.cs 14 Jan 2008 23:43:47 -0000 1.3 --- RunEfficientOTC_WorstAtNightPortfolio.cs 29 Sep 2008 21:19:16 -0000 1.4 *************** *** 3,7 **** RunEfficientOTCPortfolio_WorstAtNight.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientOTCPortfolio_WorstAtNight.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.Slippage; 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.Slippage; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 47,159 **** { /// <summary> ! /// Script to buy at open and sell at close /// the efficient open to close daily portfolio /// </summary> ! [Serializable] ! public class RunEfficientOTCPortfolio_WorstAtNight : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; protected int numOfGenomesForCTOScanning; ! public RunEfficientOTCPortfolio_WorstAtNight(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, int numOfGenomesForCTOScanning): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! // this.ScriptName = "OTC_WorstAtNight_SharpeRatioWithCoeff_OnlyMutation"; ! //this.ScriptName = "OpenCloseScriptsSharpeRatio"; ! this.ScriptName = "OTC_WorstAtNight_SharpeRatioNoCoeff"; ! //this.ScriptName = "OpenCloseScripts"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.numOfGenomesForCTOScanning = numOfGenomesForCTOScanning; } ! ! ! // delete remark delimitations for having ib commission ! // and a fixed percentage calculation of slippage ! protected override void run_initializeAccount() ! { ! this.account = new Account(this.ScriptName, ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , ! this.historicalQuoteProvider)//, ! // new FixedPercentageSlippageManager(this.historicalQuoteProvider, ! // this.endOfDayTimer,0.08)), ! ); ! //new IBCommissionManager()); ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTC_WorstAtNight(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization, ! this.numOfGenomesForCTOScanning); ! } ! ! 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 ); ! } ! ! public override string SaveScriptResults_CreateFileName() ! { ! return DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! "From_" + this.tickerGroupID + "_" + ! + this.numberOfEligibleTickers + ! "_OptDays" + this.numDaysForOptimizationPeriod + "_Port" + ! this.numberOfTickersToBeChosen + "_GenNum" + ! this.generationNumberForGeneticOptimizer + ! "_PopSize" + this.populationSizeForGeneticOptimizer + ! "_GenomesScanned" + this.numOfGenomesForCTOScanning; } - - - //necessary far calling RunEfficientPortfolio.Run() - //in classes that inherit from this class - public override void Run() - { - base.Run(); - } } } --- 47,164 ---- { /// <summary> ! /// Script to buy at open and sell at close /// the efficient open to close daily portfolio /// </summary> ! [Serializable] ! public class RunEfficientOTCPortfolio_WorstAtNight : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; protected int numOfGenomesForCTOScanning; ! public RunEfficientOTCPortfolio_WorstAtNight(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, int numOfGenomesForCTOScanning): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! // this.ScriptName = "OTC_WorstAtNight_SharpeRatioWithCoeff_OnlyMutation"; ! //this.ScriptName = "OpenCloseScriptsSharpeRatio"; ! this.ScriptName = "OTC_WorstAtNight_SharpeRatioNoCoeff"; ! //this.ScriptName = "OpenCloseScripts"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.numOfGenomesForCTOScanning = numOfGenomesForCTOScanning; } ! ! ! // delete remark delimitations for having ib commission ! // and a fixed percentage calculation of slippage ! protected override void run_initializeAccount() ! { ! this.account = new Account(this.ScriptName, ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , ! this.historicalMarketValueProvider)//, ! // new FixedPercentageSlippageManager(this.historicalQuoteProvider, ! // this.endOfDayTimer,0.08)), ! ); ! //new IBCommissionManager()); ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTC_WorstAtNight(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization, ! this.numOfGenomesForCTOScanning); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! this.historicalMarketValueProvider = new HistoricalRawQuoteProvider(); ! //this.historicalQuoteProvider = 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 ); ! } ! ! public override string SaveScriptResults_CreateFileName() ! { ! return DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + ! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + ! "From_" + this.tickerGroupID + "_" + ! + this.numberOfEligibleTickers + ! "_OptDays" + this.numDaysForOptimizationPeriod + "_Port" + ! this.numberOfTickersToBeChosen + "_GenNum" + ! this.generationNumberForGeneticOptimizer + ! "_PopSize" + this.populationSizeForGeneticOptimizer + ! "_GenomesScanned" + this.numOfGenomesForCTOScanning; ! } ! ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); } } } Index: RunEfficientOTCCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientOTCCTOPortfolio.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunEfficientOTCCTOPortfolio.cs 21 Oct 2005 18:07:45 -0000 1.1 --- RunEfficientOTCCTOPortfolio.cs 29 Sep 2008 21:19:16 -0000 1.2 *************** *** 3,7 **** RunEfficientOTCCTOPorfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientOTCCTOPorfolio.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; *************** *** 46,50 **** { /// <summary> ! /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// The efficient portfolio's generation rules --- 46,50 ---- { /// <summary> ! /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// The efficient portfolio's generation rules *************** *** 53,81 **** /// - choose the most efficient portfolio among these tickers /// </summary> ! [Serializable] ! public class RunEfficientOTCCTOPortfolio : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! public RunEfficientOTCCTOPortfolio(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 = "OpenToClose_CloseToOpenScripts"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! } ! ! #region auxiliary overriden methods for Run ! ! /* delete remark delimitations for having ib commission protected override void run_initializeAccount() { --- 53,81 ---- /// - choose the most efficient portfolio among these tickers /// </summary> ! [Serializable] ! public class RunEfficientOTCCTOPortfolio : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! public RunEfficientOTCCTOPortfolio(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 = "OpenToClose_CloseToOpenScripts"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! } ! ! #region auxiliary overriden methods for Run ! ! /* delete remark delimitations for having ib commission protected override void run_initializeAccount() { *************** *** 87,138 **** } ! */ ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCCTO(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization); ! } ! ! 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(); ! } } } --- 87,143 ---- } ! */ ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCCTO(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization); ! } ! ! 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(); ! } } } Index: RunEfficientOTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientOTCPortfolio.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RunEfficientOTCPortfolio.cs 14 Aug 2008 23:29:40 -0000 1.4 --- RunEfficientOTCPortfolio.cs 29 Sep 2008 21:19:16 -0000 1.5 *************** *** 3,7 **** RunEfficientOTCPortfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientOTCPortfolio.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.Slippage; 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.Slippage; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 47,146 **** { /// <summary> ! /// Script to buy at open and sell at close /// the efficient open to close daily portfolio /// </summary> ! [Serializable] ! public class RunEfficientOTCPortfolio : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! public RunEfficientOTCPortfolio(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 = "OpenCloseScriptsSharpeRatioWithCoeff"; ! //this.ScriptName = "OTC_SharpeRatioWithCoeff_OnlyMutation"; ! //this.ScriptName = "OpenCloseScriptsSharpeRatio"; ! this.ScriptName = "OTC_SharpeRatioNoCoeff"; //this.ScriptName = "OTC_ExpectancyScoreNoCoeff"; ! //this.ScriptName = "OpenCloseScripts"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } - - - // delete remark delimitations for having ib commission - // and a fixed percentage calculation of slippage - protected override void run_initializeAccount() - { - this.account = new Account(this.ScriptName, - this.endOfDayTimer , - new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , - this.historicalQuoteProvider ) , - new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , - this.historicalQuoteProvider)//, - // new FixedPercentageSlippageManager(this.historicalQuoteProvider, - // this.endOfDayTimer,0.08)), - ); - //new IBCommissionManager()); - - } - - - protected override void run_initializeEndOfDayTimerHandler() - { - this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTC(this.tickerGroupID, - this.numberOfEligibleTickers, - this.numberOfTickersToBeChosen, - 10, - this.numDaysForOptimizationPeriod, - this.account, - this.generationNumberForGeneticOptimizer, - this.populationSizeForGeneticOptimizer, - this.benchmark, - this.targetReturn, - this.portfolioType, this.numDaysBetweenEachOptimization); - } - - 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 ); - } - - //necessary far calling RunEfficientPortfolio.Run() - //in classes that inherit from this class - public override void Run() - { - base.Run(); - } } } --- 47,151 ---- { /// <summary> ! /// Script to buy at open and sell at close /// the efficient open to close daily portfolio /// </summary> ! [Serializable] ! public class RunEfficientOTCPortfolio : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! public RunEfficientOTCPortfolio(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 = "OpenCloseScriptsSharpeRatioWithCoeff"; ! //this.ScriptName = "OTC_SharpeRatioWithCoeff_OnlyMutation"; ! //this.ScriptName = "OpenCloseScriptsSharpeRatio"; ! this.ScriptName = "OTC_SharpeRatioNoCoeff"; //this.ScriptName = "OTC_ExpectancyScoreNoCoeff"; ! //this.ScriptName = "OpenCloseScripts"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! } ! ! ! // delete remark delimitations for having ib commission ! // and a fixed percentage calculation of slippage ! protected override void run_initializeAccount() ! { ! this.account = new Account(this.ScriptName, ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , ! this.historicalMarketValueProvider)//, ! // new FixedPercentageSlippageManager(this.historicalQuoteProvider, ! // this.endOfDayTimer,0.08)), ! ); ! //new IBCommissionManager()); ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTC(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! 10, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, this.numDaysBetweenEachOptimization); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! this.historicalMarketValueProvider = new HistoricalRawQuoteProvider(); ! // this.historicalQuoteProvider = 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 ); ! } ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); } } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:20:03
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17497/FixedLengthTwoPhases/Logging Modified Files: FLTPLogItem.cs FLTPSimpleStrategy.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: FLTPLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/Logging/FLTPLogItem.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FLTPLogItem.cs 16 Aug 2008 19:13:54 -0000 1.1 --- FLTPLogItem.cs 29 Sep 2008 21:19:30 -0000 1.2 *************** *** 63,67 **** /// <param name="numberOfEligibleTickers"></param> public FLTPLogItem( ! EndOfDayDateTime now , TestingPositions[] bestTestingPositionsInSample , int numberOfInSampleDays , --- 63,67 ---- /// <param name="numberOfEligibleTickers"></param> public FLTPLogItem( ! DateTime now , TestingPositions[] bestTestingPositionsInSample , int numberOfInSampleDays , *************** *** 90,94 **** int currentIndex , TestingPositions testingPositions , ! EndOfDayDateTime now ) { this.setTestersForFLTPTestingPositions_checkParameters( --- 90,94 ---- int currentIndex , TestingPositions testingPositions , ! DateTime now ) { this.setTestersForFLTPTestingPositions_checkParameters( *************** *** 102,106 **** private void setTestersForFLTPTestingPositions( TestingPositions[] bestTestingPositionsInSample , ! EndOfDayDateTime now ) { this.testersForBestTestingPositionsInSample = --- 102,106 ---- private void setTestersForFLTPTestingPositions( TestingPositions[] bestTestingPositionsInSample , ! DateTime now ) { this.testersForBestTestingPositionsInSample = Index: FLTPSimpleStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/Logging/FLTPSimpleStrategy.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FLTPSimpleStrategy.cs 16 Aug 2008 19:14:44 -0000 1.1 --- FLTPSimpleStrategy.cs 29 Sep 2008 21:19:30 -0000 1.2 *************** *** 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,52 **** public class FLTPSimpleStrategy : SimpleStrategy { public FLTPSimpleStrategy( WeightedPositions weightedPositions , IIntervalsSelector intervalsSelector , ! IHistoricalQuoteProvider historicalQuoteProvider ) : base( weightedPositions , intervalsSelector , ! historicalQuoteProvider ) { } --- 41,60 ---- public class FLTPSimpleStrategy : SimpleStrategy { + public override bool StopBacktestIfMaxRunningHoursHasBeenReached + { + get + { + return true; + } + } + public FLTPSimpleStrategy( WeightedPositions weightedPositions , IIntervalsSelector intervalsSelector , ! HistoricalMarketValueProvider historicalMarketValueProvider ) : base( weightedPositions , intervalsSelector , ! historicalMarketValueProvider ) { } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17302/LinearCombination Modified Files: FixedLevelOscillatorBiasedPVOStrategy.cs FixedLevelOscillatorPVOStrategy.cs FixedPeriodOscillatorStrategy.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: FixedPeriodOscillatorStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/FixedPeriodOscillatorStrategy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FixedPeriodOscillatorStrategy.cs 29 Aug 2007 09:43:36 -0000 1.3 --- FixedPeriodOscillatorStrategy.cs 29 Sep 2008 21:19:09 -0000 1.4 *************** *** 3,7 **** FixedPeriodOscillatorStrategy.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- FixedPeriodOscillatorStrategy.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; *************** *** 37,134 **** /// </summary> [Serializable] ! public class FixedPeriodOscillatorStrategy : EndOfDayTimerHandler, IEndOfDayStrategy { private int daysForRightPeriod; ! private int daysForReversalPeriod; ! //length for movement upwards or downwards of the given tickers ! private int daysCounterWithRightPositions; ! private int daysCounterWithReversalPositions; ! private bool isReversalPeriodOn = false; ! private int numOfClosesElapsed = 0; ! public FixedPeriodOscillatorStrategy( Account account , ! WeightedPositions weightedPositions, ! int daysForRightPeriod, ! int daysForReversalPeriod): ! base("", 0, ! weightedPositions.Count, 0, account, ! 0, ! 0, ! "^GSPC", 0.0, ! PortfolioType.ShortAndLong) { this.account = account; this.chosenWeightedPositions = weightedPositions; ! this.daysForRightPeriod = daysForRightPeriod; ! this.daysForReversalPeriod = daysForReversalPeriod; } ! ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! } - - private void marketCloseEventHandler_updateCounters(bool isTheFirstClose) - { - if(this.account.Portfolio.Count > 0 && isTheFirstClose == false) - { - if(this.isReversalPeriodOn) - this.daysCounterWithReversalPositions++ ; - else - this.daysCounterWithRightPositions++ ; - } - } ! public override void MarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! bool firstClose = false; ! if( (this.numOfClosesElapsed + 1) >= ! (this.daysForRightPeriod + this.daysForReversalPeriod) ) ! //strategy can now be applied because it is tuned with the optimization's results ! { ! if (this.account.Transactions.Count == 0) ! // it is the first close ! { ! firstClose = true; ! this.openPositions(); ! } ! this.marketCloseEventHandler_updateCounters(firstClose); ! if(firstClose == false && this.isReversalPeriodOn == false && ! this.daysCounterWithRightPositions == this.daysForRightPeriod) ! ! { ! AccountManager.ReversePositions(this.account); ! this.isReversalPeriodOn = true; ! } ! ! if(this.isReversalPeriodOn == true && ! this.daysCounterWithReversalPositions == this.daysForReversalPeriod) ! ! { ! AccountManager.ReversePositions(this.account); ! this.isReversalPeriodOn = false; ! } ! } ! ! this.numOfClosesElapsed++; } ! public override void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! } ! ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! } } } --- 37,148 ---- /// </summary> [Serializable] ! public class FixedPeriodOscillatorStrategy : ! QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios.EndOfDayTimerHandler , ! IStrategy { private int daysForRightPeriod; ! private int daysForReversalPeriod; ! //length for movement upwards or downwards of the given tickers ! private int daysCounterWithRightPositions; ! private int daysCounterWithReversalPositions; ! private bool isReversalPeriodOn = false; ! private int numOfClosesElapsed = 0; ! public FixedPeriodOscillatorStrategy( Account account , ! WeightedPositions weightedPositions, ! int daysForRightPeriod, ! int daysForReversalPeriod): ! base("", 0, ! weightedPositions.Count, 0, account, ! 0, ! 0, ! "^GSPC", 0.0, ! PortfolioType.ShortAndLong) { this.account = account; this.chosenWeightedPositions = weightedPositions; ! this.daysForRightPeriod = daysForRightPeriod; ! this.daysForReversalPeriod = daysForReversalPeriod; } ! ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { ! ! } ! ! private void marketCloseEventHandler_updateCounters(bool isTheFirstClose) ! { ! if(this.account.Portfolio.Count > 0 && isTheFirstClose == false) ! { ! if(this.isReversalPeriodOn) ! this.daysCounterWithReversalPositions++ ; ! else ! this.daysCounterWithRightPositions++ ; ! } } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime) { ! bool firstClose = false; ! if( (this.numOfClosesElapsed + 1) >= ! (this.daysForRightPeriod + this.daysForReversalPeriod) ) ! //strategy can now be applied because it is tuned with the optimization's results ! { ! if (this.account.Transactions.Count == 0) ! // it is the first close ! { ! firstClose = true; ! this.openPositions(); ! } ! this.marketCloseEventHandler_updateCounters(firstClose); ! if(firstClose == false && this.isReversalPeriodOn == false && ! this.daysCounterWithRightPositions == this.daysForRightPeriod) ! ! { ! AccountManager.ReversePositions(this.account); ! this.isReversalPeriodOn = true; ! } ! ! if(this.isReversalPeriodOn == true && ! this.daysCounterWithReversalPositions == this.daysForReversalPeriod) ! ! { ! AccountManager.ReversePositions(this.account); ! this.isReversalPeriodOn = false; ! } ! } ! ! this.numOfClosesElapsed++; } ! protected override void oneHourAfterMarketCloseEventHandler( Object sender , ! DateTime dateTime) { ! } ! ! public void FiveMinutesBeforeMarketCloseEventHandler( 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 ); } + } } Index: FixedLevelOscillatorBiasedPVOStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/FixedLevelOscillatorBiasedPVOStrategy.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FixedLevelOscillatorBiasedPVOStrategy.cs 19 Aug 2008 17:11:29 -0000 1.6 --- FixedLevelOscillatorBiasedPVOStrategy.cs 29 Sep 2008 21:19:08 -0000 1.7 *************** *** 43,47 **** /// </summary> [Serializable] ! public class FixedLevelOscillatorBiasedPVOStrategy : EndOfDayTimerHandlerBiasedPVO, IEndOfDayStrategy { --- 43,48 ---- /// </summary> [Serializable] ! public class FixedLevelOscillatorBiasedPVOStrategy : ! EndOfDayTimerHandlerBiasedPVO, IStrategy { *************** *** 74,79 **** } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } --- 75,80 ---- } ! protected void fiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime) { } *************** *** 107,112 **** } ! public override void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { --- 108,113 ---- } ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime) { Index: FixedLevelOscillatorPVOStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/FixedLevelOscillatorPVOStrategy.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FixedLevelOscillatorPVOStrategy.cs 12 Mar 2008 22:09:04 -0000 1.8 --- FixedLevelOscillatorPVOStrategy.cs 29 Sep 2008 21:19:08 -0000 1.9 *************** *** 3,7 **** FixedLevelOscillatorPVOStrategy.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- FixedLevelOscillatorPVOStrategy.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; *************** *** 35,84 **** { /// <summary> ! /// Fixed Level Oscillators /// Portfolio Value Oscillator strategy /// </summary> [Serializable] ! public class FixedLevelOscillatorPVOStrategy : EndOfDayTimerHandlerPVO, IEndOfDayStrategy { ! public FixedLevelOscillatorPVOStrategy( Account accountPVO , ! WeightedPositions chosenWeightedPositions, ! double oversoldThreshold, ! double overboughtThreshold, ! int numDaysForOscillatingPeriod): ! base("", 0, chosenWeightedPositions.Count, 0, ! accountPVO, ! 0,0, ! "^GSPC", ! 0, 0, 0, 0, 0, 0, false, false, 0, ! PortfolioType.ShortAndLong, 0.5, 0.5) { this.chosenWeightedPositions = chosenWeightedPositions; ! this.currentOversoldThreshold = oversoldThreshold; ! this.currentOverboughtThreshold = overboughtThreshold; ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) ! { ! } ! protected override double getCurrentChosenWeightedPositionsReturn(IndexBasedEndOfDayTimer timer) ! { ! double returnValue = 999.0; ! if(timer.CurrentDateArrayPosition - this.numDaysForOscillatingPeriod >= 0) ! //if there are sufficient data for computing currentChosenWeightedPositionsReturn ! //that's why the method has been overriden ! returnValue = ! base.getCurrentChosenWeightedPositionsReturn(timer); ! ! return returnValue; ! } ! public override void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! } } --- 35,84 ---- { /// <summary> ! /// Fixed Level Oscillators /// Portfolio Value Oscillator strategy /// </summary> [Serializable] ! public class FixedLevelOscillatorPVOStrategy : EndOfDayTimerHandlerPVO, IStrategy { ! public FixedLevelOscillatorPVOStrategy( Account accountPVO , ! WeightedPositions chosenWeightedPositions, ! double oversoldThreshold, ! double overboughtThreshold, ! int numDaysForOscillatingPeriod): ! base("", 0, chosenWeightedPositions.Count, 0, ! accountPVO, ! 0,0, ! "^GSPC", ! 0, 0, 0, 0, 0, 0, false, false, 0, ! PortfolioType.ShortAndLong, 0.5, 0.5) { this.chosenWeightedPositions = chosenWeightedPositions; ! this.currentOversoldThreshold = oversoldThreshold; ! this.currentOverboughtThreshold = overboughtThreshold; ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! DateTime dateTime) ! { ! } ! protected override double getCurrentChosenWeightedPositionsReturn(IndexBasedEndOfDayTimer timer) ! { ! double returnValue = 999.0; ! if(timer.CurrentDateArrayPosition - this.numDaysForOscillatingPeriod >= 0) ! //if there are sufficient data for computing currentChosenWeightedPositionsReturn ! //that's why the method has been overriden ! returnValue = ! base.getCurrentChosenWeightedPositionsReturn(timer); ! ! return returnValue; ! } ! protected override void oneHourAfterMarketCloseEventHandler( Object sender , ! DateTime dateTime) { ! } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:57
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17497/WalkForwardLag/WeightedPositionsChoosers Modified Files: IWFLagWeightedPositionsChooser.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: IWFLagWeightedPositionsChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/IWFLagWeightedPositionsChooser.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IWFLagWeightedPositionsChooser.cs 28 Oct 2007 18:46:57 -0000 1.3 --- IWFLagWeightedPositionsChooser.cs 29 Sep 2008 21:19:30 -0000 1.4 *************** *** 40,44 **** WFLagEligibleTickers eligibleTickersForDrivingPositions , WFLagEligibleTickers eligibleTickersForPortfolioPositions , ! EndOfDayDateTime now ); WFLagWeightedPositions WFLagChosenPositions { get; } int NumberOfDrivingPositions { get; } --- 40,44 ---- WFLagEligibleTickers eligibleTickersForDrivingPositions , WFLagEligibleTickers eligibleTickersForPortfolioPositions , ! DateTime now ); WFLagWeightedPositions WFLagChosenPositions { get; } int NumberOfDrivingPositions { get; } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16912 Modified Files: RunEfficientCTCPortfolio.cs RunEfficientCTCWeeklyPortfolio.cs RunEfficientCTO_WorstAtDayPortfolio.cs RunEfficientCTOPortfolio.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: RunEfficientCTCWeeklyPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTCWeeklyPortfolio.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunEfficientCTCWeeklyPortfolio.cs 18 Sep 2005 21:13:36 -0000 1.2 --- RunEfficientCTCWeeklyPortfolio.cs 29 Sep 2008 21:18:58 -0000 1.3 *************** *** 3,7 **** RunEfficientCTCWeeklyPorfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientCTCWeeklyPorfolio.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; *************** *** 54,118 **** public class RunEfficientCTCWeeklyPortfolio : RunEfficientPortfolio { ! protected int numDaysForReturnCalculation; ! protected double maxAcceptableCloseToCloseDrawdown; ! public RunEfficientCTCWeeklyPortfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, ! int numDaysForReturnCalculation, ! double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScriptsWeeklyEfficientPortfolio"; ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; } ! #region auxiliary overriden methods for Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTCWeekly(this.tickerGroupID, this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, this.benchmark, ! this.numDaysForReturnCalculation, ! this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); ! } ! ! 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); ! } ! ! #endregion } } --- 54,123 ---- public class RunEfficientCTCWeeklyPortfolio : RunEfficientPortfolio { ! protected int numDaysForReturnCalculation; ! protected double maxAcceptableCloseToCloseDrawdown; ! public RunEfficientCTCWeeklyPortfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, ! int numDaysForReturnCalculation, ! double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScriptsWeeklyEfficientPortfolio"; ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; } ! #region auxiliary overriden methods for Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTCWeekly(this.tickerGroupID, this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, this.benchmark, ! this.numDaysForReturnCalculation, ! this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); ! } ! ! 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); ! } ! ! ! #endregion } } Index: RunEfficientCTO_WorstAtDayPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTO_WorstAtDayPortfolio.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunEfficientCTO_WorstAtDayPortfolio.cs 30 Jun 2007 18:52:48 -0000 1.1 --- RunEfficientCTO_WorstAtDayPortfolio.cs 29 Sep 2008 21:18:59 -0000 1.2 *************** *** 3,7 **** RunEfficientCTOPorfolio_WorstAtDay.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientCTOPorfolio_WorstAtDay.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.Slippage; 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.Slippage; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 47,144 **** { /// <summary> ! /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// </summary> ! [Serializable] ! public class RunEfficientCTOPortfolio_WorstAtDay : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! protected int numOfGenomesForOTCScanning; ! public RunEfficientCTOPortfolio_WorstAtDay(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, ! int numOfGenomesForOTCScanning): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! this.ScriptName = "CTOWorstAtDay_NoCoeff_SharpeOTCCTO"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.numOfGenomesForOTCScanning = numOfGenomesForOTCScanning; ! } ! ! ! // delete remark delimitations for having ib commission ! // and a fixed percentage calculation of slippage ! protected override void run_initializeAccount() ! { ! this.account = new Account(this.ScriptName, ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , ! this.historicalQuoteProvider)); ! //, new FixedPercentageSlippageManager(this.historicalQuoteProvider, ! // this.endOfDayTimer,0.08)), ! //new IBCommissionManager()); ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTO_WorstAtDay(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, ! this.numDaysBetweenEachOptimization, ! this.numOfGenomesForOTCScanning); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! 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 ); ! } ! ! ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } } } --- 47,149 ---- { /// <summary> ! /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// </summary> ! [Serializable] ! public class RunEfficientCTOPortfolio_WorstAtDay : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! protected int numOfGenomesForOTCScanning; ! public RunEfficientCTOPortfolio_WorstAtDay(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, ! int numOfGenomesForOTCScanning): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, benchmark, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) ! { ! this.ScriptName = "CTOWorstAtDay_NoCoeff_SharpeOTCCTO"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! this.numOfGenomesForOTCScanning = numOfGenomesForOTCScanning; ! } ! ! ! // delete remark delimitations for having ib commission ! // and a fixed percentage calculation of slippage ! protected override void run_initializeAccount() ! { ! this.account = new Account(this.ScriptName, ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , ! this.historicalMarketValueProvider)); ! //, new FixedPercentageSlippageManager(this.historicalQuoteProvider, ! // this.endOfDayTimer,0.08)), ! //new IBCommissionManager()); ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTO_WorstAtDay(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, ! this.numDaysBetweenEachOptimization, ! this.numOfGenomesForOTCScanning); ! } ! ! 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.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 ); ! } ! ! ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } } } Index: RunEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTCPortfolio.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** RunEfficientCTCPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.13 --- RunEfficientCTCPortfolio.cs 29 Sep 2008 21:18:58 -0000 1.14 *************** *** 3,7 **** RunEfficientCTCPorfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientCTCPorfolio.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; *************** *** 47,51 **** /// <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 --- 47,51 ---- /// <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 *************** *** 59,133 **** public class RunEfficientCTCPortfolio : RunEfficientPortfolio { ! protected int numDayOfPortfolioLife; ! protected int numDaysWithNoPositions; ! protected int numDaysForReturnCalculation; ! protected double maxAcceptableCloseToCloseDrawdown; ! protected int numDaysBetweenEachOptimization; ! public RunEfficientCTCPortfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, 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, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScriptsDiscontinuosWithSharpe"; ! //this.ScriptName = "CloseToCloseScriptsDiscontinuosWithCoeff"; ! this.numDayOfPortfolioLife = numDaysOfPortfolioLife; ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.numDaysWithNoPositions = numDaysWithNoPositions; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } ! #region auxiliary overriden methods for Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTC(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); ! } ! ! 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); ! } ! ! #endregion } } --- 59,144 ---- public class RunEfficientCTCPortfolio : RunEfficientPortfolio { ! protected int numDayOfPortfolioLife; ! protected int numDaysWithNoPositions; ! protected int numDaysForReturnCalculation; ! protected double maxAcceptableCloseToCloseDrawdown; ! protected int numDaysBetweenEachOptimization; ! public RunEfficientCTCPortfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, 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, ! startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScriptsDiscontinuosWithSharpe"; ! //this.ScriptName = "CloseToCloseScriptsDiscontinuosWithCoeff"; ! this.numDayOfPortfolioLife = numDaysOfPortfolioLife; ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.numDaysWithNoPositions = numDaysWithNoPositions; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } ! #region auxiliary overriden methods for Run ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTC(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); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! 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.MarketClose += ! // new MarketCloseEventHandler( ! // this.endOfDayTimerHandler.MarketCloseEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); ! // ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); ! } ! ! ! #endregion } } Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** RunEfficientCTOPortfolio.cs 14 May 2006 18:21:47 -0000 1.27 --- RunEfficientCTOPortfolio.cs 29 Sep 2008 21:18:59 -0000 1.28 *************** *** 3,7 **** RunEfficientCTOPorfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- RunEfficientCTOPorfolio.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.Slippage; 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.Slippage; using QuantProject.Data.DataProviders; ! using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 47,140 **** { /// <summary> ! /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// </summary> ! [Serializable] ! public class RunEfficientCTOPortfolio : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! public RunEfficientCTOPortfolio(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 = "CloseToOpenScriptsNoCoeffSharpeRatioCombined"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! } ! ! ! // delete remark delimitations for having ib commission ! // and a fixed percentage calculation of slippage ! protected override void run_initializeAccount() ! { ! this.account = new Account(this.ScriptName, ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , ! this.historicalQuoteProvider)); ! //, new FixedPercentageSlippageManager(this.historicalQuoteProvider, ! // this.endOfDayTimer,0.08)), ! //new IBCommissionManager()); ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTO(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, ! this.numDaysBetweenEachOptimization); ! } ! ! protected override void run_initializeHistoricalQuoteProvider() ! { ! 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 ); ! } ! ! ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } } } --- 47,145 ---- { /// <summary> ! /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// </summary> ! [Serializable] ! public class RunEfficientCTOPortfolio : RunEfficientPortfolio ! { ! protected int numDaysBetweenEachOptimization; ! public RunEfficientCTOPortfolio(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 = "CloseToOpenScriptsNoCoeffSharpeRatioCombined"; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! } ! ! ! // delete remark delimitations for having ib commission ! // and a fixed percentage calculation of slippage ! protected override void run_initializeAccount() ! { ! this.account = new Account(this.ScriptName, ! this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , ! this.historicalMarketValueProvider ) , ! new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , ! this.historicalMarketValueProvider)); ! //, new FixedPercentageSlippageManager(this.historicalQuoteProvider, ! // this.endOfDayTimer,0.08)), ! //new IBCommissionManager()); ! ! } ! ! ! protected override void run_initializeEndOfDayTimerHandler() ! { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTO(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.numDaysForOptimizationPeriod, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer, ! this.benchmark, ! this.targetReturn, ! this.portfolioType, ! this.numDaysBetweenEachOptimization); ! } ! ! 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.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 ); ! } ! ! ! ! //necessary far calling RunEfficientPortfolio.Run() ! //in classes that inherit from this class ! public override void Run() ! { ! base.Run(); ! } } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:50
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17302/FixedLengthTwoPhases Modified Files: FixedLengthTwoPhasesMain.cs FixedLengthTwoPhasesStrategy.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: FixedLengthTwoPhasesStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/FixedLengthTwoPhasesStrategy.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FixedLengthTwoPhasesStrategy.cs 16 Aug 2008 19:35:59 -0000 1.8 --- FixedLengthTwoPhasesStrategy.cs 29 Sep 2008 21:19:08 -0000 1.9 *************** *** 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; *************** *** 44,47 **** --- 44,48 ---- /// first phase, then goes with the opposite for the second phase /// </summary> + [Serializable] public class FixedLengthTwoPhasesStrategy : SymmetricEndOfDayStrategyForBacktester *************** *** 66,70 **** IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , ! IHistoricalQuoteProvider historicalQuoteProvider , RankBasedOutOfSampleChooser outOfSampleChooser ) : --- 67,71 ---- IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , ! HistoricalMarketValueProvider historicalMarketValueProvider , RankBasedOutOfSampleChooser outOfSampleChooser ) : *************** *** 76,80 **** eligiblesSelector , inSampleChooser , ! historicalQuoteProvider ) { this.outOfSampleChooser = outOfSampleChooser; --- 77,81 ---- eligiblesSelector , inSampleChooser , ! historicalMarketValueProvider ) { this.outOfSampleChooser = outOfSampleChooser; *************** *** 97,102 **** bool arePositionsToBeClosed = ( ( this.Account.Portfolio.Count > 0 ) && ! ( this.now().IsEqualTo( ! this.lastIntervalAppended().Begin ) ) ); return arePositionsToBeClosed; } --- 98,103 ---- bool arePositionsToBeClosed = ( ( this.Account.Portfolio.Count > 0 ) && ! ( this.now() == ! this.lastIntervalAppended().Begin ) ); return arePositionsToBeClosed; } *************** *** 114,119 **** { bool beginsTheLastInterval = ! ( this.now().IsEqualTo( ! this.lastIntervalAppended().Begin ) ); bool lastIntervalIsALongPeriod = this.lastAppendedIntervalIsALongPeriod(); --- 115,120 ---- { bool beginsTheLastInterval = ! ( this.now() == ! this.lastIntervalAppended().Begin ); bool lastIntervalIsALongPeriod = this.lastAppendedIntervalIsALongPeriod(); *************** *** 135,139 **** WeightedPositions weightedPositions = this.outOfSampleChooser.GetPositionsToBeOpened( ! this.bestTestingPositionsInSample ); return weightedPositions; } --- 136,140 ---- WeightedPositions weightedPositions = this.outOfSampleChooser.GetPositionsToBeOpened( ! this.bestTestingPositionsInSample ); return weightedPositions; } *************** *** 309,318 **** // new FixedLengthTwoPhasesLogItem( this.now() ); // logItem.BestWeightedPositionsInSample = this.bestWeightedPositionsInSample; ! //// this.wFLagWeightedPositionsChooser.WFLagChosenPositions , ! //// this.wFLagWeightedPositionsChooser.GenerationWhenChosenPositionsWereFound , ! //// this.now().DateTime ); ! //// this.NewChosenPositions( ! //// this , new WFLagNewChosenPositionsEventArgs( ! //// wFLagLogItem ) ); // } // public void OneHourAfterMarketCloseEventHandler( --- 310,319 ---- // new FixedLengthTwoPhasesLogItem( this.now() ); // logItem.BestWeightedPositionsInSample = this.bestWeightedPositionsInSample; ! //// this.wFLagWeightedPositionsChooser.WFLagChosenPositions , ! //// this.wFLagWeightedPositionsChooser.GenerationWhenChosenPositionsWereFound , ! //// this.now().DateTime ); ! //// this.NewChosenPositions( ! //// this , new WFLagNewChosenPositionsEventArgs( ! //// wFLagLogItem ) ); // } // public void OneHourAfterMarketCloseEventHandler( Index: FixedLengthTwoPhasesMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/FixedLengthTwoPhasesMain.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** FixedLengthTwoPhasesMain.cs 18 Aug 2008 21:13:20 -0000 1.10 --- FixedLengthTwoPhasesMain.cs 29 Sep 2008 21:19:08 -0000 1.11 *************** *** 54,60 **** private Benchmark benchmark; private int numberOfPortfolioPositions; ! private IHistoricalQuoteProvider historicalQuoteProviderForInSample; ! private IHistoricalQuoteProvider ! historicalQuoteProviderForTheBacktesterAccount; public FixedLengthTwoPhasesMain() --- 54,60 ---- private Benchmark benchmark; private int numberOfPortfolioPositions; ! private HistoricalMarketValueProvider historicalMarketValueProviderForInSample; ! private HistoricalMarketValueProvider ! historicalMarketValueProviderForTheBacktesterAccount; public FixedLengthTwoPhasesMain() *************** *** 62,68 **** this.benchmark = new Benchmark( "CCE" ); this.numberOfPortfolioPositions = 2; ! this.historicalQuoteProviderForInSample = new HistoricalRawQuoteProvider(); ! this.historicalQuoteProviderForTheBacktesterAccount = new HistoricalRawQuoteProvider(); } --- 62,68 ---- this.benchmark = new Benchmark( "CCE" ); this.numberOfPortfolioPositions = 2; ! this.historicalMarketValueProviderForInSample = new HistoricalRawQuoteProvider(); ! this.historicalMarketValueProviderForTheBacktesterAccount = new HistoricalRawQuoteProvider(); } *************** *** 126,131 **** double mutationRate = 0.02; double elitismRate = 0.001; ! int populationSizeForGeneticOptimizer = 10000; ! int generationNumberForGeneticOptimizer = 5; int seedForRandomGenerator = QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; --- 126,131 ---- double mutationRate = 0.02; double elitismRate = 0.001; ! int populationSizeForGeneticOptimizer = 2000; ! int generationNumberForGeneticOptimizer = 3; int seedForRandomGenerator = QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; *************** *** 136,140 **** benchmark , decoderForWeightedPositions , fitnessEvaluator , ! this.historicalQuoteProviderForInSample , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , --- 136,140 ---- benchmark , decoderForWeightedPositions , fitnessEvaluator , ! this.historicalMarketValueProviderForInSample , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , *************** *** 155,167 **** } ! protected override IEndOfDayStrategyForBacktester getEndOfDayStrategy() { // int numberOfPortfolioPositions = 2; int numDaysForInSampleOptimization = 180; // uncomment the following line for a faster script ! numDaysForInSampleOptimization = 5; numDaysForInSampleOptimization = 45; ! int numDaysBetweenEachOtpimization = 3; IIntervalsSelector intervalsSelector = --- 155,167 ---- } ! protected override IStrategyForBacktester getStrategyForBacktester() { // int numberOfPortfolioPositions = 2; int numDaysForInSampleOptimization = 180; // uncomment the following line for a faster script ! // numDaysForInSampleOptimization = 8; numDaysForInSampleOptimization = 45; ! int numDaysBetweenEachOtpimization = 7; IIntervalsSelector intervalsSelector = *************** *** 179,183 **** benchmark , intervalsSelector , eligiblesSelector , inSampleChooser , ! this.historicalQuoteProviderForInSample , outOfSampleChooser ); // IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = --- 179,183 ---- benchmark , intervalsSelector , eligiblesSelector , inSampleChooser , ! this.historicalMarketValueProviderForInSample , outOfSampleChooser ); // IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = *************** *** 206,217 **** DateTime firstDateTime = new DateTime( 2006 , 1 , 1 ); ! DateTime lastDateTime = new DateTime( 2008 , 4 , 1 ); ! double maxRunningHours = 8; EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.endOfDayStrategy , ! this.historicalQuoteProviderForTheBacktesterAccount , accountProvider , firstDateTime , lastDateTime , --- 206,217 ---- DateTime firstDateTime = new DateTime( 2006 , 1 , 1 ); ! DateTime lastDateTime = new DateTime( 2007 , 12 , 31 ); ! double maxRunningHours = 0.01; EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( ! backTestId , this.strategyForBacktester , ! this.historicalMarketValueProviderForTheBacktesterAccount , accountProvider , firstDateTime , lastDateTime , |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:46
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16144 Modified Files: EndOfDayTimerHandler.cs EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandlerCTCWeekly.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandlerCTO_WorstAtDay.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: EndOfDayTimerHandlerCTO_WorstAtDay.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO_WorstAtDay.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerCTO_WorstAtDay.cs 19 Aug 2008 17:11:26 -0000 1.4 --- EndOfDayTimerHandlerCTO_WorstAtDay.cs 29 Sep 2008 21:17:34 -0000 1.5 *************** *** 78,83 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { AccountManager.ClosePositions(this.account); --- 78,83 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { AccountManager.ClosePositions(this.account); *************** *** 91,96 **** double lossOfCurrentWorstCombination = 0.0; double fitnessOfPreviousCombination = 0.0; ! IndexBasedEndOfDayTimer currentTimer = (IndexBasedEndOfDayTimer)this.account.EndOfDayTimer; ! DateTime today = currentTimer.GetCurrentTime().DateTime; int numOfGenomesScanned = 0; for(int i = 0; numOfGenomesScanned < this.numOfGenomesForOTCScanning; i++) --- 91,97 ---- double lossOfCurrentWorstCombination = 0.0; double fitnessOfPreviousCombination = 0.0; ! IndexBasedEndOfDayTimer currentTimer = ! (IndexBasedEndOfDayTimer)this.account.Timer; ! DateTime today = currentTimer.GetCurrentDateTime(); int numOfGenomesScanned = 0; for(int i = 0; numOfGenomesScanned < this.numOfGenomesForOTCScanning; i++) *************** *** 134,139 **** ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.currentGO != null) --- 135,140 ---- ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.currentGO != null) *************** *** 144,148 **** } ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) --- 145,149 ---- } ! #region oneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) *************** *** 222,227 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.seedForRandomGenerator++; --- 223,228 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.seedForRandomGenerator++; *************** *** 230,234 **** this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; --- 231,235 ---- this.numDaysBetweenEachOptimization - 1) { ! this.setTickers( dateTime , false); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; Index: EndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandler.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** EndOfDayTimerHandler.cs 14 Aug 2008 23:29:40 -0000 1.28 --- EndOfDayTimerHandler.cs 29 Sep 2008 21:17:34 -0000 1.29 *************** *** 3,7 **** EndOfDayTimerHandler.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- EndOfDayTimerHandler.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; 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; *************** *** 33,79 **** namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { ! /// <summary> ! /// Base class for EndOfDayTimerHandlers for efficient portfolios ! /// </summary> ! [Serializable] ! public abstract class EndOfDayTimerHandler ! { ! protected DataTable eligibleTickers; protected WeightedPositions chosenWeightedPositions = null; ! protected string tickerGroupID; ! protected int numberOfEligibleTickers; ! protected int numberOfTickersToBeChosen; ! protected int numDaysForOptimizationPeriod; ! protected int numDaysBetweenEachOptimization = 0; ! protected int numDaysElapsedSinceLastOptimization = 0; ! protected int generationNumberForGeneticOptimizer; ! protected int populationSizeForGeneticOptimizer; ! protected Account account = null; ! protected string benchmark; ! //these two values have to be updated during ! //backtest, for minimizing commission amount, ! //according to broker's commission scheme ! protected double minPriceForMinimumCommission = 30; ! protected double maxPriceForMinimumCommission = 500; ! protected double targetReturn; ! protected PortfolioType portfolioType; ! ! protected bool stopLossConditionReached = false; ! protected bool takeProfitConditionReached = false; ! protected double currentAccountValue = 0.0; ! protected double previousAccountValue = 0.0; ! protected GenomeCounter genomeCounter; ! public GenomeCounter GenomeCounter ! { ! get{return this.genomeCounter;} ! } ! ! public int NumberOfEligibleTickers ! { ! get { return this.numberOfEligibleTickers; } ! } ! public Account Account { get { return this.account; } --- 33,79 ---- namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { ! /// <summary> ! /// Base class for EndOfDayTimerHandlers for efficient portfolios ! /// </summary> ! [Serializable] ! public abstract class EndOfDayTimerHandler ! { ! protected DataTable eligibleTickers; protected WeightedPositions chosenWeightedPositions = null; ! protected string tickerGroupID; ! protected int numberOfEligibleTickers; ! protected int numberOfTickersToBeChosen; ! protected int numDaysForOptimizationPeriod; ! protected int numDaysBetweenEachOptimization = 0; ! protected int numDaysElapsedSinceLastOptimization = 0; ! protected int generationNumberForGeneticOptimizer; ! protected int populationSizeForGeneticOptimizer; ! protected Account account = null; ! protected string benchmark; ! //these two values have to be updated during ! //backtest, for minimizing commission amount, ! //according to broker's commission scheme ! protected double minPriceForMinimumCommission = 30; ! protected double maxPriceForMinimumCommission = 500; ! protected double targetReturn; ! protected PortfolioType portfolioType; ! ! protected bool stopLossConditionReached = false; ! protected bool takeProfitConditionReached = false; ! protected double currentAccountValue = 0.0; ! protected double previousAccountValue = 0.0; ! protected GenomeCounter genomeCounter; ! public GenomeCounter GenomeCounter ! { ! get{return this.genomeCounter;} ! } ! public int NumberOfEligibleTickers ! { ! get { return this.numberOfEligibleTickers; } ! } ! ! public Account Account { get { return this.account; } *************** *** 81,284 **** } ! /// <summary> ! /// bestGenomes[ i ] contains an array list with the best genomes ! /// for generation i ! /// </summary> ! protected ArrayList bestGenomes; ! public ArrayList BestGenomes ! { ! get { return this.bestGenomes; } ! } ! private void endOfDayTimerHandler_initializeBasic(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, ! int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, double targetReturn, ! PortfolioType portfolioType) ! { ! this.tickerGroupID = tickerGroupID; ! this.numberOfEligibleTickers = numberOfEligibleTickers; ! this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; ! this.numDaysForOptimizationPeriod = numDaysForOptimizationPeriod; ! this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; ! this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; ! this.benchmark = benchmark; ! this.targetReturn = targetReturn; ! this.portfolioType = portfolioType; ! } ! public EndOfDayTimerHandler(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, ! int numDaysForOptimizationPeriod, Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, double targetReturn, ! PortfolioType portfolioType) ! { ! this.endOfDayTimerHandler_initializeBasic(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, ! numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType); ! this.account = account; ! ! } public EndOfDayTimerHandler(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, ! int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, double targetReturn, ! PortfolioType portfolioType) ! { ! this.endOfDayTimerHandler_initializeBasic(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, ! numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType); ! } ! public EndOfDayTimerHandler(WeightedPositions chosenWeightedPositions, ! PortfolioType portfolioType, ! Account account, ! string benchmark) ! { ! this.account = account; ! this.benchmark = benchmark; ! this.chosenWeightedPositions = chosenWeightedPositions; ! this.numberOfTickersToBeChosen = this.chosenWeightedPositions.Count; ! this.portfolioType = portfolioType; ! } #region addGenomeToBestGenomes protected void addGenomeToBestGenomes(Genome genome, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! genome.Generation, ! eligibleTickers) ); } protected void addGenomeToBestGenomes(BruteForceOptimizableParameters BFOptimizableParameters, ! SignedTickers signedTickers, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(BFOptimizableParameters, ! signedTickers.ArrayForSignedTickers, ! firstOptimizationDate, ! secondOptimizationDate, ! eligibleTickers) ); } protected void addGenomeToBestGenomes(Genome genome, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers, int halfPeriodDays) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! genome.Generation, ! eligibleTickers, ! halfPeriodDays)); } protected void addGenomeToBestGenomes(Genome genome, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers, int halfPeriodDays, ! PortfolioType portfolioType) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! genome.Generation, ! eligibleTickers, ! halfPeriodDays, portfolioType)); } ! protected void addGenomesToBestGenomes( Genome[] genomes, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers, int halfPeriodDays, ! PortfolioType portfolioType, ! int createdGenerations) ! { foreach(Genome genome in genomes) if(genome != null) ! this.addGenomeToBestGenomes(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! eligibleTickers, halfPeriodDays, ! portfolioType, ! createdGenerations); ! } protected void addGenomeToBestGenomes(Genome genome, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers, int halfPeriodDays, ! PortfolioType portfolioType, ! int createdGenerations) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! genome.Generation, ! eligibleTickers, ! halfPeriodDays, portfolioType, createdGenerations)); } #endregion protected virtual void openPositions() ! { ! //add cash first ! if(this.account.Transactions.Count == 0) ! this.account.AddCash(15000); ! if(this.chosenWeightedPositions != null) ! AccountManager.OpenPositions(this.chosenWeightedPositions, this.account); ! } ! protected void reversePositions() { if ( this.portfolioType == PortfolioType.OnlyLong || ! this.portfolioType == PortfolioType.OnlyShort ) throw new Exception ("It's not possible to reverse positions " + ! "when portfolio has to contain only " + ! "long or short positions!"); AccountManager.ReversePositions(this.account); ! } ! public abstract void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ; ! public abstract void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! ; ! public abstract void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! ; ! } } --- 81,296 ---- } ! /// <summary> ! /// bestGenomes[ i ] contains an array list with the best genomes ! /// for generation i ! /// </summary> ! protected ArrayList bestGenomes; ! public ArrayList BestGenomes ! { ! get { return this.bestGenomes; } ! } ! private void endOfDayTimerHandler_initializeBasic(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, ! int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, double targetReturn, ! PortfolioType portfolioType) ! { ! this.tickerGroupID = tickerGroupID; ! this.numberOfEligibleTickers = numberOfEligibleTickers; ! this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; ! this.numDaysForOptimizationPeriod = numDaysForOptimizationPeriod; ! this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; ! this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; ! this.benchmark = benchmark; ! this.targetReturn = targetReturn; ! this.portfolioType = portfolioType; ! } public EndOfDayTimerHandler(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, ! int numDaysForOptimizationPeriod, Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, double targetReturn, ! PortfolioType portfolioType) ! { ! this.endOfDayTimerHandler_initializeBasic(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, ! numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType); ! this.account = account; ! ! } ! public EndOfDayTimerHandler(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, ! int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, double targetReturn, ! PortfolioType portfolioType) ! { ! this.endOfDayTimerHandler_initializeBasic(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, ! numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType); ! } ! public EndOfDayTimerHandler(WeightedPositions chosenWeightedPositions, ! PortfolioType portfolioType, ! Account account, ! string benchmark) ! { ! this.account = account; ! this.benchmark = benchmark; ! this.chosenWeightedPositions = chosenWeightedPositions; ! this.numberOfTickersToBeChosen = this.chosenWeightedPositions.Count; ! this.portfolioType = portfolioType; ! } #region addGenomeToBestGenomes protected void addGenomeToBestGenomes(Genome genome, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! genome.Generation, ! eligibleTickers) ); } protected void addGenomeToBestGenomes(BruteForceOptimizableParameters BFOptimizableParameters, ! SignedTickers signedTickers, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(BFOptimizableParameters, ! signedTickers.ArrayForSignedTickers, ! firstOptimizationDate, ! secondOptimizationDate, ! eligibleTickers) ); } protected void addGenomeToBestGenomes(Genome genome, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers, int halfPeriodDays) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! genome.Generation, ! eligibleTickers, ! halfPeriodDays)); } protected void addGenomeToBestGenomes(Genome genome, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers, int halfPeriodDays, ! PortfolioType portfolioType) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! genome.Generation, ! eligibleTickers, ! halfPeriodDays, portfolioType)); } ! protected void addGenomesToBestGenomes( Genome[] genomes, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers, int halfPeriodDays, ! PortfolioType portfolioType, ! int createdGenerations) ! { foreach(Genome genome in genomes) if(genome != null) ! this.addGenomeToBestGenomes(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! eligibleTickers, halfPeriodDays, ! portfolioType, ! createdGenerations); ! } protected void addGenomeToBestGenomes(Genome genome, ! DateTime firstOptimizationDate, ! DateTime secondOptimizationDate, ! int eligibleTickers, int halfPeriodDays, ! PortfolioType portfolioType, ! int createdGenerations) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); ! this.bestGenomes.Add(new GenomeRepresentation(genome, ! firstOptimizationDate, ! secondOptimizationDate, ! genome.Generation, ! eligibleTickers, ! halfPeriodDays, portfolioType, createdGenerations)); } #endregion protected virtual void openPositions() ! { ! //add cash first ! if(this.account.Transactions.Count == 0) ! this.account.AddCash(15000); ! if(this.chosenWeightedPositions != null) ! AccountManager.OpenPositions(this.chosenWeightedPositions, this.account); ! } ! protected void reversePositions() { if ( this.portfolioType == PortfolioType.OnlyLong || ! this.portfolioType == PortfolioType.OnlyShort ) throw new Exception ("It's not possible to reverse positions " + ! "when portfolio has to contain only " + ! "long or short positions!"); AccountManager.ReversePositions(this.account); ! } ! #region NewDateTimeEventHandler ! protected abstract void marketOpenEventHandler( ! Object sender , DateTime dateTime ) ; ! protected abstract void marketCloseEventHandler( ! Object sender , DateTime dateTime ) ! ; ! protected abstract void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime 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 ); ! } ! #endregion NewDateTimeEventHandler ! } } Index: EndOfDayTimerHandlerCTCWeekly.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCWeekly.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EndOfDayTimerHandlerCTCWeekly.cs 14 Jan 2008 23:32:31 -0000 1.9 --- EndOfDayTimerHandlerCTCWeekly.cs 29 Sep 2008 21:17:34 -0000 1.10 *************** *** 3,7 **** EndOfDayTimerHandlerCTCWeekly.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- EndOfDayTimerHandlerCTCWeekly.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; 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; *************** *** 37,180 **** { ! /// <summary> ! /// Implements MarketOpenEventHandler and MarketCloseEventHandler ! /// These handlers contain the core strategy for the efficient close to close ! /// weekly portfolio (with a given days of life)! ! /// </summary> ! [Serializable] ! public class EndOfDayTimerHandlerCTCWeekly : EndOfDayTimerHandler ! { ! protected int numDaysForReturnCalculation; ! protected double maxAcceptableCloseToCloseDrawdown; ! ! public EndOfDayTimerHandlerCTCWeekly(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, ! int numDaysForReturnCalculation, ! double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType) ! { ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; ! } ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! ; ! } ! ! #region MarketCloseEventHandler ! ! ! ! protected void updateStopLossCondition() ! { ! this.previousAccountValue = this.currentAccountValue; ! this.currentAccountValue = this.account.GetMarketValue(); ! if((this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) ! { ! this.stopLossConditionReached = true; ! } ! else ! { ! this.stopLossConditionReached = false; ! } ! } ! ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! this.updateStopLossCondition(); ! ! if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.DayOfWeek == ! DayOfWeek.Monday) ! this.openPositions(); ! ! if(this.stopLossConditionReached || ! endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.DayOfWeek == ! DayOfWeek.Friday) ! AccountManager.ClosePositions(this.account); ! ! } ! ! #endregion ! ! #region OneHourAfterMarketCloseEventHandler ! ! protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) ! { ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, ! currentDate); ! ! this.eligibleTickers = temporizedGroup.GetTableOfSelectedTickers(); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = ! new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod),currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); ! } ! ! ! protected virtual void setTickers(DateTime currentDate) ! { ! DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) ! //the optimization process is meaningful only if the initial set of tickers is ! //larger than the number of tickers to be chosen ! ! { ! ! //double targetReturnForEachPeriodOfPortfolioLife = ! // Math.Pow(1.60,(double)(1.0/(360.0/this.numDaysOfPortfolioLife))) - 1.0; ! //the target has to be such that annual system return is minimum 50% ! //(with no commissions and bid-ask spreads) ! IGenomeManager genManEfficientCTCPortfolio = ! new GenomeManagerForEfficientCTCPortfolio(setOfTickersToBeOptimized, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfTickersToBeChosen, ! this.numDaysForReturnCalculation, ! this.targetReturn, ! this.portfolioType, this.benchmark); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); ! //GO.KeepOnRunningUntilConvergenceIsReached = true; ! GO.Run(false); this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); ! } ! //else it will be buyed again the previous optimized portfolio ! //that's it the actual chosenTickers member ! } ! /// <summary> ! /// Handles a "One hour after market close" event. ! /// </summary> ! /// <param name="sender"></param> ! /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! ! if(this.account.Portfolio.Count == 0 && ! endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.DayOfWeek == ! DayOfWeek.Friday) ! { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); ! //it sets tickers to be chosen at next Monday ! } ! } ! #endregion ! } } --- 37,177 ---- { ! /// <summary> ! /// Implements MarketOpenEventHandler and MarketCloseEventHandler ! /// These handlers contain the core strategy for the efficient close to close ! /// weekly portfolio (with a given days of life)! ! /// </summary> ! [Serializable] ! public class EndOfDayTimerHandlerCTCWeekly : EndOfDayTimerHandler ! { ! protected int numDaysForReturnCalculation; ! protected double maxAcceptableCloseToCloseDrawdown; ! ! public EndOfDayTimerHandlerCTCWeekly(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, ! int numDaysForReturnCalculation, ! double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType) ! { ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; ! } ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) ! { ! ; ! } ! ! #region marketCloseEventHandler ! protected void updateStopLossCondition() ! { ! this.previousAccountValue = this.currentAccountValue; ! this.currentAccountValue = this.account.GetMarketValue(); ! if((this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) ! { ! this.stopLossConditionReached = true; ! } ! else ! { ! this.stopLossConditionReached = false; ! } ! } ! ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) ! { ! this.updateStopLossCondition(); ! ! if(dateTime.DayOfWeek == ! DayOfWeek.Monday) ! this.openPositions(); ! ! if(this.stopLossConditionReached || ! dateTime.DayOfWeek == ! DayOfWeek.Friday) ! AccountManager.ClosePositions(this.account); ! ! } ! ! #endregion marketCloseEventHandler ! ! #region oneHourAfterMarketCloseEventHandler ! ! protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) ! { ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, ! currentDate); ! ! this.eligibleTickers = temporizedGroup.GetTableOfSelectedTickers(); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = ! new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod),currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); ! } ! ! ! protected virtual void setTickers(DateTime currentDate) ! { ! DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) ! //the optimization process is meaningful only if the initial set of tickers is ! //larger than the number of tickers to be chosen ! ! { ! ! //double targetReturnForEachPeriodOfPortfolioLife = ! // Math.Pow(1.60,(double)(1.0/(360.0/this.numDaysOfPortfolioLife))) - 1.0; ! //the target has to be such that annual system return is minimum 50% ! //(with no commissions and bid-ask spreads) ! IGenomeManager genManEfficientCTCPortfolio = ! new GenomeManagerForEfficientCTCPortfolio(setOfTickersToBeOptimized, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfTickersToBeChosen, ! this.numDaysForReturnCalculation, ! this.targetReturn, ! this.portfolioType, this.benchmark); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); ! //GO.KeepOnRunningUntilConvergenceIsReached = true; ! GO.Run(false); this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); ! } ! //else it will be buyed again the previous optimized portfolio ! //that's it the actual chosenTickers member ! } ! /// <summary> ! /// Handles a "One hour after market close" event. ! /// </summary> ! /// <param name="sender"></param> ! /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) ! { ! ! if(this.account.Portfolio.Count == 0 && ! dateTime.DayOfWeek == ! DayOfWeek.Friday) ! { ! this.setTickers(dateTime); ! //it sets tickers to be chosen at next Monday ! } ! } ! #endregion oneHourAfterMarketCloseEventHandler ! } } Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** EndOfDayTimerHandlerCTC.cs 14 Jan 2008 23:32:30 -0000 1.25 --- EndOfDayTimerHandlerCTC.cs 29 Sep 2008 21:17:34 -0000 1.26 *************** *** 3,7 **** EndOfDayTimerHandlerCTC.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- EndOfDayTimerHandlerCTC.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; 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; *************** *** 37,259 **** { ! /// <summary> ! /// Implements MarketOpenEventHandler and MarketCloseEventHandler ! /// These handlers contain the core strategy for the efficient close to close ! /// portfolio (with a given days of life)! ! /// </summary> ! [Serializable] ! public class EndOfDayTimerHandlerCTC : EndOfDayTimerHandler ! { ! protected int numDaysOfPortfolioLife; ! protected int numDaysForReturnCalculation; ! protected int numDaysWithNoPositions; ! protected int daysCounterWithPositions; ! protected int daysCounterWithNoPositions; ! protected double maxAcceptableCloseToCloseDrawdown; ! ! public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, ! int numDaysOfPortfolioLife, ! int numDaysForReturnCalculation, ! int numDaysWithNoPositions, ! double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType) ! { ! this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.numDaysWithNoPositions = numDaysWithNoPositions; ! this.daysCounterWithPositions = 0; ! this.daysCounterWithNoPositions = 0; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; ! this.stopLossConditionReached = false; ! this.currentAccountValue = 0.0; ! this.previousAccountValue = 0.0; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! } ! ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! ; ! } ! #region MarketCloseEventHandler ! ! ! ! protected void updateStopLossCondition() ! { ! this.previousAccountValue = this.currentAccountValue; ! this.currentAccountValue = this.account.GetMarketValue(); ! if((this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) ! { ! this.stopLossConditionReached = true; ! } ! else ! { ! this.stopLossConditionReached = false; ! } ! } ! ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! //bool positionsJustClosed = false; ! this.updateStopLossCondition(); ! if(this.account.Portfolio.Count > 0) ! //portfolio is not empty ! { ! this.daysCounterWithPositions++; ! if(this.daysCounterWithPositions == this.numDaysOfPortfolioLife || ! this.stopLossConditionReached) ! //num days of portfolio life or ! //max acceptable close to close drawdown reached ! { ! AccountManager.ClosePositions(this.account); ! this.daysCounterWithPositions = 0; ! //positionsJustClosed = true; ! } ! } ! else//portfolio is empty ! { this.daysCounterWithNoPositions++; if(this.daysCounterWithNoPositions == this.numDaysWithNoPositions || ! this.Account.Transactions.Count <= 1) { AccountManager.OpenPositions(this.chosenWeightedPositions,this.account); ! this.daysCounterWithNoPositions = 0; } } ! } ! //old ! // if(this.account.Portfolio.Count == 0 && ! // !positionsJustClosed) ! // //portfolio is empty but it has not been closed ! // //at the current close ! // { ! // this.openPositions(); ! // this.daysCounter = 0; ! // } ! #endregion ! ! #region OneHourAfterMarketCloseEventHandler ! ! protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) ! { ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, ! currentDate); ! ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketFromTemporized = ! new SelectorByQuotationAtEachMarketDay(temporizedGroup.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod),currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! ! this.eligibleTickers = quotedAtEachMarketFromTemporized.GetTableOfSelectedTickers(); ! ! // SelectorByCloseToCloseCorrelationToBenchmark lessCorrelatedFromEligible = ! // new SelectorByCloseToCloseCorrelationToBenchmark(this.eligibleTickers, ! // this.benchmark,true, ! // currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! // currentDate, ! // this.numberOfEligibleTickers/2, ! // this.numDaysForReturnCalculation); ! // SelectorByAbsolutePerformance mostQuietFromLessCorrelated = ! // new SelectorByAbsolutePerformance(lessCorrelatedFromEligible.GetTableOfSelectedTickers(), ! // true,currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! // currentDate, ! // this.numberOfEligibleTickers/4, ! // 0.01f, 0.10f); ! // ! // return mostQuietFromLessCorrelated.GetTableOfSelectedTickers(); ! return this.eligibleTickers; ! } ! ! ! protected virtual void setTickers(DateTime currentDate, ! bool setGenomeCounter) ! { ! DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) ! //the optimization process is meaningful only if the initial set of tickers is ! //larger than the number of tickers to be chosen ! ! { ! ! //double targetReturnForEachPeriodOfPortfolioLife = ! // Math.Pow(1.60,(double)(1.0/(360.0/this.numDaysOfPortfolioLife))) - 1.0; ! //the target has to be such that annual system return is minimum 50% ! //(with no commissions and bid-ask spreads) ! IGenomeManager genManEfficientCTCPortfolio = ! new GenomeManagerForEfficientCTCPortfolio(setOfTickersToBeOptimized, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfTickersToBeChosen, ! this.numDaysForReturnCalculation, ! this.targetReturn, ! this.portfolioType, this.benchmark); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer, ! ConstantsProvider.SeedForRandomGenerator); ! if(setGenomeCounter) ! this.genomeCounter = new GenomeCounter(GO); ! ! GO.Run(false); ! this.addGenomeToBestGenomes(GO.BestGenome,((GenomeManagerForEfficientCTCPortfolio)genManEfficientCTCPortfolio).FirstQuoteDate, ! ((GenomeManagerForEfficientCTCPortfolio)genManEfficientCTCPortfolio).LastQuoteDate, ! setOfTickersToBeOptimized.Rows.Count); this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaning)GO.BestGenome.Meaning).Tickers) ); } ! //else it will be buyed again the previous optimized portfolio ! //that's it the actual chosenTickers member ! } ! ! /// <summary> ! /// Handles a "One hour after market close" event. ! /// </summary> ! /// <param name="sender"></param> ! /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! ConstantsProvider.SeedForRandomGenerator++; ! //old ! // if(this.account.Portfolio.Count == 0 ) ! // { ! // this.orders.Clear(); ! // this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! // //it sets tickers to be chosen at next close ! // } ! ! //this.oneHourAfterMarketCloseEventHandler_updatePrices(); ! this.numDaysElapsedSinceLastOptimization++; ! if(this.numDaysElapsedSinceLastOptimization == ! this.numDaysBetweenEachOptimization) ! //num days without optimization has elapsed or ! //just money has been added to the account ! { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! //sets tickers to be chosen next Market Open event ! this.numDaysElapsedSinceLastOptimization = 0; ! } ! ! } ! #endregion ! } } --- 37,259 ---- { ! /// <summary> ! /// Implements MarketOpenEventHandler and MarketCloseEventHandler ! /// These handlers contain the core strategy for the efficient close to close ! /// portfolio (with a given days of life)! ! /// </summary> ! [Serializable] ! public class EndOfDayTimerHandlerCTC : EndOfDayTimerHandler ! { ! protected int numDaysOfPortfolioLife; ! protected int numDaysForReturnCalculation; ! protected int numDaysWithNoPositions; ! protected int daysCounterWithPositions; ! protected int daysCounterWithNoPositions; ! protected double maxAcceptableCloseToCloseDrawdown; ! ! public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, ! int numDaysOfPortfolioLife, ! int numDaysForReturnCalculation, ! int numDaysWithNoPositions, ! double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! int numDaysBetweenEachOptimization): ! base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType) ! { ! this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.numDaysWithNoPositions = numDaysWithNoPositions; ! this.daysCounterWithPositions = 0; ! this.daysCounterWithNoPositions = 0; ! this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; ! this.stopLossConditionReached = false; ! this.currentAccountValue = 0.0; ! this.previousAccountValue = 0.0; ! this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; ! } ! ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) ! { ! ; ! } ! #region marketCloseEventHandler ! ! ! ! protected void updateStopLossCondition() ! { ! this.previousAccountValue = this.currentAccountValue; ! this.currentAccountValue = this.account.GetMarketValue(); ! if((this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) ! { ! this.stopLossConditionReached = true; ! } ! else ! { ! this.stopLossConditionReached = false; ! } ! } ! ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) ! { ! //bool positionsJustClosed = false; ! this.updateStopLossCondition(); ! if(this.account.Portfolio.Count > 0) ! //portfolio is not empty ! { ! this.daysCounterWithPositions++; ! if(this.daysCounterWithPositions == this.numDaysOfPortfolioLife || ! this.stopLossConditionReached) ! //num days of portfolio life or ! //max acceptable close to close drawdown reached ! { ! AccountManager.ClosePositions(this.account); ! this.daysCounterWithPositions = 0; ! //positionsJustClosed = true; ! } ! } ! else//portfolio is empty ! { this.daysCounterWithNoPositions++; if(this.daysCounterWithNoPositions == this.numDaysWithNoPositions || ! this.Account.Transactions.Count <= 1) { AccountManager.OpenPositions(this.chosenWeightedPositions,this.account); ! this.daysCounterWithNoPositions = 0; } } ! } ! //old ! // if(this.account.Portfolio.Count == 0 && ! // !positionsJustClosed) ! // //portfolio is empty but it has not been closed ! // //at the current close ! // { ! // this.openPositions(); ! // this.daysCounter = 0; ! // } ! #endregion marketCloseEventHandler ! ! #region oneHourAfterMarketCloseEventHandler ! ! protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) ! { ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, ! currentDate); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketFromTemporized = ! new SelectorByQuotationAtEachMarketDay(temporizedGroup.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod),currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! ! this.eligibleTickers = quotedAtEachMarketFromTemporized.GetTableOfSelectedTickers(); ! ! // SelectorByCloseToCloseCorrelationToBenchmark lessCorrelatedFromEligible = ! // new SelectorByCloseToCloseCorrelationToBenchmark(this.eligibleTickers, ! // this.benchmark,true, ! // currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! // currentDate, ! // this.numberOfEligibleTickers/2, ! // this.numDaysForReturnCalculation); ! // SelectorByAbsolutePerformance mostQuietFromLessCorrelated = ! // new SelectorByAbsolutePerformance(lessCorrelatedFromEligible.GetTableOfSelectedTickers(), ! // true,currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! // currentDate, ! // this.numberOfEligibleTickers/4, ! // 0.01f, 0.10f); ! // ! // return mostQuietFromLessCorrelated.GetTableOfSelectedTickers(); ! ! return this.eligibleTickers; ! } ! ! ! protected virtual void setTickers(DateTime currentDate, ! bool setGenomeCounter) ! { ! DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) ! //the optimization process is meaningful only if the initial set of tickers is ! //larger than the number of tickers to be chosen ! ! { ! ! //double targetReturnForEachPeriodOfPortfolioLife = ! // Math.Pow(1.60,(double)(1.0/(360.0/this.numDaysOfPortfolioLife))) - 1.0; ! //the target has to be such that annual system return is minimum 50% ! //(with no commissions and bid-ask spreads) ! IGenomeManager genManEfficientCTCPortfolio = ! new GenomeManagerForEfficientCTCPortfolio(setOfTickersToBeOptimized, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfTickersToBeChosen, ! this.numDaysForReturnCalculation, ! this.targetReturn, ! this.portfolioType, this.benchmark); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer, ! ConstantsProvider.SeedForRandomGenerator); ! if(setGenomeCounter) ! this.genomeCounter = new GenomeCounter(GO); ! ! GO.Run(false); ! this.addGenomeToBestGenomes(GO.BestGenome,((GenomeManagerForEfficientCTCPortfolio)genManEfficientCTCPortfolio).FirstQuoteDate, ! ((GenomeManagerForEfficientCTCPortfolio)genManEfficientCTCPortfolio).LastQuoteDate, ! setOfTickersToBeOptimized.Rows.Count); this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights, ! ... [truncated message content] |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:42
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17098/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO Modified Files: RunWeightedBalancedPVO.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: RunWeightedBalancedPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO/RunWeightedBalancedPVO.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunWeightedBalancedPVO.cs 19 Aug 2008 17:13:13 -0000 1.3 --- RunWeightedBalancedPVO.cs 29 Sep 2008 21:19:06 -0000 1.4 *************** *** 128,132 **** protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } --- 128,139 ---- protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); ! } ! ! private void newDateTimeEventHandler( ! object sender , DateTime dateTime ) ! { ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! this.checkDateForReport( sender , dateTime ); } *************** *** 134,148 **** { ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.endOfDayTimerHandler.MarketCloseEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); } --- 141,160 ---- { ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.endOfDayTimerHandler.NewDateTimeEventHandler ); ! this.endOfDayTimer.NewDateTime += ! new NewDateTimeEventHandler( this.newDateTimeEventHandler ); ! ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.endOfDayTimerHandler.MarketCloseEventHandler); ! // ! // this.endOfDayTimer.MarketClose += ! // new MarketCloseEventHandler( ! // this.checkDateForReport); ! // ! // this.endOfDayTimer.OneHourAfterMarketClose += ! // new OneHourAfterMarketCloseEventHandler( ! // this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); } *************** *** 178,182 **** //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); --- 190,194 ---- //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentDateTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17098/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers Modified Files: PVOChooserFromSavedBackTestLog.cs PVOGeneticChooser.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: PVOChooserFromSavedBackTestLog.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVOChooserFromSavedBackTestLog.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PVOChooserFromSavedBackTestLog.cs 26 Apr 2008 09:44:58 -0000 1.2 --- PVOChooserFromSavedBackTestLog.cs 29 Sep 2008 21:19:05 -0000 1.3 *************** *** 58,62 **** } ! protected override TestingPositions[] getTestingPositionsFromBackTestLog(EndOfDayDateTime lastInSampleDateOfOptimizedTestingPositions) { TestingPositions[] testingPositions = --- 58,63 ---- } ! protected override TestingPositions[] getTestingPositionsFromBackTestLog( ! DateTime lastInSampleDateOfOptimizedTestingPositions) { TestingPositions[] testingPositions = *************** *** 66,71 **** i++ ) { ! if( this.backTestLog[i].SimulatedCreationTime.DateTime == ! lastInSampleDateOfOptimizedTestingPositions.DateTime ) { Array.Copy( ((PVOLogItem)this.backTestLog[i]).BestPVOPositionsInSample , --- 67,72 ---- i++ ) { ! if( this.backTestLog[i].SimulatedCreationDateTime == ! lastInSampleDateOfOptimizedTestingPositions ) { Array.Copy( ((PVOLogItem)this.backTestLog[i]).BestPVOPositionsInSample , Index: PVOGeneticChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVOGeneticChooser.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVOGeneticChooser.cs 9 Mar 2008 22:49:23 -0000 1.1 --- PVOGeneticChooser.cs 29 Sep 2008 21:19:05 -0000 1.2 *************** *** 57,61 **** IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , ! IHistoricalQuoteProvider historicalQuoteProvider , double crossoverRate , double mutationRate , double elitismRate , int populationSizeForGeneticOptimizer , --- 57,61 ---- IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , ! HistoricalMarketValueProvider historicalMarketValueProvider , double crossoverRate , double mutationRate , double elitismRate , int populationSizeForGeneticOptimizer , *************** *** 69,73 **** base(numberOfPortfolioPositions, numberOfBestTestingPositionsToBeReturned, benchmark , decoderForTestingPositions , ! fitnessEvaluator , historicalQuoteProvider , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , --- 69,73 ---- base(numberOfPortfolioPositions, numberOfBestTestingPositionsToBeReturned, benchmark , decoderForTestingPositions , ! fitnessEvaluator , historicalMarketValueProvider , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16104/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: EndOfDayTimerHandlerPVO.cs GenomeManagerPVO.cs GenomeManagerPVO_OTC.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: GenomeManagerPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/GenomeManagerPVO.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GenomeManagerPVO.cs 14 Jan 2008 23:07:02 -0000 1.4 --- GenomeManagerPVO.cs 29 Sep 2008 21:17:25 -0000 1.5 *************** *** 3,7 **** GenomeManagerPVO.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- GenomeManagerPVO.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; *************** *** 46,170 **** /// </summary> [Serializable] ! public class GenomeManagerPVO : GenomeManagerForEfficientPortfolio ! { ! protected int minLevelForOversoldThreshold; ! protected int maxLevelForOversoldThreshold; ! protected int minLevelForOverboughtThreshold; ! protected int maxLevelForOverboughtThreshold; ! protected int divisorForThresholdComputation; ! protected bool symmetricalThresholds = false; ! protected bool overboughtMoreThanOversoldForFixedPortfolio = false; ! protected int numOfGenesDedicatedToThresholds; ! protected double currentOversoldThreshold = 0.0; ! protected double currentOverboughtThreshold = 0.0; ! protected int numDaysForOscillatingPeriod; ! protected ReturnsManager returnsManager; ! protected CorrelationProvider correlationProvider;//used for experimental ! //tests using 2 tickers and PearsonCorrelationCoefficient as fitness ! ! private void genomeManagerPVO_checkParametersForThresholdsComputation() ! { ! if(this.maxLevelForOverboughtThreshold < this.minLevelForOverboughtThreshold || ! this.maxLevelForOversoldThreshold < this.minLevelForOversoldThreshold || ! this.divisorForThresholdComputation < this.maxLevelForOverboughtThreshold || ! this.divisorForThresholdComputation < this.maxLevelForOversoldThreshold || ! (this.symmetricalThresholds && (this.minLevelForOversoldThreshold != this.minLevelForOverboughtThreshold || ! this.maxLevelForOversoldThreshold != this.maxLevelForOverboughtThreshold) ) || ! (this.overboughtMoreThanOversoldForFixedPortfolio && ! (this.minLevelForOverboughtThreshold > Convert.ToInt32(Convert.ToDouble(this.minLevelForOversoldThreshold)* Convert.ToDouble(this.divisorForThresholdComputation) / ! (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(this.minLevelForOversoldThreshold) ) ) || ! this.maxLevelForOverboughtThreshold < Convert.ToInt32(Convert.ToDouble(this.maxLevelForOversoldThreshold) * Convert.ToDouble(this.divisorForThresholdComputation) / ! (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(this.maxLevelForOversoldThreshold) ) ) ) ) ) ! throw new Exception("Bad parameters for thresholds computation!"); ! } ! public GenomeManagerPVO(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! int numDaysForOscillatingPeriod, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! PortfolioType inSamplePortfolioType, ! string benchmark) ! : ! base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! 0.0, ! inSamplePortfolioType, ! benchmark) ! ! ! { ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.divisorForThresholdComputation = divisorForThresholdComputation; this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; ! this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; ! this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; ! this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; ! this.symmetricalThresholds = symmetricalThresholds; ! this.overboughtMoreThanOversoldForFixedPortfolio = overboughtMoreThanOversoldForFixedPortfolio; ! if(this.symmetricalThresholds)//value for thresholds must be unique ! numOfGenesDedicatedToThresholds = 1; ! else ! numOfGenesDedicatedToThresholds = 2; ! this.genomeManagerPVO_checkParametersForThresholdsComputation(); ! this.setReturnsManager(firstQuoteDate , lastQuoteDate); ! } ! ! protected virtual void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! 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.numDaysForOscillatingPeriod), ! new HistoricalAdjustedQuoteProvider() ); ! } ! ! public override int GenomeSize ! { ! get{return this.genomeSize + this.numOfGenesDedicatedToThresholds;} ! } ! #region Get Min and Max Value ! private int getMinValueForGenes_getMinValueForTicker() ! { ! int returnValue; ! switch (this.portfolioType) ! { ! case PortfolioType.OnlyLong : ! returnValue = 0; ! break; ! default://For ShortAndLong or OnlyShort portfolios ! returnValue = - this.originalNumOfTickers; ! break; ! } ! return returnValue; ! } ! public override int GetMinValueForGenes(int genePosition) ! { ! int returnValue; ! switch (genePosition) ! { ! case 0 ://gene for oversold threshold returnValue = this.minLevelForOversoldThreshold; break; --- 46,172 ---- /// </summary> [Serializable] ! public class GenomeManagerPVO : GenomeManagerForEfficientPortfolio ! { ! protected int minLevelForOversoldThreshold; ! protected int maxLevelForOversoldThreshold; ! protected int minLevelForOverboughtThreshold; ! protected int maxLevelForOverboughtThreshold; ! protected int divisorForThresholdComputation; ! protected bool symmetricalThresholds = false; ! protected bool overboughtMoreThanOversoldForFixedPortfolio = false; ! protected int numOfGenesDedicatedToThresholds; ! protected double currentOversoldThreshold = 0.0; ! protected double currentOverboughtThreshold = 0.0; ! protected int numDaysForOscillatingPeriod; ! protected ReturnsManager returnsManager; ! protected CorrelationProvider correlationProvider;//used for experimental ! //tests using 2 tickers and PearsonCorrelationCoefficient as fitness ! ! private void genomeManagerPVO_checkParametersForThresholdsComputation() ! { ! if(this.maxLevelForOverboughtThreshold < this.minLevelForOverboughtThreshold || ! this.maxLevelForOversoldThreshold < this.minLevelForOversoldThreshold || ! this.divisorForThresholdComputation < this.maxLevelForOverboughtThreshold || ! this.divisorForThresholdComputation < this.maxLevelForOversoldThreshold || ! (this.symmetricalThresholds && (this.minLevelForOversoldThreshold != this.minLevelForOverboughtThreshold || ! this.maxLevelForOversoldThreshold != this.maxLevelForOverboughtThreshold) ) || ! (this.overboughtMoreThanOversoldForFixedPortfolio && ! (this.minLevelForOverboughtThreshold > Convert.ToInt32(Convert.ToDouble(this.minLevelForOversoldThreshold)* Convert.ToDouble(this.divisorForThresholdComputation) / ! (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(this.minLevelForOversoldThreshold) ) ) || ! this.maxLevelForOverboughtThreshold < Convert.ToInt32(Convert.ToDouble(this.maxLevelForOversoldThreshold) * Convert.ToDouble(this.divisorForThresholdComputation) / ! (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(this.maxLevelForOversoldThreshold) ) ) ) ) ) ! throw new Exception("Bad parameters for thresholds computation!"); ! } ! public GenomeManagerPVO(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! int numDaysForOscillatingPeriod, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! PortfolioType inSamplePortfolioType, ! string benchmark) ! : ! base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! 0.0, ! inSamplePortfolioType, ! benchmark) ! ! ! { ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; ! this.divisorForThresholdComputation = divisorForThresholdComputation; this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; ! this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; ! this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; ! this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; ! this.symmetricalThresholds = symmetricalThresholds; ! this.overboughtMoreThanOversoldForFixedPortfolio = overboughtMoreThanOversoldForFixedPortfolio; ! if(this.symmetricalThresholds)//value for thresholds must be unique ! numOfGenesDedicatedToThresholds = 1; ! else ! numOfGenesDedicatedToThresholds = 2; ! this.genomeManagerPVO_checkParametersForThresholdsComputation(); ! this.setReturnsManager(firstQuoteDate , lastQuoteDate); ! } ! ! protected virtual void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! 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.numDaysForOscillatingPeriod), ! new HistoricalAdjustedQuoteProvider() ); ! } ! ! public override int GenomeSize ! { ! get{return this.genomeSize + this.numOfGenesDedicatedToThresholds;} ! } ! #region Get Min and Max Value ! private int getMinValueForGenes_getMinValueForTicker() ! { ! int returnValue; ! switch (this.portfolioType) ! { ! case PortfolioType.OnlyLong : ! returnValue = 0; ! break; ! default://For ShortAndLong or OnlyShort portfolios ! returnValue = - this.originalNumOfTickers; ! break; ! } ! return returnValue; ! } ! public override int GetMinValueForGenes(int genePosition) ! { ! int returnValue; ! switch (genePosition) ! { ! case 0 ://gene for oversold threshold returnValue = this.minLevelForOversoldThreshold; break; *************** *** 173,206 **** returnValue = this.minLevelForOverboughtThreshold; else ! returnValue = this.getMinValueForGenes_getMinValueForTicker(); ! break; default://gene for ticker returnValue = this.getMinValueForGenes_getMinValueForTicker(); break; ! } ! return returnValue; ! } ! ! private int getMaxValueForGenes_getMaxValueForTicker() ! { ! int returnValue; ! switch (this.portfolioType) ! { ! case PortfolioType.OnlyShort : ! returnValue = - 1; ! break; ! default ://For ShortAndLong or OnlyLong portfolios ! returnValue = this.originalNumOfTickers - 1; ! break; ! } ! return returnValue; ! } ! public override int GetMaxValueForGenes(int genePosition) ! { ! int returnValue; ! switch (genePosition) ! { ! case 0 ://gene for oversold threshold returnValue = this.maxLevelForOversoldThreshold; break; --- 175,208 ---- returnValue = this.minLevelForOverboughtThreshold; else ! returnValue = this.getMinValueForGenes_getMinValueForTicker(); ! break; default://gene for ticker returnValue = this.getMinValueForGenes_getMinValueForTicker(); break; ! } ! return returnValue; ! } ! ! private int getMaxValueForGenes_getMaxValueForTicker() ! { ! int returnValue; ! switch (this.portfolioType) ! { ! case PortfolioType.OnlyShort : ! returnValue = - 1; ! break; ! default ://For ShortAndLong or OnlyLong portfolios ! returnValue = this.originalNumOfTickers - 1; ! break; ! } ! return returnValue; ! } ! public override int GetMaxValueForGenes(int genePosition) ! { ! int returnValue; ! switch (genePosition) ! { ! case 0 ://gene for oversold threshold returnValue = this.maxLevelForOversoldThreshold; break; *************** *** 214,228 **** returnValue = this.getMaxValueForGenes_getMaxValueForTicker(); break; ! } ! return returnValue; ! } ! ! #endregion ! ! #region getStrategyReturns ! ! private float[] getStrategyReturns_getReturnsActually( ! float[] plainReturns) { --- 216,230 ---- returnValue = this.getMaxValueForGenes_getMaxValueForTicker(); break; ! } ! return returnValue; ! } ! #endregion ! ! ! #region getStrategyReturns ! ! private float[] getStrategyReturns_getReturnsActually( ! float[] plainReturns) { *************** *** 232,326 **** //has been entered float coefficient = 0; ! for(int i = 0; i < returnValue.Length - 1; i++) ! { ! if( plainReturns[i] >= (float)this.currentOverboughtThreshold ) ! //portfolio has been overbought ! coefficient = -1; ! else if( plainReturns[i] <= - (float)this.currentOversoldThreshold ) ! //portfolio has been oversold ! coefficient = 1; ! //else the previous coeff is kept or, if no threshold has been ! //reached, then no positions will be opened (coefficient = 0) ! returnValue[i + 1] = coefficient * plainReturns[i + 1]; ! } ! return returnValue; //return plainReturns; } ! ! protected override float[] getStrategyReturns() { float[] plainReturns = this.weightedPositionsFromGenome.GetReturns( ! this.returnsManager); return this.getStrategyReturns_getReturnsActually(plainReturns); } ! ! #endregion ! ! private void getFitnessValue_setCurrentThresholds(Genome genome) ! { ! this.currentOversoldThreshold = Convert.ToDouble(genome.Genes()[0])/ ! Convert.ToDouble(this.divisorForThresholdComputation); ! ! if(this.symmetricalThresholds) ! this.currentOverboughtThreshold = this.currentOversoldThreshold; ! else ! this.currentOverboughtThreshold = Convert.ToDouble(genome.Genes()[1])/ ! Convert.ToDouble(this.divisorForThresholdComputation); ! } ! ! protected int getFitnessValue_getDaysOnTheMarket() ! { ! int returnValue = 0; ! foreach(float strategyReturn in this.strategyReturns) ! if(strategyReturn != 0) ! //the applied strategy gets positions on the market ! returnValue++; ! return returnValue; ! } ! private double getFitnessValue_calculate_calculateActually() ! { ! return this.AverageOfStrategyReturns/Math.Sqrt(this.VarianceOfStrategyReturns); //return Math.Sqrt(this.VarianceOfStrategyReturns); ! } ! ! ! protected override double getFitnessValue_calculate() ! { double returnValue = -1.0; ! if(this.getFitnessValue_getDaysOnTheMarket() > ! this.strategyReturns.Length / 2) ! //if the genome represents a portfolio that stays on the market ! //at least half of the theoretical days ! returnValue = ! this.getFitnessValue_calculate_calculateActually(); return returnValue; ! } ! ! protected string getFitnessValue_getFirstTickerFromGenome(Genome genome) ! { ! GenomeMeaningPVO genomeMeaning = (GenomeMeaningPVO)genome.Meaning; ! return genomeMeaning.Tickers[0]; ! } ! protected string getFitnessValue_getSecondTickerFromGenome(Genome genome) ! { ! GenomeMeaningPVO genomeMeaning = (GenomeMeaningPVO)genome.Meaning; ! return genomeMeaning.Tickers[1]; ! } ! //fitness is a sharpe-ratio based indicator for the equity line resulting //from applying the strategy ! public override double GetFitnessValue(Genome genome) ! { ! //OLD CLASSICAL IMPLEMENTATION (sharpeRatio applied to strategyReturns) ! // this.getFitnessValue_setCurrentThresholds(genome); ! // return base.GetFitnessValue(genome); ! //NEW implementation: fitness is just the pearson correlation ! //applied to two tickers. This kind of fitness is only valid ! //for experimental tests with 2-tickers portfolios double returnValue = -2.0; if(this.correlationProvider == null) --- 234,328 ---- //has been entered float coefficient = 0; ! for(int i = 0; i < returnValue.Length - 1; i++) ! { ! if( plainReturns[i] >= (float)this.currentOverboughtThreshold ) ! //portfolio has been overbought ! coefficient = -1; ! else if( plainReturns[i] <= - (float)this.currentOversoldThreshold ) ! //portfolio has been oversold ! coefficient = 1; ! //else the previous coeff is kept or, if no threshold has been ! //reached, then no positions will be opened (coefficient = 0) ! returnValue[i + 1] = coefficient * plainReturns[i + 1]; ! } ! return returnValue; //return plainReturns; } ! ! protected override float[] getStrategyReturns() { float[] plainReturns = this.weightedPositionsFromGenome.GetReturns( ! this.returnsManager); return this.getStrategyReturns_getReturnsActually(plainReturns); } ! ! #endregion ! ! private void getFitnessValue_setCurrentThresholds(Genome genome) ! { ! this.currentOversoldThreshold = Convert.ToDouble(genome.Genes()[0])/ ! Convert.ToDouble(this.divisorForThresholdComputation); ! ! if(this.symmetricalThresholds) ! this.currentOverboughtThreshold = this.currentOversoldThreshold; ! else ! this.currentOverboughtThreshold = Convert.ToDouble(genome.Genes()[1])/ ! Convert.ToDouble(this.divisorForThresholdComputation); ! } ! ! protected int getFitnessValue_getDaysOnTheMarket() ! { ! int returnValue = 0; ! foreach(float strategyReturn in this.strategyReturns) ! if(strategyReturn != 0) ! //the applied strategy gets positions on the market ! returnValue++; ! return returnValue; ! } ! private double getFitnessValue_calculate_calculateActually() ! { ! return this.AverageOfStrategyReturns/Math.Sqrt(this.VarianceOfStrategyReturns); //return Math.Sqrt(this.VarianceOfStrategyReturns); ! } ! ! ! protected override double getFitnessValue_calculate() ! { double returnValue = -1.0; ! if(this.getFitnessValue_getDaysOnTheMarket() > ! this.strategyReturns.Length / 2) ! //if the genome represents a portfolio that stays on the market ! //at least half of the theoretical days ! returnValue = ! this.getFitnessValue_calculate_calculateActually(); return returnValue; ! } ! ! protected string getFitnessValue_getFirstTickerFromGenome(Genome genome) ! { ! GenomeMeaningPVO genomeMeaning = (GenomeMeaningPVO)genome.Meaning; ! return genomeMeaning.Tickers[0]; ! } ! protected string getFitnessValue_getSecondTickerFromGenome(Genome genome) ! { ! GenomeMeaningPVO genomeMeaning = (GenomeMeaningPVO)genome.Meaning; ! return genomeMeaning.Tickers[1]; ! } ! //fitness is a sharpe-ratio based indicator for the equity line resulting //from applying the strategy ! public override double GetFitnessValue(Genome genome) ! { ! //OLD CLASSICAL IMPLEMENTATION (sharpeRatio applied to strategyReturns) ! // this.getFitnessValue_setCurrentThresholds(genome); ! // return base.GetFitnessValue(genome); ! //NEW implementation: fitness is just the pearson correlation ! //applied to two tickers. This kind of fitness is only valid ! //for experimental tests with 2-tickers portfolios double returnValue = -2.0; if(this.correlationProvider == null) *************** *** 331,336 **** string secondTicker = this.getFitnessValue_getSecondTickerFromGenome(genome); if( ( firstTicker.StartsWith("-") && !secondTicker.StartsWith("-") ) || ! ( secondTicker.StartsWith("-") && !firstTicker.StartsWith("-") ) ) ! //tickers have to be opposite in sign { double correlationIndex = correlationProvider.GetPearsonCorrelation( --- 333,338 ---- string secondTicker = this.getFitnessValue_getSecondTickerFromGenome(genome); if( ( firstTicker.StartsWith("-") && !secondTicker.StartsWith("-") ) || ! ( secondTicker.StartsWith("-") && !firstTicker.StartsWith("-") ) ) ! //tickers have to be opposite in sign { double correlationIndex = correlationProvider.GetPearsonCorrelation( *************** *** 338,463 **** SignedTicker.GetTicker(secondTicker) ); if(correlationIndex < 0.96) ! // if correlation index is not too high to be ! // probably originated by the same instrument returnValue = correlationIndex; } return returnValue; ! } ! ! public override object Decode(Genome genome) ! { ! string[] arrayOfTickers = ! new string[genome.Genes().Length - this.numOfGenesDedicatedToThresholds]; ! int geneForTicker; ! GenomeMeaningPVO meaning; ! for(int genePosition = this.numOfGenesDedicatedToThresholds; ! genePosition < genome.Genes().Length; ! genePosition++) ! { ! geneForTicker = (int)genome.Genes().GetValue(genePosition); ! arrayOfTickers[genePosition - this.numOfGenesDedicatedToThresholds] = ! this.decode_getTickerCodeForLongOrShortTrade(geneForTicker); ! } ! ! double[] arrayOfWeights = ExtendedMath.ArrayOfAbs( WeightedPositions.GetBalancedWeights(new SignedTickers(arrayOfTickers), ! this.returnsManager) ); ! ! if(this.symmetricalThresholds) ! meaning = new GenomeMeaningPVO(arrayOfTickers, ! arrayOfWeights, ! Convert.ToDouble(genome.Genes()[0])/Convert.ToDouble(this.divisorForThresholdComputation), ! Convert.ToDouble(genome.Genes()[0])/Convert.ToDouble(this.divisorForThresholdComputation), ! this.numDaysForOscillatingPeriod); ! else ! meaning = new GenomeMeaningPVO(arrayOfTickers, ! arrayOfWeights, ! Convert.ToDouble(genome.Genes()[0])/Convert.ToDouble(this.divisorForThresholdComputation), ! Convert.ToDouble(genome.Genes()[1])/Convert.ToDouble(this.divisorForThresholdComputation), ! this.numDaysForOscillatingPeriod); ! return meaning; ! } ! public override Genome[] GetChilds(Genome parent1, Genome parent2) ! { ! //in this simple implementation ! //child have the tickers of one parent ! //and the thresholds of the other ! Genome[] childs = new Genome[2]; ! childs[0] = parent1.Clone(); ! childs[1] = parent2.Clone(); ! //exchange of genes coding thresholds ! ! if(this.symmetricalThresholds)//unique value for thresholds ! { ! childs[0].SetGeneValue(parent2.GetGeneValue(0),0); ! childs[1].SetGeneValue(parent1.GetGeneValue(0),0); ! } ! else//two different values for thresholds ! { ! childs[0].SetGeneValue(parent2.GetGeneValue(0),0); ! childs[1].SetGeneValue(parent1.GetGeneValue(0),0); ! childs[0].SetGeneValue(parent2.GetGeneValue(1),1); ! childs[1].SetGeneValue(parent1.GetGeneValue(1),1); ! } ! return childs; ! } ! public override int GetNewGeneValue(Genome genome, int genePosition) ! { ! // in this implementation only new gene values pointing to tickers ! // must be different from the others already stored ! int minValueForGene = genome.GetMinValueForGenes(genePosition); ! int maxValueForGene = genome.GetMaxValueForGenes(genePosition); ! int returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene + 1); ! ! if(this.numOfGenesDedicatedToThresholds == 2 && ! this.overboughtMoreThanOversoldForFixedPortfolio && genePosition == 1) ! //genePosition points to overbought threshold, ! //dipendent from the oversold one such that the portfolio tends to be fix ! returnValue = Convert.ToInt32(Convert.ToDouble(genome.GetGeneValue(0)) * Convert.ToDouble(this.divisorForThresholdComputation) / ! (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(genome.GetGeneValue(0)))); ! ! while(genePosition > this.numOfGenesDedicatedToThresholds - 1 ! && GenomeManipulator.IsTickerContainedInGenome(returnValue, ! genome, ! this.numOfGenesDedicatedToThresholds, ! genome.Size - 1)) ! //while in the given position has to be stored ! //a new gene pointing to a ticker and ! //the proposed returnValue points to a ticker ! //already stored in the given genome ! returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene + 1); ! ! return returnValue; ! } ! ! public override void Mutate(Genome genome) ! { ! // in this implementation only one gene is mutated ! int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! int minValueForGene = genome.GetMinValueForGenes(genePositionToBeMutated); ! int maxValueForGene = genome.GetMaxValueForGenes(genePositionToBeMutated); ! int newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene +1); ! while(genePositionToBeMutated > this.numOfGenesDedicatedToThresholds - 1 && ! GenomeManipulator.IsTickerContainedInGenome(newValueForGene, ! genome, ! this.numOfGenesDedicatedToThresholds, ! genome.Size - 1)) ! //while in the proposed genePositionToBeMutated has to be stored ! //a new gene pointing to a ticker and ! //the proposed newValueForGene points to a ticker ! //already stored in the given genome ! newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene +1); ! //TODO add if when it is mutated a threshold ! //(just a single threshold or the pair of thresholds) ! if(genePositionToBeMutated > this.numOfGenesDedicatedToThresholds - 1) ! GenomeManagement.MutateOneGene(genome, ! genePositionToBeMutated, newValueForGene); ! } ! } } --- 340,465 ---- SignedTicker.GetTicker(secondTicker) ); if(correlationIndex < 0.96) ! // if correlation index is not too high to be ! // probably originated by the same instrument returnValue = correlationIndex; } return returnValue; ! } ! ! public override object Decode(Genome genome) ! { ! string[] arrayOfTickers = ! new string[genome.Genes().Length - this.numOfGenesDedicatedToThresholds]; ! int geneForTicker; ! GenomeMeaningPVO meaning; ! for(int genePosition = this.numOfGenesDedicatedToThresholds; ! genePosition < genome.Genes().Length; ! genePosition++) ! { ! geneForTicker = (int)genome.Genes().GetValue(genePosition); ! arrayOfTickers[genePosition - this.numOfGenesDedicatedToThresholds] = ! this.decode_getTickerCodeForLongOrShortTrade(geneForTicker); ! } ! ! double[] arrayOfWeights = ExtendedMath.ArrayOfAbs( WeightedPositions.GetBalancedWeights(new SignedTickers(arrayOfTickers), ! this.returnsManager) ); ! ! if(this.symmetricalThresholds) ! meaning = new GenomeMeaningPVO(arrayOfTickers, ! arrayOfWeights, ! Convert.ToDouble(genome.Genes()[0])/Convert.ToDouble(this.divisorForThresholdComputation), ! Convert.ToDouble(genome.Genes()[0])/Convert.ToDouble(this.divisorForThresholdComputation), ! this.numDaysForOscillatingPeriod); ! else ! meaning = new GenomeMeaningPVO(arrayOfTickers, ! arrayOfWeights, ! Convert.ToDouble(genome.Genes()[0])/Convert.ToDouble(this.divisorForThresholdComputation), ! Convert.ToDouble(genome.Genes()[1])/Convert.ToDouble(this.divisorForThresholdComputation), ! this.numDaysForOscillatingPeriod); ! return meaning; ! } ! public override Genome[] GetChilds(Genome parent1, Genome parent2) ! { ! //in this simple implementation ! //child have the tickers of one parent ! //and the thresholds of the other ! Genome[] childs = new Genome[2]; ! childs[0] = parent1.Clone(); ! childs[1] = parent2.Clone(); ! //exchange of genes coding thresholds ! ! if(this.symmetricalThresholds)//unique value for thresholds ! { ! childs[0].SetGeneValue(parent2.GetGeneValue(0),0); ! childs[1].SetGeneValue(parent1.GetGeneValue(0),0); ! } ! else//two different values for thresholds ! { ! childs[0].SetGeneValue(parent2.GetGeneValue(0),0); ! childs[1].SetGeneValue(parent1.GetGeneValue(0),0); ! childs[0].SetGeneValue(parent2.GetGeneValue(1),1); ! childs[1].SetGeneValue(parent1.GetGeneValue(1),1); ! } ! return childs; ! } ! public override int GetNewGeneValue(Genome genome, int genePosition) ! { ! // in this implementation only new gene values pointing to tickers ! // must be different from the others already stored ! int minValueForGene = genome.GetMinValueForGenes(genePosition); ! int maxValueForGene = genome.GetMaxValueForGenes(genePosition); ! int returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene + 1); ! ! if(this.numOfGenesDedicatedToThresholds == 2 && ! this.overboughtMoreThanOversoldForFixedPortfolio && genePosition == 1) ! //genePosition points to overbought threshold, ! //dipendent from the oversold one such that the portfolio tends to be fix ! returnValue = Convert.ToInt32(Convert.ToDouble(genome.GetGeneValue(0)) * Convert.ToDouble(this.divisorForThresholdComputation) / ! (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(genome.GetGeneValue(0)))); ! ! while(genePosition > this.numOfGenesDedicatedToThresholds - 1 ! && GenomeManipulator.IsTickerContainedInGenome(returnValue, ! genome, ! this.numOfGenesDedicatedToThresholds, ! genome.Size - 1)) ! //while in the given position has to be stored ! //a new gene pointing to a ticker and ! //the proposed returnValue points to a ticker ! //already stored in the given genome ! returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene + 1); ! ! return returnValue; ! } ! ! public override void Mutate(Genome genome) ! { ! // in this implementation only one gene is mutated ! int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! int minValueForGene = genome.GetMinValueForGenes(genePositionToBeMutated); ! int maxValueForGene = genome.GetMaxValueForGenes(genePositionToBeMutated); ! int newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene +1); ! while(genePositionToBeMutated > this.numOfGenesDedicatedToThresholds - 1 && ! GenomeManipulator.IsTickerContainedInGenome(newValueForGene, ! genome, ! this.numOfGenesDedicatedToThresholds, ! genome.Size - 1)) ! //while in the proposed genePositionToBeMutated has to be stored ! //a new gene pointing to a ticker and ! //the proposed newValueForGene points to a ticker ! //already stored in the given genome ! newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, ! maxValueForGene +1); ! //TODO add if when it is mutated a threshold ! //(just a single threshold or the pair of thresholds) ! if(genePositionToBeMutated > this.numOfGenesDedicatedToThresholds - 1) ! GenomeManagement.MutateOneGene(genome, ! genePositionToBeMutated, newValueForGene); ! } ! } } Index: EndOfDayTimerHandlerPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/EndOfDayTimerHandlerPVO.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** EndOfDayTimerHandlerPVO.cs 19 Aug 2008 17:11:28 -0000 1.10 --- EndOfDayTimerHandlerPVO.cs 29 Sep 2008 21:17:25 -0000 1.11 *************** *** 51,55 **** /// </summary> [Serializable] ! public class EndOfDayTimerHandlerPVO : EndOfDayTimerHandler { protected int minLevelForOversoldThreshold; --- 51,56 ---- /// </summary> [Serializable] ! public class EndOfDayTimerHandlerPVO : ! QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios.EndOfDayTimerHandler { protected int minLevelForOversoldThreshold; *************** *** 116,126 **** } ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } ! #region MarketCloseEventHandler protected virtual double getCurrentChosenWeightedPositionsReturn(IndexBasedEndOfDayTimer timer) --- 117,127 ---- } ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { ; } ! #region marketCloseEventHandler protected virtual double getCurrentChosenWeightedPositionsReturn(IndexBasedEndOfDayTimer timer) *************** *** 133,143 **** DateTime today = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; ! ReturnsManager returnsManager = new ReturnsManager(new CloseToCloseIntervals( ! new EndOfDayDateTime(firstDayOfOscillatingPeriod, ! EndOfDaySpecificTime.MarketClose) , ! new EndOfDayDateTime(today, ! EndOfDaySpecificTime.MarketClose) , ! this.benchmark , this.numDaysForOscillatingPeriod ) , ! this.historicalQuoteProvider ); returnValue = this.chosenWeightedPositions.GetReturn(0,returnsManager); } --- 134,149 ---- DateTime today = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; ! ReturnsManager returnsManager = new ReturnsManager( ! new CloseToCloseIntervals( ! HistoricalEndOfDayTimer.GetMarketClose( ! firstDayOfOscillatingPeriod ) , ! HistoricalEndOfDayTimer.GetMarketClose( today ) , ! // new EndOfDayDateTime(firstDayOfOscillatingPeriod, ! // EndOfDaySpecificTime.MarketClose) , ! // new EndOfDayDateTime(today, ! // EndOfDaySpecificTime.MarketClose) , ! this.benchmark , ! this.numDaysForOscillatingPeriod ) , ! this.historicalQuoteProvider ); returnValue = this.chosenWeightedPositions.GetReturn(0,returnsManager); } *************** *** 254,259 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.marketCloseEventHandler_updateStopLossAndTakeProfitConditions(); --- 260,265 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.marketCloseEventHandler_updateStopLossAndTakeProfitConditions(); *************** *** 272,276 **** #endregion ! #region OneHourAfterMarketCloseEventHandler protected virtual DataTable getSetOfTickersToBeOptimized(DateTime currentDate) --- 278,282 ---- #endregion ! #region oneHourAfterMarketCloseEventHandler protected virtual DataTable getSetOfTickersToBeOptimized(DateTime currentDate) *************** *** 404,411 **** /// <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++; --- 410,417 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! this.lastCloseDate = dateTime; this.seedForRandomGenerator++; this.numDaysElapsedSinceLastOptimization++; *************** *** 414,418 **** //num days without optimization has elapsed { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; --- 420,424 ---- //num days without optimization has elapsed { ! this.setTickers(dateTime, false); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; *************** *** 421,424 **** --- 427,441 ---- } #endregion + + 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 ); + } } } Index: GenomeManagerPVO_OTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/GenomeManagerPVO_OTC.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenomeManagerPVO_OTC.cs 14 Jan 2008 22:58:11 -0000 1.1 --- GenomeManagerPVO_OTC.cs 29 Sep 2008 21:17:25 -0000 1.2 *************** *** 3,7 **** GenomeManagerPVO_OTC.cs ! Copyright (C) 2008 Marco Milletti --- 3,7 ---- GenomeManagerPVO_OTC.cs ! Copyright (C) 2008 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; *************** *** 47,109 **** /// </summary> [Serializable] ! public class GenomeManagerPVO_OTC : GenomeManagerPVO ! { ! ! public GenomeManagerPVO_OTC(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! PortfolioType inSamplePortfolioType, ! string benchmark) ! : ! base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! 1, ! minLevelForOversoldThreshold, ! maxLevelForOversoldThreshold, ! minLevelForOverboughtThreshold, ! maxLevelForOverboughtThreshold, ! divisorForThresholdComputation, ! symmetricalThresholds, ! overboughtMoreThanOversoldForFixedPortfolio, ! inSamplePortfolioType, ! benchmark) ! ! ! { ! ! } ! ! protected override void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, ! EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, ! EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( new DailyOpenToCloseIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark), ! new HistoricalRawQuoteProvider() ); ! } ! ! //fitness is a sharpe-ratio based indicator for the equity line resulting //from applying the strategy ! public override double GetFitnessValue(Genome genome) ! { //NEW implementation: fitness is just the pearson correlation //applied to two tickers. This kind of fitness is only valid --- 47,111 ---- /// </summary> [Serializable] ! public class GenomeManagerPVO_OTC : GenomeManagerPVO ! { ! ! public GenomeManagerPVO_OTC(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! int minLevelForOversoldThreshold, ! int maxLevelForOversoldThreshold, ! int minLevelForOverboughtThreshold, ! int maxLevelForOverboughtThreshold, ! int divisorForThresholdComputation, ! bool symmetricalThresholds, ! bool overboughtMoreThanOversoldForFixedPortfolio, ! PortfolioType inSamplePortfolioType, ! string benchmark) ! : ! base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! 1, ! minLevelForOversoldThreshold, ! maxLevelForOversoldThreshold, ! minLevelForOverboughtThreshold, ! maxLevelForOverboughtThreshold, ! divisorForThresholdComputation, ! symmetricalThresholds, ! overboughtMoreThanOversoldForFixedPortfolio, ! inSamplePortfolioType, ! benchmark) ! ! ! { ! ! } ! ! protected override void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! DateTime firstDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( firstQuoteDate ); ! // new EndOfDayDateTime(firstQuoteDate, ! // EndOfDaySpecificTime.MarketOpen); ! DateTime lastDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( lastQuoteDate ); ! // new EndOfDayDateTime(lastQuoteDate, ! // EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( new DailyOpenToCloseIntervals( ! firstDateTime, ! lastDateTime, ! this.benchmark), ! new HistoricalRawQuoteProvider() ); ! } ! ! //fitness is a sharpe-ratio based indicator for the equity line resulting //from applying the strategy ! public override double GetFitnessValue(Genome genome) ! { //NEW implementation: fitness is just the pearson correlation //applied to two tickers. This kind of fitness is only valid *************** *** 117,122 **** string secondTicker = this.getFitnessValue_getSecondTickerFromGenome(genome); if( ( firstTicker.StartsWith("-") && !secondTicker.StartsWith("-") ) || ! ( secondTicker.StartsWith("-") && !firstTicker.StartsWith("-") ) ) ! //tickers have to be opposite in sign { double correlationIndex = correlationProvider.GetPearsonCorrelation( --- 119,124 ---- string secondTicker = this.getFitnessValue_getSecondTickerFromGenome(genome); if( ( firstTicker.StartsWith("-") && !secondTicker.StartsWith("-") ) || ! ( secondTicker.StartsWith("-") && !firstTicker.StartsWith("-") ) ) ! //tickers have to be opposite in sign { double correlationIndex = correlationProvider.GetPearsonCorrelation( *************** *** 124,133 **** SignedTicker.GetTicker(secondTicker) ); if(correlationIndex < 0.96) ! // if correlation index is not too high to be ! // probably originated by the same instrument returnValue = correlationIndex; } return returnValue; ! } ! } } --- 126,135 ---- SignedTicker.GetTicker(secondTicker) ); if(correlationIndex < 0.96) ! // if correlation index is not too high to be ! // probably originated by the same instrument returnValue = correlationIndex; } return returnValue; ! } ! } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:37
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17098/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO Modified Files: RunWeightedPVO.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: RunWeightedPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/RunWeightedPVO.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunWeightedPVO.cs 19 Aug 2008 17:13:13 -0000 1.3 --- RunWeightedPVO.cs 29 Sep 2008 21:19:05 -0000 1.4 *************** *** 128,132 **** protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } --- 128,132 ---- protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); } *************** *** 134,148 **** { ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.endOfDayTimerHandler.MarketCloseEventHandler); ! ! this.endOfDayTimer.MarketClose += ! new MarketCloseEventHandler( ! this.checkDateForReport); ! ! this.endOfDayTimer.OneHourAfterMarketClose += ! new OneHourAfterMarketCloseEventHandler( ! this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); } --- 134,153 ---- { ! 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); } *************** *** 178,182 **** //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); --- 183,187 ---- //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:19:35
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16773 Modified Files: GenomeManagerForEfficientCTCPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientOTCCTOPortfolio.cs GenomeManagerForEfficientOTCPortfolio.cs GenomeManagerForWeightedEfficientPortfolio.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: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GenomeManagerForEfficientCTCPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.14 --- GenomeManagerForEfficientCTCPortfolio.cs 29 Sep 2008 21:18:30 -0000 1.15 *************** *** 3,7 **** GenomeManagerForEfficientCTCPortfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- GenomeManagerForEfficientCTCPortfolio.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; *************** *** 34,90 **** { /// <summary> ! /// Class to find efficient /// portfolios based on tickers' CloseToClose rates (adjusted values), /// using the GeneticOptimizer /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTCPortfolio : GenomeManagerForEfficientPortfolio ! { ! private int numDaysForReturnCalculation; ! private ReturnsManager returnsManager; ! ! public GenomeManagerForEfficientCTCPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! int numDaysForReturnCalculation, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) ! : ! base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, ! benchmark) ! ! ! { ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); ! } ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( new CloseToCloseIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark, ! this.numDaysForReturnCalculation), ! new HistoricalAdjustedQuoteProvider() ); ! } ! ! protected override float[] getStrategyReturns() { ! return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); } ! } } --- 34,92 ---- { /// <summary> ! /// Class to find efficient /// portfolios based on tickers' CloseToClose rates (adjusted values), /// using the GeneticOptimizer /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTCPortfolio : GenomeManagerForEfficientPortfolio ! { ! private int numDaysForReturnCalculation; ! private ReturnsManager returnsManager; ! ! public GenomeManagerForEfficientCTCPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! int numDaysForReturnCalculation, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) ! : ! base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, ! benchmark) ! ! { ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); } ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! DateTime firstDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( firstQuoteDate ); ! // new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! DateTime lastDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( lastQuoteDate ); ! // new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( new CloseToCloseIntervals( ! firstDateTime, ! lastDateTime, ! this.benchmark, ! this.numDaysForReturnCalculation), ! new HistoricalAdjustedQuoteProvider() ); ! } ! ! protected override float[] getStrategyReturns() ! { ! return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); ! } ! } } Index: GenomeManagerForEfficientOTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientOTCPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GenomeManagerForEfficientOTCPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.3 --- GenomeManagerForEfficientOTCPortfolio.cs 29 Sep 2008 21:18:30 -0000 1.4 *************** *** 3,7 **** GenomeManagerForEfficientOTCPortfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- GenomeManagerForEfficientOTCPortfolio.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; *************** *** 33,84 **** { /// <summary> ! /// This class implements IGenomeManager, in order to find efficient /// portfolios based on tickers' OpenToClose rates, using the /// GeneticOptimizer /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCPortfolio : GenomeManagerForEfficientPortfolio ! { ! private ReturnsManager returnsManager; ! public GenomeManagerForEfficientOTCPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) ! :base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, ! benchmark) ! ! { ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); ! } ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( ! new DailyOpenToCloseIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark ), ! new HistoricalRawQuoteProvider() ); ! } ! protected override float[] getStrategyReturns() { ! return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); } ! } } --- 33,86 ---- { /// <summary> ! /// This class implements IGenomeManager, in order to find efficient /// portfolios based on tickers' OpenToClose rates, using the /// GeneticOptimizer /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCPortfolio : GenomeManagerForEfficientPortfolio ! { ! private ReturnsManager returnsManager; ! public GenomeManagerForEfficientOTCPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) ! :base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, ! benchmark) ! ! { ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); ! } ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! DateTime firstDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( firstQuoteDate ); ! // new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! DateTime lastDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( lastQuoteDate ); ! // new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( ! new DailyOpenToCloseIntervals( ! firstDateTime, ! lastDateTime, ! this.benchmark ), ! new HistoricalRawQuoteProvider() ); ! } ! protected override float[] getStrategyReturns() { ! return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); } ! } } Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** GenomeManagerForEfficientCTOPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.20 --- GenomeManagerForEfficientCTOPortfolio.cs 29 Sep 2008 21:18:30 -0000 1.21 *************** *** 3,7 **** GenomeManagerForEfficientCTOPortfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- GenomeManagerForEfficientCTOPortfolio.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; *************** *** 34,85 **** { /// <summary> ! /// This class implements IGenomeManager, in order to find efficient /// portfolios based on tickers' CloseToOpen rates, using the /// GeneticOptimizer /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForEfficientPortfolio ! { ! private ReturnsManager returnsManager; ! ! public GenomeManagerForEfficientCTOPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) ! :base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, ! benchmark) ! ! { ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); ! } ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( new CloseToOpenIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark), ! new HistoricalAdjustedQuoteProvider() ); ! } ! ! protected override float[] getStrategyReturns() { ! return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); } ! ! } } --- 34,87 ---- { /// <summary> ! /// This class implements IGenomeManager, in order to find efficient /// portfolios based on tickers' CloseToOpen rates, using the /// GeneticOptimizer /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForEfficientPortfolio ! { ! private ReturnsManager returnsManager; ! ! public GenomeManagerForEfficientCTOPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) ! :base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, ! benchmark) ! { ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); } ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! DateTime firstDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( firstQuoteDate ); ! // new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! DateTime lastDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( lastQuoteDate ); ! // new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( new CloseToOpenIntervals( ! firstDateTime, ! lastDateTime, ! this.benchmark), ! new HistoricalAdjustedQuoteProvider() ); ! } ! ! protected override float[] getStrategyReturns() ! { ! return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); ! } ! ! } } Index: GenomeManagerForEfficientOTCCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientOTCCTOPortfolio.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GenomeManagerForEfficientOTCCTOPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.6 --- GenomeManagerForEfficientOTCCTOPortfolio.cs 29 Sep 2008 21:18:30 -0000 1.7 *************** *** 3,7 **** GenomeManagerForEfficientOTCCTOPortfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- GenomeManagerForEfficientOTCCTOPortfolio.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; *************** *** 34,102 **** { /// <summary> ! /// This class implements IGenomeManager, in order to find efficient /// portfolios based on the OTC and CTO strategy, using the /// GeneticOptimizer /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCCTOPortfolio : GenomeManagerForEfficientPortfolio ! { ! private ReturnsManager returnsManager; ! ! public GenomeManagerForEfficientOTCCTOPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) ! :base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, ! benchmark) ! ! { ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); ! } ! //if the genome manager derives from genome manager without weights, //delete override key word ! protected ReturnIntervals getReturnIntervals(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime) { ! return new OpenToCloseCloseToOpenIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark); } ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( this.getReturnIntervals(firstEndOfDayDateTime, ! lastEndOfDayDateTime), ! new HistoricalAdjustedQuoteProvider() ); ! } ! ! protected override float[] getStrategyReturns() { ! float[] returnValue; ! returnValue = this.weightedPositionsFromGenome.GetReturns( ! this.returnsManager ) ; ! for(int i = 0; i<returnValue.Length; i++) ! if(i%2 != 0) ! //returnValue[i] is a CloseToOpen return: ! //the strategy implies to reverse positions at night ! returnValue[i] = - returnValue[i]; ! ! return returnValue; } ! } } --- 34,105 ---- { /// <summary> ! /// This class implements IGenomeManager, in order to find efficient /// portfolios based on the OTC and CTO strategy, using the /// GeneticOptimizer /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCCTOPortfolio : GenomeManagerForEfficientPortfolio ! { ! private ReturnsManager returnsManager; ! ! public GenomeManagerForEfficientOTCCTOPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) ! :base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, ! benchmark) ! ! { ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); ! } ! //if the genome manager derives from genome manager without weights, //delete override key word ! protected ReturnIntervals getReturnIntervals( ! DateTime firstDateTime, ! DateTime lastDateTime) { ! return new OpenToCloseCloseToOpenIntervals( ! firstDateTime, ! lastDateTime, ! this.benchmark); } ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) { ! DateTime firstDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( firstQuoteDate ); ! // new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! DateTime lastDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( lastQuoteDate ); ! // new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( this.getReturnIntervals(firstDateTime, ! lastDateTime), ! new HistoricalAdjustedQuoteProvider() ); } ! ! protected override float[] getStrategyReturns() ! { ! float[] returnValue; ! returnValue = this.weightedPositionsFromGenome.GetReturns( ! this.returnsManager ) ; ! for(int i = 0; i<returnValue.Length; i++) ! if(i%2 != 0) ! //returnValue[i] is a CloseToOpen return: ! //the strategy implies to reverse positions at night ! returnValue[i] = - returnValue[i]; ! ! return returnValue; ! } ! } } Index: GenomeManagerForWeightedEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForWeightedEfficientPortfolio.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GenomeManagerForWeightedEfficientPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.8 --- GenomeManagerForWeightedEfficientPortfolio.cs 29 Sep 2008 21:18:30 -0000 1.9 *************** *** 3,7 **** GenomeManagerForWeightedEfficientPortfolio.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- GenomeManagerForWeightedEfficientPortfolio.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,95 **** namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { ! /// <summary> ! /// This is the base class implementing IGenomeManager, in order to find ! /// efficient portfolios in which tickers are weighted differently ! /// </summary> ! [Serializable] ! public abstract class GenomeManagerForWeightedEfficientPortfolio : GenomeManagerForEfficientPortfolio ! { ! private ReturnsManager returnsManager; ! ! public GenomeManagerForWeightedEfficientPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark):base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, benchmark) ! ! { ! this.genomeSize = 2*this.genomeSize; ! //at even position the gene is used for finding ! //the coefficient for the ticker represented at the next odd position ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); ! } ! ! protected abstract ReturnIntervals getReturnIntervals(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime); ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( this.getReturnIntervals(firstEndOfDayDateTime, ! lastEndOfDayDateTime) , ! new HistoricalAdjustedQuoteProvider() ); ! } ! ! //this is a very generic implementation that will ! //be overriden by inherited classes specifying ! //the strategy and the type of returns ! protected override float[] getStrategyReturns() { return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); } ! ! #region override Decode protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) --- 38,98 ---- namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { ! /// <summary> ! /// This is the base class implementing IGenomeManager, in order to find ! /// efficient portfolios in which tickers are weighted differently ! /// </summary> ! [Serializable] ! public abstract class GenomeManagerForWeightedEfficientPortfolio : GenomeManagerForEfficientPortfolio ! { ! private ReturnsManager returnsManager; ! ! public GenomeManagerForWeightedEfficientPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark):base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, benchmark) ! ! { ! this.genomeSize = 2*this.genomeSize; ! //at even position the gene is used for finding ! //the coefficient for the ticker represented at the next odd position ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); ! } ! ! protected abstract ReturnIntervals getReturnIntervals( ! DateTime firstDateTime, ! DateTime lastDateTime); ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! DateTime firstDateTime = ! HistoricalEndOfDayTimer.GetMarketOpen( firstQuoteDate ); ! // new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! DateTime lastDateTime = ! HistoricalEndOfDayTimer.GetMarketClose( lastQuoteDate ); ! // new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( this.getReturnIntervals(firstDateTime, ! lastDateTime) , ! new HistoricalAdjustedQuoteProvider() ); ! } ! ! //this is a very generic implementation that will ! //be overriden by inherited classes specifying ! //the strategy and the type of returns ! protected override float[] getStrategyReturns() { return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); } ! ! #region override Decode protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) *************** *** 109,253 **** } ! public override object Decode(Genome genome) ! { ! string[] arrayOfTickers = new string[genome.Genes().Length/2]; ! double[] arrayOfTickersWeights = new double[genome.Genes().Length/2]; ! int indexOfTicker; ! int i = 0;//for the arrayOfTickers ! for(int index = 0; index < genome.Genes().Length; index++) ! { ! if(index%2==1) ! //indexForTicker is contained in genes at odd position ! { ! indexOfTicker = (int)genome.Genes().GetValue(index); ! arrayOfTickers[i] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); ! arrayOfTickersWeights[i] = this.getTickerWeight(genome.Genes(), index); ! i++; ! } ! } ! GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, ! arrayOfTickersWeights); ! return meaning; ! } ! #endregion ! public override int GetNewGeneValue(Genome genome, int genePosition) ! { ! // in this implementation only new gene values pointing to tickers ! // must be different from the others already stored (in odd positions of genome) ! int returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); ! while(genePosition%2 == 1 ! && GenomeManipulator.IsTickerContainedInGenome(returnValue,genome)) ! //while in the given position has to be stored ! //a new gene pointing to a ticker and ! //the proposed returnValue points to a ticker ! //already stored in the given genome ! { ! // a new returnValue has to be generated ! returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); ! } ! return returnValue; ! } ! ! #region override Mutate ! ! //OLD VERSION ! // public override void Mutate(Genome genome, double mutationRate) ! // { ! // // in this implementation only one gene is mutated ! // int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! // int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! // genome.GetMaxValueForGenes(genePositionToBeMutated) +1); ! // ! // while(genePositionToBeMutated%2 == 1 && ! // GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome)) ! // //while in the proposed genePositionToBeMutated has to be stored ! // //a new gene pointing to a ticker and ! // //the proposed newValueForGene points to a ticker ! // //already stored in the given genome ! // { ! // newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! // genome.GetMaxValueForGenes(genePositionToBeMutated) +1); ! // } ! // GenomeManagement.MutateOneGene(genome, mutationRate, ! // genePositionToBeMutated, newValueForGene); ! // } ! private int mutate_MutateOnlyOneWeight_getNewWeight(Genome genome, int genePositionToBeMutated) ! { ! int returnValue; ! double partOfGeneToSubtractOrAdd = 0.03; ! int geneValue = genome.GetGeneValue(genePositionToBeMutated); ! int subtractOrAdd = GenomeManagement.RandomGenerator.Next(2); ! if(subtractOrAdd == 1)//subtract a part of the gene value from the gene value itself ! { ! if( geneValue < 0 ) ! returnValue = Math.Max( geneValue - Convert.ToInt32(partOfGeneToSubtractOrAdd*Math.Abs(geneValue)), ! genome.GetMinValueForGenes(genePositionToBeMutated) ); ! else // geneValue >= 0 ! returnValue = geneValue - Convert.ToInt32(partOfGeneToSubtractOrAdd*Math.Abs(geneValue)); ! } ! else//add a part of the gene value to the gene value itself ! { ! if( geneValue < 0 ) ! returnValue = geneValue + Convert.ToInt32(partOfGeneToSubtractOrAdd*Math.Abs(geneValue)); ! else // geneValue >= 0 ! returnValue = Math.Min(genome.GetMaxValueForGenes(genePositionToBeMutated), ! geneValue + Convert.ToInt32(partOfGeneToSubtractOrAdd*geneValue)); ! } ! return returnValue; ! } ! private void mutate_MutateOnlyOneWeight(Genome genome) ! { ! int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(genePositionToBeMutated%2 == 1 ) ! //while the proposed genePositionToBeMutated points to a ticker ! genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! ! int newValueForGene = this.mutate_MutateOnlyOneWeight_getNewWeight(genome, genePositionToBeMutated); ! ! GenomeManagement.MutateOneGene(genome, genePositionToBeMutated, newValueForGene); ! } ! ! private void mutate_MutateAllGenes(Genome genome) ! { ! for(int genePositionToBeMutated = 0; ! genePositionToBeMutated < genome.Genes().Length; ! genePositionToBeMutated ++) ! { ! int newValueForGene = ! GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); ! while(genePositionToBeMutated%2 == 1 ! && GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome)) ! //while in the given position has to be stored ! //a new gene pointing to a ticker and ! //the proposed newValueForGene points to a ticker ! //already stored in the given genome ! // a new newalueForGene has to be generated ! newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); ! ! genome.SetGeneValue(newValueForGene, genePositionToBeMutated); ! } ! } ! ! //new version //mutation means just a change in one single weight //or in a complete new genome (with a probability of 50%) ! public override void Mutate(Genome genome) ! { ! int mutateOnlyOneWeight = GenomeManagement.RandomGenerator.Next(2); ! if(mutateOnlyOneWeight == 1) ! this.mutate_MutateOnlyOneWeight(genome); ! else//mutate all genome's genes ! this.mutate_MutateAllGenes(genome); ! } ! #endregion ! } } --- 112,256 ---- } ! public override object Decode(Genome genome) ! { ! string[] arrayOfTickers = new string[genome.Genes().Length/2]; ! double[] arrayOfTickersWeights = new double[genome.Genes().Length/2]; ! int indexOfTicker; ! int i = 0;//for the arrayOfTickers ! for(int index = 0; index < genome.Genes().Length; index++) ! { ! if(index%2==1) ! //indexForTicker is contained in genes at odd position ! { ! indexOfTicker = (int)genome.Genes().GetValue(index); ! arrayOfTickers[i] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); ! arrayOfTickersWeights[i] = this.getTickerWeight(genome.Genes(), index); ! i++; ! } ! } ! GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, ! arrayOfTickersWeights); ! return meaning; ! } ! #endregion ! public override int GetNewGeneValue(Genome genome, int genePosition) ! { ! // in this implementation only new gene values pointing to tickers ! // must be different from the others already stored (in odd positions of genome) ! int returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); ! while(genePosition%2 == 1 ! && GenomeManipulator.IsTickerContainedInGenome(returnValue,genome)) ! //while in the given position has to be stored ! //a new gene pointing to a ticker and ! //the proposed returnValue points to a ticker ! //already stored in the given genome ! { ! // a new returnValue has to be generated ! returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); ! } ! return returnValue; ! } ! #region override Mutate ! ! //OLD VERSION ! // public override void Mutate(Genome genome, double mutationRate) ! // { ! // // in this implementation only one gene is mutated ! // int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! // int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! // genome.GetMaxValueForGenes(genePositionToBeMutated) +1); ! // ! // while(genePositionToBeMutated%2 == 1 && ! // GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome)) ! // //while in the proposed genePositionToBeMutated has to be stored ! // //a new gene pointing to a ticker and ! // //the proposed newValueForGene points to a ticker ! // //already stored in the given genome ! // { ! // newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! // genome.GetMaxValueForGenes(genePositionToBeMutated) +1); ! // } ! // GenomeManagement.MutateOneGene(genome, mutationRate, ! // genePositionToBeMutated, newValueForGene); ! // } ! ! private int mutate_MutateOnlyOneWeight_getNewWeight(Genome genome, int genePositionToBeMutated) ! { ! int returnValue; ! double partOfGeneToSubtractOrAdd = 0.03; ! int geneValue = genome.GetGeneValue(genePositionToBeMutated); ! int subtractOrAdd = GenomeManagement.RandomGenerator.Next(2); ! if(subtractOrAdd == 1)//subtract a part of the gene value from the gene value itself ! { ! if( geneValue < 0 ) ! returnValue = Math.Max( geneValue - Convert.ToInt32(partOfGeneToSubtractOrAdd*Math.Abs(geneValue)), ! genome.GetMinValueForGenes(genePositionToBeMutated) ); ! else // geneValue >= 0 ! returnValue = geneValue - Convert.ToInt32(partOfGeneToSubtractOrAdd*Math.Abs(geneValue)); ! } ! else//add a part of the gene value to the gene value itself ! { ! if( geneValue < 0 ) ! returnValue = geneValue + Convert.ToInt32(partOfGeneToSubtractOrAdd*Math.Abs(geneValue)); ! else // geneValue >= 0 ! returnValue = Math.Min(genome.GetMaxValueForGenes(genePositionToBeMutated), ! geneValue + Convert.ToInt32(partOfGeneToSubtractOrAdd*geneValue)); ! } ! return returnValue; ! } ! private void mutate_MutateOnlyOneWeight(Genome genome) ! { ! int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(genePositionToBeMutated%2 == 1 ) ! //while the proposed genePositionToBeMutated points to a ticker ! genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! ! int newValueForGene = this.mutate_MutateOnlyOneWeight_getNewWeight(genome, genePositionToBeMutated); ! ! GenomeManagement.MutateOneGene(genome, genePositionToBeMutated, newValueForGene); ! } ! ! private void mutate_MutateAllGenes(Genome genome) ! { ! for(int genePositionToBeMutated = 0; ! genePositionToBeMutated < genome.Genes().Length; ! genePositionToBeMutated ++) ! { ! int newValueForGene = ! GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); ! while(genePositionToBeMutated%2 == 1 ! && GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome)) ! //while in the given position has to be stored ! //a new gene pointing to a ticker and ! //the proposed newValueForGene points to a ticker ! //already stored in the given genome ! // a new newalueForGene has to be generated ! newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); ! ! genome.SetGeneValue(newValueForGene, genePositionToBeMutated); ! } ! } ! ! //new version //mutation means just a change in one single weight //or in a complete new genome (with a probability of 50%) ! public override void Mutate(Genome genome) ! { ! int mutateOnlyOneWeight = GenomeManagement.RandomGenerator.Next(2); ! if(mutateOnlyOneWeight == 1) ! this.mutate_MutateOnlyOneWeight(genome); ! else//mutate all genome's genes ! this.mutate_MutateAllGenes(genome); ! } ! #endregion ! } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:31
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16791/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVOStrategy.cs RunPVO.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: PVOStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOStrategy.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PVOStrategy.cs 19 Aug 2008 17:13:01 -0000 1.6 --- PVOStrategy.cs 29 Sep 2008 21:18:34 -0000 1.7 *************** *** 25,28 **** --- 25,29 ---- using QuantProject.ADT; + using QuantProject.ADT.Histories; using QuantProject.ADT.Messaging; using QuantProject.Business.Financial.Accounting; *************** *** 56,60 **** /// </summary> [Serializable] ! public class PVOStrategy : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; --- 57,61 ---- /// </summary> [Serializable] ! public class PVOStrategy : IStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; *************** *** 68,72 **** protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalQuoteProvider historicalQuoteProvider; protected double maxAcceptableCloseToCloseDrawdown; protected double minimumAcceptableGain; --- 69,73 ---- protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; ! protected HistoricalMarketValueProvider historicalQuoteProvider; protected double maxAcceptableCloseToCloseDrawdown; protected double minimumAcceptableGain; *************** *** 137,141 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 138,142 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 172,176 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 173,177 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 195,199 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 196,200 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 220,224 **** double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 221,225 ---- double oversoldThresholdMAX, double overboughtThresholdMAX, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 243,247 **** double oversoldThreshold, double overboughtThreshold, ! HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) --- 244,248 ---- double oversoldThreshold, double overboughtThreshold, ! HistoricalMarketValueProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) *************** *** 257,282 **** } ! public virtual void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } ! public void FiveMinutesBeforeMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } ! private EndOfDayDateTime now() { ! return this.account.EndOfDayTimer.GetCurrentTime(); } #region MarketCloseEventHandler //forOutOfSampleTesting ! protected virtual EndOfDayDateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-this.numDaysForOscillatingPeriod]["quDate"], ! EndOfDaySpecificTime.MarketClose ); } --- 258,288 ---- } ! private void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { ; } ! private void fiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { } ! private DateTime now() { ! return this.account.Timer.GetCurrentDateTime(); } #region MarketCloseEventHandler //forOutOfSampleTesting ! protected virtual DateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { ! DateTime beginOfOscillatingPeriod = ! HistoricalEndOfDayTimer.GetMarketOpen( ! (DateTime)timer.IndexQuotes.Rows[ ! timer.CurrentDateArrayPosition-this.numDaysForOscillatingPeriod]["quDate"] ); ! return beginOfOscillatingPeriod; ! // return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-this.numDaysForOscillatingPeriod]["quDate"], ! // EndOfDaySpecificTime.MarketClose ); } *************** *** 299,304 **** private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) { ! EndOfDayDateTime today = timer.GetCurrentTime(); ! EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus pvoPositionsStatus = this.pvoPositionsForOutOfSample.GetStatus(beginOfOscillatingPeriod, today , this.benchmark.Ticker, this.historicalQuoteProvider, --- 305,310 ---- private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentDateTime(); ! DateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus pvoPositionsStatus = this.pvoPositionsForOutOfSample.GetStatus(beginOfOscillatingPeriod, today , this.benchmark.Ticker, this.historicalQuoteProvider, *************** *** 318,323 **** private PVOPositionsStatus marketCloseEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! EndOfDayDateTime today = timer.GetCurrentTime(); ! EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = --- 324,329 ---- private PVOPositionsStatus marketCloseEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { ! DateTime today = timer.GetCurrentDateTime(); ! DateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = *************** *** 431,436 **** } ! public virtual void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { try{ --- 437,442 ---- } ! private void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { try{ *************** *** 458,466 **** #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime) { this.returnsManager = ! new ReturnsManager(new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker, this.numDaysForOscillatingPeriod), this.historicalQuoteProvider); --- 464,472 ---- #region OneHourAfterMarketCloseEventHandler ! protected virtual void updateReturnsManager(DateTime firstDateTime, ! DateTime lastDateTime) { this.returnsManager = ! new ReturnsManager(new CloseToCloseIntervals(firstDateTime, lastDateTime, this.benchmark.Ticker, this.numDaysForOscillatingPeriod), this.historicalQuoteProvider); *************** *** 530,543 **** protected virtual void updateTestingPositions(DateTime currentDate) { ! EndOfDayHistory endOfDayHistory = this.benchmark.GetEndOfDayHistory( ! new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! EndOfDaySpecificTime.MarketClose), ! 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 ); --- 536,552 ---- protected virtual void updateTestingPositions(DateTime currentDate) { ! History history = this.benchmark.GetEndOfDayHistory( ! HistoricalEndOfDayTimer.GetMarketClose( ! currentDate.AddDays( -this.inSampleDays ) ) , ! HistoricalEndOfDayTimer.GetMarketClose( currentDate ) ); ! // new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), ! // EndOfDaySpecificTime.MarketClose), ! // 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 ); *************** *** 551,558 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public virtual void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.numDaysElapsedSinceLastOptimization++; if((this.numDaysElapsedSinceLastOptimization == --- 560,567 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! private void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ! this.lastCloseDate = dateTime; this.numDaysElapsedSinceLastOptimization++; if((this.numDaysElapsedSinceLastOptimization == *************** *** 560,564 **** //num days without optimization has elapsed { ! this.updateTestingPositions(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; --- 569,573 ---- //num days without optimization has elapsed { ! this.updateTestingPositions(dateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; *************** *** 567,570 **** --- 576,591 ---- } #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: RunPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/RunPVO.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RunPVO.cs 19 Aug 2008 17:13:01 -0000 1.6 --- RunPVO.cs 29 Sep 2008 21:18:34 -0000 1.7 *************** *** 128,151 **** protected override void run_initializeHistoricalQuoteProvider() { ! 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); } --- 128,156 ---- 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.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); } *************** *** 181,185 **** //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); --- 186,190 ---- //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:19:20
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16878/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers Modified Files: PVO_CTCCorrelationChooser.cs PVO_CTCStrongCorrelationChooser.cs PVO_OTOCorrelationChooser.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: PVO_CTCStrongCorrelationChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVO_CTCStrongCorrelationChooser.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVO_CTCStrongCorrelationChooser.cs 14 Aug 2008 23:41:49 -0000 1.1 --- PVO_CTCStrongCorrelationChooser.cs 29 Sep 2008 21:18:49 -0000 1.2 *************** *** 155,160 **** TickersPearsonCorrelation[] averageCorrelations; TickersPearsonCorrelation[] correlations_1Day; ! DateTime firstDate = returnsManager.ReturnIntervals[0].Begin.DateTime; ! DateTime lastDate = returnsManager.ReturnIntervals.LastEndOfDayDateTime.DateTime; CloseToCloseCorrelationProvider correlationProviderCTC_1 = new CloseToCloseCorrelationProvider(eligibleTickers.Tickers, firstDate, --- 155,160 ---- TickersPearsonCorrelation[] averageCorrelations; TickersPearsonCorrelation[] correlations_1Day; ! DateTime firstDate = returnsManager.ReturnIntervals[0].Begin; ! DateTime lastDate = returnsManager.ReturnIntervals.LastDateTime; CloseToCloseCorrelationProvider correlationProviderCTC_1 = new CloseToCloseCorrelationProvider(eligibleTickers.Tickers, firstDate, Index: PVO_OTOCorrelationChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVO_OTOCorrelationChooser.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVO_OTOCorrelationChooser.cs 14 Aug 2008 23:43:18 -0000 1.1 --- PVO_OTOCorrelationChooser.cs 29 Sep 2008 21:18:49 -0000 1.2 *************** *** 79,84 **** ReturnsManager returnsManager) { ! DateTime firstDate = returnsManager.ReturnIntervals[0].Begin.DateTime; ! DateTime lastDate = returnsManager.ReturnIntervals.LastEndOfDayDateTime.DateTime; this.correlationProvider = new OpenToOpenCorrelationProvider(eligibleTickers.Tickers, firstDate, --- 79,84 ---- ReturnsManager returnsManager) { ! DateTime firstDate = returnsManager.ReturnIntervals[0].Begin; ! DateTime lastDate = returnsManager.ReturnIntervals.LastDateTime; this.correlationProvider = new OpenToOpenCorrelationProvider(eligibleTickers.Tickers, firstDate, Index: PVO_CTCCorrelationChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVO_CTCCorrelationChooser.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PVO_CTCCorrelationChooser.cs 14 Aug 2008 23:28:06 -0000 1.4 --- PVO_CTCCorrelationChooser.cs 29 Sep 2008 21:18:49 -0000 1.5 *************** *** 78,83 **** ReturnsManager returnsManager) { ! DateTime firstDate = returnsManager.ReturnIntervals[0].Begin.DateTime; ! DateTime lastDate = returnsManager.ReturnIntervals.LastEndOfDayDateTime.DateTime; this.correlationProvider = new CloseToCloseCorrelationProvider(eligibleTickers.Tickers, firstDate, --- 78,83 ---- ReturnsManager returnsManager) { ! DateTime firstDate = returnsManager.ReturnIntervals[0].Begin; ! DateTime lastDate = returnsManager.ReturnIntervals.LastDateTime; this.correlationProvider = new CloseToCloseCorrelationProvider(eligibleTickers.Tickers, firstDate, |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:15
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16751/WalkForwardOneRank Modified Files: BestPerformingTickers.cs ChosenTickers.cs ComparableAccount.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: BestPerformingTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/BestPerformingTickers.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** BestPerformingTickers.cs 7 Jun 2005 15:18:56 -0000 1.10 --- BestPerformingTickers.cs 29 Sep 2008 21:18:25 -0000 1.11 *************** *** 43,47 **** private int numberDaysForPerformanceCalculation; ! private IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); --- 43,47 ---- private int numberDaysForPerformanceCalculation; ! private HistoricalMarketValueProvider historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); *************** *** 75,85 **** HistoricalEndOfDayTimer historicalEndOfDayTimer = new HistoricalEndOfDayTimer( ! new EndOfDayDateTime( dateTime.AddDays( -this.numberDaysForPerformanceCalculation ) , ! EndOfDaySpecificTime.MarketOpen ) ); ComparableAccount account = new ComparableAccount( ticker , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) ); OneRank oneRank = new OneRank( account , dateTime ); double goodness = account.Goodness; // forces Goodness computation here (for a better ProgressBar effect) --- 75,87 ---- HistoricalEndOfDayTimer historicalEndOfDayTimer = new HistoricalEndOfDayTimer( ! HistoricalEndOfDayTimer.GetMarketOpen( ! dateTime.AddDays( -this.numberDaysForPerformanceCalculation ) ) ); ! // new EndOfDayDateTime( dateTime.AddDays( -this.numberDaysForPerformanceCalculation ) , ! // EndOfDaySpecificTime.MarketOpen ) ); ComparableAccount account = new ComparableAccount( ticker , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalMarketValueProvider ) , new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalMarketValueProvider ) ); OneRank oneRank = new OneRank( account , dateTime ); double goodness = account.Goodness; // forces Goodness computation here (for a better ProgressBar effect) *************** *** 119,129 **** HistoricalEndOfDayTimer historicalEndOfDayTimer = new HistoricalEndOfDayTimer( ! new EndOfDayDateTime( dateTime.AddDays( -this.numberDaysForPerformanceCalculation ) , ! EndOfDaySpecificTime.MarketOpen ) ); ComparableAccount account = new ComparableAccount( ticker , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) ); OneRank oneRank = new OneRank( account , dateTime ); this.tickersWithGoodness.Add( new EstimatedObject( account.Key , account.Goodness ) ); --- 121,133 ---- HistoricalEndOfDayTimer historicalEndOfDayTimer = new HistoricalEndOfDayTimer( ! HistoricalEndOfDayTimer.GetMarketOpen( ! dateTime.AddDays( -this.numberDaysForPerformanceCalculation ) ) ); ! // new EndOfDayDateTime( dateTime.AddDays( -this.numberDaysForPerformanceCalculation ) , ! // EndOfDaySpecificTime.MarketOpen ) ); ComparableAccount account = new ComparableAccount( ticker , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalMarketValueProvider ) , new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalMarketValueProvider ) ); OneRank oneRank = new OneRank( account , dateTime ); this.tickersWithGoodness.Add( new EstimatedObject( account.Key , account.Goodness ) ); Index: ChosenTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/ChosenTickers.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ChosenTickers.cs 15 Oct 2005 17:59:35 -0000 1.7 --- ChosenTickers.cs 29 Sep 2008 21:18:25 -0000 1.8 *************** *** 3,7 **** ChosenTickers.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- ChosenTickers.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 **** private int numberTickersToBeChosen; ! private IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); --- 38,42 ---- private int numberTickersToBeChosen; ! private HistoricalMarketValueProvider historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); *************** *** 50,59 **** double todayMarketValueAtClose = account.DataStreamer.GetCurrentBid( ticker ); ! EndOfDayDateTime yesterdayAtClose = new ! EndOfDayDateTime( account.EndOfDayTimer.GetCurrentTime().DateTime.AddDays( - 1 ) , ! EndOfDaySpecificTime.MarketClose ); double yesterdayMarketValueAtClose = ! this.historicalQuoteProvider.GetMarketValue( ticker , ! yesterdayAtClose ); if ( todayMarketValueAtClose > yesterdayMarketValueAtClose ) // today close is higher than yesterday close --- 50,61 ---- double todayMarketValueAtClose = account.DataStreamer.GetCurrentBid( ticker ); ! DateTime yesterdayAtClose = ! HistoricalEndOfDayTimer.GetMarketClose( ! account.Timer.GetCurrentDateTime().AddDays( - 1 ) ); ! // new EndOfDayDateTime( account.EndOfDayTimer.GetCurrentTime().DateTime.AddDays( - 1 ) , ! // EndOfDaySpecificTime.MarketClose ); double yesterdayMarketValueAtClose = ! this.historicalMarketValueProvider.GetMarketValue( ticker , ! yesterdayAtClose ); if ( todayMarketValueAtClose > yesterdayMarketValueAtClose ) // today close is higher than yesterday close *************** *** 61,69 **** } private void setTickers_build( BestPerformingTickers bestPerformingTickers , ! Account account ) { int index = 0; while ( ( this.Count < this.numberTickersToBeChosen ) && ! ( index <= ( bestPerformingTickers.Count - 1 ) ) ) { string ticker = (string)bestPerformingTickers[ index ]; --- 63,71 ---- } private void setTickers_build( BestPerformingTickers bestPerformingTickers , ! Account account ) { int index = 0; while ( ( this.Count < this.numberTickersToBeChosen ) && ! ( index <= ( bestPerformingTickers.Count - 1 ) ) ) { string ticker = (string)bestPerformingTickers[ index ]; *************** *** 80,84 **** /// <param name="dateTime"></param> public void SetTickers( BestPerformingTickers bestPerformingTickers , ! Account account ) { this.Clear(); --- 82,86 ---- /// <param name="dateTime"></param> public void SetTickers( BestPerformingTickers bestPerformingTickers , ! Account account ) { this.Clear(); Index: ComparableAccount.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/ComparableAccount.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ComparableAccount.cs 15 Oct 2005 18:04:58 -0000 1.11 --- ComparableAccount.cs 29 Sep 2008 21:18:25 -0000 1.12 *************** *** 3,7 **** ComparableAccount.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- ComparableAccount.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; *************** *** 38,46 **** public class ComparableAccount : Account { ! // private double maxAcceptableDrawDown = 30; // private double minAcceptableWinningPeriods = 52; ! private IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); --- 38,46 ---- public class ComparableAccount : Account { ! // private double maxAcceptableDrawDown = 30; // private double minAcceptableWinningPeriods = 52; ! private HistoricalMarketValueProvider historicalMarketValueProvider = new HistoricalAdjustedQuoteProvider(); *************** *** 57,63 **** get { return this.goodness(); } } ! public ComparableAccount( string accountName , IEndOfDayTimer endOfDayTimer , ! IDataStreamer dataStreamer , IOrderExecutor orderExecutor ) : base( accountName , ! endOfDayTimer , dataStreamer , orderExecutor ) { } --- 57,63 ---- get { return this.goodness(); } } ! public ComparableAccount( string accountName , Timer endOfDayTimer , ! IDataStreamer dataStreamer , IOrderExecutor orderExecutor ) : base( accountName , ! endOfDayTimer , dataStreamer , orderExecutor ) { } *************** *** 68,74 **** { this.accountReport = new AccountReport( ! this , this.historicalQuoteProvider ); this.accountReport.SetEquityLine( 1 , ! this.EndOfDayTimer.GetCurrentTime() ); returnValue = AdvancedFunctions.GetSharpeRatio( this.accountReport.EquityLine.GetReturns().Values ); --- 68,75 ---- { this.accountReport = new AccountReport( ! this , this.historicalMarketValueProvider , ! new SelectorForMaketClose( this.Transactions.FirstDateTime ) ); this.accountReport.SetEquityLine( 1 , ! this.Timer.GetCurrentDateTime() ); returnValue = AdvancedFunctions.GetSharpeRatio( this.accountReport.EquityLine.GetReturns().Values ); |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:14
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16878/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO Modified Files: RunBiasedPVO_OTC.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: RunBiasedPVO_OTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/RunBiasedPVO_OTC.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunBiasedPVO_OTC.cs 19 Aug 2008 17:13:03 -0000 1.3 --- RunBiasedPVO_OTC.cs 29 Sep 2008 21:18:49 -0000 1.4 *************** *** 117,121 **** protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); } --- 117,121 ---- protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalMarketValueProvider = new HistoricalRawQuoteProvider(); } *************** *** 124,132 **** this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider, new FixedPercentageSlippageManager( ! this.historicalQuoteProvider, this.endOfDayTimer, 0.05 ) ), new IBCommissionManager() ); } --- 124,132 ---- this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalMarketValueProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalMarketValueProvider, new FixedPercentageSlippageManager( ! this.historicalMarketValueProvider, this.endOfDayTimer, 0.05 ) ), new IBCommissionManager() ); } *************** *** 206,212 **** this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), this.benchmark, ! this.historicalQuoteProvider); ObjectArchiver.Archive(accountReport, dirNameWhereToSaveReports + --- 206,212 ---- this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentDateTime(), this.benchmark, ! this.historicalMarketValueProvider); ObjectArchiver.Archive(accountReport, dirNameWhereToSaveReports + |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:11
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16833/LinearCombination Modified Files: ExtremeCounterTrendStrategy.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: ExtremeCounterTrendStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/ExtremeCounterTrendStrategy.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ExtremeCounterTrendStrategy.cs 19 Aug 2008 17:11:28 -0000 1.6 --- ExtremeCounterTrendStrategy.cs 29 Sep 2008 21:18:42 -0000 1.7 *************** *** 39,43 **** /// </summary> [Serializable] ! public class ExtremeCounterTrendStrategy : IEndOfDayStrategy { private Account account; --- 39,43 ---- /// </summary> [Serializable] ! public class ExtremeCounterTrendStrategy : IStrategy { private Account account; *************** *** 65,75 **** } ! public void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } --- 65,75 ---- } ! private void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { } ! private void fiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime) { } *************** *** 127,132 **** } ! public void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.numOfClosesElapsed++; --- 127,132 ---- } ! private void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.numOfClosesElapsed++; *************** *** 147,154 **** } ! public void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } } } --- 147,166 ---- } ! private void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime 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 ); + } + } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:10
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/InSampleChoosers/Decoding In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16833/FixedLengthTwoPhases/InSampleChoosers/Decoding Modified Files: DecoderForFLTPTestingPositionsWithBalancedWeights.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: DecoderForFLTPTestingPositionsWithBalancedWeights.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/InSampleChoosers/Decoding/DecoderForFLTPTestingPositionsWithBalancedWeights.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DecoderForFLTPTestingPositionsWithBalancedWeights.cs 16 Aug 2008 19:09:59 -0000 1.1 --- DecoderForFLTPTestingPositionsWithBalancedWeights.cs 29 Sep 2008 21:18:42 -0000 1.2 *************** *** 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; *************** *** 32,35 **** --- 32,36 ---- /// Decoder for the Fixed Length Two Phases strategy /// </summary> + [Serializable] public class DecoderForFLTPTestingPositionsWithBalancedWeights : DecoderForTestingPositionsWithBalancedWeights |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:07
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/Decoding In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16833/PairsTrading/InSample/InSampleChoosers/Decoding Modified Files: DecoderForPairsTradingTestingPositionsWithBalancedWeights.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: DecoderForPairsTradingTestingPositionsWithBalancedWeights.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/Decoding/DecoderForPairsTradingTestingPositionsWithBalancedWeights.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DecoderForPairsTradingTestingPositionsWithBalancedWeights.cs 11 May 2008 18:58:41 -0000 1.1 --- DecoderForPairsTradingTestingPositionsWithBalancedWeights.cs 29 Sep 2008 21:18:42 -0000 1.2 *************** *** 32,35 **** --- 32,36 ---- /// Decoder for the Pairs Trading strategy /// </summary> + [Serializable] public class DecoderForPairsTradingTestingPositionsWithBalancedWeights : DecoderForTestingPositionsWithBalancedWeights |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:06
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16833/FixedLengthTwoPhases/InSampleChoosers Modified Files: FixedLengthTwoPhasesFitnessEvaluator.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: FixedLengthTwoPhasesFitnessEvaluator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/InSampleChoosers/FixedLengthTwoPhasesFitnessEvaluator.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FixedLengthTwoPhasesFitnessEvaluator.cs 16 Aug 2008 19:32:17 -0000 1.3 --- FixedLengthTwoPhasesFitnessEvaluator.cs 29 Sep 2008 21:18:43 -0000 1.4 *************** *** 34,37 **** --- 34,38 ---- /// Evaluates (in sample) the fitness for a given WeightedPositions /// </summary> + [Serializable] public class FixedLengthTwoPhasesFitnessEvaluator : IFitnessEvaluator { |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:19:01
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16751/LinearCombination Modified Files: CloseToOpenDailyStrategy.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: CloseToOpenDailyStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/CloseToOpenDailyStrategy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CloseToOpenDailyStrategy.cs 12 Mar 2008 22:09:04 -0000 1.3 --- CloseToOpenDailyStrategy.cs 29 Sep 2008 21:18:26 -0000 1.4 *************** *** 3,7 **** CloseToOpenDailyStrategy.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- CloseToOpenDailyStrategy.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 **** /// </summary> [Serializable] ! public class CloseToOpenDailyStrategy : IEndOfDayStrategy { private Account account; --- 36,40 ---- /// </summary> [Serializable] ! public class CloseToOpenDailyStrategy : IStrategy { private Account account; *************** *** 48,52 **** public CloseToOpenDailyStrategy( Account account , ! WeightedPositions weightedPositions) { this.account = account; --- 48,52 ---- public CloseToOpenDailyStrategy( Account account , ! WeightedPositions weightedPositions) { this.account = account; *************** *** 54,79 **** } ! public void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { AccountManager.ClosePositions(this.account); } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } ! public void MarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! if ( ( this.account.CashAmount == 0 ) && ! ( this.account.Transactions.Count == 0 ) ) ! // cash has not been added yet ! this.account.AddCash( 15000 ); ! AccountManager.OpenPositions(this.weightedPositions, this.account); } ! public void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } } } --- 54,90 ---- } ! private void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { AccountManager.ClosePositions(this.account); } ! private void fiveMinutesBeforeMarketCloseEventHandler( Object sender , ! DateTime dateTime) { } ! private void marketCloseEventHandler( Object sender , ! DateTime dateTime) { ! if ( ( this.account.CashAmount == 0 ) && ! ( this.account.Transactions.Count == 0 ) ) ! // cash has not been added yet ! this.account.AddCash( 15000 ); ! AccountManager.OpenPositions(this.weightedPositions, this.account); } ! private void oneHourAfterMarketCloseEventHandler( Object sender , ! DateTime 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 ); + } } } |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:18:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16649/TestingOTCTypes/BruteForceOptimization Modified Files: EndOfDayTimerHandlerOTCTypesBruteForce.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: EndOfDayTimerHandlerOTCTypesBruteForce.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization/EndOfDayTimerHandlerOTCTypesBruteForce.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerOTCTypesBruteForce.cs 26 Mar 2008 00:48:26 -0000 1.4 --- EndOfDayTimerHandlerOTCTypesBruteForce.cs 29 Sep 2008 21:18:09 -0000 1.5 *************** *** 46,50 **** /// </summary> [Serializable] ! public class EndOfDayTimerHandlerOTCTypesBruteForce : EndOfDayTimerHandler { private int seedForRandomGenerator; --- 46,51 ---- /// </summary> [Serializable] ! public class EndOfDayTimerHandlerOTCTypesBruteForce : ! QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios.EndOfDayTimerHandler { private int seedForRandomGenerator; *************** *** 91,96 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { for(int i = 0; i<this.accounts.Length; i++) --- 92,97 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { for(int i = 0; i<this.accounts.Length; i++) *************** *** 114,119 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.accounts[1].Portfolio.Count > 0) --- 115,120 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.accounts[1].Portfolio.Count > 0) *************** *** 139,143 **** } ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) --- 140,144 ---- } ! #region oneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) *************** *** 210,215 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.seedForRandomGenerator++; --- 211,216 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.seedForRandomGenerator++; *************** *** 217,221 **** this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen at next Market Open event this.numDaysElapsedSinceLastOptimization = 0; --- 218,222 ---- this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(dateTime, false); //sets tickers to be chosen at next Market Open event this.numDaysElapsedSinceLastOptimization = 0; |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:18:46
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16230 Modified Files: EndOfDayTimerHandlerLastChosenPortfolio.cs EndOfDayTimerHandlerOTC.cs EndOfDayTimerHandlerOTC_WorstAtNight.cs EndOfDayTimerHandlerOTCCTO.cs EndOfDayTimerHandlerOTCMultiday.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: EndOfDayTimerHandlerOTCCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCCTO.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EndOfDayTimerHandlerOTCCTO.cs 19 Aug 2008 17:11:27 -0000 1.9 --- EndOfDayTimerHandlerOTCCTO.cs 29 Sep 2008 21:17:53 -0000 1.10 *************** *** 71,76 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //temporarily the if condition --- 71,76 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { //temporarily the if condition *************** *** 80,85 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { --- 80,85 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { *************** *** 101,105 **** ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) --- 101,105 ---- ! #region oneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) *************** *** 180,185 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.seedForRandomGenerator++; --- 180,185 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.seedForRandomGenerator++; *************** *** 188,192 **** this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; --- 188,192 ---- this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(dateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; Index: EndOfDayTimerHandlerOTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTC.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** EndOfDayTimerHandlerOTC.cs 14 Aug 2008 23:29:40 -0000 1.8 --- EndOfDayTimerHandlerOTC.cs 29 Sep 2008 21:17:53 -0000 1.9 *************** *** 74,79 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.openPositions(); --- 74,79 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { this.openPositions(); *************** *** 81,86 **** ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { AccountManager.ClosePositions(this.account); --- 81,86 ---- ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { AccountManager.ClosePositions(this.account); *************** *** 89,93 **** ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) --- 89,93 ---- ! #region oneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) *************** *** 217,222 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.seedForRandomGenerator++; --- 217,222 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.seedForRandomGenerator++; *************** *** 225,229 **** this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; --- 225,229 ---- this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(dateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; *************** *** 236,240 **** } ! #endregion } --- 236,240 ---- } ! #endregion oneHourAfterMarketCloseEventHandler } Index: EndOfDayTimerHandlerLastChosenPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerLastChosenPortfolio.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** EndOfDayTimerHandlerLastChosenPortfolio.cs 14 Jan 2008 23:32:31 -0000 1.5 --- EndOfDayTimerHandlerLastChosenPortfolio.cs 29 Sep 2008 21:17:52 -0000 1.6 *************** *** 47,58 **** public class EndOfDayTimerHandlerLastChosenPortfolio : EndOfDayTimerHandler { ! private EndOfDayDateTime firstDate; ! private EndOfDayDateTime lastDate; public EndOfDayTimerHandlerLastChosenPortfolio(string[] chosenTickers, PortfolioType portfolioType, Account account, string benchmark, ! EndOfDayDateTime firstDate, ! EndOfDayDateTime lastDate): base(new WeightedPositions( new SignedTickers(chosenTickers) ), portfolioType, account, benchmark) --- 47,58 ---- public class EndOfDayTimerHandlerLastChosenPortfolio : EndOfDayTimerHandler { ! private DateTime firstDate; ! private DateTime lastDate; public EndOfDayTimerHandlerLastChosenPortfolio(string[] chosenTickers, PortfolioType portfolioType, Account account, string benchmark, ! DateTime firstDate, ! DateTime lastDate): base(new WeightedPositions( new SignedTickers(chosenTickers) ), portfolioType, account, benchmark) *************** *** 67,74 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(endOfDayTimingEventArgs.EndOfDayDateTime.CompareTo(this.firstDate) == 0) { this.openPositions(); --- 67,74 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { ! if( dateTime == this.firstDate ) { this.openPositions(); *************** *** 76,91 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //if(endOfDayTimingEventArgs.EndOfDayDateTime.CompareTo(this.lastDate) == 0) // this.closePositions(); ! if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.CompareTo(this.lastDate.DateTime.AddDays(-1)) == 0) AccountManager.ClosePositions(this.account); } ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; --- 76,91 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { //if(endOfDayTimingEventArgs.EndOfDayDateTime.CompareTo(this.lastDate) == 0) // this.closePositions(); ! if(dateTime.CompareTo(this.lastDate.AddDays(-1)) == 0) AccountManager.ClosePositions(this.account); } ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ; Index: EndOfDayTimerHandlerOTCMultiday.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCMultiday.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EndOfDayTimerHandlerOTCMultiday.cs 14 Jan 2008 23:32:32 -0000 1.9 --- EndOfDayTimerHandlerOTCMultiday.cs 29 Sep 2008 21:17:53 -0000 1.10 *************** *** 70,75 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { --- 70,75 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { *************** *** 78,83 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.numDaysElapsedSinceLastOptimization == --- 78,83 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.numDaysElapsedSinceLastOptimization == *************** *** 86,90 **** } ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) --- 86,90 ---- } ! #region oneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) *************** *** 162,167 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.seedForRandomGenerator++; --- 162,167 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.seedForRandomGenerator++; *************** *** 170,174 **** this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; --- 170,174 ---- this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(dateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; Index: EndOfDayTimerHandlerOTC_WorstAtNight.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTC_WorstAtNight.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerOTC_WorstAtNight.cs 19 Aug 2008 17:11:26 -0000 1.4 --- EndOfDayTimerHandlerOTC_WorstAtNight.cs 29 Sep 2008 21:17:53 -0000 1.5 *************** *** 81,91 **** double lossOfCurrentWorstCombination = 0.0; double fitnessOfPreviousCombination = 0.0; ! IndexBasedEndOfDayTimer currentTimer = (IndexBasedEndOfDayTimer)this.account.EndOfDayTimer; ! DateTime today = currentTimer.GetCurrentTime().DateTime; DateTime lastMarketDay = currentTimer.GetPreviousDateTime(); ReturnsManager returnsManager = new ReturnsManager( ! new CloseToOpenIntervals(new EndOfDayDateTime(lastMarketDay, EndOfDaySpecificTime.MarketClose), ! new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketOpen), ! this.benchmark), this.historicalAdjustedQuoteProvider ); int numOfGenomesScanned = 0; --- 81,94 ---- double lossOfCurrentWorstCombination = 0.0; double fitnessOfPreviousCombination = 0.0; ! IndexBasedEndOfDayTimer currentTimer = (IndexBasedEndOfDayTimer)this.account.Timer; ! DateTime today = currentTimer.GetCurrentDateTime(); DateTime lastMarketDay = currentTimer.GetPreviousDateTime(); ReturnsManager returnsManager = new ReturnsManager( ! new CloseToOpenIntervals( ! HistoricalEndOfDayTimer.GetMarketClose( lastMarketDay ) , ! HistoricalEndOfDayTimer.GetMarketOpen( today ) , ! // new EndOfDayDateTime(lastMarketDay, EndOfDaySpecificTime.MarketClose), ! // new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketOpen), ! this.benchmark), this.historicalAdjustedQuoteProvider ); int numOfGenomesScanned = 0; *************** *** 135,140 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.currentGO != null) --- 138,143 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { if(this.currentGO != null) *************** *** 145,155 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { AccountManager.ClosePositions(this.account); } ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) --- 148,158 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { AccountManager.ClosePositions(this.account); } ! #region oneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) *************** *** 242,247 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.seedForRandomGenerator++; --- 245,250 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.seedForRandomGenerator++; *************** *** 250,254 **** this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; --- 253,257 ---- this.numDaysBetweenEachOptimization - 1) { ! this.setTickers( dateTime , false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:18:45
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16649/SimpleSelection Modified Files: EndOfDayTimerHandlerSimpleSelection.cs EndOfDayTimerHandlerSimpleSelectionOpenToClose.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: EndOfDayTimerHandlerSimpleSelection.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection/EndOfDayTimerHandlerSimpleSelection.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerSimpleSelection.cs 29 Aug 2007 09:43:34 -0000 1.2 --- EndOfDayTimerHandlerSimpleSelection.cs 29 Sep 2008 21:18:09 -0000 1.3 *************** *** 56,71 **** } ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; --- 56,71 ---- } ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { ; } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { ; } ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { ; Index: EndOfDayTimerHandlerSimpleSelectionOpenToClose.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection/EndOfDayTimerHandlerSimpleSelectionOpenToClose.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerSimpleSelectionOpenToClose.cs 29 Aug 2007 09:43:34 -0000 1.2 --- EndOfDayTimerHandlerSimpleSelectionOpenToClose.cs 29 Sep 2008 21:18:09 -0000 1.3 *************** *** 59,74 **** ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.openPositions(); } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { AccountManager.ClosePositions(this.account); } ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) --- 59,74 ---- ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { this.openPositions(); } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { AccountManager.ClosePositions(this.account); } ! #region oneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) *************** *** 144,154 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; --- 144,154 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(dateTime); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; |
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:18:44
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16649/TestingOTCTypes Modified Files: EndOfDayTimerHandlerOTCTypes.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: EndOfDayTimerHandlerOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/EndOfDayTimerHandlerOTCTypes.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EndOfDayTimerHandlerOTCTypes.cs 14 Jan 2008 23:32:32 -0000 1.9 --- EndOfDayTimerHandlerOTCTypes.cs 29 Sep 2008 21:18:09 -0000 1.10 *************** *** 85,90 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { for(int i = 0; i<this.accounts.Length; i++) --- 85,90 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { for(int i = 0; i<this.accounts.Length; i++) *************** *** 108,113 **** } ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.accounts[1].Portfolio.Count > 0) --- 108,113 ---- } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime ) { if(this.accounts[1].Portfolio.Count > 0) *************** *** 133,137 **** } ! #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) --- 133,137 ---- } ! #region oneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) *************** *** 201,206 **** /// <param name="sender"></param> /// <param name="eventArgs"></param> ! public override void OneHourAfterMarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.seedForRandomGenerator++; --- 201,206 ---- /// <param name="sender"></param> /// <param name="eventArgs"></param> ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime ) { this.seedForRandomGenerator++; *************** *** 208,212 **** this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen at next Market Open event this.numDaysElapsedSinceLastOptimization = 0; --- 208,212 ---- this.numDaysBetweenEachOptimization - 1) { ! this.setTickers(dateTime, false); //sets tickers to be chosen at next Market Open event this.numDaysElapsedSinceLastOptimization = 0; |