quantproject-developers Mailing List for QuantProject (Page 62)
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-19 17:48:23
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16727/b4_Business/a2_Strategies/Logging Added Files: NewLogItemEventArgs.cs Log Message: EventArgs when a new back test log item is found --- NEW FILE: NewLogItemEventArgs.cs --- /* QuantProject - Quantitative Finance Library NewLogItemEventArgs.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; namespace QuantProject.Business.Strategies.Logging { /// <summary> /// EventArgs when a new back test log item is found /// </summary> public class NewLogItemEventArgs { private LogItem logItem; public LogItem LogItem { get { return this.logItem; } } public NewLogItemEventArgs( LogItem logItem ) { this.logItem = logItem; } } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:46:43
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv15929/b4_Business/a2_Strategies/Logging Added Files: LogItem.cs Log Message: Single information (about a backtest) to be logged --- NEW FILE: LogItem.cs --- /* QuantProject - Quantitative Finance Library LogItem.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.Timing; namespace QuantProject.Business.Strategies.Logging { /// <summary> /// Single information (about a backtest) to be logged /// </summary> public abstract class LogItem { protected DateTime creationTime; protected EndOfDayDateTime endOfDayDateTime; public LogItem( EndOfDayDateTime endOfDayDateTime ) { this.creationTime = DateTime.Now; this.endOfDayDateTime = endOfDayDateTime; } /// <summary> /// Since LogItem(s) are usually used to store in sample /// optimization results, this method is used to run a script /// to show the optimization result. More generally, this /// method is used to show some information about the LogItem /// </summary> public abstract void Run(); } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:45:12
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv15362/b4_Business/a2_Strategies/Logging Added Files: BackTestLog.cs Log Message: Useful information to be saved for a back test --- NEW FILE: BackTestLog.cs --- /* QuantProject - Quantitative Finance Library BackTestLog.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.Financial.Accounting.Transactions; namespace QuantProject.Business.Strategies.Logging { /// <summary> /// Useful information to be saved for a back test /// </summary> [Serializable] public class BackTestLog : System.Collections.CollectionBase { private TransactionHistory transactionHistory; private string backTestId; private DateTime firstDate; private DateTime lastDate; private Benchmark benchmark; public TransactionHistory TransactionHistory { get { return this.transactionHistory; } set { this.transactionHistory = value; } } public BackTestLog( string backTestId , DateTime firstDate , DateTime lastDate , Benchmark benchmark ) { this.backTestId = backTestId; this.firstDate = firstDate; this.lastDate = lastDate; this.benchmark = benchmark; } public LogItem this[ int index ] { get { return( (LogItem) this.List[ index ] ); } set { this.List[ index ] = value; } } public void Add( LogItem logItem ) { this.List.Add( logItem ); } } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:44:37
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv15092/Logging Log Message: Directory /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Logging added to the repository |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:43:07
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv14427/b4_Business/a2_Strategies/Eligibles Added Files: MostLiquidAndLessVolatile.cs Log Message: Selects the most liquid and less volatile instruments, within the given group --- NEW FILE: MostLiquidAndLessVolatile.cs --- /* QuantProject - Quantitative Finance Library MostLiquidAndLessVolatile.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.Strategies.ReturnsManagement.Time; using QuantProject.Business.Timing; using QuantProject.Data.Selectors; namespace QuantProject.Business.Strategies.Eligibles { /// <summary> /// Selects the most liquid and less volatile instruments, /// within the given group /// </summary> public class MostLiquidAndLessVolatile : IEligiblesSelector { public event NewMessageHandler NewMessage; private string tickersGroupID; private int maxNumberOfEligibleTickersToBeChosen; /// <summary> /// Selects the most liquid and less volatile within the given /// group /// </summary> /// <param name="groupID"></param> public MostLiquidAndLessVolatile( string tickersGroupID , int maxNumberOfEligibleTickersToBeChosen ) { this.tickersGroupID = tickersGroupID; this.maxNumberOfEligibleTickersToBeChosen = maxNumberOfEligibleTickersToBeChosen; // this.firstDateTime = DateTime.MinValue; // this.lastDateTime = DateTime.MinValue; // this.maxNumberOfEligibleTickersToBeChosen = int.MinValue; // this.benchmark = ""; } // #region SetParameters // private void setParameters_checkParameters( string tickerGroupID , // DateTime firstDateTime , DateTime lastDateTime , // int maxNumberOfEligibleTickersToBeChosen , string benchmark ) // { // if ( firstDateTime >= lastDateTime ) // throw new Exception( "lastDateTime needs to be larger than " + // "firstDateTime" ); // if ( maxNumberOfEligibleTickersToBeChosen <= 0 ) // throw new Exception( "maxNumberOfEligibleTickersToBeChosen needs " + // "to be larger than zero" ); // } // /// <summary> // /// Sets the parameters to be used by the selection // /// </summary> // /// <param name="tickerGroupID">groups in which tickers are to be searched</param> // /// <param name="firstDateTime">begin of the interval</param> // /// <param name="lastDateTime">end of the interval</param> // /// <param name="maxNumberOfEligibleTickersToBeChosen">if more tickers are found // /// the first maxNumberOfEligibleTickersToBeChosen are returned</param> // /// <param name="benchmark">returned tickers must be quoted in every // /// day when the benchmark is quoted</param> // public void SetParameters( string tickerGroupID , // DateTime firstDateTime , DateTime lastDateTime , // int maxNumberOfEligibleTickersToBeChosen , string benchmark ) // { // this.setParameters_checkParameters( tickerGroupID , // firstDateTime , lastDateTime , // maxNumberOfEligibleTickersToBeChosen , benchmark ); // this.tickerGroupID = tickerGroupID; // this.firstDateTime = firstDateTime; // this.lastDateTime = lastDateTime; // this.maxNumberOfEligibleTickersToBeChosen = // maxNumberOfEligibleTickersToBeChosen; // this.benchmark = benchmark; // } // #endregion SetParameters #region GetEligibleTickers // private void checkIfAllParametersHaveBeenSet() // { // if ( ( this.tickerGroupID == null ) || // ( this.firstDateTime == DateTime.MinValue ) || // ( this.lastDateTime == DateTime.MinValue ) || // ( this.maxNumberOfEligibleTickersToBeChosen == int.MinValue ) || // ( this.benchmark == "" ) ) // throw new Exception( "GetEligbileTickers cannot be called before " + // "having called SetParameters" ); // } private EligibleTickers getEligibleTickers_actually( EndOfDayHistory endOfDayHistory ) { // DateTime dateTime = this.endOfDayTimer.GetCurrentTime().DateTime; // SelectorByGroup selectorByGroup = // new SelectorByGroup( this.tickerGroupID , dateTime ); // DataTable groupTickers = selectorByGroup.GetTableOfSelectedTickers(); SelectorByLiquidity mostLiquid = new SelectorByLiquidity( this.tickersGroupID , true , endOfDayHistory.FirstEndOfDayDateTime.DateTime , endOfDayHistory.LastEndOfDayDateTime.DateTime , 0 , this.maxNumberOfEligibleTickersToBeChosen ); DataTable groupTickers = mostLiquid.GetTableOfSelectedTickers(); // SelectorByLiquidity mostLiquid = // new SelectorByLiquidity("Test", false , dateTime.AddDays( - this.numDaysToComputeLiquidity ) , dateTime , // this.numberEligibleTickersToBeChosen ); // DataTable mostLiquidTickers = // mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedInEachMarketDay = new SelectorByQuotationAtEachMarketDay( groupTickers , false , endOfDayHistory.History , maxNumberOfEligibleTickersToBeChosen ); DataTable dtEligibleTickers = quotedInEachMarketDay.GetTableOfSelectedTickers(); EligibleTickers eligibleTickers = new EligibleTickers( dtEligibleTickers ); return eligibleTickers; } private void getEligibleTickers_sendNewMessage( EligibleTickers eligibleTickers ) { string message = "Number of Eligible tickers: " + eligibleTickers.Count; NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if(this.NewMessage != null) this.NewMessage( this , newMessageEventArgs ); } /// <summary> /// Returns the eligible tickers /// </summary> /// <returns></returns> public EligibleTickers GetEligibleTickers( EndOfDayHistory endOfDayHistory ) { EligibleTickers eligibleTickers = this.getEligibleTickers_actually( endOfDayHistory ); this.getEligibleTickers_sendNewMessage( eligibleTickers ); return eligibleTickers; } #endregion GetEligibleTickers } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:41:14
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13865/b4_Business/a2_Strategies/Eligibles Added Files: IEligiblesSelector.cs Log Message: Interface for classes that narrow down the number of tickers on which the in sample optimization will be performed --- NEW FILE: IEligiblesSelector.cs --- /* QuantProject - Quantitative Finance Library IEligiblesSelector.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.Timing; namespace QuantProject.Business.Strategies.Eligibles { /// <summary> /// Interface for classes that narrow down the number of tickers on which /// the in sample optimization will be performed /// </summary> public interface IEligiblesSelector : IMessageSender { /// <summary> /// Returns a set of eligible tickers. A ReturnIntervals object is /// given as a parameter: it may be that, for efficiency, it will /// not be used by the implementation /// </summary> /// <param name="endOfDayHistory">usually, eligible /// tickers require to be traded on specific /// market days, thus this parameter /// is given</param> /// <returns></returns> EligibleTickers GetEligibleTickers( EndOfDayHistory endOfDayHistory ); } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:40:36
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13445/b4_Business/a2_Strategies/Eligibles Added Files: EligibleTickers.cs Log Message: Strongly typed collection of tickers --- NEW FILE: EligibleTickers.cs --- /* QuantProject - Quantitative Finance Library EligibleTickers.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; namespace QuantProject.Business.Strategies.Eligibles { /// <summary> /// Strongly typed collection of tickers /// </summary> public class EligibleTickers : System.Collections.CollectionBase { /// <summary> /// /// </summary> /// <param name="dtTickers">DataTable in the form returned by /// a ticker selector</param> public EligibleTickers( DataTable dtTickers ) { this.addTickers( dtTickers ); } #region addTickers private void checkParameter( DataRow dataRow ) { if ( !( dataRow[ 0 ] is string ) ) throw new Exception( "The datatable of eligible tickers is " + "expected to have a single element in each " + "DataRow and that element should be a string" ); } private void addTicker_actually( string ticker ) { this.List.Add( ticker ); } private void addTicker( DataRow dataRow ) { this.checkParameter( dataRow ); this.addTicker_actually( (string)dataRow[ 0 ] ); } private void addTickers( DataTable dtTickers ) { foreach ( DataRow dataRow in dtTickers.Rows ) this.addTicker( dataRow ); } #endregion addTickers public string this[ int index ] { get { return( (string) this.List[ index ] ); } set { // if ( !(value is string) ) // throw new Exception( "You are trying to add " + // "a ticker that is not a string !!" ); this.List[ index ] = value; } } } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:39:43
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13006/Eligibles Log Message: Directory /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles added to the repository |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:38:18
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12216/b4_Business/a2_Strategies Added Files: IInSampleChooser.cs Log Message: Interface for classes that perform in sample researches (usually optimization) --- NEW FILE: IInSampleChooser.cs --- /* QuantProject - Quantitative Finance Library IInSampleChooser.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; using QuantProject.ADT.Messaging; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; namespace QuantProject.Business.Strategies { /// <summary> /// Interface for classes that perform in sample researches (usually optimization) /// </summary> public interface IInSampleChooser : IProgressNotifier , IMessageSender { /// <summary> /// Analizes in sample data and returns an object /// </summary> /// <param name="eligibleTickers">eligible tickers for the in sample analysis</param> /// <param name="returnsManager">manager to efficiently handle in sample</param> /// <returns>interesting data (usually an optimization's optimal result) to be used /// to take decisions out of sample</returns> object AnalyzeInSample( EligibleTickers eligibleTickers , ReturnsManager returnsManager ); // EndOfDayDateTime currentOutOfSampleEndOfDayDateTime ); /// <summary> /// short text description for the chooser (it might be used for saving /// logs for strategies) /// </summary> string Description { get; } } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:36:32
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv11683/b4_Business/a2_Strategies Added Files: IEndOfDayStrategyForBacktester.cs Log Message: Interface to be implemented by end of day strategies that are to be used by the EndOfDayStrategyBackTester --- NEW FILE: IEndOfDayStrategyForBacktester.cs --- /* QuantProject - Quantitative Finance Library IEndOfDayStrategyForBacktester.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; namespace QuantProject.Business.Strategies { /// <summary> /// Interface to be implemented by end of day strategies that are /// to be used by the EndOfDayStrategyBackTester /// </summary> public interface IEndOfDayStrategyForBacktester : IEndOfDayStrategy { /// <summary> /// use this property to signal to the end of day backtester that at current time /// a long execution is expected, so that it will decide to stop the execution if /// maxRunningHours have already expired. If this property returns false, the /// end of day backtesters goes on with its work (that should be all out /// of sample and then pretty fast). If you want the backtester to stop /// whenever maxRunningHours have elapsed, then set this property /// to always return true /// </summary> bool StopBacktestIfMaxRunningHoursHasBeenReached{ get; } event NewLogItemEventHandler NewLogItem; /// <summary> /// short description to be used as part of the log file name /// </summary> string DescriptionForLogFileName{ get; } } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:35:16
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10755/b4_Business/a2_Strategies Added Files: EndOfDayStrategyBackTester.cs Log Message: Performs a backtest for an end of day strategy --- NEW FILE: EndOfDayStrategyBackTester.cs --- /* QuantProject - Quantitative Finance Library EndOfDayStrategy.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.FileManaging; using QuantProject.ADT.Messaging; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Timing; namespace QuantProject.Business.Strategies { /// <summary> /// Performs a backtest for an end of day strategy /// </summary> public class EndOfDayStrategyBackTester : IMessageSender { public event NewMessageHandler NewMessage; private string backTestID; private IEndOfDayStrategyForBacktester endOfDayStrategy; private IHistoricalQuoteProvider historicalQuoteProvider; private DateTime firstDateTime; private DateTime lastDateTime; private Benchmark benchmark; private double cashToStart; private double maxRunningHours; private DateTime startingTimeForScript; private IEndOfDayTimer endOfDayTimer; private Account account; private BackTestLog backTestLog; public IHistoricalQuoteProvider HistoricalQuoteProvider { get { return this.historicalQuoteProvider; } } public Benchmark Benchmark { get { return this.benchmark; } } public Account Account { get { return this.account; } } public BackTestLog Log { get { return this.backTestLog; } } /// <summary> /// The timer used by the backtester, to simulate the time ticking /// </summary> public IEndOfDayTimer EndOfDayTimer { get { return this.endOfDayTimer; } } /// <summary> /// a short description for the performed backtest /// </summary> public string DescriptionForLogFileName { get { string description = this.backTestID + "_" + "from_" + this.firstDateTime.ToShortDateString() + "_" + "to_" + this.lastDateTime.ToShortDateString() + "_" + "strtgy_" + this.endOfDayStrategy.DescriptionForLogFileName; return description; } } public EndOfDayStrategyBackTester( string backTestID , IEndOfDayStrategyForBacktester endOfDayStrategy , IHistoricalQuoteProvider historicalQuoteProvider , DateTime firstDateTime , DateTime lastDateTime , Benchmark benchmark , double cashToStart , double maxRunningHours ) { this.backTestID = backTestID; this.endOfDayStrategy = endOfDayStrategy; this.historicalQuoteProvider = historicalQuoteProvider; this.firstDateTime = firstDateTime; this.lastDateTime = lastDateTime; this.benchmark = benchmark; this.cashToStart = cashToStart; this.maxRunningHours = maxRunningHours; this.initialize_endOfDayTimer(); this.initialize_account(); this.backTestLog = new BackTestLog( backTestID , firstDateTime , lastDateTime , benchmark ); } private void initialize_endOfDayTimer() { EndOfDayDateTime endOfDayDateTime = new EndOfDayDateTime( this.firstDateTime , EndOfDaySpecificTime.MarketOpen ); this.endOfDayTimer = new IndexBasedEndOfDayTimer( endOfDayDateTime , this.benchmark.Ticker ); } private void initialize_account() { this.account = new Account( this.backTestID , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , this.historicalQuoteProvider ) ); } #region Run #region run_addEventHandlers private void handlerToAddCashToStart( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Transactions.Count == 0 ) // no cash has been added yet this.account.AddCash( this.cashToStart ); } private void run_addEventHandlers_addHandlersToAddCashToStart() { this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.handlerToAddCashToStart ); this.endOfDayTimer.FiveMinutesBeforeMarketClose += new FiveMinutesBeforeMarketCloseEventHandler( this.handlerToAddCashToStart ); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.handlerToAddCashToStart ); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.handlerToAddCashToStart ); } private void run_addEventHandlers_addStrategyHandlers() { this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.endOfDayStrategy.MarketOpenEventHandler ); this.endOfDayTimer.FiveMinutesBeforeMarketClose += new FiveMinutesBeforeMarketCloseEventHandler( this.endOfDayStrategy.FiveMinutesBeforeMarketCloseEventHandler ); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayStrategy.OneHourAfterMarketCloseEventHandler ); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.endOfDayStrategy.MarketCloseEventHandler ); } private void run_addEventHandlers() { this.run_addEventHandlers_addHandlersToAddCashToStart(); this.run_addEventHandlers_addStrategyHandlers(); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.marketCloseEventHandler ); this.endOfDayStrategy.NewLogItem += new NewLogItemEventHandler( this.newLogItemEventHandler ); } #endregion run_addEventHandlers /// <summary> /// Performes the actual backtest /// </summary> public void Run() { this.startingTimeForScript = DateTime.Now; // run_initializeEndOfDayTimer(); // run_initializeAccount(); // run_initializeEndOfDayTimerHandler(); // run_initializeProgressHandlers(); run_addEventHandlers(); // this.progressBarForm.Show(); this.endOfDayTimer.Start(); } #endregion Run #region marketCloseEventHandler private bool isTimeToStop( DateTime currentTime ) { DateTime maxEndingDateTimeForScript = this.startingTimeForScript.AddHours( this.maxRunningHours ); bool scriptTimeElapsed = ( DateTime.Now >= maxEndingDateTimeForScript ); bool stopBacktestIfMaxRunningHoursHasBeenReached = this.endOfDayStrategy.StopBacktestIfMaxRunningHoursHasBeenReached; return ( ( currentTime > this.lastDateTime ) || ( scriptTimeElapsed && stopBacktestIfMaxRunningHoursHasBeenReached ) ); } private void marketCloseEventHandler_notifyProgress( IEndOfDayTimer endOfDayTimer ) { string progressMessage = "Current out of sample date:" + endOfDayTimer.GetCurrentTime().DateTime.ToString() + " - " + "First date:" + this.firstDateTime.ToString() + " - " + "Last date:" + this.lastDateTime.ToString(); NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( progressMessage ); if(this.NewMessage != null) this.NewMessage( this , newMessageEventArgs ); } private void marketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { DateTime currentTime = ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime; if ( this.isTimeToStop( currentTime ) ) { // either the simulation has reached the ending date or // too much time elapsed since the simulation started this.endOfDayTimer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , // @"C:\Documents and Settings\Glauco\Desktop\reports\final.qP" ); // this.saveLog( currentTime ); // this.showReport( sender ); // WFMultiOneRankReportDebugger wFMultiOneRankReportDebugger = // new WFMultiOneRankReportDebugger( this.numberOfPortfolioPositions , // this.numberDaysForInSampleOptimization , this.benchmark ); // report.TransactionGrid.MouseUp += // new MouseEventHandler( // wFMultiOneRankReportDebugger.MouseClickEventHandler ); } else // the simulation has not reached the ending date, yet this.marketCloseEventHandler_notifyProgress( ( IEndOfDayTimer )sender ); } #endregion marketCloseEventHandler private void newLogItemEventHandler( object sender , NewLogItemEventArgs eventArgs ) { // WFLagChosenPositions wFLagChosenPositions = // new WFLagChosenPositions( eventArgs.WFLagChosenTickers , // this.endOfDayTimer.GetCurrentTime().DateTime ); this.backTestLog.Add( eventArgs.LogItem ); } } } |
|
From: Glauco S. <gla...@us...> - 2008-01-19 17:34:00
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10334/b4_Business/a2_Strategies Added Files: Benchmark.cs Log Message: Either a security or an index that is used to time a strategy and/or to compare a strategy's results --- NEW FILE: Benchmark.cs --- using System; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Timing; namespace QuantProject.Business.Strategies { /// <summary> /// Either a security or an index that is used to time a strategy and/or /// to compare a strategy's results /// </summary> public class Benchmark { private string ticker; private HistoricalQuoteProvider historicalQuoteProvider; public string Ticker { get { return this.ticker; } } public Benchmark( string ticker ) { this.ticker = ticker; this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } #region GetTimeStep private void getTimeStep_checkParameters( EndOfDayDateTime timeStepBegin ) { if ( !this.historicalQuoteProvider.WasExchanged( this.ticker , timeStepBegin ) ) throw new Exception( "The benchmark '" + this.ticker + "' was not exchanged at the given timeStepBegin " + timeStepBegin.ToString() ); } private void isExchanged_checkParameter( EndOfDayDateTime endOfDayDateTime ) { if ( endOfDayDateTime.DateTime.Year > DateTime.Now.Year ) throw new Exception( "It looks like this is a loop! " + "You have probably asked for a GetTimeStep, but " + "there is no other trading day for this benchmark: '" + this.ticker + "'" ); } private bool isExchanged( EndOfDayDateTime endOfDayDateTime ) { this.isExchanged_checkParameter( endOfDayDateTime ); bool isTraded = this.historicalQuoteProvider.WasExchanged( this.ticker , endOfDayDateTime ); return isTraded; } private ReturnInterval getTimeStep_actually( EndOfDayDateTime timeStepBegin ) { EndOfDayDateTime currentEndOfDayDateTime = timeStepBegin.GetNextMarketStatusSwitch(); while ( !this.isExchanged( currentEndOfDayDateTime ) ) currentEndOfDayDateTime = currentEndOfDayDateTime.GetNextMarketStatusSwitch(); ReturnInterval timeStep = new ReturnInterval( timeStepBegin , currentEndOfDayDateTime ); return timeStep; } /// <summary> /// Returns the benchmark's time step that begins at timeStepBegin /// </summary> /// <param name="timeStepBegin"></param> /// <returns></returns> public ReturnInterval GetTimeStep( EndOfDayDateTime timeStepBegin ) { this.getTimeStep_checkParameters( timeStepBegin ); ReturnInterval timeStep = this.getTimeStep_actually( timeStepBegin ); return timeStep; } #endregion GetTimeStep /// <summary> /// Returns either the next market close or the next market open /// (when the benchmark is exchanged), whichever is the nearest. /// If endOfDayDateTime is either a market close or a market open /// when the benchmark is exchanged, then endOfDayDateTime itself /// is returned /// </summary> /// <param name="endOfDayDateTime"></param> /// <returns></returns> public EndOfDayDateTime GetThisOrNextMarketStatusSwitch( EndOfDayDateTime endOfDayDateTime ) { EndOfDayDateTime currentEndOfDayDateTime = endOfDayDateTime; while ( !this.isExchanged( currentEndOfDayDateTime ) ) currentEndOfDayDateTime = currentEndOfDayDateTime.GetNextMarketStatusSwitch(); return currentEndOfDayDateTime; } } } |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:54:22
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28263/b4_Business Modified Files: Business_SD.csproj Log Message: Updated SharpDevelop project files Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Business_SD.csproj 8 Nov 2007 17:46:48 -0000 1.6 --- Business_SD.csproj 14 Jan 2008 23:54:11 -0000 1.7 *************** *** 67,70 **** --- 67,74 ---- <Compile Include="a2_Strategies\returnsManagement\time\ReturnInterval.cs" /> <Compile Include="a2_Strategies\returnsManagement\time\ReturnIntervals.cs" /> + <Compile Include="a2_Strategies\TickersRelationships\CloseToCloseCorrelationProvider.cs" /> + <Compile Include="a2_Strategies\TickersRelationships\CorrelationProvider.cs" /> + <Compile Include="a2_Strategies\TickersRelationships\OpenToCloseCorrelationProvider.cs" /> + <Compile Include="a2_Strategies\TickersRelationships\TickersPearsonCorrelation.cs" /> <Compile Include="AssemblyInfo.cs" /> <Compile Include="a0_Validation\IValidator.cs" /> *************** *** 196,199 **** --- 200,204 ---- <Folder Include="a2_Strategies\returnsManagement" /> <Folder Include="a2_Strategies\returnsManagement\time" /> + <Folder Include="a2_Strategies\TickersRelationships" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:49:08
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv26028/b7_Scripts Modified Files: Scripts_SD.csproj Log Message: Updated SharpDevelop project files Index: Scripts_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts_SD.csproj,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Scripts_SD.csproj 8 Nov 2007 17:47:16 -0000 1.10 --- Scripts_SD.csproj 14 Jan 2008 23:49:05 -0000 1.11 *************** *** 56,59 **** --- 56,62 ---- <Compile Include="SimpleTesting\ShortTest\EndOfDayTimerHandler.cs" /> <Compile Include="SimpleTesting\ShortTest\RunShortTest.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\EndOfDayTimerHandlerBiasedPVO_OTC.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\RunBiasedPVO_OTC.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\GenomeManagerPVO_OTC.cs" /> <Compile Include="TickerSelectionTesting\EndOfDayTimerHandlerCTC.cs" /> <Compile Include="TickerSelectionTesting\EndOfDayTimerHandlerCTO.cs" /> *************** *** 207,218 **** <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\RunWeightedBalancedPVO.cs" /> <Compile Include="WalkForwardTesting\LinearCombination\FixedLevelOscillatorBiasedPVOStrategy.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\EndOfDayTimerHandlerBiasedPVONoThresholds.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\GenomeManagerBiasedPVONoThresholds.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\RunBiasedPVONoThresholds.cs" /> - <Compile Include="WalkForwardTesting\LinearCombination\FixedLevelOscillatorBiasedPVONoThresholdsStrategy.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\GenomeManagerBiasedOTC_PVONoThresholds.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\RunBiasedOTC_PVONoThresholds.cs" /> - <Compile Include="WalkForwardTesting\LinearCombination\FixedLevelOscBiasedOTC_PVONoThresholdsStrategy.cs" /> <Compile Include="WalkForwardTesting\WalkForwardLag\WFLagNewChosenPositionsEventArgs.cs" /> <Compile Include="WalkForwardTesting\WalkForwardLag\WeightedPositionsChoosers\IWFLagWeightedPositionsChooser.cs" /> --- 210,213 ---- *************** *** 272,276 **** <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator" /> - <Folder Include="WalkForwardTesting\WalkForwardLag\WFLagBruteForceOptimizableItemManager" /> <Folder Include="TickerSelectionTesting\TestingOTCTypes\BruteForceOptimization" /> <Folder Include="WalkForwardTesting\WalkForwardLag\GeneticOptimizerTesting" /> --- 267,270 ---- *************** *** 278,283 **** <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO" /> - <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds" /> - <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds" /> <Folder Include="WalkForwardTesting\WalkForwardLag\WeightedPositionsChoosers" /> <Folder Include="ArbitrageTesting\OverReactionHypothesis" /> --- 272,275 ---- |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:47:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv25247/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: Added PVO strategy using OTC returns Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** b7_Scripts.csproj 4 Nov 2007 18:51:54 -0000 1.80 --- b7_Scripts.csproj 14 Jan 2008 23:47:36 -0000 1.81 *************** *** 2,6 **** <CSHARP ProjectType = "Local" ! ProductVersion = "7.0.9466" SchemaVersion = "1.0" ProjectGuid = "{451DB77D-D4C7-44D1-8047-2920D864A4CD}" --- 2,6 ---- <CSHARP ProjectType = "Local" ! ProductVersion = "7.0.9955" SchemaVersion = "1.0" ProjectGuid = "{451DB77D-D4C7-44D1-8047-2920D864A4CD}" *************** *** 304,353 **** /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\GenomeMeaningPVO.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\RunPVO.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\EndOfDayTimerHandlerBiasedPVO.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\RunBiasedPVO.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\GenomeManagerBiasedOTC_PVONoThresholds.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\RunBiasedOTC_PVONoThresholds.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\EndOfDayTimerHandlerBiasedPVONoThresholds.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\GenomeManagerBiasedPVONoThresholds.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\RunBiasedPVONoThresholds.cs" SubType = "Code" BuildAction = "Compile" --- 304,338 ---- /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\GenomeManagerPVO_OTC.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\GenomeMeaningPVO.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\RunPVO.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\EndOfDayTimerHandlerBiasedPVO.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\EndOfDayTimerHandlerBiasedPVO_OTC.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\RunBiasedPVO.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\RunBiasedPVO_OTC.cs" SubType = "Code" BuildAction = "Compile" *************** *** 694,707 **** /> <File - RelPath = "WalkForwardTesting\LinearCombination\FixedLevelOscBiasedOTC_PVONoThresholdsStrategy.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "WalkForwardTesting\LinearCombination\FixedLevelOscillatorBiasedPVONoThresholdsStrategy.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "WalkForwardTesting\LinearCombination\FixedLevelOscillatorBiasedPVOStrategy.cs" SubType = "Code" --- 679,682 ---- |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:46:26
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24799/b4_Business Modified Files: b4_Business.csproj Log Message: Added classes for providing correlation indexes Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** b4_Business.csproj 23 Sep 2007 21:50:55 -0000 1.48 --- b4_Business.csproj 14 Jan 2008 23:46:23 -0000 1.49 *************** *** 713,716 **** --- 713,736 ---- /> <File + RelPath = "a2_Strategies\TickersRelationships\CloseToCloseCorrelationProvider.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "a2_Strategies\TickersRelationships\CorrelationProvider.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "a2_Strategies\TickersRelationships\OpenToCloseCorrelationProvider.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "a2_Strategies\TickersRelationships\TickersPearsonCorrelation.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a3_Testing\BackTester.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:43:51
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23521/b7_Scripts/TickerSelectionTesting Modified Files: RunEfficientOTC_WorstAtNightPortfolio.cs Log Message: Minor changes Index: RunEfficientOTC_WorstAtNightPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientOTC_WorstAtNightPortfolio.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunEfficientOTC_WorstAtNightPortfolio.cs 29 Aug 2007 10:04:26 -0000 1.2 --- RunEfficientOTC_WorstAtNightPortfolio.cs 14 Jan 2008 23:43:47 -0000 1.3 *************** *** 69,75 **** portfolioType, maxRunningHours) { ! this.ScriptName = "OTC_WorstAtNight_SharpeRatioWithCoeff_OnlyMutation"; //this.ScriptName = "OpenCloseScriptsSharpeRatio"; ! // this.ScriptName = "OTC_WorstAtNight_SharpeRatioNoCoeff"; //this.ScriptName = "OpenCloseScripts"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; --- 69,75 ---- portfolioType, maxRunningHours) { ! // this.ScriptName = "OTC_WorstAtNight_SharpeRatioWithCoeff_OnlyMutation"; //this.ScriptName = "OpenCloseScriptsSharpeRatio"; ! this.ScriptName = "OTC_WorstAtNight_SharpeRatioNoCoeff"; //this.ScriptName = "OpenCloseScripts"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:43:51
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23521/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization Modified Files: OTCBruteForceOptimizableParametersManager.cs Log Message: Minor changes Index: OTCBruteForceOptimizableParametersManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization/OTCBruteForceOptimizableParametersManager.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OTCBruteForceOptimizableParametersManager.cs 17 Sep 2006 21:37:18 -0000 1.1 --- OTCBruteForceOptimizableParametersManager.cs 14 Jan 2008 23:43:47 -0000 1.2 *************** *** 61,65 **** firstOptimizationDate , lastOptimizationDate , ! numberOfPortfolioPositions , 0.0, PortfolioType.ShortAndLong); } --- 61,66 ---- firstOptimizationDate , lastOptimizationDate , ! numberOfPortfolioPositions , 0.0, PortfolioType.ShortAndLong, ! "^GSPC"); } *************** *** 102,106 **** BruteForceOptimizableParameters bruteForceOptimizableItem ) { ! return this.otcCtoGenomeManager.GetFitnessValue(bruteForceOptimizableItem); } } --- 103,108 ---- BruteForceOptimizableParameters bruteForceOptimizableItem ) { ! return 0.0; //just for compiling ! //return this.otcCtoGenomeManager.GetFitnessValue(bruteForceOptimizableItem); } } |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:43:51
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/BestAndWorst In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23521/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/BestAndWorst Modified Files: RunBestAndWorstFollower.cs Log Message: Minor changes Index: RunBestAndWorstFollower.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/BestAndWorst/RunBestAndWorstFollower.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunBestAndWorstFollower.cs 29 Aug 2007 09:32:57 -0000 1.1 --- RunBestAndWorstFollower.cs 14 Jan 2008 23:43:47 -0000 1.2 *************** *** 37,42 **** /// Script that implements the Best and Worst Follower strategy: /// every n closes, l long positions and s short positions will be open, ! /// buying and shorting, accordingly, the l worst tickers ! /// and the s best tickers. /// For chosing the best and worst tickers just the /// previous close to close ratio is considered. --- 37,42 ---- /// Script that implements the Best and Worst Follower strategy: /// every n closes, l long positions and s short positions will be open, ! /// buying and shorting, accordingly, the l best tickers ! /// and the s worst tickers. /// For chosing the best and worst tickers just the /// previous close to close ratio is considered. |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:42:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23094/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest Modified Files: WalkForwardOpenToCloseDailyStrategy.cs Log Message: no message Index: WalkForwardOpenToCloseDailyStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest/WalkForwardOpenToCloseDailyStrategy.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** WalkForwardOpenToCloseDailyStrategy.cs 11 Jan 2006 18:21:07 -0000 1.6 --- WalkForwardOpenToCloseDailyStrategy.cs 14 Jan 2008 23:42:36 -0000 1.7 *************** *** 196,200 **** this.numberOfTickersToBeChosen , this.targetReturn , ! this.portfolioType ); this.geneticOptimizer = new GeneticOptimizer(genManEfficientOTCPortfolio, --- 196,201 ---- this.numberOfTickersToBeChosen , this.targetReturn , ! this.portfolioType, ! this.benchmark); this.geneticOptimizer = new GeneticOptimizer(genManEfficientOTCPortfolio, |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:41:48
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22669/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: LinearCombinationTest.cs MainForm.cs TestDisplayer.cs Log Message: Updated classes for single genomes testing Index: MainForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/MainForm.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** MainForm.cs 3 Aug 2006 21:15:57 -0000 1.10 --- MainForm.cs 14 Jan 2008 23:41:44 -0000 1.11 *************** *** 235,239 **** this.numberOfTickersToBeChosen, this.targetReturn, ! this.portfolioType); this.GO = new GeneticOptimizer(genManEfficientOTCPortfolio, --- 235,240 ---- this.numberOfTickersToBeChosen, this.targetReturn, ! this.portfolioType, ! this.benchmark); this.GO = new GeneticOptimizer(genManEfficientOTCPortfolio, Index: LinearCombinationTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/LinearCombinationTest.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** LinearCombinationTest.cs 29 Aug 2007 09:43:36 -0000 1.12 --- LinearCombinationTest.cs 14 Jan 2008 23:41:44 -0000 1.13 *************** *** 52,55 **** --- 52,58 ---- private double stopLoss; private double takeProfit; + private double oversoldThreshold; + private double overboughtThreshold; + private bool setDirectlyThresholdLevels; private IHistoricalQuoteProvider historicalQuoteProvider; *************** *** 58,61 **** --- 61,83 ---- private IEndOfDayStrategy endOfDayStrategy; private PortfolioType portfolioType; + + private void linearCombinationTest_commonInitialization(DateTime firstDate , DateTime lastDate , + GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, + PortfolioType portfolioType, int numDaysForOscillatorStrategy, + double stopLoss, double takeProfit, + double oversoldThreshold, double overboughtThreshold, bool setDirectlyThresholdLevels) + { + this.firstDate = firstDate; + this.lastDate = lastDate; + this.genomeRepresentations = genomeRepresentations; + this.strategyType = strategyType; + this.portfolioType = portfolioType; + this.numDaysForOscillatorStrategy = numDaysForOscillatorStrategy; + this.stopLoss = stopLoss; + this.takeProfit = takeProfit; + this.oversoldThreshold = oversoldThreshold; + this.overboughtThreshold = overboughtThreshold; + this.setDirectlyThresholdLevels = setDirectlyThresholdLevels; + } public LinearCombinationTest( DateTime firstDate , DateTime lastDate , *************** *** 63,72 **** PortfolioType portfolioType) { ! this.firstDate = firstDate; ! this.lastDate = lastDate; ! this.genomeRepresentations = genomeRepresentations; ! // this.openToCloseDaily = openToCloseDaily; ! this.strategyType = strategyType; ! this.portfolioType = portfolioType; } --- 85,90 ---- PortfolioType portfolioType) { ! this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, 0,0,0,0,0,false); } *************** *** 76,87 **** int numDaysForOscillatorStrategy) { ! this.firstDate = firstDate; ! this.lastDate = lastDate; ! this.genomeRepresentations = genomeRepresentations; ! // this.openToCloseDaily = openToCloseDaily; ! this.strategyType = strategyType; ! this.portfolioType = portfolioType; ! this.numDaysForOscillatorStrategy = numDaysForOscillatorStrategy; } public LinearCombinationTest( DateTime firstDate , DateTime lastDate , GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, --- 94,102 ---- int numDaysForOscillatorStrategy) { ! this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! 0,0,0,0,false); } + public LinearCombinationTest( DateTime firstDate , DateTime lastDate , GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, *************** *** 89,102 **** int numDaysForOscillatorStrategy, double stopLoss, double takeProfit) { ! this.firstDate = firstDate; ! this.lastDate = lastDate; ! this.genomeRepresentations = genomeRepresentations; ! // this.openToCloseDaily = openToCloseDaily; ! this.strategyType = strategyType; ! this.portfolioType = portfolioType; ! this.numDaysForOscillatorStrategy = numDaysForOscillatorStrategy; ! this.stopLoss = stopLoss; ! this.takeProfit = takeProfit; } private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) --- 104,122 ---- int numDaysForOscillatorStrategy, double stopLoss, double takeProfit) { ! this.linearCombinationTest_commonInitialization( firstDate, lastDate, ! genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, ! stopLoss, takeProfit, 0,0,false); } + public LinearCombinationTest( DateTime firstDate , DateTime lastDate , + GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, + PortfolioType portfolioType, + int numDaysForOscillatorStrategy, double stopLoss, double takeProfit, + double oversoldThreshold, double overboughtThreshold, bool setDirectlyThresholdLevels) + { + this.linearCombinationTest_commonInitialization( firstDate, lastDate, + genomeRepresentations, strategyType, portfolioType, numDaysForOscillatorStrategy, + stopLoss, takeProfit, oversoldThreshold, overboughtThreshold, + setDirectlyThresholdLevels); + } private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) *************** *** 115,151 **** } ! private void run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy() ! { ! WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! for(int i = 0; i<this.genomeRepresentations.Length;i++) ! { ! weightedPositions[i] = ! new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! ! } ! ! this.endOfDayStrategy = new FixedLevelOscBiasedOTC_PVONoThresholdsStrategy( ! this.account , weightedPositions, ! this.genomeRepresentations.Length); ! } ! private void run_setStrategy_setBiasedPVONoThresholdsStrategy() ! { ! WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! for(int i = 0; i<this.genomeRepresentations.Length;i++) ! { ! weightedPositions[i] = ! new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! ! } ! this.endOfDayStrategy = new FixedLevelOscillatorBiasedPVONoThresholdsStrategy( ! this.account , weightedPositions, ! this.genomeRepresentations.Length, ! this.stopLoss, ! this.takeProfit); ! } private void run_setStrategy_setBiasedPVOStrategy() { --- 135,192 ---- } ! // private void run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy() ! // { ! // WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! // for(int i = 0; i<this.genomeRepresentations.Length;i++) ! // { ! // weightedPositions[i] = ! // new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! // new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! // ! // } ! // ! // this.endOfDayStrategy = new FixedLevelOscBiasedOTC_PVONoThresholdsStrategy( ! // this.account , weightedPositions, ! // this.genomeRepresentations.Length); ! // } ! // private void run_setStrategy_setBiasedPVONoThresholdsStrategy() ! // { ! // WeightedPositions[] weightedPositions = new WeightedPositions[this.genomeRepresentations.Length]; ! // for(int i = 0; i<this.genomeRepresentations.Length;i++) ! // { ! // weightedPositions[i] = ! // new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), ! // new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! // ! // } ! // this.endOfDayStrategy = new FixedLevelOscillatorBiasedPVONoThresholdsStrategy( ! // this.account , weightedPositions, ! // this.genomeRepresentations.Length, ! // this.stopLoss, ! // this.takeProfit); ! // } + private double run_setStrategy_setBiasedPVOStrategy_getOversoldThreshold(int i) + { + double returnValue; + if(this.setDirectlyThresholdLevels) + returnValue = this.oversoldThreshold; + else + returnValue = this.genomeRepresentations[i].OversoldThreshold; + + return returnValue; + } + private double run_setStrategy_setBiasedPVOStrategy_getOverboughtThreshold(int i) + { + double returnValue; + if(this.setDirectlyThresholdLevels) + returnValue = this.overboughtThreshold; + else + returnValue = this.genomeRepresentations[i].OverboughtThreshold; + + return returnValue; + } + private void run_setStrategy_setBiasedPVOStrategy() { *************** *** 158,163 **** new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! oversoldThresholds[i] = this.genomeRepresentations[i].OversoldThreshold; ! overboughtThresholds[i] = this.genomeRepresentations[i].OverboughtThreshold; } --- 199,204 ---- new WeightedPositions(GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[i].WeightsForSignedTickers), new SignedTickers(this.genomeRepresentations[i].SignedTickers)); ! oversoldThresholds[i] = this.run_setStrategy_setBiasedPVOStrategy_getOversoldThreshold(i); ! overboughtThresholds[i] = this.run_setStrategy_setBiasedPVOStrategy_getOverboughtThreshold(i); } *************** *** 223,233 **** break; ! case StrategyType.PortfolioValueOscillatorBiasedNoThresholds: ! this.run_setStrategy_setBiasedPVONoThresholdsStrategy(); ! break; ! ! case StrategyType.OTC_PVOBiasedNoThresholds: ! this.run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy(); ! break; } } --- 264,274 ---- break; ! // case StrategyType.PortfolioValueOscillatorBiasedNoThresholds: ! // this.run_setStrategy_setBiasedPVONoThresholdsStrategy(); ! // break; ! // ! // case StrategyType.OTC_PVOBiasedNoThresholds: ! // this.run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy(); ! // break; } } *************** *** 262,265 **** --- 303,321 ---- } + private void run_addEquityLineForEachPositionInWeightedPositions( + WeightedPositions weightedPositions , Color color , Report report ) + { + foreach(WeightedPosition position in weightedPositions.Values) + { + WeightedPositions wp = new WeightedPositions(new SignedTickers( + position.Ticker)); + EquityLine equityLineForWeightedPositions = + wp.GetVirtualEquityLine( + 15000 , report.AccountReport.EquityLine ); + report.AddEquityLine( equityLineForWeightedPositions , + color ); + } + } + private WeightedPositions run_getWeightedPositions(GenomeRepresentation genomeRepresentation) *************** *** 313,324 **** new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^GSPC"); ! WeightedPositions weightedPositions = ! this.run_getWeightedPositions(this.genomeRepresentations[0]); ! this.run_addEquityLineForWeightedPositions(weightedPositions, Color.Brown, ! report); ! ! // ObjectArchiver.Archive( report.AccountReport , ! // @"C:\Documents and Settings\Glauco\Desktop\reports\runOneRank.qPr" ); ! report.Text = this.run_getReportTitle(); report.Show(); } --- 369,386 ---- new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^GSPC"); ! foreach(GenomeRepresentation genomeRepresentation in this.genomeRepresentations) ! { ! WeightedPositions weightedPositions = this.run_getWeightedPositions( genomeRepresentation ); ! this.run_addEquityLineForWeightedPositions( ! weightedPositions, ! Color.Brown, ! report); ! this.run_addEquityLineForEachPositionInWeightedPositions( ! weightedPositions, ! Color.DimGray, ! report); ! ! } ! report.Text = this.run_getReportTitle(); report.Show(); } Index: TestDisplayer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/TestDisplayer.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TestDisplayer.cs 29 Aug 2007 10:05:29 -0000 1.13 --- TestDisplayer.cs 14 Jan 2008 23:41:44 -0000 1.14 *************** *** 69,72 **** --- 69,77 ---- private System.Windows.Forms.RadioButton radioButtonPVOBiasedNoThresholds; private System.Windows.Forms.RadioButton radioButtonOTCPVOBiasedNoThresholds; + private System.Windows.Forms.TextBox textBoxOversoldThreshold; + private System.Windows.Forms.TextBox textBoxOverboughtThreshold; + private System.Windows.Forms.Label labelOversoldThreshold; + private System.Windows.Forms.Label labelOverboughtThreshold; + private System.Windows.Forms.CheckBox checkBoxSetDirectlyThresholdLevels; private System.Windows.Forms.ComboBox comboBoxPortfolioType; *************** *** 220,223 **** --- 225,233 ---- this.radioButtonPVOBiasedNoThresholds = new System.Windows.Forms.RadioButton(); this.radioButtonOTCPVOBiasedNoThresholds = new System.Windows.Forms.RadioButton(); + this.textBoxOversoldThreshold = new System.Windows.Forms.TextBox(); + this.textBoxOverboughtThreshold = new System.Windows.Forms.TextBox(); + this.labelOversoldThreshold = new System.Windows.Forms.Label(); + this.labelOverboughtThreshold = new System.Windows.Forms.Label(); + this.checkBoxSetDirectlyThresholdLevels = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); this.SuspendLayout(); *************** *** 419,422 **** --- 429,472 ---- this.radioButtonOTCPVOBiasedNoThresholds.CheckedChanged += new System.EventHandler(this.radioButtonOTCPVOBiasedNoThresholds_CheckedChanged); // + // textBoxOversoldThreshold + // + this.textBoxOversoldThreshold.Location = new System.Drawing.Point(504, 216); + this.textBoxOversoldThreshold.Name = "textBoxOversoldThreshold"; + this.textBoxOversoldThreshold.Size = new System.Drawing.Size(40, 20); + this.textBoxOversoldThreshold.TabIndex = 23; + this.textBoxOversoldThreshold.Text = "0.01"; + // + // textBoxOverboughtThreshold + // + this.textBoxOverboughtThreshold.Location = new System.Drawing.Point(656, 216); + this.textBoxOverboughtThreshold.Name = "textBoxOverboughtThreshold"; + this.textBoxOverboughtThreshold.Size = new System.Drawing.Size(40, 20); + this.textBoxOverboughtThreshold.TabIndex = 24; + this.textBoxOverboughtThreshold.Text = "0.01"; + // + // labelOversoldThreshold + // + this.labelOversoldThreshold.Location = new System.Drawing.Point(424, 216); + this.labelOversoldThreshold.Name = "labelOversoldThreshold"; + this.labelOversoldThreshold.Size = new System.Drawing.Size(80, 16); + this.labelOversoldThreshold.TabIndex = 25; + this.labelOversoldThreshold.Text = "OvSold thresh."; + // + // labelOverboughtThreshold + // + this.labelOverboughtThreshold.Location = new System.Drawing.Point(552, 216); + this.labelOverboughtThreshold.Name = "labelOverboughtThreshold"; + this.labelOverboughtThreshold.Size = new System.Drawing.Size(96, 16); + this.labelOverboughtThreshold.TabIndex = 26; + this.labelOverboughtThreshold.Text = "OvBought thresh."; + // + // checkBoxSetDirectlyThresholdLevels + // + this.checkBoxSetDirectlyThresholdLevels.Location = new System.Drawing.Point(432, 184); + this.checkBoxSetDirectlyThresholdLevels.Name = "checkBoxSetDirectlyThresholdLevels"; + this.checkBoxSetDirectlyThresholdLevels.Size = new System.Drawing.Size(232, 24); + this.checkBoxSetDirectlyThresholdLevels.TabIndex = 27; + this.checkBoxSetDirectlyThresholdLevels.Text = "set directly threshold-levels"; + // // TestDisplayer // *************** *** 424,427 **** --- 474,482 ---- this.ClientSize = new System.Drawing.Size(704, 414); this.Controls.AddRange(new System.Windows.Forms.Control[] { + this.checkBoxSetDirectlyThresholdLevels, + this.labelOverboughtThreshold, + this.labelOversoldThreshold, + this.textBoxOverboughtThreshold, + this.textBoxOversoldThreshold, this.radioButtonOTCPVOBiasedNoThresholds, this.radioButtonPVOBiasedNoThresholds, *************** *** 515,519 **** this.selectedStrategyType, (PortfolioType)this.comboBoxPortfolioType.SelectedItem, Convert.ToInt32(this.textBoxDaysFPOscillatorAndRevOneRank.Text), ! Convert.ToDouble(this.textBoxStopLoss.Text),Convert.ToDouble(this.textBoxTakeProfit.Text) ); linearCombinationTest.Run(); this.lastSelectedGenomeRepresentations = genomeRepresentations; --- 570,577 ---- this.selectedStrategyType, (PortfolioType)this.comboBoxPortfolioType.SelectedItem, Convert.ToInt32(this.textBoxDaysFPOscillatorAndRevOneRank.Text), ! Convert.ToDouble(this.textBoxStopLoss.Text),Convert.ToDouble(this.textBoxTakeProfit.Text), ! Convert.ToDouble(this.textBoxOversoldThreshold.Text), ! Convert.ToDouble(this.textBoxOverboughtThreshold.Text), ! this.checkBoxSetDirectlyThresholdLevels.Checked); linearCombinationTest.Run(); this.lastSelectedGenomeRepresentations = genomeRepresentations; |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:40:28
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22216/b7_Scripts/TickerSelectionTesting Modified Files: GenomeMeaning.cs Log Message: Minor changes Index: GenomeMeaning.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeMeaning.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GenomeMeaning.cs 9 Apr 2007 17:58:04 -0000 1.4 --- GenomeMeaning.cs 14 Jan 2008 23:40:23 -0000 1.5 *************** *** 24,27 **** --- 24,29 ---- using System.Collections; + using QuantProject.Business.Strategies; + namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { *************** *** 79,83 **** private void genomeMeaning_setHashCodeForTickerComposition() { ! ArrayList listOfTickers = new ArrayList(this.tickers); listOfTickers.Sort(); foreach(string tickerCode in listOfTickers) --- 81,88 ---- private void genomeMeaning_setHashCodeForTickerComposition() { ! string[] unsignedTickers = new string[this.tickers.Length]; ! for(int i = 0; i < this.tickers.Length; i++) ! unsignedTickers[i] = SignedTicker.GetTicker(this.tickers[i]); ! ArrayList listOfTickers = new ArrayList(unsignedTickers); listOfTickers.Sort(); foreach(string tickerCode in listOfTickers) |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:38:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21302/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientCTCPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientOTCCTOPortfolio.cs GenomeManagerForEfficientOTCPortfolio.cs GenomeManagerForEfficientPortfolio.cs GenomeManagerForWeightedEfficientPortfolio.cs Log Message: GenomeManagers have been updated (WeightedPositions have been used instead of CandidateProperties) Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** GenomeManagerForEfficientCTOPortfolio.cs 2 Jul 2006 19:57:34 -0000 1.19 --- GenomeManagerForEfficientCTOPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.20 *************** *** 23,31 **** using System; using System.Data; ! using System.Collections; ! using QuantProject.ADT.Statistics; ! using QuantProject.ADT.Optimizing.Genetic; ! using QuantProject.Data; ! using QuantProject.Data.DataTables; --- 23,32 ---- using System; using System.Data; ! ! using QuantProject.Business.DataProviders; ! using QuantProject.Business.Timing; ! using QuantProject.Business.Strategies; ! using QuantProject.Business.Strategies.ReturnsManagement; ! using QuantProject.Business.Strategies.ReturnsManagement.Time; *************** *** 40,50 **** public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForEfficientPortfolio { ! private GenomeManagerForEfficientOTCPortfolio genManOTC; ! public GenomeManagerForEfficientCTOPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType) :base(setOfInitialTickers, firstQuoteDate, --- 41,53 ---- 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, *************** *** 52,156 **** numberOfTickersInPortfolio, targetPerformance, ! portfolioType) { ! this.retrieveData(); ! this.genManOTC = new GenomeManagerForEfficientOTCPortfolio(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType); ! } ! private float[] getArrayOfRatesOfReturn_getCloseToOpenRates(Quotes tickerQuotes) ! { ! float[] returnValue = new float[tickerQuotes.Rows.Count - 1]; ! for(int i = 0;i<tickerQuotes.Rows.Count - 1; i++) ! { ! returnValue[i] = ! ( (float)tickerQuotes.Rows[i+1]["quOpen"]* ! (float)tickerQuotes.Rows[i+1]["quAdjustedClose"]/ ! (float)tickerQuotes.Rows[i+1]["quClose"] ) ! /(float)tickerQuotes.Rows[i]["quAdjustedClose"] - 1; ! } ! return returnValue; ! } ! protected override float[] getArrayOfRatesOfReturn(string ticker) ! { ! float[] returnValue = null; ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = this.getArrayOfRatesOfReturn_getCloseToOpenRates(tickerQuotes); ! this.numberOfExaminedReturns = returnValue.Length; ! ! return returnValue; ! } ! public override double GetFitnessValue(Genome genome) ! { ! double returnValue = 0; ! this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! double averagePortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! ! double portfolioVariance = ! BasicFunctions.Variance(this.portfolioRatesOfReturn); ! ! if(!Double.IsInfinity(portfolioVariance) && ! !Double.IsInfinity(averagePortfolioRateOfReturn) && ! !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn) && ! portfolioVariance > 0.0) ! //both variance and rate of return are ! //double values computed in the right way: ! // so it's possible to assign fitness ! { ! this.variance = portfolioVariance; ! this.rateOfReturn = averagePortfolioRateOfReturn; ! returnValue = this.getFitnessValue_calculate(); ! // returnValue = this.getFitnessValue_calculate() - ! // this.genManOTC.GetFitnessValue(genome); ! ! } ! ! return returnValue; ! } ! ! ! /*using LPM ! protected override double getFitnessValue_calculate() ! { ! double returnValue = 0; ! ! double a, b, c; ! a = 0.002; b = 2.0; c = 2.0; ! ! //returnValue = Math.Pow((a/this.Variance),b) * ! // Math.Pow((this.rateOfReturn - this.targetPerformance), ! // c); ! //this.lowerPartialMoment = AdvancedFunctions.LowerPartialMoment(this.portfolioRatesOfReturn, ! // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn), ! // 3.0); ! this.lowerPartialMoment = AdvancedFunctions.NegativeSemiVariance(this.portfolioRatesOfReturn); ! a = 1.0; ! returnValue = Math.Pow((a/this.lowerPartialMoment),b) * ! Math.Pow(Math.Max(0.0,(this.rateOfReturn - this.targetPerformance)), ! c); ! ! if(this.portfolioType == PortfolioType.OnlyShort) ! returnValue = - returnValue; ! ! if(Double.IsInfinity(returnValue) || Double.IsNaN(returnValue)) ! throw new Exception("Fitness value not computed correctly!"); ! ! return returnValue; } ! */ ! ! protected override double getFitnessValue_calculate() { ! return this.RateOfReturn/Math.Sqrt(this.Variance); } ! } - } --- 55,85 ---- 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); ! } ! } } Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** GenomeManagerForEfficientCTCPortfolio.cs 14 May 2006 18:36:37 -0000 1.13 --- GenomeManagerForEfficientCTCPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.14 *************** *** 23,31 **** using System; using System.Data; ! using System.Collections; ! using QuantProject.ADT.Statistics; ! using QuantProject.ADT.Optimizing.Genetic; ! using QuantProject.Data; ! using QuantProject.Data.DataTables; --- 23,32 ---- using System; using System.Data; ! ! using QuantProject.Business.DataProviders; ! using QuantProject.Business.Timing; ! using QuantProject.Business.Strategies; ! using QuantProject.Business.Strategies.ReturnsManagement; ! using QuantProject.Business.Strategies.ReturnsManagement.Time; *************** *** 41,59 **** { private int numDaysForReturnCalculation; ! private double shiftedPortfolioRateOfReturn; ! private float[] shiftedPortfolioRatesOfReturn; ! //private double shiftedPortfolioVariance; ! //rate of return and variance of portfolio ! //shifted ahead of numDaysForReturnCalculation ! /// <summary> ! /// Rates of returns of the portfolio shifted ahead of numDaysForReturnCalculation ! /// </summary> ! public float[] ShiftedPortfolioRatesOfReturn ! { ! get{return this.shiftedPortfolioRatesOfReturn;} ! } ! ! public GenomeManagerForEfficientCTCPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, --- 42,48 ---- { private int numDaysForReturnCalculation; ! private ReturnsManager returnsManager; ! public GenomeManagerForEfficientCTCPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, *************** *** 61,65 **** int numDaysForReturnCalculation, double targetPerformance, ! PortfolioType portfolioType) : base(setOfInitialTickers, --- 50,55 ---- int numDaysForReturnCalculation, double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) : base(setOfInitialTickers, *************** *** 68,185 **** numberOfTickersInPortfolio, targetPerformance, ! portfolioType) { ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.retrieveData(); } ! // old implementation, where a "continuos" adjusted close to close ratio, ! // based on a particular fixed interval of days, is considered ! // In this case, there is no discontinuity between the returned ratesOfReturn ! // ! // protected override float[] getArrayOfRatesOfReturn(string ticker) ! // { ! // float[] returnValue = null; ! // Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! // float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); ! // returnValue = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; ! // int i = 0; //index for ratesOfReturns array ! // for(int idx = 0; idx + this.numDaysForReturnCalculation < allAdjValues.Length; idx += this.numDaysForReturnCalculation ) ! // { ! // returnValue[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ ! // allAdjValues[idx] - 1); ! // i++; ! // } ! // this.numberOfExaminedReturns = returnValue.Length; ! // ! // return returnValue; ! // } ! ! // new implementation, where a "discontinuos" adjusted close to close ratio, ! // based on a particular fixed interval of days, is considered ! // In this case, there is a discontinuity between each pair of ratesOfReturn, ! // equal to the given interval of days ! protected override float[] getArrayOfRatesOfReturn(string ticker) { ! this.calculateShiftedRateOfReturn(ticker); ! ! float[] returnValue = null; ! returnValue = ! QuantProject.Data.DataTables.Quotes.GetArrayOfCloseToCloseRatios(ticker, ! ref this.firstQuoteDate, ! this.lastQuoteDate, ! this.numDaysForReturnCalculation); ! ! this.numberOfExaminedReturns = returnValue.Length; ! ! return returnValue; ! } ! /*LPM as fitness ! protected override double getFitnessValue_calculate() ! { ! double returnValue = 0; ! ! double a, b, c; ! a = 0.002; b = 2.0; c = 2.0; ! ! //returnValue = Math.Pow((a/this.Variance),b) * ! // Math.Pow((this.rateOfReturn - this.targetPerformance), ! // c); ! //this.lowerPartialMoment = AdvancedFunctions.LowerPartialMoment(this.portfolioRatesOfReturn, ! // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn), ! // 3.0); ! this.lowerPartialMoment = AdvancedFunctions.NegativeSemiVariance(this.portfolioRatesOfReturn); ! a = 1.0; ! returnValue = Math.Pow((a/this.lowerPartialMoment),b) * ! Math.Pow((this.rateOfReturn - this.targetPerformance), ! c); ! ! if(this.portfolioType == PortfolioType.OnlyShort) ! returnValue = - returnValue; ! ! if(Double.IsInfinity(returnValue) || Double.IsNaN(returnValue)) ! throw new Exception("Fitness value not computed correctly!"); ! ! return returnValue; ! } ! */ ! private void calculateShiftedRateOfReturn(string ticker) ! { ! try ! { ! float[] closeToCloseRatios = Quotes.GetArrayOfCloseToCloseRatios(ticker, ref this.firstQuoteDate, ! this.lastQuoteDate, ! this.numDaysForReturnCalculation, ! this.numDaysForReturnCalculation); ! this.shiftedPortfolioRatesOfReturn = closeToCloseRatios; ! this.shiftedPortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(closeToCloseRatios); ! //this.shiftedPortfolioVariance = ! //BasicFunctions.Variance(closeToCloseRatios); ! } ! catch(Exception ex) ! { ! ex = ex; ! } ! } ! ! protected override double getFitnessValue_calculate() ! { ! // return (this.RateOfReturn/Math.Sqrt(this.Variance))* ! // -this.shiftedPortfolioRateOfReturn * ! // -this.ShiftedPortfolioRatesOfReturn[this.ShiftedPortfolioRatesOfReturn.Length -1]; ! double sharpeRatioWaveUp = this.RateOfReturn/ ! Math.Sqrt(this.Variance); ! double sharpeRatioWaveDown = this.shiftedPortfolioRateOfReturn/ ! Math.Sqrt(BasicFunctions.Variance(this.shiftedPortfolioRatesOfReturn)); ! ! return sharpeRatioWaveUp - sharpeRatioWaveDown; ! ! } ! } - } --- 58,90 ---- 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); ! } } } Index: GenomeManagerForEfficientOTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientOTCPortfolio.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManagerForEfficientOTCPortfolio.cs 14 May 2006 18:36:37 -0000 1.2 --- GenomeManagerForEfficientOTCPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.3 *************** *** 23,32 **** using System; using System.Data; - using System.Collections; - using QuantProject.ADT.Statistics; - using QuantProject.ADT.Optimizing.Genetic; - using QuantProject.Data; - using QuantProject.Data.DataTables; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios --- 23,32 ---- using System; using System.Data; + using QuantProject.Business.DataProviders; + using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; + using QuantProject.Business.Strategies.ReturnsManagement; + using QuantProject.Business.Strategies.ReturnsManagement.Time; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios *************** *** 40,107 **** public class GenomeManagerForEfficientOTCPortfolio : GenomeManagerForEfficientPortfolio { ! ! public GenomeManagerForEfficientOTCPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType) ! :base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType) { ! this.retrieveData(); ! } ! ! protected override float[] getArrayOfRatesOfReturn(string ticker) ! { ! float[] returnValue = null; ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = ExtendedDataTable.GetRatesOfReturnsFromColumns(tickerQuotes, "quClose", "quOpen"); ! this.numberOfExaminedReturns = returnValue.Length; ! ! return returnValue; ! } ! /*using LPM ! protected override double getFitnessValue_calculate() ! { ! double returnValue = 0; ! ! double a, b, c; ! a = 0.002; b = 2.0; c = 2.0; ! ! //returnValue = Math.Pow((a/this.Variance),b) * ! // Math.Pow((this.rateOfReturn - this.targetPerformance), ! // c); ! //this.lowerPartialMoment = AdvancedFunctions.LowerPartialMoment(this.portfolioRatesOfReturn, ! // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn), ! // 3.0); ! this.lowerPartialMoment = AdvancedFunctions.NegativeSemiVariance(this.portfolioRatesOfReturn); ! a = 1.0; ! returnValue = Math.Pow((a/this.lowerPartialMoment),b) * ! Math.Pow(Math.Max(0.0,(this.rateOfReturn - this.targetPerformance)), ! c); ! ! if(this.portfolioType == PortfolioType.OnlyShort) ! returnValue = - returnValue; ! ! if(Double.IsInfinity(returnValue) || Double.IsNaN(returnValue)) ! throw new Exception("Fitness value not computed correctly!"); ! ! return returnValue; } - */ ! protected override double getFitnessValue_calculate() { ! return this.RateOfReturn/Math.Sqrt(this.Variance); } ! } - } --- 40,84 ---- 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); ! } } } Index: GenomeManagerForEfficientOTCCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientOTCCTOPortfolio.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GenomeManagerForEfficientOTCCTOPortfolio.cs 29 Aug 2007 09:56:00 -0000 1.5 --- GenomeManagerForEfficientOTCCTOPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.6 *************** *** 23,31 **** using System; using System.Data; ! using System.Collections; ! using QuantProject.ADT.Statistics; ! using QuantProject.ADT.Optimizing.Genetic; ! using QuantProject.Data; ! using QuantProject.Data.DataTables; --- 23,32 ---- using System; using System.Data; ! ! using QuantProject.Business.DataProviders; ! using QuantProject.Business.Timing; ! using QuantProject.Business.Strategies; ! using QuantProject.Business.Strategies.ReturnsManagement; ! using QuantProject.Business.Strategies.ReturnsManagement.Time; *************** *** 38,44 **** /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCCTOPortfolio : GenomeManagerForWeightedEfficientPortfolio { ! public GenomeManagerForEfficientOTCCTOPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, --- 39,46 ---- /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCCTOPortfolio : GenomeManagerForEfficientPortfolio { ! private ReturnsManager returnsManager; ! public GenomeManagerForEfficientOTCCTOPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, *************** *** 46,50 **** int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType) :base(setOfInitialTickers, firstQuoteDate, --- 48,53 ---- int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) :base(setOfInitialTickers, firstQuoteDate, *************** *** 52,95 **** numberOfTickersInPortfolio, targetPerformance, ! portfolioType) { ! this.retrieveData(); ! } ! ! protected override float[] getArrayOfRatesOfReturn(string ticker) ! { ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! float[] returnValue = new float[2*tickerQuotes.Rows.Count - 1]; ! int j = 0; ! for(int i = 0;i<tickerQuotes.Rows.Count; i++) ! { ! //open to close ! returnValue[j] = (float)tickerQuotes.Rows[i]["quClose"]/ ! (float)tickerQuotes.Rows[i]["quOpen"] - 1; ! //close to open ! if(i<tickerQuotes.Rows.Count-1) ! { ! returnValue[j+1] = ! -(( (float)tickerQuotes.Rows[i+1]["quOpen"]* ! (float)tickerQuotes.Rows[i+1]["quAdjustedClose"]/ ! (float)tickerQuotes.Rows[i+1]["quClose"] ) ! /(float)tickerQuotes.Rows[i]["quAdjustedClose"] - 1); ! } ! j += 2 ; ! } ! this.numberOfExaminedReturns = returnValue.Length; ! return returnValue; } ! ! ! protected override double getFitnessValue_calculate() { ! return this.RateOfReturn/Math.Sqrt(this.Variance); ! //return AdvancedFunctions.GetExpectancyScore(this.PortfolioRatesOfReturn); } ! ! } - } --- 55,102 ---- 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; ! } } } Index: GenomeManagerForWeightedEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForWeightedEfficientPortfolio.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenomeManagerForWeightedEfficientPortfolio.cs 29 Aug 2007 09:54:51 -0000 1.7 --- GenomeManagerForWeightedEfficientPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.8 *************** *** 24,27 **** --- 24,28 ---- using System.Data; using System.Collections; + using QuantProject.ADT; using QuantProject.ADT.Statistics; *************** *** 29,33 **** using QuantProject.Data; using QuantProject.Data.DataTables; ! using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios --- 30,38 ---- using QuantProject.Data; using QuantProject.Data.DataTables; ! using QuantProject.Business.DataProviders; ! using QuantProject.Business.Timing; ! using QuantProject.Business.Strategies; ! using QuantProject.Business.Strategies.ReturnsManagement; ! using QuantProject.Business.Strategies.ReturnsManagement.Time; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios *************** *** 38,43 **** /// </summary> [Serializable] ! public class GenomeManagerForWeightedEfficientPortfolio : GenomeManagerForEfficientPortfolio { public GenomeManagerForWeightedEfficientPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, --- 43,50 ---- /// </summary> [Serializable] ! public abstract class GenomeManagerForWeightedEfficientPortfolio : GenomeManagerForEfficientPortfolio { + private ReturnsManager returnsManager; + public GenomeManagerForWeightedEfficientPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, *************** *** 45,54 **** int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType):base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, targetPerformance, ! portfolioType) { --- 52,62 ---- int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType, ! string benchmark):base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, targetPerformance, ! portfolioType, benchmark) { *************** *** 56,99 **** //at even position the gene is used for finding //the coefficient for the ticker represented at the next odd position ! } ! ! #region override getPortfolioRatesOfReturn ! ! protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) ! { ! double minimumWeight = (1.0 - ConstantsProvider.AmountOfVariableWeightToBeAssignedToTickers)/ ! (genes.Length / 2); ! double totalOfValuesForWeightsInGenes = 0.0; ! for(int j = 0; j<genes.Length; j++) ! { ! if(j%2==0) ! //ticker weight is contained in genes at even position ! totalOfValuesForWeightsInGenes += Math.Abs(genes[j]) + 1.0; ! //0 has to be avoided ! ! } ! double freeWeight = (Math.Abs(genes[tickerPositionInGenes-1]) + 1.0)/totalOfValuesForWeightsInGenes; ! return minimumWeight + freeWeight * (1.0 - minimumWeight * genes.Length / 2); ! } ! ! protected override double[] getPortfolioRatesOfReturn(int[] genes) { ! double[] returnValue = new double[this.numberOfExaminedReturns]; ! for(int i = 0; i<returnValue.Length; i++) ! { ! for(int j = 0; j<genes.Length; j++) ! { ! if(j%2==1) ! //ticker ID is contained in genes at odd position ! returnValue[i] += ! this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(genes,j,i); ! } ! } ! return returnValue; } ! ! #endregion ! #region override Decode public override object Decode(Genome genome) { --- 64,112 ---- //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) + { + double minimumWeight = (1.0 - ConstantsProvider.AmountOfVariableWeightToBeAssignedToTickers)/ + (genes.Length / 2); + double totalOfValuesForWeightsInGenes = 0.0; + for(int j = 0; j<genes.Length; j++) + { + if(j%2==0) + //ticker weight is contained in genes at even position + totalOfValuesForWeightsInGenes += Math.Abs(genes[j]) + 1.0; + //0 has to be avoided ! + } + double freeWeight = (Math.Abs(genes[tickerPositionInGenes-1]) + 1.0)/totalOfValuesForWeightsInGenes; + return minimumWeight + freeWeight * (1.0 - minimumWeight * genes.Length / 2); + } + public override object Decode(Genome genome) { *************** *** 114,123 **** } GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, ! arrayOfTickersWeights, ! this.PortfolioRatesOfReturn[this.portfolioRatesOfReturn.Length - 1], ! this.RateOfReturn, ! this.Variance); return meaning; - } #endregion --- 127,132 ---- } GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, ! arrayOfTickersWeights); return meaning; } #endregion *************** *** 140,144 **** genome.GetMaxValueForGenes(genePosition) + 1); } - return returnValue; } --- 149,152 ---- *************** *** 190,196 **** geneValue + Convert.ToInt32(partOfGeneToSubtractOrAdd*geneValue)); } - return returnValue; - } --- 198,202 ---- *************** *** 245,248 **** } - } --- 251,253 ---- Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** GenomeManagerForEfficientPortfolio.cs 29 Aug 2007 09:56:00 -0000 1.28 --- GenomeManagerForEfficientPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.29 *************** *** 31,36 **** using QuantProject.Data.DataTables; using QuantProject.Business.Strategies; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; - using QuantProject.Scripts.WalkForwardTesting.WalkForwardLag; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios --- 31,36 ---- using QuantProject.Data.DataTables; using QuantProject.Business.Strategies; + using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios *************** *** 41,122 **** /// </summary> [Serializable] ! public class GenomeManagerForEfficientPortfolio : IGenomeManager { protected int genomeSize; protected int minValueForGenes; protected int maxValueForGenes; ! ! protected DataTable setOfTickers;//used only for keeping ! //the same signature for ! //protected retrieveData() method ! protected CandidateProperties[] setOfCandidates; protected int originalNumOfTickers; protected DateTime firstQuoteDate; protected DateTime lastQuoteDate; protected double targetPerformance; ! protected double variance; ! //protected double lowerPartialMoment; ! protected double rateOfReturn; protected PortfolioType portfolioType; ! protected double[] portfolioRatesOfReturn; ! protected int numberOfExaminedReturns; protected GeneticOptimizer currentGeneticOptimizer; - //IGenomeManager implementation for properties public virtual int GenomeSize { get{return this.genomeSize;} } - public virtual int GetMinValueForGenes(int genePosition) { return this.minValueForGenes; } - public virtual int GetMaxValueForGenes(int genePosition) { return this.maxValueForGenes; } ! //end of implementation for properties ! ! public double Variance { ! get{return this.variance;} } ! ! public double RateOfReturn { ! get{return this.rateOfReturn;} } - public PortfolioType PortfolioType { get{return this.portfolioType;} - //set{this.portfolioType = value;} } ! ! public double[] PortfolioRatesOfReturn { ! get{return this.portfolioRatesOfReturn;} } - public DateTime FirstQuoteDate { get{return this.firstQuoteDate;} } - public DateTime LastQuoteDate { get{return this.lastQuoteDate;} } //setOfInitialTickers has to contain the //ticker's symbol in the first column ! - public GenomeManagerForEfficientPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType) { --- 41,108 ---- /// </summary> [Serializable] ! public abstract class GenomeManagerForEfficientPortfolio : IGenomeManager { protected int genomeSize; protected int minValueForGenes; protected int maxValueForGenes; ! protected DataTable setOfTickers; protected int originalNumOfTickers; protected DateTime firstQuoteDate; protected DateTime lastQuoteDate; protected double targetPerformance; ! protected double varianceOfStrategyReturns; ! protected double averageOfStrategyReturns; protected PortfolioType portfolioType; ! protected string benchmark; ! protected float[] strategyReturns; protected GeneticOptimizer currentGeneticOptimizer; + protected WeightedPositions weightedPositionsFromGenome; public virtual int GenomeSize { get{return this.genomeSize;} } public virtual int GetMinValueForGenes(int genePosition) { return this.minValueForGenes; } public virtual int GetMaxValueForGenes(int genePosition) { return this.maxValueForGenes; } ! public double VarianceOfStrategyReturns { ! get{return this.varianceOfStrategyReturns;} } ! public double AverageOfStrategyReturns { ! get{return this.averageOfStrategyReturns;} } public PortfolioType PortfolioType { get{return this.portfolioType;} } ! public float[] StrategyReturns { ! get{return this.strategyReturns;} } public DateTime FirstQuoteDate { get{return this.firstQuoteDate;} } public DateTime LastQuoteDate { get{return this.lastQuoteDate;} } + //setOfInitialTickers has to contain the //ticker's symbol in the first column ! public GenomeManagerForEfficientPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) { *************** *** 130,133 **** --- 116,120 ---- this.genomeSize = numberOfTickersInPortfolio; this.portfolioType = portfolioType; + this.benchmark = benchmark; this.setMinAndMaxValueForGenes(); GenomeManagement.SetRandomGenerator(QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator); *************** *** 157,240 **** } - //this protected method has to be called by inherited genome - //managers (open to close or close to close) - //only after all initializations provided - //by their respective constructors - protected void retrieveData() - { - this.setOfCandidates = new CandidateProperties[setOfTickers.Rows.Count]; - for(int i = 0; i<setOfTickers.Rows.Count; i++) - { - string ticker = (string)setOfTickers.Rows[i][0]; - this.setOfCandidates[i] = new CandidateProperties(ticker, - this.getArrayOfRatesOfReturn(ticker)); - } - } - - //implementation of IGenomeManager - #region GetFitnessValue protected virtual double getFitnessValue_calculate() { ! double returnValue = 0; ! ! NormalDistribution normal = ! new NormalDistribution(this.rateOfReturn, ! Math.Sqrt(this.variance)); ! if(this.portfolioType == PortfolioType.OnlyLong || ! this.portfolioType == PortfolioType.ShortAndLong) ! //the genome fitness is evaluated as if ! //the portfolio was long ! //returnValue = normal.GetProbability(this.targetPerformance*0.75,this.targetPerformance*1.25); ! returnValue = 1.0 - normal.GetProbability(this.targetPerformance); ! else//only short orders are permitted ! //returnValue = normal.GetProbability(-this.targetPerformance*1.25,-this.targetPerformance*0.75); ! returnValue = normal.GetProbability(-this.targetPerformance); ! /*the following code has to be tested ! if(this.currentGeneticOptimizer.AverageRandomFitness != 0.0 && ! this.currentGeneticOptimizer.StandardDeviationOfRandomFitness != 0.0) ! //the two properties remain equal to 0.0 for the GeneticOptimizer ! //instance created in the Run method: the two properties are updated ! //effectively only for the GO instance calling the Run method ! returnValue = (returnValue - this.CurrentGeneticOptimizer.AverageRandomFitness)/ ! this.CurrentGeneticOptimizer.StandardDeviationOfRandomFitness; ! if(returnValue < 0.0) ! returnValue = 0.0; ! //fitness should be now pure positive number ! */ ! return returnValue; ! } public virtual double GetFitnessValue(Genome genome) { double returnValue = 0; ! this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! double averagePortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! ! double portfolioVariance = ! BasicFunctions.Variance(this.portfolioRatesOfReturn); ! if(!Double.IsInfinity(portfolioVariance) && ! !Double.IsInfinity(averagePortfolioRateOfReturn) && ! !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn) && ! portfolioVariance > 0.0) ! //both variance and rate of return are //double values computed in the right way: // so it's possible to assign fitness { - this.variance = portfolioVariance; - this.rateOfReturn = averagePortfolioRateOfReturn; - SignedTickers signedTickers = - new SignedTickers( ((GenomeMeaning)genome.Meaning).Tickers ); - WeightedPositions weightedPositions = - new WeightedPositions( ((GenomeMeaning)genome.Meaning).TickersPortfolioWeights, - signedTickers ); if( this.portfolioType == PortfolioType.OnlyMixed && ! ( weightedPositions.NumberOfLongPositions == 0 || ! weightedPositions.NumberOfShortPositions == 0 ) ) // if both long and short positions have to be taken and // there aren't both long and short positions in portfolio --- 144,186 ---- } #region GetFitnessValue protected virtual double getFitnessValue_calculate() { ! return this.AverageOfStrategyReturns/Math.Sqrt(this.VarianceOfStrategyReturns); } + protected abstract float[] getStrategyReturns(); + + private void setWeightedPositionsFromGenome(Genome genome) + { + GenomeMeaning genomeMeaning = (GenomeMeaning)genome.Meaning; + this.weightedPositionsFromGenome = new WeightedPositions( + genomeMeaning.TickersPortfolioWeights, + new SignedTickers(genomeMeaning.Tickers) ); + } + public virtual double GetFitnessValue(Genome genome) { double returnValue = 0; ! this.setWeightedPositionsFromGenome(genome); ! this.strategyReturns = this.getStrategyReturns(); ! this.averageOfStrategyReturns = ! BasicFunctions.SimpleAverage(this.strategyReturns); ! this.varianceOfStrategyReturns = ! BasicFunctions.Variance(this.strategyReturns); ! if(!Double.IsInfinity(this.VarianceOfStrategyReturns) && ! !Double.IsInfinity(this.AverageOfStrategyReturns) && ! !Double.IsNaN(this.VarianceOfStrategyReturns) && ! !Double.IsNaN(this.AverageOfStrategyReturns) && ! this.VarianceOfStrategyReturns > 0.0) ! //both varianceOfStrate and rate of return are //double values computed in the right way: // so it's possible to assign fitness { if( this.portfolioType == PortfolioType.OnlyMixed && ! ( this.weightedPositionsFromGenome.NumberOfLongPositions == 0 || ! this.weightedPositionsFromGenome.NumberOfShortPositions == 0 ) ) // if both long and short positions have to be taken and // there aren't both long and short positions in portfolio *************** *** 244,278 **** returnValue = this.getFitnessValue_calculate(); } - return returnValue; } ! public virtual double GetFitnessValue(BruteForceOptimizableParameters bruteForceOptimizableParameters) ! { ! double returnValue = 0; ! this.portfolioRatesOfReturn = ! this.getPortfolioRatesOfReturn(bruteForceOptimizableParameters.GetValues()); ! double averagePortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! ! double portfolioVariance = ! BasicFunctions.Variance(this.portfolioRatesOfReturn); ! ! if(!Double.IsInfinity(portfolioVariance) && ! !Double.IsInfinity(averagePortfolioRateOfReturn) && ! !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn) && ! portfolioVariance > 0.0) ! //both variance and rate of return are ! //double values computed in the right way: ! // so it's possible to assign fitness ! { ! this.variance = portfolioVariance; ! this.rateOfReturn = averagePortfolioRateOfReturn; ! returnValue = this.getFitnessValue_calculate(); ! } ! ! return returnValue; ! } #endregion --- 190,223 ---- returnValue = this.getFitnessValue_calculate(); } return returnValue; } ! // public virtual double GetFitnessValue(BruteForceOptimizableParameters bruteForceOptimizableParameters) ! // { ! // double returnValue = 0; ! // this.portfolioRatesOfReturn = ! // this.getPortfolioRatesOfReturn(bruteForceOptimizableParameters.GetValues()); ! // double averagePortfolioRateOfReturn = ! // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! // ! // double portfolioVariance = ! // BasicFunctions.Variance(this.portfolioRatesOfReturn); ! // ! // if(!Double.IsInfinity(portfolioVariance) && ! // !Double.IsInfinity(averagePortfolioRateOfReturn) && ! // !Double.IsNaN(portfolioVariance) && ! // !Double.IsNaN(averagePortfolioRateOfReturn) && ! // portfolioVariance > 0.0) ! // //both variance and rate of return are ! // //double values computed in the right way: ! // // so it's possible to assign fitness ! // { ! // this.variance = portfolioVariance; ! // this.rateOfReturn = averagePortfolioRateOfReturn; ! // returnValue = this.getFitnessValue_calculate(); ! // } ! // ! // return returnValue; ! // } #endregion *************** *** 289,300 **** // the others already stored in the given genome int returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); while( GenomeManipulator.IsTickerContainedInGenome(returnValue,genome) ) //the portfolio can't have a long position and a short one for the same ticker { returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); } - return returnValue; } --- 234,244 ---- // the others already stored in the given genome int returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); while( GenomeManipulator.IsTickerContainedInGenome(returnValue,genome) ) //the portfolio can't have a long position and a short one for the same ticker { returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); } return returnValue; } *************** *** 306,316 **** int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); ! ! while( GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome) ) //the portfolio can't have a long position and a short one for the same ticker { newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); } GenomeManagement.MutateOneGene(genome, genePositionToBeMutated, newValueForGene); --- 250,259 ---- int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); ! while( GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome) ) //the portfolio can't have a long position and a short one for the same ticker { newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); } GenomeManagement.MutateOneGene(genome, genePositionToBeMutated, newValueForGene); *************** *** 319,323 **** #region Decode ! protected string decode_getTickerCodeForLongOrShortTrade(int geneValue) { string initialCharForTickerCode = ""; --- 262,266 ---- #region Decode ! protected virtual string decode_getTickerCodeForLongOrShortTrade(int geneValue) { string initialCharForTickerCode = ""; *************** *** 328,332 **** initialCharForTickerCode = "-"; } ! return initialCharForTickerCode + this.setOfCandidates[position].Ticker; } --- 271,275 ---- initialCharForTickerCode = "-"; } ! return initialCharForTickerCode + (string)setOfTickers.Rows[position][0]; } *************** *** 347,351 **** public virtual object Decode(Genome genome) { - string[] arrayOfTickers = new string[genome.Genes().Length]; int indexOfTicker; --- 290,293 ---- *************** *** 355,369 **** arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } ! GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, ! this.PortfolioRatesOfReturn[this.portfolioRatesOfReturn.Length - 1], ! this.RateOfReturn, ! this.Variance); return meaning; - } #endregion - // end of implementation of IGenomeManager - #region old implementation for variance computation /* --- 297,305 ---- arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } ! GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers); return meaning; } #endregion #region old implementation for variance computation /* *************** *** 412,427 **** #endregion - - //this protected method must be overriden by inherited classes - //specifing the type of rates of return that have to - //be analyzed - protected virtual float[] getArrayOfRatesOfReturn(string ticker) - { - float[] returnValue = null; - this.numberOfExaminedReturns = returnValue.Length; - return returnValue; - - } - protected virtual double getTickerWeight(int[] genes, int tickerPositionInGenes) { --- 348,351 ---- *************** *** 429,473 **** //weights for tickers are all the same in this implementation } - - #region getPortfolioRatesOfReturn - - protected int getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInSetOfCandidates(int geneValueForTickerIdx) - { - int position = geneValueForTickerIdx; - if(geneValueForTickerIdx < 0) - position = Math.Abs(geneValueForTickerIdx) - 1; - return position; - } - - protected float getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(int[] genes, - int tickerPositionInGenes, - int arrayElementPosition) - { - bool longReturns = false; - if(genes[tickerPositionInGenes] >= 0) - //genes[tickerPositionInGenes], the code for ticker, points to a ticker for which long returns are to be examined - longReturns = true; - int position = this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInSetOfCandidates(genes[tickerPositionInGenes]); - this.setOfCandidates[position].LongRatesOfReturn = longReturns; - float[] arrayOfRatesOfReturn = this.setOfCandidates[position].ArrayOfRatesOfReturn; - double tickerWeight = this.getTickerWeight(genes,tickerPositionInGenes); - return (arrayOfRatesOfReturn[arrayElementPosition]*(float)tickerWeight); - } - - protected virtual double[] getPortfolioRatesOfReturn(int[] genes) - { - double[] returnValue = new double[this.numberOfExaminedReturns]; - for(int i = 0; i<returnValue.Length; i++) - { - for(int j=0; j<genes.Length; j++) - returnValue[i] += - this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(genes,j,i); - } - return returnValue; - } - - #endregion - } - } --- 353,356 ---- |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:38:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedPeriodOscillators In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21302/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedPeriodOscillators Modified Files: GenomeManagerForFPOscillatorCTC.cs Log Message: GenomeManagers have been updated (WeightedPositions have been used instead of CandidateProperties) Index: GenomeManagerForFPOscillatorCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedPeriodOscillators/GenomeManagerForFPOscillatorCTC.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenomeManagerForFPOscillatorCTC.cs 14 May 2006 15:29:22 -0000 1.1 --- GenomeManagerForFPOscillatorCTC.cs 14 Jan 2008 23:38:36 -0000 1.2 *************** *** 24,31 **** --- 24,37 ---- using System.Data; using System.Collections; + using QuantProject.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; + using QuantProject.Business.DataProviders; + using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; + using QuantProject.Business.Strategies.ReturnsManagement; + using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; *************** *** 41,44 **** --- 47,51 ---- { private int numDaysForReturnCalculation; + private ReturnsManager returnsManager; public GenomeManagerForFPOscillatorCTC(DataTable setOfInitialTickers, *************** *** 47,51 **** int numberOfTickersInPortfolio, int numDaysForReturnCalculation, ! PortfolioType portfolioType) : base(setOfInitialTickers, --- 54,59 ---- int numberOfTickersInPortfolio, int numDaysForReturnCalculation, ! PortfolioType portfolioType, ! string benchmark) : base(setOfInitialTickers, *************** *** 54,226 **** numberOfTickersInPortfolio, 0.0, ! portfolioType) { this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.retrieveData(); ! } ! ! private float[] getArrayOfRatesOfReturn_getAdjustedArray(Quotes sourceQuotes, ! int numDaysForHalfPeriod, ! ref DateTime firstQuoteDate) ! { ! float[] returnValue = ExtendedDataTable.GetArrayOfFloatFromColumn(sourceQuotes, ! Quotes.AdjustedCloseToCloseRatio); ! for(int i = 0;i<returnValue.Length;i++) ! returnValue[i] = returnValue[i]-1; ! //in order to be alligned at the following market day, ! //the array has to be long n, where n is such that ! //n%(2 * hp) + 1 = 2 * hp (hp = half period) ! //if some rates are deleted, first quote day has to be updated ! while( (returnValue.Length + 1) % (2*numDaysForHalfPeriod) != 0) ! { ! float[] newReturnValue = new float[returnValue.Length - 1]; ! for(int k = 0;k<returnValue.Length - 1;k++) ! newReturnValue[k] = returnValue[k + 1]; ! returnValue = newReturnValue; ! firstQuoteDate = firstQuoteDate.AddDays(1); ! firstQuoteDate = sourceQuotes.GetQuoteDateOrFollowing(firstQuoteDate); ! } ! ! return returnValue; ! } ! ! protected override float[] getArrayOfRatesOfReturn(string ticker) ! { ! float[] returnValue = null; ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = this.getArrayOfRatesOfReturn_getAdjustedArray(tickerQuotes, this.numDaysForReturnCalculation, ! ref this.firstQuoteDate); ! this.numberOfExaminedReturns = returnValue.Length; ! ! return returnValue; ! } ! ! // //implementation with fitness as average of modified sh for single tickers ! // private double getFitnessValue_getModifiedSharpeRatioForTicker(int[] genes, ! // int tickerPositionInGenes) ! // { ! // bool longReturns = false; ! // if(genes[tickerPositionInGenes] > 0) ! // //genes[tickerPositionInGenes], the code for ticker, points to a ticker for which long returns are to be examined ! // longReturns = true; ! // int position = this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(genes[tickerPositionInGenes]); ! // this.setOfCandidates[position].LongRatesOfReturn = longReturns; ! // float[] arrayOfRatesOfReturn = this.setOfCandidates[position].ArrayOfRatesOfReturn; ! // float[] strategyReturns = new float[arrayOfRatesOfReturn.Length]; ! // float sign = 1.0F; ! // for(int i=0; i<arrayOfRatesOfReturn.Length; i++) ! // { ! // if(i > 0 && (i % this.numDaysForReturnCalculation == 0) ) ! // sign = -sign; ! // ! // strategyReturns[i] = sign * arrayOfRatesOfReturn[i]; ! // } ! // double stdDev = BasicFunctions.StdDev(strategyReturns); ! // double powerForStdDev = 2.0; ! // ! // return BasicFunctions.SimpleAverage(strategyReturns)/ ! // Math.Pow(stdDev, powerForStdDev); ! // } ! // ! //// new implementation: fitness is the averaged sum of the "modified" sharpeRatios ! //// for each single ticker ! // public override double GetFitnessValue(Genome genome) ! // { ! // double returnValue = 0.0; ! // for(int i = 0; i<genome.Size; i++) ! // { ! // returnValue += this.getFitnessValue_getModifiedSharpeRatioForTicker( genome.Genes(),i ); ! // } ! // return returnValue/genome.Size; ! // } ! ! public override object Decode(Genome genome) ! { ! ! string[] arrayOfTickers = new string[genome.Genes().Length]; ! int indexOfTicker; ! for(int index = 0; index < genome.Genes().Length; index++) ! { ! indexOfTicker = (int)genome.Genes().GetValue(index); ! arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); ! } ! GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers); ! return meaning; } ! //OLD IMPLEMENTATION - linear combination ! public override double GetFitnessValue(Genome genome) { ! double returnValue = 0.0; ! this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! ! double[] oscillatorPortfolioRatesOfReturn = this.getFitnessValue_getOscillatorRates(); ! ! double averageOscillatorPortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(oscillatorPortfolioRatesOfReturn); ! ! double oscillatorPortfolioStdDev = ! BasicFunctions.StdDev(oscillatorPortfolioRatesOfReturn); ! ! returnValue = averageOscillatorPortfolioRateOfReturn / ! Math.Pow(oscillatorPortfolioStdDev,1.2); ! ! return returnValue; } ! private double[] getFitnessValue_getOscillatorRates() ! { ! double[] returnValue = new double[this.PortfolioRatesOfReturn.Length]; ! double sign = 1.0; ! for(int i = 0;i<this.PortfolioRatesOfReturn.Length; i++) { ! if(i > 0 && (i % this.numDaysForReturnCalculation == 0) ) ! sign = -sign; ! returnValue[i] = sign*this.PortfolioRatesOfReturn[i]; } - return returnValue; ! } ! ! //new implementation: changed how fitness is computed ! //now it is the sharpe ratio for the equity line resulting ! //from applying the strategy ! // public override double GetFitnessValue(Genome genome) ! // { ! // double returnValue = 0.0; ! // this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! // ! // double[] equityLine = this.getFitnessValue_getEquityLineRates(); ! // ! // double averageEquityLineRateOfReturn = ! // BasicFunctions.SimpleAverage(equityLine); ! // ! // double equityLineStdDev = ! // BasicFunctions.StdDev(equityLine); ! // ! // returnValue = averageEquityLineRateOfReturn / ! // Math.Pow(equityLineStdDev,2.0); ! // ! // return returnValue; ! // } ! // ! // private double[] getFitnessValue_getEquityLineRates() ! // { ! // double[] returnValue = new double[this.PortfolioRatesOfReturn.Length]; ! // double sign = 1.0; ! // for(int i = this.numDaysForReturnCalculation - 1; ! // i<this.PortfolioRatesOfReturn.Length; ! // i++) ! // { ! // // if gain of last half period is negative, ! // // then add to the array the returns of the second half ! // } ! // ! // return returnValue; ! // } ! ! } ! } --- 62,112 ---- numberOfTickersInPortfolio, 0.0, ! 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() ); } ! private float[] getStrategyReturns_getReturnsActually( ! float[] plainReturns) ! { ! float[] returnValue = new float[plainReturns.Length]; ! for(int i = 0; i < returnValue.Length; i++) { ! if( i%2 == 0 ) ! //even periods are expected to have the same sign as plain ctc returns ! returnValue[i] = plainReturns[i]; ! else//odd periods are reversed ! returnValue[i] = - plainReturns[i]; } return returnValue; ! } ! ! protected override float[] getStrategyReturns() ! { ! float[] plainReturns = ! this.weightedPositionsFromGenome.GetReturns( ! this.returnsManager); ! return this.getStrategyReturns_getReturnsActually(plainReturns); ! } ! } } |
|
From: Marco M. <mi...@us...> - 2008-01-14 23:38:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21302/b7_Scripts/TickerSelectionTesting/TestingOTCTypes Modified Files: GenomeManagerForEfficientOTCTypes.cs Log Message: GenomeManagers have been updated (WeightedPositions have been used instead of CandidateProperties) Index: GenomeManagerForEfficientOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/GenomeManagerForEfficientOTCTypes.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManagerForEfficientOTCTypes.cs 14 May 2006 18:36:37 -0000 1.2 --- GenomeManagerForEfficientOTCTypes.cs 14 Jan 2008 23:38:36 -0000 1.3 *************** *** 38,44 **** /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCTypes : GenomeManagerForEfficientPortfolio { ! private GenomeManagerForEfficientCTOPortfolio genManCTO; public GenomeManagerForEfficientOTCTypes(DataTable setOfInitialTickers, DateTime firstQuoteDate, --- 38,46 ---- /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCTypes : GenomeManagerForEfficientOTCCTOPortfolio { ! // private GenomeManagerForEfficientCTOPortfolio genManCTO; ! // private string benchmark; ! public GenomeManagerForEfficientOTCTypes(DataTable setOfInitialTickers, DateTime firstQuoteDate, *************** *** 46,50 **** int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType) :base(setOfInitialTickers, firstQuoteDate, --- 48,53 ---- int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) :base(setOfInitialTickers, firstQuoteDate, *************** *** 52,115 **** numberOfTickersInPortfolio, targetPerformance, ! portfolioType) { ! this.retrieveData(); ! this.genManCTO = new GenomeManagerForEfficientCTOPortfolio(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType); } //rate of return = rawClose/rawOpen - 1 ! protected override float[] getArrayOfRatesOfReturn(string ticker) ! { ! float[] returnValue = null; ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = ExtendedDataTable.GetRatesOfReturnsFromColumns(tickerQuotes, "quClose", "quOpen"); ! this.numberOfExaminedReturns = returnValue.Length; ! ! return returnValue; ! } ! ! public override double GetFitnessValue(Genome genome) ! { ! double returnValue = 0; ! this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! double averagePortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! ! double portfolioVariance = ! BasicFunctions.Variance(this.portfolioRatesOfReturn); ! ! if(!Double.IsInfinity(portfolioVariance) && ! !Double.IsInfinity(averagePortfolioRateOfReturn) && ! !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn) && ! portfolioVariance > 0.0) ! //both variance and rate of return are ! //double values computed in the right way: ! // so it's possible to assign fitness ! { ! this.variance = portfolioVariance; ! this.rateOfReturn = averagePortfolioRateOfReturn; ! //returnValue = this.getFitnessValue_calculate(); ! returnValue = this.getFitnessValue_calculate() - ! this.genManCTO.GetFitnessValue(genome); ! ! } ! ! return returnValue; ! } ! ! ! protected override double getFitnessValue_calculate() ! { ! return this.RateOfReturn/Math.Sqrt(this.Variance); ! } ! ! ! } ! } --- 55,118 ---- numberOfTickersInPortfolio, targetPerformance, ! portfolioType, ! benchmark) { ! // this.benchmark = benchmark; ! // this.retrieveData(); ! // this.genManCTO = new GenomeManagerForEfficientCTOPortfolio(setOfInitialTickers, ! // firstQuoteDate, ! // lastQuoteDate, ! // numberOfTickersInPortfolio, ! // targetPerformance, ! // portfolioType, ! // benchmark); } //rate of return = rawClose/rawOpen - 1 ! // protected override float[] getArrayOfRatesOfReturn(string ticker) ! // { ! // float[] returnValue = null; ! // Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! // returnValue = ExtendedDataTable.GetRatesOfReturnsFromColumns(tickerQuotes, "quClose", "quOpen"); ! // this.numberOfExaminedReturns = returnValue.Length; ! // ! // return returnValue; ! // } ! // ! // public override double GetFitnessValue(Genome genome) ! // { ! // double returnValue = 0; ! // this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! // double averagePortfolioRateOfReturn = ! // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! // ! // double portfolioVariance = ! // BasicFunctions.Variance(this.portfolioRatesOfReturn); ! // ! // if(!Double.IsInfinity(portfolioVariance) && ! // !Double.IsInfinity(averagePortfolioRateOfReturn) && ! // !Double.IsNaN(portfolioVariance) && ! // !Double.IsNaN(averagePortfolioRateOfReturn) && ! // portfolioVariance > 0.0) ! // //both variance and rate of return are ! // //double values computed in the right way: ! // // so it's possible to assign fitness ! // { ! // this.variance = portfolioVariance; ! // this.rateOfReturn = averagePortfolioRateOfReturn; ! // //returnValue = this.getFitnessValue_calculate(); ! // returnValue = this.getFitnessValue_calculate() - ! // this.genManCTO.GetFitnessValue(genome); ! // ! // } ! // ! // return returnValue; ! // } ! // ! // ! // protected override double getFitnessValue_calculate() ! // { ! // return this.RateOfReturn/Math.Sqrt(this.Variance); ! // } ! } } |