quantproject-developers Mailing List for QuantProject (Page 108)
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-06-02 18:04:33
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18636/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: Minor changes for the GeneticOptimizer class Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GeneticOptimizer.cs 17 May 2005 23:00:57 -0000 1.3 --- GeneticOptimizer.cs 2 Jun 2005 18:03:59 -0000 1.4 *************** *** 37,48 **** { #region fields ! private double mutationRate = 0.02; ! private double crossoverRate = 0.85; ! private double elitismRate = 0.01; ! private double minConvergenceRate = 0.80; ! private bool keepOnRunningUntilConvergenceIsReached = false; ! private int populationSize = 1000; ! private int generationNumber = 100; private int genomeSize; private int minValueForGenes; --- 37,49 ---- { #region fields + private static Random random = new Random((int)DateTime.Now.Ticks); ! private double mutationRate; ! private double crossoverRate; ! private double elitismRate; ! private double minConvergenceRate; ! private bool keepOnRunningUntilConvergenceIsReached; ! private int populationSize; ! private int generationNumber; private int genomeSize; private int minValueForGenes; *************** *** 59,63 **** private ArrayList cumulativeFitnessList; - private static Random random = new Random((int)DateTime.Now.Ticks); private int generationCounter; #endregion --- 60,63 ---- *************** *** 158,162 **** private void commonInitialization() { ! this.genomeSize = this.genomeManager.GenomeSize; this.minValueForGenes = this.genomeManager.MinValueForGenes; this.maxValueForGenes = this.genomeManager.MaxValueForGenes; --- 158,167 ---- private void commonInitialization() { ! this.mutationRate = 0.02; ! this.crossoverRate = 0.85; ! this.elitismRate = 0.01; ! this.minConvergenceRate = 0.80; ! this.keepOnRunningUntilConvergenceIsReached = false; ! this.genomeSize = this.genomeManager.GenomeSize; this.minValueForGenes = this.genomeManager.MinValueForGenes; this.maxValueForGenes = this.genomeManager.MaxValueForGenes; *************** *** 164,176 **** this.cumulativeFitnessList = new ArrayList(this.PopulationSize); this.currentGeneration = new ArrayList(this.PopulationSize); ! this.nextGeneration = new ArrayList(); ! this.currentEliteToTransmitToNextGeneration = ! new ArrayList((int)(this.ElitismRate*(double)this.PopulationSize)); ! this.generationCounter = 1; } /// <summary> ! /// Method which starts the GeneticOptmizer /// </summary> public void Run(bool showOutputToConsole) --- 169,181 ---- this.cumulativeFitnessList = new ArrayList(this.PopulationSize); this.currentGeneration = new ArrayList(this.PopulationSize); ! int eliteNumber = (int)(this.ElitismRate*(double)this.PopulationSize); ! this.currentEliteToTransmitToNextGeneration = new ArrayList(eliteNumber); ! this.nextGeneration = new ArrayList(this.populationSize + ! eliteNumber); this.generationCounter = 1; } /// <summary> ! /// Method to start the GeneticOptmizer /// </summary> public void Run(bool showOutputToConsole) *************** *** 252,263 **** double randomFitness = this.totalFitness *(double)GeneticOptimizer.random.Next(1,1001)/1000; int idx = -1; - int mid; int first = 0; int last = this.populationSize -1; ! mid = (last - first)/2; ! // Need to implement a specific search, because the // ArrayList's BinarySearch is for exact values only - while (idx == -1 && first <= last) { --- 257,265 ---- double randomFitness = this.totalFitness *(double)GeneticOptimizer.random.Next(1,1001)/1000; int idx = -1; int first = 0; int last = this.populationSize -1; ! int mid = (last - first)/2; // Need to implement a specific search, because the // ArrayList's BinarySearch is for exact values only while (idx == -1 && first <= last) { *************** *** 270,279 **** first = mid; } - mid = (first + last)/2; if ((last - first) == 1) idx = last; ! ! } return idx; } --- 272,279 ---- first = mid; } mid = (first + last)/2; if ((last - first) == 1) idx = last; ! } return idx; } *************** *** 285,289 **** private void calculateTotalFitness() { ! this.totalFitness = 0; for (int i = 0; i < this.populationSize; i++) { --- 285,289 ---- private void calculateTotalFitness() { ! this.totalFitness = 0.0; for (int i = 0; i < this.populationSize; i++) { |
|
From: Marco M. <mi...@us...> - 2005-06-02 18:02:24
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17387/b7_Scripts Modified Files: Scripts.prjx Log Message: Updated #develop projects files. Index: Scripts.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts.prjx,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Scripts.prjx 4 May 2005 18:21:01 -0000 1.4 --- Scripts.prjx 2 Jun 2005 18:02:08 -0000 1.5 *************** *** 32,35 **** --- 32,37 ---- <File name=".\TickerSelectionTesting\RunTestOptimizedCTOPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\TickerSelectionTesting\EndOfDayTimerHandlerCTOTest.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\RunTestOptimizedCTCPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\EndOfDayTimerHandlerCTCTest.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-06-02 18:02:23
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17387/b3_Data Modified Files: Data.prjx Log Message: Updated #develop projects files. Index: Data.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Data.prjx,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Data.prjx 17 May 2005 23:06:00 -0000 1.5 --- Data.prjx 2 Jun 2005 18:02:08 -0000 1.6 *************** *** 10,13 **** --- 10,14 ---- <File name=".\DataProviders\Quote.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\DataProviders\Timer.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\DataProviders\Caching\Cache.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\DataTables\GroupQuotes.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\DataTables\Quotes.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> *************** *** 34,37 **** --- 35,40 ---- <File name=".\Selectors\SelectorByWinningOpenToClose.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\Selectors\SelectorByOpenCloseCorrelationToBenchmark.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\DataProviders\Caching\EarlyDateException.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\DataProviders\Caching\CachePage.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-06-02 18:02:19
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17387/b1_ADT Modified Files: ADT.prjx Log Message: Updated #develop projects files. Index: ADT.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ADT.prjx,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ADT.prjx 19 Apr 2005 18:26:57 -0000 1.2 --- ADT.prjx 2 Jun 2005 18:02:07 -0000 1.3 *************** *** 30,33 **** --- 30,34 ---- <File name=".\Histories\PreviousInterpolator.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\Histories\IInterpolatonMethod.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\IndexOfKeyOrPreviousException.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References /> |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16116/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandlerCTOTest.cs GenomeManagerForEfficientCTCPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientPortfolio.cs RunEfficientCTCPortfolio.cs RunEfficientCTOPortfolio.cs RunEfficientPortfolio.cs RunTestOptimizedCTOPortfolio.cs Added Files: EndOfDayTimerHandlerCTCTest.cs RunTestOptimizedCTCPortfolio.cs Log Message: Scripts for finding the efficient portfolio have been reorganized in a more object-oriented way. Test script handlers (for checking the optimization process through in - sample simulation) now derive directly from the main classes used for out of sample simulations. Index: RunTestOptimizedCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunTestOptimizedCTOPortfolio.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunTestOptimizedCTOPortfolio.cs 4 May 2005 18:21:07 -0000 1.1 --- RunTestOptimizedCTOPortfolio.cs 2 Jun 2005 18:00:47 -0000 1.2 *************** *** 50,54 **** /// </summary> [Serializable] ! public class RunTestOptimizedCTOPorfolio : RunEfficientPorfolio { --- 50,54 ---- /// </summary> [Serializable] ! public class RunTestOptimizedCTOPorfolio : RunEfficientCTOPorfolio { *************** *** 58,62 **** int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, ! PortfolioType portfolioType): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, --- 58,62 ---- int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, ! PortfolioType portfolioType, double maxRunningHours): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, *************** *** 64,68 **** populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, ! portfolioType) { this.ScriptName = "TestOptimizedCTOPortfolio"; --- 64,68 ---- populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) { this.ScriptName = "TestOptimizedCTOPortfolio"; *************** *** 82,120 **** this.portfolioType); - - } - protected override void run_initializeHistoricalQuoteProvider() - { - this.historicalQuoteProvider = - new HistoricalRawQuoteProvider(); - } public override void Run() { ! run_initializeHistoricalQuoteProvider(); ! run_initializeEndOfDayTimer(); ! run_initializeAccount(); ! run_initializeEndOfDayTimerHandler(); ! ! 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 ); ! ! this.endOfDayTimer.Start(); ((EndOfDayTimerHandlerCTOTest)this.endOfDayTimerHandler).Reset(); - } --- 82,91 ---- this.portfolioType); } public override void Run() { ! base.Run(); ((EndOfDayTimerHandlerCTOTest)this.endOfDayTimerHandler).Reset(); } Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GenomeManagerForEfficientCTOPortfolio.cs 26 Apr 2005 19:02:13 -0000 1.8 --- GenomeManagerForEfficientCTOPortfolio.cs 2 Jun 2005 18:00:47 -0000 1.9 *************** *** 99,103 **** } ! } --- 99,121 ---- } ! protected override double getFitnessValue_calculate() ! { ! double returnValue = 0; ! ! double a, b, c; ! a = 0.002; b = 2.0; c = 3.0; ! ! returnValue = Math.Pow((a/this.Variance),b) * ! Math.Pow((this.rateOfReturn - this.targetPerformance), ! c); ! if(this.portfolioType == PortfolioType.OnlyShort) ! returnValue = - returnValue; ! ! if(Double.IsInfinity(returnValue) || Double.IsNaN(returnValue)) ! throw new Exception("Fitness value not computed correctly!"); ! ! return returnValue; ! } ! } Index: RunEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTCPortfolio.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RunEfficientCTCPortfolio.cs 17 May 2005 23:13:25 -0000 1.6 --- RunEfficientCTCPortfolio.cs 2 Jun 2005 18:00:47 -0000 1.7 *************** *** 59,64 **** public class RunEfficientCTCPorfolio : RunEfficientPorfolio { ! private int numDayOfPortfolioLife; ! private double maxAcceptableCloseToCloseDrawdown; public RunEfficientCTCPorfolio(string tickerGroupID, int numberOfEligibleTickers, --- 59,65 ---- public class RunEfficientCTCPorfolio : RunEfficientPorfolio { ! protected int numDayOfPortfolioLife; ! protected int numDaysForReturnCalculation; ! protected double maxAcceptableCloseToCloseDrawdown; public RunEfficientCTCPorfolio(string tickerGroupID, int numberOfEligibleTickers, *************** *** 67,72 **** int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, ! int numDaysOfPortfolioLife, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, --- 68,75 ---- int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, ! int numDaysOfPortfolioLife, int numDaysForReturnCalculation, ! double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, *************** *** 74,81 **** populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, ! portfolioType) { this.ScriptName = "CloseToCloseScripts"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; } --- 77,85 ---- populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) { this.ScriptName = "CloseToCloseScripts"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; + this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; } *************** *** 90,94 **** this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, ! this.numDayOfPortfolioLife, this.targetReturn, this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } --- 94,99 ---- this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, ! this.numDayOfPortfolioLife, this.numDaysForReturnCalculation, ! this.targetReturn, this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } --- NEW FILE: RunTestOptimizedCTCPortfolio.cs --- /* QuantProject - Quantitative Finance Library RunTestOptimizedCTCPortfolio.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.Data; using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Accounting.Reporting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Scripting; using QuantProject.Business.Strategies; using QuantProject.Business.Testing; using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; using QuantProject.ADT.FileManaging; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Script to buy at close and sell at close /// after a specified number of market days /// the efficient portfolio /// The efficient portfolio's generation rules /// (contained in the EndOfDayTimerHandler) are: /// - choose the most liquid tickers; /// - choose only tickers quoted at each market day /// during a given previous interval of days; /// - choose the most efficient portfolio among these tickers /// </summary> [Serializable] public class RunTestOptimizedCTCPortfolio : RunEfficientCTCPorfolio { public RunTestOptimizedCTCPortfolio(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, int numDaysOfPortfolioLife, int numDaysForReturnCalculation, double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, double maxRunningHours): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, numDaysOfPortfolioLife, numDaysForReturnCalculation, targetReturn, portfolioType, maxAcceptableCloseToCloseDrawdown, maxRunningHours) { this.ScriptName = "TestOptimizedCTCPortfolio"; } protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTCTest(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForLiquidity, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.numDayOfPortfolioLife, this.numDaysForReturnCalculation, this.targetReturn, this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } public override void Run() { base.Run(); ((EndOfDayTimerHandlerCTCTest)this.endOfDayTimerHandler).Reset(); } } } Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GenomeManagerForEfficientCTCPortfolio.cs 26 Apr 2005 19:02:12 -0000 1.3 --- GenomeManagerForEfficientCTCPortfolio.cs 2 Jun 2005 18:00:47 -0000 1.4 *************** *** 40,43 **** --- 40,44 ---- { private int numDaysOfPortfolioLife; + private int numDaysForReturnCalculation; public GenomeManagerForEfficientCTCPortfolio(DataTable setOfInitialTickers, *************** *** 46,49 **** --- 47,51 ---- int numberOfTickersInPortfolio, int numDaysOfPortfolioLife, + int numDaysForReturnCalculation, double targetPerformance, PortfolioType portfolioType) *************** *** 59,62 **** --- 61,65 ---- { this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; + this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.retrieveData(); } *************** *** 83,92 **** Quotes tickerQuotes = new Quotes(tickerCode, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); ! float[] ratesOfReturns = new float[allAdjValues.Length/this.numDaysOfPortfolioLife + 1]; int i = 0; //index for ratesOfReturns array ! for(int idx = 0; idx + this.numDaysOfPortfolioLife < allAdjValues.Length; idx += this.numDaysOfPortfolioLife ) { ! ratesOfReturns[i] = (allAdjValues[idx+this.numDaysOfPortfolioLife]/ allAdjValues[idx] - 1)*coefficient; i++; --- 86,95 ---- Quotes tickerQuotes = new Quotes(tickerCode, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); ! float[] ratesOfReturns = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; int i = 0; //index for ratesOfReturns array ! for(int idx = 0; idx + this.numDaysForReturnCalculation < allAdjValues.Length; idx += this.numDaysForReturnCalculation ) { ! ratesOfReturns[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ allAdjValues[idx] - 1)*coefficient; i++; Index: EndOfDayTimerHandlerCTOTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTOTest.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerCTOTest.cs 17 May 2005 23:13:25 -0000 1.2 --- EndOfDayTimerHandlerCTOTest.cs 2 Jun 2005 18:00:47 -0000 1.3 *************** *** 42,46 **** /// </summary> [Serializable] ! public class EndOfDayTimerHandlerCTOTest : EndOfDayTimerHandler { private static bool optimized; --- 42,46 ---- /// </summary> [Serializable] ! public class EndOfDayTimerHandlerCTOTest : EndOfDayTimerHandlerCTO { private static bool optimized; *************** *** 60,137 **** } - - #region MarketOpenEventHandler - - private void marketOpenEventHandler_orderChosenTickers_addToOrderList() - { - int idx = 0; - foreach ( string ticker in this.chosenTickers ) - { - if(ticker != null) - { - this.addOrderForTicker( ticker ); - this.lastChosenTickers[idx] = - GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); - } - idx++; - } - } - - private void marketOpenEventHandler_orderChosenTickers() - { - this.marketOpenEventHandler_orderChosenTickers_addToOrderList(); - } - - /// <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.orders.Count == 0 && this.account.Transactions.Count == 0) - this.account.AddCash(17000); - - this.marketOpenEventHandler_orderChosenTickers(); - - foreach(object item in this.orders) - { - this.account.AddOrder((Order)item); - } - } - #endregion - - #region MarketCloseEventHandler ! private void marketCloseEventHandler_closePosition( ! string ticker ) ! { ! this.account.ClosePosition( ticker ); ! } ! private void marketCloseEventHandler_closePositions() ! { ! if(this.lastChosenTickers != null) ! { ! foreach( string ticker in this.lastChosenTickers) ! { ! for(int i = 0; i<this.account.Portfolio.Keys.Count; i++) ! { ! if(this.account.Portfolio[ticker]!=null) ! marketCloseEventHandler_closePosition( ticker ); ! } ! } ! } ! } ! ! public override void MarketCloseEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! ! this.marketCloseEventHandler_closePositions(); } - - - #endregion public void Reset() --- 60,72 ---- } ! protected override void setTickers(DateTime currentDate) { ! if(!EndOfDayTimerHandlerCTOTest.optimized) ! { ! base.setTickers(currentDate); ! EndOfDayTimerHandlerCTOTest.optimized = true; ! } } public void Reset() *************** *** 139,239 **** EndOfDayTimerHandlerCTOTest.optimized = false; } - - #region OneHourAfterMarketCloseEventHandler - - private 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(); - */ - - SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, - currentDate.AddDays(-this.numDaysForLiquidity), currentDate, - this.numberOfEligibleTickers); - //SelectorByOpenToCloseVolatility lessVolatile = - // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), - // true, currentDate.AddDays(-this.numDaysForLiquidity/3), - // currentDate, - // this.numberOfEligibleTickers/4); - - this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); - SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = - new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, - false, currentDate.AddDays(-this.numDaysForLiquidity), - currentDate, this.numberOfEligibleTickers, this.benchmark); - //SelectorByWinningOpenToClose winners = - // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), - // false, currentDate.AddDays(-2), - // currentDate, this.numberOfEligibleTickers/4); - //return winners.GetTableOfSelectedTickers(); - return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); - } - - - private void setTickers(DateTime currentDate) - { - if(!EndOfDayTimerHandlerCTOTest.optimized) - { - DataTable setOfTickersToBeOptimized = - this.getSetOfTickersToBeOptimized(currentDate.AddDays(this.numDaysForLiquidity)); - 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, - currentDate.AddDays(this.numDaysForLiquidity), - this.numberOfTickersToBeChosen, - this.targetReturn, - this.portfolioType); - GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, - this.populationSizeForGeneticOptimizer, - this.generationNumberForGeneticOptimizer); - //GO.KeepOnRunningUntilConvergenceIsReached = true; - GO.GenerationNumber = this.generationNumberForGeneticOptimizer; - GO.PopulationSize = this.populationSizeForGeneticOptimizer; - GO.Run(false); - this.chosenTickers = (string[])GO.BestGenome.Meaning; - - EndOfDayTimerHandlerCTOTest.optimized = true; - //this.lastChosenTickers = this.chosenTickers; - } - //else it will be buyed again the previous optimized portfolio - //that's it the actual chosenTickers member - } - } - private 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.oneHourAfterMarketCloseEventHandler_updatePrices(); - this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); - //sets tickers to be chosen next Market Open event - this.orders.Clear(); - } - - #endregion - } } --- 74,78 ---- Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** EndOfDayTimerHandlerCTO.cs 17 May 2005 23:13:25 -0000 1.11 --- EndOfDayTimerHandlerCTO.cs 2 Jun 2005 18:00:47 -0000 1.12 *************** *** 63,67 **** #region MarketOpenEventHandler ! private void marketOpenEventHandler_orderChosenTickers_addToOrderList() { int idx = 0; --- 63,67 ---- #region MarketOpenEventHandler ! protected void marketOpenEventHandler_orderChosenTickers_addToOrderList() { int idx = 0; *************** *** 78,82 **** } ! private void marketOpenEventHandler_orderChosenTickers() { this.marketOpenEventHandler_orderChosenTickers_addToOrderList(); --- 78,82 ---- } ! protected void marketOpenEventHandler_orderChosenTickers() { this.marketOpenEventHandler_orderChosenTickers_addToOrderList(); *************** *** 105,114 **** #region MarketCloseEventHandler ! private void marketCloseEventHandler_closePosition( string ticker ) { this.account.ClosePosition( ticker ); } ! private void marketCloseEventHandler_closePositions() { if(this.lastChosenTickers != null) --- 105,114 ---- #region MarketCloseEventHandler ! protected void marketCloseEventHandler_closePosition( string ticker ) { this.account.ClosePosition( ticker ); } ! protected void marketCloseEventHandler_closePositions() { if(this.lastChosenTickers != null) *************** *** 136,140 **** #region OneHourAfterMarketCloseEventHandler ! private DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { /* --- 136,140 ---- #region OneHourAfterMarketCloseEventHandler ! protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { /* *************** *** 150,161 **** currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers); ! //SelectorByOpenToCloseVolatility lessVolatile = ! // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), ! // true, currentDate.AddDays(-this.numDaysForLiquidity/3), ! // currentDate, ! // this.numberOfEligibleTickers/4); this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), --- 150,161 ---- currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers); ! /*SelectorByOpenToCloseVolatility lessVolatile = ! new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), ! true, currentDate.AddDays(-5), ! currentDate, ! this.numberOfEligibleTickers/2);*/ this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), *************** *** 166,174 **** // currentDate, this.numberOfEligibleTickers/4); //return winners.GetTableOfSelectedTickers(); ! return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } ! private void setTickers(DateTime currentDate) { --- 166,174 ---- // currentDate, this.numberOfEligibleTickers/4); //return winners.GetTableOfSelectedTickers(); ! return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); } ! protected virtual void setTickers(DateTime currentDate) { *************** *** 186,198 **** this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); ! //GO.KeepOnRunningUntilConvergenceIsReached = true; ! GO.GenerationNumber = this.generationNumberForGeneticOptimizer; ! GO.PopulationSize = this.populationSizeForGeneticOptimizer; GO.Run(false); this.chosenTickers = (string[])GO.BestGenome.Meaning; - //this.lastChosenTickers = this.chosenTickers; } //else it will be buyed again the previous optimized portfolio --- 186,197 ---- this.targetReturn, this.portfolioType); + GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); ! GO.Run(false); + this.chosenTickers = (string[])GO.BestGenome.Meaning; } //else it will be buyed again the previous optimized portfolio *************** *** 200,204 **** } ! private void oneHourAfterMarketCloseEventHandler_updatePrices() { //min price for minimizing commission amount --- 199,203 ---- } ! protected void oneHourAfterMarketCloseEventHandler_updatePrices() { //min price for minimizing commission amount Index: RunEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientPortfolio.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RunEfficientPortfolio.cs 17 May 2005 23:13:25 -0000 1.7 --- RunEfficientPortfolio.cs 2 Jun 2005 18:00:47 -0000 1.8 *************** *** 53,59 **** public class RunEfficientPorfolio { - public static double MaxNumberOfHoursForScript = 5; - //if MaxNumberOfHoursForScript has elapsed and the script - //is still running, it will be stopped. protected string tickerGroupID; protected int numberOfEligibleTickers; --- 53,56 ---- *************** *** 87,90 **** --- 84,90 ---- protected DateTime startingTimeForScript; + protected double maxRunningHours; + //if MaxNumberOfHoursForScript has elapsed and the script + //is still running, it will be stopped. public virtual string ScriptName *************** *** 100,109 **** public RunEfficientPorfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForLiquidity, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, ! double targetReturn, ! PortfolioType portfolioType) { //this.progressBarForm = new ProgressBarForm(); --- 100,110 ---- public RunEfficientPorfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForLiquidity, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, string benchmark, ! DateTime startDate, DateTime endDate, ! double targetReturn, ! PortfolioType portfolioType, ! double maxRunningHours) { //this.progressBarForm = new ProgressBarForm(); *************** *** 124,127 **** --- 125,129 ---- this.portfolioType = portfolioType; this.startingTimeForScript = DateTime.Now; + this.maxRunningHours = maxRunningHours; //this.numIntervalDays = 3; } *************** *** 165,170 **** { if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(RunEfficientPorfolio.MaxNumberOfHoursForScript)) ! //last date is reached by the timer or MaxNumberOfHoursForScript hours //are elapsed from the time script started this.SaveScriptResults(); --- 167,172 ---- { 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(); --- NEW FILE: EndOfDayTimerHandlerCTCTest.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerCTCTest.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 and MarketCloseEventHandler /// These handlers contain the core strategy for the efficient close to close /// portfolio (with a given days of life)! /// </summary> [Serializable] public class EndOfDayTimerHandlerCTCTest : EndOfDayTimerHandlerCTC { private static bool optimized; public EndOfDayTimerHandlerCTCTest(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, int numDaysOfPortfolioLife, int numDaysForReturnCalculation, double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, numDaysOfPortfolioLife, numDaysForReturnCalculation, targetReturn, portfolioType, maxAcceptableCloseToCloseDrawdown) { } protected override void setTickers(DateTime currentDate) { if(!EndOfDayTimerHandlerCTCTest.optimized) { base.setTickers(currentDate); EndOfDayTimerHandlerCTCTest.optimized = true; } } public void Reset() { EndOfDayTimerHandlerCTCTest.optimized = false; } } } Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** RunEfficientCTOPortfolio.cs 4 May 2005 18:30:54 -0000 1.18 --- RunEfficientCTOPortfolio.cs 2 Jun 2005 18:00:47 -0000 1.19 *************** *** 62,66 **** int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, ! PortfolioType portfolioType): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, --- 62,66 ---- int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, ! PortfolioType portfolioType, double maxRunningHours): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, *************** *** 68,72 **** populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, ! portfolioType) { this.ScriptName = "OpenCloseScripts"; --- 68,72 ---- populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, ! portfolioType, maxRunningHours) { this.ScriptName = "OpenCloseScripts"; Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GenomeManagerForEfficientPortfolio.cs 4 May 2005 18:29:00 -0000 1.8 --- GenomeManagerForEfficientPortfolio.cs 2 Jun 2005 18:00:47 -0000 1.9 *************** *** 163,168 **** } ! public virtual double GetFitnessValue(Genome genome) { double returnValue = 0; --- 163,188 ---- } + protected virtual double getFitnessValue_calculate() + { + double returnValue = 0; + + NormalDistribution normal = + new NormalDistribution(this.rateOfReturn, + Math.Sqrt(this.variance)); + if(this.portfolioType == PortfolioType.OnlyLong || + this.portfolioType == PortfolioType.ShortAndLong) + //the genome fitness is evaluated as if + //the portfolio was long + //returnValue = normal.GetProbability(this.targetPerformance*0.75,this.targetPerformance*1.25); + returnValue = 1.0 - normal.GetProbability(this.targetPerformance); + else//only short orders are permitted + //returnValue = normal.GetProbability(-this.targetPerformance*1.25,-this.targetPerformance*0.75); + returnValue = normal.GetProbability(-this.targetPerformance); + + return returnValue; + + } ! public double GetFitnessValue(Genome genome) { double returnValue = 0; *************** *** 179,202 **** !Double.IsInfinity(averagePortfolioRateOfReturn) && !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn)) //both variance and rate of return are //double values computed in the right way: ! // so it's possible to assign fitness using normal distribution class { this.variance = portfolioVariance; this.rateOfReturn = averagePortfolioRateOfReturn; ! NormalDistribution normal = ! new NormalDistribution(this.rateOfReturn, ! Math.Sqrt(this.variance)); ! if(this.portfolioType == PortfolioType.OnlyLong || ! this.portfolioType == PortfolioType.ShortAndLong) ! //the genome fitness is evaluated as if ! //the portfolio was long ! //returnValue = normal.GetProbability(this.targetPerformance*0.75,this.targetPerformance*1.25); ! returnValue = 1.0 - normal.GetProbability(this.targetPerformance); ! else//only short orders are permitted ! //returnValue = normal.GetProbability(-this.targetPerformance*1.25,-this.targetPerformance*0.75); ! returnValue = normal.GetProbability(-this.targetPerformance); } return returnValue; } --- 199,213 ---- !Double.IsInfinity(averagePortfolioRateOfReturn) && !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn) && ! portfolioVariance > 0.0) //both variance and rate of return are //double values computed in the right way: ! // so it's possible to assign fitness { this.variance = portfolioVariance; this.rateOfReturn = averagePortfolioRateOfReturn; ! returnValue = this.getFitnessValue_calculate(); } + return returnValue; } *************** *** 233,237 **** genome.MaxValueForGenes +1); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(genome.HasGene(newValueForGene)) { newValueForGene = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, --- 244,251 ---- genome.MaxValueForGenes +1); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); ! while(genome.HasGene(newValueForGene) || ! genome.HasGene(newValueForGene + this.originalNumOfTickers)) ! //the portfolio can't have a long position and a short position ! // for the same ticker { newValueForGene = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** EndOfDayTimerHandlerCTC.cs 17 May 2005 23:13:25 -0000 1.7 --- EndOfDayTimerHandlerCTC.cs 2 Jun 2005 18:00:47 -0000 1.8 *************** *** 44,53 **** public class EndOfDayTimerHandlerCTC : EndOfDayTimerHandler { ! private int numDaysOfPortfolioLife; ! private int daysCounter; ! private double maxAcceptableCloseToCloseDrawdown; ! private bool stopLossConditionReached; ! private double currentAccountValue; ! private double previousAccountValue; public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, --- 44,54 ---- public class EndOfDayTimerHandlerCTC : EndOfDayTimerHandler { ! protected int numDaysOfPortfolioLife; ! protected int numDaysForReturnCalculation; ! protected int daysCounter; ! protected double maxAcceptableCloseToCloseDrawdown; ! protected bool stopLossConditionReached; ! protected double currentAccountValue; ! protected double previousAccountValue; public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, *************** *** 58,61 **** --- 59,63 ---- string benchmark, int numDaysOfPortfolioLife, + int numDaysForReturnCalculation, double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): *************** *** 68,71 **** --- 70,74 ---- { this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; + this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.daysCounter = 0; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; *************** *** 76,80 **** #region MarketOpenEventHandler ! private DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID,false, --- 79,83 ---- #region MarketOpenEventHandler ! protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID,false, *************** *** 91,95 **** ! private void setTickers(DateTime currentDate) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); --- 94,98 ---- ! protected virtual void setTickers(DateTime currentDate) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); *************** *** 108,112 **** currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfTickersToBeChosen, ! this.numDaysOfPortfolioLife, this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio, --- 111,116 ---- currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfTickersToBeChosen, ! this.numDaysOfPortfolioLife, this.numDaysForReturnCalculation, ! this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio, *************** *** 143,147 **** #region MarketCloseEventHandler ! private void marketCloseEventHandler_orderChosenTickers_addToOrderList() { int idx = 0; --- 147,151 ---- #region MarketCloseEventHandler ! protected void marketCloseEventHandler_orderChosenTickers_addToOrderList() { int idx = 0; *************** *** 155,159 **** } } ! private void marketCloseEventHandler_orderChosenTickers() { this.marketCloseEventHandler_orderChosenTickers_addToOrderList(); --- 159,163 ---- } } ! protected void marketCloseEventHandler_orderChosenTickers() { this.marketCloseEventHandler_orderChosenTickers_addToOrderList(); *************** *** 161,165 **** ! private void marketCloseEventHandler_openPositions() { if(this.orders.Count == 0 && this.account.Transactions.Count == 0) --- 165,169 ---- ! protected void marketCloseEventHandler_openPositions() { if(this.orders.Count == 0 && this.account.Transactions.Count == 0) *************** *** 174,183 **** } ! private void marketCloseEventHandler_closePosition( string ticker ) { this.account.ClosePosition( ticker ); } ! private void marketCloseEventHandler_closePositions() { if(this.lastChosenTickers != null) --- 178,187 ---- } ! protected void marketCloseEventHandler_closePosition( string ticker ) { this.account.ClosePosition( ticker ); } ! protected void marketCloseEventHandler_closePositions() { if(this.lastChosenTickers != null) *************** *** 194,198 **** } ! private void updateStopLossCondition() { this.previousAccountValue = this.currentAccountValue; --- 198,202 ---- } ! protected void updateStopLossCondition() { this.previousAccountValue = this.currentAccountValue; |
|
From: Marco M. <mi...@us...> - 2005-06-02 18:00:58
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16116/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: Scripts for finding the efficient portfolio have been reorganized in a more object-oriented way. Test script handlers (for checking the optimization process through in - sample simulation) now derive directly from the main classes used for out of sample simulations. Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** b7_Scripts.csproj 4 May 2005 18:21:01 -0000 1.26 --- b7_Scripts.csproj 2 Jun 2005 18:00:48 -0000 1.27 *************** *** 164,167 **** --- 164,172 ---- /> <File + RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerCTCTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerCTO.cs" SubType = "Code" *************** *** 209,212 **** --- 214,222 ---- /> <File + RelPath = "TickerSelectionTesting\RunTestOptimizedCTCPortfolio.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\RunTestOptimizedCTOPortfolio.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2005-06-02 17:52:23
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11184/Downloader Modified Files: TickerDownloader.cs WebDownloader.cs Log Message: Fixed bug in the TickerDownloader object. Now, new adjusted quotes are committed to database only if the new close to close ratio is the same as previous one. This check has to be set by the user through the WebDownloader form. Index: WebDownloader.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/WebDownloader.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** WebDownloader.cs 22 Jan 2005 19:35:04 -0000 1.18 --- WebDownloader.cs 2 Jun 2005 17:52:10 -0000 1.19 *************** *** 52,55 **** --- 52,56 ---- internal System.Windows.Forms.CheckBox checkBoxComputeCloseToCloseValues; private System.Windows.Forms.ToolTip toolTip1; + internal System.Windows.Forms.CheckBox checkBoxDownloadOnlyAfterCloseToCloseCheck; private System.ComponentModel.IContainer components; *************** *** 153,156 **** --- 154,158 ---- this.checkBoxComputeCloseToCloseValues = new System.Windows.Forms.CheckBox(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.checkBoxDownloadOnlyAfterCloseToCloseCheck = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.groupBoxWebDownloaderOptions.SuspendLayout(); *************** *** 160,164 **** // button1 // ! this.button1.Location = new System.Drawing.Point(16, 392); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(112, 32); --- 162,166 ---- // button1 // ! this.button1.Location = new System.Drawing.Point(16, 424); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(112, 32); *************** *** 255,259 **** // buttonDownloadQuotesOfSelectedTickers // ! this.buttonDownloadQuotesOfSelectedTickers.Location = new System.Drawing.Point(136, 392); this.buttonDownloadQuotesOfSelectedTickers.Name = "buttonDownloadQuotesOfSelectedTickers"; this.buttonDownloadQuotesOfSelectedTickers.Size = new System.Drawing.Size(112, 32); --- 257,261 ---- // buttonDownloadQuotesOfSelectedTickers // ! this.buttonDownloadQuotesOfSelectedTickers.Location = new System.Drawing.Point(136, 424); this.buttonDownloadQuotesOfSelectedTickers.Name = "buttonDownloadQuotesOfSelectedTickers"; this.buttonDownloadQuotesOfSelectedTickers.Size = new System.Drawing.Size(112, 32); *************** *** 264,268 **** // labelNumberOfTickersToDownload // ! this.labelNumberOfTickersToDownload.Location = new System.Drawing.Point(160, 448); this.labelNumberOfTickersToDownload.Name = "labelNumberOfTickersToDownload"; this.labelNumberOfTickersToDownload.Size = new System.Drawing.Size(48, 24); --- 266,270 ---- // labelNumberOfTickersToDownload // ! this.labelNumberOfTickersToDownload.Location = new System.Drawing.Point(160, 472); this.labelNumberOfTickersToDownload.Name = "labelNumberOfTickersToDownload"; this.labelNumberOfTickersToDownload.Size = new System.Drawing.Size(48, 24); *************** *** 272,276 **** // labelTickersLeft // ! this.labelTickersLeft.Location = new System.Drawing.Point(16, 448); this.labelTickersLeft.Name = "labelTickersLeft"; this.labelTickersLeft.Size = new System.Drawing.Size(136, 24); --- 274,278 ---- // labelTickersLeft // ! this.labelTickersLeft.Location = new System.Drawing.Point(16, 472); this.labelTickersLeft.Name = "labelTickersLeft"; this.labelTickersLeft.Size = new System.Drawing.Size(136, 24); *************** *** 385,389 **** // this.buttonAbort.Enabled = false; ! this.buttonAbort.Location = new System.Drawing.Point(256, 408); this.buttonAbort.Name = "buttonAbort"; this.buttonAbort.Size = new System.Drawing.Size(32, 23); --- 387,391 ---- // this.buttonAbort.Enabled = false; ! this.buttonAbort.Location = new System.Drawing.Point(256, 440); this.buttonAbort.Name = "buttonAbort"; this.buttonAbort.Size = new System.Drawing.Size(32, 23); *************** *** 401,409 **** this.checkBoxComputeCloseToCloseValues.Text = "Compute close to close ratios (slower)"; // // WebDownloader // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(840, 486); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.checkBoxComputeCloseToCloseValues, this.buttonAbort, --- 403,422 ---- this.checkBoxComputeCloseToCloseValues.Text = "Compute close to close ratios (slower)"; // + // checkBoxDownloadOnlyAfterCloseToCloseCheck + // + this.checkBoxDownloadOnlyAfterCloseToCloseCheck.Location = new System.Drawing.Point(16, 384); + this.checkBoxDownloadOnlyAfterCloseToCloseCheck.Name = "checkBoxDownloadOnlyAfterCloseToCloseCheck"; + this.checkBoxDownloadOnlyAfterCloseToCloseCheck.Size = new System.Drawing.Size(272, 24); + this.checkBoxDownloadOnlyAfterCloseToCloseCheck.TabIndex = 17; + this.checkBoxDownloadOnlyAfterCloseToCloseCheck.Text = "Download only after CTC check (slower)"; + this.toolTip1.SetToolTip(this.checkBoxDownloadOnlyAfterCloseToCloseCheck, "If checked, commit to database is performed only for tickers for which new adjust" + + "ed values respect current close to close ratio "); + // // WebDownloader // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(840, 494); this.Controls.AddRange(new System.Windows.Forms.Control[] { + this.checkBoxDownloadOnlyAfterCloseToCloseCheck, this.checkBoxComputeCloseToCloseValues, this.buttonAbort, *************** *** 790,793 **** --- 803,813 ---- } } + public bool IsCheckCloseToCloseSelected + { + get + { + return this.checkBoxDownloadOnlyAfterCloseToCloseCheck.Checked; + } + } } } Index: TickerDownloader.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerDownloader.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** TickerDownloader.cs 22 Jan 2005 19:35:04 -0000 1.15 --- TickerDownloader.cs 2 Jun 2005 17:52:09 -0000 1.16 *************** *** 325,329 **** { this.updateCurrentStatusAdjustedClose("Changed!"); ! if (Quotes.IsAdjustedCloseToCloseRatioChanged(this.p_quTicker, this.getTableOfDownloadedValues(Quotes.GetStartDate(this.p_quTicker), Quotes.GetEndDate(this.p_quTicker)))) --- 325,330 ---- { this.updateCurrentStatusAdjustedClose("Changed!"); ! if (this.p_myForm.IsCheckCloseToCloseSelected && ! Quotes.IsAdjustedCloseToCloseRatioChanged(this.p_quTicker, this.getTableOfDownloadedValues(Quotes.GetStartDate(this.p_quTicker), Quotes.GetEndDate(this.p_quTicker)))) *************** *** 335,339 **** else { ! this.updateCurrentStatusAdjustedCloseToCloseRatio("OK"); this.updateAdjustedClose(); this.updateCurrentStatusAdjustedClose("Updated!"); --- 336,343 ---- else { ! if(this.p_myForm.IsCheckCloseToCloseSelected) ! this.updateCurrentStatusAdjustedCloseToCloseRatio("OK"); ! else ! this.updateCurrentStatusAdjustedCloseToCloseRatio("Not Checked"); this.updateAdjustedClose(); this.updateCurrentStatusAdjustedClose("Updated!"); |
|
From: Marco M. <mi...@us...> - 2005-06-02 17:45:58
|
Update of /cvsroot/quantproject/QuantProject/b5_Presentation/Reporting/WindowsForm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7126/b5_Presentation/Reporting/WindowsForm Modified Files: Report.cs Log Message: It is now possible to save to disk the account report (o simply the account) currently visualized by the report form. Index: Report.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b5_Presentation/Reporting/WindowsForm/Report.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Report.cs 14 Apr 2005 18:35:58 -0000 1.10 --- Report.cs 2 Jun 2005 17:45:49 -0000 1.11 *************** *** 41,44 **** --- 41,49 ---- private AccountReport accountReport; private ReportTabControl reportTabControl; + private MainMenu mainMenu; + private System.Windows.Forms.MenuItem file; + private System.Windows.Forms.MenuItem saveAccount; + private System.Windows.Forms.MenuItem saveReport; + private SaveFileDialog saveFileDialog; public Report( Account account , IHistoricalQuoteProvider historicalQuoteProvider ) *************** *** 46,49 **** --- 51,55 ---- this.account = account; this.historicalQuoteProvider = historicalQuoteProvider; + this.initializeComponent(); } public Report( AccountReport accountReport ) *************** *** 51,56 **** this.accountReport = accountReport; this.account = this.accountReport.Account; } ! /// <summary> /// Populates the form and displays itself --- 57,87 ---- this.accountReport = accountReport; this.account = this.accountReport.Account; + this.initializeComponent(); } ! ! private void initializeComponent() ! { ! this.mainMenu = new MainMenu(); ! ! this.saveAccount = new MenuItem(); ! this.saveAccount.Text = "Save Account"; ! ! this.saveReport = new MenuItem(); ! this.saveReport.Text = "Save Report"; ! ! this.file = new MenuItem(); ! this.file.Text = "File"; ! this.mainMenu.MenuItems.AddRange(new MenuItem[] ! {this.file}); ! ! this.file.MenuItems.AddRange(new MenuItem[] ! {this.saveAccount, ! this.saveReport}); ! this.Menu = this.mainMenu; ! this.saveAccount.Click += new System.EventHandler(this.saveAccount_Click); ! this.saveReport.Click += new System.EventHandler(this.saveReport_Click); ! ! } ! /// <summary> /// Populates the form and displays itself *************** *** 104,107 **** --- 135,203 ---- return (DateTime)returnValue; } + + #region save account or report + + private void saveAccount_Click(object sender, System.EventArgs e) + { + this.saveAccountOrReport((MenuItem)sender); + } + + + private void saveReport_Click(object sender, System.EventArgs e) + { + this.saveAccountOrReport((MenuItem)sender); + } + + private void saveAccountOrReport_setSaveFileDialog(MenuItem sender) + { + this.saveFileDialog = new SaveFileDialog(); + if(sender.Text.EndsWith("Report")) + //if text property of the menu item sender contains at the end + // the word "Report", then it will be saved an account Report object + { + this.saveFileDialog.DefaultExt = "qPr"; + this.saveFileDialog.InitialDirectory = + System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"]; + } + else + //else the text property of the menu item sender contains at the end + // the word "Account"; so it will be saved an account object + { + this.saveFileDialog.DefaultExt = "qPa"; + this.saveFileDialog.InitialDirectory = + System.Configuration.ConfigurationSettings.AppSettings["AccountsArchive"]; + } + + this.saveFileDialog.AddExtension = true; + this.saveFileDialog.CreatePrompt = true; + this.saveFileDialog.OverwritePrompt = true; + this.saveFileDialog.Title = sender.Text; + //the saveFileDialog title is the same as the + //menu item clicked by the user + this.saveFileDialog.CheckPathExists = true; + } + + private void saveAccountOrReport(MenuItem sender) + { + this.saveAccountOrReport_setSaveFileDialog(sender); + this.saveFileDialog.FileOk += new System.ComponentModel.CancelEventHandler(this.fileOk_Click); + this.saveFileDialog.ShowDialog(); + } + + private void fileOk_Click(object sender, System.ComponentModel.CancelEventArgs e) + { + if(((SaveFileDialog)sender).Title.EndsWith("Report")) + QuantProject.ADT.FileManaging.ObjectArchiver.Archive(this.accountReport, + this.saveFileDialog.FileName); + else + QuantProject.ADT.FileManaging.ObjectArchiver.Archive(this.account, + this.saveFileDialog.FileName); + } + + + + + #endregion + // /// <summary> // /// Imports an existing account report |
|
From: Glauco S. <gla...@us...> - 2005-05-30 18:35:12
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18279/b3_Data/DataProviders/Caching Added Files: MissingQuoteException.cs Log Message: Thrown when a quote is asked, but it is not present in the database --- NEW FILE: MissingQuoteException.cs --- /* QuantProject - Quantitative Finance Library MissingQuoteException.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Data.DataProviders.Caching { /// <summary> /// Thrown when a quote is requested, but it is not present in /// the database /// </summary> public class MissingQuoteException : Exception { public MissingQuoteException( string ticker , DateTime dateTime ) { // // TODO: Add constructor logic here // } } } |
|
From: Glauco S. <gla...@us...> - 2005-05-30 18:32:44
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16906/b7_Scripts/WalkForwardTesting/WalkForwardOneRank Modified Files: BestPerformingTickers.cs Log Message: - the MissingQuoteException is handled now Index: BestPerformingTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/BestPerformingTickers.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** BestPerformingTickers.cs 26 May 2005 23:36:18 -0000 1.8 --- BestPerformingTickers.cs 30 May 2005 18:32:35 -0000 1.9 *************** *** 30,33 **** --- 30,34 ---- using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; + using QuantProject.Data.DataProviders.Caching; using QuantProject.Scripts.SimpleTesting; *************** *** 133,144 **** foreach ( string ticker in eligibleTickers.Keys ) { ! setTickers_build_addTickerWithGoodness( ticker , dateTime ); ! this.calculatedTickers++; ! if ( Math.Floor( this.calculatedTickers / this.tickersWithGoodness.Count * 100 ) > ! Math.Floor( ( this.calculatedTickers - 1 ) / this.tickersWithGoodness.Count * 100 ) ) ! // a new time percentage point has been elapsed ! this.NewProgress( this , new NewProgressEventArgs( ! Convert.ToInt32( Math.Floor( this.calculatedTickers / eligibleTickers.Count * 100 ) ) , ! 100 ) ); } for ( int index=this.tickersWithGoodness.Count - 1 ; --- 134,153 ---- foreach ( string ticker in eligibleTickers.Keys ) { ! try ! { ! setTickers_build_addTickerWithGoodness( ticker , dateTime ); ! this.calculatedTickers++; ! if ( Math.Floor( this.calculatedTickers / this.tickersWithGoodness.Count * 100 ) > ! Math.Floor( ( this.calculatedTickers - 1 ) / this.tickersWithGoodness.Count * 100 ) ) ! // a new time percentage point has been elapsed ! this.NewProgress( this , new NewProgressEventArgs( ! Convert.ToInt32( Math.Floor( this.calculatedTickers / eligibleTickers.Count * 100 ) ) , ! 100 ) ); ! } ! catch ( MissingQuoteException exception ) ! { ! // the given ticker has not quotes for alle the inSample period ! string doNothing = exception.Message; ! } } for ( int index=this.tickersWithGoodness.Count - 1 ; |
|
From: Glauco S. <gla...@us...> - 2005-05-30 18:31:24
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16205/b3_Data/DataProviders/Caching Modified Files: Cache.cs Log Message: - EarlyDateException is not used anymore - MissingQuoteException has been introduced Index: Cache.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching/Cache.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Cache.cs 26 May 2005 23:24:02 -0000 1.1 --- Cache.cs 30 May 2005 18:31:15 -0000 1.2 *************** *** 131,134 **** --- 131,139 ---- } #endregion + // private void getQuote_checkEarlyDateException( DateTime dateTime ) + // { + // if ( dateTime < ConstantsProvider.MinQuoteDateTime ) + // throw new EarlyDateException( dateTime ); + // } #region addPage // private void addTicker( string ticker ) *************** *** 157,175 **** // } // } ! private void addPage( string ticker , DateTime dateTime , QuoteField quoteField ) { if ( this.Count + 1 > this.maxNumPages ) this.removeUnusedPages(); ! CachePage cachePage = new CachePage( ticker , dateTime.Year , quoteField ); cachePage.LoadData(); ! this.Add( this.getKey( ticker , dateTime.Year , quoteField ) , cachePage ); this.currentNumPages ++ ; } #endregion public double GetQuote( string ticker , DateTime dateTime , QuoteField quoteField ) { double returnValue; ! if ( dateTime < ConstantsProvider.MinQuoteDateTime ) ! throw new EarlyDateException( dateTime ); if ( !this.ContainsKey( this.getKey( ticker , dateTime.Year , quoteField ) ) ) // the instrument instrumentKey has not been cached yet, for the given bar component --- 162,183 ---- // } // } ! private void addPage( string ticker , int year , QuoteField quoteField ) { if ( this.Count + 1 > this.maxNumPages ) this.removeUnusedPages(); ! CachePage cachePage = new CachePage( ticker , year , quoteField ); cachePage.LoadData(); ! this.Add( this.getKey( ticker , year , quoteField ) , cachePage ); this.currentNumPages ++ ; } + private void addPage( string ticker , DateTime dateTime , QuoteField quoteField ) + { + this.addPage( ticker , dateTime.Year , quoteField ); + } #endregion public double GetQuote( string ticker , DateTime dateTime , QuoteField quoteField ) { double returnValue; ! // this.getQuote_checkEarlyDateException( dateTime ); if ( !this.ContainsKey( this.getKey( ticker , dateTime.Year , quoteField ) ) ) // the instrument instrumentKey has not been cached yet, for the given bar component *************** *** 178,181 **** --- 186,199 ---- { CachePage cachePage = this.getCachePage( ticker , dateTime , quoteField ); + if ( cachePage.Quotes.Count == 0 ) + { + this.addPage( ticker , dateTime.Year - 1 , quoteField ); + cachePage = this.getCachePage( ticker , dateTime.Year - 1 , quoteField ); + if ( cachePage.Quotes.Count == 0 ) + // ticker has no quotes both in the dateTime year and in the + // previous year + throw new MissingQuoteException( ticker , dateTime ); + } + if ( cachePage.Rank != this.currentPageRank ) { |
|
From: Glauco S. <gla...@us...> - 2005-05-30 18:30:37
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15544/b3_Data/DataProviders/Caching Modified Files: CachePage.cs Log Message: - CachePage is not an Hashtable anymore Index: CachePage.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching/CachePage.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CachePage.cs 26 May 2005 23:24:35 -0000 1.1 --- CachePage.cs 30 May 2005 18:29:59 -0000 1.2 *************** *** 31,35 **** /// A page containing quotes in main memory (fetched from the disk) /// </summary> ! public class CachePage : Hashtable { private string ticker; --- 31,35 ---- /// A page containing quotes in main memory (fetched from the disk) /// </summary> ! public class CachePage { private string ticker; |
|
From: Glauco S. <gla...@us...> - 2005-05-30 18:28:22
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14590/b3_Data Modified Files: b3_Data.csproj Log Message: - removed DataProviders\Caching\EarlyDateException.cs - added DataProviders\Caching\MissingQuoteException.cs Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** b3_Data.csproj 26 May 2005 23:17:43 -0000 1.28 --- b3_Data.csproj 30 May 2005 18:28:13 -0000 1.29 *************** *** 193,197 **** /> <File ! RelPath = "DataProviders\Caching\EarlyDateException.cs" SubType = "Code" BuildAction = "Compile" --- 193,197 ---- /> <File ! RelPath = "DataProviders\Caching\MissingQuoteException.cs" SubType = "Code" BuildAction = "Compile" |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:44:19
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28833/b2_DataAccess Modified Files: DataBase.cs Log Message: getHistory_common() private method has been introduced: now an History can be asked specifying the first date and the second date. Index: DataBase.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/DataBase.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DataBase.cs 9 Jan 2005 22:22:36 -0000 1.5 --- DataBase.cs 26 May 2005 23:44:07 -0000 1.6 *************** *** 84,92 **** #region "GetHistory" ! private static History getHistory_try( string instrumentKey , QuoteField quoteField ) { History history = new History(); string commandString = ! "select * from quotes where quTicker='" + instrumentKey + "'"; OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter( commandString , oleDbConnection ); DataTable dataTable = new DataTable(); --- 84,95 ---- #region "GetHistory" ! private static History getHistory_try( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) { History history = new History(); string commandString = ! "select * from quotes where (quTicker='" + instrumentKey + "') " + ! "and (quDate>=" + SQLBuilder.GetDateConstant( firstDate ) + ") " + ! "and (quDate<=" + SQLBuilder.GetDateConstant( lastDate ) + ")"; OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter( commandString , oleDbConnection ); DataTable dataTable = new DataTable(); *************** *** 95,168 **** return history; } ! /// <summary> ! /// Returns the full history for the instrument and the specified quote field ! /// </summary> ! /// <param name="instrumentKey">Identifier (ticker) for the instrument whose story ! /// has to be returned</param> ! /// <param name="quoteField">Discriminates among Open, High, Low and Closure</param> ! /// <returns>The history for the given instrument and quote field</returns> ! public static History GetHistory( string instrumentKey , QuoteField quoteField ) ! { ! History history; ! try ! { ! history = getHistory_try( instrumentKey , quoteField ); ! } ! catch (Exception ex) ! { ! MessageBox.Show( ex.ToString() ); ! history = null; ! } ! return history; ! } ! #endregion ! // #region "GetHistories" ! // private static Single getHistories_try_getValue( DataRow dataRow , DateTime dateTime , ! // QuoteField quoteField ) ! // { ! // Single returnValue; ! // if ( quoteField == QuoteField.cl ) ! // returnValue = (Single)dataRow[ getFieldName( quoteField ) ]; ! // else ! // returnValue = (Single)dataRow[ getFieldName( quoteField ) ] * ! // (Single)dataRow[ "quAdjustedClose" ] / (Single)dataRow[ "quClose" ]; ! // return returnValue; ! // } ! // private static Hashtable getHistories_try( string instrumentKey , Hashtable barComponents , DateTime startDateTime , DateTime endDateTime ) ! // { ! // Hashtable histories = new Hashtable(); ! // foreach (BarComponent barComponent in barComponents.Keys) ! // histories.Add( barComponent , new History() ); ! // string commandString = ! // "select * from quotes where quTicker='" + instrumentKey + "' and " + ! // "quDate>=" + SQLBuilder.GetDateConstant( startDateTime ) + " and " + ! // "quDate<=" + SQLBuilder.GetDateConstant( endDateTime ); ! // OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter( commandString , oleDbConnection ); ! // DataSet dataSet = new DataSet(); ! // oleDbDataAdapter.Fill( dataSet , "history" ); ! // foreach ( DataRow dataRow in dataSet.Tables[ "history" ].Rows ) ! // foreach ( BarComponent barComponent in barComponents.Keys ) ! // ((History) histories[ barComponent ]).Add( (DateTime) dataRow[ "quDate" ] , ! // getHistories_try_getValue( dataRow , (DateTime) dataRow[ "quDate" ] , barComponent ) ); ! //// ((History) histories[ barComponent ]).Add( (DateTime) dataRow[ "quDate" ] , ! //// dataRow[ getFieldName( barComponent ) ] ); ! // return histories; ! // } ! // public static Hashtable GetHistories( string instrumentKey , Hashtable barComponents , DateTime startDateTime , DateTime endDateTime ) ! // { ! // Hashtable histories; ! // try ! // { ! // histories = getHistories_try( instrumentKey , barComponents , startDateTime , endDateTime ); ! // } ! // catch (Exception ex) ! // { ! // MessageBox.Show( ex.ToString() ); ! // histories = null; ! // } ! // return histories; ! // } ! // #endregion } } --- 98,143 ---- return history; } ! private static History getHistory_common( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) ! { ! History history; ! try ! { ! history = getHistory_try( instrumentKey , quoteField , firstDate , lastDate ); ! } ! catch (Exception ex) ! { ! MessageBox.Show( ex.ToString() ); ! history = null; ! } ! return history; ! } ! /// <summary> ! /// Returns the full history for the instrument and the specified quote field ! /// </summary> ! /// <param name="instrumentKey">Identifier (ticker) for the instrument whose story ! /// has to be returned</param> ! /// <param name="quoteField">Discriminates among Open, High, Low and Closure</param> ! /// <returns>The history for the given instrument and quote field</returns> ! public static History GetHistory( string instrumentKey , QuoteField quoteField ) ! { ! return getHistory_common( instrumentKey , quoteField , DateTime.MinValue , DateTime.MaxValue ); ! } ! /// <summary> ! /// Returns the history for the instrument and the specified quote field ! /// </summary> ! /// <param name="instrumentKey">Identifier (ticker) for the instrument whose story ! /// has to be returned</param> ! /// <param name="quoteField">Discriminates among Open, High, Low and Closure</param> ! /// <param name="firstDate">First date for quotes to be fetched</param> ! /// <param name="lastDate">Last date for quotes to be fetched</param> ! /// <returns>The history for the given instrument and quote field</returns> ! public static History GetHistory( string instrumentKey , QuoteField quoteField , ! DateTime firstDate , DateTime lastDate ) ! { ! return getHistory_common( instrumentKey , quoteField , firstDate , lastDate ); ! } ! #endregion } } |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:42:33
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28522/b3_Data/DataProviders Modified Files: HistoricalDataProvider.cs Log Message: The private Cache privateCache object is used now Index: HistoricalDataProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/HistoricalDataProvider.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** HistoricalDataProvider.cs 20 Jan 2005 01:21:21 -0000 1.7 --- HistoricalDataProvider.cs 26 May 2005 23:42:25 -0000 1.8 *************** *** 24,29 **** --- 24,31 ---- using System.Collections; using System.Data; + using QuantProject.ADT; using QuantProject.ADT.Histories; + using QuantProject.Data.DataProviders.Caching; using QuantProject.DataAccess; using QuantProject.DataAccess.Tables; *************** *** 36,40 **** public class HistoricalDataProvider { ! private static Hashtable cachedHistories = new Hashtable(); public HistoricalDataProvider() --- 38,66 ---- public class HistoricalDataProvider { ! private static Hashtable cachedHistories = new Hashtable(); ! ! private static Cache privateCache = new Cache(); ! ! ! private static DateTime minDate = DateTime.MinValue; ! private static DateTime maxDate = DateTime.MaxValue; ! ! /// <summary> ! /// When defined, sets the minimum DateTime to be cached ! /// </summary> ! public static DateTime MinDate ! { ! get { return minDate; } ! set { minDate = value; } ! } ! ! /// <summary> ! /// When defined, sets the maximum DateTime to be cached ! /// </summary> ! public static DateTime MaxDate ! { ! get { return maxDate; } ! set { maxDate = value; } ! } public HistoricalDataProvider() *************** *** 97,100 **** --- 123,140 ---- } + private static History getHistory( string ticker , QuoteField quoteField , + DateTime firstDate , DateTime lastDate ) + { + History returnValue = new History(); + DateTime currentDate = firstDate; + while ( currentDate <= lastDate ) + { + returnValue.Add( currentDate , privateCache.GetQuote( + ticker , currentDate , quoteField ) ); + currentDate = currentDate.AddDays( 1 ); + } + return returnValue; + } + public static History GetOpenHistory( string instrumentKey ) { *************** *** 122,125 **** --- 162,186 ---- } + public static History GetAdjustedCloseHistory( string ticker , + DateTime firstDate , DateTime lastDate ) + { + return getHistory( ticker , QuoteField.AdjustedClose , + firstDate , lastDate ); + } + + private static History cache_getHistory( string instrumentKey , QuoteField quoteField ) + { + History returnValue; + if ( ( MinDate != DateTime.MinValue ) && + ( MaxDate != DateTime.MaxValue ) ) + // the script has set a min date value and a max date value for the historical quotes + returnValue = DataBase.GetHistory( instrumentKey , quoteField , + MinDate , MaxDate ); + else + // the script has NOT set a min date value and a max date value for the historical quotes + returnValue = DataBase.GetHistory( instrumentKey , quoteField ); + return returnValue; + } + private static void cache( string instrumentKey , QuoteField quoteField ) { *************** *** 127,132 **** // no component at all for the instrument instrumentKey has been cached yet cachedHistories.Add( instrumentKey , new Hashtable() ); ((Hashtable)cachedHistories[ instrumentKey ]).Add( quoteField , ! DataBase.GetHistory( instrumentKey , quoteField ) ); } // public static double GetMarketValue( string instrumentKey , ExtendedDateTime extendedDateTime ) --- 188,194 ---- // no component at all for the instrument instrumentKey has been cached yet cachedHistories.Add( instrumentKey , new Hashtable() ); + History quoteHistory = cache_getHistory( instrumentKey , quoteField ); ((Hashtable)cachedHistories[ instrumentKey ]).Add( quoteField , ! quoteHistory ); } // public static double GetMarketValue( string instrumentKey , ExtendedDateTime extendedDateTime ) *************** *** 176,180 **** { double returnValue; ! double adjustedClose = getQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.AdjustedClose ); if ( extendedDateTime.BarComponent == BarComponent.Close ) --- 238,242 ---- { double returnValue; ! double adjustedClose = privateCache.GetQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.AdjustedClose ); if ( extendedDateTime.BarComponent == BarComponent.Close ) *************** *** 183,189 **** // extendedDateTime.BarComponent is equal to BarComponent.Open { ! double open = getQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.Open ); ! double close = getQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.Close ); returnValue = open * adjustedClose / close; --- 245,251 ---- // extendedDateTime.BarComponent is equal to BarComponent.Open { ! double open = privateCache.GetQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.Open ); ! double close = privateCache.GetQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.Close ); returnValue = open * adjustedClose / close; *************** *** 209,221 **** return returnValue; } ! public static bool WasExchanged( string instrumentKey , ExtendedDateTime extendedDateTime ) { ! ExtendedDateTime atClose = new ExtendedDateTime( ! extendedDateTime.DateTime , BarComponent.Close ); ! double marketValue = GetRawMarketValue( instrumentKey , ! atClose ); // forces caching if needed ! return ( (History) ((Hashtable) ! cachedHistories[ instrumentKey ])[ QuoteField.Close ] ).ContainsKey( ! extendedDateTime.DateTime ); } --- 271,288 ---- return returnValue; } ! // public static bool WasExchanged( string instrumentKey , ExtendedDateTime extendedDateTime ) ! // { ! // ExtendedDateTime atClose = new ExtendedDateTime( ! // extendedDateTime.DateTime , BarComponent.Close ); ! // double marketValue = GetRawMarketValue( instrumentKey , ! // atClose ); // forces caching if needed ! // History instrumentQuotes = ! // (History)((Hashtable)cachedHistories[ instrumentKey ])[ QuoteField.Close ]; ! // bool returnValue = instrumentQuotes.ContainsKey( extendedDateTime.DateTime ); ! // return returnValue; ! // } ! public static bool WasExchanged( string ticker , ExtendedDateTime extendedDateTime ) { ! return privateCache.WasExchanged( ticker , extendedDateTime ); } |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:37:01
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27408/b7_Scripts/WalkForwardTesting/WalkForwardOneRank Modified Files: ChosenTickers.cs Log Message: Better memory managment: Accounts are released immediately now (only Goodness is kept for subsequent use) Index: ChosenTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/ChosenTickers.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ChosenTickers.cs 20 Jan 2005 01:17:16 -0000 1.5 --- ChosenTickers.cs 26 May 2005 23:36:53 -0000 1.6 *************** *** 67,71 **** ( index <= ( bestPerformingTickers.Count - 1 ) ) ) { ! string ticker = ((Account)bestPerformingTickers[ index ]).Key; if ( account.DataStreamer.IsExchanged( ticker ) ) setTickers_build_handleTicker( ticker , --- 67,71 ---- ( index <= ( bestPerformingTickers.Count - 1 ) ) ) { ! string ticker = (string)bestPerformingTickers[ index ]; if ( account.DataStreamer.IsExchanged( ticker ) ) setTickers_build_handleTicker( ticker , |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:36:30
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27324/b7_Scripts/WalkForwardTesting/WalkForwardOneRank Modified Files: BestPerformingTickers.cs Log Message: Better memory managment: Accounts are released immediately now (only Goodness is kept for subsequent use) Index: BestPerformingTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/BestPerformingTickers.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** BestPerformingTickers.cs 20 Jan 2005 01:14:20 -0000 1.7 --- BestPerformingTickers.cs 26 May 2005 23:36:18 -0000 1.8 *************** *** 24,27 **** --- 24,28 ---- using QuantProject.ADT; + using QuantProject.ADT.FileManaging; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; *************** *** 47,50 **** --- 48,52 ---- private ArrayList eligibleAccounts; + private SortedList tickersWithGoodness; private DateTime lastUpdate; *************** *** 61,64 **** --- 63,67 ---- this.numberDaysForPerformanceCalculation = numberDaysForPerformanceCalculation; this.eligibleAccounts = new ArrayList(); + this.tickersWithGoodness = new SortedList(); } *************** *** 66,90 **** #region SetTickers ! private void setTickers_build_addAccount( string ticker , DateTime dateTime ) { HistoricalEndOfDayTimer historicalEndOfDayTimer = new HistoricalEndOfDayTimer( ! new EndOfDayDateTime( dateTime.AddYears( -1 ).AddDays( -1 ) , EndOfDaySpecificTime.MarketOpen ) ); ComparableAccount account = new ComparableAccount( ticker , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) ); ! OneRank oneRank = new OneRank( account , ! dateTime.AddDays( this.numberDaysForPerformanceCalculation ) ); double goodness = account.Goodness; // forces Goodness computation here (for a better ProgressBar effect) this.eligibleAccounts.Add( account ); } ! private void setTickers_build( EligibleTickers eligibleTickers , DateTime dateTime ) { foreach ( string ticker in eligibleTickers.Keys ) { ! setTickers_build_addAccount( ticker , dateTime ); this.calculatedTickers++; if ( Math.Floor( this.calculatedTickers / eligibleAccounts.Count * 100 ) > --- 69,99 ---- #region SetTickers ! #region setTickers_build_forDebug ! private void setTickers_build_forDebug_addAccount( string ticker , DateTime dateTime ) { HistoricalEndOfDayTimer historicalEndOfDayTimer = new HistoricalEndOfDayTimer( ! new EndOfDayDateTime( dateTime.AddDays( -this.numberDaysForPerformanceCalculation ) , EndOfDaySpecificTime.MarketOpen ) ); ComparableAccount account = new ComparableAccount( ticker , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) ); ! OneRank oneRank = new OneRank( account , dateTime ); double goodness = account.Goodness; // forces Goodness computation here (for a better ProgressBar effect) this.eligibleAccounts.Add( account ); } ! /// <summary> ! /// used to debug insample results ! /// </summary> ! /// <param name="eligibleTickers"></param> ! /// <param name="dateTime"></param> ! private void setTickers_build_forDebug( EligibleTickers eligibleTickers , DateTime dateTime ) { + this.eligibleAccounts.Clear(); foreach ( string ticker in eligibleTickers.Keys ) { ! setTickers_build_forDebug_addAccount( ticker , dateTime ); this.calculatedTickers++; if ( Math.Floor( this.calculatedTickers / eligibleAccounts.Count * 100 ) > *************** *** 99,103 **** index >= this.eligibleAccounts.Count - this.numberBestPerformingTickers ; index-- ) ! this.Add( this.eligibleAccounts[ index ] ); } /// <summary> --- 108,151 ---- index >= this.eligibleAccounts.Count - this.numberBestPerformingTickers ; index-- ) ! { ! ComparableAccount account = (ComparableAccount)this.eligibleAccounts[ index ]; ! this.Add( account ); ! } ! } ! #endregion ! private void setTickers_build_addTickerWithGoodness( string ticker , DateTime dateTime ) ! { ! HistoricalEndOfDayTimer historicalEndOfDayTimer = ! new HistoricalEndOfDayTimer( ! new EndOfDayDateTime( dateTime.AddDays( -this.numberDaysForPerformanceCalculation ) , ! EndOfDaySpecificTime.MarketOpen ) ); ! ComparableAccount account = new ComparableAccount( ticker , historicalEndOfDayTimer , ! new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , ! this.historicalQuoteProvider ) ); ! OneRank oneRank = new OneRank( account , dateTime ); ! this.tickersWithGoodness.Add( account.Key , account.Goodness ); ! } ! private void setTickers_build( EligibleTickers eligibleTickers , DateTime dateTime ) ! { ! this.tickersWithGoodness.Clear(); ! foreach ( string ticker in eligibleTickers.Keys ) ! { ! setTickers_build_addTickerWithGoodness( ticker , dateTime ); ! this.calculatedTickers++; ! if ( Math.Floor( this.calculatedTickers / this.tickersWithGoodness.Count * 100 ) > ! Math.Floor( ( this.calculatedTickers - 1 ) / this.tickersWithGoodness.Count * 100 ) ) ! // a new time percentage point has been elapsed ! this.NewProgress( this , new NewProgressEventArgs( ! Convert.ToInt32( Math.Floor( this.calculatedTickers / eligibleTickers.Count * 100 ) ) , ! 100 ) ); ! } ! for ( int index=this.tickersWithGoodness.Count - 1 ; ! index >= this.tickersWithGoodness.Count - this.numberBestPerformingTickers ; ! index-- ) ! { ! this.Add( this.tickersWithGoodness.GetKey( index ) ); ! } } /// <summary> *************** *** 110,114 **** this.NewProgress( this , new NewProgressEventArgs( 0 , 100 ) ); this.Clear(); ! this.eligibleAccounts.Clear(); this.setTickers_build( eligibleTickers , dateTime ); this.lastUpdate = dateTime; --- 158,162 ---- this.NewProgress( this , new NewProgressEventArgs( 0 , 100 ) ); this.Clear(); ! // this.setTickers_build_forDebug( eligibleTickers , dateTime ); this.setTickers_build( eligibleTickers , dateTime ); this.lastUpdate = dateTime; |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:34:37
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26911/b7_Scripts/WalkForwardTesting/WalkForwardOneRank Modified Files: ComparableAccount.cs Log Message: A time interval of a single day is now used to compute the Account goodness Index: ComparableAccount.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/ComparableAccount.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ComparableAccount.cs 24 Apr 2005 16:26:13 -0000 1.8 --- ComparableAccount.cs 26 May 2005 23:34:29 -0000 1.9 *************** *** 65,69 **** double returnValue; if ( this.accountReport == null ) ! this.accountReport = this.CreateReport( this.Key , 7 , this.EndOfDayTimer.GetCurrentTime() , this.Key , this.historicalQuoteProvider ); --- 65,69 ---- double returnValue; if ( this.accountReport == null ) ! this.accountReport = this.CreateReport( this.Key , 1 , this.EndOfDayTimer.GetCurrentTime() , this.Key , this.historicalQuoteProvider ); |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:32:33
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26527/b4_Business/a1_Financial/a2_Accounting/h5_Reporting Modified Files: AccountReport.cs Log Message: The benchmark equity line time interval, is better computed, now Index: AccountReport.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting/AccountReport.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AccountReport.cs 17 Apr 2005 02:13:52 -0000 1.13 --- AccountReport.cs 26 May 2005 23:32:23 -0000 1.14 *************** *** 248,252 **** { History benchmarkQuotes = HistoricalDataProvider.GetAdjustedCloseHistory( ! this.benchmark ); this.benchmarkEquityLine = benchmarkQuotes.Select( this.EquityHistory ); this.benchmarkEquityLine.Interpolate( this.EquityHistory.Keys , new PreviousInterpolator() ); --- 248,253 ---- { History benchmarkQuotes = HistoricalDataProvider.GetAdjustedCloseHistory( ! this.benchmark , (DateTime)this.EquityHistory.GetKey( 0 ) , ! (DateTime)this.EquityHistory.GetKey( this.EquityHistory.Count - 1 ) ); this.benchmarkEquityLine = benchmarkQuotes.Select( this.EquityHistory ); this.benchmarkEquityLine.Interpolate( this.EquityHistory.Keys , new PreviousInterpolator() ); |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:29:54
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26023/b1_ADT Modified Files: AdvancedSortedList.cs Log Message: - better internal documentation - GetByKeyOrPrevious method has been added Index: AdvancedSortedList.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/AdvancedSortedList.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AdvancedSortedList.cs 1 Dec 2003 15:23:08 -0000 1.2 --- AdvancedSortedList.cs 26 May 2005 23:29:45 -0000 1.3 *************** *** 59,75 **** } ! public int previousIndexOfKey( Object key ) ! { ! if ( ((IComparable)this.GetKey( this.Count - 1 )).CompareTo( key ) < 0 ) ! // the last element key is less then the key to search ! return this.Count - 1; ! else ! // ((IComparable)this.GetKey( this.Count - 1 )).CompareTo( key ) > 0 ! return ! previousIndexOfKey_dicotomicSearch( key , 0 , this.Count - 1 ); ! } public int IndexOfKeyOrPrevious( Object key ) { int indexOfKey = this.IndexOfKey( key ); if ( indexOfKey >= 0 ) --- 59,84 ---- } ! public int previousIndexOfKey( Object key ) ! { ! if ( ((IComparable)this.GetKey( this.Count - 1 )).CompareTo( key ) < 0 ) ! // the last element key is less then the key to search ! return this.Count - 1; ! else ! // ((IComparable)this.GetKey( this.Count - 1 )).CompareTo( key ) > 0 ! return ! previousIndexOfKey_dicotomicSearch( key , 0 , this.Count - 1 ); ! } + /// <summary> + /// Returns the index for the given key. If the key is missing, it returns the + /// index for the next previous element. + /// </summary> + /// <param name="key"></param> + /// <returns></returns> public int IndexOfKeyOrPrevious( Object key ) { + if ( ((IComparable)this.GetKey( 0 )).CompareTo( key ) > 0 ) + // the given key is less then the first key in the sorted list + throw new IndexOfKeyOrPreviousException( (IComparable)this.GetKey( 0 ) , key ); int indexOfKey = this.IndexOfKey( key ); if ( indexOfKey >= 0 ) *************** *** 83,86 **** --- 92,99 ---- return this.GetKey( this.IndexOfKeyOrPrevious( key ) ); } + public object GetByKeyOrPrevious( Object key ) + { + return this[ this.GetKeyOrPrevious( key ) ]; + } public bool IsLastKey( Object key ) { |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:26:49
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25351/b1_ADT Modified Files: ConstantsProvider.cs Log Message: - MinQuoteDateTime has been added - CachePages has been added - PagesToBeRemovedFromCache has been added Index: ConstantsProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ConstantsProvider.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ConstantsProvider.cs 24 Apr 2005 16:21:39 -0000 1.9 --- ConstantsProvider.cs 26 May 2005 23:26:41 -0000 1.10 *************** *** 27,30 **** --- 27,33 ---- public static double MaxNumDaysDownloadedAtEachConnection = 200; public static string FormatWithTwoDecimals = "0:#,#.00"; + public static DateTime MinQuoteDateTime = new DateTime( 1950 , 1 , 1 ); + public static int CachePages = 1000; + public static int PagesToBeRemovedFromCache = 500; // for Garbage Collection } } |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:24:43
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24904 Added Files: CachePage.cs Log Message: A page containing quotes in main memory (fetched from the disk) --- NEW FILE: CachePage.cs --- /* QuantProject - Quantitative Finance Library CachePage.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT.Histories; using QuantProject.DataAccess; namespace QuantProject.Data.DataProviders.Caching { /// <summary> /// A page containing quotes in main memory (fetched from the disk) /// </summary> public class CachePage : Hashtable { private string ticker; private int year; private QuoteField quoteField; private long rank; private History quotes; public long Rank { get { return this.rank; } set { this.rank = value; } } public History Quotes { get { return this.quotes; } } /// <summary> /// Contains (in main memory) data for the given ticker, for the given year, /// for the given quote field (open, high, low, close, volume, adjustedClose ) /// </summary> /// <param name="ticker"></param> /// <param name="year"></param> public CachePage( string ticker , int year , QuoteField quoteField ) { this.ticker = ticker; this.year = year; this.quoteField = quoteField; this.rank = long.MinValue; } /// <summary> /// Loads data from disk to main memory /// </summary> public void LoadData() { this.quotes = DataBase.GetHistory( ticker , quoteField , new DateTime( year , 1 , 1 ) , new DateTime( year , 12 , 31 ) ); } } } |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:24:13
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24785 Added Files: Cache.cs Log Message: Handles quote cashing, from mass storage to main memory --- NEW FILE: Cache.cs --- /* QuantProject - Quantitative Finance Library Cache.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Histories; using QuantProject.DataAccess; namespace QuantProject.Data.DataProviders.Caching { /// <summary> /// Handles quote cashing, from mass storage to main memory /// </summary> public class Cache : Hashtable { /// <summary> /// number of pages currently cached /// </summary> private int currentNumPages; private int maxNumPages; /// <summary> /// rank for the page where it has been peformed the last GetQuote() /// </summary> private long currentPageRank; public int MaxNumPages { get { return this.maxNumPages; } set { this.maxNumPages = value; } } private int pagesToBeRemovedWithGarbageCollection; public int PagesToBeRemovedWithGarbageCollection { get { return this.pagesToBeRemovedWithGarbageCollection; } set { this.pagesToBeRemovedWithGarbageCollection = value; } } public Cache() { this.currentNumPages = 0; this.currentPageRank = 0; this.maxNumPages = ConstantsProvider.CachePages; this.pagesToBeRemovedWithGarbageCollection = ConstantsProvider.PagesToBeRemovedFromCache; } // private Hashtable getQuotes( string ticker ) // { // return ( Hashtable )this[ ticker ]; // } // private Hashtable getQuotes( string ticker , int year ) // { // return ( Hashtable )(this.getQuotes( ticker )[ year ] ); // } // private Hashtable getQuotes( string ticker , DateTime dateTime ) // { // return this.getQuotes( ticker , dateTime.Year ); // } private string getKey( string ticker , int year , QuoteField quoteField ) { string key1 = ticker; string key2 = year.ToString(); string key3 = quoteField.ToString(); string returnValue = key1 + ";" + key2 + ";" + key3; return returnValue; } private CachePage getCachePage( string ticker , int year , QuoteField quoteField ) { return (CachePage)( this[ this.getKey( ticker , year , quoteField ) ] ); } private CachePage getCachePage( string ticker , DateTime dateTime , QuoteField quoteField ) { return this.getCachePage( ticker , dateTime.Year , quoteField ); } #region removeUnusedPages private long removeUnusedPages_getMinPageRankToKeep() { ArrayList arrayList = new ArrayList(); foreach ( string key in this.Keys ) arrayList.Add( ((CachePage)this[ key ]).Rank ); arrayList.Sort(); return (long)arrayList[ this.pagesToBeRemovedWithGarbageCollection ]; } // private void removeCachePage( string ticker , int year , // QuoteField quoteField ) // { // CachePage cachePage = this.getCachePage( ticker , year , quoteField ); // cachePage.Clear(); // this.Remove( this.getKey( ticker , year , quoteField ) ); // this.getQuotes( ticker , year ).Remove( quoteField ); // this.currentNumPages -- ; // } private void removeUnusedPages() { long minPageRankToKeep = removeUnusedPages_getMinPageRankToKeep(); ArrayList keysToBeRemoved = new ArrayList(); foreach ( string key in this.Keys ) { CachePage cachePage = ( CachePage )this[ key ]; if ( cachePage.Rank < minPageRankToKeep ) // the current cache page has not been requested recently keysToBeRemoved.Add( key ); } foreach ( string key in keysToBeRemoved ) this.Remove( key ); } #endregion #region addPage // private void addTicker( string ticker ) // { // if ( !this.ContainsKey( ticker ) ) // { // this.Add( ticker , new Hashtable() ); // } // } // private void addYear( string ticker , int year ) // { // Hashtable quotesForTicker = this.getQuotes( ticker ); // if ( !quotesForTicker.ContainsKey( year ) ) // { // quotesForTicker.Add( year , new Hashtable() ); // } // } // private void addCachePage( string ticker , int year , QuoteField quoteField ) // { // Hashtable quotesForTickerAndYear = this.getQuotes( ticker , year ); // if ( !quotesForTickerAndYear.ContainsKey( quoteField ) ) // { // CachePage cachePage = new CachePage( ticker , year , quoteField ); // cachePage.LoadData(); // quotesForTickerAndYear.Add( quoteField , cachePage ); // } // } private void addPage( string ticker , DateTime dateTime , QuoteField quoteField ) { if ( this.Count + 1 > this.maxNumPages ) this.removeUnusedPages(); CachePage cachePage = new CachePage( ticker , dateTime.Year , quoteField ); cachePage.LoadData(); this.Add( this.getKey( ticker , dateTime.Year , quoteField ) , cachePage ); this.currentNumPages ++ ; } #endregion public double GetQuote( string ticker , DateTime dateTime , QuoteField quoteField ) { double returnValue; if ( dateTime < ConstantsProvider.MinQuoteDateTime ) throw new EarlyDateException( dateTime ); if ( !this.ContainsKey( this.getKey( ticker , dateTime.Year , quoteField ) ) ) // the instrument instrumentKey has not been cached yet, for the given bar component this.addPage( ticker , dateTime , quoteField ); try { CachePage cachePage = this.getCachePage( ticker , dateTime , quoteField ); if ( cachePage.Rank != this.currentPageRank ) { this.currentPageRank ++ ; cachePage.Rank = this.currentPageRank; } returnValue = Convert.ToDouble( cachePage.Quotes.GetByKeyOrPrevious( dateTime ) ); } catch ( IndexOfKeyOrPreviousException ex ) { // the given date is at the beginning of the year and no // date is given for such date string message = ex.Message; // to avoid warning returnValue = this.GetQuote( ticker , new DateTime( dateTime.Year - 1 , 12 , 31 ) , quoteField ); } return returnValue; } public bool WasExchanged( string ticker , ExtendedDateTime extendedDateTime ) { bool returnValue; // forces quote caching this.GetQuote( ticker , extendedDateTime.DateTime , QuoteField.Open ); if ( !((CachePage)this[ this.getKey( ticker , extendedDateTime.DateTime.Year , QuoteField.Open ) ] ).Quotes.ContainsKey( extendedDateTime.DateTime ) ) // the ticker was not exchanged at the given date returnValue = false; else // the ticker was exchanged at the given date returnValue = true; return returnValue; } } } |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:22:04
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24270 Added Files: EarlyDateException.cs Log Message: Thrown when a quote is asked for a too much old date --- NEW FILE: EarlyDateException.cs --- /* QuantProject - Quantitative Finance Library EarlyDateException.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Data.DataProviders.Caching { /// <summary> /// Thrown when a quote is asked for a too much old date /// </summary> public class EarlyDateException : Exception { public EarlyDateException( DateTime dateTime ) { // // TODO: Add constructor logic here // } } } |
|
From: Glauco S. <gla...@us...> - 2005-05-26 23:20:27
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23981/Caching Log Message: Directory /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching added to the repository |