quantproject-developers Mailing List for QuantProject (Page 102)
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: Marco M. <mi...@us...> - 2005-08-21 10:09:33
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Statistics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25089/b1_ADT/Statistics Modified Files: BasicFunctions.cs Log Message: Added statistic methods for getting Percentile, Median and DecileAverage (even though these methods are not used by the project, at the moment). Index: BasicFunctions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Statistics/BasicFunctions.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BasicFunctions.cs 22 Aug 2004 16:52:40 -0000 1.4 --- BasicFunctions.cs 21 Aug 2005 10:09:23 -0000 1.5 *************** *** 22,25 **** --- 22,26 ---- using System; + using QuantProject.ADT.Statistics; namespace QuantProject.ADT.Statistics *************** *** 30,34 **** public class BasicFunctions { ! static public double Sum( double[] data ) { double sum = 0; --- 31,44 ---- public class BasicFunctions { ! private static double[] orderedData; ! ! static private void setOrderedData(double[] data) ! { ! orderedData = new double[data.Length]; ! data.CopyTo(orderedData,0); ! Array.Sort(orderedData); ! } ! ! static public double Sum( double[] data ) { double sum = 0; *************** *** 185,190 **** throw new Exception("The two variables haven't the same length!"); } } } ! \ No newline at end of file --- 195,276 ---- throw new Exception("The two variables haven't the same length!"); } + + /// <summary> + /// Returns the t-th percentile for a given set of data + /// </summary> + /// <param name="data">Data for which t-th percentile is to be computed </param> + /// <param name="percentileNumber">A number between 0 and 100, corresponding + /// to the requested t-th percentile </param> + static public double Percentile(double[] data, + int percentileNumber) + { + if(percentileNumber<0 || percentileNumber >100) + throw new Exception("percentileNumber has to be a number between 0 and 100!"); + setOrderedData(data); + int n = orderedData.Length; + double np = ((double)n+1) * (double)percentileNumber/100.0; + if(np<=1.0) + return orderedData[0]; + if(np>=n) + return orderedData[n-1]; + + int integerPart_np = (int)Math.Floor(np); + double fractionalPart_np = np - integerPart_np; + //if np is not a whole number, it has to be returned a + // number between two data points + // In this implementation the method used to return such number + // is based on a simple interpolation + return (orderedData[integerPart_np-1] + + fractionalPart_np* (orderedData[integerPart_np] - orderedData[integerPart_np-1])); + + } + + /// <summary> + /// Returns the median for a given set of data + /// (Median is the value, belonging or not to the given set of data, such that + /// number of data points below that value is equal to the number of data points + /// above that value) + /// </summary> + /// <param name="data">Data for which median is to be computed</param> + static public double Median(double[] data) + { + return Percentile(data, 50); + } + + /// <summary> + /// Returns the average value for the given decile of + /// a given set of data + /// </summary> + /// <param name="data">The set of data</param> + /// <param name="decileNumber">The decile for which the average has to be computed</param> + static public double GetDecileAverage(double[] data, + int decileNumber) + { + if(decileNumber<1 || decileNumber >9) + throw new Exception("decileNumber has to be a number between 1 and 9!"); + + double firstCorrespondingPercentile = + Percentile(data, decileNumber * 10 - 10); + double secondCorrespondingPercentile = + Percentile(data, decileNumber * 10); + double totalBetweenPercentiles = 0.0; + int numberOfDataPointsBetweenPercentiles = 0; + for(int i = 0; i<orderedData.Length; i++) + { + if(orderedData[i]>= firstCorrespondingPercentile && + orderedData[i]< secondCorrespondingPercentile) + { + numberOfDataPointsBetweenPercentiles++; + totalBetweenPercentiles += orderedData[i]; + } + + } + + return totalBetweenPercentiles/numberOfDataPointsBetweenPercentiles; + } + + } } ! |
|
From: Marco M. <mi...@us...> - 2005-08-21 10:07:58
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24776/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: Changed default values for the geneticOptimizer (default values can always be changed as they are public properties) Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GeneticOptimizer.cs 3 Aug 2005 23:08:33 -0000 1.10 --- GeneticOptimizer.cs 21 Aug 2005 10:07:36 -0000 1.11 *************** *** 211,216 **** private void commonInitialization() { ! this.mutationRate = 0.10; ! this.crossoverRate = 0.85; this.elitismRate = 0.0; this.minConvergenceRate = 0.80; --- 211,216 ---- private void commonInitialization() { ! this.mutationRate = 0.20; ! this.crossoverRate = 0.99; this.elitismRate = 0.0; this.minConvergenceRate = 0.80; |
|
From: Marco M. <mi...@us...> - 2005-08-20 16:09:23
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29643/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio Added Files: RunTestingOptimizationOpenToClose.cs Log Message: Added objects for testing optimization technique. --- NEW FILE: RunTestingOptimizationOpenToClose.cs --- /* QuantProject - Quantitative Finance Library RunTestingOptimizationOpenToClose.cs Copyright (C) 2003 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.Data; using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.EvaluatingOptimizationTechnique.EfficientPortfolio { /// <summary> /// For the evaluation of the optimization technique used by the script /// for the efficient open to close portfolio /// </summary> [Serializable] public class RunTestingOptimizationOpenToClose { private double[] fitnessesInSample; private double[] fitnessesOutOfSample; private string tickerGroupID; private int numberOfEligibleTickers; private int numberOfTickersToBeChosen; private int numDaysForLiquidity; private int populationSizeForGeneticOptimizer; private string benchmark; private DateTime marketDate; private double targetReturn; private PortfolioType portfolioType; private int numDaysAfterLastOptimizationDay; private int numberOfSubsets; public RunTestingOptimizationOpenToClose(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, int populationSizeForGeneticOptimizer, string benchmark, DateTime marketDate, double targetReturn, PortfolioType portfolioType, int numDaysAfterLastOptimizationDay) { this.fitnessesInSample = new double[populationSizeForGeneticOptimizer]; this.fitnessesOutOfSample = new double[populationSizeForGeneticOptimizer]; this.tickerGroupID = tickerGroupID; this.numberOfEligibleTickers = numberOfEligibleTickers; this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; this.numDaysForLiquidity = numDaysForLiquidity; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.benchmark = benchmark; this.marketDate = marketDate; this.targetReturn = targetReturn; this.portfolioType = portfolioType; this.numDaysAfterLastOptimizationDay = numDaysAfterLastOptimizationDay; this.numberOfSubsets = 5; } private DataTable getSetOfTickersToBeOptimized(DateTime date) { /* SelectorByAverageRawOpenPrice selectorByOpenPrice = new SelectorByAverageRawOpenPrice(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers, this.minPriceForMinimumCommission, this.maxPriceForMinimumCommission, 0, 2); DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, date.AddDays(-this.numDaysForLiquidity), date, this.numberOfEligibleTickers); /*SelectorByOpenToCloseVolatility lessVolatile = new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), true, currentDate.AddDays(-5), currentDate, this.numberOfEligibleTickers/2);*/ DataTable eligibleTickers; eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( eligibleTickers, false, date.AddDays(-this.numDaysForLiquidity), date, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), // false, currentDate.AddDays(-2), // currentDate, this.numberOfEligibleTickers/4); //return winners.GetTableOfSelectedTickers(); //SelectorByOpenCloseCorrelationToBenchmark lessCorrelated = // new SelectorByOpenCloseCorrelationToBenchmark(quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(), // this.benchmark, true, // currentDate.AddDays(-this.numDaysForLiquidity), // currentDate, this.numberOfEligibleTickers/2); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); //return lessCorrelated.GetTableOfSelectedTickers(); } private double setFitnesses_setFitnessesActually_getFitnessOutOfSample(Genome genome) { double returnValue = 0; foreach(string tickerCode in (string[])genome.Meaning) { double coefficient = 1.0; string ticker = tickerCode; if(ticker.StartsWith("-")) { ticker = ticker.Substring(1,ticker.Length -1); coefficient = -1.0; } DateTime dateOutOfSample = this.marketDate.AddDays(this.numDaysAfterLastOptimizationDay); Quotes tickerQuotes = new Quotes(ticker, dateOutOfSample, dateOutOfSample); returnValue += (tickerQuotes.GetFirstValidRawClose(dateOutOfSample)/ tickerQuotes.GetFirstValidRawOpen(dateOutOfSample) - 1.0)*coefficient; } return returnValue/genome.Size; } private void setFitnesses_setFitnessesActually(GeneticOptimizer GO) { for(int i = 0; i<GO.CurrentGeneration.Count; i++) { this.fitnessesInSample[i]=((Genome)GO.CurrentGeneration[i]).Fitness; this.fitnessesOutOfSample[i]= this.setFitnesses_setFitnessesActually_getFitnessOutOfSample((Genome)GO.CurrentGeneration[i]); } } private void setFitnesses() { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(this.marketDate); IGenomeManager genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, this.marketDate.AddDays(-this.numDaysForLiquidity), this.marketDate, this.numberOfTickersToBeChosen, this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, 0, ConstantsProvider.SeedForRandomGenerator); GO.Run(false); this.setFitnesses_setFitnessesActually(GO); } public void Run() { this.setFitnesses(); OptimizationTechniqueEvaluator evaluator = new OptimizationTechniqueEvaluator(this.fitnessesInSample, this.fitnessesOutOfSample); double[] averagesInSample = evaluator.GetAveragesOfSubsetsInSample(this.numberOfSubsets); double[] averagesOutOfSample = evaluator.GetAveragesOfSubsetsOutOfSample(this.numberOfSubsets); double r = evaluator.GetCorrelationBetweenFitnesses(); } } } |
|
From: Marco M. <mi...@us...> - 2005-08-20 16:09:23
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29643/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: Added objects for testing optimization technique. Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** b7_Scripts.csproj 10 Aug 2005 16:44:50 -0000 1.36 --- b7_Scripts.csproj 20 Aug 2005 16:08:47 -0000 1.37 *************** *** 122,125 **** --- 122,135 ---- BuildAction = "Compile" /> + <File + RelPath = "EvaluatingOptimizationTechnique\OptimizationTechniqueEvaluator.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "EvaluatingOptimizationTechnique\EfficientPortfolio\RunTestingOptimizationOpenToClose.cs" + SubType = "Code" + BuildAction = "Compile" + /> <Folder RelPath = "MultiTesting\MultiTestOneRank\" /> <File *************** *** 309,317 **** /> <File - RelPath = "WalkForwardTesting\LinearCombination\TestDisplayer.resx" - DependentUpon = "TestDisplayer.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "WalkForwardTesting\LinearCombination\VisualObjectArchiver.cs" SubType = "Code" --- 319,322 ---- |
|
From: Marco M. <mi...@us...> - 2005-08-20 16:09:22
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29643/b7_Scripts/EvaluatingOptimizationTechnique Added Files: OptimizationTechniqueEvaluator.cs Log Message: Added objects for testing optimization technique. --- NEW FILE: OptimizationTechniqueEvaluator.cs --- /* QuantProject - Quantitative Finance Library OptimizationTechniqueEvaluator.cs Copyright (C) 2003 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.Statistics; namespace QuantProject.Scripts.EvaluatingOptimizationTechnique { /// <summary> /// Class for evaluating a given optimization technique /// </summary> [Serializable] public class OptimizationTechniqueEvaluator { double[] fitnessesInSample; double[] fitnessesOutOfSample; /// <summary> /// Creates a new instance of OptimizationTechniqueEvaluator /// </summary> /// <param name="fitnessesInSample">The array has to contain the fitnesses in sample (the values computed by the optimizer). Fitnesses in sample have to be ordered!</param> /// <param name="fitnessesOutOfSample">The array has to contain the fitnesses out of sample /// (the values evaluated by the trading simpulation). Fitnesses out of sample have to /// corresponde one by one to fitnesses in sample</param> public OptimizationTechniqueEvaluator(double[] fitnessesInSample, double[] fitnessesOutOfSample) { this.optimizationTechniqueEvaluator_checkParameters(fitnessesInSample, fitnessesOutOfSample); this.fitnessesInSample = fitnessesInSample; this.fitnessesOutOfSample = fitnessesOutOfSample; } private void optimizationTechniqueEvaluator_checkParameters(double[] fitnessesInSample, double[] fitnessesOutOfSample) { if(fitnessesInSample.Length != fitnessesOutOfSample.Length) throw new Exception("fitnessesInSample and fitnessesOutOfSample " + "can't have a different size!"); } /// <summary> /// Returns the average values for the given sub-sets of /// fitnesses in sample. Fitnesses in sample are ordered! /// </summary> /// <param name="numberOfSubsets">Number of sub-sets fitnessesInSample are divided into</param> public double[] GetAveragesOfSubsetsInSample(int numberOfSubsets) { return this.getSubsetAverage(this.fitnessesInSample, numberOfSubsets); } /// <summary> /// Returns the average values for the given sub-sets of /// fitnesses out of sample /// </summary> /// <param name="numberOfSubsets">Number of sub-sets fitnessesOutOfSample are divided into</param> public double[] GetAveragesOfSubsetsOutOfSample(int numberOfSubsets) { return this.getSubsetAverage(this.fitnessesOutOfSample, numberOfSubsets); } private void getSubsetAverage_checkParameters(int numberOfSubsets) { if(numberOfSubsets > this.fitnessesInSample.Length) //fitnessesInSample have the same length as fitnessesOutOfSample throw new Exception("numberOfSubsets can't be greater than the number of data points!"); } /// <summary> /// Returns the average values for the given sub-set of /// a given set of data /// </summary> /// <param name="data">The set of data points(inSample or OutOfSample)</param> /// <param name="numberOfSubsets">Number of sub-sets the /// given set of data is divided into</param> private double[] getSubsetAverage(double[] data, int numberOfSubsets) { this.getSubsetAverage_checkParameters(numberOfSubsets); int numberOfDataPointsInEachSubset = (int)Math.Floor(Convert.ToDouble(data.Length)/Convert.ToDouble(numberOfSubsets)); double[] returnValue = new double[numberOfSubsets]; for(int i = 0; i<numberOfSubsets; i++) { for(int j = i * numberOfDataPointsInEachSubset; j<(i+1)* numberOfDataPointsInEachSubset; j++) { returnValue[i]+= data[j]/numberOfDataPointsInEachSubset; } } return returnValue; } /// <summary> /// Returns the Pearson correlation coefficient between fitnesses in sample /// and fitnesses out of sample /// </summary> public double GetCorrelationBetweenFitnesses() { return BasicFunctions.PearsonCorrelationCoefficient(this.fitnessesInSample, this.fitnessesOutOfSample); } } } |
|
From: Marco M. <mi...@us...> - 2005-08-20 16:06:03
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29146/EfficientPortfolio Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio added to the repository |
|
From: Marco M. <mi...@us...> - 2005-08-20 16:05:55
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29112/EvaluatingOptimizationTechnique Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique added to the repository |
|
From: Glauco S. <gla...@us...> - 2005-08-11 23:02:12
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv608 Added Files: WalkForwardOpenToCloseDailyStrategy.cs Log Message: Open to close daily strategy, for walk forward testing --- NEW FILE: WalkForwardOpenToCloseDailyStrategy.cs --- /* QuantProject - Quantitative Finance Library WalkForwardOpenToCloseDailyStrategy.cs Copyright (C) 2003 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.Collections; using System.Data; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Strategies; using QuantProject.Business.Timing; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Open to close daily strategy, for walk forward testing /// </summary> [Serializable] public class WalkForwardOpenToCloseDailyStrategy : IEndOfDayStrategy { private Account account; private string tickerGroupID; private int numDaysForInSampleOptimization; private int numberOfEligibleTickers; private int numberOfTickersToBeChosen; private string benchmark; private double targetReturn; private PortfolioType portfolioType; private int populationSizeForGeneticOptimizer; private int generationNumberForGeneticOptimizer; private string[] signedTickersFromLastOptimization; private GeneticOptimizer geneticOptimizer; public WalkForwardOpenToCloseDailyStrategy( Account account , string tickerGroupID , int numDaysForInSampleOptimization , int numberOfEligibleTickers , int numberOfTickersToBeChosen , string benchmark , double targetReturn , PortfolioType portfolioType , int populationSizeForGeneticOptimizer , int generationNumberForGeneticOptimizer ) { this.account = account; this.tickerGroupID = tickerGroupID; this.numDaysForInSampleOptimization = numDaysForInSampleOptimization; this.numberOfEligibleTickers = numberOfEligibleTickers; this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; this.benchmark = benchmark; this.targetReturn = targetReturn; this.portfolioType = portfolioType; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; } private long marketOpenEventHandler_addOrder_getQuantity( string ticker ) { double accountValue = this.account.GetMarketValue(); double currentTickerAsk = this.account.DataStreamer.GetCurrentAsk( ticker ); double maxPositionValueForThisTicker = accountValue/this.signedTickersFromLastOptimization.Length; long quantity = Convert.ToInt64( Math.Floor( maxPositionValueForThisTicker / currentTickerAsk ) ); return quantity; } private void marketOpenEventHandler_addOrder( string signedTicker ) { OrderType orderType = GenomeRepresentation.GetOrderType( signedTicker ); string ticker = GenomeRepresentation.GetTicker( signedTicker ); long quantity = marketOpenEventHandler_addOrder_getQuantity( ticker ); Order order = new Order( orderType , new Instrument( ticker ) , quantity ); this.account.AddOrder( order ); } private void marketOpenEventHandler_addOrders() { if ( this.signedTickersFromLastOptimization != null ) foreach ( string signedTicker in this.signedTickersFromLastOptimization ) marketOpenEventHandler_addOrder( signedTicker ); } public void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( ( this.account.CashAmount == 0 ) && ( this.account.Transactions.Count == 0 ) ) // cash has not been added yet this.account.AddCash( 30000 ); marketOpenEventHandler_addOrders(); } private void fiveMinutesBeforeMarketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); foreach ( Position position in this.account.Portfolio.Positions ) tickers.Add( position.Instrument.Key ); foreach ( string ticker in tickers ) this.account.ClosePosition( ticker ); } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { this.fiveMinutesBeforeMarketCloseEventHandler_closePositions(); } public void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } protected DataTable getSetOfTickersToBeOptimized( DateTime optimizationFirstDate , DateTime optimizationLastDate ) { SelectorByLiquidity mostLiquid = new SelectorByLiquidity( this.tickerGroupID , false , optimizationFirstDate , optimizationLastDate , this.numberOfEligibleTickers ); DataTable eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( eligibleTickers, false , optimizationFirstDate , optimizationLastDate , this.numberOfEligibleTickers, this.benchmark); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); } private void newGenerationEventHandler( object sender , NewGenerationEventArgs newGenerationEventArgs ) { Console.WriteLine( newGenerationEventArgs.GenerationCounter.ToString() + " / " + newGenerationEventArgs.GenerationNumber.ToString() + " - " + DateTime.Now.ToString() ); } private void oneHourAfterMarketCloseEventHandler_set_signedTickersFromLastOptimization( DateTime currentDate ) { // this.bestGenomes = new ArrayList(); // DataTable setOfTickersToBeOptimized = // this.getSetOfTickersToBeOptimized_quickly(); DateTime optimizationFirstDate = currentDate.AddDays( -this.numDaysForInSampleOptimization + 1 ); DateTime optimizationLastDate = currentDate; DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized( optimizationFirstDate , optimizationLastDate ); GenomeManagerForEfficientCTOPortfolio genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio( setOfTickersToBeOptimized , currentDate.AddDays( this.numDaysForInSampleOptimization - 1 ) , currentDate , this.numberOfTickersToBeChosen , this.targetReturn , this.portfolioType ); this.geneticOptimizer = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); this.geneticOptimizer.NewGeneration += new NewGenerationEventHandler( this.newGenerationEventHandler ); // Thread thread = new Thread(new ThreadStart(this.createOptimizedGenomes_go)); // thread.IsBackground = true; // thread.Start(); this.geneticOptimizer.Run(false); this.signedTickersFromLastOptimization = (string[])this.geneticOptimizer.BestGenome.Meaning; } public void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { if ( endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.DayOfWeek == DayOfWeek.Friday ) // current day is Friday { Console.WriteLine( endOfDayTimingEventArgs.EndOfDayDateTime.DateTime.ToString() + " - " + DateTime.Now.ToString() ); oneHourAfterMarketCloseEventHandler_set_signedTickersFromLastOptimization( endOfDayTimingEventArgs.EndOfDayDateTime.DateTime ); } } } } |
|
From: Glauco S. <gla...@us...> - 2005-08-11 23:02:05
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv304 Added Files: RunWalkForwardLinearCombination.cs Log Message: Walk Forward test for the linear combination strategy --- NEW FILE: RunWalkForwardLinearCombination.cs --- /* QuantProject - Quantitative Finance Library RunWalkForwardLinearCombination.cs Copyright (C) 2003 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.Collections; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Strategies; using QuantProject.Business.Timing; using QuantProject.Presentation.Reporting.WindowsForm; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Walk Forward test for the linear combination strategy /// </summary> public class RunWalkForwardLinearCombination { private string tickerGroupID; private int numDaysForInSampleOptimization; private int numberOfEligibleTickers; private int numberOfTickersToBeChosen; private int numDaysForLiquidity; private int generationNumberForGeneticOptimizer; private int populationSizeForGeneticOptimizer; private string benchmark; private DateTime firstDate; private DateTime lastDate; private double targetReturn; private PortfolioType portfolioType; private bool openToCloseDaily; private IHistoricalQuoteProvider historicalQuoteProvider; private HistoricalEndOfDayTimer historicalEndOfDayTimer; private Account account; private IEndOfDayStrategy endOfDayStrategy; public RunWalkForwardLinearCombination(string tickerGroupID, int numDaysForInSampleOptimization , int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime firstDate, DateTime lastDate, double targetReturn, PortfolioType portfolioType , bool openToCloseDaily ) { this.tickerGroupID = tickerGroupID; this.numDaysForInSampleOptimization = numDaysForInSampleOptimization; this.numberOfEligibleTickers = numberOfEligibleTickers; this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; this.numDaysForLiquidity = numDaysForLiquidity; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.benchmark = benchmark; this.firstDate = firstDate; this.lastDate = lastDate; this.targetReturn = targetReturn; this.portfolioType = portfolioType; this.openToCloseDaily = openToCloseDaily; } private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.EndOfDayTimer.GetCurrentTime().DateTime >= this.lastDate ) this.account.EndOfDayTimer.Stop(); } private void run_setHistoricalQuoteProvider() { if ( this.openToCloseDaily ) this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); else this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } private void run_setStrategy() { if ( this.openToCloseDaily ) this.endOfDayStrategy = new WalkForwardOpenToCloseDailyStrategy( this.account , this.tickerGroupID , this.numDaysForInSampleOptimization , this.numberOfEligibleTickers , this.numberOfTickersToBeChosen , this.benchmark , this.targetReturn , this.portfolioType , this.populationSizeForGeneticOptimizer , this.generationNumberForGeneticOptimizer ); // else // this.endOfDayStrategy = new OpenToCloseWeeklyStrategy( // this.account , this.signedTickers ); } public void Run() { this.historicalEndOfDayTimer = new IndexBasedEndOfDayTimer( new EndOfDayDateTime( this.firstDate , EndOfDaySpecificTime.MarketOpen ) , "DYN" ); run_setHistoricalQuoteProvider(); this.account = new Account( "LinearCombination" , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , this.historicalQuoteProvider ) ); run_setStrategy(); // OneRank oneRank = new OneRank( account , // this.endDateTime ); this.historicalEndOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.endOfDayStrategy.MarketOpenEventHandler ); this.historicalEndOfDayTimer.FiveMinutesBeforeMarketClose += new FiveMinutesBeforeMarketCloseEventHandler( this.endOfDayStrategy.FiveMinutesBeforeMarketCloseEventHandler ); this.historicalEndOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayStrategy.OneHourAfterMarketCloseEventHandler ); this.historicalEndOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.oneHourAfterMarketCloseEventHandler ); this.account.EndOfDayTimer.Start(); Report report = new Report( this.account , this.historicalQuoteProvider ); report.Create( "Linear Combination" , 1 , new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^SPX" ); // ObjectArchiver.Archive( report.AccountReport , // @"C:\Documents and Settings\Glauco\Desktop\reports\runOneRank.qPr" ); report.Show(); } } } |
|
From: Glauco S. <gla...@us...> - 2005-08-11 23:00:57
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32476/WalkForwardTest Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest added to the repository |
|
From: Glauco S. <gla...@us...> - 2005-08-10 16:53:58
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28434/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: TestDisplayer.cs Log Message: The genomeRepresentation is passed as a parameter, now Index: TestDisplayer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/TestDisplayer.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TestDisplayer.cs 2 Aug 2005 23:10:35 -0000 1.4 --- TestDisplayer.cs 10 Aug 2005 16:53:45 -0000 1.5 *************** *** 223,227 **** LinearCombinationTest linearCombinationTest = new LinearCombinationTest( this.dtpFirstDate.Value , ! this.dtpLastDate.Value , signedTickers , this.radioButtonOpenToCloseDaily.Checked ); linearCombinationTest.Run(); --- 223,227 ---- LinearCombinationTest linearCombinationTest = new LinearCombinationTest( this.dtpFirstDate.Value , ! this.dtpLastDate.Value , genomeRepresentation , this.radioButtonOpenToCloseDaily.Checked ); linearCombinationTest.Run(); |
|
From: Glauco S. <gla...@us...> - 2005-08-10 16:51:38
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27983/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: LinearCombinationTest.cs Log Message: - added an informative title (to be compacted, yet) - the genomeRepresentation is passed as a parameter, now Index: LinearCombinationTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/LinearCombinationTest.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** LinearCombinationTest.cs 2 Aug 2005 23:12:59 -0000 1.2 --- LinearCombinationTest.cs 10 Aug 2005 16:51:31 -0000 1.3 *************** *** 43,47 **** private DateTime firstDate; private DateTime lastDate; ! private string[] signedTickers; private bool openToCloseDaily; --- 43,47 ---- private DateTime firstDate; private DateTime lastDate; ! private GenomeRepresentation genomeRepresentation; private bool openToCloseDaily; *************** *** 52,60 **** public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! string[] signedTickers , bool openToCloseDaily ) { this.firstDate = firstDate; this.lastDate = lastDate; ! this.signedTickers = signedTickers; this.openToCloseDaily = openToCloseDaily; } --- 52,60 ---- public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation genomeRepresentation , bool openToCloseDaily ) { this.firstDate = firstDate; this.lastDate = lastDate; ! this.genomeRepresentation = genomeRepresentation; this.openToCloseDaily = openToCloseDaily; } *************** *** 77,86 **** private void run_setStrategy() { if ( this.openToCloseDaily ) this.endOfDayStrategy = new OpenToCloseDailyStrategy( ! this.account , this.signedTickers ); else this.endOfDayStrategy = new OpenToCloseWeeklyStrategy( ! this.account , this.signedTickers ); } public void Run() --- 77,107 ---- private void run_setStrategy() { + string[] signedTickers = GenomeRepresentation.GetSignedTickers( + this.genomeRepresentation.SignedTickers ); if ( this.openToCloseDaily ) this.endOfDayStrategy = new OpenToCloseDailyStrategy( ! this.account , signedTickers ); else this.endOfDayStrategy = new OpenToCloseWeeklyStrategy( ! this.account , signedTickers ); ! } ! private string getDateString( DateTime dateTime ) ! { ! string returnValue = dateTime.ToString( "yy-MM-dd" ); ! return returnValue; ! } ! private string run_getReportTitle() ! { ! string returnValue = "Fitness:" + ! this.genomeRepresentation.Fitness.ToString() + ! " | Tickers:" + ! this.genomeRepresentation.SignedTickers + " - " + ! "from " + this.getDateString( this.firstDate ) + ! " to " + this.getDateString( this.lastDate ) + ! " opt. in sample from " + this.getDateString( ! this.genomeRepresentation.FirstOptimizationDate ) + ! " to " + this.getDateString( ! this.genomeRepresentation.LastOptimizationDate ); ! return returnValue; } public void Run() *************** *** 97,102 **** this.historicalQuoteProvider ) ); run_setStrategy(); ! // OneRank oneRank = new OneRank( account , ! // this.endDateTime ); this.historicalEndOfDayTimer.MarketOpen += new MarketOpenEventHandler( --- 118,123 ---- this.historicalQuoteProvider ) ); run_setStrategy(); ! // OneRank oneRank = new OneRank( account , ! // this.endDateTime ); this.historicalEndOfDayTimer.MarketOpen += new MarketOpenEventHandler( *************** *** 116,119 **** --- 137,141 ---- // ObjectArchiver.Archive( report.AccountReport , // @"C:\Documents and Settings\Glauco\Desktop\reports\runOneRank.qPr" ); + report.Text = this.run_getReportTitle(); report.Show(); } |
|
From: Glauco S. <gla...@us...> - 2005-08-10 16:49:27
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27494/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: MainForm.cs Log Message: TestDisplayer is not modal anymore. Index: MainForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/MainForm.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MainForm.cs 29 Jul 2005 13:39:35 -0000 1.4 --- MainForm.cs 10 Aug 2005 16:49:20 -0000 1.5 *************** *** 224,231 **** { this.bestGenomes = new ArrayList(); - DataTable setOfTickersToBeOptimized = - this.getSetOfTickersToBeOptimized_quickly(); // DataTable setOfTickersToBeOptimized = ! // this.getSetOfTickersToBeOptimized(); GenomeManagerForEfficientCTOPortfolio genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, --- 224,231 ---- { this.bestGenomes = new ArrayList(); // DataTable setOfTickersToBeOptimized = ! // this.getSetOfTickersToBeOptimized_quickly(); ! DataTable setOfTickersToBeOptimized = ! this.getSetOfTickersToBeOptimized(); GenomeManagerForEfficientCTOPortfolio genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, *************** *** 276,280 **** TestDisplayer testDisplayer = new TestDisplayer( this.firstDate , this.lastDate , this.bestGenomes ); ! testDisplayer.ShowDialog(); } private void testOptimizedGenomes() --- 276,281 ---- TestDisplayer testDisplayer = new TestDisplayer( this.firstDate , this.lastDate , this.bestGenomes ); ! this.bestGenomes = null; ! testDisplayer.Show(); } private void testOptimizedGenomes() |
|
From: Glauco S. <gla...@us...> - 2005-08-10 16:48:06
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27234/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs Log Message: Now, an exception is thrown if setOfInitialTickers is empty. Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** GenomeManagerForEfficientPortfolio.cs 8 Aug 2005 19:15:40 -0000 1.17 --- GenomeManagerForEfficientPortfolio.cs 10 Aug 2005 16:47:59 -0000 1.18 *************** *** 118,121 **** --- 118,123 ---- { this.setOfTickers = setOfInitialTickers; + if ( setOfInitialTickers.Rows.Count == 0 ) + throw new Exception( "setOfInitialTickers cannot be empty!" ); this.originalNumOfTickers = setOfInitialTickers.Rows.Count; this.firstQuoteDate = firstQuoteDate; |
|
From: Glauco S. <gla...@us...> - 2005-08-10 16:47:08
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26935/b2_DataAccess Modified Files: DataBaseLocator.cs Log Message: We are a bit lazy... but finally, the bug has been fixed :-) Now the database location is not asked if it is not needed !!! Index: DataBaseLocator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/DataBaseLocator.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DataBaseLocator.cs 24 Jun 2005 22:35:56 -0000 1.3 --- DataBaseLocator.cs 10 Aug 2005 16:46:59 -0000 1.4 *************** *** 45,49 **** this.dataBaseType = fileExtension; //it looks for the file in the application directory ! if (!File.Exists("DataBase.xml")) createXmlFile(); --- 45,53 ---- this.dataBaseType = fileExtension; //it looks for the file in the application directory ! // if (!File.Exists("DataBase.xml")) ! string xmlPath = Application.ExecutablePath.Substring(0, ! Application.ExecutablePath.LastIndexOf('\\') ) ! + @"\DataBase.xml"; ! if (!File.Exists( xmlPath )) createXmlFile(); |
|
From: Glauco S. <gla...@us...> - 2005-08-10 16:44:58
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26470/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: - WalkForwardTesting\LinearCombination\WalkForwardTest\RunWalkForwardLinearCombination.cs has been added - WalkForwardTesting\LinearCombination\WalkForwardTest\WalkForwardOpenToCloseDailyStrategy.cs has been added Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** b7_Scripts.csproj 2 Aug 2005 23:06:22 -0000 1.35 --- b7_Scripts.csproj 10 Aug 2005 16:44:50 -0000 1.36 *************** *** 319,322 **** --- 319,332 ---- /> <File + RelPath = "WalkForwardTesting\LinearCombination\WalkForwardTest\RunWalkForwardLinearCombination.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\LinearCombination\WalkForwardTest\WalkForwardOpenToCloseDailyStrategy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\MSFTwalkForward\TsMSFTwalkForward.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2005-08-10 04:53:32
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20612/b4_Business Modified Files: Business.prjx Log Message: Updated #develop projects files. Index: Business.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business.prjx,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Business.prjx 24 Jun 2005 22:54:50 -0000 1.4 --- Business.prjx 8 Aug 2005 19:16:17 -0000 1.5 *************** *** 91,94 **** --- 91,95 ---- <File name=".\a1_Financial\a2_Accounting\h5_Reporting\SummaryRows\IntegerSummaryRow.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\a1_Financial\a2_Accounting\h5_Reporting\SummaryRows\PercentageSummaryRow.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\a2_Strategies\IEndOfDayStrategy.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-08-10 04:37:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20612/b7_Scripts Modified Files: Scripts.prjx Log Message: Updated #develop projects files. Index: Scripts.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts.prjx,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Scripts.prjx 3 Aug 2005 18:59:58 -0000 1.9 --- Scripts.prjx 8 Aug 2005 19:16:17 -0000 1.10 *************** *** 48,51 **** --- 48,53 ---- <File name=".\TickerSelectionTesting\RunEfficientCTCWeeklyPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\TickerSelectionTesting\GenomeManipulator.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\WalkForwardTesting\LinearCombination\OpenToCloseWeeklyStrategy.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\WalkForwardTesting\LinearCombination\OpenToCloseDailyStrategy.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-08-10 03:57:04
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20455/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs GenomeManipulator.cs Log Message: GetNewGeneValue and Mutate have been modified. Added new method to GenomeManipulator. Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** GenomeManagerForEfficientPortfolio.cs 7 Aug 2005 22:37:28 -0000 1.16 --- GenomeManagerForEfficientPortfolio.cs 8 Aug 2005 19:15:40 -0000 1.17 *************** *** 230,236 **** int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); ! while(genome.HasGene(returnValue) || ! ( returnValue<0 && genome.HasGene(Math.Abs(returnValue) - 1 ) )|| ! (returnValue>0 && genome.HasGene(- Math.Abs(returnValue) - 1)) ) //the portfolio can't have a long position and a short one for the same ticker { --- 230,235 ---- int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); ! while(GenomeManipulator.IsTickerContainedInGenome(returnValue, ! genome) ) //the portfolio can't have a long position and a short one for the same ticker { *************** *** 249,255 **** genome.MaxValueForGenes +1); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(genome.HasGene(returnValue) || ! ( returnValue<0 && genome.HasGene(Math.Abs(returnValue) - 1 ) )|| ! (returnValue>0 && genome.HasGene(- Math.Abs(returnValue) - 1)) ) //the efficient portfolio, in this implementation, // can't have a long position and a short position --- 248,253 ---- genome.MaxValueForGenes +1); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(GenomeManipulator.IsTickerContainedInGenome(newValueForGene, ! genome) ) //the efficient portfolio, in this implementation, // can't have a long position and a short position Index: GenomeManipulator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManipulator.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GenomeManipulator.cs 7 Aug 2005 08:20:53 -0000 1.4 --- GenomeManipulator.cs 8 Aug 2005 19:15:41 -0000 1.5 *************** *** 217,220 **** --- 217,239 ---- return childs; } + + /// <summary> + /// Returns true if a given gene, when decoded by the + /// GenomeManagerForEfficientPortfolio, refers to a + /// ticker already contained in a given genome + /// </summary> + /// <param name="geneCorrespondingToATicker">Gene, corresponding to a certain ticker, that has to be checked</param> + /// <param name="genome">Genome containing or not the ticker geneCorrespondingToATicker refers to</param> + public static bool IsTickerContainedInGenome(int geneCorrespondingToATicker, + Genome genome) + { + return( + genome.HasGene(geneCorrespondingToATicker) || + (geneCorrespondingToATicker<0 && + genome.HasGene(Math.Abs(geneCorrespondingToATicker)-1)) || + (geneCorrespondingToATicker>0 && genome.HasGene(- Math.Abs(geneCorrespondingToATicker)- 1)) + ); + + } } |
|
From: Marco M. <mi...@us...> - 2005-08-07 22:37:43
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5555/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs Log Message: Fixed bugs in GetNewGeneValue and Mutate methods Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** GenomeManagerForEfficientPortfolio.cs 31 Jul 2005 20:03:31 -0000 1.15 --- GenomeManagerForEfficientPortfolio.cs 7 Aug 2005 22:37:28 -0000 1.16 *************** *** 231,236 **** genome.MaxValueForGenes + 1); while(genome.HasGene(returnValue) || ! genome.HasGene(Math.Abs(returnValue) - 1 ) || ! genome.HasGene(- Math.Abs(returnValue) - 1) ) //the portfolio can't have a long position and a short one for the same ticker { --- 231,236 ---- genome.MaxValueForGenes + 1); while(genome.HasGene(returnValue) || ! ( returnValue<0 && genome.HasGene(Math.Abs(returnValue) - 1 ) )|| ! (returnValue>0 && genome.HasGene(- Math.Abs(returnValue) - 1)) ) //the portfolio can't have a long position and a short one for the same ticker { *************** *** 249,255 **** genome.MaxValueForGenes +1); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(genome.HasGene(newValueForGene) || ! genome.HasGene(Math.Abs(newValueForGene) - 1 ) || ! genome.HasGene(- Math.Abs(newValueForGene) - 1) ) //the efficient portfolio, in this implementation, // can't have a long position and a short position --- 249,255 ---- genome.MaxValueForGenes +1); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(genome.HasGene(returnValue) || ! ( returnValue<0 && genome.HasGene(Math.Abs(returnValue) - 1 ) )|| ! (returnValue>0 && genome.HasGene(- Math.Abs(returnValue) - 1)) ) //the efficient portfolio, in this implementation, // can't have a long position and a short position |
|
From: Marco M. <mi...@us...> - 2005-08-07 08:21:09
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18128/b1_ADT/Optimizing/Genetic Modified Files: GenomeManagement.cs Log Message: Code has been simplified and a bug has been fixed in setMaskForChildsForMixingWithoutDuplicates (method used by MixGenesWithoutDuplicates) Index: GenomeManagement.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagement.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GenomeManagement.cs 31 Jul 2005 19:53:44 -0000 1.6 --- GenomeManagement.cs 7 Aug 2005 08:20:53 -0000 1.7 *************** *** 56,68 **** } - private static void assignFitnessAndMeaningToChilds() - { - foreach(Genome child in childs) - { - child.AssignMeaning(); - child.CalculateFitness(); - } - } - private static void setChildsUsingMaskForChilds(Genome parent1, Genome parent2) --- 56,59 ---- *************** *** 114,118 **** } } - GenomeManagement.assignFitnessAndMeaningToChilds(); return GenomeManagement.childs; } --- 105,108 ---- |
|
From: Marco M. <mi...@us...> - 2005-08-07 08:21:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18128/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManipulator.cs Log Message: Code has been simplified and a bug has been fixed in setMaskForChildsForMixingWithoutDuplicates (method used by MixGenesWithoutDuplicates) Index: GenomeManipulator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManipulator.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GenomeManipulator.cs 3 Aug 2005 23:12:25 -0000 1.3 --- GenomeManipulator.cs 7 Aug 2005 08:20:53 -0000 1.4 *************** *** 86,90 **** return returnValue; } ! private static void setMaskForChildsForMixingWithoutDuplicates(Genome parent1, Genome parent2) --- 86,90 ---- return returnValue; } ! /*old private static void setMaskForChildsForMixingWithoutDuplicates(Genome parent1, Genome parent2) *************** *** 119,123 **** } } ! private static void setChildsUsingMaskForChilds(Genome parent1, Genome parent2) --- 119,154 ---- } } ! */ ! private static void setMaskForChildsForMixingWithoutDuplicates(Genome parent1, Genome parent2) ! ! { ! int[] genePlacesOfParent1NotPresentInParent2 = ! genePositionsOfParent1NotPresentInParent2(parent1, parent2); ! int[] genePlacesOfParent2NotPresentInParent1 = ! genePositionsOfParent1NotPresentInParent2(parent2, parent1); ! bool justExchangedAtPreviousPosition = false; ! for(int i = 0;i<parent1.Size;i++) ! { ! if(!justExchangedAtPreviousPosition) ! //exchanges between genes of parents in childs ! //must follow an alternate pattern, in order to ! //avoid plain copy of parents in childs when all genes ! //of the first parent are not in the second one (and viceversa) ! { ! if(genePlacesOfParent2NotPresentInParent1[i]!= - 1) ! { ! maskForChilds[0, i] = 2; ! justExchangedAtPreviousPosition = true; ! } ! if(genePlacesOfParent1NotPresentInParent2[i]!= - 1) ! { ! maskForChilds[1, i] = 1; ! justExchangedAtPreviousPosition = true; ! } ! } ! else ! justExchangedAtPreviousPosition = false; ! } ! } private static void setChildsUsingMaskForChilds(Genome parent1, Genome parent2) |
|
From: Marco M. <mi...@us...> - 2005-08-03 23:12:33
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16620/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManipulator.cs Log Message: MixGenesWithoutDuplicates is now "stronger": exchange of genes occurs (if possible) in next gene position, if it hasn't in previous. Index: GenomeManipulator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManipulator.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManipulator.cs 3 Aug 2005 18:59:19 -0000 1.2 --- GenomeManipulator.cs 3 Aug 2005 23:12:25 -0000 1.3 *************** *** 31,35 **** /// <summary> /// Class providing static methods for manipulating Genomes ! /// (used by th IGenomeManagerForEfficientPortfolio) /// </summary> [Serializable] --- 31,35 ---- /// <summary> /// Class providing static methods for manipulating Genomes ! /// (used by IGenomeManagerForEfficientPortfolio) /// </summary> [Serializable] *************** *** 51,58 **** { genomeSize = parent1.Size; ! childs[0] = parent1.Clone(); ! childs[1] = parent2.Clone(); ! //the two childs now points to their parents, ! //and so do maskForChilds maskForChilds = new int[childs.Length, genomeSize]; for(int i = 0; i<genomeSize; i++) --- 51,56 ---- { genomeSize = parent1.Size; ! childs[0]=parent1.Clone(); ! childs[1]=parent2.Clone(); maskForChilds = new int[childs.Length, genomeSize]; for(int i = 0; i<genomeSize; i++) *************** *** 61,131 **** maskForChilds[1,i]=2; } } - private static void assignFitnessAndMeaningToChilds() - { - foreach(Genome child in childs) - { - child.AssignMeaning(); - child.CalculateFitness(); - } - } - - /*old - private static int firstGenePositionOfParent1NotPresentInParent2(Genome parent1, - Genome parent2) - { - int returnValue = -1; - for(int genePos = 0 ; - genePos < GenomeManipulator.genomeSize && returnValue == -1; - genePos++) - { - int geneValue = parent1.GetGeneValue(genePos); - if(geneValue >= 0) - { - if(!parent2.HasGene(geneValue) && - !parent2.HasGene(-Math.Abs(geneValue) - 1)) - returnValue = genePos; - } - else - { - if(!parent2.HasGene(geneValue) && - !parent2.HasGene(Math.Abs(geneValue) - 1)) - returnValue = genePos; - } - } - return returnValue; - } - */ - /* old - private static bool setMaskForChildsForMixingWithoutDuplicates(Genome parent1, Genome parent2) - - { - bool returnValue = false; - int firstGenePosOfParent1NotPresentInParent2 = - firstGenePositionOfParent1NotPresentInParent2(parent1, parent2); - int firstGenePosOfParent2NotPresentInParent1 = - firstGenePositionOfParent1NotPresentInParent2(parent2, parent1); - if(firstGenePosOfParent1NotPresentInParent2 > -1 && - firstGenePosOfParent2NotPresentInParent1 > -1 ) - //there is at least a gene in parent1 not present in parent2 and viceversa - { - for(int genePos = 0 ; genePos < GenomeManipulator.genomeSize ; genePos++) - { - if(genePos == firstGenePosOfParent1NotPresentInParent2) - maskForChilds[0, genePos] = 1; - else - maskForChilds[0, genePos] = 2; - - if(genePos == firstGenePosOfParent2NotPresentInParent1) - maskForChilds[1, genePos] = 2; - else - maskForChilds[1, genePos] = 1; - } - returnValue = true; - } - return returnValue; - } - */ private static int[] genePositionsOfParent1NotPresentInParent2(Genome parent1, Genome parent2) --- 59,66 ---- maskForChilds[1,i]=2; } + //maskForChilds has been set in order to re-create + //a copy of parents by using setChildsUsingMaskForChilds() } private static int[] genePositionsOfParent1NotPresentInParent2(Genome parent1, Genome parent2) *************** *** 159,166 **** int[] genePlacesOfParent2NotPresentInParent1 = genePositionsOfParent1NotPresentInParent2(parent2, parent1); for(int i = 0;i<parent1.Size;i++) { ! if(i%2 == 0) ! //genes are ex-changed only at even positions { if(genePlacesOfParent2NotPresentInParent1[i]!= - 1) --- 94,104 ---- int[] genePlacesOfParent2NotPresentInParent1 = genePositionsOfParent1NotPresentInParent2(parent2, parent1); + bool justExchangedAtPreviousPosition = false; for(int i = 0;i<parent1.Size;i++) { ! if(!justExchangedAtPreviousPosition) ! //exchanges between genes of parents in childs ! //must follow an alternate pattern, in order to ! //avoid plain copy of parents in childs { if(genePlacesOfParent2NotPresentInParent1[i]!= - 1) *************** *** 168,171 **** --- 106,110 ---- maskForChilds[0, i] = 2;//the change between genes maskForChilds[1, i] = 1;//creates a child different from parents + justExchangedAtPreviousPosition = true; } else if(genePlacesOfParent1NotPresentInParent2[i]!= - 1) //see 1st if *************** *** 173,178 **** --- 112,120 ---- maskForChilds[0, i] = 1; maskForChilds[1, i] = 2; + justExchangedAtPreviousPosition = true; } } + else + justExchangedAtPreviousPosition = false; } } |
|
From: Marco M. <mi...@us...> - 2005-08-03 23:08:42
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15585/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: Calculation of fitness and assigning of meaning now are not called for genomes that have been cloned and not changed by mutation process. Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GeneticOptimizer.cs 31 Jul 2005 20:03:31 -0000 1.9 --- GeneticOptimizer.cs 3 Aug 2005 23:08:33 -0000 1.10 *************** *** 481,485 **** foreach(Genome g in populationOfGenomes) { ! if(g != null) this.genomeManager.Mutate(g, this.MutationRate); } --- 481,485 ---- foreach(Genome g in populationOfGenomes) { ! //if(g != null) this.genomeManager.Mutate(g, this.MutationRate); } *************** *** 491,495 **** foreach(Genome g in populationOfGenomes) { ! if(g != null) { g.CalculateFitness(); --- 491,498 ---- foreach(Genome g in populationOfGenomes) { ! if(!g.HasBeenCloned || g.HasBeenChanged) ! //if it has been cloned and it has not been changed, ! //it's useless ! //to calculate again fitness and meaning { g.CalculateFitness(); |
|
From: Marco M. <mi...@us...> - 2005-08-03 23:05:32
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14556/b1_ADT/Optimizing/Genetic Modified Files: Genome.cs Log Message: Added HasBeenCloned and HasBeenChanged properties to the class. Index: Genome.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/Genome.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Genome.cs 1 Aug 2005 22:26:32 -0000 1.6 --- Genome.cs 3 Aug 2005 23:05:23 -0000 1.7 *************** *** 40,46 **** private double fitness; private object meaning; ! IGenomeManager genomeManager; public double Fitness { --- 40,63 ---- private double fitness; private object meaning; ! private bool hasBeenCloned; ! private bool hasBeenChanged; ! IGenomeManager genomeManager; + public bool HasBeenCloned + { + get{return this.hasBeenCloned;} + //set{this.hasBeenCloned = value;} + } + + /// <summary> + /// Returns true if a gene has been set + /// by calling SetGeneValue + /// </summary> + public bool HasBeenChanged + { + get{return this.hasBeenChanged;} + } + public double Fitness { *************** *** 120,123 **** --- 137,141 ---- returnValue.Fitness = this.Fitness; returnValue.Meaning = this.Meaning; + returnValue.hasBeenCloned = true; return returnValue; *************** *** 141,144 **** --- 159,163 ---- this.genes[genePosition] = geneValue; + this.hasBeenChanged = true; } |