quantproject-developers Mailing List for QuantProject (Page 55)
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-02-27 21:16:58
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv20779 Added Files: PairsTradingLogItem.cs Log Message: Log item for the Pairs Trading strategy --- NEW FILE: PairsTradingLogItem.cs --- /* QuantProject - Quantitative Finance Library PairsTradingLogItem.cs Copyright (C) 2008 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.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; using QuantProject.Scripts.General.Reporting; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading { /// <summary> /// Log item for the Pairs Trading strategy /// </summary> [Serializable] public class PairsTradingLogItem : LogItem { private TestingPositions[] bestTestingPositionsInSample; private int numberOfEligibleTickers; // public TestingPositions BestTestingPositionsInSample // { // set { this.bestTestingPositionsInSample = value; } // } // public WeightedPositions BestWeightedPositionsInSample // { // get // { // return this.bestTestingPositionsInSample.WeightedPositions; // } // } public int NumberOfEligibleTickers { get { return this.numberOfEligibleTickers; } } public PairsTradingLogItem( EndOfDayDateTime endOfDayDateTime , TestingPositions[] bestTestingPositionsInSample , int numberOfEligibleTickers ) : base( endOfDayDateTime ) { this.numberOfEligibleTickers = int.MinValue; this.bestTestingPositionsInSample = bestTestingPositionsInSample; this.numberOfEligibleTickers = numberOfEligibleTickers; } public override void Run() { // string backTestId = "SimpleFLTP"; // double cashToStart = 30000; // // Benchmark benchmark = new Benchmark( "MSFT" ); // // IHistoricalQuoteProvider historicalQuoteProvider = // new HistoricalAdjustedQuoteProvider(); // // IInSampleChooser inSampleChooser = // (IInSampleChooser)new ConstantWeightedPositionsChooser( this.BestWeightedPositionsInSample ); // // IIntervalsSelector intervalsSelector = // new FixedLengthTwoPhasesIntervalsSelector( // 1 , 1 , benchmark ); // IEligiblesSelector eligiblesSelector = new DummyEligibleSelector(); // // FixedLengthTwoPhasesStrategy fixedLengthTwoPhasesStrategy = // new FixedLengthTwoPhasesStrategy( // this.BestWeightedPositionsInSample.Count , // 9999 , 9 , benchmark , intervalsSelector , // eligiblesSelector , inSampleChooser , historicalQuoteProvider ); // // DateTime firstDateTime = this.simulatedCreationTime.DateTime.AddDays( -90 ); // DateTime lastDateTime = this.simulatedCreationTime.DateTime; // double maxRunningHours = 0.3; // EndOfDayStrategyBackTester endOfDayStrategyBackTester = // new EndOfDayStrategyBackTester( // backTestId , fixedLengthTwoPhasesStrategy , // historicalQuoteProvider , firstDateTime , // lastDateTime , benchmark , cashToStart , maxRunningHours ); // // fixedLengthTwoPhasesStrategy.Account = endOfDayStrategyBackTester.Account; // // endOfDayStrategyBackTester.Run(); // BackTesterReportViewer.ShowReport( lastDateTime , // endOfDayStrategyBackTester ); } } } |
|
From: Glauco S. <gla...@us...> - 2008-02-27 21:16:38
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/Genetic In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv20739 Added Files: PairsTradingGeneticChooser.cs Log Message: genetic IInSampleChooser for the pairs trading strategy --- NEW FILE: PairsTradingGeneticChooser.cs --- /* QuantProject - Quantitative Finance Library PairsTradingGeneticChooser.cs Copyright (C) 2008 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.Optimizing.GenomeManagers; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading { /// <summary> /// genetic IInSampleChooser for the pairs trading strategy /// </summary> public class PairsTradingGeneticChooser : GeneticChooser { public PairsTradingGeneticChooser( int numberOfBestTestingPositionsToBeReturned , Benchmark benchmark , IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , IHistoricalQuoteProvider historicalQuoteProvider , double crossoverRate , double mutationRate , double elitismRate , int populationSizeForGeneticOptimizer , int generationNumberForGeneticOptimizer , int seedForRandomGenerator ) : base( 2 , numberOfBestTestingPositionsToBeReturned , benchmark , decoderForTestingPositions , fitnessEvaluator , historicalQuoteProvider , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , seedForRandomGenerator ) { // // TODO: Add constructor logic here // } protected override IGenomeManager getGenomeManager( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { GenomeManagerWithDuplicateGenes genomeManagerWithDuplicateGenes = new GenomeManagerWithDuplicateGenes( 2 , eligibleTickers , returnsManager , this.decoderForTestingPositions , this.fitnessEvaluator , GenomeManagerType.ShortAndLong , this.seedForRandomGenerator ); return genomeManagerWithDuplicateGenes; } protected override string getHashCodeForGenome( Genome genome ) { return ((TestingPositions)(genome.Meaning)).HashCodeForTickerComposition; } } } |
|
From: Glauco S. <gla...@us...> - 2008-02-27 21:15:32
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/Genetic In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv20330/Genetic Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers/Genetic added to the repository |
|
From: Glauco S. <gla...@us...> - 2008-02-27 21:15:12
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv20178 Added Files: PairsTradingFitnessEvaluator.cs Log Message: Evaluates (in sample) the Pearson Correlation between two weighted positions --- NEW FILE: PairsTradingFitnessEvaluator.cs --- /* QuantProject - Quantitative Finance Library PairsTradingFitnessEvaluator.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.Statistics; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.ReturnsManagement; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading { /// <summary> /// Evaluates (in sample) the Pearson Correlation /// between two weighted positions /// </summary> public class PairsTradingFitnessEvaluator : IFitnessEvaluator { public string Description { get { return "pearsonCrrltn"; } } public PairsTradingFitnessEvaluator() { } #region GetFitnessValue private void getFitnessValue_checkParameters( object meaning ) { if ( !( meaning is TestingPositions ) ) throw new Exception( "The meaning should always be a TestingPositions!" ); } private void getFitnessValue_checkWeightedPositions( WeightedPositions weightedPositions ) { if ( weightedPositions.Count != 2 ) throw new Exception( "This fitness evaluatore requires " + "two positions!" ); } private double getFitnessValue( WeightedPosition firstPosition , WeightedPosition secondPosition , ReturnsManager returnsManager ) { float[] firstPositionReturns = returnsManager.GetReturns( firstPosition.Ticker ); float[] secondPositionReturns = returnsManager.GetReturns( secondPosition.Ticker ); double fitnessValue = BasicFunctions.PearsonCorrelationCoefficient( firstPosition.Weight , firstPositionReturns , secondPosition.Weight , secondPositionReturns ); return fitnessValue; } private double getFitnessValue( WeightedPositions weightedPositions , ReturnsManager returnsManager ) { this.getFitnessValue_checkWeightedPositions( weightedPositions ); WeightedPosition firstPosition = weightedPositions[ 0 ]; WeightedPosition secondPosition = weightedPositions[ 1 ]; double fitnessValue = this.getFitnessValue( firstPosition , secondPosition , returnsManager ); return fitnessValue; } private double getFitnessValue( TestingPositions testingPositions , ReturnsManager returnsManager ) { double fitnessValue; WeightedPositions weightedPositions = testingPositions.WeightedPositions; if ( weightedPositions == null ) // the current optimization's candidate contains // two genes that decode to the same tickers fitnessValue = -0.4; else // for the current optimization's candidate, // all positions's tickers are distinct fitnessValue = this.getFitnessValue( weightedPositions , returnsManager ); return fitnessValue; } public double GetFitnessValue( object meaning , ReturnsManager returnsManager ) { this.getFitnessValue_checkParameters( meaning ); double fitnessValue = this.getFitnessValue( (TestingPositions)meaning , returnsManager ); return fitnessValue; } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2008-02-27 21:14:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19898/InSampleChoosers Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample/InSampleChoosers added to the repository |
|
From: Glauco S. <gla...@us...> - 2008-02-27 21:14:23
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19881/Logging Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Logging added to the repository |
|
From: Glauco S. <gla...@us...> - 2008-02-27 21:14:06
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19505/InSample Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/InSample added to the repository |
|
From: Glauco S. <gla...@us...> - 2008-02-27 21:12:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19072 Added Files: PairsTradingStrategy.cs Log Message: Pairs Trading strategy with in sample optimizations --- NEW FILE: PairsTradingStrategy.cs --- /* QuantProject - Quantitative Finance Library PairsTradingStrategy.cs Copyright (C) 2008 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.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading { /// <summary> /// Pairs Trading strategy with in sample optimizations /// </summary> public class PairsTradingStrategy : BasicEndOfDayStrategyForBacktester { // private WeightedPositions positionsToBeOpened; private double minThresholdForGoingLong, maxThresholdForGoingLong, minThresholdForGoingShort, maxThresholdForGoingShort; private HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider; public PairsTradingStrategy( int numDaysBeetweenEachOtpimization , int numDaysForInSampleOptimization , IIntervalsSelector intervalsSelector , IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , IHistoricalQuoteProvider historicalQuoteProvider , double minThresholdForGoingLong , double maxThresholdForGoingLong , double minThresholdForGoingShort , double maxThresholdForGoingShort ) : base( numDaysBeetweenEachOtpimization , numDaysForInSampleOptimization , intervalsSelector , eligiblesSelector , inSampleChooser , historicalQuoteProvider ) { this.minThresholdForGoingLong = minThresholdForGoingLong; this.maxThresholdForGoingLong = maxThresholdForGoingLong; this.minThresholdForGoingShort = minThresholdForGoingShort; this.maxThresholdForGoingShort = maxThresholdForGoingShort; this.historicalAdjustedQuoteProvider = new HistoricalAdjustedQuoteProvider(); } protected override string getTextIdentifier() { return "pairsTrdng"; } private bool arePositionsToBeClosed() { bool endsTheLastInterval = ( this.now().IsEqualTo( this.lastIntervalAppended().End ) ); return ( endsTheLastInterval ); } protected override bool marketOpenEventHandler_arePositionsToBeOpened() { return this.arePositionsToBeOpened(); } protected override bool marketCloseEventHandler_arePositionsToBeOpened() { return this.arePositionsToBeOpened(); } private bool arePositionsToBeOpened() { bool beginsTheLastInterval = ( this.now().IsEqualTo( this.lastIntervalAppended().Begin ) ); return ( beginsTheLastInterval ); } #region getPositionsToBeOpened #region getReturnsManagerForLastSecondPhaseInterval private EndOfDayDateTime getIntervalBeginForLastSecondPhaseInterval() { // this method will be invoked only if (this.returnIntervals.Count >= 2) int secondLastIntervalIndex = this.returnIntervals.Count - 2; ReturnInterval secondLastInterval = this.returnIntervals[ secondLastIntervalIndex ]; return secondLastInterval.End; } private EndOfDayDateTime getIntervalEndForLastSecondPhaseInterval() { return this.lastIntervalAppended().Begin; } private ReturnInterval getReturnIntervalForLastSecondPhaseInterval() { EndOfDayDateTime intervalBegin = this.getIntervalBeginForLastSecondPhaseInterval(); EndOfDayDateTime intervalEnd = this.getIntervalEndForLastSecondPhaseInterval(); ReturnInterval returnIntervalForLastSecondPhaseInterval = new ReturnInterval( intervalBegin , intervalEnd ); return returnIntervalForLastSecondPhaseInterval; } private ReturnIntervals getReturnIntervalsForLastSecondPhaseInterval() { ReturnInterval returnIntervalForLastSecondPhaseInterval = this.getReturnIntervalForLastSecondPhaseInterval(); ReturnIntervals returnIntervalsForLastSecondPhaseInterval = new ReturnIntervals( returnIntervalForLastSecondPhaseInterval ); return returnIntervalsForLastSecondPhaseInterval; } private ReturnsManager getReturnsManagerForLastSecondPhaseInterval() { ReturnIntervals returnIntervals = this.getReturnIntervalsForLastSecondPhaseInterval(); ReturnsManager returnsManager = new ReturnsManager( returnIntervals , this.historicalAdjustedQuoteProvider ); return returnsManager; } #endregion getReturnsManagerForLastSecondPhaseInterval private double getReturnForTheLastSecondPhaseInterval( ReturnsManager returnsManager , WeightedPositions weightedPositions ) { // returnsManager should contain a single ReturnInterval, and // this ReturnInterval should be the last second phase interval double returnForTheLastSecondPhaseInterval = weightedPositions.GetReturn( 0 , returnsManager ); return returnForTheLastSecondPhaseInterval; } // if the currentWeightedPositions' return satisfies the thresholds // then this method returns the WeightedPositions to be opened. // Otherwise (currentWeightedPositions' return does NOT // satisfy the thresholds) this method returns null private WeightedPositions getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( ReturnsManager returnsManager , WeightedPositions currentWeightedPositions ) { WeightedPositions weightedPositionsToBeOpened = null; try { double returnForTheLastSecondPhaseInterval = this.getReturnForTheLastSecondPhaseInterval( returnsManager , currentWeightedPositions ); if ( ( returnForTheLastSecondPhaseInterval >= this.minThresholdForGoingLong ) && ( returnForTheLastSecondPhaseInterval <= this.maxThresholdForGoingLong ) ) // it looks like there has been an inefficiency that // might be recovered, by going short weightedPositionsToBeOpened = currentWeightedPositions.Opposite; if ( ( -returnForTheLastSecondPhaseInterval >= this.minThresholdForGoingShort ) && ( -returnForTheLastSecondPhaseInterval <= this.maxThresholdForGoingShort ) ) // it looks like there has been an inefficiency that // might be recovered, by going long weightedPositionsToBeOpened = currentWeightedPositions; } catch( TickerNotExchangedException ex ) { string dummy = ex.Message; } return weightedPositionsToBeOpened; } private WeightedPositions getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( ReturnsManager returnsManager , int currentTestingPositionsIndex ) { WeightedPositions currentWeightedPositions = this.bestTestingPositionsInSample[ currentTestingPositionsIndex ].WeightedPositions; WeightedPositions weightedPositionsToBeOpended = this.getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( returnsManager , currentWeightedPositions ); return weightedPositionsToBeOpended; } protected WeightedPositions getPositionsToBeOpened( ReturnsManager returnsManager ) { WeightedPositions weightedPositionsToBeOpended = null; int currentTestingPositionsIndex = 0; while ( ( weightedPositionsToBeOpended == null ) && ( currentTestingPositionsIndex < this.bestTestingPositionsInSample.Length ) ) { weightedPositionsToBeOpended = this.getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( returnsManager , currentTestingPositionsIndex ); currentTestingPositionsIndex++; } return weightedPositionsToBeOpended; } private WeightedPositions getPositionsToBeOpened_withAtLeastASecondPhaseInterval() { ReturnsManager returnsManager = this.getReturnsManagerForLastSecondPhaseInterval(); return this.getPositionsToBeOpened( returnsManager ); } protected WeightedPositions getPositionsToBeOpened() { WeightedPositions weightedPositions = null; if ( this.returnIntervals.Count >= 2 ) // at least a second phase interval exists weightedPositions = this.getPositionsToBeOpened_withAtLeastASecondPhaseInterval(); return weightedPositions; } #endregion protected override WeightedPositions marketOpenEventHandler_getPositionsToBeOpened() { return this.getPositionsToBeOpened(); } protected override WeightedPositions marketCloseEventHandler_getPositionsToBeOpened() { return this.getPositionsToBeOpened(); } protected override bool marketOpenEventHandler_arePositionsToBeClosed() { return this.arePositionsToBeClosed(); } protected override bool marketCloseEventHandler_arePositionsToBeClosed() { return this.arePositionsToBeClosed(); } protected override LogItem getLogItem( EligibleTickers eligibleTickers ) { PairsTradingLogItem logItem = new PairsTradingLogItem( this.now() , this.bestTestingPositionsInSample , eligibleTickers.Count ); // logItem.BestWeightedPositionsInSample = // this.bestTestingPositionsInSample.WeightedPositions; // logItem.NumberOfEligibleTickers = // eligibleTickers.Count; return logItem; } } } |
|
From: Glauco S. <gla...@us...> - 2008-02-27 21:12:07
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18673 Added Files: PairsTradingMain.cs Log Message: Entry point for the PairsTradingMain strategy. If any strategy parameter had to be changed, this is the place where it should be done --- NEW FILE: PairsTradingMain.cs --- /* QuantProject - Quantitative Finance Library PairsTradingMain.cs Copyright (C) 2008 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; using QuantProject.Presentation; using QuantProject.Scripts.General.Logging; using QuantProject.Scripts.General.Reporting; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading { /// <summary> /// Entry point for the PairsTradingMain strategy. If any strategy /// parameter had to be changed, this is the place where it should /// be done /// </summary> public class PairsTradingMain { public PairsTradingMain() { } #region Run private MessageManager setMessageManager( IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , IEndOfDayStrategyForBacktester endOfDayStrategy , EndOfDayStrategyBackTester endOfDayStrategyBackTester ) { string dateStamp = ExtendedDateTime.GetCompleteShortDescriptionForFileName( DateTime.Now ); MessageManager messageManager = new MessageManager( "NotificationMessagesForCurrentStrategy_" + dateStamp + ".Txt" ); messageManager.Monitor( eligiblesSelector ); messageManager.Monitor( inSampleChooser ); messageManager.Monitor( endOfDayStrategy ); messageManager.Monitor( endOfDayStrategyBackTester ); return messageManager; } private void saveLog( BackTestLog backTestLog , string suggestedLogFileName ) { string defaultFolderPath = "C:\\qpReports\\"; // this.wFLagLog.TransactionHistory = this.account.Transactions; LogArchiver.Save( backTestLog , suggestedLogFileName , defaultFolderPath ); } public void Run1() { BackTestLog backTestLog = LogArchiver.Load( "C:\\qpReports\\" ); LogViewer logViewer = new LogViewer( backTestLog ); logViewer.Show(); } public void Run() { string backTestId = "PairsTrading"; double cashToStart = 30000; int inSampleDays = 90; string tickersGroupId = "SP500"; // uncomment the following two lines for faster scripts // int inSampleDays = 30; // string tickersGroupId = "fastTest"; Benchmark benchmark = new Benchmark( "MSFT" ); int maxNumberOfEligiblesToBeChosen = 100; IDecoderForTestingPositions decoderForWeightedPositions = new DecoderForTestingPositionsWithBalancedWeights(); IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); // definition for the Fitness Evaluator // IEquityEvaluator equityEvaluator = new SharpeRatio(); IFitnessEvaluator fitnessEvaluator = new PairsTradingFitnessEvaluator(); // parameters for the genetic optimizer double crossoverRate = 0.85; double mutationRate = 0.02; double elitismRate = 0.001; int populationSizeForGeneticOptimizer = 20000; int generationNumberForGeneticOptimizer = 8; int seedForRandomGenerator = QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; IInSampleChooser inSampleChooser = new PairsTradingGeneticChooser( 10 , benchmark , decoderForWeightedPositions , fitnessEvaluator , historicalQuoteProvider , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , seedForRandomGenerator ); // IIntervalsSelector intervalsSelector = // new FixedLengthTwoPhasesIntervalsSelector( // 1 , 1 , benchmark ); IIntervalsSelector intervalsSelector = new OddIntervalsSelector( 1 , 1 , benchmark ); IEligiblesSelector eligiblesSelector = new MostLiquidAndLessVolatile( tickersGroupId , maxNumberOfEligiblesToBeChosen ); PairsTradingStrategy pairsTradingStrategy = new PairsTradingStrategy( 7 , inSampleDays , intervalsSelector , eligiblesSelector , inSampleChooser , historicalQuoteProvider , 0.003 , 0.99 , 0.003 , 0.99 ); DateTime firstDateTime = new DateTime( 2002 , 1 , 29 ); DateTime lastDateTime = new DateTime( 2002 , 2 , 28 ); double maxRunningHours = 8; EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( backTestId , pairsTradingStrategy , historicalQuoteProvider , firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); // TO DO check if you can do this assign in the EndOfDayStrategyBackTester // constructor pairsTradingStrategy.Account = endOfDayStrategyBackTester.Account; MessageManager messageManager = this.setMessageManager( eligiblesSelector , inSampleChooser , pairsTradingStrategy , endOfDayStrategyBackTester ); endOfDayStrategyBackTester.Run(); BackTesterReportViewer.ShowReport( lastDateTime , endOfDayStrategyBackTester ); this.saveLog( endOfDayStrategyBackTester.Log , endOfDayStrategyBackTester.Description ); } #endregion Run } } |
|
From: Marco M. <mi...@us...> - 2008-02-25 23:09:08
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18908/a2_Strategies/InSample Modified Files: GeneticChooser.cs Log Message: Deleted an obsolete field; the abstract method setGenomeManager has been changed (it was void; now it has to return a IGenomeManager object; its name is now getGenomeManager) Index: GeneticChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample/GeneticChooser.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GeneticChooser.cs 22 Feb 2008 20:59:19 -0000 1.3 --- GeneticChooser.cs 25 Feb 2008 23:09:00 -0000 1.4 *************** *** 47,59 **** public event NewProgressEventHandler NewProgress; public event NewMessageEventHandler NewMessage; ! protected int numberOfPortfolioPositions; protected int numberOfBestTestingPositionsToBeReturned; - protected bool choosePositionsWithAtLeastOneDifferentTicker; //the genetic chooser will return the requested number //of genome (which meaning is a TestingPositions) that ! //have a different hash code //the method that returns the hash code for genome ! //is virtual protected TestingPositions[] bestTestingPositions; protected Benchmark benchmark; --- 47,58 ---- public event NewProgressEventHandler NewProgress; public event NewMessageEventHandler NewMessage; ! protected int numberOfPortfolioPositions; protected int numberOfBestTestingPositionsToBeReturned; //the genetic chooser will return the requested number //of genome (which meaning is a TestingPositions) that ! //have a different hash code ( //the method that returns the hash code for genome ! //is virtual) protected TestingPositions[] bestTestingPositions; protected Benchmark benchmark; *************** *** 207,213 **** } ! protected abstract void setGenomeManager(EligibleTickers eligibleTickers , ReturnsManager returnsManager); ! //sets the member genomeManager in inherited classes private TestingPositions[] getBestTestingPositionsInSample( --- 206,212 ---- } ! protected abstract IGenomeManager getGenomeManager(EligibleTickers eligibleTickers , ReturnsManager returnsManager); ! //returns a specific IGenomeManager object in inherited classes private TestingPositions[] getBestTestingPositionsInSample( *************** *** 216,220 **** ) { ! this.setGenomeManager(eligibleTickers, returnsManager); this.geneticOptimizer = new GeneticOptimizer( this.crossoverRate , --- 215,219 ---- ) { ! this.genomeManager = this.getGenomeManager(eligibleTickers, returnsManager); this.geneticOptimizer = new GeneticOptimizer( this.crossoverRate , |
|
From: Marco M. <mi...@us...> - 2008-02-22 20:59:24
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv25672/a2_Strategies/InSample Modified Files: GeneticChooser.cs Log Message: Removed parameter from the constructor (it created only confusion) Index: GeneticChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample/GeneticChooser.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GeneticChooser.cs 13 Feb 2008 21:46:59 -0000 1.2 --- GeneticChooser.cs 22 Feb 2008 20:59:19 -0000 1.3 *************** *** 52,57 **** protected bool choosePositionsWithAtLeastOneDifferentTicker; //the genetic chooser will return the requested number ! //of TestingPositions that have a different tickers'composition ! //(that is TestingPositions with a different HashCodeForTickerComposition) protected TestingPositions[] bestTestingPositions; protected Benchmark benchmark; --- 52,59 ---- protected bool choosePositionsWithAtLeastOneDifferentTicker; //the genetic chooser will return the requested number ! //of genome (which meaning is a TestingPositions) that ! //have a different hash code ! //the method that returns the hash code for genome ! //is virtual protected TestingPositions[] bestTestingPositions; protected Benchmark benchmark; *************** *** 90,104 **** /// AnalyzeInSample method will return /// </param> - /// <param name="choosePositionsWithAtLeastOneDifferentTicker"> - /// If true, the returned TestingPositions - /// will be different in TickerComposition - /// (there won't be two TestingPositions with - /// exactly the same tickers). - /// If false, there will be returned just the best TestingPositions - /// ordered by fitness by the genetic optimizer - /// </param> public GeneticChooser( int numberOfPortfolioPositions , int numberOfBestTestingPositionsToBeReturned , - bool choosePositionsWithAtLeastOneDifferentTicker , Benchmark benchmark , IDecoderForTestingPositions decoderForTestingPositions , --- 92,97 ---- *************** *** 181,192 **** //it returns a hashCode for the given genome protected virtual string getHashCodeForGenome(Genome genome) { ! string returnValue; ! if (this.choosePositionsWithAtLeastOneDifferentTicker) ! returnValue = ((TestingPositions)genome.Meaning).HashCodeForTickerComposition; ! else ! returnValue = genome.Meaning.GetHashCode().ToString(); ! return returnValue; } --- 174,184 ---- //it returns a hashCode for the given genome + //normally, it should be overrided in inherited classes protected virtual string getHashCodeForGenome(Genome genome) { ! string returnValue = genome.Meaning.GetHashCode().ToString(); ! // if (this.choosePositionsWithAtLeastOneDifferentTicker) ! // returnValue = ((TestingPositions)genome.Meaning).HashCodeForTickerComposition; ! // else return returnValue; } |
|
From: Marco M. <mi...@us...> - 2008-02-22 20:58:09
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24772/a2_Strategies/Optimizing/Decoding Modified Files: BasicDecoderForTestingPositions.cs Log Message: IDecoderForTestingPositions has to implement ILogDescriptor interface Index: BasicDecoderForTestingPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding/BasicDecoderForTestingPositions.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BasicDecoderForTestingPositions.cs 6 Feb 2008 23:11:27 -0000 1.1 --- BasicDecoderForTestingPositions.cs 22 Feb 2008 20:57:58 -0000 1.2 *************** *** 44,48 **** protected EligibleTickers eligibleTickers; protected ReturnsManager returnsManager; ! public BasicDecoderForTestingPositions() { --- 44,58 ---- protected EligibleTickers eligibleTickers; protected ReturnsManager returnsManager; ! ! public virtual string Description ! { ! get ! { ! string description = ! "BasicDecoderForTestingPositions_DecodedOnlyTickers_EqualWeights"; ! return description; ! } ! } ! public BasicDecoderForTestingPositions() { |
|
From: Marco M. <mi...@us...> - 2008-02-22 20:57:09
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24315/a2_Strategies/Optimizing/Decoding Modified Files: DecoderForTestingPositionsWithBalancedWeights.cs IDecoderForTestingPositions.cs Log Message: The interface has to implement ILogDescriptor interface Index: DecoderForTestingPositionsWithBalancedWeights.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding/DecoderForTestingPositionsWithBalancedWeights.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DecoderForTestingPositionsWithBalancedWeights.cs 6 Feb 2008 23:11:27 -0000 1.1 --- DecoderForTestingPositionsWithBalancedWeights.cs 22 Feb 2008 20:57:01 -0000 1.2 *************** *** 41,44 **** --- 41,54 ---- } + public override string Description + { + get + { + string description = + "DecoderForTestingPositions_DecodedOnlyTickers_WeightsAreBalancedOnVolatilityBase"; + return description; + } + } + protected override double[] getWeights() { Index: IDecoderForTestingPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding/IDecoderForTestingPositions.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IDecoderForTestingPositions.cs 6 Feb 2008 23:08:58 -0000 1.1 --- IDecoderForTestingPositions.cs 22 Feb 2008 20:57:01 -0000 1.2 *************** *** 26,29 **** --- 26,30 ---- using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; + using QuantProject.Business.Strategies.Logging; namespace QuantProject.Business.Strategies.Optimizing.Decoding *************** *** 34,38 **** /// StrategyPositionsForTesting /// </summary> ! public interface IDecoderForTestingPositions { /// <summary> --- 35,39 ---- /// StrategyPositionsForTesting /// </summary> ! public interface IDecoderForTestingPositions : ILogDescriptor { /// <summary> |
|
From: Marco M. <mi...@us...> - 2008-02-22 20:55:46
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23838/a2_Strategies/OutOfSample Modified Files: TestingPositions.cs Log Message: Fixed bug in HashCodeForTickerComposition Index: TestingPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample/TestingPositions.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestingPositions.cs 6 Feb 2008 23:05:49 -0000 1.1 --- TestingPositions.cs 22 Feb 2008 20:55:37 -0000 1.2 *************** *** 58,62 **** listOfTickers.Sort(); foreach(string tickerCode in listOfTickers) ! this.hashCodeForTickerComposition += tickerCode; } return this.hashCodeForTickerComposition; --- 58,62 ---- listOfTickers.Sort(); foreach(string tickerCode in listOfTickers) ! this.hashCodeForTickerComposition += tickerCode + ";"; } return this.hashCodeForTickerComposition; *************** *** 69,73 **** } ! //it creates a empty TestingPositions public TestingPositions() { --- 69,73 ---- } ! //it creates an empty TestingPositions public TestingPositions() { |
|
From: Glauco S. <gla...@us...> - 2008-02-19 21:56:32
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/GenomeManagers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv27053/b4_Business/a2_Strategies/Optimizing/GenomeManagers Modified Files: BasicGenomeManager.cs Log Message: - seedForRandomGenerator is given as a parameter, now - a couple of "one line" return statements have been split up, to allow an easier debugging/breakpointing Index: BasicGenomeManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/GenomeManagers/BasicGenomeManager.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BasicGenomeManager.cs 13 Feb 2008 21:31:42 -0000 1.1 --- BasicGenomeManager.cs 19 Feb 2008 21:56:24 -0000 1.2 *************** *** 59,70 **** return this.maxValueForGenes; } ! public BasicGenomeManager(EligibleTickers eligibleTickers, ! int numberOfTickersInPortfolio, ! IDecoderForTestingPositions decoderForTestingPositions, ! IFitnessEvaluator fitnessEvaluator, ! GenomeManagerType genomeManagerType, ! ReturnsManager returnsManager) ! { this.eligibleTickers = eligibleTickers; --- 59,71 ---- return this.maxValueForGenes; } ! public BasicGenomeManager(EligibleTickers eligibleTickers, ! int numberOfTickersInPortfolio, ! IDecoderForTestingPositions decoderForTestingPositions, ! IFitnessEvaluator fitnessEvaluator, ! GenomeManagerType genomeManagerType, ! ReturnsManager returnsManager , ! int seedForRandomGenerator ) ! { this.eligibleTickers = eligibleTickers; *************** *** 75,79 **** this.returnsManager = returnsManager; this.setMinAndMaxValueForGenes(); ! GenomeManagement.SetRandomGenerator(QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator); } --- 76,80 ---- this.returnsManager = returnsManager; this.setMinAndMaxValueForGenes(); ! GenomeManagement.SetRandomGenerator( seedForRandomGenerator ); } *************** *** 103,107 **** public virtual double GetFitnessValue(Genome genome) { ! return this.fitnessEvaluator.GetFitnessValue(genome.Meaning, this.returnsManager); } --- 104,110 ---- public virtual double GetFitnessValue(Genome genome) { ! double fitnessValue = ! this.fitnessEvaluator.GetFitnessValue(genome.Meaning, this.returnsManager); ! return fitnessValue; } *************** *** 142,150 **** // // // } ! public virtual object Decode(Genome genome) { ! return this.decoderForTestingPositions.Decode(genome.Genes(), ! this.eligibleTickers, this.returnsManager); } } --- 145,155 ---- // // // } ! public virtual object Decode(Genome genome) { ! object decoded = ! this.decoderForTestingPositions.Decode(genome.Genes(), ! this.eligibleTickers, this.returnsManager); ! return decoded; } } |
|
From: Marco M. <mi...@us...> - 2008-02-13 22:20:02
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24497 Modified Files: b4_Business.csproj Business_SD.csproj Log Message: Updated vs net and SD project files Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Business_SD.csproj 10 Feb 2008 19:46:31 -0000 1.11 --- Business_SD.csproj 13 Feb 2008 22:19:56 -0000 1.12 *************** *** 73,76 **** --- 73,77 ---- <Compile Include="a2_Strategies\IInSampleChooser.cs" /> <Compile Include="a2_Strategies\InSample\ConstantWeightedPositionsChooser.cs" /> + <Compile Include="a2_Strategies\InSample\GeneticChooser.cs" /> <Compile Include="a2_Strategies\Logging\BackTestLog.cs" /> <Compile Include="a2_Strategies\Logging\ILogDescriptor.cs" /> *************** *** 82,85 **** --- 83,89 ---- <Compile Include="a2_Strategies\Optimizing\Decoding\IDecoderForTestingPositions.cs" /> <Compile Include="a2_Strategies\Optimizing\Decoding\IDecoderForWeightedPositions.cs" /> + <Compile Include="a2_Strategies\Optimizing\FitnessEvaluation\IFitnessEvaluator.cs" /> + <Compile Include="a2_Strategies\Optimizing\GenomeManagers\BasicGenomeManager.cs" /> + <Compile Include="a2_Strategies\Optimizing\GenomeManagers\GenomeManagerType.cs" /> <Compile Include="a2_Strategies\OutOfSample\TestingPositions.cs" /> <Compile Include="a2_Strategies\returnsManagement\time\CloseToCloseIntervals.cs" /> *************** *** 223,226 **** --- 227,232 ---- </ProjectReference> <Folder Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows" /> + <Folder Include="a2_Strategies\Optimizing\FitnessEvaluation" /> + <Folder Include="a2_Strategies\Optimizing\GenomeManagers" /> <Folder Include="a2_Strategies\OutOfSample" /> <Folder Include="a2_Strategies\Eligibles" /> Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** b4_Business.csproj 10 Feb 2008 14:13:57 -0000 1.53 --- b4_Business.csproj 13 Feb 2008 22:19:56 -0000 1.54 *************** *** 738,741 **** --- 738,746 ---- /> <File + RelPath = "a2_Strategies\InSample\GeneticChooser.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a2_Strategies\Logging\BackTestLog.cs" SubType = "Code" *************** *** 788,791 **** --- 793,806 ---- /> <File + RelPath = "a2_Strategies\Optimizing\GenomeManagers\BasicGenomeManager.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "a2_Strategies\Optimizing\GenomeManagers\GenomeManagerType.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a2_Strategies\OutOfSample\TestingPositions.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2008-02-13 21:47:06
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10870 Modified Files: GeneticChooser.cs Log Message: Fixed bug in GeneticChooser class. The class has not been tested yet ... Index: GeneticChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample/GeneticChooser.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GeneticChooser.cs 13 Feb 2008 21:30:21 -0000 1.1 --- GeneticChooser.cs 13 Feb 2008 21:46:59 -0000 1.2 *************** *** 215,219 **** } ! protected abstract void setGenomeManager(); //sets the member genomeManager in inherited classes --- 215,220 ---- } ! protected abstract void setGenomeManager(EligibleTickers eligibleTickers , ! ReturnsManager returnsManager); //sets the member genomeManager in inherited classes *************** *** 223,227 **** ) { ! this.setGenomeManager(); this.geneticOptimizer = new GeneticOptimizer( this.crossoverRate , --- 224,228 ---- ) { ! this.setGenomeManager(eligibleTickers, returnsManager); this.geneticOptimizer = new GeneticOptimizer( this.crossoverRate , |
|
From: Marco M. <mi...@us...> - 2008-02-13 21:31:45
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/GenomeManagers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv4477 Added Files: BasicGenomeManager.cs GenomeManagerType.cs Log Message: Added BasicGenomeManager, an abstract class that should be inherited by all the IGenomeManagers created for genetic optimization. --- NEW FILE: BasicGenomeManager.cs --- /* QuantProject - Quantitative Finance Library BasicGenomeManager.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; namespace QuantProject.Business.Strategies.Optimizing.GenomeManagers { /// <summary> /// This is a basic abstract implementation of IGenomeManager, that should be /// inherited by specific GenomeManagers for specific strategies /// </summary> [Serializable] public abstract class BasicGenomeManager : IGenomeManager { protected int genomeSize; protected int minValueForGenes; protected int maxValueForGenes; protected GenomeManagerType genomeManagerType; protected EligibleTickers eligibleTickers; protected ReturnsManager returnsManager; protected IDecoderForTestingPositions decoderForTestingPositions; protected IFitnessEvaluator fitnessEvaluator; 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 BasicGenomeManager(EligibleTickers eligibleTickers, int numberOfTickersInPortfolio, IDecoderForTestingPositions decoderForTestingPositions, IFitnessEvaluator fitnessEvaluator, GenomeManagerType genomeManagerType, ReturnsManager returnsManager) { this.eligibleTickers = eligibleTickers; this.genomeSize = numberOfTickersInPortfolio; this.decoderForTestingPositions = decoderForTestingPositions; this.fitnessEvaluator = fitnessEvaluator; this.genomeManagerType = genomeManagerType; this.returnsManager = returnsManager; this.setMinAndMaxValueForGenes(); GenomeManagement.SetRandomGenerator(QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator); } private void setMinAndMaxValueForGenes() { switch (this.genomeManagerType) { case GenomeManagerType.OnlyLong : //OnlyLong orders are admitted this.minValueForGenes = 0; this.maxValueForGenes = this.eligibleTickers.Count - 1; break; case GenomeManagerType.OnlyShort : //OnlyShort orders are admitted this.minValueForGenes = - this.eligibleTickers.Count; //if gene g is negative, it refers to the ticker |g|-1 to be shorted this.maxValueForGenes = - 1; break; default : //Both Long and Short orders are admitted this.minValueForGenes = - this.eligibleTickers.Count; this.maxValueForGenes = this.eligibleTickers.Count - 1; break; } } public virtual double GetFitnessValue(Genome genome) { return this.fitnessEvaluator.GetFitnessValue(genome.Meaning, this.returnsManager); } public abstract Genome[] GetChilds(Genome parent1, Genome parent2); public abstract int GetNewGeneValue(Genome genome, int genePosition); // { // // in this implementation new gene values must be different from // // 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; // } public abstract void Mutate(Genome genome); // { // // in this implementation only one gene is mutated // // the new value has to be different from all the other genes of the genome // 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); // } // public virtual object Decode(BruteForceOptimizableParameters bruteForceOptimizableParameters) // { // // // } public virtual object Decode(Genome genome) { return this.decoderForTestingPositions.Decode(genome.Genes(), this.eligibleTickers, this.returnsManager); } } } --- NEW FILE: GenomeManagerType.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerType.cs Copyright (C) 2008 Marco Milletti 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.Optimizing.GenomeManagers { /// <summary> /// Specifies the type of the GenomeManager /// </summary> [Serializable] public enum GenomeManagerType { OnlyLong,//it selects genes that are to be decoded //as tickers for only long orders (and so on) OnlyShort, ShortAndLong, OnlyMixed } } |
|
From: Marco M. <mi...@us...> - 2008-02-13 21:30:29
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv4013 Added Files: GeneticChooser.cs Log Message: Added GeneticChooser, an abstract class that should be inherited by all the IInSampleChoosers that use genetic optimization. --- NEW FILE: GeneticChooser.cs --- /* QuantProject - Quantitative Finance Library GeneticChooser.cs Copyright (C) 2008 Marco Milletti 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.Collections; using QuantProject.ADT; using QuantProject.ADT.Messaging; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Timing; using QuantProject.Business.Strategies.OutOfSample; namespace QuantProject.Business.Strategies.InSample { /// <summary> /// Abstract GeneticChooser to be used for /// in sample optimization /// </summary> public abstract class GeneticChooser : IInSampleChooser { public event NewProgressEventHandler NewProgress; public event NewMessageEventHandler NewMessage; protected int numberOfPortfolioPositions; protected int numberOfBestTestingPositionsToBeReturned; protected bool choosePositionsWithAtLeastOneDifferentTicker; //the genetic chooser will return the requested number //of TestingPositions that have a different tickers'composition //(that is TestingPositions with a different HashCodeForTickerComposition) protected TestingPositions[] bestTestingPositions; protected Benchmark benchmark; protected IDecoderForTestingPositions decoderForTestingPositions; protected IFitnessEvaluator fitnessEvaluator; protected IHistoricalQuoteProvider historicalQuoteProvider; protected IGenomeManager genomeManager; protected double crossoverRate; protected double mutationRate; protected double elitismRate; protected int populationSizeForGeneticOptimizer; protected int generationNumberForGeneticOptimizer; protected int seedForRandomGenerator; protected GeneticOptimizer geneticOptimizer; public string Description { get { string description = "PopSize_" + this.populationSizeForGeneticOptimizer + "_GenNum_" + this.generationNumberForGeneticOptimizer + "_FitnEval_" + this.fitnessEvaluator.Description + "_DecoderForTestingPositions_" + this.decoderForTestingPositions; return description; } } /// <summary> /// Abstract GeneticChooser to be used for /// in sample optimization /// </summary> /// <param name="numberOfBestTestingPositionsToBeReturned"> /// The number of TestingPositions that the /// AnalyzeInSample method will return /// </param> /// <param name="choosePositionsWithAtLeastOneDifferentTicker"> /// If true, the returned TestingPositions /// will be different in TickerComposition /// (there won't be two TestingPositions with /// exactly the same tickers). /// If false, there will be returned just the best TestingPositions /// ordered by fitness by the genetic optimizer /// </param> public GeneticChooser( int numberOfPortfolioPositions , int numberOfBestTestingPositionsToBeReturned , bool choosePositionsWithAtLeastOneDifferentTicker , Benchmark benchmark , IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , IHistoricalQuoteProvider historicalQuoteProvider , double crossoverRate , double mutationRate , double elitismRate , int populationSizeForGeneticOptimizer , int generationNumberForGeneticOptimizer , int seedForRandomGenerator ) { this.numberOfPortfolioPositions = numberOfPortfolioPositions; this.numberOfBestTestingPositionsToBeReturned = numberOfBestTestingPositionsToBeReturned; this.bestTestingPositions = new TestingPositions[numberOfBestTestingPositionsToBeReturned]; this.benchmark = benchmark; this.decoderForTestingPositions = decoderForTestingPositions; this.fitnessEvaluator = fitnessEvaluator; this.historicalQuoteProvider = historicalQuoteProvider; this.crossoverRate = crossoverRate; this.mutationRate = mutationRate; this.elitismRate = elitismRate; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.seedForRandomGenerator = seedForRandomGenerator; } #region AnalyzeInSample private void analyzeInSample_checkParameters( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { if ( eligibleTickers.Count < this.numberOfPortfolioPositions ) throw new Exception( "Eligible tickers for driving positions contains " + "only " + eligibleTickers.Count + " elements, while NumberOfDrivingPositions is " + this.numberOfPortfolioPositions ); if ( this.numberOfBestTestingPositionsToBeReturned > this.populationSizeForGeneticOptimizer ) throw new Exception( "Number of BestTestingPositions for " + "out of sample testing is too high with " + "respect to the population size of the " + "genetic optimizer" ); } #region newGenerationEventHandler private void sendNewProgress( NewGenerationEventArgs e ) { if ( this.NewProgress != null ) this.NewProgress( this , new NewProgressEventArgs( e.GenerationCounter , e.GenerationNumber ) ); } #region sendNewMessage private string getProgressMessage( int generationCounter , int generationNumber ) { string progressMessage = generationCounter.ToString() + " / " + generationNumber.ToString() + " - " + DateTime.Now.ToString(); return progressMessage; } private void sendNewMessage( NewGenerationEventArgs e ) { string message = this.getProgressMessage( e.GenerationCounter , e.GenerationNumber ); NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if( this.NewMessage != null ) this.NewMessage( this , newMessageEventArgs ); } #endregion sendNewMessage private void newGenerationEventHandler( object sender , NewGenerationEventArgs e ) { this.sendNewProgress( e ); this.sendNewMessage( e ); } #endregion newGenerationEventHandler //it returns a hashCode for the given genome protected virtual string getHashCodeForGenome(Genome genome) { string returnValue; if (this.choosePositionsWithAtLeastOneDifferentTicker) returnValue = ((TestingPositions)genome.Meaning).HashCodeForTickerComposition; else returnValue = genome.Meaning.GetHashCode().ToString(); return returnValue; } private void setBestTestingPositions() { GeneticOptimizer GO = this.geneticOptimizer; int addedTestingPositions = 0; int counter = 0; Genome currentGenome = null; string currentGenomeHashcode; Hashtable genomesCollector = new Hashtable(); while(addedTestingPositions < this.numberOfBestTestingPositionsToBeReturned && counter < GO.PopulationSize) { currentGenome = (Genome)GO.CurrentGeneration[GO.PopulationSize - 1 - counter]; currentGenomeHashcode = this.getHashCodeForGenome(currentGenome); if( counter == 0 || !genomesCollector.ContainsKey(currentGenomeHashcode) ) { this.bestTestingPositions[addedTestingPositions] = (TestingPositions)currentGenome.Meaning; genomesCollector.Add(currentGenomeHashcode, null); } counter ++ ; } } protected abstract void setGenomeManager(); //sets the member genomeManager in inherited classes private TestingPositions[] getBestTestingPositionsInSample( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { this.setGenomeManager(); this.geneticOptimizer = new GeneticOptimizer( this.crossoverRate , this.mutationRate , this.elitismRate , this.populationSizeForGeneticOptimizer , this.generationNumberForGeneticOptimizer , this.genomeManager , this.seedForRandomGenerator ); this.geneticOptimizer.NewGeneration += new NewGenerationEventHandler( this.newGenerationEventHandler ); this.geneticOptimizer.Run( false ); this.setBestTestingPositions(); return this.bestTestingPositions; } /// <summary> /// Returns the best TestingPositions with respect to the in sample data /// </summary> /// <param name="eligibleTickers"></param> /// <returns></returns> public object AnalyzeInSample( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { this.analyzeInSample_checkParameters( eligibleTickers , returnsManager ); TestingPositions[] bestTestingPositionsInSample = this.getBestTestingPositionsInSample( eligibleTickers , returnsManager ); return bestTestingPositionsInSample; } #endregion AnalyzeInSample } } |
|
From: Marco M. <mi...@us...> - 2008-02-13 21:28:12
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/GenomeManagers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2551/GenomeManagers Log Message: Directory /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/GenomeManagers added to the repository |
|
From: Marco M. <mi...@us...> - 2008-02-10 19:46:37
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32139 Modified Files: Business_SD.csproj Log Message: Added ILogDescriptor interface to the project, to be used for logging activities (naming of log files and creating log files' contents) Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Business_SD.csproj 7 Feb 2008 18:13:39 -0000 1.10 --- Business_SD.csproj 10 Feb 2008 19:46:31 -0000 1.11 *************** *** 74,77 **** --- 74,78 ---- <Compile Include="a2_Strategies\InSample\ConstantWeightedPositionsChooser.cs" /> <Compile Include="a2_Strategies\Logging\BackTestLog.cs" /> + <Compile Include="a2_Strategies\Logging\ILogDescriptor.cs" /> <Compile Include="a2_Strategies\Logging\LogItem.cs" /> <Compile Include="a2_Strategies\Logging\NewLogItemEventArgs.cs" /> |
|
From: Glauco S. <gl...@my...> - 2008-02-10 18:01:26
|
Marco Milletti wrote: > Update of /cvsroot/quantproject/QuantProject/b4_Business/a05_Timing > In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10185/b4_Business/a05_Timing > > Modified Files: > EndOfDayDateTime.cs > Log Message: > == and != operator have been overloaded when used with objects of this type > VSNet mi da' questi due warnings (ho settato VSNet per darmi solo warnings "significativi"): C:\QuantProject\QuantProject\b4_Business\a05_Timing\EndOfDayDateTime.cs(32,17): warning CS0660: 'QuantProject.Business.Timing.EndOfDayDateTime' defines operator == or operator != but does not override Object.Equals(object o) C:\QuantProject\QuantProject\b4_Business\a05_Timing\EndOfDayDateTime.cs(32,17): warning CS0661: 'QuantProject.Business.Timing.EndOfDayDateTime' defines operator == or operator != but does not override Object.GetHashCode() Ti dicono qualcosa? |
|
From: Glauco S. <gla...@us...> - 2008-02-10 15:27:26
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30442/b3_Data Modified Files: b3_Data.csproj Log Message: Minor VSNet automatic change Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** b3_Data.csproj 7 Feb 2008 17:12:16 -0000 1.52 --- b3_Data.csproj 10 Feb 2008 15:27:21 -0000 1.53 *************** *** 144,148 **** <File RelPath = "ExtendedDataTable.cs" ! SubType = "Component" BuildAction = "Compile" /> --- 144,148 ---- <File RelPath = "ExtendedDataTable.cs" ! SubType = "Code" BuildAction = "Compile" /> |
|
From: Glauco S. <gla...@us...> - 2008-02-10 15:26:39
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EquityEvaluation In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30032/b4_Business/a2_Strategies/EquityEvaluation Modified Files: WinningPeriods.cs Log Message: The property public string Description has been implemented Index: WinningPeriods.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EquityEvaluation/WinningPeriods.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WinningPeriods.cs 13 Jul 2007 10:18:03 -0000 1.2 --- WinningPeriods.cs 10 Feb 2008 15:26:34 -0000 1.3 *************** *** 31,34 **** --- 31,42 ---- public class WinningPeriods : IEquityEvaluator { + public string Description + { + get + { + return "EqEvltr_wnngPrds"; + } + } + public WinningPeriods() { |
|
From: Glauco S. <gla...@us...> - 2008-02-10 15:26:19
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EquityEvaluation In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30000/b4_Business/a2_Strategies/EquityEvaluation Modified Files: SharpeRatio.cs Log Message: The property public string Description has been implemented Index: SharpeRatio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EquityEvaluation/SharpeRatio.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SharpeRatio.cs 14 Aug 2007 14:51:01 -0000 1.2 --- SharpeRatio.cs 10 Feb 2008 15:26:15 -0000 1.3 *************** *** 34,37 **** --- 34,45 ---- public class SharpeRatio : IEquityEvaluator { + public string Description + { + get + { + return "EqEvltr_shrpRt"; + } + } + public SharpeRatio() { |