quantproject-developers Mailing List for QuantProject (Page 80)
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...> - 2006-09-17 21:33:31
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv29454/b4_Business/a2_Strategies Modified Files: SignedTicker.cs Log Message: Fixed bug in GetCloseToClosePortfolioReturn method. The portfolio return is properly computed now. Index: SignedTicker.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/SignedTicker.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SignedTicker.cs 22 Jul 2006 20:50:16 -0000 1.5 --- SignedTicker.cs 17 Sep 2006 21:33:27 -0000 1.6 *************** *** 171,175 **** DateTime endDate ) { ! double returnValue = 0.0; Quotes[] tickersQuotes = new Quotes[signedTickers.Length]; for(int i = 0; i<signedTickers.Length; i++) --- 171,176 ---- DateTime endDate ) { ! const double initialEquity = 1.0; ! double equityValue = initialEquity; Quotes[] tickersQuotes = new Quotes[signedTickers.Length]; for(int i = 0; i<signedTickers.Length; i++) *************** *** 186,192 **** tickersWeights, tickersQuotes); for(int i = 0; i < returns.Length; i++) ! returnValue = (1.0+returnValue) * returns[i]; ! return returnValue; } --- 187,194 ---- tickersWeights, tickersQuotes); for(int i = 0; i < returns.Length; i++) ! equityValue = ! equityValue + equityValue * returns[i]; ! return (equityValue - initialEquity)/initialEquity; } *************** *** 221,225 **** SortedList commonMarketDays ) { ! double returnValue = 0.0; Quotes[] tickersQuotes = new Quotes[ signedTickers.Length ]; for( int i = 0 ; i < signedTickers.Length ; i++ ) --- 223,228 ---- SortedList commonMarketDays ) { ! const double initialEquity = 1.0; ! double equityValue = initialEquity; Quotes[] tickersQuotes = new Quotes[ signedTickers.Length ]; for( int i = 0 ; i < signedTickers.Length ; i++ ) *************** *** 233,239 **** tickersWeights , tickersQuotes); for( int i = 0 ; i < returns.Length ; i++ ) ! returnValue = (1.0+returnValue) * returns[i]; ! ! return returnValue; } --- 236,243 ---- tickersWeights , tickersQuotes); for( int i = 0 ; i < returns.Length ; i++ ) ! equityValue = ! equityValue + equityValue * returns[i]; ! ! return (equityValue - initialEquity)/initialEquity; } |
|
From: Marco M. <mi...@us...> - 2006-09-17 21:24:57
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv25928/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Added Files: RunPVO.cs GenomeMeaningPVO.cs GenomeManagerPVO.cs EndOfDayTimerHandlerPVO.cs Log Message: Added Portfolio Value Oscillator strategy. This strategy is similar to the strategy based on the popular technical RSI indicator (Relative Strength Index). --- NEW FILE: GenomeManagerPVO.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerPVO.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 System.Collections; using QuantProject.ADT; using QuantProject.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Implements what needed to use the Genetic Optimizer /// for finding the portfolio that best suites /// the Portfolio Value Oscillator strategy /// </summary> [Serializable] public class GenomeManagerPVO : GenomeManagerForEfficientPortfolio { private int minLevelForOversoldThreshold; private int maxLevelForOversoldThreshold; private int minLevelForOverboughtThreshold; private int maxLevelForOverboughtThreshold; private int divisorForThresholdComputation; private double currentOversoldThreshold = 0.0; private double currentOverboughtThreshold = 0.0; private int numDaysForOscillatingPeriod; private double[] portfolioValues;//the values for each unit, invested //at the beginning of the optimization period, //throughout the period itself private void genomeManagerPVO_checkParametersForThresholdComputation() { if(this.maxLevelForOverboughtThreshold < this.minLevelForOverboughtThreshold || this.maxLevelForOversoldThreshold < this.minLevelForOversoldThreshold || this.divisorForThresholdComputation < this.maxLevelForOverboughtThreshold || this.divisorForThresholdComputation < this.maxLevelForOversoldThreshold) throw new Exception("Bad parameters for threshold computation!"); } public GenomeManagerPVO(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, int numDaysForOscillatingPeriod, int minLevelForOversoldThreshold, int maxLevelForOversoldThreshold, int minLevelForOverboughtThreshold, int maxLevelForOverboughtThreshold, int divisorForThresholdComputation, PortfolioType portfolioType) : base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, 0.0, portfolioType) { this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; this.divisorForThresholdComputation = divisorForThresholdComputation; this.genomeManagerPVO_checkParametersForThresholdComputation(); this.retrieveData(); } public override int GenomeSize { get{return this.genomeSize + 2;} //two initial genes are for oversold and overbought thresholds } public override int GetMinValueForGenes(int genePosition) { int returnValue; switch (genePosition) { case 0 ://gene for oversold threshold returnValue = this.minLevelForOversoldThreshold; break; case 1 ://gene for overbought threshold returnValue = this.minLevelForOverboughtThreshold; break; default://gene for ticker returnValue = - this.originalNumOfTickers; break; } return returnValue; } public override int GetMaxValueForGenes(int genePosition) { int returnValue; switch (genePosition) { case 0 ://gene for oversold threshold returnValue = this.maxLevelForOversoldThreshold; break; case 1 ://gene for overbought threshold returnValue = this.maxLevelForOverboughtThreshold; break; default://gene for ticker returnValue = this.originalNumOfTickers - 1; break; } return returnValue; } protected override float[] getArrayOfRatesOfReturn(string ticker) { float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); returnValue = QuantProject.ADT.ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, Quotes.AdjustedCloseToCloseRatio); for(int i = 0; i<returnValue.Length; i++) returnValue[i] = returnValue[i] - 1.0f; this.numberOfExaminedReturns = returnValue.Length; return returnValue; } //starting from this.numDaysForOscillatingPeriod day, //it computes for each day ahead the value of the //portfolio opened numDaysForOscillatingPeriod days ago private double[] getPortfolioMovingValues() { double[] returnValue = new double[this.portfolioRatesOfReturn.Length]; double[] valuesInOscillatingPeriod = new double[this.numDaysForOscillatingPeriod]; valuesInOscillatingPeriod[0] = 1.0; for(int i = this.numDaysForOscillatingPeriod; i<returnValue.Length; i++) { for(int j = 1; j < this.numDaysForOscillatingPeriod; j++) valuesInOscillatingPeriod[j] = valuesInOscillatingPeriod[j - 1] + valuesInOscillatingPeriod[j - 1] * this.portfolioRatesOfReturn[i-this.numDaysForOscillatingPeriod+j]; returnValue[i-1] = valuesInOscillatingPeriod[this.numDaysForOscillatingPeriod -1]; } return returnValue; } private void getFitnessValue_setCurrentThresholds(Genome genome) { this.currentOversoldThreshold = Convert.ToDouble(genome.Genes()[0])/ Convert.ToDouble(this.divisorForThresholdComputation); this.currentOverboughtThreshold = Convert.ToDouble(genome.Genes()[1])/ Convert.ToDouble(this.divisorForThresholdComputation); } private int getFitnessValue_getDaysOnTheMarket(double[] equityLine) { int returnValue = 0; foreach(double equityReturn in equityLine) if(equityReturn > 0.0) returnValue++; return returnValue; } //fitness is a sharpe-ratio based indicator for the equity line resulting //from applying the strategy public override double GetFitnessValue(Genome genome) { double returnValue = -1.0; this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); this.portfolioValues = this.getPortfolioMovingValues(); this.getFitnessValue_setCurrentThresholds(genome); double[] equityLine = this.getFitnessValue_getEquityLineRates(); double fitness = Double.NaN; if(this.getFitnessValue_getDaysOnTheMarket(equityLine) > equityLine.Length / 2) //if the genome represents a portfolio that stays on the market //at least half of the theoretical days fitness = AdvancedFunctions.GetSharpeRatio(equityLine); if(!double.IsNaN(fitness) && !double.IsInfinity(fitness)) returnValue = fitness; return returnValue; } private double[] getFitnessValue_getEquityLineRates() { double[] returnValue = new double[this.PortfolioRatesOfReturn.Length]; double coefficient = 0.0; for(int i = 0; i<this.PortfolioRatesOfReturn.Length - 1;i++) { if(this.portfolioValues[i] >= 1.0 + this.currentOverboughtThreshold) //portfolio is overbought coefficient = -1.0; else if(this.portfolioValues[i] <= 1.0 - this.currentOversoldThreshold && this.portfolioValues[i] > 0.0) //portfolio is oversold coefficient = 1.0; returnValue[i + 1] = coefficient * this.PortfolioRatesOfReturn[i + 1]; } return returnValue; } protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) { return 1.0/(genes.Length - 2); //two genes are for thresholds } protected override double[] getPortfolioRatesOfReturn(int[] genes) { double[] returnValue = new double[this.numberOfExaminedReturns]; for(int i = 0; i<returnValue.Length; i++) { for(int j=2; j<genes.Length; j++)//the first two genes are for thresholds returnValue[i] += this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(genes,j,i); } return returnValue; } public override object Decode(Genome genome) { string[] arrayOfTickers = new string[genome.Genes().Length - 2]; int geneForTicker; for(int genePosition = 2; genePosition < genome.Genes().Length; genePosition++) { geneForTicker = (int)genome.Genes().GetValue(genePosition); arrayOfTickers[genePosition - 2] = this.decode_getTickerCodeForLongOrShortTrade(geneForTicker); } GenomeMeaningPVO meaning = new GenomeMeaningPVO( arrayOfTickers, Convert.ToDouble(genome.Genes()[0])/Convert.ToDouble(this.divisorForThresholdComputation), Convert.ToDouble(genome.Genes()[1])/Convert.ToDouble(this.divisorForThresholdComputation), this.numDaysForOscillatingPeriod); return meaning; } public override Genome[] GetChilds(Genome parent1, Genome parent2) { //in this simple implementation //child have the tickers of one parent //and the thresholds of the other Genome[] childs = new Genome[2]; childs[0] = parent1.Clone(); childs[1] = parent2.Clone(); //exchange of genes coding thresholds childs[0].SetGeneValue(parent2.GetGeneValue(0),0); childs[0].SetGeneValue(parent2.GetGeneValue(1),1); childs[1].SetGeneValue(parent1.GetGeneValue(0),0); childs[1].SetGeneValue(parent1.GetGeneValue(1),1); return childs; } public override int GetNewGeneValue(Genome genome, int genePosition) { // in this implementation only new gene values pointing to tickers // must be different from the others already stored int minValueForGene = genome.GetMinValueForGenes(genePosition); int maxValueForGene = genome.GetMaxValueForGenes(genePosition); int returnValue = minValueForGene; if( minValueForGene != maxValueForGene) { returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, maxValueForGene + 1); while(genePosition > 1 && GenomeManipulator.IsTickerContainedInGenome(returnValue,genome,2,genome.Size - 1)) //while in the given position has to be stored //a new gene pointing to a ticker and //the proposed returnValue points to a ticker //already stored in the given genome { // a new returnValue has to be generated returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, maxValueForGene + 1); } } return returnValue; } public override void Mutate(Genome genome, double mutationRate) { // in this implementation only one gene is mutated int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); int minValueForGene = genome.GetMinValueForGenes(genePositionToBeMutated); int maxValueForGene = genome.GetMaxValueForGenes(genePositionToBeMutated); if(minValueForGenes != maxValueForGenes) { int newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, maxValueForGene +1); while(genePositionToBeMutated > 1 && GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome,2,genome.Size - 1)) //while in the proposed genePositionToBeMutated has to be stored //a new gene pointing to a ticker and //the proposed newValueForGene points to a ticker //already stored in the given genome { newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, maxValueForGene +1); } GenomeManagement.MutateOneGene(genome, mutationRate, genePositionToBeMutated, newValueForGene); } } } } --- NEW FILE: GenomeMeaningPVO.cs --- /* QuantProject - Quantitative Finance Library GenomeMeaningPVO.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 QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// This is the class representing the meaning for genome /// for the Portfolio Value Oscillator strategy /// </summary> [Serializable] public class GenomeMeaningPVO : GenomeMeaning { private double oversoldThreshold; private double overboughtThreshold; private int numDaysForOscillatingPeriod; public double OversoldThreshold { get{return this.oversoldThreshold;} } public double OverboughtThreshold { get{return this.overboughtThreshold;} } public int NumDaysForOscillatingPeriod { get{return this.numDaysForOscillatingPeriod;} } public GenomeMeaningPVO(string[] tickers, double[] tickersPortfolioWeights, double oversoldThreshold, double overboughtThreshold, int numDaysForOscillatingPeriod): base(tickers, tickersPortfolioWeights) { this.oversoldThreshold = oversoldThreshold; this.overboughtThreshold = overboughtThreshold; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } public GenomeMeaningPVO(string[] tickers, double oversoldThreshold, double overboughtThreshold, int numDaysForOscillatingPeriod): base(tickers) { this.oversoldThreshold = oversoldThreshold; this.overboughtThreshold = overboughtThreshold; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } } } --- NEW FILE: RunPVO.cs --- /* QuantProject - Quantitative Finance Library RunPVO.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 System.Data; using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Accounting.Reporting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Scripting; using QuantProject.Business.Strategies; using QuantProject.Business.Testing; using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; using QuantProject.ADT.FileManaging; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Script that implements an oscillating strategy, /// based on the classical technical indicator /// RelativeStrengthIndex - RSI /// </summary> [Serializable] public class RunPVO : RunEfficientPortfolio { private int minLevelForOversoldThreshold; private int maxLevelForOversoldThreshold; private int minLevelForOverboughtThreshold; private int maxLevelForOverboughtThreshold; private int divisorForThresholdComputation; //to be used by the optimizer private int numDaysBetweenEachOptimization; private double maxAcceptableCloseToCloseDrawdown; private int numDaysForOscillatingPeriod; public RunPVO(string tickerGroupID, int maxNumOfEligibleTickersForOptimization, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, int numDaysForOscillatingPeriod, int minLevelForOversoldThreshold, int maxLevelForOversoldThreshold, int minLevelForOverboughtThreshold, int maxLevelForOverboughtThreshold, int divisorForThresholdComputation, int numDaysBetweenEachOptimization, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, double maxRunningHours): base(tickerGroupID, maxNumOfEligibleTickersForOptimization, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, 0.0, portfolioType, maxRunningHours) { this.ScriptName = "PVO_SR_NoWeights_PriceSel"; this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; this.divisorForThresholdComputation = divisorForThresholdComputation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } #region auxiliary overriden methods for Run protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerPVO(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.numDaysForOscillatingPeriod, this.minLevelForOversoldThreshold, this.maxLevelForOversoldThreshold, this.minLevelForOverboughtThreshold, this.maxLevelForOverboughtThreshold, this.divisorForThresholdComputation, this.numDaysBetweenEachOptimization, this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } protected override void run_initializeHistoricalQuoteProvider() { this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.endOfDayTimerHandler.MarketCloseEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.checkDateForReport); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); } public override void SaveScriptResults() { string fileName = this.scriptName + "OsDays_" + numDaysForOscillatingPeriod + "_From_" + this.tickerGroupID + "_" + this.numberOfEligibleTickers + "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tick" + this.numberOfTickersToBeChosen + "GenN°" + this.generationNumberForGeneticOptimizer + "PopSize" + this.populationSizeForGeneticOptimizer + Convert.ToString(this.portfolioType); string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveBestGenomes = System.Configuration.ConfigurationSettings.AppSettings["GenomesArchive"] + "\\" + this.ScriptName + "\\"; this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); OptimizationOutput optimizationOutput = new OptimizationOutput(); foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) optimizationOutput.Add(genomeRepresentation); ObjectArchiver.Archive(optimizationOutput, dirNameWhereToSaveBestGenomes + fileName + ".bgn"); //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ObjectArchiver.Archive(accountReport, dirNameWhereToSaveReports + fileName + ".qPr"); this.endOfDayTimer.Stop(); } #endregion } } --- NEW FILE: EndOfDayTimerHandlerPVO.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerPVO.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 System.Collections; using QuantProject.ADT; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Business.Strategies; using QuantProject.Data; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Implements MarketOpenEventHandler and MarketCloseEventHandler /// These handlers contain the core strategy for the Portfolio Value /// Oscillator /// </summary> [Serializable] public class EndOfDayTimerHandlerPVO : EndOfDayTimerHandler { private int minLevelForOversoldThreshold; private int maxLevelForOversoldThreshold; private int minLevelForOverboughtThreshold; private int maxLevelForOverboughtThreshold; private int divisorForThresholdComputation; protected int numDaysForOscillatingPeriod; protected double currentOversoldThreshold; protected double currentOverboughtThreshold; private double maxAcceptableCloseToCloseDrawdown; private bool stopLossConditionReached; private double currentAccountValue; private double previousAccountValue; private int numDaysBetweenEachOptimization; private int numDaysElapsedSinceLastOptimization; private DateTime lastCloseDate; private IGenomeManager iGenomeManager; private int seedForRandomGenerator; private bool portfolioHasBeenOverbought; private bool portfolioHasBeenOversold; public EndOfDayTimerHandlerPVO(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, int numDaysForOscillatingPeriod, int minLevelForOversoldThreshold, int maxLevelForOversoldThreshold, int minLevelForOverboughtThreshold, int maxLevelForOverboughtThreshold, int divisorForThresholdComputation, int numDaysBetweenEachOptimization, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, 0.0, portfolioType) { this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; this.divisorForThresholdComputation = divisorForThresholdComputation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.stopLossConditionReached = false; this.currentAccountValue = 0.0; this.previousAccountValue = 0.0; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; this.portfolioHasBeenOverbought = false; this.portfolioHasBeenOversold = false; } #region MarketCloseEventHandler protected void marketCloseEventHandler_updateStopLossCondition() { this.previousAccountValue = this.currentAccountValue; this.currentAccountValue = this.account.GetMarketValue(); if((this.currentAccountValue - this.previousAccountValue) /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) { this.stopLossConditionReached = true; } else { this.stopLossConditionReached = false; } } protected virtual double getCurrentChosenTickersValue(IndexBasedEndOfDayTimer timer) { double returnValue = 999.0; try { DateTime initialDate = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - this.numDaysForOscillatingPeriod + 2]["quDate"]; //so to replicate exactly in sample scheme, where only numOscillatingDay - 1 returns //are computed DateTime finalDate = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; returnValue = SignedTicker.GetCloseToClosePortfolioReturn( this.chosenTickers, this.chosenTickersPortfolioWeights, initialDate,finalDate) + 1.0; } catch(MissingQuotesException ex) { ex = ex; } return returnValue; } private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) { double currentChosenTickersValue = this.getCurrentChosenTickersValue(timer); if(currentChosenTickersValue != 999.0) //currentChosenTickersValue has been properly computed { if(this.portfolioType == PortfolioType.ShortAndLong) //it is possible to reverse positions { if(currentChosenTickersValue >= 1.0 + currentOverboughtThreshold && this.portfolioHasBeenOversold) //open positions derive from an overSold period but now //an the overbought threshold has been reached { this.reversePositions(); this.portfolioHasBeenOversold = false; this.portfolioHasBeenOverbought = true; } if(currentChosenTickersValue <= 1.0 - currentOversoldThreshold && this.portfolioHasBeenOverbought) //open positions derive from an overSold period but now //an the overbought threshold has been reached { this.reversePositions(); this.portfolioHasBeenOversold = true; this.portfolioHasBeenOverbought = false; } } } } private void marketCloseEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { double currentChosenTickersValue = this.getCurrentChosenTickersValue(timer); if(currentChosenTickersValue != 999.0) //currentChosenTickersValue has been properly computed { if(currentChosenTickersValue >= 1.0 + currentOverboughtThreshold && this.portfolioType == PortfolioType.ShortAndLong) { SignedTicker.ChangeSignOfEachTicker(this.chosenTickers); //short the portfolio try { base.openPositions(this.chosenTickers); this.portfolioHasBeenOverbought = true; this.portfolioHasBeenOversold = false; } catch(Exception ex) { ex = ex; } finally { SignedTicker.ChangeSignOfEachTicker(this.chosenTickers); } } else if (currentChosenTickersValue <= 1.0 - currentOversoldThreshold) { try { base.openPositions(this.chosenTickers); this.portfolioHasBeenOverbought = false; this.portfolioHasBeenOversold = true; } catch(Exception ex) { ex = ex; } } } } protected virtual void marketCloseEventHandler_closePositionsIfNeeded() { if(this.stopLossConditionReached || this.numDaysElapsedSinceLastOptimization + 1 == this.numDaysBetweenEachOptimization ) { base.closePositions(); //a new optimization is needed, now this.chosenTickers[0] = null; //when positions are closed, these parameters //have to be reset to false this.portfolioHasBeenOverbought = false; this.portfolioHasBeenOversold = false; } } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //this.marketCloseEventHandler_updateStopLossCondition(); this.marketCloseEventHandler_closePositionsIfNeeded(); if(this.chosenTickers[0] != null) //tickers to buy have been chosen by the optimizer { if(this.account.Portfolio.Count == 0) this.marketCloseEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); //positions are opened only if thresholds are reached else//there are some opened positions this.marketCloseEventHandler_reverseIfNeeded((IndexBasedEndOfDayTimer)sender);; } } #endregion #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); DataTable tickersFromGroup = temporizedGroup.GetTableOfSelectedTickers(); int numOfTickersInGroupAtCurrentDate = tickersFromGroup.Rows.Count; SelectorByAverageRawOpenPrice byPrice = new SelectorByAverageRawOpenPrice(tickersFromGroup,false,currentDate, currentDate.AddDays(-30), numOfTickersInGroupAtCurrentDate, 25,500, 0.0001,100); SelectorByLiquidity mostLiquidSelector = new SelectorByLiquidity(byPrice.GetTableOfSelectedTickers(), false,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay(mostLiquidSelector.GetTableOfSelectedTickers(), false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers, this.benchmark); return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } private void addPVOGenomeToBestGenomes(Genome genome, DateTime firstOptimizationDate, DateTime secondOptimizationDate, int eligibleTickers, int daysForOscillatingPeriod, PortfolioType portfolioType, int createdGenerations, double oversoldThreshold, double overboughtThreshold) { if(this.bestGenomes == null) this.bestGenomes = new ArrayList(); this.bestGenomes.Add(new GenomeRepresentation(genome, firstOptimizationDate, secondOptimizationDate, genome.Generation, eligibleTickers, daysForOscillatingPeriod, portfolioType, createdGenerations, oversoldThreshold, overboughtThreshold)); } protected virtual void setTickers(DateTime currentDate, bool setGenomeCounter) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is meaningful only if the initial set of tickers is //larger than the number of tickers to be chosen { this.iGenomeManager = new GenomeManagerPVO(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfTickersToBeChosen, this.numDaysForOscillatingPeriod, this.minLevelForOversoldThreshold, this.maxLevelForOversoldThreshold, this.minLevelForOverboughtThreshold, this.maxLevelForOverboughtThreshold, this.divisorForThresholdComputation, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(this.iGenomeManager, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, this.seedForRandomGenerator); if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); GO.MutationRate = 0.4; GO.Run(false); this.chosenTickers = ((GenomeMeaningPVO)GO.BestGenome.Meaning).Tickers; this.chosenTickersPortfolioWeights = ((GenomeMeaningPVO)GO.BestGenome.Meaning).TickersPortfolioWeights; this.currentOversoldThreshold = ((GenomeMeaningPVO)GO.BestGenome.Meaning).OversoldThreshold; this.currentOverboughtThreshold = ((GenomeMeaningPVO)GO.BestGenome.Meaning).OverboughtThreshold; this.addPVOGenomeToBestGenomes(GO.BestGenome,((GenomeManagerForEfficientPortfolio)this.iGenomeManager).FirstQuoteDate, ((GenomeManagerForEfficientPortfolio)this.iGenomeManager).LastQuoteDate, setOfTickersToBeOptimized.Rows.Count, this.numDaysForOscillatingPeriod, this.portfolioType, GO.GenerationCounter, this.currentOversoldThreshold, this.currentOverboughtThreshold); } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member } /// <summary> /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.seedForRandomGenerator++; this.numDaysElapsedSinceLastOptimization++; this.orders.Clear(); if((this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization)) //num days without optimization has elapsed { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; } } #endregion } } |
|
From: Marco M. <mi...@us...> - 2006-09-17 21:24:57
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv25928/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: TestDisplayer.cs StrategyType.cs LinearCombinationTest.cs GenomeRepresentation.cs Added Files: FixedLevelOscillatorPVOStrategy.cs Log Message: Added Portfolio Value Oscillator strategy. This strategy is similar to the strategy based on the popular technical RSI indicator (Relative Strength Index). Index: LinearCombinationTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/LinearCombinationTest.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** LinearCombinationTest.cs 7 Aug 2006 21:19:40 -0000 1.9 --- LinearCombinationTest.cs 17 Sep 2006 21:24:53 -0000 1.10 *************** *** 23,26 **** --- 23,27 ---- using System; using System.Collections; + using System.Drawing; using QuantProject.Business.DataProviders; *************** *** 32,35 **** --- 33,37 ---- using QuantProject.Presentation.Reporting.WindowsForm; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; + using QuantProject.Scripts.WalkForwardTesting.WalkForwardLag; *************** *** 139,142 **** --- 141,151 ---- this.account , signedTickers , weightsForSignedTickers, this.numDaysForOscillatorStrategy ); break; + + case StrategyType.PortfolioValueOscillator: + this.endOfDayStrategy = new FixedLevelOscillatorPVOStrategy( + this.account , signedTickers , weightsForSignedTickers, + this.genomeRepresentation.OversoldThreshold, this.genomeRepresentation.OverboughtThreshold, + this.numDaysForOscillatorStrategy ); + break; } } *************** *** 160,164 **** return returnValue; } ! public void Run() { this.historicalEndOfDayTimer = --- 169,202 ---- return returnValue; } ! ! private void run_addEquityLineForWeightedPositions( ! WeightedPositions weightedPositions , Color color , Report report ) ! { ! EquityLine equityLineForWeightedPositions = ! weightedPositions.GetVirtualEquityLine( ! 30000 , report.AccountReport.EquityLine ); ! report.AddEquityLine( equityLineForWeightedPositions , ! color ); ! } ! ! private WeightedPositions run_getWeightedPositions(GenomeRepresentation genomeRepresentation) ! ! { ! double[] normalizedWeights = ! GenomeRepresentation.GetWeightsArray(this.genomeRepresentation.WeightsForSignedTickers); ! string[] tickers = ! GenomeRepresentation.GetSignedTickers(this.genomeRepresentation.SignedTickers); ! for(int i = 0; i<tickers.Length; i++) ! { ! if(tickers[i].StartsWith("-")) ! { ! tickers[i] = SignedTicker.GetTicker(tickers[i]); ! normalizedWeights[i] = -1.0 * normalizedWeights[i]; ! } ! } ! return new WeightedPositions(normalizedWeights, tickers); ! } ! ! public void Run() { this.historicalEndOfDayTimer = *************** *** 190,196 **** Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "Linear Combination" , 1 , new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^GSPC"); // ObjectArchiver.Archive( report.AccountReport , --- 228,238 ---- Report report = new Report( this.account , this.historicalQuoteProvider ); ! report.Create( "Linear Combination" , 1 , new EndOfDayDateTime( this.lastDate , EndOfDaySpecificTime.MarketClose ) , "^GSPC"); + WeightedPositions weightedPositions = + this.run_getWeightedPositions(this.genomeRepresentation); + this.run_addEquityLineForWeightedPositions(weightedPositions, Color.Brown, + report); // ObjectArchiver.Archive( report.AccountReport , Index: StrategyType.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/StrategyType.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** StrategyType.cs 3 Aug 2006 21:15:57 -0000 1.4 --- StrategyType.cs 17 Sep 2006 21:24:53 -0000 1.5 *************** *** 36,40 **** FixedPeriodOscillator, ExtremeCounterTrend, ! ImmediateTrendFollower } } --- 36,41 ---- FixedPeriodOscillator, ExtremeCounterTrend, ! ImmediateTrendFollower, ! PortfolioValueOscillator } } Index: GenomeRepresentation.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/GenomeRepresentation.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenomeRepresentation.cs 7 Aug 2006 21:19:40 -0000 1.7 --- GenomeRepresentation.cs 17 Sep 2006 21:24:53 -0000 1.8 *************** *** 27,30 **** --- 27,31 ---- using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; + using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.Business.Financial.Ordering; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; *************** *** 47,50 **** --- 48,54 ---- private int halfPeriodDays = -1; private PortfolioType portfolioType = PortfolioType.ShortAndLong; + private int createdGenerations = -1; + private double oversoldThreshold = 0.0; + private double overboughtThreshold = 0.0; public string SignedTickers *************** *** 91,94 **** --- 95,107 ---- } + /// <summary> + /// Total number of the generations created by the GO + /// that produced the current genome + /// </summary> + public int CreatedGenerations + { + get { return this.createdGenerations; } + } + public int HalfPeriodDays { *************** *** 106,109 **** --- 119,139 ---- } } + + public double OversoldThreshold + { + get + { + return this.oversoldThreshold; + } + } + + public double OverboughtThreshold + { + get + { + return this.overboughtThreshold; + } + } + // public static string[] GetSignedTickers( string signedTickers ) // { *************** *** 124,132 **** } ! public static string[] GetSignedTickers( string signedTickersWithWeights ) { string[] returnValue = ! signedTickersWithWeights.Split( ConstantsProvider.SeparatorForTickers.ToCharArray()); ! if( signedTickersWithWeights.Split( ConstantsProvider.SeparatorForWeights.ToCharArray() ).Length > 1 ) //the separator char for tickers is contained in signedTickersWithWeights: //so weights have been saved within tickers, separated by this special char --- 154,162 ---- } ! public static string[] GetSignedTickers( string signedTickersWithOrWithoutWeights ) { string[] returnValue = ! signedTickersWithOrWithoutWeights.Split( ConstantsProvider.SeparatorForTickers.ToCharArray()); ! if( signedTickersWithOrWithoutWeights.Split( ConstantsProvider.SeparatorForWeights.ToCharArray() ).Length > 1 ) //the separator char for tickers is contained in signedTickersWithWeights: //so weights have been saved within tickers, separated by this special char *************** *** 141,154 **** } ! public static double[] GetWeightsForSignedTickers( string signedTickersWithWeights ) { ! string[] signedTickersWithWeightsArray = ! signedTickersWithWeights.Split( ConstantsProvider.SeparatorForTickers.ToCharArray() ); double[] returnValue = ! new double[signedTickersWithWeightsArray.Length]; for(int i = 0; i<returnValue.Length; i++) returnValue[i] = 1.0/returnValue.Length; ! if((signedTickersWithWeights.Split(ConstantsProvider.SeparatorForWeights.ToCharArray())).Length > 1) //the separator for weights is contained in signedTickersWithWeights: //so weights have been saved within tickers, separated by this char --- 171,184 ---- } ! public static double[] GetWeightsForSignedTickers( string signedTickersWithOrWithoutWeights ) { ! string[] signedTickersWithOrWithoutWeightsArray = ! signedTickersWithOrWithoutWeights.Split( ConstantsProvider.SeparatorForTickers.ToCharArray() ); double[] returnValue = ! new double[signedTickersWithOrWithoutWeights.Length]; for(int i = 0; i<returnValue.Length; i++) returnValue[i] = 1.0/returnValue.Length; ! if((signedTickersWithOrWithoutWeights.Split(ConstantsProvider.SeparatorForWeights.ToCharArray())).Length > 1) //the separator for weights is contained in signedTickersWithWeights: //so weights have been saved within tickers, separated by this char *************** *** 157,161 **** { returnValue[i] = ! Convert.ToDouble( signedTickersWithWeightsArray[i].Split( ConstantsProvider.SeparatorForWeights.ToCharArray() )[1] ); } } --- 187,191 ---- { returnValue[i] = ! Convert.ToDouble( signedTickersWithOrWithoutWeightsArray[i].Split( ConstantsProvider.SeparatorForWeights.ToCharArray() )[1] ); } } *************** *** 182,195 **** } ! private string getSignedTickers( Genome genome ) { string signedTickers = ""; ! foreach ( string geneValue in ((GenomeMeaning)genome.Meaning).Tickers ) ! signedTickers += geneValue + ";"; signedTickers = signedTickers.Substring( 0 , signedTickers.Length - 1 ); return signedTickers; } ! private string getWeights( Genome genome ) { --- 212,225 ---- } ! private string getSignedTickers( string[] signedTickersArray ) { string signedTickers = ""; ! foreach ( string signedTicker in signedTickersArray ) ! signedTickers += signedTicker + ";"; signedTickers = signedTickers.Substring( 0 , signedTickers.Length - 1 ); return signedTickers; } ! private string getWeights( Genome genome ) { *************** *** 200,205 **** return weights; } ! ! // private string getSignedTickersWithWeights( Genome genome ) // { // string signedTickersWithWeights = ""; --- 230,235 ---- return weights; } ! ! // private string getSignedTickersWithWeights( Genome genome ) // { // string signedTickersWithWeights = ""; *************** *** 265,273 **** private void genomeRepresentation( Genome genome , DateTime firstOptimizationDate , DateTime lastOptimizationDate , ! int generationCounter, int eligibleTickers, int halfPeriodDays, PortfolioType portfolioType ) { this.fitness = genome.Fitness; //this.signedTickers = this.getSignedTickersWithWeights( genome ); ! this.signedTickers = this.getSignedTickers( genome ); this.weights = this.getWeights( genome ); this.firstOptimizationDate = firstOptimizationDate; --- 295,305 ---- private void genomeRepresentation( Genome genome , DateTime firstOptimizationDate , DateTime lastOptimizationDate , ! int generationCounter, int eligibleTickers, ! int halfPeriodDays, PortfolioType portfolioType, ! int createdGenerations) { this.fitness = genome.Fitness; //this.signedTickers = this.getSignedTickersWithWeights( genome ); ! this.signedTickers = this.getSignedTickers( ((GenomeMeaning)genome.Meaning).Tickers ); this.weights = this.getWeights( genome ); this.firstOptimizationDate = firstOptimizationDate; *************** *** 277,280 **** --- 309,313 ---- this.halfPeriodDays = halfPeriodDays; this.portfolioType = portfolioType; + this.createdGenerations = createdGenerations; } *************** *** 283,287 **** { this.genomeRepresentation( genome , ! firstOptimizationDate , lastOptimizationDate , -1, -1, -1, PortfolioType.ShortAndLong ); } --- 316,320 ---- { this.genomeRepresentation( genome , ! firstOptimizationDate , lastOptimizationDate , -1, -1, -1, PortfolioType.ShortAndLong, -1 ); } *************** *** 291,297 **** { this.genomeRepresentation( genome , firstOptimizationDate , ! lastOptimizationDate , generationCounter, -1, -1, PortfolioType.ShortAndLong); } public GenomeRepresentation( Genome genome , DateTime firstOptimizationDate , DateTime lastOptimizationDate , --- 324,345 ---- { this.genomeRepresentation( genome , firstOptimizationDate , ! lastOptimizationDate , generationCounter, -1, -1, PortfolioType.ShortAndLong, -1); } + public GenomeRepresentation( BruteForceOptimizableParameters BFOptimizableParamaters , + string[] signedTickersArray, + DateTime firstOptimizationDate , DateTime lastOptimizationDate , + int eligibleTickers ) + { + this.fitness = BFOptimizableParamaters.Fitness; + //this.signedTickers = this.getSignedTickersWithWeights( genome ); + this.signedTickers = this.getSignedTickers(signedTickersArray); + this.weights = null; + this.firstOptimizationDate = firstOptimizationDate; + this.lastOptimizationDate = lastOptimizationDate; + this.eligibleTickers = eligibleTickers; + } + + public GenomeRepresentation( Genome genome , DateTime firstOptimizationDate , DateTime lastOptimizationDate , *************** *** 299,303 **** { this.genomeRepresentation( genome , firstOptimizationDate , ! lastOptimizationDate , generationCounter, eligibleTickers, -1, PortfolioType.ShortAndLong); } --- 347,351 ---- { this.genomeRepresentation( genome , firstOptimizationDate , ! lastOptimizationDate , generationCounter, eligibleTickers, -1, PortfolioType.ShortAndLong, -1); } *************** *** 308,320 **** this.genomeRepresentation( genome , firstOptimizationDate , lastOptimizationDate , generationCounter, eligibleTickers, halfPeriodDays, ! PortfolioType.ShortAndLong); } public GenomeRepresentation( Genome genome , DateTime firstOptimizationDate , DateTime lastOptimizationDate , ! int generationCounter, int eligibleTickers, int halfPeriodDays, PortfolioType portfolioType ) { this.genomeRepresentation( genome , firstOptimizationDate , ! lastOptimizationDate , generationCounter, eligibleTickers, halfPeriodDays, portfolioType); } --- 356,393 ---- this.genomeRepresentation( genome , firstOptimizationDate , lastOptimizationDate , generationCounter, eligibleTickers, halfPeriodDays, ! PortfolioType.ShortAndLong, -1); } public GenomeRepresentation( Genome genome , DateTime firstOptimizationDate , DateTime lastOptimizationDate , ! int generationCounter, int eligibleTickers, ! int halfPeriodDays, PortfolioType portfolioType ) { this.genomeRepresentation( genome , firstOptimizationDate , ! lastOptimizationDate , generationCounter, eligibleTickers, ! halfPeriodDays, portfolioType, -1); ! } ! ! public GenomeRepresentation( Genome genome , ! DateTime firstOptimizationDate , DateTime lastOptimizationDate , ! int generationCounter, int eligibleTickers, ! int halfPeriodDays, PortfolioType portfolioType, int createdGenerations ) ! { ! this.genomeRepresentation( genome , firstOptimizationDate , ! lastOptimizationDate , generationCounter, eligibleTickers, ! halfPeriodDays, portfolioType, createdGenerations); ! } ! ! public GenomeRepresentation( Genome genome , ! DateTime firstOptimizationDate , DateTime lastOptimizationDate , ! int generationCounter, int eligibleTickers, ! int halfPeriodDays, PortfolioType portfolioType, int createdGenerations, ! double oversoldThreshold, double overboughtThreshold) ! { ! this.genomeRepresentation( genome , firstOptimizationDate , ! lastOptimizationDate , generationCounter, eligibleTickers, ! halfPeriodDays, portfolioType, createdGenerations); ! this.oversoldThreshold = oversoldThreshold; ! this.overboughtThreshold = overboughtThreshold; } Index: TestDisplayer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/TestDisplayer.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TestDisplayer.cs 7 Aug 2006 21:19:40 -0000 1.10 --- TestDisplayer.cs 17 Sep 2006 21:24:53 -0000 1.11 *************** *** 59,62 **** --- 59,63 ---- private StrategyType selectedStrategyType = StrategyType.OpenToCloseDaily; private System.Windows.Forms.Label labelPortfolioType; + private System.Windows.Forms.RadioButton radioButtonPVO; private System.Windows.Forms.ComboBox comboBoxPortfolioType; *************** *** 97,100 **** --- 98,106 ---- ts.GridColumnStyles.Add(genNumber); + DataGridTextBoxColumn createdGen = new DataGridTextBoxColumn(); + createdGen.MappingName ="CreatedGenerations"; + createdGen.HeaderText = "TotGen"; + ts.GridColumnStyles.Add(createdGen); + DataGridTextBoxColumn eligible = new DataGridTextBoxColumn(); eligible.MappingName ="EligibleTickers"; *************** *** 102,105 **** --- 108,121 ---- ts.GridColumnStyles.Add(eligible); + DataGridTextBoxColumn oversoldThreshold = new DataGridTextBoxColumn(); + oversoldThreshold.MappingName ="OversoldThreshold"; + oversoldThreshold.HeaderText = "OversoldThreshold"; + ts.GridColumnStyles.Add(oversoldThreshold); + + DataGridTextBoxColumn overboughtThreshold = new DataGridTextBoxColumn(); + overboughtThreshold.MappingName ="OverboughtThreshold"; + overboughtThreshold.HeaderText = "OverboughtThreshold"; + ts.GridColumnStyles.Add(overboughtThreshold); + this.dgBestGenomes.TableStyles.Clear(); ts.AllowSorting = true; *************** *** 172,175 **** --- 188,192 ---- this.comboBoxPortfolioType = new System.Windows.Forms.ComboBox(); this.labelPortfolioType = new System.Windows.Forms.Label(); + this.radioButtonPVO = new System.Windows.Forms.RadioButton(); ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); this.SuspendLayout(); *************** *** 206,210 **** // textBoxDaysFPOscillatorAndRevOneRank // ! this.textBoxDaysFPOscillatorAndRevOneRank.Location = new System.Drawing.Point(320, 176); this.textBoxDaysFPOscillatorAndRevOneRank.Name = "textBoxDaysFPOscillatorAndRevOneRank"; this.textBoxDaysFPOscillatorAndRevOneRank.Size = new System.Drawing.Size(56, 20); --- 223,227 ---- // textBoxDaysFPOscillatorAndRevOneRank // ! this.textBoxDaysFPOscillatorAndRevOneRank.Location = new System.Drawing.Point(472, 128); this.textBoxDaysFPOscillatorAndRevOneRank.Name = "textBoxDaysFPOscillatorAndRevOneRank"; this.textBoxDaysFPOscillatorAndRevOneRank.Size = new System.Drawing.Size(56, 20); *************** *** 263,269 **** // labelDays // ! this.labelDays.Location = new System.Drawing.Point(272, 176); this.labelDays.Name = "labelDays"; ! this.labelDays.Size = new System.Drawing.Size(40, 16); this.labelDays.TabIndex = 9; this.labelDays.Text = "days"; --- 280,286 ---- // labelDays // ! this.labelDays.Location = new System.Drawing.Point(432, 136); this.labelDays.Name = "labelDays"; ! this.labelDays.Size = new System.Drawing.Size(32, 16); this.labelDays.TabIndex = 9; this.labelDays.Text = "days"; *************** *** 288,292 **** // comboBoxPortfolioType // ! this.comboBoxPortfolioType.Location = new System.Drawing.Point(480, 104); this.comboBoxPortfolioType.Name = "comboBoxPortfolioType"; this.comboBoxPortfolioType.Size = new System.Drawing.Size(184, 21); --- 305,309 ---- // comboBoxPortfolioType // ! this.comboBoxPortfolioType.Location = new System.Drawing.Point(472, 80); this.comboBoxPortfolioType.Name = "comboBoxPortfolioType"; this.comboBoxPortfolioType.Size = new System.Drawing.Size(184, 21); *************** *** 296,300 **** // labelPortfolioType // ! this.labelPortfolioType.Location = new System.Drawing.Point(480, 88); this.labelPortfolioType.Name = "labelPortfolioType"; this.labelPortfolioType.Size = new System.Drawing.Size(100, 16); --- 313,317 ---- // labelPortfolioType // ! this.labelPortfolioType.Location = new System.Drawing.Point(472, 64); this.labelPortfolioType.Name = "labelPortfolioType"; this.labelPortfolioType.Size = new System.Drawing.Size(100, 16); *************** *** 302,305 **** --- 319,331 ---- this.labelPortfolioType.Text = "Type of portfolio"; // + // radioButtonPVO + // + this.radioButtonPVO.Location = new System.Drawing.Point(232, 168); + this.radioButtonPVO.Name = "radioButtonPVO"; + this.radioButtonPVO.Size = new System.Drawing.Size(192, 24); + this.radioButtonPVO.TabIndex = 15; + this.radioButtonPVO.Text = "Portfolio Value Oscillator"; + this.radioButtonPVO.CheckedChanged += new System.EventHandler(this.radioButtonPVO_CheckedChanged); + // // TestDisplayer // *************** *** 307,310 **** --- 333,337 ---- this.ClientSize = new System.Drawing.Size(704, 373); this.Controls.AddRange(new System.Windows.Forms.Control[] { + this.radioButtonPVO, this.labelPortfolioType, this.comboBoxPortfolioType, *************** *** 436,439 **** --- 463,468 ---- else if(this.radioButtonImmediateTrendFollower.Checked) this.selectedStrategyType = StrategyType.ImmediateTrendFollower; + else if(this.radioButtonPVO.Checked) + this.selectedStrategyType = StrategyType.PortfolioValueOscillator; } *************** *** 469,472 **** --- 498,506 ---- this.update_selectedStrategyType(); } + + private void radioButtonPVO_CheckedChanged(object sender, System.EventArgs e) + { + this.update_selectedStrategyType(); + } } --- NEW FILE: FixedLevelOscillatorPVOStrategy.cs --- /* QuantProject - Quantitative Finance Library FixedLevelOscillatorPVOStrategy.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.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Strategies; using QuantProject.Business.Timing; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Fixed Level Oscillators /// Portfolio Value Oscillator strategy /// </summary> [Serializable] public class FixedLevelOscillatorPVOStrategy : EndOfDayTimerHandlerPVO, IEndOfDayStrategy { public FixedLevelOscillatorPVOStrategy( Account accountPVO , string[] tickers, double[] tickersPortfolioWeights, double oversoldThreshold, double overboughtThreshold, int numDaysForOscillatingPeriod): base("", 0, tickers.Length, 0, accountPVO, 0,0, "^GSPC", 0, 0, 0, 0, 0, 0, 0, PortfolioType.ShortAndLong, 0.5) { this.chosenTickers = tickers; this.chosenTickersPortfolioWeights = tickersPortfolioWeights; this.currentOversoldThreshold = oversoldThreshold; this.currentOverboughtThreshold = overboughtThreshold; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } protected override void marketCloseEventHandler_closePositionsIfNeeded() { } protected override double getCurrentChosenTickersValue(IndexBasedEndOfDayTimer timer) { double returnValue = 999.0; if(timer.CurrentDateArrayPosition + 2 >= this.numDaysForOscillatingPeriod) { try { DateTime initialDate = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - this.numDaysForOscillatingPeriod + 2]["quDate"]; //so to replicate exactly in sample scheme, where only numOscillatingDay - 1 returns //are computed DateTime finalDate = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; returnValue = SignedTicker.GetCloseToClosePortfolioReturn( this.chosenTickers, this.chosenTickersPortfolioWeights, initialDate,finalDate) + 1.0; } catch(Exception ex) { ex = ex; } } return returnValue; } public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } } } |
|
From: Marco M. <mi...@us...> - 2006-09-17 21:16:38
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv23471/BruteForceOptimization Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/BruteForceOptimization added to the repository |
|
From: Marco M. <mi...@us...> - 2006-09-17 21:14:26
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv22982/PortfolioValueOscillator Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator added to the repository |
|
From: Marco M. <mi...@us...> - 2006-09-17 21:14:01
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv22587/FixedLevelOscillators Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators added to the repository |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:36:35
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/BruteForce In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv11219/b1_ADT/Optimizing/BruteForce Modified Files: BruteForceOptimizer.cs Log Message: The Run method has been overloaded, with parameters to decide the NewProgress event frequency Index: BruteForceOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/BruteForce/BruteForceOptimizer.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BruteForceOptimizer.cs 21 Aug 2006 19:42:16 -0000 1.1 --- BruteForceOptimizer.cs 8 Sep 2006 15:36:33 -0000 1.2 *************** *** 35,38 **** --- 35,41 ---- bruteForceOptimizableParametersManager; + private int numberOfAnalizedItemsForNewProgess; + private int totalNumberOfItemsToBeAnalized; + private BruteForceOptimizableParameters bestParameters; *************** *** 51,64 **** this.bruteForceOptimizableParametersManager = bruteForceOptimizableParametersManager; } #region Run private void handleProgress() { ! analizedItems ++ ; ! if ( analizedItems % 100000 == 0 ) { NewProgressEventArgs newProgressEventArgs = new NewProgressEventArgs( analizedItems , ! 0 ); if ( this.NewProgress != null ) this.NewProgress( this , newProgressEventArgs ); --- 54,69 ---- this.bruteForceOptimizableParametersManager = bruteForceOptimizableParametersManager; + this.numberOfAnalizedItemsForNewProgess = 100000; + this.totalNumberOfItemsToBeAnalized = 0; } #region Run private void handleProgress() { ! this.analizedItems ++ ; ! if ( analizedItems % this.numberOfAnalizedItemsForNewProgess == 0 ) { NewProgressEventArgs newProgressEventArgs = new NewProgressEventArgs( analizedItems , ! this.totalNumberOfItemsToBeAnalized ); if ( this.NewProgress != null ) this.NewProgress( this , newProgressEventArgs ); *************** *** 83,86 **** --- 88,100 ---- } } + public void Run( int numberOfAnalizedItemsForNewProgess , + int totalNumberOfItemsToBeAnalized ) + { + this.numberOfAnalizedItemsForNewProgess = + numberOfAnalizedItemsForNewProgess; + this.totalNumberOfItemsToBeAnalized = + totalNumberOfItemsToBeAnalized; + this.Run(); + } #endregion } |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:34:44
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Statistics/Combinatorial In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10282/b1_ADT/Statistics/Combinatorial Modified Files: Combination.cs Log Message: The TotalNumberOfCombinations property has been added (to be read to know how many combinations will be generated) Index: Combination.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Statistics/Combinatorial/Combination.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Combination.cs 21 Aug 2006 19:45:05 -0000 1.1 --- Combination.cs 8 Sep 2006 15:34:41 -0000 1.2 *************** *** 16,23 **** --- 16,33 ---- private int length; + /// <summary> + /// each combination length + /// </summary> public int Length { get { return this.length; } } + public long TotalNumberOfCombinations + { + get + { + return this.totalNumberOfCombinations(); + } + } /// <summary> *************** *** 129,132 **** --- 139,163 ---- return this.currentCombinationValues[ elementIndex ]; } + #region totalNumberOfCombinations + private long totalNumberOfCombinations_getNumerator() + { + int firstFactor = this.maxValue - this.minValue + 1; + long numerator = 1; + for ( int factor = firstFactor ; factor > firstFactor - this.length ; + factor -- ) + numerator *= factor; + return numerator; + } + private long totalNumberOfCombinations_getDenominator() + { + return ExtendedMath.Factorial( this.length ); + } + private long totalNumberOfCombinations() + { + long numerator = this.totalNumberOfCombinations_getNumerator(); + long denominator = this.totalNumberOfCombinations_getDenominator(); + return numerator / denominator; + } + #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:32:30
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv9429/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WeightedPositions.cs Log Message: - the public static method AreValidTickers has been added - the constructor's parameter are further checked now: no duplicate is allowed for tickers Index: WeightedPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositions.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WeightedPositions.cs 31 Jul 2006 16:42:29 -0000 1.1 --- WeightedPositions.cs 8 Sep 2006 15:32:27 -0000 1.2 *************** *** 59,62 **** --- 59,74 ---- } } + #region checkParameters + private void checkParameters_checkDoubleTickers( string[] tickers ) + { + SortedList sortedTicker = new SortedList(); + foreach ( string ticker in tickers ) + if ( !sortedTicker.ContainsKey( ticker ) ) + sortedTicker.Add( ticker , ticker ); + else + throw new Exception( "The WeightedPositions constructur " + + "has received a tickers parameter with the ticker '" + + ticker + "' that is contained twice! This is not allowed." ); + } private void checkParameters( double[] normalizedWeightValues , string[] tickers ) *************** *** 72,76 **** --- 84,90 ---- "should sum up to 1, " + "but it sums up to " + totalWeight.ToString() ); + this.checkParameters_checkDoubleTickers( tickers ); } + #endregion public WeightedPosition GetWeightedPosition( string ticker ) { *************** *** 250,253 **** --- 264,278 ---- } #endregion + /// <summary> + /// It controls if a WeightedPositions class may be build on the + /// given tickers + /// </summary> + /// <param name="tickers"></param> + /// <returns></returns> + public static bool AreValidTickers( string[] tickers ) + { + return !QuantProject.ADT.Collections.CollectionManager.ContainsDuplicates( + tickers ); + } } |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:30:24
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv8597/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagChosenTickers.cs Log Message: The private method setWeightedPositions_withFixedPortfolio has been added, to set positions with fixed portfolio. Index: WFLagChosenTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagChosenTickers.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WFLagChosenTickers.cs 21 Aug 2006 21:21:37 -0000 1.5 --- WFLagChosenTickers.cs 8 Sep 2006 15:30:17 -0000 1.6 *************** *** 181,185 **** 0.85 , 0.02 , ! 0.1 , this.populationSizeForGeneticOptimizer , this.generationNumberForGeneticOptimizer , --- 181,185 ---- 0.85 , 0.02 , ! 0.001 , this.populationSizeForGeneticOptimizer , this.generationNumberForGeneticOptimizer , *************** *** 243,246 **** --- 243,292 ---- } #endregion + #region setWeightedPositions_withFixedPortfolio + // private void newBruteForceOptimizerProgressEventHandler( + // object sender , NewProgressEventArgs e ) + // { + // this.NewProgress( sender , e ); + // } + public virtual void setWeightedPositions_withFixedPortfolio( + WFLagEligibleTickers eligibleTickers , + string longPortfolioTicker , string shortPortfolioTicker ) + { + this.firstOptimizationDate = + this.endOfDayTimer.GetCurrentTime().DateTime.AddDays( + -( this.inSampleDays - 1 ) ); + this.lastOptimizationDate = + this.endOfDayTimer.GetCurrentTime().DateTime; + + WFLagFixedPortfolioBruteForceOptimizableParametersManager + wFLagFixedPortfolioBruteForceOptimizableParametersManager= + new WFLagFixedPortfolioBruteForceOptimizableParametersManager( + eligibleTickers.EligibleTickers , + longPortfolioTicker , + shortPortfolioTicker , + this.firstOptimizationDate , + this.lastOptimizationDate , + this.numberOfDrivingPositions ); + + BruteForceOptimizer bruteForceOptimizer = new BruteForceOptimizer( + wFLagFixedPortfolioBruteForceOptimizableParametersManager ); + + bruteForceOptimizer.NewProgress += + new NewProgressEventHandler( + this.newBruteForceOptimizerProgressEventHandler ); + + bruteForceOptimizer.Run( 100000 , + wFLagFixedPortfolioBruteForceOptimizableParametersManager.TotalIterations ); + + BruteForceOptimizableParameters bestParameters = + bruteForceOptimizer.BestParameters; + + WFLagWeightedPositions wFLagWeightedPositions = + ( WFLagWeightedPositions )wFLagFixedPortfolioBruteForceOptimizableParametersManager.Decode( + bestParameters ); + + this.setWeightedPositions( wFLagWeightedPositions ); + } + #endregion public virtual void SetWeightedPositions( WFLagEligibleTickers eligibleTickers ) *************** *** 248,253 **** // this.setWeightedPositions_usingTheGeneticOptimizer( // eligibleTickers ); ! this.setWeightedPositions_usingTheBruteForceOptimizer( ! eligibleTickers ); } #endregion --- 294,301 ---- // this.setWeightedPositions_usingTheGeneticOptimizer( // eligibleTickers ); ! // this.setWeightedPositions_usingTheBruteForceOptimizer( ! // eligibleTickers ); ! this.setWeightedPositions_withFixedPortfolio( ! eligibleTickers , "SPY" , "IWM" ); } #endregion |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:27:38
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7265/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: WalkForwardTesting\WalkForwardLag\WFLagBruteForceOptimizableItemManager\WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs has been added Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** b7_Scripts.csproj 21 Aug 2006 19:46:41 -0000 1.61 --- b7_Scripts.csproj 8 Sep 2006 15:27:35 -0000 1.62 *************** *** 663,666 **** --- 663,667 ---- BuildAction = "Compile" /> + <Folder RelPath = "WalkForwardTesting\WalkForwardLag\EligibleTickers\" /> <File RelPath = "WalkForwardTesting\WalkForwardLag\GeneticOptimizerTesting\WFLagGOTester.cs" *************** *** 674,677 **** --- 675,683 ---- /> <File + RelPath = "WalkForwardTesting\WalkForwardLag\WFLagBruteForceOptimizableItemManager\WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\WalkForwardLag\WFLagDebugger\WFLagChosenPositions.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:26:58
|
Update of /cvsroot/quantproject/QuantProject/b5_Presentation In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6841/b5_Presentation Modified Files: b5_Presentation.csproj Log Message: A few .resx file have been removed Index: b5_Presentation.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b5_Presentation/b5_Presentation.csproj,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** b5_Presentation.csproj 2 Jul 2006 20:16:16 -0000 1.29 --- b5_Presentation.csproj 8 Sep 2006 15:26:54 -0000 1.30 *************** *** 126,138 **** /> <Reference - Name = "b4_Business" - Project = "{6EE31501-376E-491B-869E-F06D5B7C9C30}" - Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" - /> - <Reference Name = "NPlot" AssemblyName = "NPlot" HintPath = "..\..\..\NPlot.dll" /> </References> </Build> --- 126,138 ---- /> <Reference Name = "NPlot" AssemblyName = "NPlot" HintPath = "..\..\..\NPlot.dll" /> + <Reference + Name = "b4_Business" + Project = "{6EE31501-376E-491B-869E-F06D5B7C9C30}" + Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" + /> </References> </Build> *************** *** 180,188 **** /> <File - RelPath = "Reporting\WindowsForm\AccountViewer.resx" - DependentUpon = "AccountViewer.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "Reporting\WindowsForm\EquityChartTabPage.cs" SubType = "Component" --- 180,183 ---- *************** *** 195,203 **** /> <File - RelPath = "Reporting\WindowsForm\Report.resx" - DependentUpon = "Report.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "Reporting\WindowsForm\ReportGrid.cs" SubType = "Component" --- 190,193 ---- *************** *** 215,223 **** /> <File - RelPath = "Reporting\WindowsForm\ReportShower.resx" - DependentUpon = "ReportShower.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "Reporting\WindowsForm\ReportTabControl.cs" SubType = "Component" --- 205,208 ---- |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:23:44
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv5595/b1_ADT Modified Files: b1_ADT.csproj Log Message: - ExtendedMath.cs has been added - Collections\CollectionManager.cs has been added Index: b1_ADT.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/b1_ADT.csproj,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** b1_ADT.csproj 21 Aug 2006 19:48:17 -0000 1.23 --- b1_ADT.csproj 8 Sep 2006 15:23:36 -0000 1.24 *************** *** 118,121 **** --- 118,126 ---- /> <File + RelPath = "ExtendedMath.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "HashProvider.cs" SubType = "Code" *************** *** 148,151 **** --- 153,161 ---- /> <File + RelPath = "Collections\CollectionManager.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Collections\QPHashtable.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:21:12
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv4756/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager Added Files: WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs Log Message: This class implements IBruteForceOptimizableParametersManager, in order to find the best driving positions for a fixed portfolio with two tickers (one long position and one short position). Weights are NOT used in this implementation --- NEW FILE: WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs --- /* QuantProject - Quantitative Finance Library WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs Copyright (C) 2006 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.ADT.Statistics.Combinatorial; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { /// <summary> /// This class implements IBruteForceOptimizableParametersManager, /// in order to find the best driving positions for a fixed /// portfolio with two tickers (one long position and one short /// position). /// Weights are NOT used in this implementation /// </summary> public class WFLagFixedPortfolioBruteForceOptimizableParametersManager : IBruteForceOptimizableParametersManager { private Combination drivingCombination; private int numberOfDrivingPositions; private WFLagGenomeManager wFLagGenomeManager; private DataTable eligibleTickersForDrivingPositions; private string portfolioLongTicker; private string portfolioShortTicker; public int TotalIterations { get { return Convert.ToInt32( this.drivingCombination.TotalNumberOfCombinations ); } } public WFLagFixedPortfolioBruteForceOptimizableParametersManager( DataTable eligibleTickersForDrivingPositions , string portfolioLongTicker , string portfolioShortTicker , DateTime firstOptimizationDate , DateTime lastOptimizationDate , int numberOfDrivingPositions ) { this.eligibleTickersForDrivingPositions = eligibleTickersForDrivingPositions; this.portfolioLongTicker = portfolioLongTicker; this.portfolioShortTicker = portfolioShortTicker; this.numberOfDrivingPositions = numberOfDrivingPositions; this.drivingCombination = new Combination( - eligibleTickersForDrivingPositions.Rows.Count , eligibleTickersForDrivingPositions.Rows.Count - 1 , numberOfDrivingPositions ); this.wFLagGenomeManager = new WFLagGenomeManager( eligibleTickersForDrivingPositions , eligibleTickersForDrivingPositions , firstOptimizationDate , lastOptimizationDate , numberOfDrivingPositions , 2 , QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator ); } public bool MoveNext() { return this.drivingCombination.MoveNext(); } public void Reset() { this.drivingCombination.Reset(); } #region Current public object Current { get { return this.getCurrent(); } } private object getCurrent() { int[] currentValues = new int[ this.drivingCombination.Length ]; for ( int i = 0 ; i < this.drivingCombination.Length ; i ++ ) currentValues[ i ] = this.drivingCombination.GetValue( i ); BruteForceOptimizableParameters bruteForceOptimizableParameters = new BruteForceOptimizableParameters( currentValues , this ); return bruteForceOptimizableParameters; } #endregion #region Decode private bool isReallyMeaningful( BruteForceOptimizableParameters bruteForceOptimizableParameters ) { int[] optimizableParameterValues = bruteForceOptimizableParameters.GetValues(); int[] tickerRelatedParameterValues = this.getTickerRelatedParameterValuesForDrivingPositions( optimizableParameterValues ); string[] tickersForDrivingPositions = this.decodeTickers( tickerRelatedParameterValues , this.eligibleTickersForDrivingPositions ); return WeightedPositions.AreValidTickers( tickersForDrivingPositions ); } private double getWeight( int[] optimizableItem , int index ) { int weight = 1; if ( optimizableItem[ index ] < 0 ) // the position is short weight = -1; return weight; } private double[] getWeightRelatedParameterValuesForDrivingPositions( int[] optimizableParameters ) { double[] weightRelatedParameterValuesForDrivingPositions = new double[ this.numberOfDrivingPositions ]; for ( int parameterPosition = 0 ; parameterPosition < this.numberOfDrivingPositions ; parameterPosition++ ) weightRelatedParameterValuesForDrivingPositions[ parameterPosition ] = this.getWeight( optimizableParameters , parameterPosition ) / this.numberOfDrivingPositions; return weightRelatedParameterValuesForDrivingPositions; } private int getTickerIndexForDrivingPositions( int[] parameterValues , int parameterPosition ) { int tickerIndex = parameterValues[ parameterPosition ]; if ( tickerIndex < 0 ) // the position is short tickerIndex += this.eligibleTickersForDrivingPositions.Rows.Count; return tickerIndex; } private int[] getTickerRelatedParameterValuesForDrivingPositions( int[] optimizableParameters ) { int[] tickerRelatedParameterValuesForDrivingPositions = new int[ this.numberOfDrivingPositions ]; for ( int parameterPosition = 0 ; parameterPosition < this.numberOfDrivingPositions ; parameterPosition++ ) tickerRelatedParameterValuesForDrivingPositions[ parameterPosition ] = this.getTickerIndexForDrivingPositions( optimizableParameters , parameterPosition ); return tickerRelatedParameterValuesForDrivingPositions; } #region decodeWeightedPositions private string[] decodeTickers( int[] tickerRelatedParameterValues , DataTable eligibleTickers ) { string[] tickers = new string[ tickerRelatedParameterValues.Length ]; for( int i = 0 ; i < tickerRelatedParameterValues.Length ; i++ ) { int currentParameterValue = tickerRelatedParameterValues[ i ]; tickers[ i ] = ( string )eligibleTickers.Rows[ currentParameterValue ][ 0 ]; } return tickers; } private WeightedPositions decodeWeightedPositions( double[] weightRelatedParameterValues , int[] tickerRelatedParameterValues , DataTable eligibleTickers ) { string[] tickers = this.decodeTickers( tickerRelatedParameterValues , eligibleTickers ); WeightedPositions weightedPositions = new WeightedPositions( weightRelatedParameterValues , tickers ); return weightedPositions; } #endregion private WeightedPositions decodeDrivingWeightedPositions( int[] optimizableItemValues ) { double[] weightRelatedParameterValuesForDrivingPositions = this.getWeightRelatedParameterValuesForDrivingPositions( optimizableItemValues ); int[] tickerRelatedParameterValuesForDrivingPositions = this.getTickerRelatedParameterValuesForDrivingPositions( optimizableItemValues ); return decodeWeightedPositions( weightRelatedParameterValuesForDrivingPositions , tickerRelatedParameterValuesForDrivingPositions , this.eligibleTickersForDrivingPositions ); } private WeightedPositions decodePortfolioWeightedPositions( int[] optimizableParameters ) { double[] weightsForPortfolioPositions = new double[ 2 ] { 0.5 , -0.5 }; string[] tickersForPortfolioPositions = new string[ 2 ] { this.portfolioLongTicker , this.portfolioShortTicker }; WeightedPositions weightedPositions = new WeightedPositions( weightsForPortfolioPositions , tickersForPortfolioPositions ); return weightedPositions; } private object decodeMeaningfulParameters( BruteForceOptimizableParameters bruteForceOptimizableParameters ) { int[] optimizablePrameterValues = bruteForceOptimizableParameters.GetValues(); WeightedPositions drivingWeightedPositions = this.decodeDrivingWeightedPositions( optimizablePrameterValues ); WeightedPositions portfolioWeightedPositions = this.decodePortfolioWeightedPositions( optimizablePrameterValues ); WFLagWeightedPositions wFLagWeightedPositions = new WFLagWeightedPositions( drivingWeightedPositions , portfolioWeightedPositions ); return wFLagWeightedPositions; } public object Decode( BruteForceOptimizableParameters bruteForceOptimizableParameters ) { object meaning; if ( this.isReallyMeaningful( bruteForceOptimizableParameters ) ) meaning = this.decodeMeaningfulParameters( bruteForceOptimizableParameters ); else meaning = null; return meaning; } #endregion #region GetFitnessValue public double GetFitnessValue( BruteForceOptimizableParameters bruteForceOptimizableItem ) { double fitnessValue; WFLagWeightedPositions wFLagWeightedPositions = ( WFLagWeightedPositions )this.Decode( bruteForceOptimizableItem ); if ( wFLagWeightedPositions == null ) // the optimizable parameters object // contains a duplicate ticker for // driving positions. It is not meaningful in this implementation fitnessValue = -0.2; else // all driving position parameters refer to distinct tickers fitnessValue = this.wFLagGenomeManager.GetFitnessValue( wFLagWeightedPositions ); return fitnessValue; } #endregion private int getMinValueForParameter( int parameterPosition ) { int minValueForParameter = -this.eligibleTickersForDrivingPositions.Rows.Count; return minValueForParameter; } private int getMaxValueForParameter( int parameterPosition ) { int maxValueForParameter = this.eligibleTickersForDrivingPositions.Rows.Count - 1; return maxValueForParameter; } } } |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:19:54
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Collections In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv3915/b1_ADT/Collections Added Files: CollectionManager.cs Log Message: This class provides some functions for collections --- NEW FILE: CollectionManager.cs --- /* QuantProject - Quantitative Finance Library CollectionManager.cs Copyright (C) 2006 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; namespace QuantProject.ADT.Collections { /// <summary> /// This class provides some functions for collections /// </summary> public class CollectionManager { public CollectionManager() { // // TODO: Add constructor logic here // } public static bool ContainsDuplicates( ICollection collection ) { bool containsDuplicates = false; SortedList sortedTicker = new SortedList(); foreach ( object obj in collection ) if ( !sortedTicker.ContainsKey( obj ) ) sortedTicker.Add( obj , obj ); else containsDuplicates = true; return containsDuplicates; } } } |
|
From: Glauco S. <gla...@us...> - 2006-09-08 15:18:31
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv3469/b1_ADT Added Files: ExtendedMath.cs Log Message: Mathematical function provider --- NEW FILE: ExtendedMath.cs --- using System; namespace QuantProject.ADT { /// <summary> /// Mathematical function provider /// </summary> public class ExtendedMath { public ExtendedMath() { // // TODO: Add constructor logic here // } public static long Factorial( int n ) { if ( n < 0 ) throw new Exception( "Factorial is undefined for n<0!" ); long factorial; if ( ( n == 0 ) || ( n == 1 ) ) factorial = 1; else factorial = n * Factorial( n - 1 ); return factorial; } } } |
|
From: Glauco S. <gla...@us...> - 2006-09-08 13:59:29
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv2664/Downloader Modified Files: Downloader.csproj Log Message: Minor changes applied by the IDE environment Index: Downloader.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/Downloader.csproj,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Downloader.csproj 29 Mar 2005 14:59:25 -0000 1.30 --- Downloader.csproj 8 Sep 2006 13:59:22 -0000 1.31 *************** *** 201,205 **** <File RelPath = "QuotesEditor\QuotesChart.cs" ! SubType = "UserControl" BuildAction = "Compile" /> --- 201,205 ---- <File RelPath = "QuotesEditor\QuotesChart.cs" ! SubType = "Code" BuildAction = "Compile" /> *************** *** 236,240 **** <File RelPath = "QuotesEditor\VisualValidationChart.cs" ! SubType = "UserControl" BuildAction = "Compile" /> --- 236,240 ---- <File RelPath = "QuotesEditor\VisualValidationChart.cs" ! SubType = "Code" BuildAction = "Compile" /> *************** *** 251,255 **** <File RelPath = "QuotesEditor\CloseToClose\CloseToCloseChart.cs" ! SubType = "UserControl" BuildAction = "Compile" /> --- 251,255 ---- <File RelPath = "QuotesEditor\CloseToClose\CloseToCloseChart.cs" ! SubType = "Code" BuildAction = "Compile" /> *************** *** 281,285 **** <File RelPath = "QuotesEditor\RangeToRange\RangeToRangeChart.cs" ! SubType = "UserControl" BuildAction = "Compile" /> --- 281,285 ---- <File RelPath = "QuotesEditor\RangeToRange\RangeToRangeChart.cs" ! SubType = "Code" BuildAction = "Compile" /> |
|
From: Glauco S. <gla...@us...> - 2006-09-03 13:46:05
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10110/Downloader Modified Files: TickerDownloader.cs Log Message: - Quotes.GetStartDate calls have been replaced by Quotes.GetFirstQuoteDate calls - Quotes.GetEndDate calls have been replaced by Quotes.GetLastQuoteDate calls Index: TickerDownloader.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerDownloader.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** TickerDownloader.cs 2 Jul 2006 20:04:15 -0000 1.20 --- TickerDownloader.cs 3 Sep 2006 13:45:57 -0000 1.21 *************** *** 315,319 **** private void downloadTickerBeforeFirstQuote() { ! this.endDate = Quotes.GetStartDate(this.p_quTicker); this.resetStartDateIfNecessary(); this.checkForNewAdjustedAndContinueOrStop(); --- 315,319 ---- private void downloadTickerBeforeFirstQuote() { ! this.endDate = Quotes.GetFirstQuoteDate(this.p_quTicker); this.resetStartDateIfNecessary(); this.checkForNewAdjustedAndContinueOrStop(); *************** *** 343,348 **** this.updateCurrentStatusAdjustedClose("Changed!"); if (Quotes.IsAdjustedCloseToCloseRatioChanged(this.p_quTicker, ! this.getTableOfDownloadedValues(Quotes.GetStartDate(this.p_quTicker), ! Quotes.GetEndDate(this.p_quTicker))) && this.p_myForm.IsCheckCloseToCloseSelected) { --- 343,348 ---- this.updateCurrentStatusAdjustedClose("Changed!"); if (Quotes.IsAdjustedCloseToCloseRatioChanged(this.p_quTicker, ! this.getTableOfDownloadedValues(Quotes.GetFirstQuoteDate(this.p_quTicker), ! Quotes.GetLastQuoteDate(this.p_quTicker))) && this.p_myForm.IsCheckCloseToCloseSelected) { *************** *** 359,363 **** this.updateAdjustedClose(); this.updateCurrentStatusAdjustedClose("Updated!"); ! this.downloadedValuesFromSource = this.getTableOfDownloadedValues(Quotes.GetEndDate(this.p_quTicker), DateTime.Now); this.commitDownloadedValuesToDatabase(); --- 359,363 ---- this.updateAdjustedClose(); this.updateCurrentStatusAdjustedClose("Updated!"); ! this.downloadedValuesFromSource = this.getTableOfDownloadedValues(Quotes.GetLastQuoteDate(this.p_quTicker), DateTime.Now); this.commitDownloadedValuesToDatabase(); *************** *** 396,400 **** private void downloadTickerAfterLastQuote() { ! this.startDate = Quotes.GetEndDate(this.p_quTicker); this.endDate = DateTime.Today; this.checkForNewAdjustedAndContinueOrStop(); --- 396,400 ---- private void downloadTickerAfterLastQuote() { ! this.startDate = Quotes.GetLastQuoteDate(this.p_quTicker); this.endDate = DateTime.Today; this.checkForNewAdjustedAndContinueOrStop(); |
|
From: Marco M. <mi...@us...> - 2006-08-22 19:09:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv29403/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManipulator.cs Log Message: Method IsTickerContainedInGenome has been overloaded: added parameters fromGenePosition and toGenePosition in order to perform check only in the given section of the given genome Index: GenomeManipulator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManipulator.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenomeManipulator.cs 7 Aug 2006 21:03:24 -0000 1.7 --- GenomeManipulator.cs 22 Aug 2006 19:09:35 -0000 1.8 *************** *** 232,235 **** --- 232,264 ---- } + + /// <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> + /// <param name="fromGenePosition">First gene position from which the checking + /// has to be done, inside the given genome</param> + /// <param name="toGenePosition">Last gene position to which the checking + /// has to be done, inside the given genome</param> + public static bool IsTickerContainedInGenome(int geneCorrespondingToATicker, + Genome genome, int fromGenePosition, + int toGenePosition) + { + return( + genome.HasGene(geneCorrespondingToATicker, + fromGenePosition, toGenePosition) || + ( geneCorrespondingToATicker < 0 && + genome.HasGene( + Math.Abs(geneCorrespondingToATicker)-1, + fromGenePosition, toGenePosition) ) || + ( geneCorrespondingToATicker >= 0 && + genome.HasGene(- Math.Abs(geneCorrespondingToATicker)- 1, + fromGenePosition, toGenePosition)) + ); + + } } |
|
From: Marco M. <mi...@us...> - 2006-08-22 19:08:00
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv28561/b1_ADT/Optimizing/Genetic Modified Files: Genome.cs Log Message: Method HasGene has been overloaded: added parameters fromGenePosition and toGenePosition in order to perform check only in the given section of the genome Index: Genome.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/Genome.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Genome.cs 7 Aug 2006 21:03:24 -0000 1.13 --- Genome.cs 22 Aug 2006 19:07:50 -0000 1.14 *************** *** 209,212 **** --- 209,237 ---- return returnValue; } + + /// <summary> + /// It returns true if the given gene is already stored in the current genome + /// </summary> + /// <param name="fromGenePosition">First gene position from which the checking + /// has to be done, inside the given genome</param> + /// <param name="toGenePosition">Last gene position to which the checking + /// has to be done, inside the given genome</param> + public bool HasGene(int geneValue, int fromGenePosition, + int toGenePosition) + { + if(fromGenePosition < 0 || + toGenePosition < 0 || + fromGenePosition >= this.size || + toGenePosition >= this.size) + throw new IndexOutOfRangeException("error in parameters fromGenePosition or toGenePosition!"); + + bool returnValue = false; + for(int i = fromGenePosition; i <= toGenePosition; i++) + { + if( geneValue == this.Genes()[i] ) + returnValue = true; + } + return returnValue; + } /// <summary> |
|
From: Marco M. <mi...@us...> - 2006-08-22 19:05:55
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv27732/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: no message Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** GeneticOptimizer.cs 13 Aug 2006 19:00:55 -0000 1.21 --- GeneticOptimizer.cs 22 Aug 2006 19:05:50 -0000 1.22 *************** *** 478,483 **** this.nextGeneration.Clear(); this.createNextGeneration_addChildsWithRouletteSelection(); - this.createNextGeneration_transmitEliteToNextGeneration(); this.mutateGenomes(); this.calculateFitnessAndMeaningForAllGenomes(); this.updateCurrentGeneration(); --- 478,483 ---- this.nextGeneration.Clear(); this.createNextGeneration_addChildsWithRouletteSelection(); this.mutateGenomes(); + this.createNextGeneration_transmitEliteToNextGeneration(); this.calculateFitnessAndMeaningForAllGenomes(); this.updateCurrentGeneration(); |
|
From: Glauco S. <gla...@us...> - 2006-08-21 21:21:41
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6397/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagChosenTickers.cs Log Message: Added a private method to allow the SetTickers method to use a brute force optimizer Index: WFLagChosenTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagChosenTickers.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WFLagChosenTickers.cs 8 Aug 2006 09:43:40 -0000 1.4 --- WFLagChosenTickers.cs 21 Aug 2006 21:21:37 -0000 1.5 *************** *** 26,29 **** --- 26,30 ---- using QuantProject.ADT; using QuantProject.ADT.Collections; + using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Strategies; *************** *** 42,52 **** public event NewProgressEventHandler NewProgress; ! private WFLagEligibleTickers eligibleTickers; ! private int numberOfDrivingPositions; ! private int numberOfPositionsToBeChosen; ! private int inSampleDays; ! private IEndOfDayTimer endOfDayTimer; ! private int generationNumberForGeneticOptimizer; ! private int populationSizeForGeneticOptimizer; private WeightedPositions drivingWeightedPositions; --- 43,53 ---- public event NewProgressEventHandler NewProgress; ! protected WFLagEligibleTickers eligibleTickers; ! protected int numberOfDrivingPositions; ! protected int numberOfPositionsToBeChosen; ! protected int inSampleDays; ! protected IEndOfDayTimer endOfDayTimer; ! protected int generationNumberForGeneticOptimizer; ! protected int populationSizeForGeneticOptimizer; private WeightedPositions drivingWeightedPositions; *************** *** 125,129 **** } ! #region SetSignedTickers // private void setSignedTickers_clearPositions() // { --- 126,130 ---- } ! #region SetWeightedPositions // private void setSignedTickers_clearPositions() // { *************** *** 131,134 **** --- 132,136 ---- // this.portfolioPositions.Clear(); // } + #region setWeightedPositions_usingTheGeneticOptimizer private void newGenerationEventHandler( object sender , NewGenerationEventArgs e ) *************** *** 137,140 **** --- 139,150 ---- new NewProgressEventArgs( e.GenerationCounter , e.GenerationNumber ) ); } + private void setWeightedPositions( + WFLagWeightedPositions wFLagWeightedPositions ) + { + this.drivingWeightedPositions = + wFLagWeightedPositions.DrivingWeightedPositions; + this.portfolioWeightedPositions = + wFLagWeightedPositions.PortfolioWeightedPositions; + } private void setSignedTickers_setTickersFromGenome( IGenomeManager genomeManager , *************** *** 143,155 **** WFLagWeightedPositions wFLagWeightedPositions = ( WFLagWeightedPositions )genomeManager.Decode( genome ); ! this.drivingWeightedPositions = ! wFLagWeightedPositions.DrivingWeightedPositions; ! this.portfolioWeightedPositions = ! wFLagWeightedPositions.PortfolioWeightedPositions; } ! public void SetWeightedPositions( WFLagEligibleTickers eligibleTickers ) { - // this.setSignedTickers_clearPositions(); - this.firstOptimizationDate = this.endOfDayTimer.GetCurrentTime().DateTime.AddDays( --- 153,165 ---- WFLagWeightedPositions wFLagWeightedPositions = ( WFLagWeightedPositions )genomeManager.Decode( genome ); ! this.setWeightedPositions( wFLagWeightedPositions ); ! // this.drivingWeightedPositions = ! // wFLagWeightedPositions.DrivingWeightedPositions; ! // this.portfolioWeightedPositions = ! // wFLagWeightedPositions.PortfolioWeightedPositions; } ! public virtual void setWeightedPositions_usingTheGeneticOptimizer( ! WFLagEligibleTickers eligibleTickers ) { this.firstOptimizationDate = this.endOfDayTimer.GetCurrentTime().DateTime.AddDays( *************** *** 158,163 **** this.endOfDayTimer.GetCurrentTime().DateTime; ! WFLagGenomeManagerWithWeights genomeManager = ! new WFLagGenomeManagerWithWeights( eligibleTickers.EligibleTickers , eligibleTickers.EligibleTickers , --- 168,173 ---- this.endOfDayTimer.GetCurrentTime().DateTime; ! WFLagGenomeManager genomeManager = ! new WFLagGenomeManager( eligibleTickers.EligibleTickers , eligibleTickers.EligibleTickers , *************** *** 165,174 **** this.lastOptimizationDate , this.numberOfDrivingPositions , ! this.numberOfPositionsToBeChosen ); GeneticOptimizer geneticOptimizer = new GeneticOptimizer( ! genomeManager , this.populationSizeForGeneticOptimizer , this.generationNumberForGeneticOptimizer , ConstantsProvider.SeedForRandomGenerator ); --- 175,188 ---- this.lastOptimizationDate , this.numberOfDrivingPositions , ! this.numberOfPositionsToBeChosen , ! QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator ); GeneticOptimizer geneticOptimizer = new GeneticOptimizer( ! 0.85 , ! 0.02 , ! 0.1 , this.populationSizeForGeneticOptimizer , this.generationNumberForGeneticOptimizer , + genomeManager , ConstantsProvider.SeedForRandomGenerator ); *************** *** 185,188 **** --- 199,255 ---- } #endregion + #region setWeightedPositions_usingTheBruteForceOptimizer + private void newBruteForceOptimizerProgressEventHandler( + object sender , NewProgressEventArgs e ) + { + this.NewProgress( sender , e ); + } + public virtual void setWeightedPositions_usingTheBruteForceOptimizer( + WFLagEligibleTickers eligibleTickers ) + { + this.firstOptimizationDate = + this.endOfDayTimer.GetCurrentTime().DateTime.AddDays( + -( this.inSampleDays - 1 ) ); + this.lastOptimizationDate = + this.endOfDayTimer.GetCurrentTime().DateTime; + + WFLagBruteForceOptimizableParametersManager + wFLagBruteForceOptimizableItemManager= + new WFLagBruteForceOptimizableParametersManager( + eligibleTickers.EligibleTickers , + eligibleTickers.EligibleTickers , + this.firstOptimizationDate , + this.lastOptimizationDate , + this.numberOfDrivingPositions , + this.numberOfPositionsToBeChosen ); + + BruteForceOptimizer bruteForceOptimizer = new BruteForceOptimizer( + wFLagBruteForceOptimizableItemManager ); + + bruteForceOptimizer.NewProgress += + new NewProgressEventHandler( + this.newBruteForceOptimizerProgressEventHandler ); + + bruteForceOptimizer.Run(); + + BruteForceOptimizableParameters bestParameters = + bruteForceOptimizer.BestParameters; + + WFLagWeightedPositions wFLagWeightedPositions = + ( WFLagWeightedPositions )wFLagBruteForceOptimizableItemManager.Decode( + bestParameters ); + + this.setWeightedPositions( wFLagWeightedPositions ); + } + #endregion + public virtual void SetWeightedPositions( + WFLagEligibleTickers eligibleTickers ) + { + // this.setWeightedPositions_usingTheGeneticOptimizer( + // eligibleTickers ); + this.setWeightedPositions_usingTheBruteForceOptimizer( + eligibleTickers ); + } + #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-08-21 21:17:35
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv4733/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagGenomeManagerWithWeights.cs Log Message: - an int seedForRandomGenerator parameter has been added to the constructor - now the fitness value for the invalid genomes is set to -0.2, it was set to double.MinValue before, but it gave problems with the roulette selection algorithm Index: WFLagGenomeManagerWithWeights.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomeManagerWithWeights.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFLagGenomeManagerWithWeights.cs 8 Aug 2006 09:37:57 -0000 1.2 --- WFLagGenomeManagerWithWeights.cs 21 Aug 2006 21:17:32 -0000 1.3 *************** *** 1,2 **** --- 1,24 ---- + /* + QuantProject - Quantitative Finance Library + + WFLagGenomeManagerWithWeights.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; *************** *** 31,36 **** - private GeneticOptimizer currentGeneticOptimizer; - public int GenomeSize { --- 53,56 ---- *************** *** 76,80 **** DateTime lastOptimizationDate , int numberOfDrivingPositions , ! int numberOfTickersInPortfolio ) { --- 96,101 ---- DateTime lastOptimizationDate , int numberOfDrivingPositions , ! int numberOfTickersInPortfolio , ! int seedForRandomGenerator ) { *************** *** 92,98 **** this.minimumPositionWeight = 0.2; // TO DO this value should become a constructor parameter ! GenomeManagement.SetRandomGenerator( ! QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator ! + this.firstOptimizationDate.DayOfYear ); this.wFLagCandidates = new WFLagCandidates( --- 113,122 ---- this.minimumPositionWeight = 0.2; // TO DO this value should become a constructor parameter ! // GenomeManagement.SetRandomGenerator( ! // QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator ! // + this.firstOptimizationDate.DayOfYear ); ! // GenomeManagement.SetRandomGenerator( ! // 11 ); ! GenomeManagement.SetRandomGenerator( seedForRandomGenerator ); this.wFLagCandidates = new WFLagCandidates( *************** *** 186,195 **** private double getFitnessValue( double[] strategyReturns ) { ! // double fitnessValue = ! // AdvancedFunctions.GetSharpeRatio( ! // strategyReturns ); ! double fitnessValue = ! AdvancedFunctions.GetExpectancyScore( ! strategyReturns ); // double fitnessValue = // this.getFitnessValue_withGoodFinal( strategyReturns ); --- 210,219 ---- private double getFitnessValue( double[] strategyReturns ) { ! double fitnessValue = ! AdvancedFunctions.GetSharpeRatio( ! strategyReturns ); ! // double fitnessValue = ! // AdvancedFunctions.GetExpectancyScore( ! // strategyReturns ); // double fitnessValue = // this.getFitnessValue_withGoodFinal( strategyReturns ); *************** *** 227,231 **** // genome contains a duplicate gene either for // driving positions or for portfolio positions ! fitnessValue = double.MinValue; else // all driving positions genes are distinct and --- 251,256 ---- // genome contains a duplicate gene either for // driving positions or for portfolio positions ! //fitnessValue = double.MinValue; ! fitnessValue = -0.2; else // all driving positions genes are distinct and |
|
From: Glauco S. <gla...@us...> - 2006-08-21 19:55:24
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv30800/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagGenomeManager.cs Log Message: - an int seedForRandomGenerator parameter has been added to the constructor - now the fitness value for the invalid genomes is set to -0.2, it was set to double.MinValue before, but it gave problems with the roulette selection algorithm Index: WFLagGenomeManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomeManager.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagGenomeManager.cs 8 Aug 2006 09:37:57 -0000 1.3 --- WFLagGenomeManager.cs 21 Aug 2006 19:55:17 -0000 1.4 *************** *** 3,7 **** WFLagGenomeManager.cs ! Copyright (C) 2003 Glauco Siliprandi --- 3,7 ---- WFLagGenomeManager.cs ! Copyright (C) 2003 Glauco Siliprandi *************** *** 27,32 **** using QuantProject.ADT.Optimizing.Genetic; using QuantProject.ADT.Statistics; ! using QuantProject.Data.DataTables; ! using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag --- 27,31 ---- using QuantProject.ADT.Optimizing.Genetic; using QuantProject.ADT.Statistics; ! using QuantProject.Business.Strategies; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag *************** *** 35,59 **** /// This class implements IGenomeManager, in order to find the /// best driving position group and the best ! /// portfolio position group with respect to the lag strategy /// </summary> public class WFLagGenomeManager : IGenomeManager { - private DataTable eligibleTickers; - private DateTime firstQuoteDate; - private DateTime lastQuoteDate; private int numberOfDrivingPositions; private int numberOfTickersInPortfolio; ! private int numberOfEligibleTickers; private WFLagCandidates wFLagCandidates; public int GenomeSize { get { ! return this.numberOfDrivingPositions + this.numberOfTickersInPortfolio; } } // public GeneticOptimizer CurrentGeneticOptimizer // { --- 34,71 ---- /// This class implements IGenomeManager, in order to find the /// best driving position group and the best ! /// portfolio position group with respect to the lag strategy. ! /// Weights are NOT used /// </summary> public class WFLagGenomeManager : IGenomeManager { private int numberOfDrivingPositions; private int numberOfTickersInPortfolio; + private int numberOfEligibleTickersForDrivingWeightedPositions; + private DataTable eligibleTickersForDrivingWeightedPositions; + private DataTable eligibleTickersForPortfolioWeightedPositions; + private DateTime firstOptimizationDate; + private DateTime lastOptimizationDate; ! private double minimumPositionWeight; private WFLagCandidates wFLagCandidates; + public int GenomeSize { get { ! return ( this.numberOfDrivingPositions + this.numberOfTickersInPortfolio ); } } + + // public int MinValueForGenes + // { + // get { return -this.numberOfEligibleTickersForDrivingWeightedPositions; } + // } + // public int MaxValueForGenes + // { + // get { return this.numberOfEligibleTickersForDrivingWeightedPositions - 1; } + // } // public GeneticOptimizer CurrentGeneticOptimizer // { *************** *** 62,146 **** // } public WFLagGenomeManager( ! DataTable eligibleTickers , ! DateTime firstQuoteDate , ! DateTime lastQuoteDate , int numberOfDrivingPositions , ! int numberOfTickersInPortfolio ) { - this.eligibleTickers = eligibleTickers; - this.firstQuoteDate = firstQuoteDate; - this.lastQuoteDate = lastQuoteDate; this.numberOfDrivingPositions = numberOfDrivingPositions; this.numberOfTickersInPortfolio = numberOfTickersInPortfolio; ! this.numberOfEligibleTickers = eligibleTickers.Rows.Count; ! GenomeManagement.SetRandomGenerator( ! QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator + ! firstQuoteDate.Date.DayOfYear ); ! this.wFLagCandidates = new WFLagCandidates( this.eligibleTickers , ! this.firstQuoteDate , this.lastQuoteDate ); } - public int GetMinValueForGenes( int genePosition ) { ! return -this.numberOfEligibleTickers; } public int GetMaxValueForGenes( int genePosition ) { ! return this.numberOfEligibleTickers - 1; ! } ! ! public static string GetTicker( string signedTicker ) ! { ! string returnValue; ! if ( signedTicker.IndexOf( "-" ) == 0 ) ! returnValue = signedTicker.Substring( 1 , signedTicker.Length - 1 ); ! else ! returnValue = signedTicker; ! return returnValue; } #region GetFitnessValue ! #region getFitnessValue_getLinearCombinationReturns ! private ArrayList getEnumeratedSignedTickers( ! ICollection signedTickers ) ! { ! ArrayList enumeratedSignedTickers = new ArrayList(); ! foreach ( string signedTicker in signedTickers ) ! enumeratedSignedTickers.Add( signedTicker ); ! return enumeratedSignedTickers; ! } ! private ArrayList getTickers( ICollection signedTickers ) { ! ArrayList tickers = new ArrayList(); ! foreach ( string signedTicker in signedTickers ) ! tickers.Add( WFLagGenomeManager.GetTicker( signedTicker ) ); return tickers; } ! private float[] getMultipliers( ArrayList signedTickers ) { ! float[] multipliers = new float[ signedTickers.Count ]; ! int i = 0; ! foreach ( string signedTicker in signedTickers ) { ! float multiplier = 1F; ! if ( signedTicker.IndexOf( "-" ) == 0 ) ! multiplier = -1F; ! multipliers[ i ] = multiplier; ! i++; } return multipliers; } private double[] getFitnessValue_getLinearCombinationReturns( ! ICollection signedTickers ) { ! ArrayList enumeratedSignedTicker = ! this.getEnumeratedSignedTickers( signedTickers ); ! int numberOfSignedTickers = enumeratedSignedTicker.Count; ! ArrayList tickers = this.getTickers( enumeratedSignedTicker ); ! float[] multipliers = this.getMultipliers( enumeratedSignedTicker ); // arrays of close to close returns, one for each signed ticker float[][] tickersReturns = --- 74,167 ---- // } + /// <summary> + /// This class implements IGenomeManager, in order to find the + /// best driving position group and the best + /// portfolio position group with respect to the lag strategy. + /// Weighted positions are used for both the driving positions + /// and the portfolio positions + /// </summary> + /// <param name="eligibleTickersForDrivingWeightedPositions">weighted positions + /// for driving positions will be chosen among these tickers</param> + /// <param name="eligibleTickersForPortfolioWeightedPositions">weighted positions + /// for portfolio positions will be chosen among these tickers</param> + /// <param name="firstOptimizationDate"></param> + /// <param name="lastQuoteDate"></param> + /// <param name="numberOfDrivingPositions"></param> + /// <param name="numberOfTickersInPortfolio"></param> public WFLagGenomeManager( ! DataTable eligibleTickersForDrivingWeightedPositions , ! DataTable eligibleTickersForPortfolioWeightedPositions , ! DateTime firstOptimizationDate , ! DateTime lastOptimizationDate , int numberOfDrivingPositions , ! int numberOfTickersInPortfolio , ! int seedForRandomGenerator ) ! { this.numberOfDrivingPositions = numberOfDrivingPositions; this.numberOfTickersInPortfolio = numberOfTickersInPortfolio; + this.numberOfEligibleTickersForDrivingWeightedPositions = + eligibleTickersForDrivingWeightedPositions.Rows.Count; + this.eligibleTickersForDrivingWeightedPositions = + eligibleTickersForDrivingWeightedPositions; + this.eligibleTickersForPortfolioWeightedPositions = + eligibleTickersForPortfolioWeightedPositions; + this.firstOptimizationDate = firstOptimizationDate; + this.lastOptimizationDate = lastOptimizationDate; ! this.minimumPositionWeight = 0.2; // TO DO this value should become a constructor parameter ! // GenomeManagement.SetRandomGenerator( ! // QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator ! // + this.firstOptimizationDate.DayOfYear ); ! // GenomeManagement.SetRandomGenerator( ! // 11 ); ! GenomeManagement.SetRandomGenerator( seedForRandomGenerator ); ! this.wFLagCandidates = new WFLagCandidates( ! this.eligibleTickersForDrivingWeightedPositions , ! this.firstOptimizationDate , this.lastOptimizationDate ); } public int GetMinValueForGenes( int genePosition ) { ! int minValueForGene = ! -this.numberOfEligibleTickersForDrivingWeightedPositions; ! return minValueForGene; } public int GetMaxValueForGenes( int genePosition ) { ! return this.numberOfEligibleTickersForDrivingWeightedPositions - 1; } #region GetFitnessValue ! private string[] getTickers( WeightedPositions weightedPositions ) { ! string[] tickers = new string[ weightedPositions.Count ]; ! for ( int i = 0 ; i < weightedPositions.Count ; i++ ) ! { ! WeightedPosition weightedPosition = weightedPositions.GetWeightedPosition( i ); ! tickers[ i ] = weightedPosition.Ticker; ! } return tickers; } ! private float[] getMultipliers( WeightedPositions weightedPositions ) { ! float[] multipliers = new float[ weightedPositions.Count ]; ! for ( int i = 0 ; i < weightedPositions.Count ; i++ ) { ! WeightedPosition weightedPosition = weightedPositions.GetWeightedPosition( i ); ! multipliers[ i ] = Convert.ToSingle( weightedPosition.Weight ); } return multipliers; } + private double[] getFitnessValue_getLinearCombinationReturns( ! WeightedPositions weightedPositions ) { ! // ArrayList enumeratedweightedPositions = ! // this.getEnumeratedWeightedPositions( weightedPositions ); ! int numberOfWeightedPositions = weightedPositions.Count; ! string[] tickers = this.getTickers( weightedPositions ); ! float[] multipliers = this.getMultipliers( weightedPositions ); // arrays of close to close returns, one for each signed ticker float[][] tickersReturns = *************** *** 152,168 **** { linearCombinationReturns[ i ] = 0; ! for ( int j=0 ; j < numberOfSignedTickers ; j++ ) { ! double signedTickerReturn = tickersReturns[ j ][ i ] * multipliers[ j ]; ! // the investment is assumed to be equally divided for each ! // signed ticker ! linearCombinationReturns[ i ] += signedTickerReturn / ! numberOfSignedTickers; } } return linearCombinationReturns; } - #endregion private double[] getFitnessValue_getStrategyReturn( double[] drivingPositionsReturns , double[] portfolioPositionsReturns ) --- 173,185 ---- { linearCombinationReturns[ i ] = 0; ! for ( int j=0 ; j < weightedPositions.Count ; j++ ) { ! double weightedPositionReturn = tickersReturns[ j ][ i ] * multipliers[ j ]; ! linearCombinationReturns[ i ] += weightedPositionReturn; } } return linearCombinationReturns; } private double[] getFitnessValue_getStrategyReturn( double[] drivingPositionsReturns , double[] portfolioPositionsReturns ) *************** *** 188,225 **** } - private double[] getFinalReturns( double[] strategyReturns , - int finalLength ) - { - double[] finalReturns = new double[ finalLength ]; - for ( int i = strategyReturns.Length - finalLength ; - i < strategyReturns.Length ; i++ ) - finalReturns[ i - ( strategyReturns.Length - finalLength ) ] = - strategyReturns[ i ]; - return finalReturns; - } - private double getFitnessValue_sharpeRatio( - double[] returns ) - { - double fitnessValue = - AdvancedFunctions.GetSharpeRatio( - returns ); - return fitnessValue; - } - private double getFitnessValue_withGoodFinal( - double[] strategyReturns ) - { - double[] secondHalfStrategyReturns = - this.getFinalReturns( strategyReturns , - strategyReturns.Length/2 ); - double[] fourthQuorterStrategyReturns = - this.getFinalReturns( strategyReturns , - strategyReturns.Length/4 ); - double fitnessValue = - this.getFitnessValue_sharpeRatio( strategyReturns ) * - this.getFitnessValue_sharpeRatio( secondHalfStrategyReturns ) * - this.getFitnessValue_sharpeRatio( fourthQuorterStrategyReturns ); - return fitnessValue; - } - private double getFitnessValue( double[] strategyReturns ) { --- 205,208 ---- *************** *** 227,235 **** AdvancedFunctions.GetSharpeRatio( strategyReturns ); ! // double fitnessValue = ! // AdvancedFunctions.GetExpectancyScore( ! // strategyReturns ); // double fitnessValue = ! // this.getFitnessValue_withGoodFinal( strategyReturns ); // double fitnessValue = // BasicFunctions.GetSimpleAverage( strategyReturns ) / --- 210,218 ---- AdvancedFunctions.GetSharpeRatio( strategyReturns ); ! // double fitnessValue = ! // AdvancedFunctions.GetExpectancyScore( ! // strategyReturns ); // double fitnessValue = ! // this.getFitnessValue_withGoodFinal( strategyReturns ); // double fitnessValue = // BasicFunctions.GetSimpleAverage( strategyReturns ) / *************** *** 237,248 **** return fitnessValue; } ! private double getFitnessValue( WFLagSignedTickers wFLagSignedTickers ) { double[] drivingPositionsReturns = this.getFitnessValue_getLinearCombinationReturns( ! wFLagSignedTickers.DrivingPositions.Keys ); double[] portfolioPositionsReturns = this.getFitnessValue_getLinearCombinationReturns( ! wFLagSignedTickers.PortfolioPositions.Keys ); double[] strategyReturns = this.getFitnessValue_getStrategyReturn( --- 220,233 ---- return fitnessValue; } ! ! public double GetFitnessValue( ! WFLagWeightedPositions wFLagWeightedPositions ) { double[] drivingPositionsReturns = this.getFitnessValue_getLinearCombinationReturns( ! wFLagWeightedPositions.DrivingWeightedPositions ); double[] portfolioPositionsReturns = this.getFitnessValue_getLinearCombinationReturns( ! wFLagWeightedPositions.PortfolioWeightedPositions ); double[] strategyReturns = this.getFitnessValue_getStrategyReturn( *************** *** 253,259 **** public double GetFitnessValue( Genome genome ) { ! WFLagSignedTickers wFLagSignedTickers = ! ( WFLagSignedTickers )this.Decode( genome ); ! return this.getFitnessValue( wFLagSignedTickers ); } #endregion --- 238,259 ---- public double GetFitnessValue( Genome genome ) { ! double fitnessValue; ! WFLagWeightedPositions wFLagWeightedPositions = ! ( WFLagWeightedPositions )this.Decode( genome ); ! int genomeLength = genome.Genes().Length; ! int decodedWeightedPositions = ! wFLagWeightedPositions.DrivingWeightedPositions.Count + ! wFLagWeightedPositions.PortfolioWeightedPositions.Count; ! if ( decodedWeightedPositions < genomeLength ) ! // genome contains a duplicate gene either for ! // driving positions or for portfolio positions ! //fitnessValue = double.MinValue; ! fitnessValue = -0.2; ! else ! // all driving positions genes are distinct and ! // all portfolio positions genes are distinct ! fitnessValue = ! this.GetFitnessValue( wFLagWeightedPositions ); ! return fitnessValue; } #endregion *************** *** 261,368 **** { return ! GenomeManipulator.MixGenesWithoutDuplicates(parent1, parent2); } public void Mutate( Genome genome , double mutationRate ) { ! // 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, in this implementation, ! // can't have a long position and a short position ! // for the same ticker ! { ! newValueForGene = GenomeManagement.RandomGenerator.Next( ! genome.GetMinValueForGenes( genePositionToBeMutated ) , ! genome.GetMaxValueForGenes( genePositionToBeMutated ) + 1 ); ! } GenomeManagement.MutateOneGene( genome , mutationRate , genePositionToBeMutated , newValueForGene ); } #region Decode ! private string decode_getSignedTicker( int geneValue ) { ! string initialCharForTickerCode = ""; ! int position = geneValue; ! if( geneValue < 0 ) ! { ! position = Math.Abs( geneValue ) - 1; ! initialCharForTickerCode = "-"; ! } ! return initialCharForTickerCode + ! ( string )this.eligibleTickers.Rows[ position ][ 0 ]; } ! private void decode_addDrivingPosition( ! Genome genome , int geneIndex , WFLagSignedTickers wFLagSignedTickers ) { ! int indexOfTicker = (int)genome.Genes().GetValue( geneIndex ); ! string signedTicker = this.decode_getSignedTicker( indexOfTicker ); ! wFLagSignedTickers.DrivingPositions.Add( signedTicker , null ); } ! private void decode_addPortfolioPosition( ! Genome genome , int geneIndex , WFLagSignedTickers wFLagSignedTickers ) { ! int indexOfTicker = (int)genome.Genes().GetValue( geneIndex ); ! string signedTicker = this.decode_getSignedTicker( indexOfTicker ); ! wFLagSignedTickers.PortfolioPositions.Add( signedTicker , null ); } ! private string decode_getSignedTickerForGeneValue( int geneValue ) { ! string initialCharForTickerCode = ""; ! int position = geneValue; ! if( geneValue < 0 ) { ! position = Math.Abs( geneValue ) - 1; ! initialCharForTickerCode = "-"; } ! return initialCharForTickerCode + ! ( string )this.eligibleTickers.Rows[ position ][ 0 ]; } ! public virtual object Decode(Genome genome) { ! WFLagSignedTickers wFLagSignedTickers = new WFLagSignedTickers(); ! for ( int geneIndex = 0 ; geneIndex < this.numberOfDrivingPositions ; ! geneIndex ++ ) ! this.decode_addDrivingPosition( genome , geneIndex , wFLagSignedTickers ); ! for ( int geneIndex = this.numberOfDrivingPositions ; ! geneIndex < this.numberOfDrivingPositions + this.numberOfTickersInPortfolio ; ! geneIndex ++ ) ! this.decode_addPortfolioPosition( genome , geneIndex , wFLagSignedTickers ); ! string[] arrayOfTickers = new string[genome.Genes().Length]; ! int indexOfTicker; ! for(int index = 0; index < genome.Genes().Length; index++) { ! indexOfTicker = (int)genome.Genes().GetValue(index); ! arrayOfTickers[index] = ! this.decode_getSignedTickerForGeneValue(indexOfTicker); } ! return wFLagSignedTickers; } #endregion ! public int GetNewGeneValue( Genome genome , int i ) { ! // 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( i ) , ! genome.GetMaxValueForGenes( i ) + 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( i ) , ! genome.GetMaxValueForGenes( i ) + 1 ); } ! return returnValue; } } } --- 261,510 ---- { return ! GenomeManagement.AlternateFixedCrossover(parent1, parent2); } public void Mutate( Genome genome , double mutationRate ) { ! // int newValueForGene = GenomeManagement.RandomGenerator.Next( ! // genome.MinValueForGenes , ! // genome.MaxValueForGenes + 1 ); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next( genome.Size ); ! int newValueForGene = ! this.GetNewGeneValue( genome , genePositionToBeMutated ); GenomeManagement.MutateOneGene( genome , mutationRate , genePositionToBeMutated , newValueForGene ); } #region Decode ! private int getWeight( Genome genome , int genePosition ) { ! int geneValue = 1; ! if ( genome.GetGeneValue( genePosition ) < 0 ) ! // the position is short ! geneValue = -1; ! return geneValue; } ! private int[] getWeightRelatedGeneValuesForDrivingPositions( ! Genome genome ) { ! int[] weightRelatedGeneValuesForDrivingPositions = ! new int[ this.numberOfDrivingPositions ]; ! for ( int genePosition = 0 ; ! genePosition < this.numberOfDrivingPositions ; genePosition++ ) ! weightRelatedGeneValuesForDrivingPositions[ genePosition ] = ! this.getWeight( genome , genePosition ); ! return weightRelatedGeneValuesForDrivingPositions; } ! private int getTickerIndex( Genome genome , int genePosition ) { ! int tickerIndex = genome.GetGeneValue( genePosition ); ! if ( tickerIndex < 0 ) ! // the position is short ! tickerIndex += -this.GetMinValueForGenes( genePosition ); ! return tickerIndex; } ! private int[] getTickerRelatedGeneValuesForDrivingPositions( ! Genome genome ) { ! int[] tickerRelatedGeneValuesForDrivingPositions = ! new int[ this.numberOfDrivingPositions ]; ! for ( int genePosition = 0 ; ! genePosition < this.numberOfDrivingPositions ; genePosition++ ) ! tickerRelatedGeneValuesForDrivingPositions[ genePosition ] = ! this.getTickerIndex( genome , genePosition ); ! return tickerRelatedGeneValuesForDrivingPositions; ! } ! private int[] getWeightRelatedGeneValuesForPortfolioPositions( ! Genome genome ) ! { ! int[] weightRelatedGeneValuesForPortfolioPositions = ! new int[ this.numberOfTickersInPortfolio ]; ! int firstPositionForPortfolioRelatedGenomes = ! this.numberOfDrivingPositions; ! for ( int i = 0 ; i < this.numberOfTickersInPortfolio ; i++ ) { ! int genePosition = ! firstPositionForPortfolioRelatedGenomes + i; ! weightRelatedGeneValuesForPortfolioPositions[ i ] = ! this.getWeight( genome , genePosition ); } ! return weightRelatedGeneValuesForPortfolioPositions; } ! private int[] getTickerRelatedGeneValuesForPortfolioPositions( ! Genome genome ) { ! int[] tickerRelatedGeneValuesForPortfolioPositions = ! new int[ this.numberOfTickersInPortfolio ]; ! int firstPositionForPortfolioRelatedGenomes = ! this.numberOfDrivingPositions; ! for ( int i = 0 ; i < this.numberOfTickersInPortfolio ; i++ ) { ! int genePosition = ! firstPositionForPortfolioRelatedGenomes + i; ! tickerRelatedGeneValuesForPortfolioPositions[ i ] = ! this.getTickerIndex( genome , genePosition ); } ! return tickerRelatedGeneValuesForPortfolioPositions; ! } ! #region decodeWeightedPositions ! #region getNormalizedWeightValues ! private double getAdditionalWeight( int weightRelatedGeneValue ) ! { ! double midrangeValue = ( ! this.GetMinValueForGenes( 0 ) + this.GetMaxValueForGenes( 0 ) ) / 2; ! double singleWeightFreeRange = 1 - this.minimumPositionWeight; ! double scaleRange = Convert.ToDouble( ! this.GetMinValueForGenes( 0 ) - this.GetMaxValueForGenes( 0 ) ); ! double nonScaledAdditionalWeight = Convert.ToDouble( weightRelatedGeneValue ) - ! midrangeValue; ! double scaledAdditionalWeight = ! nonScaledAdditionalWeight * singleWeightFreeRange / scaleRange; ! return scaledAdditionalWeight; ! } ! private double getNonNormalizedWeightValue( int weightRelatedGeneValue ) ! { ! double additionalWeight = this.getAdditionalWeight( weightRelatedGeneValue ); ! double nonNormalizedWeightValue = 0; ! if ( additionalWeight >= 0 ) ! // the gene value represents a long position ! nonNormalizedWeightValue = this.minimumPositionWeight + additionalWeight; ! else ! // additionalWeight < 0 , i.e. the gene value represents a short position ! nonNormalizedWeightValue = -this.minimumPositionWeight + additionalWeight; ! return nonNormalizedWeightValue; ! } ! private double[] getNonNormalizedWeightValues( int[] weightRelatedGeneValues ) ! { ! double[] nonNormalizedWeightValues = new double[ weightRelatedGeneValues.Length ]; ! for ( int i = 0 ; i < weightRelatedGeneValues.Length ; i++ ) ! nonNormalizedWeightValues[ i ] = ! this.getNonNormalizedWeightValue( weightRelatedGeneValues[ i ] ); ! return nonNormalizedWeightValues; ! } ! private double getNormalizingFactor( double[] nonNormalizedWeightValues ) ! { ! // the absolute value for each nonNormalizedWeightValue is between ! // this.minimumPositionWeight and 1 ! double totalForNonNormalizedWeightValues = BasicFunctions.SumOfAbs( nonNormalizedWeightValues ); ! double normalizingFactor = 1 / totalForNonNormalizedWeightValues; ! return normalizingFactor; ! } ! private double[] getNormalizedWeightValues( double[] nonNormalizedWeightValues , ! double normalizingFactor ) ! { ! return BasicFunctions.MultiplyBy( nonNormalizedWeightValues , normalizingFactor ); ! } ! private double[] getNormalizedWeightValues( double[] nonNormalizedWeightValues ) ! { ! double normalizingFactor = this.getNormalizingFactor( nonNormalizedWeightValues ); ! return getNormalizedWeightValues( nonNormalizedWeightValues , normalizingFactor ); ! } ! private double[] getNormalizedWeightValues( int[] weightRelatedGeneValues ) ! { ! double[] nonNormalizedWeightValues = ! this.getNonNormalizedWeightValues( weightRelatedGeneValues ); ! return this.getNormalizedWeightValues( nonNormalizedWeightValues ); } #endregion ! private string[] decodeTickers( int[] tickerRelatedGeneValues , ! DataTable eligibleTickers ) { ! string[] tickers = new string[ tickerRelatedGeneValues.Length ]; ! for( int i = 0 ; i < tickerRelatedGeneValues.Length ; i++ ) { ! int currentGeneValue = tickerRelatedGeneValues[ i ]; ! tickers[ i ] = ! ( string )eligibleTickers.Rows[ currentGeneValue ][ 0 ]; } ! return tickers; ! } ! private WeightedPositions decodeWeightedPositions( int[] weightRelatedGeneValues , ! int[] tickerRelatedGeneValues , DataTable eligibleTickers ) ! { ! double[] normalizedWeightValues = this.getNormalizedWeightValues( weightRelatedGeneValues ); ! string[] tickers = this.decodeTickers( tickerRelatedGeneValues , eligibleTickers ); ! WeightedPositions weightedPositions = new WeightedPositions( ! normalizedWeightValues , tickers ); ! return weightedPositions; ! } ! #endregion ! private WeightedPositions decodeDrivingWeightedPositions( ! Genome genome ) ! { ! int[] weightRelatedGeneValuesForDrivingPositions = ! this.getWeightRelatedGeneValuesForDrivingPositions( genome ); ! int[] tickerRelatedGeneValuesForDrivingPositions = ! this.getTickerRelatedGeneValuesForDrivingPositions( genome ); ! return decodeWeightedPositions( ! weightRelatedGeneValuesForDrivingPositions , ! tickerRelatedGeneValuesForDrivingPositions , ! this.eligibleTickersForDrivingWeightedPositions ); ! // ! // double weight = this.decodeDrivingWeight( genome , geneIndex ); ! // string ticker = this.decodeDrivingTicker( genome , geneIndex ); ! // WeightedPosition weightedPosition = new WeightedPosition( ! // weight , ticker ); ! // wFLagWeightedPositions.DrivingWeightedPositions.AddWeightedPosition( ! // weightedPosition ); } + private WeightedPositions decodePortfolioWeightedPositions( + Genome genome ) + { + int[] weightRelatedGeneValuesForPortfolioPositions = + this.getWeightRelatedGeneValuesForPortfolioPositions( genome ); + int[] tickerRelatedGeneValuesForPortfolioPositions = + this.getTickerRelatedGeneValuesForPortfolioPositions( genome ); + return decodeWeightedPositions( + weightRelatedGeneValuesForPortfolioPositions , + tickerRelatedGeneValuesForPortfolioPositions , + this.eligibleTickersForPortfolioWeightedPositions ); + // + // double weight = this.decodeDrivingWeight( genome , geneIndex ); + // string ticker = this.decodeDrivingTicker( genome , geneIndex ); + // WeightedPosition weightedPosition = new WeightedPosition( + // weight , ticker ); + // wFLagWeightedPositions.DrivingWeightedPositions.AddWeightedPosition( + // weightedPosition ); + } + public virtual object Decode(Genome genome) + { + WeightedPositions drivingWeightedPositions = + this.decodeDrivingWeightedPositions( genome ); + WeightedPositions portfolioWeightedPositions = + this.decodePortfolioWeightedPositions( genome ); + WFLagWeightedPositions wFLagWeightedPositions = + new WFLagWeightedPositions( + drivingWeightedPositions , portfolioWeightedPositions ); + // int[] drivingGeneValues = this.getDrivingGeneValues( genome ); + // for ( int geneIndex = 0 ; geneIndex < this.numberOfDrivingPositions * 2 ; + // geneIndex += 2 ) + // this.decode_addDrivingPosition( genome , geneIndex , wFLagWeightedPositions ); + // for ( int geneIndex = this.numberOfDrivingPositions * 2 ; + // geneIndex < + // ( this.numberOfDrivingPositions + this.numberOfTickersInPortfolio ) * 2 ; + // geneIndex += 2 ) + // this.decode_addPortfolioPosition( genome , geneIndex , wFLagSignedTickers ); + // string[] arrayOfTickers = new string[genome.Genes().Length]; + // int indexOfTicker; + // for(int index = 0; index < genome.Genes().Length; index++) + // { + // indexOfTicker = (int)genome.Genes().GetValue(index); + // arrayOfTickers[index] = + // this.decode_getSignedTickerForGeneValue(indexOfTicker); + // } + return wFLagWeightedPositions; + } + #endregion + #region GetNewGeneValue + public int GetNewGeneValue( Genome genome , int genePosition ) + { + int minGeneValue = this.GetMinValueForGenes( genePosition ); + int maxGeneValue = this.GetMaxValueForGenes( genePosition ); + int returnValue = + GenomeManagement.RandomGenerator.Next( + minGeneValue , maxGeneValue + 1); + return returnValue; + } + #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-08-21 19:49:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv27666/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank Modified Files: WFMultiOneRankGenomeManager.cs Log Message: The private variable currentGeneticOptimizer was unused. It has been removed. Index: WFMultiOneRankGenomeManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank/WFMultiOneRankGenomeManager.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WFMultiOneRankGenomeManager.cs 8 Aug 2006 09:37:34 -0000 1.4 --- WFMultiOneRankGenomeManager.cs 21 Aug 2006 19:49:36 -0000 1.5 *************** *** 45,49 **** private int numberOfEligibleTickers; - private GeneticOptimizer currentGeneticOptimizer; private CandidateProperties[] setOfCandidates; --- 45,48 ---- |