quantproject-developers Mailing List for QuantProject (Page 98)
Brought to you by:
glauco_1
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(7) |
Nov
(103) |
Dec
(67) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(52) |
Feb
(9) |
Mar
(69) |
Apr
(53) |
May
(80) |
Jun
(23) |
Jul
(24) |
Aug
(112) |
Sep
(9) |
Oct
|
Nov
(58) |
Dec
(93) |
| 2005 |
Jan
(90) |
Feb
(93) |
Mar
(61) |
Apr
(56) |
May
(37) |
Jun
(61) |
Jul
(55) |
Aug
(68) |
Sep
(25) |
Oct
(46) |
Nov
(41) |
Dec
(37) |
| 2006 |
Jan
(33) |
Feb
(7) |
Mar
(19) |
Apr
(27) |
May
(73) |
Jun
(49) |
Jul
(83) |
Aug
(66) |
Sep
(45) |
Oct
(16) |
Nov
(15) |
Dec
(7) |
| 2007 |
Jan
(14) |
Feb
(33) |
Mar
|
Apr
(21) |
May
|
Jun
(34) |
Jul
(18) |
Aug
(100) |
Sep
(39) |
Oct
(55) |
Nov
(12) |
Dec
(2) |
| 2008 |
Jan
(120) |
Feb
(133) |
Mar
(129) |
Apr
(104) |
May
(42) |
Jun
(2) |
Jul
(52) |
Aug
(99) |
Sep
(134) |
Oct
|
Nov
(137) |
Dec
(48) |
| 2009 |
Jan
(48) |
Feb
(55) |
Mar
(61) |
Apr
(3) |
May
(2) |
Jun
(1) |
Jul
|
Aug
(51) |
Sep
|
Oct
(7) |
Nov
|
Dec
|
| 2010 |
Jan
(7) |
Feb
(1) |
Mar
(145) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
| 2011 |
Jan
(78) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(88) |
Sep
(6) |
Oct
(1) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Marco M. <mi...@us...> - 2005-11-08 18:32:33
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23226/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs Log Message: Changed IGenomeManager interface: added new parameters for the GetNewGeneValue method. Changed access modifier for some methods of GenomeManagerForEfficientPortfolio Updated Genome and GeneticOptimizer. Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** GenomeManagerForEfficientPortfolio.cs 23 Oct 2005 19:09:04 -0000 1.20 --- GenomeManagerForEfficientPortfolio.cs 8 Nov 2005 18:32:25 -0000 1.21 *************** *** 52,56 **** protected double targetPerformance; protected double variance; ! protected double lowerPartialMoment; protected double rateOfReturn; protected PortfolioType portfolioType; --- 52,56 ---- protected double targetPerformance; protected double variance; ! //protected double lowerPartialMoment; protected double rateOfReturn; protected PortfolioType portfolioType; *************** *** 224,228 **** #endregion ! public Genome[] GetChilds(Genome parent1, Genome parent2) { return --- 224,228 ---- #endregion ! public virtual Genome[] GetChilds(Genome parent1, Genome parent2) { return *************** *** 230,237 **** } ! public int GetNewGeneValue(Genome genome) { // in this implementation new gene values must be different from // the others already stored in the given genome int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); --- 230,239 ---- } ! public virtual int GetNewGeneValue(Genome genome, int genePosition) { // in this implementation new gene values must be different from // the others already stored in the given genome + // the generation of new genes doesn't depend on gene's position + // within the genome int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); *************** *** 247,251 **** } ! public void Mutate(Genome genome, double mutationRate) { // in this implementation only one gene is mutated --- 249,253 ---- } ! public virtual void Mutate(Genome genome, double mutationRate) { // in this implementation only one gene is mutated *************** *** 269,273 **** #region Decode ! private string decode_getTickerCodeForLongOrShortTrade(int geneValue) { string initialCharForTickerCode = ""; --- 271,275 ---- #region Decode ! protected string decode_getTickerCodeForLongOrShortTrade(int geneValue) { string initialCharForTickerCode = ""; *************** *** 355,364 **** { float[] returnValue = null; return returnValue; } #region getPortfolioRatesOfReturn ! private int getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(int geneValueForTickerIdx) { int position = geneValueForTickerIdx; --- 357,374 ---- { float[] returnValue = null; + this.numberOfExaminedReturns = returnValue.Length; return returnValue; + + } + + protected virtual double getTickerWeight(int[] genes, int tickerPositionInGenes) + { + return 1.0/genes.Length; + //weights for tickers are all the same in this implementation } #region getPortfolioRatesOfReturn ! protected int getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(int geneValueForTickerIdx) { int position = geneValueForTickerIdx; *************** *** 368,393 **** } ! private float getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(int tickerIdx, int arrayElementPosition) { bool longReturns = false; ! if(tickerIdx > 0) ! //the tickerIdx points to a ticker for which long returns are to be examined longReturns = true; ! int position = this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(tickerIdx); this.setOfCandidates[position].LongRatesOfReturn = longReturns; float[] arrayOfRatesOfReturn = this.setOfCandidates[position].ArrayOfRatesOfReturn; ! return (arrayOfRatesOfReturn[arrayElementPosition]/this.GenomeSize); ! //the investment is assumed to be equally divided for each ticker } ! protected double[] getPortfolioRatesOfReturn(int[] tickersIdx) { double[] returnValue = new double[this.numberOfExaminedReturns]; for(int i = 0; i<returnValue.Length; i++) { ! foreach(int tickerIdx in tickersIdx) returnValue[i] += ! this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(tickerIdx,i); } return returnValue; --- 378,404 ---- } ! protected float getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(int[] genes, ! int tickerPositionInGenes, int arrayElementPosition) { bool longReturns = false; ! if(genes[tickerPositionInGenes] > 0) ! //genes[tickerPositionInGenes], the code for ticker, points to a ticker for which long returns are to be examined longReturns = true; ! int position = this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(genes[tickerPositionInGenes]); this.setOfCandidates[position].LongRatesOfReturn = longReturns; float[] arrayOfRatesOfReturn = this.setOfCandidates[position].ArrayOfRatesOfReturn; ! double tickerWeight = this.getTickerWeight(genes,tickerPositionInGenes); ! return (arrayOfRatesOfReturn[arrayElementPosition]*(float)tickerWeight); } ! protected virtual double[] getPortfolioRatesOfReturn(int[] genes) { double[] returnValue = new double[this.numberOfExaminedReturns]; for(int i = 0; i<returnValue.Length; i++) { ! for(int j=0; j<genes.Length; j++) returnValue[i] += ! this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(genes,j,i); } return returnValue; |
|
From: Marco M. <mi...@us...> - 2005-11-08 18:32:33
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23226/b1_ADT/Optimizing/Genetic Modified Files: IGenomeManager.cs GenomeManagerTest.cs Genome.cs GeneticOptimizer.cs Log Message: Changed IGenomeManager interface: added new parameters for the GetNewGeneValue method. Changed access modifier for some methods of GenomeManagerForEfficientPortfolio Updated Genome and GeneticOptimizer. Index: Genome.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/Genome.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Genome.cs 18 Sep 2005 21:07:21 -0000 1.9 --- Genome.cs 8 Nov 2005 18:32:25 -0000 1.10 *************** *** 131,135 **** { for (int i = 0 ; i < this.size ; i++) ! this.genes[i] = this.genomeManager.GetNewGeneValue(this); //whenever at least one gene has been written, //the current generation number is stored --- 131,135 ---- { for (int i = 0 ; i < this.size ; i++) ! this.genes[i] = this.genomeManager.GetNewGeneValue(this,i); //whenever at least one gene has been written, //the current generation number is stored Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** GeneticOptimizer.cs 21 Oct 2005 18:15:47 -0000 1.12 --- GeneticOptimizer.cs 8 Nov 2005 18:32:25 -0000 1.13 *************** *** 480,487 **** { foreach(Genome g in populationOfGenomes) ! { ! //if(g != null) ! this.genomeManager.Mutate(g, this.MutationRate); ! } } --- 480,484 ---- { foreach(Genome g in populationOfGenomes) ! this.genomeManager.Mutate(g,this.MutationRate); } Index: GenomeManagerTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagerTest.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GenomeManagerTest.cs 31 Jul 2005 20:03:31 -0000 1.4 --- GenomeManagerTest.cs 8 Nov 2005 18:32:25 -0000 1.5 *************** *** 68,72 **** } ! public int GetNewGeneValue(Genome genome) { return GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, --- 68,72 ---- } ! public int GetNewGeneValue(Genome genome, int genePosition) { return GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, Index: IGenomeManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/IGenomeManager.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IGenomeManager.cs 31 Jul 2005 20:03:31 -0000 1.2 --- IGenomeManager.cs 8 Nov 2005 18:32:25 -0000 1.3 *************** *** 45,49 **** GeneticOptimizer CurrentGeneticOptimizer{get;set;} ! int GetNewGeneValue(Genome genome); // Used in generation of genes // by the Genome parameter double GetFitnessValue(Genome genome); --- 45,49 ---- GeneticOptimizer CurrentGeneticOptimizer{get;set;} ! int GetNewGeneValue(Genome genome, int genePosition); // Used in generation of genes // by the Genome parameter double GetFitnessValue(Genome genome); |
|
From: Marco M. <mi...@us...> - 2005-11-08 18:28:43
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22120/b7_Scripts/TickerSelectionTesting Modified Files: GenomeMeaning.cs Log Message: Added new property (of Array type) containing weights for Tickers (of Array type). Added new constructors. Index: GenomeMeaning.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeMeaning.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenomeMeaning.cs 23 Oct 2005 19:04:28 -0000 1.1 --- GenomeMeaning.cs 8 Nov 2005 18:28:30 -0000 1.2 *************** *** 22,32 **** using System; - using System.Data; - using System.Collections; - using QuantProject.ADT.Statistics; - using QuantProject.ADT.Optimizing.Genetic; - using QuantProject.Data; - using QuantProject.Data.DataTables; - using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios --- 22,25 ---- *************** *** 39,42 **** --- 32,36 ---- { private string[] tickers; + private double[] tickersPortfolioWeights; private double returnAtLastDayInSample; private double averageReturnInSample; *************** *** 62,69 **** get{return this.varianceReturnInSample;} } ! public GenomeMeaning(string[] tickers) { this.tickers = tickers; } --- 56,82 ---- get{return this.varianceReturnInSample;} } ! ! public double[] TickersPortfolioWeights ! { ! get{return this.tickersPortfolioWeights;} ! } ! ! private void setDefaultTickersPortfolioWeights() ! { ! this.tickersPortfolioWeights = new double[this.tickers.Length]; ! for(int i = 0;i<this.tickers.Length;i++) ! this.tickersPortfolioWeights[i]=1.0/this.tickers.Length; ! } ! public GenomeMeaning(string[] tickers) { this.tickers = tickers; + this.setDefaultTickersPortfolioWeights(); + } + + public GenomeMeaning(string[] tickers, double[] tickersPortfolioWeights) + { + this.tickers = tickers; + this.tickersPortfolioWeights = tickersPortfolioWeights; } *************** *** 77,82 **** --- 90,108 ---- this.averageReturnInSample = averageReturnInSample; this.varianceReturnInSample = varianceReturnInSample; + this.setDefaultTickersPortfolioWeights(); } + public GenomeMeaning(string[] tickers, + double[] tickersPortfolioWeights, + double returnAtLastDayInSample, + double averageReturnInSample, + double varianceReturnInSample) + { + this.tickers = tickers; + this.tickersPortfolioWeights = tickersPortfolioWeights; + this.returnAtLastDayInSample = returnAtLastDayInSample; + this.averageReturnInSample = averageReturnInSample; + this.varianceReturnInSample = varianceReturnInSample; + } } |
|
From: Marco M. <mi...@us...> - 2005-10-23 19:14:48
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27865 Removed Files: MeaningForGenome.cs Log Message: MeaningForGenome changed to GenomeMeaning --- MeaningForGenome.cs DELETED --- |
|
From: Marco M. <mi...@us...> - 2005-10-23 19:09:17
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26271/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest Modified Files: WalkForwardOpenToCloseDailyStrategy.cs Log Message: MeaningForGenome changed to GenomeMeaning Index: WalkForwardOpenToCloseDailyStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest/WalkForwardOpenToCloseDailyStrategy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WalkForwardOpenToCloseDailyStrategy.cs 21 Oct 2005 18:39:01 -0000 1.3 --- WalkForwardOpenToCloseDailyStrategy.cs 23 Oct 2005 19:09:03 -0000 1.4 *************** *** 208,212 **** this.signedTickersFromLastOptimization = ! ((MeaningForGenome)this.geneticOptimizer.BestGenome.Meaning).Tickers; this.addGenomeToBestGenomes( geneticOptimizer.BestGenome , optimizationFirstDate , optimizationLastDate ); --- 208,212 ---- this.signedTickersFromLastOptimization = ! ((GenomeMeaning)this.geneticOptimizer.BestGenome.Meaning).Tickers; this.addGenomeToBestGenomes( geneticOptimizer.BestGenome , optimizationFirstDate , optimizationLastDate ); |
|
From: Marco M. <mi...@us...> - 2005-10-23 19:09:16
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26271/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: GenomeRepresentation.cs Log Message: MeaningForGenome changed to GenomeMeaning Index: GenomeRepresentation.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/GenomeRepresentation.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GenomeRepresentation.cs 21 Oct 2005 18:14:04 -0000 1.3 --- GenomeRepresentation.cs 23 Oct 2005 19:09:04 -0000 1.4 *************** *** 94,98 **** { string signedTickers = ""; ! foreach ( string geneValue in ((MeaningForGenome)genome.Meaning).Tickers ) signedTickers += geneValue + ";"; signedTickers = signedTickers.Substring( 0 , --- 94,98 ---- { string signedTickers = ""; ! foreach ( string geneValue in ((GenomeMeaning)genome.Meaning).Tickers ) signedTickers += geneValue + ";"; signedTickers = signedTickers.Substring( 0 , |
|
From: Marco M. <mi...@us...> - 2005-10-23 19:09:16
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26271/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs EndOfDayTimerHandlerOTCMultiday.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandlerCTCWeekly.cs EndOfDayTimerHandlerCTC.cs Log Message: MeaningForGenome changed to GenomeMeaning Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** EndOfDayTimerHandlerCTO.cs 21 Oct 2005 18:18:08 -0000 1.19 --- EndOfDayTimerHandlerCTO.cs 23 Oct 2005 19:09:04 -0000 1.20 *************** *** 162,166 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((MeaningForGenome)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio --- 162,166 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** GenomeManagerForEfficientPortfolio.cs 21 Oct 2005 18:14:04 -0000 1.19 --- GenomeManagerForEfficientPortfolio.cs 23 Oct 2005 19:09:04 -0000 1.20 *************** *** 291,295 **** arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } ! MeaningForGenome meaning = new MeaningForGenome(arrayOfTickers, this.PortfolioRatesOfReturn[this.portfolioRatesOfReturn.Length - 1], this.RateOfReturn, --- 291,295 ---- arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } ! GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, this.PortfolioRatesOfReturn[this.portfolioRatesOfReturn.Length - 1], this.RateOfReturn, Index: EndOfDayTimerHandlerCTCWeekly.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCWeekly.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** EndOfDayTimerHandlerCTCWeekly.cs 21 Oct 2005 18:18:08 -0000 1.3 --- EndOfDayTimerHandlerCTCWeekly.cs 23 Oct 2005 19:09:04 -0000 1.4 *************** *** 152,156 **** //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.Run(false); ! this.chosenTickers = ((MeaningForGenome)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio --- 152,156 ---- //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.Run(false); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** EndOfDayTimerHandlerCTC.cs 21 Oct 2005 18:18:08 -0000 1.15 --- EndOfDayTimerHandlerCTC.cs 23 Oct 2005 19:09:04 -0000 1.16 *************** *** 177,181 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((MeaningForGenome)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio --- 177,181 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio Index: EndOfDayTimerHandlerOTCMultiday.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCMultiday.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerOTCMultiday.cs 21 Oct 2005 18:07:45 -0000 1.1 --- EndOfDayTimerHandlerOTCMultiday.cs 23 Oct 2005 19:09:04 -0000 1.2 *************** *** 137,150 **** { string[] returnValue = ! ((MeaningForGenome)genomeManager.CurrentGeneticOptimizer.BestGenome.Meaning).Tickers; int numOfGenomes = genomeManager.CurrentGeneticOptimizer.CurrentGeneration.Count; int i; for(i = 0;i<numOfGenomes; i++) { ! if(((MeaningForGenome)((Genome)genomeManager.CurrentGeneticOptimizer.CurrentGeneration[numOfGenomes - i - 1]).Meaning).ReturnAtLastDayInSample < 0) //the current portfolio has a negative return at the last day in sample { returnValue = ! ((MeaningForGenome)((Genome)genomeManager.CurrentGeneticOptimizer.CurrentGeneration[numOfGenomes - i - 1]).Meaning).Tickers; i = numOfGenomes; } --- 137,150 ---- { string[] returnValue = ! ((GenomeMeaning)genomeManager.CurrentGeneticOptimizer.BestGenome.Meaning).Tickers; int numOfGenomes = genomeManager.CurrentGeneticOptimizer.CurrentGeneration.Count; int i; for(i = 0;i<numOfGenomes; i++) { ! if(((GenomeMeaning)((Genome)genomeManager.CurrentGeneticOptimizer.CurrentGeneration[numOfGenomes - i - 1]).Meaning).ReturnAtLastDayInSample < 0) //the current portfolio has a negative return at the last day in sample { returnValue = ! ((GenomeMeaning)((Genome)genomeManager.CurrentGeneticOptimizer.CurrentGeneration[numOfGenomes - i - 1]).Meaning).Tickers; i = numOfGenomes; } |
|
From: Marco M. <mi...@us...> - 2005-10-23 19:05:54
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25277/EvaluatingOptimizationTechnique/EfficientPortfolio Modified Files: RunTestingOptimizationOpenToClose.cs Log Message: Updated script file Index: RunTestingOptimizationOpenToClose.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio/RunTestingOptimizationOpenToClose.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RunTestingOptimizationOpenToClose.cs 21 Oct 2005 18:18:08 -0000 1.4 --- RunTestingOptimizationOpenToClose.cs 23 Oct 2005 19:05:37 -0000 1.5 *************** *** 126,130 **** { double returnValue = 0; ! foreach(string tickerCode in ((MeaningForGenome)genome.Meaning).Tickers) { double coefficient = 1.0; --- 126,130 ---- { double returnValue = 0; ! foreach(string tickerCode in ((GenomeMeaning)genome.Meaning).Tickers) { double coefficient = 1.0; |
|
From: Marco M. <mi...@us...> - 2005-10-23 19:04:36
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25073/TickerSelectionTesting Added Files: GenomeMeaning.cs Log Message: MeaningForGenome changed to GenomeMeaning --- NEW FILE: GenomeMeaning.cs --- /* QuantProject - Quantitative Finance Library GenomeMeaning.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.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// This is the class representing the meaning for genome /// </summary> [Serializable] public class GenomeMeaning { private string[] tickers; private double returnAtLastDayInSample; private double averageReturnInSample; private double varianceReturnInSample; public string[] Tickers { get{return this.tickers;} } public double ReturnAtLastDayInSample { get{return this.returnAtLastDayInSample;} } public double AverageReturnInSample { get{return this.averageReturnInSample;} } public double VarianceReturnInSample { get{return this.varianceReturnInSample;} } public GenomeMeaning(string[] tickers) { this.tickers = tickers; } public GenomeMeaning(string[] tickers, double returnAtLastDayInSample, double averageReturnInSample, double varianceReturnInSample) { this.tickers = tickers; this.returnAtLastDayInSample = returnAtLastDayInSample; this.averageReturnInSample = averageReturnInSample; this.varianceReturnInSample = varianceReturnInSample; } } } |
|
From: Marco M. <mi...@us...> - 2005-10-23 19:04:36
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25073 Modified Files: b7_Scripts.csproj Log Message: MeaningForGenome changed to GenomeMeaning Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** b7_Scripts.csproj 21 Oct 2005 18:07:45 -0000 1.40 --- b7_Scripts.csproj 23 Oct 2005 19:04:29 -0000 1.41 *************** *** 249,253 **** /> <File ! RelPath = "TickerSelectionTesting\MeaningForGenome.cs" SubType = "Code" BuildAction = "Compile" --- 249,253 ---- /> <File ! RelPath = "TickerSelectionTesting\GenomeMeaning.cs" SubType = "Code" BuildAction = "Compile" |
|
From: Marco M. <mi...@us...> - 2005-10-23 18:11:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14144/b7_Scripts/TickerSelectionTesting/SimpleSelection Modified Files: BestTickersScreener.cs Log Message: Fixed bug Index: BestTickersScreener.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection/BestTickersScreener.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BestTickersScreener.cs 21 Oct 2005 22:16:50 -0000 1.2 --- BestTickersScreener.cs 23 Oct 2005 18:11:28 -0000 1.3 *************** *** 151,155 **** Array.Sort(allTickersShortOrLong); for(int t = 0; t<returnValue.Length; t++) ! returnValue[t] = allTickersShortOrLong[t].Ticker; } --- 151,155 ---- Array.Sort(allTickersShortOrLong); for(int t = 0; t<returnValue.Length; t++) ! returnValue[t] = allTickersShortOrLong[allTickersShortOrLong.Length - t -1].Ticker; } |
|
From: Marco M. <mi...@us...> - 2005-10-21 22:16:57
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10523/b7_Scripts/TickerSelectionTesting/SimpleSelection Modified Files: BestTickersScreener.cs Log Message: Fixed bug. Index: BestTickersScreener.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection/BestTickersScreener.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BestTickersScreener.cs 21 Oct 2005 17:54:11 -0000 1.1 --- BestTickersScreener.cs 21 Oct 2005 22:16:50 -0000 1.2 *************** *** 133,149 **** int numOfTickers = this.setOfCandidates.Length; this.setSetOfCandidates(true); ! for(int i = 0; i<numOfTickers; i++) allTickersShortOrLong[i] = new CandidateProperties(this.setOfCandidates[i].Ticker, ! this.setOfCandidates[i].ArrayOfRatesOfReturn); this.setSetOfCandidates(false); ! for(int i = numOfTickers; i<numOfTickers*2; i++) ! allTickersShortOrLong[i] = ! new CandidateProperties("-" + this.setOfCandidates[i].Ticker, ! this.setOfCandidates[i].ArrayOfRatesOfReturn); Array.Sort(allTickersShortOrLong); ! for(int i = 0; i<returnValue.Length; i++) ! returnValue[i] = allTickersShortOrLong[i].Ticker; } --- 133,155 ---- int numOfTickers = this.setOfCandidates.Length; this.setSetOfCandidates(true); ! int i = 0; ! for(; i<numOfTickers; i++) allTickersShortOrLong[i] = new CandidateProperties(this.setOfCandidates[i].Ticker, ! this.setOfCandidates[i].ArrayOfRatesOfReturn, ! this.setOfCandidates[i].Fitness); this.setSetOfCandidates(false); ! for(int j = 0; j<numOfTickers; j++) ! { ! allTickersShortOrLong[i] = ! new CandidateProperties("-" + this.setOfCandidates[j].Ticker, ! this.setOfCandidates[j].ArrayOfRatesOfReturn, ! this.setOfCandidates[j].Fitness); ! i++; ! } Array.Sort(allTickersShortOrLong); ! for(int t = 0; t<returnValue.Length; t++) ! returnValue[t] = allTickersShortOrLong[t].Ticker; } |
|
From: Marco M. <mi...@us...> - 2005-10-21 22:16:01
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10066/b7_Scripts/TickerSelectionTesting Modified Files: CandidateProperties.cs Log Message: Added new constructor to CandidateProperties class. Index: CandidateProperties.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/CandidateProperties.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CandidateProperties.cs 21 Oct 2005 18:25:01 -0000 1.2 --- CandidateProperties.cs 21 Oct 2005 22:15:53 -0000 1.3 *************** *** 40,51 **** protected double fitness; ! public CandidateProperties(string ticker, float[] arrayOfRatesOfReturn) { this.ticker = ticker; this.longRatesOfReturn = true; this.arrayOfRatesOfReturn = arrayOfRatesOfReturn; ! this.fitness = 0.0; } ! private float[] arrayOfRatesOfReturn_getOppositeArrayOfRatesOfReturn() { --- 40,58 ---- protected double fitness; ! public CandidateProperties(string ticker, float[] arrayOfRatesOfReturn): ! this(ticker,arrayOfRatesOfReturn,0.0) ! { ! ! } ! ! public CandidateProperties(string ticker, float[] arrayOfRatesOfReturn, ! double fitness) { this.ticker = ticker; this.longRatesOfReturn = true; this.arrayOfRatesOfReturn = arrayOfRatesOfReturn; ! this.fitness = fitness; } ! private float[] arrayOfRatesOfReturn_getOppositeArrayOfRatesOfReturn() { |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:39:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26486/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest Modified Files: WalkForwardOpenToCloseDailyStrategy.cs Log Message: Changed Decode implementation for GenomeManagerForEfficientPortfolio. Now Decode, used to assign Meaning to the Genome, return a MeaningForGenome Index: WalkForwardOpenToCloseDailyStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest/WalkForwardOpenToCloseDailyStrategy.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WalkForwardOpenToCloseDailyStrategy.cs 22 Aug 2005 22:27:07 -0000 1.2 --- WalkForwardOpenToCloseDailyStrategy.cs 21 Oct 2005 18:39:01 -0000 1.3 *************** *** 208,212 **** this.signedTickersFromLastOptimization = ! (string[])this.geneticOptimizer.BestGenome.Meaning; this.addGenomeToBestGenomes( geneticOptimizer.BestGenome , optimizationFirstDate , optimizationLastDate ); --- 208,212 ---- this.signedTickersFromLastOptimization = ! ((MeaningForGenome)this.geneticOptimizer.BestGenome.Meaning).Tickers; this.addGenomeToBestGenomes( geneticOptimizer.BestGenome , optimizationFirstDate , optimizationLastDate ); |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:26:51
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24577/b3_Data Modified Files: b3_Data.csproj Log Message: Modifications by VS .NET environment Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** b3_Data.csproj 18 Sep 2005 21:05:30 -0000 1.31 --- b3_Data.csproj 21 Oct 2005 18:26:43 -0000 1.32 *************** *** 144,148 **** <File RelPath = "ExtendedDataTable.cs" ! SubType = "Component" BuildAction = "Compile" /> --- 144,148 ---- <File RelPath = "ExtendedDataTable.cs" ! SubType = "Code" BuildAction = "Compile" /> |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:25:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24066/b7_Scripts/TickerSelectionTesting Modified Files: CandidateProperties.cs Log Message: Implemented IComparable interface through the new Fitness property. Members are now protected (and not private anymore), in order to be visible by inherited classes. Index: CandidateProperties.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/CandidateProperties.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CandidateProperties.cs 25 Jul 2005 22:24:09 -0000 1.1 --- CandidateProperties.cs 21 Oct 2005 18:25:01 -0000 1.2 *************** *** 29,42 **** /// <summary> /// This is the class containing basic information ! /// for each candidate to be evaluated in order ! /// to discover the efficient frontier /// </summary> [Serializable] ! public class CandidateProperties { ! private string ticker; ! private float[] arrayOfRatesOfReturn; ! private float[] oppositeArrayOfRatesOfReturn; ! private bool longRatesOfReturn; public CandidateProperties(string ticker, float[] arrayOfRatesOfReturn) --- 29,42 ---- /// <summary> /// This is the class containing basic information ! /// for each candidate to be evaluated /// </summary> [Serializable] ! public class CandidateProperties : IComparable { ! protected string ticker; ! protected float[] arrayOfRatesOfReturn; ! protected float[] oppositeArrayOfRatesOfReturn; ! protected bool longRatesOfReturn; ! protected double fitness; public CandidateProperties(string ticker, float[] arrayOfRatesOfReturn) *************** *** 45,48 **** --- 45,49 ---- this.longRatesOfReturn = true; this.arrayOfRatesOfReturn = arrayOfRatesOfReturn; + this.fitness = 0.0; } *************** *** 58,62 **** --- 59,76 ---- return this.oppositeArrayOfRatesOfReturn; } + //implementation of IComparable interface + public int CompareTo(object obj) + { + if(obj is CandidateProperties) + { + CandidateProperties candidate = (CandidateProperties)obj; + return this.Fitness.CompareTo(candidate.Fitness); + } + + throw new ArgumentException("Object is not of CandidateProperties type!"); + } + //end of implementation of IComparable interface + public float[] ArrayOfRatesOfReturn { *************** *** 80,84 **** get{return this.ticker;} } ! } --- 94,107 ---- get{return this.ticker;} } ! ! public virtual double Fitness ! { ! get{return this.fitness;} ! } ! ! public virtual void setFitness() ! { ! this.fitness = 0.0; ! } } |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:19:05
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22322/b4_Business Modified Files: Business.prjx Log Message: Updated #develop projects files. Index: Business.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business.prjx,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Business.prjx 18 Sep 2005 21:05:30 -0000 1.6 --- Business.prjx 21 Oct 2005 18:18:58 -0000 1.7 *************** *** 93,96 **** --- 93,98 ---- <File name=".\a2_Strategies\IEndOfDayStrategy.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\a1_Financial\a2_Accounting\h5_Reporting\SummaryRows\SharpeRatio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\a1_Financial\a2_Accounting\EquityLine.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\a1_Financial\a2_Accounting\PositionType.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:18:19
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22049/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandlerCTCWeekly.cs EndOfDayTimerHandlerCTO.cs Log Message: Updated some script files inside the TickerSelectionTesting namespace Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** EndOfDayTimerHandlerCTO.cs 18 Sep 2005 21:13:36 -0000 1.18 --- EndOfDayTimerHandlerCTO.cs 21 Oct 2005 18:18:08 -0000 1.19 *************** *** 162,166 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = (string[])GO.BestGenome.Meaning; } //else it will be buyed again the previous optimized portfolio --- 162,166 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((MeaningForGenome)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio Index: EndOfDayTimerHandlerCTCWeekly.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCWeekly.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerCTCWeekly.cs 18 Sep 2005 21:13:36 -0000 1.2 --- EndOfDayTimerHandlerCTCWeekly.cs 21 Oct 2005 18:18:08 -0000 1.3 *************** *** 152,156 **** //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.Run(false); ! this.chosenTickers = (string[])GO.BestGenome.Meaning; } //else it will be buyed again the previous optimized portfolio --- 152,156 ---- //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.Run(false); ! this.chosenTickers = ((MeaningForGenome)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** EndOfDayTimerHandlerCTC.cs 18 Sep 2005 21:13:36 -0000 1.14 --- EndOfDayTimerHandlerCTC.cs 21 Oct 2005 18:18:08 -0000 1.15 *************** *** 177,181 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = (string[])GO.BestGenome.Meaning; } //else it will be buyed again the previous optimized portfolio --- 177,181 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((MeaningForGenome)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:18:16
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22049/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio Modified Files: RunTestingOptimizationOpenToClose.cs Log Message: Updated some script files inside the TickerSelectionTesting namespace Index: RunTestingOptimizationOpenToClose.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio/RunTestingOptimizationOpenToClose.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunTestingOptimizationOpenToClose.cs 27 Sep 2005 22:26:02 -0000 1.3 --- RunTestingOptimizationOpenToClose.cs 21 Oct 2005 18:18:08 -0000 1.4 *************** *** 126,130 **** { double returnValue = 0; ! foreach(string tickerCode in (string[])genome.Meaning) { double coefficient = 1.0; --- 126,130 ---- { double returnValue = 0; ! foreach(string tickerCode in ((MeaningForGenome)genome.Meaning).Tickers) { double coefficient = 1.0; |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:16:01
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21410/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: Fixed minor bug in GeneticOptimizer Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GeneticOptimizer.cs 21 Aug 2005 10:07:36 -0000 1.11 --- GeneticOptimizer.cs 21 Oct 2005 18:15:47 -0000 1.12 *************** *** 401,406 **** Genome g = new Genome(this.genomeManager); g.CreateGenes(); - g.AssignMeaning(); g.CalculateFitness(); this.currentGeneration.Add(g); } --- 401,406 ---- Genome g = new Genome(this.genomeManager); g.CreateGenes(); g.CalculateFitness(); + g.AssignMeaning(); this.currentGeneration.Add(g); } |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:14:12
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20797/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs Added Files: MeaningForGenome.cs Log Message: Added MeaningForGenome class, to be used inside the TickerSelectionTesting namespace. Decode implementation in GenomeManagerForEfficientPortfolio (and so the Meaning property for the correlated Genome) has been changed. --- NEW FILE: MeaningForGenome.cs --- /* QuantProject - Quantitative Finance Library MeaningForGenome.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.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// This is the class representing the meaning for genome /// </summary> [Serializable] public class MeaningForGenome { private string[] tickers; private double returnAtLastDayInSample; private double averageReturnInSample; private double varianceReturnInSample; public string[] Tickers { get{return this.tickers;} } public double ReturnAtLastDayInSample { get{return this.returnAtLastDayInSample;} } public double AverageReturnInSample { get{return this.averageReturnInSample;} } public double VarianceReturnInSample { get{return this.varianceReturnInSample;} } public MeaningForGenome(string[] tickers) { this.tickers = tickers; } public MeaningForGenome(string[] tickers, double returnAtLastDayInSample, double averageReturnInSample, double varianceReturnInSample) { this.tickers = tickers; this.returnAtLastDayInSample = returnAtLastDayInSample; this.averageReturnInSample = averageReturnInSample; this.varianceReturnInSample = varianceReturnInSample; } } } Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** GenomeManagerForEfficientPortfolio.cs 10 Aug 2005 16:47:59 -0000 1.18 --- GenomeManagerForEfficientPortfolio.cs 21 Oct 2005 18:14:04 -0000 1.19 *************** *** 105,108 **** --- 105,112 ---- set{this.currentGeneticOptimizer = value;} } + public double[] PortfolioRatesOfReturn + { + get{return this.portfolioRatesOfReturn;} + } //setOfInitialTickers has to contain the *************** *** 279,283 **** public virtual object Decode(Genome genome) { ! string[] arrayOfTickers = new string[genome.Genes().Length]; int indexOfTicker; for(int index = 0; index < genome.Genes().Length; index++) --- 283,288 ---- public virtual object Decode(Genome genome) { ! ! string[] arrayOfTickers = new string[genome.Genes().Length]; int indexOfTicker; for(int index = 0; index < genome.Genes().Length; index++) *************** *** 286,290 **** arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } ! return arrayOfTickers; } --- 291,299 ---- arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } ! MeaningForGenome meaning = new MeaningForGenome(arrayOfTickers, ! this.PortfolioRatesOfReturn[this.portfolioRatesOfReturn.Length - 1], ! this.RateOfReturn, ! this.Variance); ! return meaning; } |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:14:12
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20797/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: GenomeRepresentation.cs Log Message: Added MeaningForGenome class, to be used inside the TickerSelectionTesting namespace. Decode implementation in GenomeManagerForEfficientPortfolio (and so the Meaning property for the correlated Genome) has been changed. Index: GenomeRepresentation.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/GenomeRepresentation.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeRepresentation.cs 29 Jul 2005 13:36:28 -0000 1.2 --- GenomeRepresentation.cs 21 Oct 2005 18:14:04 -0000 1.3 *************** *** 25,28 **** --- 25,29 ---- using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Financial.Ordering; + using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination *************** *** 93,97 **** { string signedTickers = ""; ! foreach ( string geneValue in (string[])genome.Meaning ) signedTickers += geneValue + ";"; signedTickers = signedTickers.Substring( 0 , --- 94,98 ---- { string signedTickers = ""; ! foreach ( string geneValue in ((MeaningForGenome)genome.Meaning).Tickers ) signedTickers += geneValue + ";"; signedTickers = signedTickers.Substring( 0 , |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18615/b7_Scripts/TickerSelectionTesting Added Files: EndOfDayTimerHandlerOTCCTO.cs EndOfDayTimerHandlerOTCMultiday.cs RunEfficientOTCCTOPortfolio.cs RunEfficientOTCPortfolioMultiday.cs Log Message: Added: - SimpleSelection script; - Open To Close combined with Close to Open; - Open To Close multiday --- NEW FILE: EndOfDayTimerHandlerOTCCTO.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerOTCCTO.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.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.ADT.Optimizing.Genetic; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Implements MarketOpenEventHandler, /// TwoMinutesBeforeMarketCloseEventHandler and OneHourAfterMarketCloseEventHandler /// These handlers contain the core strategy for the efficient close to open portfolio! /// </summary> [Serializable] public class EndOfDayTimerHandlerOTCCTO : EndOfDayTimerHandler { protected int numDaysBetweenEachOptimization; private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; public EndOfDayTimerHandlerOTCCTO(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, double targetReturn, PortfolioType portfolioType, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, targetReturn, portfolioType) { this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.numDaysElapsedSinceLastOptimization = 0; this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; } /// <summary> /// Handles a "Market Open" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public override void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //temporarily the if condition //if(this.numDaysElapsedSinceLastOptimization == 0) this.closePositions(); this.openPositions(); } private void reverseSignOfChosenTickers() { for(int i = 0; i<this.chosenTickers.Length; i++) { if(this.chosenTickers[i] != null) { if(this.chosenTickers[i].StartsWith("-")) this.chosenTickers[i] = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[i]); else this.chosenTickers[i] = "-" + this.chosenTickers[i]; } } } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //temporarily //if(this.numDaysElapsedSinceLastOptimization == // this.numDaysBetweenEachOptimization) this.closePositions(); this.orders.Clear(); this.reverseSignOfChosenTickers(); this.openPositions(); } #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { /* SelectorByAverageRawOpenPrice selectorByOpenPrice = new SelectorByAverageRawOpenPrice(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers, this.minPriceForMinimumCommission, this.maxPriceForMinimumCommission, 0, 2); DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromTemporizedGroup = new SelectorByOpenCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), this.benchmark,true, currentDate.AddDays(-this.numDaysForOptimizationPeriod ), currentDate, this.numberOfEligibleTickers); this.eligibleTickers = lessCorrelatedFromTemporizedGroup.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), // false, currentDate.AddDays(-2), // currentDate, this.numberOfEligibleTickers/4); //return winners.GetTableOfSelectedTickers(); //SelectorByOpenCloseCorrelationToBenchmark lessCorrelated = // new SelectorByOpenCloseCorrelationToBenchmark(quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(), // this.benchmark, true, // currentDate.AddDays(-this.numDaysForLiquidity), // currentDate, this.numberOfEligibleTickers/2); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); //return lessCorrelated.GetTableOfSelectedTickers(); } 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 possible only if the initial set of tickers is //as large as the number of tickers to be chosen { IGenomeManager genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfTickersToBeChosen, this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, this.seedForRandomGenerator); if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); GO.Run(false); this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); this.chosenTickers = (string[])GO.BestGenome.Meaning; } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member } protected void oneHourAfterMarketCloseEventHandler_updatePrices() { //min price for minimizing commission amount //according to IB Broker's commission scheme this.minPriceForMinimumCommission = this.account.CashAmount/(this.numberOfTickersToBeChosen*100); this.maxPriceForMinimumCommission = this.maxPriceForMinimumCommission; //just to avoid warning message } /// <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.seedForRandomGenerator++; this.orders.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; } else { this.numDaysElapsedSinceLastOptimization++; } } #endregion } } --- NEW FILE: RunEfficientOTCPortfolioMultiday.cs --- /* QuantProject - Quantitative Finance Library RunEfficientOTCPorfolioMultiday.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.ADT.FileManaging; 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.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// The efficient portfolio's generation rules /// (contained in the EndOfDayTimerHandler) are: /// - choose the most liquid tickers; /// - choose the most efficient portfolio among these tickers /// </summary> [Serializable] public class RunEfficientOTCPortfolioMultiday : RunEfficientPortfolio { protected int numDaysBetweenEachOptimization; public RunEfficientOTCPortfolioMultiday(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, PortfolioType portfolioType, double maxRunningHours, int numDaysPortfolioLife): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, portfolioType, maxRunningHours) { this.ScriptName = "MultidayOpenCloseScripts"; this.numDaysBetweenEachOptimization = numDaysPortfolioLife; } #region auxiliary overriden methods for Run /* delete remark delimitations for having ib commission protected override void run_initializeAccount() { this.account = new Account( this.ScriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , this.historicalQuoteProvider ), new IBCommissionManager()); } */ protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCMultiday(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.targetReturn, this.portfolioType, this.numDaysBetweenEachOptimization); } protected override void run_initializeHistoricalQuoteProvider() { //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.endOfDayTimerHandler.MarketOpenEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.endOfDayTimerHandler.MarketCloseEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.checkDateForReport); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); } #endregion //necessary far calling RunEfficientPortfolio.Run() //in classes that inherit from this class public override void Run() { base.Run(); } } } --- NEW FILE: EndOfDayTimerHandlerOTCMultiday.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerOTCMultiday.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.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.ADT.Optimizing.Genetic; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Implements MarketOpenEventHandler, /// TwoMinutesBeforeMarketCloseEventHandler and OneHourAfterMarketCloseEventHandler /// These handlers contain the core strategy for the efficient close to open portfolio! /// </summary> [Serializable] public class EndOfDayTimerHandlerOTCMultiday : EndOfDayTimerHandler { protected int numDaysBetweenEachOptimization; private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; public EndOfDayTimerHandlerOTCMultiday(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, double targetReturn, PortfolioType portfolioType, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, targetReturn, portfolioType) { this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.numDaysElapsedSinceLastOptimization = 0; this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; } /// <summary> /// Handles a "Market Open" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public override void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.numDaysElapsedSinceLastOptimization == 0) this.openPositions(); } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) this.closePositions(); } #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { /* SelectorByAverageRawOpenPrice selectorByOpenPrice = new SelectorByAverageRawOpenPrice(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers, this.minPriceForMinimumCommission, this.maxPriceForMinimumCommission, 0, 2); DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromTemporizedGroup = new SelectorByOpenCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), this.benchmark,true, currentDate.AddDays(-this.numDaysForOptimizationPeriod ), currentDate, this.numberOfEligibleTickers); this.eligibleTickers = lessCorrelatedFromTemporizedGroup.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), // false, currentDate.AddDays(-2), // currentDate, this.numberOfEligibleTickers/4); //return winners.GetTableOfSelectedTickers(); //SelectorByOpenCloseCorrelationToBenchmark lessCorrelated = // new SelectorByOpenCloseCorrelationToBenchmark(quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(), // this.benchmark, true, // currentDate.AddDays(-this.numDaysForLiquidity), // currentDate, this.numberOfEligibleTickers/2); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); //return lessCorrelated.GetTableOfSelectedTickers(); } private string[] setTickers_getBestTickersLosingAtLastDay(IGenomeManager genomeManager) { string[] returnValue = ((MeaningForGenome)genomeManager.CurrentGeneticOptimizer.BestGenome.Meaning).Tickers; int numOfGenomes = genomeManager.CurrentGeneticOptimizer.CurrentGeneration.Count; int i; for(i = 0;i<numOfGenomes; i++) { if(((MeaningForGenome)((Genome)genomeManager.CurrentGeneticOptimizer.CurrentGeneration[numOfGenomes - i - 1]).Meaning).ReturnAtLastDayInSample < 0) //the current portfolio has a negative return at the last day in sample { returnValue = ((MeaningForGenome)((Genome)genomeManager.CurrentGeneticOptimizer.CurrentGeneration[numOfGenomes - i - 1]).Meaning).Tickers; i = numOfGenomes; } } return returnValue; } 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 possible only if the initial set of tickers is //as large as the number of tickers to be chosen { IGenomeManager genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfTickersToBeChosen, this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, this.seedForRandomGenerator); if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); GO.Run(false); this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); //this.chosenTickers = ((MeaningForGenome)GO.BestGenome.Meaning).Tickers; this.chosenTickers = this.setTickers_getBestTickersLosingAtLastDay(genManEfficientCTOPortfolio); } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member } protected void oneHourAfterMarketCloseEventHandler_updatePrices() { //min price for minimizing commission amount //according to IB Broker's commission scheme this.minPriceForMinimumCommission = this.account.CashAmount/(this.numberOfTickersToBeChosen*100); this.maxPriceForMinimumCommission = this.maxPriceForMinimumCommission; //just to avoid warning message } /// <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.seedForRandomGenerator++; this.orders.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; } else { this.numDaysElapsedSinceLastOptimization++; } } #endregion } } --- NEW FILE: RunEfficientOTCCTOPortfolio.cs --- /* QuantProject - Quantitative Finance Library RunEfficientOTCCTOPorfolio.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.ADT.FileManaging; 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.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Script to buy at open and sell at close /// the efficient close to open daily portfolio /// The efficient portfolio's generation rules /// (contained in the EndOfDayTimerHandler) are: /// - choose the most liquid tickers; /// - choose the most efficient portfolio among these tickers /// </summary> [Serializable] public class RunEfficientOTCCTOPortfolio : RunEfficientPortfolio { protected int numDaysBetweenEachOptimization; public RunEfficientOTCCTOPortfolio(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, PortfolioType portfolioType, double maxRunningHours, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, portfolioType, maxRunningHours) { this.ScriptName = "OpenToClose_CloseToOpenScripts"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } #region auxiliary overriden methods for Run /* delete remark delimitations for having ib commission protected override void run_initializeAccount() { this.account = new Account( this.ScriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , this.historicalQuoteProvider ), new IBCommissionManager()); } */ protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTCCTO(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.targetReturn, this.portfolioType, this.numDaysBetweenEachOptimization); } protected override void run_initializeHistoricalQuoteProvider() { //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.endOfDayTimerHandler.MarketOpenEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.endOfDayTimerHandler.MarketCloseEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.checkDateForReport); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); } #endregion //necessary far calling RunEfficientPortfolio.Run() //in classes that inherit from this class public override void Run() { base.Run(); } } } |
|
From: Marco M. <mi...@us...> - 2005-10-21 18:08:00
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18615/b7_Scripts Modified Files: Scripts.prjx b7_Scripts.csproj Log Message: Added: - SimpleSelection script; - Open To Close combined with Close to Open; - Open To Close multiday Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** b7_Scripts.csproj 15 Oct 2005 18:02:27 -0000 1.39 --- b7_Scripts.csproj 21 Oct 2005 18:07:45 -0000 1.40 *************** *** 219,222 **** --- 219,232 ---- /> <File + RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerOTCCTO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerOTCMultiday.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\GenomeManagerForEfficientCTCPortfolio.cs" SubType = "Code" *************** *** 239,242 **** --- 249,257 ---- /> <File + RelPath = "TickerSelectionTesting\MeaningForGenome.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\PortfolioType.cs" SubType = "Code" *************** *** 264,267 **** --- 279,292 ---- /> <File + RelPath = "TickerSelectionTesting\RunEfficientOTCCTOPortfolio.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TickerSelectionTesting\RunEfficientOTCPortfolioMultiday.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\RunEfficientPortfolio.cs" SubType = "Code" *************** *** 284,287 **** --- 309,347 ---- /> <File + RelPath = "TickerSelectionTesting\SimpleSelection\BestTickersScreener.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TickerSelectionTesting\SimpleSelection\BestTickersScreenerOpenToClose.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TickerSelectionTesting\SimpleSelection\CandidatePropertiesForSimpleSelection.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TickerSelectionTesting\SimpleSelection\EndOfDayTimerHandlerSimpleSelection.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TickerSelectionTesting\SimpleSelection\EndOfDayTimerHandlerSimpleSelectionOpenToClose.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TickerSelectionTesting\SimpleSelection\RunSimpleSelection.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TickerSelectionTesting\SimpleSelection\RunSimpleSelectionOpenToClose.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\GenomeRepresentation.cs" SubType = "Code" Index: Scripts.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts.prjx,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Scripts.prjx 27 Sep 2005 22:32:40 -0000 1.13 --- Scripts.prjx 21 Oct 2005 18:07:45 -0000 1.14 *************** *** 23,27 **** <File name=".\WalkForwardTesting\WalkForwardOneRank\ComparableAccount.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\WalkForwardTesting\WalkForwardOneRank\EligibleTickers.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\WalkForwardTesting\WalkForwardOneRank\EndOfDayTimerHandler.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\WalkForwardTesting\WalkForwardOneRank\ProgressBarForm.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\WalkForwardTesting\WalkForwardOneRank\RunWalkForwardOneRank.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> --- 23,26 ---- *************** *** 58,61 **** --- 57,74 ---- <File name=".\TickerSelectionTesting\EndOfDayTimerHandlerCTOMultiAccount.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\TickerSelectionTesting\RunEfficientCTOPortfolioMultiAccount.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\EndOfDayTimerHandlerOTCCTO.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\RunEfficientOTCCTOPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\RunEfficientOTCPortfolioMultiday.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\EndOfDayTimerHandlerOTCMultiday.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\SimpleSelection" subtype="Directory" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\SimpleSelection\RunSimpleSelectionOpenToClose.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\SimpleSelection\BestTickersScreener.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\SimpleSelection\BestTickersScreenerOpenToClose.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\SimpleSelection\CandidatePropertiesForSimpleSelection.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\SimpleSelection\EndOfDayTimerHandlerSimpleSelection.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\SimpleSelection\EndOfDayTimerHandlerSimpleSelectionOpenToClose.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\SimpleSelection\RunSimpleSelection.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\WalkForwardTesting\WalkForwardOneRank\MyEndOfDayTimerHandler.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\MeaningForGenome.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-10-21 17:54:22
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/SimpleSelection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15209 Added Files: RunSimpleSelectionOpenToClose.cs RunSimpleSelection.cs EndOfDayTimerHandlerSimpleSelectionOpenToClose.cs EndOfDayTimerHandlerSimpleSelection.cs CandidatePropertiesForSimpleSelection.cs BestTickersScreenerOpenToClose.cs BestTickersScreener.cs Log Message: Added files for SimpleSelection script --- NEW FILE: EndOfDayTimerHandlerSimpleSelection.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerSimpleSelection.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.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.SimpleSelection { /// <summary> /// Base class for EndOfDayTimerHandlers for simple selection /// </summary> [Serializable] public class EndOfDayTimerHandlerSimpleSelection { protected DataTable eligibleTickers; protected string[] chosenTickers; protected string[] lastOrderedTickers; protected string tickerGroupID; protected int numberOfEligibleTickers; protected int numberOfTickersToBeChosen; protected int numDaysForOptimizationPeriod; protected Account account; protected ArrayList orders; protected string benchmark; //these two values have to be updated during //backtest, for minimizing commission amount, //according to broker's commission scheme protected double minPriceForMinimumCommission = 0; protected double maxPriceForMinimumCommission = 500; protected double targetReturn; protected PortfolioType portfolioType; public string[] LastOrderedTickers { get { return this.lastOrderedTickers; } } public int NumberOfEligibleTickers { get { return this.numberOfEligibleTickers; } } public Account Account { get { return this.account; } } public EndOfDayTimerHandlerSimpleSelection(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, string benchmark, double targetReturn, PortfolioType portfolioType) { this.tickerGroupID = tickerGroupID; this.numberOfEligibleTickers = numberOfEligibleTickers; this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; this.numDaysForOptimizationPeriod = numDaysForOptimizationPeriod; this.account = account; this.benchmark = benchmark; this.orders = new ArrayList(); this.chosenTickers = new string[numberOfTickersToBeChosen]; this.lastOrderedTickers = new string[numberOfTickersToBeChosen]; this.targetReturn = targetReturn; this.portfolioType = portfolioType; } protected virtual void addOrderForTicker(string ticker ) { string tickerCode = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); double cashForSinglePosition = this.account.CashAmount / this.numberOfTickersToBeChosen; long quantity = Convert.ToInt64( Math.Floor( cashForSinglePosition / this.account.DataStreamer.GetCurrentBid( tickerCode ) ) ); Order order; if(this.portfolioType == PortfolioType.OnlyShort || (this.portfolioType == PortfolioType.ShortAndLong && ticker != tickerCode)) order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); else order = new Order( OrderType.MarketBuy, new Instrument( tickerCode ) , quantity ); this.orders.Add(order); } protected virtual void closePosition( string ticker ) { this.account.ClosePosition( ticker ); } protected virtual void closePositions() { if(this.lastOrderedTickers != null) { foreach( string ticker in this.lastOrderedTickers) { for(int i = 0; i<this.account.Portfolio.Keys.Count; i++) { if(this.account.Portfolio[ticker]!=null) closePosition( ticker ); } } } } protected virtual void addChosenTickersToOrderList() { int idx = 0; foreach ( string ticker in this.chosenTickers ) { if(ticker != null) { this.addOrderForTicker( ticker ); this.lastOrderedTickers[idx] = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); } idx++; } } protected bool openPositions_allChosenTickersQuotedAtCurrentDate() { bool returnValue = true; DateTime currentDate = this.Account.EndOfDayTimer.GetCurrentTime().DateTime; foreach(string ticker in this.chosenTickers) { if(ticker != null) { Quotes tickerQuotes = new Quotes(GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker), currentDate, currentDate); if(tickerQuotes.Rows.Count == 0) //no quote available for the current ticker returnValue = false; } } return returnValue; } protected virtual void openPositions() { //add cash first if(this.orders.Count == 0 && this.account.Transactions.Count == 0) this.account.AddCash(17000); if(this.openPositions_allChosenTickersQuotedAtCurrentDate()) //all tickers have quotes at the current date, so orders can be filled { this.addChosenTickersToOrderList(); //execute orders actually foreach(object item in this.orders) this.account.AddOrder((Order)item); } } public virtual void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } public virtual void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } public virtual void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } } // end of class } --- NEW FILE: BestTickersScreenerOpenToClose.cs --- /* QuantProject - Quantitative Finance Library BestTickersScreenerOpenToClose.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.Statistics; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.SimpleSelection { /// <summary> /// Class for tickers' selection without combination /// Open to close /// </summary> [Serializable] public class BestTickersScreenerOpenToClose : BestTickersScreener { public BestTickersScreenerOpenToClose(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, double targetPerformance, PortfolioType portfolioType): base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, targetPerformance, portfolioType) { this.retrieveData(); } protected override float[] getArrayOfRatesOfReturn(string ticker) { Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); return ExtendedDataTable.GetRatesOfReturnsFromColumns(tickerQuotes, "quClose", "quOpen"); } } } --- NEW FILE: CandidatePropertiesForSimpleSelection.cs --- /* QuantProject - Quantitative Finance Library CandidatePropertiesForSimpleSelection.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.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.ADT.Statistics; namespace QuantProject.Scripts.TickerSelectionTesting.SimpleSelection { /// <summary> /// This is the class containing basic information /// for each candidate to be evaluated for the simple selection script /// </summary> [Serializable] public class CandidatePropertiesForSimpleSelection : CandidateProperties { private double targetPerformance; public CandidatePropertiesForSimpleSelection(string ticker, float[] arrayOfRatesOfReturn, double targetPerformance): base(ticker, arrayOfRatesOfReturn) { this.targetPerformance = targetPerformance; } public override void setFitness() { NormalDistribution normal = new NormalDistribution(BasicFunctions.SimpleAverage(this.ArrayOfRatesOfReturn), BasicFunctions.StdDev(this.ArrayOfRatesOfReturn)); this.fitness = 1-normal.GetProbability(this.targetPerformance); } } } --- NEW FILE: RunSimpleSelection.cs --- /* QuantProject - Quantitative Finance Library RunSimpleSelection.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.IO; using System.Collections; using System.Data; using System.Windows.Forms; using QuantProject.ADT; using QuantProject.ADT.FileManaging; 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.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.TickerSelectionTesting.SimpleSelection { /// <summary> /// Base class for simple selection test /// The strategy simply chooses the tickers with the highest fitness, /// for short or long trading /// </summary> [Serializable] public class RunSimpleSelection { protected string tickerGroupID; protected int numberOfEligibleTickers; protected int numberOfTickersToBeChosen; protected int numDaysForOptimizationPeriod; protected ReportTable reportTable; protected EndOfDayDateTime startDateTime; protected EndOfDayDateTime endDateTime; protected IHistoricalQuoteProvider historicalQuoteProvider; protected EndOfDayTimerHandlerSimpleSelection endOfDayTimerHandler; protected Account account; protected IEndOfDayTimer endOfDayTimer; protected string benchmark; protected string scriptName; protected double targetReturn; protected PortfolioType portfolioType; protected DateTime startingTimeForScript; protected double maxRunningHours; //if MaxNumberOfHoursForScript has elapsed and the script //is still running, it will be stopped. public string[] LastOrderedTickers { get { return this.endOfDayTimerHandler.LastOrderedTickers; } } public PortfolioType TypeOfPortfolio { get { return this.portfolioType; } } public virtual string ScriptName { get{return this.scriptName;} set{this.scriptName = value;} } public DateTime TimerLastDate { get{return this.endOfDayTimer.GetCurrentTime().DateTime ;} } public RunSimpleSelection(string benchmark, DateTime startDate, DateTime endDate, PortfolioType portfolioType, double maxRunningHours) { this.startDateTime = new EndOfDayDateTime( startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); this.endDateTime = new EndOfDayDateTime( endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "SimpleTestGeneric"; this.portfolioType = portfolioType; this.startingTimeForScript = DateTime.Now; this.maxRunningHours = maxRunningHours; //this.numIntervalDays = 3; } public RunSimpleSelection(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, PortfolioType portfolioType, double maxRunningHours) { //this.progressBarForm = new ProgressBarForm(); this.tickerGroupID = tickerGroupID; this.numberOfEligibleTickers = numberOfEligibleTickers; this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; this.numDaysForOptimizationPeriod = numDaysForOptimizationPeriod; this.reportTable = new ReportTable( "Summary_Reports" ); this.startDateTime = new EndOfDayDateTime( startDate, EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); this.endDateTime = new EndOfDayDateTime( endDate, EndOfDaySpecificTime.OneHourAfterMarketClose ); this.benchmark = benchmark; this.ScriptName = "SimpleTestGeneric"; this.targetReturn = targetReturn; this.portfolioType = portfolioType; this.startingTimeForScript = DateTime.Now; this.maxRunningHours = maxRunningHours; //this.numIntervalDays = 3; } #region Run protected virtual void run_initializeEndOfDayTimer() { //default endOfDayTimer this.endOfDayTimer = new IndexBasedEndOfDayTimer( this.startDateTime, this.benchmark ); } protected virtual void run_initializeAccount() { //default account with no commissions this.account = new Account( this.scriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , this.historicalQuoteProvider )); } protected virtual void run_initializeEndOfDayTimerHandler() { //always needs specific implementation in inherited classes; } protected virtual void run_initializeHistoricalQuoteProvider() { //always needs specific implementation in inherited classes; } protected void checkDateForReport_createDirIfNotPresent(string dirPath) { if(!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath); } protected virtual void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || DateTime.Now >= this.startingTimeForScript.AddHours(this.maxRunningHours)) //last date is reached by the timer or maxRunning hours //are elapsed from the time script started this.SaveScriptResults(); } public virtual void SaveScriptResults() { string fileName = "SimpleSelectionFrom"+this.numberOfEligibleTickers + "OptDays" + this.numDaysForOptimizationPeriod + "Portfolio" + this.numberOfTickersToBeChosen + "Target" + Convert.ToString(this.targetReturn) + Convert.ToString(this.portfolioType); string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; //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.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ObjectArchiver.Archive(this.account.Transactions, dirNameWhereToSaveTransactions + fileName + ".qPt"); // this.endOfDayTimer.Stop(); } protected virtual void run_initialize() { run_initializeHistoricalQuoteProvider(); run_initializeEndOfDayTimer(); run_initializeAccount(); run_initializeEndOfDayTimerHandler(); //run_initializeProgressHandlers(); } protected virtual void run_addEventHandlers() { this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.checkDateForReport); //in inherited classes'override method: //add here TimerHandler's handlers to timer's events //example //this.endOfDayTimer.EVENT_NAME += // new EVENT_NAMEEventHandler( // this.endOfDayTimerHandler.EVENT_NAMEEventHandler); } public virtual void Run() { this.run_initialize(); this.run_addEventHandlers(); //this.progressBarForm.Show(); this.endOfDayTimer.Start(); } #endregion } } --- NEW FILE: BestTickersScreener.cs --- /* QuantProject - Quantitative Finance Library BestTickersScreener.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.Statistics; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.SimpleSelection { /// <summary> /// Base class for tickers' selection without combination /// </summary> [Serializable] public class BestTickersScreener { protected DataTable setOfTickers;//used only for keeping //the same signature for //protected retrieveData() method protected CandidatePropertiesForSimpleSelection[] setOfCandidates; protected DateTime firstQuoteDate; protected DateTime lastQuoteDate; protected double targetPerformance; protected PortfolioType portfolioType; //setOfInitialTickers has to contain the //ticker's symbol in the first column ! public BestTickersScreener(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, double targetPerformance, PortfolioType portfolioType) { this.setOfTickers = setOfInitialTickers; if ( setOfInitialTickers.Rows.Count == 0 ) throw new Exception( "setOfInitialTickers cannot be empty!" ); this.firstQuoteDate = firstQuoteDate; this.lastQuoteDate = lastQuoteDate; this.targetPerformance = targetPerformance; this.portfolioType = portfolioType; } //this protected method has to be called by inherited classes //(open to close or close to close) //only after all initializations provided //by their respective constructors protected void retrieveData() { this.setOfCandidates = new CandidatePropertiesForSimpleSelection[setOfTickers.Rows.Count]; for(int i = 0; i<setOfTickers.Rows.Count; i++) { string ticker = (string)setOfTickers.Rows[i][0]; this.setOfCandidates[i] = new CandidatePropertiesForSimpleSelection(ticker, this.getArrayOfRatesOfReturn(ticker), this.targetPerformance); } } //this protected method must be overriden by inherited classes //specifing the type of rates of return that have to //be analyzed protected virtual float[] getArrayOfRatesOfReturn(string ticker) { float[] returnValue = null; return returnValue; } private void setSetOfCandidates(bool longRatesOfReturn) { for(int i = 0; i<this.setOfCandidates.Length;i++) { this.setOfCandidates[i].LongRatesOfReturn = longRatesOfReturn; this.setOfCandidates[i].setFitness(); } Array.Sort(this.setOfCandidates); } private void getBestTickers_setReturnValueForOnlyLong(string[] returnValue) { this.setSetOfCandidates(true); for(int i = 0; i<returnValue.Length;i++) //the last items of the array are the best tickers for long trades returnValue[i] = this.setOfCandidates[this.setOfCandidates.Length - i - 1].Ticker; } private void getBestTickers_setReturnValueForOnlyShort(string[] returnValue) { this.setSetOfCandidates(true); for(int i = 0; i<returnValue.Length;i++) //the first items of the array are surely the best tickers for short trades returnValue[i] = "-" + this.setOfCandidates[i].Ticker; } /*OLD IMPLEMENTATION: HALF SHORT HALF LONG private void getBestTickers_setReturnValueForShortAndLong(string[] returnValue) { this.getBestTickers_setReturnValueForOnlyLong(returnValue); //the first half is for long tickers int numberOfTickersForShort = returnValue.Length / 2; for(int i = 0; i<numberOfTickersForShort;i++) returnValue[i] = "-" + this.setOfCandidates[i].Ticker; //the second half is for short tickers (if returnValue.Length is //odd, n° of short tickers = n° of long tickers - 1 } */ //new implementation tickers with highest fitness, //short or long private void getBestTickers_setReturnValueForShortAndLong(string[] returnValue) { CandidateProperties[] allTickersShortOrLong = new CandidateProperties[this.setOfCandidates.Length * 2]; int numOfTickers = this.setOfCandidates.Length; this.setSetOfCandidates(true); for(int i = 0; i<numOfTickers; i++) allTickersShortOrLong[i] = new CandidateProperties(this.setOfCandidates[i].Ticker, this.setOfCandidates[i].ArrayOfRatesOfReturn); this.setSetOfCandidates(false); for(int i = numOfTickers; i<numOfTickers*2; i++) allTickersShortOrLong[i] = new CandidateProperties("-" + this.setOfCandidates[i].Ticker, this.setOfCandidates[i].ArrayOfRatesOfReturn); Array.Sort(allTickersShortOrLong); for(int i = 0; i<returnValue.Length; i++) returnValue[i] = allTickersShortOrLong[i].Ticker; } /// <summary> /// It gets best tickers for trading /// If PortfolioType is ShortAndLong, half of numberOfTickers is for short and /// the remaining half for long. Tickers for short trading are signed! /// </summary> public string[] GetBestTickers(int numberOfTickers) { string[] returnValue = new string[numberOfTickers]; if(this.portfolioType == PortfolioType.OnlyLong) this.getBestTickers_setReturnValueForOnlyLong(returnValue); else if(this.portfolioType == PortfolioType.OnlyShort) this.getBestTickers_setReturnValueForOnlyShort(returnValue); else if(this.portfolioType == PortfolioType.ShortAndLong) this.getBestTickers_setReturnValueForShortAndLong(returnValue); return returnValue; } } } --- NEW FILE: RunSimpleSelectionOpenToClose.cs --- /* QuantProject - Quantitative Finance Library RunSimpleSelectionOpenToClose.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.FileManaging; 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.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.TickerSelectionTesting.SimpleSelection { /// <summary> /// Script to buy at open and sell at close (within the same day) /// the tickers with the highest fitness, for short or long trade /// </summary> [Serializable] public class RunSimpleSelectionOpenToClose : RunSimpleSelection { protected int numDaysBetweenEachOptimization; public RunSimpleSelectionOpenToClose(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, PortfolioType portfolioType, double maxRunningHours, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, benchmark, startDate, endDate, targetReturn, portfolioType, maxRunningHours) { this.ScriptName = "SimpleSelectionOpenToClose"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } #region auxiliary overriden methods for Run /* delete remark delimitations for having ib commission protected override void run_initializeAccount() { this.account = new Account( this.ScriptName , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , this.historicalQuoteProvider ), new IBCommissionManager()); } */ protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerSimpleSelectionOpenToClose(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.benchmark, this.targetReturn, this.portfolioType, this.numDaysBetweenEachOptimization); } protected override void run_initializeHistoricalQuoteProvider() { this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); //this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.endOfDayTimerHandler.MarketOpenEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.endOfDayTimerHandler.MarketCloseEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.checkDateForReport); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); } #endregion public override void SaveScriptResults() { string fileName = "SimpleOTCDailySelectionFrom"+this.numberOfEligibleTickers + "OptDays" + this.numDaysForOptimizationPeriod + "Portfolio" + this.numberOfTickersToBeChosen + "Target" + Convert.ToString(this.targetReturn) + Convert.ToString(this.portfolioType); string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; //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.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); ObjectArchiver.Archive(this.account.Transactions, dirNameWhereToSaveTransactions + fileName + ".qPt"); // this.endOfDayTimer.Stop(); } //necessary far calling RunEfficientPortfolio.Run() //in classes that inherit from this class public override void Run() { base.Run(); } } } --- NEW FILE: EndOfDayTimerHandlerSimpleSelectionOpenToClose.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerSimpleSelectionOpenToClose.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.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.SimpleSelection { /// <summary> /// Base class for EndOfDayTimerHandlers for simple selection /// </summary> [Serializable] public class EndOfDayTimerHandlerSimpleSelectionOpenToClose : EndOfDayTimerHandlerSimpleSelection { protected int numDaysBetweenEachOptimization; private int numDaysElapsedSinceLastOptimization; public EndOfDayTimerHandlerSimpleSelectionOpenToClose(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, string benchmark, double targetReturn, PortfolioType portfolioType, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, benchmark, targetReturn, portfolioType) { this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.numDaysElapsedSinceLastOptimization = 0; } public override void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.openPositions(); } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.closePositions(); } #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { /* SelectorByAverageRawOpenPrice selectorByOpenPrice = new SelectorByAverageRawOpenPrice(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers, this.minPriceForMinimumCommission, this.maxPriceForMinimumCommission, 0, 2); DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromTemporizedGroup = new SelectorByOpenCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), this.benchmark,true, currentDate.AddDays(-this.numDaysForOptimizationPeriod ), currentDate, this.numberOfEligibleTickers); this.eligibleTickers = lessCorrelatedFromTemporizedGroup.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), // false, currentDate.AddDays(-2), // currentDate, this.numberOfEligibleTickers/4); //return winners.GetTableOfSelectedTickers(); //SelectorByOpenCloseCorrelationToBenchmark lessCorrelated = // new SelectorByOpenCloseCorrelationToBenchmark(quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(), // this.benchmark, true, // currentDate.AddDays(-this.numDaysForLiquidity), // currentDate, this.numberOfEligibleTickers/2); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); //return lessCorrelated.GetTableOfSelectedTickers(); } protected virtual void setTickers(DateTime currentDate) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); if(setOfTickersToBeOptimized.Rows.Count >= this.chosenTickers.Length) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen { BestTickersScreenerOpenToClose OTCScreener = new BestTickersScreenerOpenToClose(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.targetReturn, this.portfolioType); this.chosenTickers = OTCScreener.GetBestTickers(this.numberOfTickersToBeChosen); } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member } protected void oneHourAfterMarketCloseEventHandler_updatePrices() { //min price for minimizing commission amount //according to IB Broker's commission scheme this.minPriceForMinimumCommission = this.account.CashAmount/(this.numberOfTickersToBeChosen*100); this.maxPriceForMinimumCommission = this.maxPriceForMinimumCommission; //just to avoid warning message } /// <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.orders.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; } else { this.numDaysElapsedSinceLastOptimization++; } } #endregion } // end of class } |