quantproject-developers Mailing List for QuantProject (Page 60)
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-01-27 02:30:34
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21473/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases Modified Files: FixedLengthTwoPhasesMain.cs Log Message: An even smaller group of tickers has been added, to perform even faster tests. Index: FixedLengthTwoPhasesMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/FixedLengthTwoPhasesMain.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FixedLengthTwoPhasesMain.cs 19 Jan 2008 18:35:34 -0000 1.1 --- FixedLengthTwoPhasesMain.cs 27 Jan 2008 02:30:30 -0000 1.2 *************** *** 96,100 **** int numberOfPortfolioPositions = 2; int inSampleDays = 30; ! string tickersGroupId = "millo"; Benchmark benchmark = new Benchmark( "MSFT" ); --- 96,101 ---- int numberOfPortfolioPositions = 2; int inSampleDays = 30; ! // string tickersGroupId = "millo"; ! string tickersGroupId = "fastTest"; Benchmark benchmark = new Benchmark( "MSFT" ); *************** *** 142,146 **** DateTime firstDateTime = new DateTime( 2001 , 1 , 2 ); ! DateTime lastDateTime = new DateTime( 2004 , 1 , 15 ); double maxRunningHours = 0.2; EndOfDayStrategyBackTester endOfDayStrategyBackTester = --- 143,147 ---- DateTime firstDateTime = new DateTime( 2001 , 1 , 2 ); ! DateTime lastDateTime = new DateTime( 2001 , 1 , 7 ); double maxRunningHours = 0.2; EndOfDayStrategyBackTester endOfDayStrategyBackTester = |
|
From: Glauco S. <gla...@us...> - 2008-01-27 02:29:41
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv20895/b1_ADT Modified Files: ExtendedDateTime.cs Log Message: The method public static string GetShortDescriptionForFileName( DateTime dateTime ) has been added. It returns a DateTime short description suitable for file names (no slashes) Index: ExtendedDateTime.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ExtendedDateTime.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ExtendedDateTime.cs 19 Jan 2008 18:54:42 -0000 1.4 --- ExtendedDateTime.cs 27 Jan 2008 02:29:36 -0000 1.5 *************** *** 104,107 **** --- 104,120 ---- } /// <summary> + /// Returns a DateTime short description suitable for file names (no slashes) + /// </summary> + /// <returns></returns> + public static string GetShortDescriptionForFileName( + DateTime dateTime ) + { + string stringForFileName = + dateTime.Year.ToString() + "_" + + dateTime.Month.ToString().PadLeft( 2 , '0' ) + "_" + + dateTime.Day.ToString().PadLeft( 2 , '0' ); + return stringForFileName; + } + /// <summary> /// Returns the earliest date /// </summary> |
|
From: Glauco S. <gla...@us...> - 2008-01-27 02:27:50
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19994/b4_Business/a2_Strategies Modified Files: EndOfDayStrategyBackTester.cs Log Message: The property DescriptionForLogFileName has been improved Index: EndOfDayStrategyBackTester.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EndOfDayStrategyBackTester.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayStrategyBackTester.cs 19 Jan 2008 17:35:04 -0000 1.1 --- EndOfDayStrategyBackTester.cs 27 Jan 2008 02:27:46 -0000 1.2 *************** *** 23,26 **** --- 23,27 ---- using System; + using QuantProject.ADT; using QuantProject.ADT.FileManaging; using QuantProject.ADT.Messaging; *************** *** 89,95 **** string description = this.backTestID + "_" + ! "from_" + this.firstDateTime.ToShortDateString() + "_" + ! "to_" + this.lastDateTime.ToShortDateString() + "_" + ! "strtgy_" + this.endOfDayStrategy.DescriptionForLogFileName; return description; } --- 90,98 ---- string description = this.backTestID + "_" + ! "from_" + ! ExtendedDateTime.GetShortDescriptionForFileName( this.firstDateTime ) + ! "_to_" + ! ExtendedDateTime.GetShortDescriptionForFileName( this.lastDateTime ) + ! "_strtgy_" + this.endOfDayStrategy.DescriptionForLogFileName; return description; } |
|
From: Glauco S. <gla...@us...> - 2008-01-27 02:25:48
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19133/b4_Business/a1_Financial/a2_Accounting/h5_Reporting Modified Files: AccountReport.cs Log Message: A text description for the report, suitable for file names also Index: AccountReport.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting/AccountReport.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** AccountReport.cs 19 Feb 2006 18:03:44 -0000 1.18 --- AccountReport.cs 27 Jan 2008 02:25:43 -0000 1.19 *************** *** 125,128 **** --- 125,135 ---- } + /// <summary> + /// A text description for the report, suitable for file names also + /// </summary> + public string Description + { + get { return this.reportName; } + } /// <summary> /// Add the last account record to the AccountReport |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:30:41
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv26438/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagMain.cs Log Message: Minor changes to test a slightly different strategy Index: WFLagMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagMain.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** WFLagMain.cs 4 Nov 2007 19:00:14 -0000 1.15 --- WFLagMain.cs 19 Jan 2008 19:30:38 -0000 1.16 *************** *** 148,160 **** // new QuantProject.Business.Strategies.EquityEvaluation.SharpeRatio() , // 1000 , 20 ); - wFLagWeightedPositionsChooser = - new WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio( - 4 , new SignedTickers( "IWM;-SPY" ) , 100 , "EWQ" , - new QuantProject.Business.Strategies.EquityEvaluation.SharpeRatio() , - 10000 , 30 ); // wFLagWeightedPositionsChooser = ! // new WFLagBruteForceWeightedPositionsChooserForBalancedFixedPortfolioAndBalancedDriving( // 4 , new SignedTickers( "IWM;-SPY" ) , 100 , "EWQ" , ! // new QuantProject.Business.Strategies.EquityEvaluation.SharpeRatio() ); // new RunWalkForwardLag( "DrvPstns" , 200 , // wFLagWeightedPositionsChooser , 7 , --- 148,160 ---- // new QuantProject.Business.Strategies.EquityEvaluation.SharpeRatio() , // 1000 , 20 ); // wFLagWeightedPositionsChooser = ! // new WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio( // 4 , new SignedTickers( "IWM;-SPY" ) , 100 , "EWQ" , ! // new QuantProject.Business.Strategies.EquityEvaluation.SharpeRatio() , ! // 10000 , 30 ); ! wFLagWeightedPositionsChooser = ! new WFLagBruteForceWeightedPositionsChooserForBalancedFixedPortfolioAndBalancedDriving( ! 2 , new SignedTickers( "IWM;-SPY" ) , 100 , "EWQ" , ! new QuantProject.Business.Strategies.EquityEvaluation.SharpeRatio() ); // new RunWalkForwardLag( "DrvPstns" , 200 , // wFLagWeightedPositionsChooser , 7 , |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:29:37
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv25961/b3_Data/DataTables Modified Files: TickerDataTable.cs Log Message: - The method public static DataTable GetTickersQuotedInEachMarketDay( History marketDays, DataTable setOfTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers) has been added Index: TickerDataTable.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/TickerDataTable.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TickerDataTable.cs 26 Sep 2007 22:01:44 -0000 1.9 --- TickerDataTable.cs 19 Jan 2008 19:29:34 -0000 1.10 *************** *** 191,195 **** #endregion ! private static void addColumnNumberOfQuotes(DataTable tableToAnalyze) { --- 191,195 ---- #endregion ! #region GetTickersQuotedInEachMarketDay private static void addColumnNumberOfQuotes(DataTable tableToAnalyze) { *************** *** 197,210 **** tableToAnalyze.Columns.Add("NumberOfQuotes", System.Type.GetType("System.Int32")); } ! ! private static int getNumberOfTradingDays(string marketIndex, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate) ! { ! QuantProject.Data.DataTables.Quotes marketQuotes = ! new QuantProject.Data.DataTables.Quotes(marketIndex, firstQuoteDate, lastQuoteDate); ! return marketQuotes.Rows.Count; ! } ! private static void getTickersQuotedInEachMarketDay_addRow(DataRow rowToBeAdded, int numberOfTradingDays, DataTable tableToWhichRowIsToBeAdded) --- 197,201 ---- tableToAnalyze.Columns.Add("NumberOfQuotes", System.Type.GetType("System.Int32")); } ! private static void getTickersQuotedInEachMarketDay_addRow(DataRow rowToBeAdded, int numberOfTradingDays, DataTable tableToWhichRowIsToBeAdded) *************** *** 214,316 **** newRow["NumberOfQuotes"] = numberOfTradingDays; tableToWhichRowIsToBeAdded.Rows.Add(newRow); } ! //new implementation ! public static DataTable GetTickersQuotedInEachMarketDay(string marketIndex, string groupID, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers) { ! History marketDaysForIndex = Quotes.GetMarketDays(marketIndex, firstQuoteDate , lastQuoteDate); ! DataTable groupOfTicker = QuantProject.DataAccess.Tables.Tickers_tickerGroups.GetTickers(groupID); ! TickerDataTable.addColumnNumberOfQuotes(groupOfTicker); ! QuantProject.Data.DataTables.GroupQuotes tickerQuotes = ! new QuantProject.Data.DataTables.GroupQuotes( ! groupID, firstQuoteDate, lastQuoteDate); ! DataTable returnValue = groupOfTicker.Clone(); ! History marketDaysForTicker; ! foreach(DataRow row in groupOfTicker.Rows) ! { ! marketDaysForTicker = Quotes.GetMarketDays( (string)row[0], ! firstQuoteDate , lastQuoteDate); ! if( marketDaysForTicker.ContainsAllTheDatesIn(marketDaysForIndex) ) ! //the current ticker has been effectively traded in each market day ! TickerDataTable.getTickersQuotedInEachMarketDay_addRow( ! row, marketDaysForTicker.Count, returnValue); ! } ! ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers); ! return returnValue; } ! //new implementation ! public static DataTable GetTickersQuotedInEachMarketDay(string marketIndex, DataTable setOfTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers) { ! History marketDaysForIndex = Quotes.GetMarketDays(marketIndex, ! firstQuoteDate , lastQuoteDate); ! TickerDataTable.addColumnNumberOfQuotes(setOfTickers); ! DataTable returnValue = setOfTickers.Clone(); ! History marketDaysForTicker; ! foreach(DataRow row in setOfTickers.Rows) ! { ! marketDaysForTicker = Quotes.GetMarketDays( (string)row[0], ! firstQuoteDate , lastQuoteDate); ! if( marketDaysForTicker.ContainsAllTheDatesIn(marketDaysForIndex) ) ! //the current ticker has been effectively traded in each market day ! TickerDataTable.getTickersQuotedInEachMarketDay_addRow( ! row, marketDaysForTicker.Count, returnValue); ! } ! ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers); ! return returnValue; } - - //OLD IMPLEMENTATION OF GetTickersQuotedInEachMarketDay - // public static DataTable GetTickersQuotedInEachMarketDay(string marketIndex, string groupID, - // DateTime firstQuoteDate, - // DateTime lastQuoteDate, - // long maxNumOfReturnedTickers) - // { - // int marketDaysForTheGivenMarket = - // TickerDataTable.getNumberOfTradingDays(marketIndex, firstQuoteDate, lastQuoteDate); - // DataTable groupOfTicker = QuantProject.DataAccess.Tables.Tickers_tickerGroups.GetTickers(groupID); - // TickerDataTable.addColumnNumberOfQuotes(groupOfTicker); - // QuantProject.Data.DataTables.GroupQuotes tickerQuotes = - // new QuantProject.Data.DataTables.GroupQuotes( - // groupID, firstQuoteDate, lastQuoteDate); - // DataTable returnValue = groupOfTicker.Clone(); - // foreach(DataRow row in groupOfTicker.Rows) - // { - // if(tickerQuotes.GetNumberOfDaysWithEffectiveTrades((string)row[0]) == marketDaysForTheGivenMarket) - // //the current ticker has been effectively traded in each market day - // TickerDataTable.getTickersQuotedInEachMarketDay_addRow(row, marketDaysForTheGivenMarket, - // returnValue); - // } - // ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers); - // return returnValue; - // - // } - // - // public static DataTable GetTickersQuotedInEachMarketDay(string marketIndex, DataTable setOfTickers, - // DateTime firstQuoteDate, - // DateTime lastQuoteDate, - // long maxNumOfReturnedTickers) - // { - // int marketDaysForTheGivenMarket = - // TickerDataTable.getNumberOfTradingDays(marketIndex, firstQuoteDate, lastQuoteDate); - // TickerDataTable.addColumnNumberOfQuotes(setOfTickers); - // DataTable returnValue = setOfTickers.Clone(); - // foreach(DataRow row in setOfTickers.Rows) - // { - // if(QuantProject.DataAccess.Tables.Quotes.GetNumberOfDaysWithEffectiveTrades((string)row[0],firstQuoteDate,lastQuoteDate) == marketDaysForTheGivenMarket) - // //the current ticker has the same number of quotes as the market index - // TickerDataTable.getTickersQuotedInEachMarketDay_addRow(row, marketDaysForTheGivenMarket, - // returnValue); - // } - // ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers); - // return returnValue; - // } private static void getTickersQuotedNotAtEachMarketDay_addRow(DataRow rowToBeAdded, int numberOfTradingDays, --- 205,263 ---- newRow["NumberOfQuotes"] = numberOfTradingDays; tableToWhichRowIsToBeAdded.Rows.Add(newRow); + } + + private static void getTickersQuotedInEachMarketDay_handleRow( + DataRow row , History marketDays , + DateTime firstQuoteDate , DateTime lastQuoteDate , + DataTable tableToWhichRowIsToBeAdded ) + { + History marketDaysForTicker = Quotes.GetMarketDays( (string)row[0], + firstQuoteDate , lastQuoteDate); + if( marketDaysForTicker.ContainsAllTheDatesIn( marketDays ) ) + //the current ticker has been effectively traded in each market day + TickerDataTable.getTickersQuotedInEachMarketDay_addRow( + row , marketDaysForTicker.Count , tableToWhichRowIsToBeAdded ); } ! public static DataTable GetTickersQuotedInEachMarketDay( ! History marketDays, DataTable setOfTickers, ! DateTime firstQuoteDate, DateTime lastQuoteDate, ! long maxNumOfReturnedTickers) ! { ! TickerDataTable.addColumnNumberOfQuotes(setOfTickers); ! DataTable returnValue = setOfTickers.Clone(); ! foreach(DataRow row in setOfTickers.Rows) ! getTickersQuotedInEachMarketDay_handleRow( ! row , marketDays , ! firstQuoteDate , lastQuoteDate , returnValue ); ! ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers); ! return returnValue; ! } ! #endregion GetTickersQuotedInEachMarketDay ! ! public static DataTable GetTickersQuotedInEachMarketDay(string marketIndex, DataTable setOfTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers) { ! History marketDaysForIndex = Quotes.GetMarketDays(marketIndex, firstQuoteDate , lastQuoteDate); ! return GetTickersQuotedInEachMarketDay( ! marketDaysForIndex , setOfTickers , ! firstQuoteDate , lastQuoteDate , maxNumOfReturnedTickers ); } ! public static DataTable GetTickersQuotedInEachMarketDay(string marketIndex, string groupID, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers) { ! DataTable groupOfTicker = ! QuantProject.DataAccess.Tables.Tickers_tickerGroups.GetTickers(groupID); ! return GetTickersQuotedInEachMarketDay( ! marketIndex , groupOfTicker , ! firstQuoteDate , lastQuoteDate , maxNumOfReturnedTickers ); } + private static void getTickersQuotedNotAtEachMarketDay_addRow(DataRow rowToBeAdded, int numberOfTradingDays, *************** *** 345,351 **** } public static DataTable GetTickersNotQuotedAtEachMarketDay(string marketIndex, DataTable setOfTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, long maxNumOfReturnedTickers) { --- 292,306 ---- } + private static int getNumberOfTradingDays(string marketIndex, + DateTime firstQuoteDate, + DateTime lastQuoteDate) + { + QuantProject.Data.DataTables.Quotes marketQuotes = + new QuantProject.Data.DataTables.Quotes(marketIndex, firstQuoteDate, lastQuoteDate); + return marketQuotes.Rows.Count; + } public static DataTable GetTickersNotQuotedAtEachMarketDay(string marketIndex, DataTable setOfTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, long maxNumOfReturnedTickers) { |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:27:41
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv25124/b3_Data/Selectors Modified Files: SelectorByQuotationAtEachMarketDay.cs Log Message: - the new constructor public SelectorByQuotationAtEachMarketDay( DataTable setOfTickersToBeSelected , bool orderInASCmode , History marketDays , long maxNumOfReturnedTickers ) has been added - the method GetTableOfSelectedTickers() has been changed accordingly MILLO, PLEASE CHECK if any bug may have been introduced by the changes. Index: SelectorByQuotationAtEachMarketDay.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Selectors/SelectorByQuotationAtEachMarketDay.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SelectorByQuotationAtEachMarketDay.cs 27 Feb 2005 19:56:07 -0000 1.1 --- SelectorByQuotationAtEachMarketDay.cs 19 Jan 2008 19:27:38 -0000 1.2 *************** *** 25,28 **** --- 25,30 ---- using System.Data; using System.Windows.Forms; + + using QuantProject.ADT.Histories; using QuantProject.DataAccess.Tables; using QuantProject.Data.DataTables; *************** *** 35,39 **** public class SelectorByQuotationAtEachMarketDay : TickerSelector , ITickerSelector { ! private string marketIndex; public SelectorByQuotationAtEachMarketDay(DataTable setOfTickersToBeSelected, --- 37,42 ---- public class SelectorByQuotationAtEachMarketDay : TickerSelector , ITickerSelector { ! private string marketIndex; ! private History marketDays; public SelectorByQuotationAtEachMarketDay(DataTable setOfTickersToBeSelected, *************** *** 60,87 **** lastQuoteDate, maxNumOfReturnedTickers) ! { ! this.marketIndex = marketIndex; ! } ! public DataTable GetTableOfSelectedTickers() ! { ! if(this.marketIndex == "") ! throw new Exception("You first need to set TickerSelector's property <<MarketIndex>>!"); ! if(this.setOfTickersToBeSelected == null) ! return QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedInEachMarketDay( ! this.marketIndex, this.groupID, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers); ! else ! return QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedInEachMarketDay( ! this.marketIndex, this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers); ! } ! public void SelectAllTickers() ! { ! ; ! } ! } } --- 63,123 ---- lastQuoteDate, maxNumOfReturnedTickers) ! { ! this.marketIndex = marketIndex; ! } ! ! public SelectorByQuotationAtEachMarketDay( ! DataTable setOfTickersToBeSelected , bool orderInASCmode , ! History marketDays , long maxNumOfReturnedTickers ): ! base(setOfTickersToBeSelected , ! orderInASCmode , ! marketDays.FirstDateTime , ! marketDays.LastDateTime , ! maxNumOfReturnedTickers ) ! { ! this.marketIndex = ""; ! this.marketDays = marketDays; ! } + ! #region GetTableOfSelectedTickers ! private DataTable getTableOfSelectedTickers_givenMarketDays() ! { ! DataTable dataTable = ! QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedInEachMarketDay( ! this.marketDays , this.setOfTickersToBeSelected , this.firstQuoteDate , ! this.lastQuoteDate , this.maxNumOfReturnedTickers ); ! return dataTable; ! } ! private DataTable getTableOfSelectedTickers_givenMarketIndex() ! { ! if(this.marketIndex == "") ! throw new Exception("You first need to set TickerSelector's property <<MarketIndex>>!"); ! if(this.setOfTickersToBeSelected == null) ! return QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedInEachMarketDay( ! this.marketIndex, this.groupID, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers); ! else ! return QuantProject.Data.DataTables.TickerDataTable.GetTickersQuotedInEachMarketDay( ! this.marketIndex, this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, ! this.maxNumOfReturnedTickers); ! } ! public DataTable GetTableOfSelectedTickers() ! { ! if ( this.marketDays != null ) ! // marketDays has been passed to the constructor ! return this.getTableOfSelectedTickers_givenMarketDays(); ! else ! // marketIndex has been passed to the constructor ! return this.getTableOfSelectedTickers_givenMarketIndex(); ! } ! #endregion GetTableOfSelectedTickers ! public void SelectAllTickers() ! { ! ; ! } ! } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:23:48
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23501/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: RunWalkForwardLag.cs Log Message: no message Index: RunWalkForwardLag.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/RunWalkForwardLag.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RunWalkForwardLag.cs 28 Oct 2007 18:48:48 -0000 1.11 --- RunWalkForwardLag.cs 19 Jan 2008 19:23:45 -0000 1.12 *************** *** 132,137 **** public static void WriteToTextLog( string message ) { ! Console.WriteLine( message ); ! Console.WriteLine( "" ); System.Diagnostics.Debug.Listeners[0].WriteLine( message ); --- 132,137 ---- public static void WriteToTextLog( string message ) { ! // Console.WriteLine( message ); ! // Console.WriteLine( "" ); System.Diagnostics.Debug.Listeners[0].WriteLine( message ); |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:23:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23494/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: RunSimpleLag.cs Log Message: Minor changes, to do some debugging Index: RunSimpleLag.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/RunSimpleLag.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunSimpleLag.cs 8 Nov 2007 17:48:36 -0000 1.2 --- RunSimpleLag.cs 19 Jan 2008 19:23:42 -0000 1.3 *************** *** 71,75 **** public void Run() { ! // optimal driving positions // double[] drivingWeights = { 0.550560760218599 , -0.172289820708961 , -0.16220520521007 , 0.11494421386237 }; // string[] drivingTickers = { "^OEX" , "BDH" , "HHH" , "IIH" }; --- 71,75 ---- public void Run() { ! // 4 optimal driving positions // double[] drivingWeights = { 0.550560760218599 , -0.172289820708961 , -0.16220520521007 , 0.11494421386237 }; // string[] drivingTickers = { "^OEX" , "BDH" , "HHH" , "IIH" }; *************** *** 80,99 **** // Description "^DJT;-0.272826060576681--^OEX;0.304736475342285--BDH;-0.0953627582891244--EWJ;0.32707470579191--" string ! // two optimal driving positions ! double[] drivingWeights = { 0.550560760218599 , -0.172289820708961 }; ! string[] drivingTickers = { "^OEX" , "BDH" }; ! // three optimal driving positions // double[] drivingWeights = { 0.550560760218599 , -0.172289820708961 , -0.16220520521007 }; // string[] drivingTickers = { "^OEX" , "BDH" , "HHH" }; ! // two optimal driving with similar weights // double[] drivingWeights = { 0.304736475342285 , -0.0953627582891244 }; // string[] drivingTickers = { "^OEX" , "BDH" }; ! // single optimal driving // double[] drivingWeights = { 1 }; // string[] drivingTickers = { "IIH" }; ! --- 80,114 ---- // Description "^DJT;-0.272826060576681--^OEX;0.304736475342285--BDH;-0.0953627582891244--EWJ;0.32707470579191--" string ! // subset of 2 optimal driving positions ! // double[] drivingWeights = { 0.550560760218599 , -0.172289820708961 }; ! // string[] drivingTickers = { "^OEX" , "BDH" }; ! // subset of three optimal driving positions // double[] drivingWeights = { 0.550560760218599 , -0.172289820708961 , -0.16220520521007 }; // string[] drivingTickers = { "^OEX" , "BDH" , "HHH" }; ! // subseto of two optimal driving with similar weights // double[] drivingWeights = { 0.304736475342285 , -0.0953627582891244 }; // string[] drivingTickers = { "^OEX" , "BDH" }; ! // subset of single optimal driving from the 4 optimal driving // double[] drivingWeights = { 1 }; // string[] drivingTickers = { "IIH" }; ! ! ! ! // 2 optimal driving positions ! // double[] drivingWeights = { 0.74152744108066 , -0.25847255891934 }; ! // string[] drivingTickers = { "^NYA" , "^PSE" }; ! ! // subset of single driving positions out of 2 optimal driving ! double[] drivingWeights = { 1 }; ! string[] drivingTickers = { "^NYA" }; ! // double[] drivingWeights = { -1 }; ! // string[] drivingTickers = { "^PSE" }; ! ! // 2 optimal driving positions, but with weights slightly changed ! // double[] drivingWeights = { 0.7 , -0.3 }; ! // string[] drivingTickers = { "^NYA" , "^PSE" }; |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:23:00
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement/time In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23093/b4_Business/a2_Strategies/returnsManagement/time Modified Files: ReturnIntervals.cs Log Message: - The class is not abstract anymore - the property LastEndOfDayDateTime has been improved (an exception has been added) - A new constructor public ReturnIntervals( IIntervalsSelector intervalSelector) has been added. intervalSelector will be used to add new intervals progressively - derived classes should become IIntervalSelector(s) - the method public void AppendIntervalsButDontGoBeyondLastDate( EndOfDayDateTime lastDate ) has been added - the method public void AppendIntervalsToGoJustBeyond( EndOfDayDateTime lastDate ) has been added - the method public void AppendFirstInterval( EndOfDayDateTime firstDate ) has been added Index: ReturnIntervals.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement/time/ReturnIntervals.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ReturnIntervals.cs 30 Oct 2007 19:06:48 -0000 1.4 --- ReturnIntervals.cs 19 Jan 2008 19:22:57 -0000 1.5 *************** *** 25,28 **** --- 25,29 ---- using QuantProject.ADT.Histories; + using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; *************** *** 33,37 **** /// never begins before the (n)th interval ends /// </summary> ! public abstract class ReturnIntervals : CollectionBase { protected EndOfDayDateTime firstEndOfDayDateTime; --- 34,38 ---- /// never begins before the (n)th interval ends /// </summary> ! public class ReturnIntervals : CollectionBase { protected EndOfDayDateTime firstEndOfDayDateTime; *************** *** 41,46 **** private EndOfDayHistory bordersHistory; protected int intervalLength; ! public ReturnInterval this[ int index ] { get --- 42,49 ---- private EndOfDayHistory bordersHistory; protected int intervalLength; + + private IIntervalsSelector intervalsSelector; ! public ReturnInterval this[ int index ] { get *************** *** 61,64 **** --- 64,71 ---- get { + if ( this.Count == 0 ) + throw new Exception( "LastEndOfDayDateTime " + + "cannot be used when ReturnIntervals has " + + "no ReturnInterval added yet!" ); return this[ this.Count - 1 ].End; } *************** *** 134,137 **** --- 141,156 ---- } + /// <summary> + /// Use this constructor if you want to create an empty + /// collection of intervals. The object will then be populated + /// adding intervals by means of an IIntervalSelector + /// </summary> + /// <param name="intervalSelector">to be used for adding + /// intervals</param> + public ReturnIntervals( IIntervalsSelector intervalSelector) + { + this.intervalsSelector = intervalSelector; + } + protected virtual void setMarketDaysForBenchmark() { *************** *** 141,145 **** } ! protected abstract void setIntervals(); /// <summary> --- 160,168 ---- } ! protected virtual void setIntervals() ! { ! // TO DO remove this method and change ! // derived classes to become IIntervalSelector ! } /// <summary> *************** *** 215,218 **** --- 238,367 ---- this.List.Add( returnInterval ); } + + #region appendIntervalsButDontGoBeyondLastDate + private void appendIntervalsButDontGoBeyondLastDate_checkParameters( + EndOfDayDateTime firstDate , EndOfDayDateTime lastDate ) + { + if ( firstDate.CompareTo( lastDate ) >= 0 ) + throw new Exception( "lastDate must be greater than firstDate!" ); + if ( this.Count > 0 ) + // some interval has already been added + { + EndOfDayDateTime currentLastEndOfDayDateTime = + this[ this.Count - 1 ].End; + if ( firstDate.CompareTo( currentLastEndOfDayDateTime ) < 0 ) + throw new Exception( "firstDate cannot be smaller than " + + "the end of the last interval already in this collection!" ); + } + } + /// <summary> + /// Appends a list of intervals, starting from firstDate and + /// until the next one would go beyond lastDate. + /// This method can be invoked even if the ReturnIntervals object + /// is empty. + /// The firstDate has to be earlier than lastDate + /// </summary> + /// <param name="firstDate"></param> + /// <param name="lastDate"></param> + private void appendIntervalsButDontGoBeyondLastDate( EndOfDayDateTime firstDate , + EndOfDayDateTime lastDate ) + { + this.appendIntervalsButDontGoBeyondLastDate_checkParameters( + firstDate , lastDate ); + ReturnInterval nextInterval = + this.intervalsSelector.GetFirstInterval( firstDate ); + while ( nextInterval.End.CompareTo( lastDate ) <= 0 ) + { + this.Add( nextInterval ); + nextInterval = + this.intervalsSelector.GetNextInterval( this ); + } + } + #endregion appendIntervalsButDontGoBeyondLastDate + + #region AppendIntervalsButDontGoBeyondLastDate + private void appendIntervalsButDontGoBeyondLastDate_checkParameters( + EndOfDayDateTime lastDate ) + { + if ( this.Count == 0 ) + throw new Exception( + "ReturnIntervals.AppendIntervalsButDontGoBeyondLastDate( " + + "EndOfDayDateTime lastDate ) " + + "has been invoked but the current ReturnIntervals " + + "object is empty!" ); + if ( lastDate.IsLessThanOrEqualTo( this.LastEndOfDayDateTime ) ) + throw new Exception( + "ReturnIntervals.AppendIntervalsButDontGoBeyondLastDate( " + + "EndOfDayDateTime lastDate ) " + + "has been invoked but lastDate must be larger than the " + + "end of the last ReturnInterval already in this collection" ); + } + /// <summary> + /// Appends a list of intervals, + /// until the next one would go beyond lastDate. + /// This method can be invoked only if the ReturnIntervals object + /// is not empty. + /// The last added interval must end before lastDate + /// </summary> + /// <param name="lastDate"></param> + public void AppendIntervalsButDontGoBeyondLastDate( + EndOfDayDateTime lastDate ) + { + this.appendIntervalsButDontGoBeyondLastDate_checkParameters( + lastDate ); + EndOfDayDateTime firstDate = this.LastEndOfDayDateTime; + this.appendIntervalsButDontGoBeyondLastDate( firstDate , lastDate ); + } + #endregion AppendIntervalsButDontGoBeyondLastDate + + #region AppendIntervalsToGoJustBeyond + private void appendIntervalsToGoJustBeyondLastDate_checkParameters( + EndOfDayDateTime lastDate ) + { + if ( this.Count == 0 ) + throw new Exception( + "ReturnIntervals.AppendIntervalsToGoJustBeyond( EndOfDayDateTime lastDate ) " + + "has been invoked but the current ReturnIntervals " + + "object is empty!" ); + if ( lastDate.IsLessThan( this.LastEndOfDayDateTime ) ) + throw new Exception( + "ReturnIntervals.AppendIntervalsToGoJustBeyond( EndOfDayDateTime lastDate ) " + + "has been invoked but lastDate must be larger than or equal to " + + "the end of the last ReturnInterval already in the collection" ); + } + + /// <summary> + /// Appends a list of intervals, and stops as soon + /// as the last added interval exceeds lastDate. + /// This method can be invoked only if the ReturnIntervals object + /// is not empty. + /// The last added interval cannot end after lastDate + /// </summary> + /// <param name="lastDate"></param> + public void AppendIntervalsToGoJustBeyond( + EndOfDayDateTime lastDate ) + { + this.appendIntervalsToGoJustBeyondLastDate_checkParameters( + lastDate ); + if ( this.LastEndOfDayDateTime.IsLessThan( lastDate ) ) + // lastDate comes after the last interval already added + this.AppendIntervalsButDontGoBeyondLastDate( lastDate ); + ReturnInterval lastInterval = + this.intervalsSelector.GetNextInterval( this ); + this.Add( lastInterval ); + } + #endregion AppendIntervalsToGoJustBeyond + + /// <summary> + /// Appends the first interval (starting from firstDate) + /// </summary> + /// <param name="firstDate"></param> + public void AppendFirstInterval( + EndOfDayDateTime firstDate ) + { + ReturnInterval firstInterval = + this.intervalsSelector.GetFirstInterval( firstDate ); + this.Add( firstInterval ); + } } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:10:40
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement/time In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19882/b4_Business/a2_Strategies/returnsManagement/time Modified Files: ReturnInterval.cs Log Message: Now begin and end are duplicated. In the previous version, they may have moved after the interval was built. I believe that would have been bad. MILLO, PLEASE TEST YOUR SCRIPTS with this new version. Index: ReturnInterval.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement/time/ReturnInterval.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ReturnInterval.cs 16 Sep 2007 21:40:02 -0000 1.1 --- ReturnInterval.cs 19 Jan 2008 19:10:37 -0000 1.2 *************** *** 56,61 **** { this.checkParameters( begin , end ); ! this.begin = begin; ! this.end = end; } private void checkParameters( EndOfDayDateTime begin , --- 56,61 ---- { this.checkParameters( begin , end ); ! this.begin = begin.Copy(); ! this.end = end.Copy(); } private void checkParameters( EndOfDayDateTime begin , |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:08:09
|
Update of /cvsroot/quantproject/QuantProject/b91_QuantProject In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18960/b91_QuantProject Modified Files: Main.cs Log Message: Changed to use the FixedLengthTwoPhases strategy Index: Main.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b91_QuantProject/Main.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Main.cs 24 Jun 2007 21:27:16 -0000 1.17 --- Main.cs 19 Jan 2008 19:08:06 -0000 1.18 *************** *** 32,35 **** --- 32,37 ---- using QuantProject.Scripts.SimpleTesting; + using QuantProject.Scripts.WalkForwardTesting.FixedLengthTwoPhases; + using QuantProject.Scripts.WalkForwardTesting.LinearCombination; using QuantProject.Scripts.WalkForwardTesting.WalkForwardOneRank; using QuantProject.Scripts.WalkForwardTesting.WalkForwardLag; *************** *** 385,388 **** --- 387,394 ---- //new RunEfficientCTCPorfolio().Run(); //new RunEfficientPorfolio().Run(); + + // QuantProject.Scripts.WalkForwardTesting.FixedLengthTwoPhases.FixedLengthTwoPhasesMain + // myMain = + // new QuantProject.Scripts.WalkForwardTesting.FixedLengthTwoPhases.FixedLengthTwoPhasesMain().Run; Application.Run(new Principale()); //geneticOptimizerTest(); *************** *** 458,462 **** // {//call here your scripts //new RunWalkForwardOneRank().Run(); ! new WFLagMain().ShowDialog(); // new RunOneRank().Run(); --- 464,469 ---- // {//call here your scripts //new RunWalkForwardOneRank().Run(); ! // new WFLagMain().ShowDialog(); ! new FixedLengthTwoPhasesMain().Run(); // new RunOneRank().Run(); |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:07:09
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18476/b4_Business/a2_Strategies Modified Files: IEndOfDayStrategy.cs Log Message: The new delegate public delegate void NewLogItemEventHandler( Object sender , NewLogItemEventArgs eventArgs ); has been added (for the NewLogItem event, to be used by strategies) Index: IEndOfDayStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/IEndOfDayStrategy.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IEndOfDayStrategy.cs 2 Aug 2005 23:04:43 -0000 1.1 --- IEndOfDayStrategy.cs 19 Jan 2008 19:07:05 -0000 1.2 *************** *** 24,27 **** --- 24,28 ---- using QuantProject.Business.Financial.Accounting.Transactions; + using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Timing; *************** *** 29,32 **** --- 30,36 ---- namespace QuantProject.Business.Strategies { + public delegate void NewLogItemEventHandler( + Object sender , NewLogItemEventArgs eventArgs ); + /// <summary> /// Interface to be implemented by end of day strategies |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:03:08
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Histories In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16813/b1_ADT/Histories Modified Files: History.cs Log Message: - The property FirstDateTime has been included - The property LastDateTime has been included Index: History.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Histories/History.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** History.cs 26 Sep 2007 21:58:18 -0000 1.12 --- History.cs 19 Jan 2008 19:03:05 -0000 1.13 *************** *** 44,51 **** get { return this.Keys; } } public History() : base() { } ! public Object GetValue( DateTime dateTime ) { --- 44,81 ---- get { return this.Keys; } } + + /// <summary> + /// The first DateTime value in the TimeLine + /// </summary> + public DateTime FirstDateTime + { + get + { + if ( this.TimeLine.Count == 0 ) + throw new Exception( "This History collection is empty, " + + "thus FirstDateTime is meaningless!" ); + return (DateTime)(this.GetKey( 0 )); + } + } + + /// <summary> + /// The last DateTime value in the TimeLine + /// </summary> + public DateTime LastDateTime + { + get + { + if ( this.TimeLine.Count == 0 ) + throw new Exception( "This History collection is empty, " + + "thus LastDateTime is meaningless!" ); + int lastIndex = this.TimeLine.Count - 1; + return (DateTime)( this.GetKey( lastIndex ) ); + } + } + public History() : base() { } ! public Object GetValue( DateTime dateTime ) { |
|
From: Glauco S. <gla...@us...> - 2008-01-19 19:02:22
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16514/b4_Business/a05_Timing Modified Files: HistoricalEndOfDayTimer.cs Log Message: The method GetCurrentTime() has been improved (exception included now) Index: HistoricalEndOfDayTimer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/HistoricalEndOfDayTimer.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** HistoricalEndOfDayTimer.cs 4 Feb 2005 00:10:24 -0000 1.7 --- HistoricalEndOfDayTimer.cs 19 Jan 2008 19:02:18 -0000 1.8 *************** *** 110,113 **** --- 110,116 ---- public EndOfDayDateTime GetCurrentTime() { + if ( this.currentTime == null ) + throw new Exception( "Start() has not been invoked yet!" + + "GetCurrentTime() cannot be invoked before Start()" ); return this.currentTime; } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:59:26
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv15239/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: It has been improved the code to debug exceptions given by this.currentGeneration.Sort Now a full cycle through the generation (computing each fitness) can easily be done (thus, step by step debug is now allowed) Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** GeneticOptimizer.cs 21 Aug 2007 21:52:23 -0000 1.26 --- GeneticOptimizer.cs 19 Jan 2008 18:59:19 -0000 1.27 *************** *** 297,303 **** private void sortCurrentGenerationAndFireNewGenerationEvent() { ! // comment out the following line if you have an exception // in the Sort method and you want to break to the proper line ! // double fitness = ((Genome) this.currentGeneration[ 0 ]).Fitness; this.currentGeneration.Sort(this.genomeComparer); if(this.NewGeneration != null) --- 297,306 ---- private void sortCurrentGenerationAndFireNewGenerationEvent() { ! // comment out the following three lines if you have an exception // in the Sort method and you want to break to the proper line ! // double fitness; ! // for ( int i = 0 ; i < this.currentGeneration.Count ; i++ ) ! // fitness = ((Genome) this.currentGeneration[ i ]).Fitness; ! this.currentGeneration.Sort(this.genomeComparer); if(this.NewGeneration != null) |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:54:45
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13267/b1_ADT Modified Files: ExtendedDateTime.cs Log Message: The method public static DateTime Min( DateTime dateTime1 , DateTime dateTime2 ) has been added Index: ExtendedDateTime.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ExtendedDateTime.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExtendedDateTime.cs 22 Jul 2006 20:57:38 -0000 1.3 --- ExtendedDateTime.cs 19 Jan 2008 18:54:42 -0000 1.4 *************** *** 103,106 **** --- 103,119 ---- return this.DateTime.ToString() + " - " + this.BarComponent.ToString(); } + /// <summary> + /// Returns the earliest date + /// </summary> + /// <param name="dateTime1"></param> + /// <param name="dateTime2"></param> + /// <returns></returns> + public static DateTime Min( DateTime dateTime1 , DateTime dateTime2 ) + { + DateTime returnValue = dateTime1; + if ( dateTime2 < dateTime1 ) + returnValue = dateTime2; + return returnValue; + } // public static SortedList GetArray( SortedList sortedDateTimes ) // { |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:53:54
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12862/b4_Business/a05_Timing Modified Files: EndOfDayHistory.cs Log Message: - the property FirstEndOfDayDateTime has been added - the property LastEndOfDayDateTime has been improved (exception included) - the property History has been added Index: EndOfDayHistory.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/EndOfDayHistory.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayHistory.cs 16 Sep 2007 21:30:42 -0000 1.1 --- EndOfDayHistory.cs 19 Jan 2008 18:53:51 -0000 1.2 *************** *** 25,28 **** --- 25,29 ---- using System.Data; using QuantProject.ADT; + using QuantProject.ADT.Histories; using QuantProject.ADT.Statistics; *************** *** 36,43 **** public class EndOfDayHistory : AdvancedSortedList { - public EndOfDayDateTime LastEndOfDayDateTime - { - get { return (EndOfDayDateTime)this.GetKey( this.Count - 1 ); } - } /// <summary> /// Returns the ICollection of EndOfDayDateTimes on which the --- 37,40 ---- *************** *** 48,51 **** --- 45,113 ---- get { return this.Keys; } } + /// <summary> + /// The first EndOfDayDateTime value in the collection + /// </summary> + public EndOfDayDateTime FirstEndOfDayDateTime + { + get + { + if ( this.TimeLine.Count == 0 ) + throw new Exception( "This EndOfDayHistory collection is empty, " + + "thus FirstEndOfDayDateTime is meaningless!" ); + return (EndOfDayDateTime)(this.GetKey( 0 )); + } + } + /// <summary> + /// The last EndOfDayDateTime value in the collection + /// </summary> + public EndOfDayDateTime LastEndOfDayDateTime + { + get + { + if ( this.TimeLine.Count == 0 ) + throw new Exception( "This EndOfDayHistory collection is empty, " + + "thus LastEndOfDayDateTime is meaningless!" ); + int lastIndex = this.TimeLine.Count - 1; + return (EndOfDayDateTime)( this.GetKey( lastIndex ) ); + } + } + + #region History + private void addDateTimes( History history ) + { + DateTime currentDateTime = this.FirstEndOfDayDateTime.DateTime; + history.Add( currentDateTime , currentDateTime ); + foreach ( EndOfDayDateTime endOfDayDateTime + in this.Keys ) + if ( endOfDayDateTime.DateTime > currentDateTime ) + { + history.Add( endOfDayDateTime.DateTime , + endOfDayDateTime.DateTime ); + currentDateTime = endOfDayDateTime.DateTime; + } + } + private History getHistory() + { + History history = new History(); + if ( this.Count > 0 ) + this.addDateTimes( history ); + return history; + } + + + /// <summary> + /// Returns the collection of DateTime(s) for these EndOfDayDateTimes + /// </summary> + public History History + { + get + { + return this.getHistory(); + } + + + } + #endregion History + public EndOfDayHistory() : base() { |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:51:57
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12062/b4_Business/a05_Timing Modified Files: EndOfDayDateTime.cs Log Message: - the property Description has been added (useful for fast debugging in SharpDevelop) - the method public bool IsLessThan( EndOfDayDateTime dateTimeToCompareTo ) has been added - the method public bool IsLessThanOrEqualTo( EndOfDayDateTime dateTimeToCompareTo ) has been added - the method public bool IsEqualTo( EndOfDayDateTime dateTimeToCompareTo ) has been added - the method public EndOfDayDateTime GetNextMarketStatusSwitch() has been added Index: EndOfDayDateTime.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing/EndOfDayDateTime.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayDateTime.cs 30 Jan 2005 19:57:37 -0000 1.4 --- EndOfDayDateTime.cs 19 Jan 2008 18:51:53 -0000 1.5 *************** *** 46,49 **** --- 46,59 ---- set { endOfDaySpecificTime = value; } } + + public string Description + { + get + { + string description = this.dateTime.ToString() + " - " + + this.endOfDaySpecificTime.ToString(); + return description; + } + } public EndOfDayDateTime( DateTime dateTime , EndOfDaySpecificTime endOfDaySpecificTime ) *************** *** 94,97 **** --- 104,140 ---- } /// <summary> + /// True iif this object does not come before dateTimeToCompareTo + /// </summary> + /// <param name="dateTimeToCompareTo"></param> + /// <returns></returns> + public bool IsLessThan( EndOfDayDateTime dateTimeToCompareTo ) + { + bool isLessThan = + ( this.CompareTo( dateTimeToCompareTo ) < 0 ); + return isLessThan; + } + /// <summary> + /// True iif this object does not come after dateTimeToCompareTo + /// </summary> + /// <param name="dateTimeToCompareTo"></param> + /// <returns></returns> + public bool IsLessThanOrEqualTo( EndOfDayDateTime dateTimeToCompareTo ) + { + bool isLessThanOrEqual = + ( this.CompareTo( dateTimeToCompareTo ) <= 0 ); + return isLessThanOrEqual; + } + /// <summary> + /// True iif this object is equal to dateTimeToCompareTo + /// </summary> + /// <param name="dateTimeToCompareTo"></param> + /// <returns></returns> + public bool IsEqualTo( EndOfDayDateTime dateTimeToCompareTo ) + { + bool isEqualTo = + ( this.CompareTo( dateTimeToCompareTo ) == 0 ); + return isEqualTo; + } + /// <summary> /// Returns a deep copy of the current instance /// </summary> *************** *** 103,106 **** --- 146,178 ---- this.endOfDaySpecificTime ); } + /// <summary> + /// Returns either the next market close or the next market open, + /// whichever is the nearest (all days are considered as market + /// days, week-ends included) + /// We have a market status switch when the market opens and when + /// the market closes + /// </summary> + /// <returns></returns> + public EndOfDayDateTime GetNextMarketStatusSwitch() + { + EndOfDayDateTime nextMarketStatusSwitch; + if ( this.EndOfDaySpecificTime < EndOfDaySpecificTime.MarketOpen ) + nextMarketStatusSwitch = new EndOfDayDateTime( + this.DateTime , EndOfDaySpecificTime.MarketOpen ); + else + { + // this.EndOfDaySpecificTime >= EndOfDaySpecificTime.MarketOpen + if ( this.EndOfDaySpecificTime < EndOfDaySpecificTime.MarketClose ) + // ( this.EndOfDaySpecificTime >= EndOfDaySpecificTime.MarketOpen ) + // AND ( this.EndOfDaySpecificTime < EndOfDaySpecificTime.MarketClose ) + nextMarketStatusSwitch = new EndOfDayDateTime( + this.DateTime , EndOfDaySpecificTime.MarketClose ); + else + // ( this.EndOfDaySpecificTime >= EndOfDaySpecificTime.MarketClose ) + nextMarketStatusSwitch = new EndOfDayDateTime( + this.DateTime.AddDays( 1 ) , EndOfDaySpecificTime.MarketOpen ); + } + return nextMarketStatusSwitch; + } #region MoveNext private EndOfDaySpecificTime getNextSpecificTime( ) |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:46:31
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9856 Modified Files: Scripts_SD.csproj Log Message: WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesLogItem.cs has been added WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesMain.cs has been added WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesStrategy.cs has been added WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\FixedLengthTwoPhasesFitnessEvaluator.cs has been added WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\Genetic\FixedLengthTwoPhasesGeneticChooser.cs has been added WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\Genetic\FixedLengthTwoPhasesGenomeManager.cs has been added Index: Scripts_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts_SD.csproj,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Scripts_SD.csproj 14 Jan 2008 23:49:05 -0000 1.11 --- Scripts_SD.csproj 19 Jan 2008 18:46:27 -0000 1.12 *************** *** 66,69 **** --- 66,75 ---- <Compile Include="TickerSelectionTesting\RunEfficientCTCPortfolio.cs" /> <Compile Include="TickerSelectionTesting\RunEfficientCTOPortfolio.cs" /> + <Compile Include="WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesLogItem.cs" /> + <Compile Include="WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesMain.cs" /> + <Compile Include="WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesStrategy.cs" /> + <Compile Include="WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\FixedLengthTwoPhasesFitnessEvaluator.cs" /> + <Compile Include="WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\Genetic\FixedLengthTwoPhasesGeneticChooser.cs" /> + <Compile Include="WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\Genetic\FixedLengthTwoPhasesGenomeManager.cs" /> <Compile Include="WalkForwardTesting\MSFTwalkForward\TsMSFTwalkForward.cs" /> <Compile Include="WalkForwardTesting\WalkForwardLag\RunSimpleLag.cs" /> *************** *** 232,236 **** --- 238,246 ---- <Folder Include="EvaluatingOptimizationTechnique\" /> <Folder Include="EvaluatingOptimizationTechnique\EfficientPortfolio\" /> + <Folder Include="BackTesting" /> <Folder Include="TickerSelectionTesting\SimpleSelection\" /> + <Folder Include="WalkForwardTesting\FixedLengthTwoPhases" /> + <Folder Include="WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers" /> + <Folder Include="WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\Genetic" /> <Folder Include="WalkForwardTesting\WalkForwardLag\WeightedPositionsChoosers\BruteForce" /> <Folder Include="WalkForwardTesting\WalkForwardLag\WeightedPositionsChoosers\Decoding" /> |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:45:54
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9451 Modified Files: b7_Scripts.csproj Log Message: WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesLogItem.cs has been added WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesMain.cs has been added WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesStrategy.cs has been added WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\FixedLengthTwoPhasesFitnessEvaluator.cs has been added WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\Genetic\FixedLengthTwoPhasesGeneticChooser.cs has been added WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\Genetic\FixedLengthTwoPhasesGenomeManager.cs has been added Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.81 retrieving revision 1.82 diff -C2 -d -r1.81 -r1.82 *** b7_Scripts.csproj 14 Jan 2008 23:47:36 -0000 1.81 --- b7_Scripts.csproj 19 Jan 2008 18:45:50 -0000 1.82 *************** *** 212,215 **** --- 212,216 ---- BuildAction = "Compile" /> + <Folder RelPath = "BackTesting\" /> <File RelPath = "CallingReportsForRunScripts\ShowReportFromFile.cs" *************** *** 669,672 **** --- 670,703 ---- /> <File + RelPath = "WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesLogItem.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesMain.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesStrategy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\FixedLengthTwoPhasesFitnessEvaluator.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\Genetic\FixedLengthTwoPhasesGeneticChooser.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\FixedLengthTwoPhases\InSampleChoosers\Genetic\FixedLengthTwoPhasesGenomeManager.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\CloseToOpenDailyStrategy.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:43:56
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/InSampleChoosers/Genetic In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8397/InSampleChoosers/Genetic Added Files: FixedLengthTwoPhasesGenomeManager.cs Log Message: Genome manager for the fixed length two phases strategy --- NEW FILE: FixedLengthTwoPhasesGenomeManager.cs --- /* QuantProject - Quantitative Finance Library FixedLengthTwoPhasesGenomeManager.cs Copyright (C) 2007 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License 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 QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.ReturnsManagement; namespace QuantProject.Scripts.WalkForwardTesting.FixedLengthTwoPhases { /// <summary> /// Genome manager for the fixed length two phases strategy /// </summary> public class FixedLengthTwoPhasesGenomeManager : IGenomeManager { int numberOfPortfolioPositions; EligibleTickers eligibleTickers; ReturnsManager returnsManager; IDecoderForWeightedPositions decoderForWeightedPositions; FixedLengthTwoPhasesFitnessEvaluator fitnessEvaluator; int seedForRandomGenerator; public FixedLengthTwoPhasesGenomeManager( int numberOfPortfolioPositions , EligibleTickers eligibleTickers , ReturnsManager returnsManager , IDecoderForWeightedPositions decoderForWeightedPositions , FixedLengthTwoPhasesFitnessEvaluator fitnessEvaluator , int seedForRandomGenerator ) { this.numberOfPortfolioPositions = numberOfPortfolioPositions; this.eligibleTickers = eligibleTickers; this.returnsManager = returnsManager; this.decoderForWeightedPositions = decoderForWeightedPositions; this.fitnessEvaluator = fitnessEvaluator; this.seedForRandomGenerator = seedForRandomGenerator; } public int GenomeSize { get { return ( this.numberOfPortfolioPositions ); } } public int GetMaxValueForGenes( int genePosition ) { return this.eligibleTickers.Count - 1; } public int GetMinValueForGenes( int genePosition ) { int minValueForGene = -this.eligibleTickers.Count; return minValueForGene; } public int GetNewGeneValue( Genome genome , int genePosition ) { int minGeneValue = this.GetMinValueForGenes( genePosition ); int maxGeneValue = this.GetMaxValueForGenes( genePosition ); int returnValue = GenomeManagement.RandomGenerator.Next( minGeneValue , maxGeneValue + 1); return returnValue; } public object Decode( Genome genome ) { return this.decoderForWeightedPositions.Decode( genome.Genes() , this.eligibleTickers , this.returnsManager ); } public double GetFitnessValue( Genome genome ) { object meaning = this.Decode( genome ); double fitnessValue = this.fitnessEvaluator.GetFitnessValue( meaning , this.returnsManager ); return fitnessValue; } public Genome[] GetChilds( Genome parent1 , Genome parent2 ) { return GenomeManagement.AlternateFixedCrossover(parent1, parent2); } public void Mutate( Genome genome ) { // int newValueForGene = GenomeManagement.RandomGenerator.Next( // genome.MinValueForGenes , // genome.MaxValueForGenes + 1 ); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next( genome.Size ); int newValueForGene = this.GetNewGeneValue( genome , genePositionToBeMutated ); GenomeManagement.MutateOneGene( genome , genePositionToBeMutated , newValueForGene ); } } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:41:08
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/InSampleChoosers/Genetic In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6825/InSampleChoosers/Genetic Added Files: FixedLengthTwoPhasesGeneticChooser.cs Log Message: In sample analyzer for the walk forward fixed length two phases strategy --- NEW FILE: FixedLengthTwoPhasesGeneticChooser.cs --- /* QuantProject - Quantitative Finance Library FixedLengthTwoPhasesGeneticChooser.cs Copyright (C) 2007 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License 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 QuantProject.ADT; using QuantProject.ADT.Messaging; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Timing; namespace QuantProject.Scripts.WalkForwardTesting.FixedLengthTwoPhases { /// <summary> /// In sample analyzer for the walk forward fixed length two phases strategy /// </summary> public class FixedLengthTwoPhasesGeneticChooser : IInSampleChooser { public event NewProgressEventHandler NewProgress; public event NewMessageHandler NewMessage; private int numberOfPortfolioPositions; private int inSampleDays; private Benchmark benchmark; private IDecoderForWeightedPositions decoderForWeightedPositions; private FixedLengthTwoPhasesFitnessEvaluator fixedLengthTwoPhasesFitnessEvaluator; private IHistoricalQuoteProvider historicalQuoteProvider; private double crossoverRate; private double mutationRate; private double elitismRate; private int populationSizeForGeneticOptimizer; private int generationNumberForGeneticOptimizer; private int seedForRandomGenerator; private GeneticOptimizer geneticOptimizer; public string Description { get { string description = "geneticOTCCTO"; return description; } } public FixedLengthTwoPhasesGeneticChooser( int numberOfPortfolioPositions , int inSampleDays , Benchmark benchmark , IDecoderForWeightedPositions decoderForWeightedPositions , FixedLengthTwoPhasesFitnessEvaluator fixedLengthTwoPhasesFitnessEvaluator , IHistoricalQuoteProvider historicalQuoteProvider , double crossoverRate , double mutationRate , double elitismRate , int populationSizeForGeneticOptimizer , int generationNumberForGeneticOptimizer , int seedForRandomGenerator ) { this.numberOfPortfolioPositions = numberOfPortfolioPositions; this.inSampleDays = inSampleDays; this.benchmark = benchmark; this.decoderForWeightedPositions = decoderForWeightedPositions; this.fixedLengthTwoPhasesFitnessEvaluator = fixedLengthTwoPhasesFitnessEvaluator; this.historicalQuoteProvider = historicalQuoteProvider; this.crossoverRate = crossoverRate; this.mutationRate = mutationRate; this.elitismRate = elitismRate; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.seedForRandomGenerator = seedForRandomGenerator; } #region AnalyzeInSample private void analyzeInSample_checkParameters( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { if ( eligibleTickers.Count < this.numberOfPortfolioPositions ) throw new Exception( "Eligilbe tickers for driving positions contains " + "only " + eligibleTickers.Count + " elements, while NumberOfDrivingPositions is " + this.numberOfPortfolioPositions ); } #region newGenerationEventHandler private void sendNewProgress( NewGenerationEventArgs e ) { if ( this.NewProgress != null ) this.NewProgress( this , new NewProgressEventArgs( e.GenerationCounter , e.GenerationNumber ) ); } #region sendNewMessage private string getProgressMessage( int generationCounter , int generationNumber ) { string progressMessage = generationCounter.ToString() + " / " + generationNumber.ToString() + " - " + DateTime.Now.ToString(); return progressMessage; } private void sendNewMessage( NewGenerationEventArgs e ) { string message = this.getProgressMessage( e.GenerationCounter , e.GenerationNumber ); NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if( this.NewMessage != null ) this.NewMessage( this , newMessageEventArgs ); } #endregion sendNewMessage private void newGenerationEventHandler( object sender , NewGenerationEventArgs e ) { // // comment out this line if no debug is done // WFLagGenerationDebugger wFLagGenerationDebugger = // new WFLagGenerationDebugger( // e.Generation , // this.timeWhenChosePositionsIsRequested.DateTime , // this.NumberDaysForInSampleOptimization , // this.benchmark ); // wFLagGenerationDebugger.Debug(); this.sendNewProgress( e ); this.sendNewMessage( e ); } #endregion newGenerationEventHandler private void checkIfBestGenomeIsDecodable( IGenomeManager genomeManager , Genome genome ) { object genomeMeaning = genomeManager.Decode( genome ); if ( !(genomeMeaning is WeightedPositions) ) throw new Exception( "The genome is not a WeightedPositions. " + "It should happen only if the genome is undecodable. This " + "should never happen for the best genome." ); } private WeightedPositions getBestWeightedPositionsInSample( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { FixedLengthTwoPhasesGenomeManager genomeManager = new FixedLengthTwoPhasesGenomeManager( this.numberOfPortfolioPositions , eligibleTickers , returnsManager , this.decoderForWeightedPositions , this.fixedLengthTwoPhasesFitnessEvaluator , QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator ); this.geneticOptimizer = new GeneticOptimizer( this.crossoverRate , this.mutationRate , this.elitismRate , this.populationSizeForGeneticOptimizer , this.generationNumberForGeneticOptimizer , genomeManager , this.seedForRandomGenerator ); this.geneticOptimizer.NewGeneration += new NewGenerationEventHandler( this.newGenerationEventHandler ); this.geneticOptimizer.Run( false ); // this.generation = geneticOptimizer.BestGenome.Generation; this.checkIfBestGenomeIsDecodable( genomeManager , this.geneticOptimizer.BestGenome ); WeightedPositions bestWeightedPositionsInSample = (WeightedPositions)genomeManager.Decode( this.geneticOptimizer.BestGenome ); return bestWeightedPositionsInSample; } /// <summary> /// Returns the best WeightedPositions with respect to the in sample data /// </summary> /// <param name="eligibleTickers"></param> /// <param name="currentOutOfSampleEndOfDayDateTime"></param> /// <returns></returns> public object AnalyzeInSample( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { this.analyzeInSample_checkParameters( eligibleTickers , returnsManager ); WeightedPositions bestWeightedPositionsInSample = this.getBestWeightedPositionsInSample( eligibleTickers , returnsManager ); return bestWeightedPositionsInSample; } #endregion AnalyzeInSample } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:38:38
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv5222/InSampleChoosers Added Files: FixedLengthTwoPhasesFitnessEvaluator.cs Log Message: FixedLengthTwoPhases strategy with in sample optimizations --- NEW FILE: FixedLengthTwoPhasesFitnessEvaluator.cs --- /* QuantProject - Quantitative Finance Library FixedLengthTwoPhasesFitnessEvaluator.cs Copyright (C) 2007 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License 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 QuantProject.Business.Strategies; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.ReturnsManagement; namespace QuantProject.Scripts.WalkForwardTesting.FixedLengthTwoPhases { /// <summary> /// Evaluates (in sample) the fitness for a given WeightedPositions /// </summary> public class FixedLengthTwoPhasesFitnessEvaluator { private IEquityEvaluator equityEvaluator; public FixedLengthTwoPhasesFitnessEvaluator( IEquityEvaluator equityEvaluator ) { this.equityEvaluator = equityEvaluator; } #region GetFitnessValue /// <summary> /// This private method is written in compact mode, in order /// to gain efficiency (it would have been more readable if /// we used a nested method call in it, but it would have /// been much slower) /// </summary> /// <param name="weightedPositionsReturns"></param> /// <returns></returns> private float[] getFitnessValue_getStrategyReturns( float[] weightedPositionsReturns ) { float[] strategyReturns = new float[ weightedPositionsReturns.Length ]; for ( int i = 0 ; i < weightedPositionsReturns.Length ; i++ ) { // this for content would be more readable if a method call was used, // but it would have dramatically slowed down the script if ( i % 2 == 0 ) // the i-th return refers to the first phase, thus it is // a long phase strategyReturns[ i ] = weightedPositionsReturns[ i ]; else // the i-th return refers to the first phase, thus it is // a long phase strategyReturns[ i ] = -weightedPositionsReturns[ i ]; } return strategyReturns; } private double getFitnessValue( WeightedPositions weightedPositions , ReturnsManager returnsManager ) { float[] weightedPositionsReturns = weightedPositions.GetReturns( returnsManager ); float[] strategyReturns = this.getFitnessValue_getStrategyReturns( weightedPositionsReturns ); float fitnessValue = this.equityEvaluator.GetReturnsEvaluation( strategyReturns ); return fitnessValue; } public double GetFitnessValue( object meaning , ReturnsManager returnsManager ) { double fitnessValue; if ( meaning is WeightedPositions ) { // for the current optimization's candidate, // all positions's tickers are distinct WeightedPositions weightedPositions = (WeightedPositions)meaning; fitnessValue = this.getFitnessValue( weightedPositions , returnsManager ); } else { // the current optimization's candidate contains // two genes that decode to the same tickers fitnessValue = -0.4; } return fitnessValue; } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 18:37:18
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/FixedLengthTwoPhases In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv4805 Added Files: FixedLengthTwoPhasesStrategy.cs Log Message: FixedLengthTwoPhases strategy with in sample optimizations --- NEW FILE: FixedLengthTwoPhasesStrategy.cs --- /* QuantProject - Quantitative Finance Library FixedLengthTwoPhasesStrategy.cs Copyright (C) 2007 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License 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; using QuantProject.ADT.Messaging; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; using QuantProject.Presentation; namespace QuantProject.Scripts.WalkForwardTesting.FixedLengthTwoPhases { /// <summary> /// FixedLengthTwoPhases strategy with in sample optimizations /// </summary> public class FixedLengthTwoPhasesStrategy : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; public event NewMessageHandler NewMessage; private int numberOfPortfolioPositions; private int numDaysBeetweenEachOtpimization; private int numDaysForInSampleOptimization; private Benchmark benchmark; private IIntervalsSelector intervalsSelector; private IEligiblesSelector eligiblesSelector; private IInSampleChooser inSampleChooser; private DateTime lastOptimizationDateTime; private ReturnIntervals returnIntervals; private IHistoricalQuoteProvider historicalQuoteProvider; private Account account; // private bool arePositionsToBeClosed; // private bool arePositionsToBeOpened; private WeightedPositions bestWeightedPositionsInSample; public Account Account { set { this.account = value; } } public bool StopBacktestIfMaxRunningHoursHasBeenReached { get { return this.isInsampleOptimizationNeeded(); } } public string DescriptionForLogFileName { get { string descriptionForLogFileName = "WFOTC_" + "oS_" + this.numDaysBeetweenEachOtpimization + "_" + this.inSampleChooser.Description; return descriptionForLogFileName; } } public FixedLengthTwoPhasesStrategy( int numberOfPortfolioPositions , int numDaysBeetweenEachOtpimization , int numDaysForInSampleOptimization , Benchmark benchmark , IIntervalsSelector intervalsSelector , IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , IHistoricalQuoteProvider historicalQuoteProvider ) { this.numberOfPortfolioPositions = numberOfPortfolioPositions; this.numDaysBeetweenEachOtpimization = numDaysBeetweenEachOtpimization; this.numDaysForInSampleOptimization = numDaysForInSampleOptimization; this.benchmark = benchmark; this.intervalsSelector = intervalsSelector; this.eligiblesSelector = eligiblesSelector; this.inSampleChooser = inSampleChooser; this.historicalQuoteProvider = historicalQuoteProvider; this.returnIntervals = new ReturnIntervals( this.intervalsSelector ); // this.arePositionsToBeClosed = false; // this.arePositionsToBeOpened = false; } #region MarketOpenEventHandler private bool marketOpenEventHandler_arePositionsToBeClosed() { bool arePositionsToBeClosed = ( ( this.account.Portfolio.Count > 0 ) && ( this.now().IsEqualTo( this.lastIntervalAppended().Begin ) ) ); return arePositionsToBeClosed; } #region marketOpenEventHandler_arePositionsToBeOpened private bool lastAppendedIntervalIsALongPeriod() { bool isALongPeriod = ( ( this.returnIntervals.Count % 2 ) == 1 ); return isALongPeriod; } private bool currentTimeBeginsALongPeriod() { bool beginsTheLastInterval = ( this.now().IsEqualTo( this.lastIntervalAppended().Begin ) ); bool lastIntervalIsALongPeriod = this.lastAppendedIntervalIsALongPeriod(); return ( beginsTheLastInterval && lastIntervalIsALongPeriod ); } private bool marketOpenEventHandler_arePositionsToBeOpened() { bool arePositionsToBeOpened = ( ( this.bestWeightedPositionsInSample != null ) && ( this.currentTimeBeginsALongPeriod() ) ); return arePositionsToBeOpened; } #endregion marketOpenEventHandler_arePositionsToBeOpened public void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.updateReturnIntervals(); if ( this.marketOpenEventHandler_arePositionsToBeClosed() ) AccountManager.ClosePositions( this.account ); if ( this.marketOpenEventHandler_arePositionsToBeOpened() ) AccountManager.OpenPositions( this.bestWeightedPositionsInSample , this.account ); } #endregion MarketOpenEventHandler public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } #region MarketCloseEventHandler private bool marketCloseEventHandler_arePositionsToBeClosed() { return marketOpenEventHandler_arePositionsToBeClosed(); } private bool marketCloseEventHandler_arePositionsToBeOpened() { // this strategy goes long only return false; } public void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.updateReturnIntervals(); if ( this.marketCloseEventHandler_arePositionsToBeClosed() ) AccountManager.ClosePositions( this.account ); if ( this.marketCloseEventHandler_arePositionsToBeOpened() ) { this.bestWeightedPositionsInSample.Reverse(); AccountManager.OpenPositions( this.bestWeightedPositionsInSample , this.account ); this.bestWeightedPositionsInSample.Reverse(); } } #endregion MarketCloseEventHandler #region OneHourAfterMarketCloseEventHandler private bool optimalWeightedPositionsAreToBeUpdated() { TimeSpan timeSpanSinceLastOptimization = this.now().DateTime - this.lastOptimizationDateTime; bool areToBeUpdated = ( timeSpanSinceLastOptimization.Days >= this.numDaysBeetweenEachOtpimization ); return areToBeUpdated; } #region getInSampleReturnIntervals private EndOfDayDateTime getInSampleReturnIntervals_getFirstDate() { DateTime firstDateTime = this.now().DateTime.AddDays( -this.numDaysForInSampleOptimization ); EndOfDayDateTime firstDate = new EndOfDayDateTime( firstDateTime , EndOfDaySpecificTime.MarketOpen ); return firstDate; } private ReturnIntervals getInSampleReturnIntervals() { EndOfDayDateTime firstDate = this.getInSampleReturnIntervals_getFirstDate(); EndOfDayDateTime lastDate = new EndOfDayDateTime( this.now().DateTime , EndOfDaySpecificTime.MarketClose ); ReturnIntervals inSampleReturnIntervals = new ReturnIntervals( this.intervalsSelector ); inSampleReturnIntervals.AppendFirstInterval( firstDate ); if ( inSampleReturnIntervals.LastEndOfDayDateTime.IsLessThan( lastDate ) ) inSampleReturnIntervals.AppendIntervalsButDontGoBeyondLastDate( lastDate ); return inSampleReturnIntervals; } #endregion getInSampleReturnIntervals private void notifyMessage( EligibleTickers eligibleTickers ) { string message = "Number of Eligible tickers: " + eligibleTickers.Count; NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if ( this.NewMessage != null ) this.NewMessage( this , newMessageEventArgs ); } #region logOptimizationInfo private void outputMessage( string message ) { MessageManager.DisplayMessage( message , "FixedLengthUpDown.Txt" ); } private FixedLengthTwoPhasesLogItem getLogItem( EligibleTickers eligibleTickers ) { FixedLengthTwoPhasesLogItem logItem = new FixedLengthTwoPhasesLogItem( this.now() ); logItem.BestWeightedPositionsInSample = this.bestWeightedPositionsInSample; logItem.NumberOfEligibleTickers = eligibleTickers.Count; return logItem; } private void raiseNewLogItem( EligibleTickers eligibleTickers ) { FixedLengthTwoPhasesLogItem logItem = this.getLogItem( eligibleTickers ); NewLogItemEventArgs newLogItemEventArgs = new NewLogItemEventArgs( logItem ); this.NewLogItem( this , newLogItemEventArgs ); } private void logOptimizationInfo( EligibleTickers eligibleTickers ) { this.raiseNewLogItem( eligibleTickers ); } #endregion logOptimizationInfo private void updateOptimalWeightedPositions_actually() { ReturnIntervals inSampleReturnIntervals = this.getInSampleReturnIntervals(); EligibleTickers eligibleTickers = this.eligiblesSelector.GetEligibleTickers( inSampleReturnIntervals.BordersHistory ); ReturnsManager returnsManager = new ReturnsManager( inSampleReturnIntervals , this.historicalQuoteProvider ); this.bestWeightedPositionsInSample = (WeightedPositions)this.inSampleChooser.AnalyzeInSample( eligibleTickers , returnsManager ); this.notifyMessage( eligibleTickers ); this.logOptimizationInfo( eligibleTickers ); } private void updateOptimalWeightedPositions() { this.updateOptimalWeightedPositions_actually(); this.lastOptimizationDateTime = this.now().DateTime; FixedLengthTwoPhasesLogItem logItem = 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( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.optimalWeightedPositionsAreToBeUpdated() ) this.updateOptimalWeightedPositions(); } #endregion OneHourAfterMarketCloseEventHandler public bool isInsampleOptimizationNeeded() { DateTime dateTimeForNextOptimization = this.lastOptimizationDateTime.AddDays( this.numDaysBeetweenEachOtpimization ); bool returnValue = ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ( this.now().DateTime >= dateTimeForNextOptimization ) ); return returnValue; } private void updateReturnIntervals() { EndOfDayDateTime currentEndOfDayDateTime = this.account.EndOfDayTimer.GetCurrentTime(); if ( this.returnIntervals.Count == 0 ) // no interval has been added yet this.returnIntervals.AppendFirstInterval( currentEndOfDayDateTime ); else // at least one interval has already been added if ( this.returnIntervals.LastEndOfDayDateTime.IsLessThanOrEqualTo( currentEndOfDayDateTime ) ) this.returnIntervals.AppendIntervalsToGoJustBeyond( currentEndOfDayDateTime ); } private EndOfDayDateTime now() { return this.account.EndOfDayTimer.GetCurrentTime(); } private ReturnInterval lastIntervalAppended() { ReturnInterval lastInterval = this.returnIntervals[ this.returnIntervals.Count - 1 ]; return lastInterval; } } } |