quantproject-developers Mailing List for QuantProject (Page 94)
Brought to you by:
glauco_1
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(7) |
Nov
(103) |
Dec
(67) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(52) |
Feb
(9) |
Mar
(69) |
Apr
(53) |
May
(80) |
Jun
(23) |
Jul
(24) |
Aug
(112) |
Sep
(9) |
Oct
|
Nov
(58) |
Dec
(93) |
| 2005 |
Jan
(90) |
Feb
(93) |
Mar
(61) |
Apr
(56) |
May
(37) |
Jun
(61) |
Jul
(55) |
Aug
(68) |
Sep
(25) |
Oct
(46) |
Nov
(41) |
Dec
(37) |
| 2006 |
Jan
(33) |
Feb
(7) |
Mar
(19) |
Apr
(27) |
May
(73) |
Jun
(49) |
Jul
(83) |
Aug
(66) |
Sep
(45) |
Oct
(16) |
Nov
(15) |
Dec
(7) |
| 2007 |
Jan
(14) |
Feb
(33) |
Mar
|
Apr
(21) |
May
|
Jun
(34) |
Jul
(18) |
Aug
(100) |
Sep
(39) |
Oct
(55) |
Nov
(12) |
Dec
(2) |
| 2008 |
Jan
(120) |
Feb
(133) |
Mar
(129) |
Apr
(104) |
May
(42) |
Jun
(2) |
Jul
(52) |
Aug
(99) |
Sep
(134) |
Oct
|
Nov
(137) |
Dec
(48) |
| 2009 |
Jan
(48) |
Feb
(55) |
Mar
(61) |
Apr
(3) |
May
(2) |
Jun
(1) |
Jul
|
Aug
(51) |
Sep
|
Oct
(7) |
Nov
|
Dec
|
| 2010 |
Jan
(7) |
Feb
(1) |
Mar
(145) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
| 2011 |
Jan
(78) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(88) |
Sep
(6) |
Oct
(1) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Glauco S. <gla...@us...> - 2006-01-11 18:36:48
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20544/b3_Data/DataProviders/Caching Modified Files: Cache.cs Log Message: The ICache interface is implemented Index: Cache.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Caching/Cache.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Cache.cs 30 May 2005 18:31:15 -0000 1.2 --- Cache.cs 11 Jan 2006 18:36:40 -0000 1.3 *************** *** 32,36 **** /// Handles quote cashing, from mass storage to main memory /// </summary> ! public class Cache : Hashtable { /// <summary> --- 32,36 ---- /// Handles quote cashing, from mass storage to main memory /// </summary> ! public class Cache : Hashtable,ICache { /// <summary> |
|
From: Glauco S. <gla...@us...> - 2006-01-11 18:36:13
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20283/b2_DataAccess Modified Files: DataBase.cs Log Message: Code has been formatted: tab are used instead of blanks Index: DataBase.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/DataBase.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DataBase.cs 26 May 2005 23:44:07 -0000 1.6 --- DataBase.cs 11 Jan 2006 18:36:02 -0000 1.7 *************** *** 37,41 **** public class DataBase { ! private static OleDbConnection oleDbConnection = ConnectionProvider.OleDbConnection; public DataBase() --- 37,41 ---- public class DataBase { ! private static OleDbConnection oleDbConnection = ConnectionProvider.OleDbConnection; public DataBase() *************** *** 46,68 **** } ! /// <summary> ! /// Returns the field name corresponding to the quote field ! /// </summary> ! /// <param name="quoteField">Discriminates among Open, High, Low and Closure</param> ! /// <returns>Field name corresponding to the quote field</returns> ! private static string getFieldName( QuoteField quoteField ) ! { ! string fieldName = ""; ! switch ( quoteField ) ! { ! case QuoteField.Open: ! fieldName = "quOpen"; ! break; ! case QuoteField.High: ! fieldName = "quHigh"; ! break; ! case QuoteField.Low: ! fieldName = "quLow"; ! break; case QuoteField.Close: fieldName = "quClose"; --- 46,68 ---- } ! /// <summary> ! /// Returns the field name corresponding to the quote field ! /// </summary> ! /// <param name="quoteField">Discriminates among Open, High, Low and Closure</param> ! /// <returns>Field name corresponding to the quote field</returns> ! private static string getFieldName( QuoteField quoteField ) ! { ! string fieldName = ""; ! switch ( quoteField ) ! { ! case QuoteField.Open: ! fieldName = "quOpen"; ! break; ! case QuoteField.High: ! fieldName = "quHigh"; ! break; ! case QuoteField.Low: ! fieldName = "quLow"; ! break; case QuoteField.Close: fieldName = "quClose"; *************** *** 78,101 **** break; default: ! break; ! } ! return fieldName; ! } #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(); ! oleDbDataAdapter.Fill( dataTable ); ! history.Import( dataTable , "quDate" , getFieldName( quoteField ) ); ! return history; ! } private static History getHistory_common( string instrumentKey , QuoteField quoteField , DateTime firstDate , DateTime lastDate ) --- 78,101 ---- break; default: ! break; ! } ! return fieldName; ! } #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(); ! oleDbDataAdapter.Fill( dataTable ); ! history.Import( dataTable , "quDate" , getFieldName( quoteField ) ); ! return history; ! } private static History getHistory_common( string instrumentKey , QuoteField quoteField , DateTime firstDate , DateTime lastDate ) *************** *** 140,143 **** } #endregion ! } } --- 140,143 ---- } #endregion ! } } |
|
From: Glauco S. <gla...@us...> - 2006-01-11 18:24:41
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16510/b3_Data/DataProviders Modified Files: HistoricalDataProvider.cs Log Message: Added Cache property, to allow to use a non default ICache Index: HistoricalDataProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/HistoricalDataProvider.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** HistoricalDataProvider.cs 31 Jul 2005 20:04:09 -0000 1.9 --- HistoricalDataProvider.cs 11 Jan 2006 18:24:33 -0000 1.10 *************** *** 40,44 **** private static Hashtable cachedHistories = new Hashtable(); ! private static Cache privateCache = new Cache(); --- 40,45 ---- private static Hashtable cachedHistories = new Hashtable(); ! // private static Cache privateCache = new Cache(); ! private static ICache privateCache = new Cache(); *************** *** 64,67 **** --- 65,80 ---- } + /// <summary> + /// Caching class + /// </summary> + public static ICache Cache + { + get { return privateCache; } + set { privateCache = value; } + } + + /// <summary> + /// Provides historical data + /// </summary> public HistoricalDataProvider() { *************** *** 71,75 **** } ! // to be deleted public static void Add( string instrumentKey ) { --- 84,88 ---- } ! // to be deleted public static void Add( string instrumentKey ) { *************** *** 238,243 **** --- 251,262 ---- { double returnValue; + int firstSecond = DateTime.Now.Second; + int firstMillisecond = DateTime.Now.Millisecond; double adjustedClose = privateCache.GetQuote( instrumentKey , extendedDateTime.DateTime , QuoteField.AdjustedClose ); + int secondSecond = DateTime.Now.Second; + int secondMillisecond = DateTime.Now.Millisecond; + int elapsedMillisecond = ( secondSecond - firstSecond ) * + 1000 + ( secondMillisecond - firstMillisecond ); if ( extendedDateTime.BarComponent == BarComponent.Close ) returnValue = adjustedClose; |
|
From: Glauco S. <gla...@us...> - 2006-01-11 18:21:20
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15421/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest Modified Files: WalkForwardOpenToCloseDailyStrategy.cs Log Message: Added commented code, for possible fast testing Index: WalkForwardOpenToCloseDailyStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest/WalkForwardOpenToCloseDailyStrategy.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WalkForwardOpenToCloseDailyStrategy.cs 7 Jan 2006 10:45:07 -0000 1.5 --- WalkForwardOpenToCloseDailyStrategy.cs 11 Jan 2006 18:21:07 -0000 1.6 *************** *** 146,149 **** --- 146,152 ---- DataTable eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); + // SelectorByGroup selectorByGroup = + // new SelectorByGroup( "SP500" , optimizationLastDate ); + // DataTable eligibleTickers = selectorByGroup.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( eligibleTickers, |
|
From: Marco M. <mi...@us...> - 2006-01-08 23:38:51
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30312/b3_Data/DataTables Modified Files: Quotes.cs Log Message: Adde GetFirstValidAdjustedClose and GetFirstValidAdjustedOpen methods Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Quotes.cs 7 Jan 2006 10:56:09 -0000 1.22 --- Quotes.cs 8 Jan 2006 23:38:43 -0000 1.23 *************** *** 870,873 **** --- 870,886 ---- } /// <summary> + /// Gets the first valid adjusted close at the given date + /// </summary> + /// <returns></returns> + public float GetFirstValidAdjustedClose(DateTime date ) + { + object[] keys = new object[1]; + keys[0] = this.GetFirstValidQuoteDate(date.Date); + DataRow foundRow = this.Rows.Find(keys); + if(foundRow==null) + throw new Exception("No quote for such a date!"); + return (float)foundRow[Quotes.AdjustedClose]; + } + /// <summary> /// Gets the first valid raw (not adjusted) open at the given date /// </summary> *************** *** 883,886 **** --- 896,915 ---- } + /// <summary> + /// Gets the first valid adjusted open at the given date + /// </summary> + /// <returns></returns> + public float GetFirstValidAdjustedOpen(DateTime date ) + { + object[] keys = new object[1]; + keys[0] = this.GetFirstValidQuoteDate(date.Date); + DataRow foundRow = this.Rows.Find(keys); + if(foundRow==null) + throw new Exception("No quote for such a date!"); + + return (float)foundRow[Quotes.Open]*((float)foundRow[Quotes.AdjustedClose]/ + (float)foundRow[Quotes.Close]); + } + // public DateTime GetPrecedingDate( DateTime quoteDate , int precedingDays ) // { |
|
From: Marco M. <mi...@us...> - 2006-01-08 23:36:15
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29775/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio Added Files: RunTestingOptimizationCloseToOpen.cs Log Message: RunTestingOptimizationCloseToOpen has been added, for evaluating how good close to open optimization is. --- NEW FILE: RunTestingOptimizationCloseToOpen.cs --- /* QuantProject - Quantitative Finance Library RunTestingOptimizationCloseToOpen.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.IO; using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.EvaluatingOptimizationTechnique.EfficientPortfolio { /// <summary> /// For the evaluation of the optimization technique used by the script /// for the efficient close to open portfolio /// </summary> [Serializable] public class RunTestingOptimizationCloseToOpen { private double[] fitnessesInSample; private double[] fitnessesOutOfSample; private string tickerGroupID; private int numberOfEligibleTickers; private int numberOfTickersToBeChosen; private int numDaysForOptimization; private int populationSizeForGeneticOptimizer; private int generationNumberForGeneticOptimizer; private string benchmark; private DateTime marketDate; private double targetReturn; private PortfolioType portfolioType; private int numDaysAfterLastOptimizationDay; private int numberOfSubsets; private Genome[] genomesToTestOutOfSample; private int numberOfGenomesToTest; public RunTestingOptimizationCloseToOpen(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimization, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime marketDate, double targetReturn, PortfolioType portfolioType, int numDaysAfterLastOptimizationDay, int numberOfSubsets, int numberOfGenomesToTest) { this.numberOfGenomesToTest = numberOfGenomesToTest; this.genomesToTestOutOfSample = new Genome[numberOfGenomesToTest]; this.fitnessesInSample = new double[numberOfGenomesToTest]; this.fitnessesOutOfSample = new double[numberOfGenomesToTest]; this.tickerGroupID = tickerGroupID; this.numberOfEligibleTickers = numberOfEligibleTickers; this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; this.numDaysForOptimization = numDaysForOptimization; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.benchmark = benchmark; this.marketDate = marketDate; this.targetReturn = targetReturn; this.portfolioType = portfolioType; this.numDaysAfterLastOptimizationDay = numDaysAfterLastOptimizationDay; this.numberOfSubsets = numberOfSubsets; } private DataTable getSetOfTickersToBeOptimized(DateTime date) { SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, date); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( temporizedGroup.GetTableOfSelectedTickers(), false, date.AddDays(-this.numDaysForOptimization), date, this.numberOfEligibleTickers, this.benchmark); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); } private double setFitnesses_setFitnessesActually_getFitnessOutOfSample(Genome genome) { double returnValue = 0; foreach(string tickerCode in ((GenomeMeaning)genome.Meaning).Tickers) { double coefficient = 1.0; string ticker = tickerCode; if(ticker.StartsWith("-")) { ticker = ticker.Substring(1,ticker.Length -1); coefficient = -1.0; } DateTime dateOutOfSample = this.marketDate.AddDays(this.numDaysAfterLastOptimizationDay); //returnValue is the single return for the numDaysAfterLastOptimizationDay - th day //after the given market date //Quotes tickerQuotes = new Quotes(ticker, dateOutOfSample, // dateOutOfSample); //returnValue += // (tickerQuotes.GetFirstValidAdjustedOpen(dateOutOfSample.AddDays(1))/ // tickerQuotes.GetFirstValidAdjustedClose(dateOutOfSample) - 1.0)*coefficient; // //returnValue is the average return for the interval between //the given market date and the numDaysAfterLastOptimizationDay - th //day after the given market date Quotes tickerQuotes = new Quotes(ticker, this.marketDate, dateOutOfSample); double close, open; for(int i = 0; i<this.numDaysAfterLastOptimizationDay; i++) { close = tickerQuotes.GetFirstValidAdjustedClose(this.marketDate.AddDays(i)); open = tickerQuotes.GetFirstValidAdjustedOpen(this.marketDate.AddDays(i+1)); returnValue += (open/close - 1.0)*coefficient/this.numDaysAfterLastOptimizationDay; } } return returnValue/genome.Size; } private bool setFitnesses_setFitnessesActually_setGenomesToTestOutOfSample_addGenomes_sharesNoGeneWithGenomesAlreadyAdded(Genome genomeToBeAdded, bool addWorstGenomes) { bool returnValue = true; if(addWorstGenomes) //the first half containing the worst genomes has to be checked { for(int i = 0; i<this.numberOfGenomesToTest/2; i++) { if(this.genomesToTestOutOfSample[i]==null) return true; if(!genomeToBeAdded.SharesNoGeneWith(this.genomesToTestOutOfSample[i])) return false; } } else //the second half containing the best genomes has to be checked { for(int i = 0; i<this.numberOfGenomesToTest/2; i++) { if(this.genomesToTestOutOfSample[this.numberOfGenomesToTest-1-i]==null) return true; if(!genomeToBeAdded.SharesNoGeneWith(this.genomesToTestOutOfSample[this.numberOfGenomesToTest-1-i])) return false; } } return returnValue; } private void setFitnesses_setFitnessesActually_setGenomesToTestOutOfSample_addGenomes(GeneticOptimizer optimizer, bool addWorstGenomes) { Genome currentGenome; Genome previousGenome = null; int numOfDifferentGenomesFound = 0; for(int j = 0; j<this.populationSizeForGeneticOptimizer && numOfDifferentGenomesFound<this.numberOfGenomesToTest/2; j++) { if(addWorstGenomes == true) currentGenome = (Genome)optimizer.CurrentGeneration[j]; else currentGenome = (Genome)optimizer.CurrentGeneration[this.populationSizeForGeneticOptimizer-j-1]; if(this.setFitnesses_setFitnessesActually_setGenomesToTestOutOfSample_addGenomes_sharesNoGeneWithGenomesAlreadyAdded(currentGenome, addWorstGenomes)) //no genes of the current genome are present in the relative half { if(this.genomesToTestOutOfSample[numOfDifferentGenomesFound]!= null) //the first half of the array has already been filled this.genomesToTestOutOfSample[this.numberOfGenomesToTest-1-numOfDifferentGenomesFound]=currentGenome; else//the first half is still empty this.genomesToTestOutOfSample[numOfDifferentGenomesFound] = currentGenome; previousGenome = currentGenome; numOfDifferentGenomesFound++; } } } private void setFitnesses_setFitnessesActually_setGenomesToTestOutOfSample(IGenomeManager genomeManager) { GeneticOptimizer optimizer = new GeneticOptimizer(genomeManager, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, ConstantsProvider.SeedForRandomGenerator); optimizer.Run(false); this.setFitnesses_setFitnessesActually_setGenomesToTestOutOfSample_addGenomes(optimizer, true); this.setFitnesses_setFitnessesActually_setGenomesToTestOutOfSample_addGenomes(optimizer, false); Array.Sort(this.genomesToTestOutOfSample); } private void setFitnesses_setFitnessesActually(IGenomeManager genomeManager) { this.setFitnesses_setFitnessesActually_setGenomesToTestOutOfSample(genomeManager); for(int i = 0; i<this.numberOfGenomesToTest; i++) { this.fitnessesInSample[i]=(this.genomesToTestOutOfSample[i]).Fitness; this.fitnessesOutOfSample[i]= this.setFitnesses_setFitnessesActually_getFitnessOutOfSample(this.genomesToTestOutOfSample[i]); } } private void setFitnesses() { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(this.marketDate); IGenomeManager genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, this.marketDate.AddDays(-this.numDaysForOptimization), this.marketDate, this.numberOfTickersToBeChosen, this.targetReturn, this.portfolioType); this.setFitnesses_setFitnessesActually(genManEfficientCTOPortfolio); } public void Run() { try { this.setFitnesses(); OptimizationTechniqueEvaluator evaluator = new OptimizationTechniqueEvaluator(this.fitnessesInSample, this.fitnessesOutOfSample); this.run_writeToLogFile(evaluator); } catch(Exception ex) { ex = ex; } } private void run_writeToLogFile(OptimizationTechniqueEvaluator evaluator) { double[] averagesInSample = evaluator.GetAveragesOfSubsetsInSample(this.numberOfSubsets); double[] averagesOutOfSample = evaluator.GetAveragesOfSubsetsOutOfSample(this.numberOfSubsets); double r = evaluator.GetCorrelationBetweenFitnesses(); GenomeCounter genomeCounter = new GenomeCounter(this.genomesToTestOutOfSample); int differentEvaluatedGenomes = genomeCounter.TotalEvaluatedGenomes; string pathFile = System.Configuration.ConfigurationSettings.AppSettings["GenericArchive"] + "\\CloseToOpenOptimizationEvaluation.txt"; StreamWriter w = File.AppendText(pathFile); w.WriteLine ("\n----------------------------------------------\r\n"); w.Write("\r\nNew Test for Evaluation of Close To Open Optimization {0}\r", DateTime.Now.ToLongDateString()+ " " +DateTime.Now.ToLongTimeString()); w.Write("\r\nNum days for optimization {0}\r", this.numDaysForOptimization.ToString()); w.Write("\r\nOptimizing market date {0}\r", this.marketDate.ToLongDateString()); w.Write("\r\nMarket date for test (out of sample){0}\r", this.marketDate.AddDays(this.numDaysAfterLastOptimizationDay).ToLongDateString()); w.Write("\r\nNumber of tickers: {0}\r", this.numberOfTickersToBeChosen.ToString()); w.WriteLine ("\n----------------------------------------------"); w.Write("\r\nFitnesses compared: {0}\r", this.fitnessesInSample.Length.ToString()); w.Write("\r\nDifferent evaluated genomes: {0}\r", differentEvaluatedGenomes.ToString()); w.Write("\r\nAverages of the {0} sub sets of fitnesses In Sample:\r", this.numberOfSubsets); // for(int i = 0; i<averagesInSample.Length; i++) w.WriteLine("\n{0}-->{1}", i.ToString(), averagesInSample[i].ToString()); w.WriteLine ("\n\n----------------------------------------------"); w.Write("\r\nAverages of the {0} sub sets of fitnesses Out of Sample:\r", this.numberOfSubsets); // for(int i = 0; i<averagesOutOfSample.Length; i++) w.WriteLine("\n{0}-->{1}", i.ToString(), averagesOutOfSample[i].ToString()); w.WriteLine ("\n\n----------------------------------------------"); // w.Write("\r\nCorrelation coefficient between fitnesses: {0}\r", r.ToString()); w.WriteLine ("\n-----------------End of Test------------------\r\n"); // Update the underlying file. w.Flush(); w.Close(); } } } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29203/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: TestDisplayer.cs LinearCombinationTest.cs Added Files: StrategyType.cs CloseToOpenDailyStrategy.cs Log Message: Close to open strategy type has been added to the TestDisplayer for examining in sample/outOfSample behaviour of genomes (for linear combination strategies) Index: LinearCombinationTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/LinearCombinationTest.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** LinearCombinationTest.cs 10 Aug 2005 16:51:31 -0000 1.3 --- LinearCombinationTest.cs 8 Jan 2006 23:33:52 -0000 1.4 *************** *** 44,48 **** private DateTime lastDate; private GenomeRepresentation genomeRepresentation; ! private bool openToCloseDaily; private IHistoricalQuoteProvider historicalQuoteProvider; --- 44,49 ---- private DateTime lastDate; private GenomeRepresentation genomeRepresentation; ! // private bool openToCloseDaily; ! private StrategyType strategyType; private IHistoricalQuoteProvider historicalQuoteProvider; *************** *** 52,61 **** public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation genomeRepresentation , bool openToCloseDaily ) { this.firstDate = firstDate; this.lastDate = lastDate; this.genomeRepresentation = genomeRepresentation; ! this.openToCloseDaily = openToCloseDaily; } --- 53,63 ---- public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation genomeRepresentation , StrategyType strategyType) { this.firstDate = firstDate; this.lastDate = lastDate; this.genomeRepresentation = genomeRepresentation; ! // this.openToCloseDaily = openToCloseDaily; ! this.strategyType = strategyType; } *************** *** 70,74 **** private void run_setHistoricalQuoteProvider() { ! if ( this.openToCloseDaily ) this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); else --- 72,76 ---- private void run_setHistoricalQuoteProvider() { ! if ( this.strategyType == StrategyType.OpenToCloseDaily ) this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); else *************** *** 79,88 **** string[] signedTickers = GenomeRepresentation.GetSignedTickers( this.genomeRepresentation.SignedTickers ); ! if ( this.openToCloseDaily ) ! this.endOfDayStrategy = new OpenToCloseDailyStrategy( ! this.account , signedTickers ); ! else ! this.endOfDayStrategy = new OpenToCloseWeeklyStrategy( ! this.account , signedTickers ); } private string getDateString( DateTime dateTime ) --- 81,99 ---- string[] signedTickers = GenomeRepresentation.GetSignedTickers( this.genomeRepresentation.SignedTickers ); ! switch (this.strategyType) ! { ! case StrategyType.OpenToCloseDaily: ! this.endOfDayStrategy = new OpenToCloseDailyStrategy( ! this.account , signedTickers ); ! break; ! case StrategyType.OpenToCloseWeekly: ! this.endOfDayStrategy = new OpenToCloseWeeklyStrategy( ! this.account , signedTickers ); ! break; ! case StrategyType.CloseToOpenDaily: ! this.endOfDayStrategy = new CloseToOpenDailyStrategy( ! this.account , signedTickers ); ! break; ! } } private string getDateString( DateTime dateTime ) *************** *** 126,129 **** --- 137,143 ---- new FiveMinutesBeforeMarketCloseEventHandler( this.endOfDayStrategy.FiveMinutesBeforeMarketCloseEventHandler ); + this.historicalEndOfDayTimer.MarketClose += + new MarketCloseEventHandler( + this.endOfDayStrategy.MarketCloseEventHandler ); this.historicalEndOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( --- NEW FILE: StrategyType.cs --- /* QuantProject - Quantitative Finance Library StrategyType.cs Copyright (C) 2004 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Enumeration for strategy types based on linear combination /// </summary> public enum StrategyType { OpenToCloseDaily, OpenToCloseWeekly, CloseToOpenDaily } } --- NEW FILE: CloseToOpenDailyStrategy.cs --- /* QuantProject - Quantitative Finance Library CloseToOpenDailyStrategy.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Strategies; using QuantProject.Business.Timing; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Close To Open daily strategy /// </summary> [Serializable] public class CloseToOpenDailyStrategy : IEndOfDayStrategy { private Account account; private string[] signedTickers; public CloseToOpenDailyStrategy( Account account , string[] signedTickers) { this.account = account; this.signedTickers = signedTickers; } private long marketCloseEventHandler_addOrder_getQuantity( string ticker ) { double accountValue = this.account.GetMarketValue(); double currentTickerAsk = this.account.DataStreamer.GetCurrentAsk( ticker ); double maxPositionValueForThisTicker = accountValue/this.signedTickers.Length; long quantity = Convert.ToInt64( Math.Floor( maxPositionValueForThisTicker / currentTickerAsk ) ); return quantity; } private void marketCloseEventHandler_addOrder( string signedTicker ) { OrderType orderType = GenomeRepresentation.GetOrderType( signedTicker ); string ticker = GenomeRepresentation.GetTicker( signedTicker ); long quantity = marketCloseEventHandler_addOrder_getQuantity( ticker ); Order order = new Order( orderType , new Instrument( ticker ) , quantity ); this.account.AddOrder( order ); } private void marketCloseEventHandler_addOrders() { foreach ( string signedTicker in this.signedTickers ) marketCloseEventHandler_addOrder( signedTicker ); } public void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.marketOpen_closePositions(); } private void marketOpen_closePositions() { ArrayList tickers = new ArrayList(); foreach ( Position position in this.account.Portfolio.Positions ) tickers.Add( position.Instrument.Key ); foreach ( string ticker in tickers ) this.account.ClosePosition( ticker ); } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } public void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { if ( ( this.account.CashAmount == 0 ) && ( this.account.Transactions.Count == 0 ) ) // cash has not been added yet this.account.AddCash( 30000 ); marketCloseEventHandler_addOrders(); } public void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } } } Index: TestDisplayer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/TestDisplayer.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TestDisplayer.cs 10 Aug 2005 16:53:45 -0000 1.5 --- TestDisplayer.cs 8 Jan 2006 23:33:52 -0000 1.6 *************** *** 48,52 **** --- 48,54 ---- private System.Windows.Forms.RadioButton radioButtonOpenToCloseDaily; private System.Windows.Forms.RadioButton radioButtonOpenToCloseWeekly; + private System.Windows.Forms.RadioButton radioButtonCloseToOpenDaily; private GenomeRepresentation lastSelectedGenomeRepresentation; + private StrategyType selectedStrategyType = StrategyType.OpenToCloseDaily; private void testdisplayer() *************** *** 98,178 **** private void InitializeComponent() { ! this.dgBestGenomes = new System.Windows.Forms.DataGrid(); ! this.dtpFirstDate = new System.Windows.Forms.DateTimePicker(); ! this.dtpLastDate = new System.Windows.Forms.DateTimePicker(); ! this.label1 = new System.Windows.Forms.Label(); ! this.radioButtonOpenToCloseDaily = new System.Windows.Forms.RadioButton(); ! this.radioButtonOpenToCloseWeekly = new System.Windows.Forms.RadioButton(); ! ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); ! this.SuspendLayout(); ! // ! // dgBestGenomes ! // ! this.dgBestGenomes.DataMember = ""; ! this.dgBestGenomes.Dock = System.Windows.Forms.DockStyle.Bottom; ! this.dgBestGenomes.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dgBestGenomes.Location = new System.Drawing.Point(0, 125); ! this.dgBestGenomes.Name = "dgBestGenomes"; ! this.dgBestGenomes.Size = new System.Drawing.Size(520, 248); ! this.dgBestGenomes.TabIndex = 0; ! this.dgBestGenomes.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgBestGenomes_MouseUp); ! // ! // dtpFirstDate ! // ! this.dtpFirstDate.Location = new System.Drawing.Point(16, 24); ! this.dtpFirstDate.Name = "dtpFirstDate"; ! this.dtpFirstDate.TabIndex = 1; ! // ! // dtpLastDate ! // ! this.dtpLastDate.Location = new System.Drawing.Point(264, 24); ! this.dtpLastDate.Name = "dtpLastDate"; ! this.dtpLastDate.Size = new System.Drawing.Size(208, 20); ! this.dtpLastDate.TabIndex = 2; ! // ! // label1 ! // ! this.label1.Location = new System.Drawing.Point(32, 64); ! this.label1.Name = "label1"; ! this.label1.Size = new System.Drawing.Size(400, 40); ! this.label1.TabIndex = 3; ! this.label1.Text = "Left click data grid rows to reset dates to the optimization period. Right click " + ! "to preserve date displacements and backtest."; ! // ! // radioButtonOpenToCloseDaily ! // ! this.radioButtonOpenToCloseDaily.Checked = true; ! this.radioButtonOpenToCloseDaily.Location = new System.Drawing.Point(64, 96); ! this.radioButtonOpenToCloseDaily.Name = "radioButtonOpenToCloseDaily"; ! this.radioButtonOpenToCloseDaily.Size = new System.Drawing.Size(144, 24); ! this.radioButtonOpenToCloseDaily.TabIndex = 4; ! this.radioButtonOpenToCloseDaily.TabStop = true; ! this.radioButtonOpenToCloseDaily.Text = "Open To Close Daily"; ! // ! // radioButtonOpenToCloseWeekly ! // ! this.radioButtonOpenToCloseWeekly.Location = new System.Drawing.Point(224, 96); ! this.radioButtonOpenToCloseWeekly.Name = "radioButtonOpenToCloseWeekly"; ! this.radioButtonOpenToCloseWeekly.Size = new System.Drawing.Size(144, 24); ! this.radioButtonOpenToCloseWeekly.TabIndex = 5; ! this.radioButtonOpenToCloseWeekly.Text = "Open To Close Weekly"; ! // ! // TestDisplayer ! // ! this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(520, 373); ! this.Controls.AddRange(new System.Windows.Forms.Control[] { ! this.radioButtonOpenToCloseWeekly, ! this.radioButtonOpenToCloseDaily, ! this.label1, ! this.dtpLastDate, ! this.dtpFirstDate, ! this.dgBestGenomes}); ! this.Name = "TestDisplayer"; ! this.Text = "TestDisplayer"; ! ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).EndInit(); ! this.ResumeLayout(false); ! } #endregion --- 100,193 ---- private void InitializeComponent() { ! this.dgBestGenomes = new System.Windows.Forms.DataGrid(); ! this.dtpFirstDate = new System.Windows.Forms.DateTimePicker(); ! this.dtpLastDate = new System.Windows.Forms.DateTimePicker(); ! this.label1 = new System.Windows.Forms.Label(); ! this.radioButtonOpenToCloseDaily = new System.Windows.Forms.RadioButton(); ! this.radioButtonOpenToCloseWeekly = new System.Windows.Forms.RadioButton(); ! this.radioButtonCloseToOpenDaily = new System.Windows.Forms.RadioButton(); ! ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); ! this.SuspendLayout(); ! // ! // dgBestGenomes ! // ! this.dgBestGenomes.DataMember = ""; ! this.dgBestGenomes.Dock = System.Windows.Forms.DockStyle.Bottom; ! this.dgBestGenomes.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dgBestGenomes.Location = new System.Drawing.Point(0, 157); ! this.dgBestGenomes.Name = "dgBestGenomes"; ! this.dgBestGenomes.Size = new System.Drawing.Size(584, 216); ! this.dgBestGenomes.TabIndex = 0; ! this.dgBestGenomes.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgBestGenomes_MouseUp); ! // ! // dtpFirstDate ! // ! this.dtpFirstDate.Location = new System.Drawing.Point(16, 24); ! this.dtpFirstDate.Name = "dtpFirstDate"; ! this.dtpFirstDate.TabIndex = 1; ! // ! // dtpLastDate ! // ! this.dtpLastDate.Location = new System.Drawing.Point(264, 24); ! this.dtpLastDate.Name = "dtpLastDate"; ! this.dtpLastDate.Size = new System.Drawing.Size(208, 20); ! this.dtpLastDate.TabIndex = 2; ! // ! // label1 ! // ! this.label1.Location = new System.Drawing.Point(32, 64); ! this.label1.Name = "label1"; ! this.label1.Size = new System.Drawing.Size(400, 40); ! this.label1.TabIndex = 3; ! this.label1.Text = "Left click data grid rows to reset dates to the optimization period. Right click " + ! "to preserve date displacements and backtest."; ! // ! // radioButtonOpenToCloseDaily ! // ! this.radioButtonOpenToCloseDaily.Checked = true; ! this.radioButtonOpenToCloseDaily.Location = new System.Drawing.Point(64, 96); ! this.radioButtonOpenToCloseDaily.Name = "radioButtonOpenToCloseDaily"; ! this.radioButtonOpenToCloseDaily.Size = new System.Drawing.Size(144, 24); ! this.radioButtonOpenToCloseDaily.TabIndex = 4; ! this.radioButtonOpenToCloseDaily.TabStop = true; ! this.radioButtonOpenToCloseDaily.Text = "Open To Close Daily"; ! this.radioButtonOpenToCloseDaily.CheckedChanged += new System.EventHandler(this.radioButtonOpenToCloseDaily_CheckedChanged); ! // ! // radioButtonOpenToCloseWeekly ! // ! this.radioButtonOpenToCloseWeekly.Location = new System.Drawing.Point(224, 96); ! this.radioButtonOpenToCloseWeekly.Name = "radioButtonOpenToCloseWeekly"; ! this.radioButtonOpenToCloseWeekly.Size = new System.Drawing.Size(144, 24); ! this.radioButtonOpenToCloseWeekly.TabIndex = 5; ! this.radioButtonOpenToCloseWeekly.Text = "Open To Close Weekly"; ! this.radioButtonOpenToCloseWeekly.CheckedChanged += new System.EventHandler(this.radioButtonOpenToCloseWeekly_CheckedChanged); ! // ! // radioButtonCloseToOpenDaily ! // ! this.radioButtonCloseToOpenDaily.Location = new System.Drawing.Point(64, 128); ! this.radioButtonCloseToOpenDaily.Name = "radioButtonCloseToOpenDaily"; ! this.radioButtonCloseToOpenDaily.Size = new System.Drawing.Size(144, 24); ! this.radioButtonCloseToOpenDaily.TabIndex = 6; ! this.radioButtonCloseToOpenDaily.Text = "Close To Open Daily"; ! this.radioButtonCloseToOpenDaily.CheckedChanged += new System.EventHandler(this.radioButtonCloseToOpenDaily_CheckedChanged); ! // ! // TestDisplayer ! // ! this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(584, 373); ! this.Controls.AddRange(new System.Windows.Forms.Control[] { ! this.radioButtonCloseToOpenDaily, ! this.radioButtonOpenToCloseWeekly, ! this.radioButtonOpenToCloseDaily, ! this.label1, ! this.dtpLastDate, ! this.dtpFirstDate, ! this.dgBestGenomes}); ! this.Name = "TestDisplayer"; ! this.Text = "TestDisplayer"; ! ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).EndInit(); ! this.ResumeLayout(false); ! } #endregion *************** *** 224,228 **** new LinearCombinationTest( this.dtpFirstDate.Value , this.dtpLastDate.Value , genomeRepresentation , ! this.radioButtonOpenToCloseDaily.Checked ); linearCombinationTest.Run(); this.lastSelectedGenomeRepresentation = genomeRepresentation; --- 239,243 ---- new LinearCombinationTest( this.dtpFirstDate.Value , this.dtpLastDate.Value , genomeRepresentation , ! this.selectedStrategyType); linearCombinationTest.Run(); this.lastSelectedGenomeRepresentation = genomeRepresentation; *************** *** 254,257 **** --- 269,296 ---- this.dgBestGenomes_MouseUp_leftButton( sender , e ); } + + private void update_selectedStrategyType() + { + if(this.radioButtonOpenToCloseDaily.Checked) + this.selectedStrategyType = StrategyType.OpenToCloseDaily; + else if(this.radioButtonOpenToCloseWeekly.Checked) + this.selectedStrategyType = StrategyType.OpenToCloseWeekly; + else if(this.radioButtonCloseToOpenDaily.Checked) + this.selectedStrategyType = StrategyType.CloseToOpenDaily; + } + private void radioButtonOpenToCloseDaily_CheckedChanged(object sender, System.EventArgs e) + { + this.update_selectedStrategyType(); + } + + private void radioButtonOpenToCloseWeekly_CheckedChanged(object sender, System.EventArgs e) + { + this.update_selectedStrategyType(); + } + + private void radioButtonCloseToOpenDaily_CheckedChanged(object sender, System.EventArgs e) + { + this.update_selectedStrategyType(); + } } } |
|
From: Marco M. <mi...@us...> - 2006-01-08 23:34:01
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29203/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: Close to open strategy type has been added to the TestDisplayer for examining in sample/outOfSample behaviour of genomes (for linear combination strategies) Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** b7_Scripts.csproj 7 Jan 2006 10:39:03 -0000 1.48 --- b7_Scripts.csproj 8 Jan 2006 23:33:53 -0000 1.49 *************** *** 128,131 **** --- 128,136 ---- /> <File + RelPath = "EvaluatingOptimizationTechnique\EfficientPortfolio\RunTestingOptimizationCloseToOpen.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "EvaluatingOptimizationTechnique\EfficientPortfolio\RunTestingOptimizationOpenToClose.cs" SubType = "Code" *************** *** 384,387 **** --- 389,397 ---- /> <File + RelPath = "WalkForwardTesting\LinearCombination\CloseToOpenDailyStrategy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\GenomeRepresentation.cs" SubType = "Code" *************** *** 424,427 **** --- 434,442 ---- /> <File + RelPath = "WalkForwardTesting\LinearCombination\StrategyType.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\TestDisplayer.cs" SubType = "Form" |
|
From: Marco M. <mi...@us...> - 2006-01-07 11:12:41
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader/TickerSelectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10006/Downloader/TickerSelectors Modified Files: TickerSelectorForm.cs Log Message: SelectorByCloseToOpenVolatility and SelectoByAverageCloseToOpenPerformance can now be called visually. In addition, minor changes have been made to names that appear in the combo box of the visual selector form. Index: TickerSelectorForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerSelectors/TickerSelectorForm.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** TickerSelectorForm.cs 18 Sep 2005 20:53:16 -0000 1.17 --- TickerSelectorForm.cs 7 Jan 2006 11:12:30 -0000 1.18 *************** *** 69,72 **** --- 69,74 ---- private System.Windows.Forms.Splitter splitter1; private System.Windows.Forms.CheckBox checkBoxOnlyWithAtLeastOneWinningDay; + private System.Windows.Forms.TextBox textBoxNumDaysBetweenEachClose; + private System.Windows.Forms.Label labelNumDaysBetweenEachClose; private DataTable tableOfSelectedTickers; *************** *** 82,94 **** this.comboBoxAvailableSelectionRules.Items.Add("Performance"); this.comboBoxAvailableSelectionRules.Items.Add("CloseToCloseVolatility"); this.comboBoxAvailableSelectionRules.Items.Add("CloseToOpenVolatility"); this.comboBoxAvailableSelectionRules.Items.Add("AverageCloseToClosePerformance"); this.comboBoxAvailableSelectionRules.Items.Add("CloseToCloseLinearCorrelation"); ! this.comboBoxAvailableSelectionRules.Items.Add("CloseToOpenLinearCorrelation"); this.comboBoxAvailableSelectionRules.Items.Add("AverageCloseToOpenPerformance"); this.comboBoxAvailableSelectionRules.Items.Add("QuotedAtEachMarketDay"); this.comboBoxAvailableSelectionRules.Items.Add("AverageRawOpenPrice"); this.comboBoxAvailableSelectionRules.Items.Add("WinningOpenToClose"); ! this.comboBoxAvailableSelectionRules.Items.Add("OpenCloseCorrelationToBenchmark"); } --- 84,99 ---- this.comboBoxAvailableSelectionRules.Items.Add("Performance"); this.comboBoxAvailableSelectionRules.Items.Add("CloseToCloseVolatility"); + this.comboBoxAvailableSelectionRules.Items.Add("OpenToCloseVolatility"); this.comboBoxAvailableSelectionRules.Items.Add("CloseToOpenVolatility"); this.comboBoxAvailableSelectionRules.Items.Add("AverageCloseToClosePerformance"); this.comboBoxAvailableSelectionRules.Items.Add("CloseToCloseLinearCorrelation"); ! this.comboBoxAvailableSelectionRules.Items.Add("OpenToCloseLinearCorrelation"); ! this.comboBoxAvailableSelectionRules.Items.Add("AverageOpenToClosePerformance"); this.comboBoxAvailableSelectionRules.Items.Add("AverageCloseToOpenPerformance"); this.comboBoxAvailableSelectionRules.Items.Add("QuotedAtEachMarketDay"); this.comboBoxAvailableSelectionRules.Items.Add("AverageRawOpenPrice"); this.comboBoxAvailableSelectionRules.Items.Add("WinningOpenToClose"); ! this.comboBoxAvailableSelectionRules.Items.Add("OpenToCloseCorrelationToBenchmark"); ! this.comboBoxAvailableSelectionRules.Items.Add("CloseToCloseCorrelationToBenchmark"); } *************** *** 136,139 **** --- 141,145 ---- this.panel2 = new System.Windows.Forms.Panel(); this.groupBoxSelectionRule = new System.Windows.Forms.GroupBox(); + this.checkBoxOnlyWithAtLeastOneWinningDay = new System.Windows.Forms.CheckBox(); this.textBoxMaxStdDev = new System.Windows.Forms.TextBox(); this.labelMinStdDev = new System.Windows.Forms.Label(); *************** *** 154,158 **** this.dataGrid1 = new System.Windows.Forms.DataGrid(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); ! this.checkBoxOnlyWithAtLeastOneWinningDay = new System.Windows.Forms.CheckBox(); this.panel2.SuspendLayout(); this.groupBoxSelectionRule.SuspendLayout(); --- 160,165 ---- this.dataGrid1 = new System.Windows.Forms.DataGrid(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); ! this.textBoxNumDaysBetweenEachClose = new System.Windows.Forms.TextBox(); ! this.labelNumDaysBetweenEachClose = new System.Windows.Forms.Label(); this.panel2.SuspendLayout(); this.groupBoxSelectionRule.SuspendLayout(); *************** *** 235,238 **** --- 242,247 ---- // this.groupBoxSelectionRule.Controls.AddRange(new System.Windows.Forms.Control[] { + this.labelNumDaysBetweenEachClose, + this.textBoxNumDaysBetweenEachClose, this.checkBoxOnlyWithAtLeastOneWinningDay, this.labelMaxStdDev, *************** *** 264,267 **** --- 273,286 ---- this.groupBoxSelectionRule.Text = "Single Selection rule"; // + // checkBoxOnlyWithAtLeastOneWinningDay + // + this.checkBoxOnlyWithAtLeastOneWinningDay.Enabled = false; + this.checkBoxOnlyWithAtLeastOneWinningDay.Location = new System.Drawing.Point(192, 144); + this.checkBoxOnlyWithAtLeastOneWinningDay.Name = "checkBoxOnlyWithAtLeastOneWinningDay"; + this.checkBoxOnlyWithAtLeastOneWinningDay.Size = new System.Drawing.Size(152, 24); + this.checkBoxOnlyWithAtLeastOneWinningDay.TabIndex = 38; + this.checkBoxOnlyWithAtLeastOneWinningDay.Text = "Exclude \"pure\" losers"; + this.toolTip1.SetToolTip(this.checkBoxOnlyWithAtLeastOneWinningDay, "Check if you want to filter only tickers with at least one winning day"); + // // textBoxMaxStdDev // *************** *** 311,315 **** // labelMarketIndexKey // ! this.labelMarketIndexKey.Location = new System.Drawing.Point(88, 208); this.labelMarketIndexKey.Name = "labelMarketIndexKey"; this.labelMarketIndexKey.Size = new System.Drawing.Size(96, 23); --- 330,334 ---- // labelMarketIndexKey // ! this.labelMarketIndexKey.Location = new System.Drawing.Point(16, 208); this.labelMarketIndexKey.Name = "labelMarketIndexKey"; this.labelMarketIndexKey.Size = new System.Drawing.Size(96, 23); *************** *** 320,326 **** // textBoxMarketIndex // ! this.textBoxMarketIndex.Location = new System.Drawing.Point(192, 208); this.textBoxMarketIndex.Name = "textBoxMarketIndex"; ! this.textBoxMarketIndex.Size = new System.Drawing.Size(88, 20); this.textBoxMarketIndex.TabIndex = 28; this.textBoxMarketIndex.Text = ""; --- 339,345 ---- // textBoxMarketIndex // ! this.textBoxMarketIndex.Location = new System.Drawing.Point(120, 208); this.textBoxMarketIndex.Name = "textBoxMarketIndex"; ! this.textBoxMarketIndex.Size = new System.Drawing.Size(56, 20); this.textBoxMarketIndex.TabIndex = 28; this.textBoxMarketIndex.Text = ""; *************** *** 412,424 **** this.dataGrid1.TabIndex = 2; // ! // checkBoxOnlyWithAtLeastOneWinningDay // ! this.checkBoxOnlyWithAtLeastOneWinningDay.Enabled = false; ! this.checkBoxOnlyWithAtLeastOneWinningDay.Location = new System.Drawing.Point(192, 144); ! this.checkBoxOnlyWithAtLeastOneWinningDay.Name = "checkBoxOnlyWithAtLeastOneWinningDay"; ! this.checkBoxOnlyWithAtLeastOneWinningDay.Size = new System.Drawing.Size(152, 24); ! this.checkBoxOnlyWithAtLeastOneWinningDay.TabIndex = 38; ! this.checkBoxOnlyWithAtLeastOneWinningDay.Text = "Exclude \"pure\" losers"; ! this.toolTip1.SetToolTip(this.checkBoxOnlyWithAtLeastOneWinningDay, "Check if you want to filter only tickers with at least one winning day"); // // TickerSelectorForm --- 431,451 ---- this.dataGrid1.TabIndex = 2; // ! // textBoxNumDaysBetweenEachClose // ! this.textBoxNumDaysBetweenEachClose.Location = new System.Drawing.Point(328, 208); ! this.textBoxNumDaysBetweenEachClose.Name = "textBoxNumDaysBetweenEachClose"; ! this.textBoxNumDaysBetweenEachClose.Size = new System.Drawing.Size(32, 20); ! this.textBoxNumDaysBetweenEachClose.TabIndex = 39; ! this.textBoxNumDaysBetweenEachClose.Text = ""; ! this.textBoxNumDaysBetweenEachClose.Visible = false; ! // ! // labelNumDaysBetweenEachClose ! // ! this.labelNumDaysBetweenEachClose.Location = new System.Drawing.Point(184, 208); ! this.labelNumDaysBetweenEachClose.Name = "labelNumDaysBetweenEachClose"; ! this.labelNumDaysBetweenEachClose.Size = new System.Drawing.Size(144, 23); ! this.labelNumDaysBetweenEachClose.TabIndex = 40; ! this.labelNumDaysBetweenEachClose.Text = "Num days betw. each close"; ! this.labelNumDaysBetweenEachClose.Visible = false; // // TickerSelectorForm *************** *** 516,520 **** this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); } ! else if (this.comboBoxAvailableSelectionRules.Text == "CloseToOpenVolatility") { if(this.textBoxGroupID.Text != "") --- 543,547 ---- this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); } ! else if (this.comboBoxAvailableSelectionRules.Text == "OpenToCloseVolatility") { if(this.textBoxGroupID.Text != "") *************** *** 526,530 **** this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); ! } else if (this.comboBoxAvailableSelectionRules.Text == "AverageCloseToClosePerformance") { --- 553,568 ---- this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); ! } ! else if (this.comboBoxAvailableSelectionRules.Text == "CloseToOpenVolatility") ! { ! if(this.textBoxGroupID.Text != "") ! returnValue = new SelectorByCloseToOpenVolatility (this.textBoxGroupID.Text, ! this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, ! this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); ! else ! returnValue = new SelectorByCloseToOpenVolatility (this.tableOfSelectedTickers, ! this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, ! this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); ! } else if (this.comboBoxAvailableSelectionRules.Text == "AverageCloseToClosePerformance") { *************** *** 549,553 **** this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); } ! else if (this.comboBoxAvailableSelectionRules.Text == "CloseToOpenLinearCorrelation") { if(this.textBoxGroupID.Text != "") --- 587,591 ---- this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); } ! else if (this.comboBoxAvailableSelectionRules.Text == "OpenToCloseLinearCorrelation") { if(this.textBoxGroupID.Text != "") *************** *** 560,564 **** this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); } ! else if (this.comboBoxAvailableSelectionRules.Text == "AverageCloseToOpenPerformance") { if(this.textBoxGroupID.Text != "") --- 598,602 ---- this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); } ! else if (this.comboBoxAvailableSelectionRules.Text == "AverageOpenToClosePerformance") { if(this.textBoxGroupID.Text != "") *************** *** 570,574 **** this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); ! } else if (this.comboBoxAvailableSelectionRules.Text == "QuotedAtEachMarketDay") { --- 608,623 ---- this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); ! } ! else if (this.comboBoxAvailableSelectionRules.Text == "AverageCloseToOpenPerformance") ! { ! if(this.textBoxGroupID.Text != "") ! returnValue = new SelectorByAverageCloseToOpenPerformance(this.textBoxGroupID.Text, ! this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, ! this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); ! else ! returnValue = new SelectorByAverageCloseToOpenPerformance(this.tableOfSelectedTickers, ! this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, ! this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); ! } else if (this.comboBoxAvailableSelectionRules.Text == "QuotedAtEachMarketDay") { *************** *** 611,615 **** this.checkBoxOnlyWithAtLeastOneWinningDay.Checked); } ! else if (this.comboBoxAvailableSelectionRules.Text == "OpenCloseCorrelationToBenchmark") { if(this.textBoxGroupID.Text != "") --- 660,664 ---- this.checkBoxOnlyWithAtLeastOneWinningDay.Checked); } ! else if (this.comboBoxAvailableSelectionRules.Text == "OpenToCloseCorrelationToBenchmark") { if(this.textBoxGroupID.Text != "") *************** *** 622,625 **** --- 671,687 ---- this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); } + else if (this.comboBoxAvailableSelectionRules.Text == "CloseToCloseCorrelationToBenchmark") + { + if(this.textBoxGroupID.Text != "") + returnValue = new SelectorByCloseToCloseCorrelationToBenchmark(this.textBoxGroupID.Text, this.textBoxMarketIndex.Text, + this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, + this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text), + Int32.Parse(this.textBoxNumDaysBetweenEachClose.Text)); + else + returnValue = new SelectorByCloseToCloseCorrelationToBenchmark(this.tableOfSelectedTickers, this.textBoxMarketIndex.Text, + this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, + this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text), + Int32.Parse(this.textBoxNumDaysBetweenEachClose.Text)); + } return returnValue; } *************** *** 648,657 **** this.textBoxMaxStdDev.Visible = showControls; ! } private void comboBoxAvailableSelectionRules_SelectedValueChanged(object sender, System.EventArgs e) { if(this.comboBoxAvailableSelectionRules.Text == "QuotedAtEachMarketDay" || ! this.comboBoxAvailableSelectionRules.Text == "OpenCloseCorrelationToBenchmark") { this.setVisibilityForControls_AverageRawOpenPrice(false); this.setVisibilityForControls_WinningOpenToClose(false); --- 710,729 ---- this.textBoxMaxStdDev.Visible = showControls; ! } ! ! private void setVisibilityForControls_NumDaysBetweenEachClose(bool showControls) ! { ! this.labelNumDaysBetweenEachClose.Visible = showControls; ! this.textBoxNumDaysBetweenEachClose.Visible = showControls; ! this.labelMarketIndexKey.Visible = showControls; ! this.textBoxMarketIndex.Visible = showControls; ! } ! private void comboBoxAvailableSelectionRules_SelectedValueChanged(object sender, System.EventArgs e) { if(this.comboBoxAvailableSelectionRules.Text == "QuotedAtEachMarketDay" || ! this.comboBoxAvailableSelectionRules.Text == "OpenToCloseCorrelationToBenchmark") { + this.setVisibilityForControls_NumDaysBetweenEachClose(false); this.setVisibilityForControls_AverageRawOpenPrice(false); this.setVisibilityForControls_WinningOpenToClose(false); *************** *** 661,664 **** --- 733,737 ---- { this.textBoxMarketIndex.Text = ""; + this.setVisibilityForControls_NumDaysBetweenEachClose(false); this.setVisibilityForControls_QuotedAtEachMarketDay(false); this.setVisibilityForControls_WinningOpenToClose(false); *************** *** 668,675 **** --- 741,756 ---- { this.textBoxMarketIndex.Text = ""; + this.setVisibilityForControls_NumDaysBetweenEachClose(false); this.setVisibilityForControls_QuotedAtEachMarketDay(false); this.setVisibilityForControls_AverageRawOpenPrice(false); this.setVisibilityForControls_WinningOpenToClose(true); } + else if(this.comboBoxAvailableSelectionRules.Text == "CloseToCloseCorrelationToBenchmark") + { + this.setVisibilityForControls_QuotedAtEachMarketDay(false); + this.setVisibilityForControls_AverageRawOpenPrice(false); + this.setVisibilityForControls_WinningOpenToClose(false); + this.setVisibilityForControls_NumDaysBetweenEachClose(true); + } else { *************** *** 678,681 **** --- 759,763 ---- this.setVisibilityForControls_AverageRawOpenPrice(false); this.setVisibilityForControls_WinningOpenToClose(false); + this.setVisibilityForControls_NumDaysBetweenEachClose(false); this.checkBoxASCMode.Enabled = true; } |
|
From: Marco M. <mi...@us...> - 2006-01-07 11:08:23
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9427 Removed Files: SelectionType.cs Log Message: SelectionType enumeration has been removed from the project --- SelectionType.cs DELETED --- |
|
From: Marco M. <mi...@us...> - 2006-01-07 11:04:35
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8937/b7_Scripts Modified Files: Scripts.prjx Log Message: Updated #develop project files Index: Scripts.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts.prjx,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Scripts.prjx 28 Dec 2005 23:30:04 -0000 1.17 --- Scripts.prjx 7 Jan 2006 11:04:20 -0000 1.18 *************** *** 28,33 **** <File name=".\TickerSelectionTesting\RunEfficientPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\TickerSelectionTesting\PortfolioType.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <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="" /> --- 28,31 ---- *************** *** 53,58 **** <File name=".\EvaluatingOptimizationTechnique\OptimizationTechniqueEvaluator.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\EvaluatingOptimizationTechnique\EfficientPortfolio\RunTestingOptimizationOpenToClose.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\TickerSelectionTesting\EndOfDayTimerHandlerCTOMultiAccount.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <File name=".\TickerSelectionTesting\RunEfficientCTOPortfolioMultiAccount.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\TickerSelectionTesting\EndOfDayTimerHandlerOTCCTO.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\TickerSelectionTesting\RunEfficientOTCCTOPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> --- 51,54 ---- *************** *** 84,87 **** --- 80,89 ---- <File name=".\TickerSelectionTesting\TestingOTCTypes\EndOfDayTimerHandlerOTCTypes.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\TickerSelectionTesting\TestingOTCTypes\RunEfficientOTCTypes.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\GenomeManagerForEfficientOTCPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\RunEfficientOTCPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\EndOfDayTimerHandlerOTC.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\RunTestOptimizedOTCPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\TestingOTCTypes\GenomeManagerForEfficientOTCTypes.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\TickerSelectionTesting\EndOfDayTimerHandlerOTCTest.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2006-01-07 11:04:01
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8773/b3_Data Modified Files: b3_Data.csproj Log Message: SelectionType enumeration has been removed from the project Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** b3_Data.csproj 7 Jan 2006 10:50:40 -0000 1.34 --- b3_Data.csproj 7 Jan 2006 11:03:45 -0000 1.35 *************** *** 253,261 **** /> <File - RelPath = "Selectors\SelectionType.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "Selectors\SelectorByAbsolutePerformance.cs" SubType = "Code" --- 253,256 ---- |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:56:22
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7476/b2_DataAccess/Tables Modified Files: Quotes.cs Log Message: Methods have been properly renamed. Added new methods for Close To Open data management. Fixed some bugs (tickers without quotes are now excluded from selection). Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Quotes.cs,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Quotes.cs 18 Sep 2005 21:03:43 -0000 1.27 --- Quotes.cs 7 Jan 2006 10:56:09 -0000 1.28 *************** *** 483,491 **** return SqlExecutor.GetDataTable( sql ); } ! /// <summary> ! /// Returns tickers ordered by a close to open volatility index (stdDev of Close To Open ratio) /// </summary> ! public static DataTable GetTickersByCloseToOpenVolatility( bool orderInASCMode, string groupID, DateTime firstQuoteDate, DateTime lastQuoteDate, --- 483,491 ---- return SqlExecutor.GetDataTable( sql ); } ! /// <summary> ! /// Returns tickers ordered by the open to close volatility index (stdDev of OTC ratio) /// </summary> ! public static DataTable GetTickersByOpenToCloseVolatility( bool orderInASCMode, string groupID, DateTime firstQuoteDate, DateTime lastQuoteDate, *************** *** 493,497 **** { string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! "StDev(quotes.quClose/quotes.quOpen) AS CloseToOpenStandDev " + "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + --- 493,497 ---- { string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! "StDev(quotes.quClose/quotes.quOpen - 1) AS OpenToCloseStandDev " + "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + *************** *** 502,506 **** SQLBuilder.GetDateConstant(lastQuoteDate) + "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! "ORDER BY StDev(quotes.quClose/quotes.quOpen)"; string sortDirection = " DESC"; if(orderInASCMode) --- 502,506 ---- SQLBuilder.GetDateConstant(lastQuoteDate) + "GROUP BY tickers.tiTicker, tickers.tiCompanyName " + ! "ORDER BY StDev(quotes.quClose/quotes.quOpen - 1)"; string sortDirection = " DESC"; if(orderInASCMode) *************** *** 537,543 **** /// <summary> ! /// Returns tickers ordered by average close to open performance (in the same bar) /// </summary> ! public static DataTable GetTickersByAverageCloseToOpenPerformance( bool orderInASCMode, string groupID, DateTime firstQuoteDate, DateTime lastQuoteDate, --- 537,543 ---- /// <summary> ! /// Returns tickers ordered by average open to close performance (in the same bar) /// </summary> ! public static DataTable GetTickersByAverageOpenToClosePerformance( bool orderInASCMode, string groupID, DateTime firstQuoteDate, DateTime lastQuoteDate, *************** *** 545,549 **** { string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! "Avg(quotes.quClose/quotes.quOpen) AS AverageCloseToOpenPerformance " + "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + --- 545,549 ---- { string sql = "SELECT TOP " + maxNumOfReturnedTickers + " tickers.tiTicker, tickers.tiCompanyName, " + ! "Avg(quotes.quClose/quotes.quOpen - 1) AS AverageOpenToClosePerformance " + "FROM quotes INNER JOIN (tickers INNER JOIN tickers_tickerGroups " + "ON tickers.tiTicker = tickers_tickerGroups.ttTiId) " + *************** *** 667,680 **** /// <summary> ! /// returns the average close to open performance value for the given ticker in the specified interval /// </summary> ! public static double GetAverageCloseToOpenPerformance( string ticker, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate) { DataTable dt; string sql = "SELECT quotes.quTicker, " + ! "Avg([quClose]/[quOpen]) AS AverageCloseToOpenPerformance " + "FROM quotes WHERE quTicker ='" + ticker + "' " + --- 667,681 ---- /// <summary> ! /// returns the average open to close performance ! /// for the given ticker in the specified interval /// </summary> ! public static double GetAverageOpenToClosePerformance(string ticker, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate) { DataTable dt; string sql = "SELECT quotes.quTicker, " + ! "Avg([quClose]/[quOpen] - 1) AS AverageOpenToClosePerformance " + "FROM quotes WHERE quTicker ='" + ticker + "' " + *************** *** 683,690 **** " GROUP BY quotes.quTicker"; dt = SqlExecutor.GetDataTable( sql ); ! if(dt.Rows.Count==0) ! return 0; ! else ! return (double)dt.Rows[0]["AverageCloseToOpenPerformance"]; } --- 684,688 ---- " GROUP BY quotes.quTicker"; dt = SqlExecutor.GetDataTable( sql ); ! return (double)dt.Rows[0]["AverageOpenToClosePerformance"]; } *************** *** 715,718 **** --- 713,737 ---- /// <summary> + /// returns the standard deviation of the open to close ratio + /// for the given ticker in the specified interval + /// </summary> + public static double GetOpenToCloseStandardDeviation( string ticker, + DateTime firstQuoteDate, + DateTime lastQuoteDate) + + { + DataTable dt; + string sql = "SELECT quotes.quTicker, " + + "StDev(quotes.quClose/quotes.quOpen - 1) AS OpenToCloseStandDev " + + "FROM quotes WHERE quTicker ='" + + ticker + "' " + + "AND quotes.quDate BETWEEN " + SQLBuilder.GetDateConstant(firstQuoteDate) + + " AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + + " GROUP BY quotes.quTicker"; + dt = SqlExecutor.GetDataTable( sql ); + return (double)dt.Rows[0]["OpenToCloseStandDev"]; + } + + /// <summary> /// returns the standard deviation of the adjusted close to open ratio /// for the given ticker in the specified interval |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:56:22
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7476/b3_Data/DataTables Modified Files: Quotes.cs Log Message: Methods have been properly renamed. Added new methods for Close To Open data management. Fixed some bugs (tickers without quotes are now excluded from selection). Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Quotes.cs 28 Dec 2005 23:27:56 -0000 1.21 --- Quotes.cs 7 Jan 2006 10:56:09 -0000 1.22 *************** *** 117,124 **** /// <summary> ! /// returns tickers ordered by volatility computed with Standard deviation of adjusted ! /// close to open ratio, within the given set of tickers /// </summary> ! public static DataTable GetTickersByCloseToOpenVolatility( bool orderByASC, DataTable setOfTickers, DateTime firstQuoteDate, --- 117,124 ---- /// <summary> ! /// returns tickers ordered by volatility computed with Standard deviation of ! /// open to close ratio, within the given set of tickers /// </summary> ! public static DataTable GetTickersByOpenToCloseVolatility( bool orderByASC, DataTable setOfTickers, DateTime firstQuoteDate, *************** *** 126,148 **** long maxNumOfReturnedTickers) { ! if(!setOfTickers.Columns.Contains("CloseToOpenStandDev")) ! setOfTickers.Columns.Add("CloseToOpenStandDev", System.Type.GetType("System.Double")); foreach(DataRow row in setOfTickers.Rows) { ! row["CloseToOpenStandDev"] = ! QuantProject.DataAccess.Tables.Quotes.GetCloseToOpenStandardDeviation((string)row[0], ! firstQuoteDate, ! lastQuoteDate); } ! DataTable getTickersByVolatility = ExtendedDataTable.CopyAndSort(setOfTickers,"CloseToOpenStandDev", orderByASC); ExtendedDataTable.DeleteRows(getTickersByVolatility, maxNumOfReturnedTickers); return getTickersByVolatility; } /// <summary> /// returns tickers by average close to close performance within the given set of tickers /// </summary> - public static DataTable GetTickersByAverageCloseToClosePerformance( bool orderByASC, DataTable setOfTickers, --- 126,180 ---- long maxNumOfReturnedTickers) { ! if(!setOfTickers.Columns.Contains("OpenToCloseStandDev")) ! setOfTickers.Columns.Add("OpenToCloseStandDev", System.Type.GetType("System.Double")); foreach(DataRow row in setOfTickers.Rows) { ! try ! { ! row["OpenToCloseStandDev"] = -1000000.0; ! row["OpenToCloseStandDev"] = ! QuantProject.DataAccess.Tables.Quotes.GetOpenToCloseStandardDeviation((string)row[0], ! firstQuoteDate, ! lastQuoteDate); ! } ! catch(Exception ex) ! {ex=ex;} } ! DataTable getTickersByVolatility = ExtendedDataTable.CopyAndSort(setOfTickers, ! "OpenToCloseStandDev>-1000000.0", ! "OpenToCloseStandDev", ! orderByASC); ExtendedDataTable.DeleteRows(getTickersByVolatility, maxNumOfReturnedTickers); return getTickersByVolatility; } + // /// <summary> + // /// returns tickers ordered by volatility computed with Standard deviation of adjusted + // /// close to open ratio, within the given set of tickers + // /// </summary> + // public static DataTable GetTickersByCloseToOpenVolatility( bool orderByASC, + // DataTable setOfTickers, + // DateTime firstQuoteDate, + // DateTime lastQuoteDate, + // long maxNumOfReturnedTickers) + // { + // if(!setOfTickers.Columns.Contains("CloseToOpenStandDev")) + // setOfTickers.Columns.Add("CloseToOpenStandDev", System.Type.GetType("System.Double")); + // foreach(DataRow row in setOfTickers.Rows) + // { + // row["CloseToOpenStandDev"] = + // QuantProject.DataAccess.Tables.Quotes.GetCloseToOpenStandardDeviation((string)row[0], + // firstQuoteDate, + // lastQuoteDate); + // } + // DataTable getTickersByVolatility = ExtendedDataTable.CopyAndSort(setOfTickers,"CloseToOpenStandDev", orderByASC); + // ExtendedDataTable.DeleteRows(getTickersByVolatility, maxNumOfReturnedTickers); + // return getTickersByVolatility; + // } + /// <summary> /// returns tickers by average close to close performance within the given set of tickers /// </summary> public static DataTable GetTickersByAverageCloseToClosePerformance( bool orderByASC, DataTable setOfTickers, *************** *** 166,173 **** /// <summary> ! /// returns tickers by average close to open performance within the given set of tickers /// </summary> ! public static DataTable GetTickersByAverageCloseToOpenPerformance( bool orderByASC, DataTable setOfTickers, DateTime firstQuoteDate, --- 198,206 ---- /// <summary> ! /// returns tickers by average open to close performance ! /// within the given set of tickers /// </summary> ! public static DataTable GetTickersByAverageOpenToClosePerformance( bool orderByASC, DataTable setOfTickers, DateTime firstQuoteDate, *************** *** 175,188 **** long maxNumOfReturnedTickers) { ! if(!setOfTickers.Columns.Contains("AverageCloseToOpenPerformance")) ! setOfTickers.Columns.Add("AverageCloseToOpenPerformance", System.Type.GetType("System.Double")); foreach(DataRow row in setOfTickers.Rows) { ! row["AverageCloseToOpenPerformance"] = ! QuantProject.DataAccess.Tables.Quotes.GetAverageCloseToOpenPerformance((string)row[0], ! firstQuoteDate, ! lastQuoteDate); } ! DataTable tableToReturn = ExtendedDataTable.CopyAndSort(setOfTickers,"AverageCloseToOpenPerformance", orderByASC); ExtendedDataTable.DeleteRows(tableToReturn, maxNumOfReturnedTickers); return tableToReturn; --- 208,230 ---- long maxNumOfReturnedTickers) { ! if(!setOfTickers.Columns.Contains("AverageOpenToClosePerformance")) ! setOfTickers.Columns.Add("AverageOpenToClosePerformance", System.Type.GetType("System.Double")); foreach(DataRow row in setOfTickers.Rows) { ! try ! { ! row["AverageOpenToClosePerformance"] = -1000000.0; ! row["AverageOpenToClosePerformance"] = ! QuantProject.DataAccess.Tables.Quotes.GetAverageOpenToClosePerformance((string)row[0], ! firstQuoteDate, ! lastQuoteDate); ! } ! catch(Exception ex) ! {ex=ex;} } ! DataTable tableToReturn = ExtendedDataTable.CopyAndSort(setOfTickers, ! "AverageOpenToClosePerformance>-1000000.0", ! "AverageOpenToClosePerformance", ! orderByASC); ExtendedDataTable.DeleteRows(tableToReturn, maxNumOfReturnedTickers); return tableToReturn; |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:56:16
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7476/b3_Data/Selectors Modified Files: SelectorByOpenToCloseVolatility.cs SelectorByAverageOpenToClosePerformance.cs Log Message: Methods have been properly renamed. Added new methods for Close To Open data management. Fixed some bugs (tickers without quotes are now excluded from selection). Index: SelectorByAverageOpenToClosePerformance.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Selectors/SelectorByAverageOpenToClosePerformance.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SelectorByAverageOpenToClosePerformance.cs 27 Feb 2005 19:56:07 -0000 1.1 --- SelectorByAverageOpenToClosePerformance.cs 7 Jan 2006 10:56:09 -0000 1.2 *************** *** 68,77 **** { if(this.setOfTickersToBeSelected == null) ! return QuantProject.DataAccess.Tables.Quotes.GetTickersByAverageCloseToOpenPerformance(this.isOrderedInASCMode, this.groupID, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers); else ! return QuantProject.Data.DataTables.Quotes.GetTickersByAverageCloseToOpenPerformance(this.isOrderedInASCMode, this.setOfTickersToBeSelected, this.firstQuoteDate, --- 68,77 ---- { if(this.setOfTickersToBeSelected == null) ! return QuantProject.DataAccess.Tables.Quotes.GetTickersByAverageOpenToClosePerformance(this.isOrderedInASCMode, this.groupID, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers); else ! return QuantProject.Data.DataTables.Quotes.GetTickersByAverageOpenToClosePerformance(this.isOrderedInASCMode, this.setOfTickersToBeSelected, this.firstQuoteDate, Index: SelectorByOpenToCloseVolatility.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Selectors/SelectorByOpenToCloseVolatility.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SelectorByOpenToCloseVolatility.cs 27 Feb 2005 19:56:07 -0000 1.1 --- SelectorByOpenToCloseVolatility.cs 7 Jan 2006 10:56:09 -0000 1.2 *************** *** 68,72 **** { if(this.setOfTickersToBeSelected == null) ! return QuantProject.DataAccess.Tables.Quotes.GetTickersByCloseToOpenVolatility(this.isOrderedInASCMode, this.groupID, this.firstQuoteDate, --- 68,72 ---- { if(this.setOfTickersToBeSelected == null) ! return QuantProject.DataAccess.Tables.Quotes.GetTickersByOpenToCloseVolatility(this.isOrderedInASCMode, this.groupID, this.firstQuoteDate, *************** *** 75,79 **** else ! return QuantProject.Data.DataTables.Quotes.GetTickersByCloseToOpenVolatility(this.isOrderedInASCMode, this.setOfTickersToBeSelected, this.firstQuoteDate, --- 75,79 ---- else ! return QuantProject.Data.DataTables.Quotes.GetTickersByOpenToCloseVolatility(this.isOrderedInASCMode, this.setOfTickersToBeSelected, this.firstQuoteDate, |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:50:49
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6816/b3_Data/Selectors Added Files: SelectorByCloseToOpenVolatility.cs SelectorByAverageCloseToOpenPerformance.cs Log Message: SelectorByCloseToOpenVolatility and SelectoByAverageCloseToOpenPerformance have been added to the project. --- NEW FILE: SelectorByAverageCloseToOpenPerformance.cs --- /* QuantProject - Quantitative Finance Library SelectorByAverageCloseToOpenPerformance.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 System.Windows.Forms; using QuantProject.DataAccess.Tables; using QuantProject.Data.DataTables; namespace QuantProject.Data.Selectors { /// <summary> /// Class for selection on tickers by average close (at day x) /// to open (at day x+1) performance /// </summary> public class SelectorByAverageCloseToOpenPerformance : TickerSelector, ITickerSelector { public SelectorByAverageCloseToOpenPerformance(DataTable setOfTickersToBeSelected, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers): base(setOfTickersToBeSelected, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { } public SelectorByAverageCloseToOpenPerformance(string groupID, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers): base(groupID, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { } private double getTableOfSelectedTickers_getTickersFromTable_getAverageCTOForTicker(string ticker) { Data.DataTables.Quotes tickerQuotes = new Data.DataTables.Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] closeToOpenReturns = new float[tickerQuotes.Rows.Count - 1]; for(int i = 0;i<tickerQuotes.Rows.Count - 1; i++) { closeToOpenReturns[i] = ( (float)tickerQuotes.Rows[i+1]["quOpen"]* (float)tickerQuotes.Rows[i+1]["quAdjustedClose"]/ (float)tickerQuotes.Rows[i+1]["quClose"] ) /(float)tickerQuotes.Rows[i]["quAdjustedClose"] - 1; } return QuantProject.ADT.Statistics.BasicFunctions.SimpleAverage(closeToOpenReturns); } private DataTable getTableOfSelectedTickers_getTickersFromTable() { if(!this.setOfTickersToBeSelected.Columns.Contains("AverageCloseToOpenPerformance")) this.setOfTickersToBeSelected.Columns.Add("AverageCloseToOpenPerformance", System.Type.GetType("System.Double")); foreach(DataRow row in this.setOfTickersToBeSelected.Rows) { try { row["AverageCloseToOpenPerformance"] = -1000000.0; row["AverageCloseToOpenPerformance"] = this.getTableOfSelectedTickers_getTickersFromTable_getAverageCTOForTicker((string)row[0]); } catch(Exception ex) {ex=ex;} } DataTable tableToReturn = ExtendedDataTable.CopyAndSort(this.setOfTickersToBeSelected, "AverageCloseToOpenPerformance>-1000000.0", "AverageCloseToOpenPerformance", this.isOrderedInASCMode); ExtendedDataTable.DeleteRows(tableToReturn, this.maxNumOfReturnedTickers); return tableToReturn; } private DataTable getTableOfSelectedTickers_getTickersFromGroup() { this.setOfTickersToBeSelected = QuantProject.DataAccess.Tables.Tickers_tickerGroups.GetTickers(this.groupID); return this.getTableOfSelectedTickers_getTickersFromTable(); } public DataTable GetTableOfSelectedTickers() { if(this.setOfTickersToBeSelected == null) return this.getTableOfSelectedTickers_getTickersFromGroup(); else//setOfTickersToBeSelected != null return this.getTableOfSelectedTickers_getTickersFromTable(); } public void SelectAllTickers() { ; } } } --- NEW FILE: SelectorByCloseToOpenVolatility.cs --- /* QuantProject - Quantitative Finance Library SelectorByCloseToOpenVolatility.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 System.Windows.Forms; using QuantProject.DataAccess.Tables; using QuantProject.Data.DataTables; namespace QuantProject.Data.Selectors { /// <summary> /// Class for selection on tickers by Close to open volatility /// </summary> public class SelectorByCloseToOpenVolatility : TickerSelector, ITickerSelector { public SelectorByCloseToOpenVolatility(DataTable setOfTickersToBeSelected, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers): base(setOfTickersToBeSelected, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { } public SelectorByCloseToOpenVolatility(string groupID, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers): base(groupID, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { } private double getTableOfSelectedTickers_getTickersFromTable_getCTOStdDevForTicker(string ticker) { Data.DataTables.Quotes tickerQuotes = new Data.DataTables.Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] closeToOpenReturns = new float[tickerQuotes.Rows.Count - 1]; for(int i = 0;i<tickerQuotes.Rows.Count - 1; i++) { closeToOpenReturns[i] = ( (float)tickerQuotes.Rows[i+1]["quOpen"]* (float)tickerQuotes.Rows[i+1]["quAdjustedClose"]/ (float)tickerQuotes.Rows[i+1]["quClose"] ) /(float)tickerQuotes.Rows[i]["quAdjustedClose"] - 1; } return QuantProject.ADT.Statistics.BasicFunctions.StdDev(closeToOpenReturns); } private DataTable getTableOfSelectedTickers_getTickersFromTable() { if(!this.setOfTickersToBeSelected.Columns.Contains("CloseToOpenStandardDeviation")) this.setOfTickersToBeSelected.Columns.Add("CloseToOpenStandardDeviation", System.Type.GetType("System.Double")); foreach(DataRow row in this.setOfTickersToBeSelected.Rows) { try { row["CloseToOpenStandardDeviation"] = -1000000.0; row["CloseToOpenStandardDeviation"] = this.getTableOfSelectedTickers_getTickersFromTable_getCTOStdDevForTicker((string)row[0]); } catch(Exception ex) {ex=ex;} } DataTable tableToReturn = ExtendedDataTable.CopyAndSort(this.setOfTickersToBeSelected, "CloseToOpenStandardDeviation>-1000000.0", "CloseToOpenStandardDeviation", this.isOrderedInASCMode); ExtendedDataTable.DeleteRows(tableToReturn, this.maxNumOfReturnedTickers); return tableToReturn; } private DataTable getTableOfSelectedTickers_getTickersFromGroup() { this.setOfTickersToBeSelected = QuantProject.DataAccess.Tables.Tickers_tickerGroups.GetTickers(this.groupID); return this.getTableOfSelectedTickers_getTickersFromTable(); } public DataTable GetTableOfSelectedTickers() { if(this.setOfTickersToBeSelected == null) return this.getTableOfSelectedTickers_getTickersFromGroup(); else//setOfTickersToBeSelected != null return this.getTableOfSelectedTickers_getTickersFromTable(); } public void SelectAllTickers() { ; } } } |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:50:49
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6816/b3_Data Modified Files: b3_Data.csproj Log Message: SelectorByCloseToOpenVolatility and SelectoByAverageCloseToOpenPerformance have been added to the project. Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** b3_Data.csproj 17 Nov 2005 21:34:40 -0000 1.33 --- b3_Data.csproj 7 Jan 2006 10:50:40 -0000 1.34 *************** *** 268,271 **** --- 268,276 ---- /> <File + RelPath = "Selectors\SelectorByAverageCloseToOpenPerformance.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Selectors\SelectorByAverageOpenToClosePerformance.cs" SubType = "Code" *************** *** 293,296 **** --- 298,306 ---- /> <File + RelPath = "Selectors\SelectorByCloseToOpenVolatility.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Selectors\SelectorByGroup.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:45:15
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5914/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: MainForm.cs Log Message: GenomeManagerForEfficientCTOPortfolio now manages Close To Open data: so, GenomeManagerForEfficientOTCPortfolio has to be called. Index: MainForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/MainForm.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** MainForm.cs 11 Dec 2005 18:02:10 -0000 1.8 --- MainForm.cs 7 Jan 2006 10:45:07 -0000 1.9 *************** *** 229,234 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(); ! GenomeManagerForEfficientCTOPortfolio genManEfficientCTOPortfolio = ! new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, this.firstDate, this.lastDate, --- 229,234 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(); ! GenomeManagerForEfficientOTCPortfolio genManEfficientOTCPortfolio = ! new GenomeManagerForEfficientOTCPortfolio(setOfTickersToBeOptimized, this.firstDate, this.lastDate, *************** *** 237,241 **** this.portfolioType); ! this.GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); --- 237,241 ---- this.portfolioType); ! this.GO = new GeneticOptimizer(genManEfficientOTCPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:45:15
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5914/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest Modified Files: WalkForwardOpenToCloseDailyStrategy.cs Log Message: GenomeManagerForEfficientCTOPortfolio now manages Close To Open data: so, GenomeManagerForEfficientOTCPortfolio has to be called. Index: WalkForwardOpenToCloseDailyStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/WalkForwardTest/WalkForwardOpenToCloseDailyStrategy.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WalkForwardOpenToCloseDailyStrategy.cs 23 Oct 2005 19:09:03 -0000 1.4 --- WalkForwardOpenToCloseDailyStrategy.cs 7 Jan 2006 10:45:07 -0000 1.5 *************** *** 186,191 **** Console.WriteLine( "Number of tickers to be optimized: " + setOfTickersToBeOptimized.Rows.Count.ToString() ); ! GenomeManagerForEfficientCTOPortfolio genManEfficientCTOPortfolio = ! new GenomeManagerForEfficientCTOPortfolio( setOfTickersToBeOptimized , currentDate.AddDays( -this.numDaysForInSampleOptimization + 1 ) , --- 186,191 ---- Console.WriteLine( "Number of tickers to be optimized: " + setOfTickersToBeOptimized.Rows.Count.ToString() ); ! GenomeManagerForEfficientOTCPortfolio genManEfficientOTCPortfolio = ! new GenomeManagerForEfficientOTCPortfolio( setOfTickersToBeOptimized , currentDate.AddDays( -this.numDaysForInSampleOptimization + 1 ) , *************** *** 195,199 **** this.portfolioType ); ! this.geneticOptimizer = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); --- 195,199 ---- this.portfolioType ); ! this.geneticOptimizer = new GeneticOptimizer(genManEfficientOTCPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer); |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:39:32
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4505/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: Added files for the Open To Close daily strategy. These are now properly named. Old files, named with CTO, have been changed so to perform the Close To Open strategy. Some old files (signed with CTO) have been temporarily removed from project (right CTO implementation has to be done). Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** b7_Scripts.csproj 28 Dec 2005 23:23:59 -0000 1.47 --- b7_Scripts.csproj 7 Jan 2006 10:39:03 -0000 1.48 *************** *** 204,223 **** /> <File ! RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerCTOMultiAccount.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerCTOTest.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerLastChosenPortfolio.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerOTCCTO.cs" SubType = "Code" BuildAction = "Compile" --- 204,223 ---- /> <File ! RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerLastChosenPortfolio.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerOTC.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerOTCCTO.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerOTCMultiAccount.cs" SubType = "Code" BuildAction = "Compile" *************** *** 229,232 **** --- 229,237 ---- /> <File + RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerOTCTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\GenomeManagerForEfficientCTCPortfolio.cs" SubType = "Code" *************** *** 239,242 **** --- 244,252 ---- /> <File + RelPath = "TickerSelectionTesting\GenomeManagerForEfficientOTCPortfolio.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\GenomeManagerForEfficientPortfolio.cs" SubType = "Code" *************** *** 279,288 **** /> <File ! RelPath = "TickerSelectionTesting\RunEfficientCTOPortfolioMultiAccount.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TickerSelectionTesting\RunEfficientOTCCTOPortfolio.cs" SubType = "Code" BuildAction = "Compile" --- 289,303 ---- /> <File ! RelPath = "TickerSelectionTesting\RunEfficientOTCCTOPortfolio.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "TickerSelectionTesting\RunEfficientOTCPortfolio.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "TickerSelectionTesting\RunEfficientOTCPortfolioMultiAccount.cs" SubType = "Code" BuildAction = "Compile" *************** *** 309,313 **** /> <File ! RelPath = "TickerSelectionTesting\RunTestOptimizedCTOPortfolio.cs" SubType = "Code" BuildAction = "Compile" --- 324,328 ---- /> <File ! RelPath = "TickerSelectionTesting\RunTestOptimizedOTCPortfolio.cs" SubType = "Code" BuildAction = "Compile" *************** *** 354,357 **** --- 369,377 ---- /> <File + RelPath = "TickerSelectionTesting\TestingOTCTypes\GenomeManagerForEfficientOTCTypes.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\TestingOTCTypes\RunEfficientOTCTypes.cs" SubType = "Code" |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4080/b7_Scripts/TickerSelectionTesting Modified Files: RunEfficientCTOPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs EndOfDayTimerHandlerOTCMultiday.cs EndOfDayTimerHandlerOTCCTO.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandler.cs Added Files: RunTestOptimizedOTCPortfolio.cs RunEfficientOTCPortfolioMultiAccount.cs RunEfficientOTCPortfolio.cs GenomeManagerForEfficientOTCPortfolio.cs EndOfDayTimerHandlerOTCTest.cs EndOfDayTimerHandlerOTCMultiAccount.cs EndOfDayTimerHandlerOTC.cs Log Message: Added files for the Open To Close daily strategy. These are now properly named. Old files, named with CTO, have been changed so to perform the Close To Open strategy. Index: EndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandler.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** EndOfDayTimerHandler.cs 28 Dec 2005 23:29:40 -0000 1.19 --- EndOfDayTimerHandler.cs 7 Jan 2006 10:35:39 -0000 1.20 *************** *** 56,60 **** protected int populationSizeForGeneticOptimizer; ! protected Account account; protected ArrayList orders; --- 56,60 ---- protected int populationSizeForGeneticOptimizer; ! protected Account account = null; protected ArrayList orders; *************** *** 99,104 **** get { return this.bestGenomes; } } ! public EndOfDayTimerHandler(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, --- 99,105 ---- get { return this.bestGenomes; } } ! ! private void endOfDayTimerHandler_initializeBasic(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, *************** *** 110,114 **** this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; this.numDaysForOptimizationPeriod = numDaysForOptimizationPeriod; - this.account = account; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; --- 111,114 ---- *************** *** 122,126 **** } ! public EndOfDayTimerHandler(string[] chosenTickers, PortfolioType portfolioType, --- 122,159 ---- } ! ! public EndOfDayTimerHandler(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, double targetReturn, ! PortfolioType portfolioType) ! { ! this.endOfDayTimerHandler_initializeBasic(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType); ! this.account = account; ! ! } ! public EndOfDayTimerHandler(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer, ! string benchmark, double targetReturn, ! PortfolioType portfolioType) ! { ! this.endOfDayTimerHandler_initializeBasic(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, ! generationNumberForGeneticOptimizer, ! populationSizeForGeneticOptimizer, ! benchmark, targetReturn, ! portfolioType); ! } ! ! ! public EndOfDayTimerHandler(string[] chosenTickers, PortfolioType portfolioType, *************** *** 138,142 **** this.setDefaultChosenTickersPortfolioWeights(); } ! private void setDefaultChosenTickersPortfolioWeights() { --- 171,175 ---- this.setDefaultChosenTickersPortfolioWeights(); } ! private void setDefaultChosenTickersPortfolioWeights() { --- NEW FILE: EndOfDayTimerHandlerOTCTest.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerOTCTest.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.ADT.Optimizing.Genetic; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Implements MarketOpenEventHandler, /// TwoMinutesBeforeMarketCloseEventHandler and OneHourAfterMarketCloseEventHandler /// These handlers contain the core strategy for the efficient close to open portfolio! /// </summary> [Serializable] public class EndOfDayTimerHandlerOTCTest : EndOfDayTimerHandlerOTC { private static bool optimized; public EndOfDayTimerHandlerOTCTest(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, double targetReturn, PortfolioType portfolioType, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, targetReturn, portfolioType, numDaysBetweenEachOptimization) { } protected override void setTickers(DateTime currentDate, bool setGenomeCounter) { //setGenomeCounter never used; it is necessary for overriding if(!EndOfDayTimerHandlerOTCTest.optimized) { base.setTickers(currentDate.AddDays(this.numDaysForOptimizationPeriod), true); EndOfDayTimerHandlerOTCTest.optimized = true; } } public void Reset() { EndOfDayTimerHandlerOTCTest.optimized = false; } } } --- NEW FILE: EndOfDayTimerHandlerOTC.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerOTC.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.ADT.Optimizing.Genetic; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Implements MarketOpenEventHandler, /// TwoMinutesBeforeMarketCloseEventHandler and OneHourAfterMarketCloseEventHandler /// These handlers contain the core strategy for the efficient close to open portfolio! /// </summary> [Serializable] public class EndOfDayTimerHandlerOTC : EndOfDayTimerHandler { protected int numDaysBetweenEachOptimization; private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; public EndOfDayTimerHandlerOTC(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, double targetReturn, PortfolioType portfolioType, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, targetReturn, portfolioType) { this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.numDaysElapsedSinceLastOptimization = 0; this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; } private double marketOpenEventHandler_currCombinationHasLost_getValue(ExtendedDateTime extendedDateTime) { double returnValue = 0.0; string signedTicker; string unsignedTicker; double tickerMarketValue; for(int i = 0; i<this.chosenTickers.Length; i++) { signedTicker = this.chosenTickers[i]; unsignedTicker = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(signedTicker); tickerMarketValue = HistoricalDataProvider.GetAdjustedMarketValue(unsignedTicker,extendedDateTime); if(signedTicker == unsignedTicker) //long position for the ticker returnValue += this.chosenTickersPortfolioWeights[i]*tickerMarketValue; else//short position for the ticker returnValue -= this.chosenTickersPortfolioWeights[i]*tickerMarketValue; } return returnValue; } private bool marketOpenEventHandler_currCombinationHasLost() { bool returnValue = false; IndexBasedEndOfDayTimer currentTimer = (IndexBasedEndOfDayTimer)this.account.EndOfDayTimer; ExtendedDateTime now = new ExtendedDateTime(currentTimer.GetCurrentTime().DateTime, BarComponent.Open); ExtendedDateTime previousClose = new ExtendedDateTime(currentTimer.GetPreviousDateTime(), BarComponent.Close); double currentCombinationValue_Now = this.marketOpenEventHandler_currCombinationHasLost_getValue(now); double currentCombinationValue_AtPreviousMarketClose = this.marketOpenEventHandler_currCombinationHasLost_getValue(previousClose); if(currentCombinationValue_Now < currentCombinationValue_AtPreviousMarketClose) returnValue = true; return returnValue; } /// <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(30000); bool allTickerHasBeenChosen = true; for( int i = 0; i<this.chosenTickers.Length; i++) { if(this.chosenTickers[i] == null) allTickerHasBeenChosen = false; } if(allTickerHasBeenChosen && this.marketOpenEventHandler_currCombinationHasLost()) this.openPositions(); } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.closePositions(); } #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); SelectorByLiquidity mostLiquidFromTemporized = new SelectorByLiquidity(temporizedGroup.GetTableOfSelectedTickers(), false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers); SelectorByAverageRawOpenPrice selectorByOpenPriceFromMostLiquid = new SelectorByAverageRawOpenPrice(mostLiquidFromTemporized.GetTableOfSelectedTickers(), false, currentDate.AddDays(-10), currentDate, this.numberOfEligibleTickers, this.minPriceForMinimumCommission, this.maxPriceForMinimumCommission, 0, 10); SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromSelectedByPrice = new SelectorByOpenCloseCorrelationToBenchmark(selectorByOpenPriceFromMostLiquid.GetTableOfSelectedTickers(), this.benchmark,true, currentDate.AddDays(-this.numDaysForOptimizationPeriod ), currentDate, this.numberOfEligibleTickers/2); this.eligibleTickers = lessCorrelatedFromSelectedByPrice.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers/2, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), // false, currentDate.AddDays(-2), // currentDate, this.numberOfEligibleTickers/4); //return winners.GetTableOfSelectedTickers(); //SelectorByOpenCloseCorrelationToBenchmark lessCorrelated = // new SelectorByOpenCloseCorrelationToBenchmark(quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(), // this.benchmark, true, // currentDate.AddDays(-this.numDaysForLiquidity), // currentDate, this.numberOfEligibleTickers/2); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); //return mostLiquidFromQuotedAtEachMarketDay.GetTableOfSelectedTickers(); //return lessCorrelated.GetTableOfSelectedTickers(); //return selectorByOpenPriceFromMostLiquid.GetTableOfSelectedTickers(); } protected virtual void setTickers(DateTime currentDate, bool setGenomeCounter) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen { IGenomeManager genManEfficientOTCPortfolio = new GenomeManagerForEfficientOTCPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfTickersToBeChosen, this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientOTCPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, this.seedForRandomGenerator); if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); GO.Run(false); this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member } protected void oneHourAfterMarketCloseEventHandler_updatePrices() { //min price for minimizing commission amount //according to IB Broker's commission scheme this.minPriceForMinimumCommission = this.account.CashAmount/(this.numberOfTickersToBeChosen*100); this.maxPriceForMinimumCommission = this.maxPriceForMinimumCommission; //just to avoid warning message } /// <summary> /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.seedForRandomGenerator++; this.orders.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; } else { this.numDaysElapsedSinceLastOptimization++; } } #endregion } } Index: EndOfDayTimerHandlerOTCCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCCTO.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerOTCCTO.cs 8 Nov 2005 18:36:48 -0000 1.2 --- EndOfDayTimerHandlerOTCCTO.cs 7 Jan 2006 10:35:39 -0000 1.3 *************** *** 161,166 **** { ! IGenomeManager genManEfficientCTOPortfolio = ! new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, --- 161,166 ---- { ! IGenomeManager genManEfficientOTCPortfolio = ! new GenomeManagerForEfficientOTCPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, *************** *** 169,173 **** this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, --- 169,173 ---- this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientOTCPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, --- NEW FILE: RunEfficientOTCPortfolio.cs --- /* QuantProject - Quantitative Finance Library RunEfficientOTCPortfolio.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.Data; using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.ADT.FileManaging; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Accounting.Reporting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Scripting; using QuantProject.Business.Strategies; using QuantProject.Business.Testing; using QuantProject.Business.Timing; using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Business.Financial.Accounting.Slippage; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Script to buy at open and sell at close /// the efficient open to close daily portfolio /// </summary> [Serializable] public class RunEfficientOTCPortfolio : RunEfficientPortfolio { protected int numDaysBetweenEachOptimization; public RunEfficientOTCPortfolio(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, PortfolioType portfolioType, double maxRunningHours, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, portfolioType, maxRunningHours) { //this.ScriptName = "OpenCloseScriptsSharpeRatioWithCoeff"; //this.ScriptName = "OpenCloseScriptsSharpeRatio"; this.ScriptName = "OpenCloseScriptsWithCoeff"; //this.ScriptName = "OpenCloseScripts"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } // delete remark delimitations for having ib commission // and a fixed percentage calculation of slippage protected override void run_initializeAccount() { this.account = new Account(this.ScriptName, this.endOfDayTimer , new HistoricalEndOfDayDataStreamer(this.endOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , this.historicalQuoteProvider, new FixedPercentageSlippageManager(this.historicalQuoteProvider, this.endOfDayTimer,0.08)), new IBCommissionManager()); } protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerOTC(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.targetReturn, this.portfolioType, this.numDaysBetweenEachOptimization); } protected override void run_initializeHistoricalQuoteProvider() { //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.endOfDayTimerHandler.MarketOpenEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.endOfDayTimerHandler.MarketCloseEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.checkDateForReport); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); } //necessary far calling RunEfficientPortfolio.Run() //in classes that inherit from this class public override void Run() { base.Run(); } } } Index: EndOfDayTimerHandlerOTCMultiday.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCMultiday.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** EndOfDayTimerHandlerOTCMultiday.cs 8 Nov 2005 18:36:48 -0000 1.3 --- EndOfDayTimerHandlerOTCMultiday.cs 7 Jan 2006 10:35:39 -0000 1.4 *************** *** 164,169 **** { ! IGenomeManager genManEfficientCTOPortfolio = ! new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, --- 164,169 ---- { ! IGenomeManager genManEfficientOTCPortfolio = ! new GenomeManagerForEfficientOTCPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, *************** *** 172,176 **** this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, --- 172,176 ---- this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientOTCPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** GenomeManagerForEfficientCTOPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.16 --- GenomeManagerForEfficientCTOPortfolio.cs 7 Jan 2006 10:35:39 -0000 1.17 *************** *** 38,42 **** /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForWeightedEfficientPortfolio { --- 38,42 ---- /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForEfficientPortfolio { *************** *** 57,66 **** this.retrieveData(); } ! protected override float[] getArrayOfRatesOfReturn(string ticker) { float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = ExtendedDataTable.GetRatesOfReturnsFromColumns(tickerQuotes, "quClose", "quOpen"); this.numberOfExaminedReturns = returnValue.Length; --- 57,78 ---- this.retrieveData(); } ! private float[] getArrayOfRatesOfReturn_getCloseToOpenRates(Quotes tickerQuotes) ! { ! float[] returnValue = new float[tickerQuotes.Rows.Count - 1]; ! for(int i = 0;i<tickerQuotes.Rows.Count - 1; i++) ! { ! returnValue[i] = ! ( (float)tickerQuotes.Rows[i+1]["quOpen"]* ! (float)tickerQuotes.Rows[i+1]["quAdjustedClose"]/ ! (float)tickerQuotes.Rows[i+1]["quClose"] ) ! /(float)tickerQuotes.Rows[i]["quAdjustedClose"] - 1; ! } ! return returnValue; ! } protected override float[] getArrayOfRatesOfReturn(string ticker) { float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = this.getArrayOfRatesOfReturn_getCloseToOpenRates(tickerQuotes); this.numberOfExaminedReturns = returnValue.Length; *************** *** 96,105 **** } */ ! /* protected override double getFitnessValue_calculate() { return this.RateOfReturn/Math.Sqrt(this.Variance); } ! */ } --- 108,117 ---- } */ ! protected override double getFitnessValue_calculate() { return this.RateOfReturn/Math.Sqrt(this.Variance); } ! } Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** EndOfDayTimerHandlerCTO.cs 28 Dec 2005 23:29:40 -0000 1.22 --- EndOfDayTimerHandlerCTO.cs 7 Jan 2006 10:35:39 -0000 1.23 *************** *** 66,111 **** } ! private double marketOpenEventHandler_currCombinationHasLost_getValue(ExtendedDateTime extendedDateTime) ! { ! double returnValue = 0.0; ! string signedTicker; ! string unsignedTicker; ! double tickerMarketValue; ! for(int i = 0; i<this.chosenTickers.Length; i++) ! { ! signedTicker = this.chosenTickers[i]; ! unsignedTicker = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(signedTicker); ! tickerMarketValue = ! HistoricalDataProvider.GetAdjustedMarketValue(unsignedTicker,extendedDateTime); ! if(signedTicker == unsignedTicker) ! //long position for the ticker ! returnValue += this.chosenTickersPortfolioWeights[i]*tickerMarketValue; ! else//short position for the ticker ! returnValue -= this.chosenTickersPortfolioWeights[i]*tickerMarketValue; ! } ! return returnValue; ! ! } ! ! private bool marketOpenEventHandler_currCombinationHasLost() ! { ! bool returnValue = false; ! IndexBasedEndOfDayTimer currentTimer = (IndexBasedEndOfDayTimer)this.account.EndOfDayTimer; ! ExtendedDateTime now = ! new ExtendedDateTime(currentTimer.GetCurrentTime().DateTime, ! BarComponent.Open); ! ExtendedDateTime previousClose = ! new ExtendedDateTime(currentTimer.GetPreviousDateTime(), ! BarComponent.Close); ! double currentCombinationValue_Now = ! this.marketOpenEventHandler_currCombinationHasLost_getValue(now); ! double currentCombinationValue_AtPreviousMarketClose = ! this.marketOpenEventHandler_currCombinationHasLost_getValue(previousClose); ! if(currentCombinationValue_Now < currentCombinationValue_AtPreviousMarketClose) ! returnValue = true; ! return returnValue; ! } ! /// <summary> /// Handles a "Market Open" event. --- 66,70 ---- } ! /// <summary> /// Handles a "Market Open" event. *************** *** 116,130 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(30000); ! bool allTickerHasBeenChosen = true; ! for( int i = 0; i<this.chosenTickers.Length; i++) ! { ! if(this.chosenTickers[i] == null) ! allTickerHasBeenChosen = false; ! } ! if(allTickerHasBeenChosen && ! this.marketOpenEventHandler_currCombinationHasLost()) ! this.openPositions(); } --- 75,79 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.closePositions(); } *************** *** 133,140 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! this.closePositions(); } - - #region OneHourAfterMarketCloseEventHandler --- 82,94 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(30000); ! ! // if(this.numDaysElapsedSinceLastOptimization < ! // this.numDaysBetweenEachOptimization - 1) ! // { ! this.openPositions(); ! // } } #region OneHourAfterMarketCloseEventHandler *************** *** 142,186 **** protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { ! ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! ! SelectorByLiquidity mostLiquidFromTemporized = ! new SelectorByLiquidity(temporizedGroup.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfEligibleTickers); ! ! SelectorByAverageRawOpenPrice selectorByOpenPriceFromMostLiquid = ! new SelectorByAverageRawOpenPrice(mostLiquidFromTemporized.GetTableOfSelectedTickers(), false, ! currentDate.AddDays(-10), currentDate, ! this.numberOfEligibleTickers, this.minPriceForMinimumCommission, ! this.maxPriceForMinimumCommission, 0, 10); ! ! SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromSelectedByPrice = ! new SelectorByOpenCloseCorrelationToBenchmark(selectorByOpenPriceFromMostLiquid.GetTableOfSelectedTickers(), ! this.benchmark,true, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! currentDate, ! this.numberOfEligibleTickers/2); ! this.eligibleTickers = lessCorrelatedFromSelectedByPrice.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfEligibleTickers/2, this.benchmark); ! ! //SelectorByWinningOpenToClose winners = ! // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), ! // false, currentDate.AddDays(-2), ! // currentDate, this.numberOfEligibleTickers/4); ! //return winners.GetTableOfSelectedTickers(); ! //SelectorByOpenCloseCorrelationToBenchmark lessCorrelated = ! // new SelectorByOpenCloseCorrelationToBenchmark(quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(), ! // this.benchmark, true, ! // currentDate.AddDays(-this.numDaysForLiquidity), ! // currentDate, this.numberOfEligibleTickers/2); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); - //return mostLiquidFromQuotedAtEachMarketDay.GetTableOfSelectedTickers(); - //return lessCorrelated.GetTableOfSelectedTickers(); - //return selectorByOpenPriceFromMostLiquid.GetTableOfSelectedTickers(); } --- 96,115 ---- protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! // SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromTemporizedGroup = ! // new SelectorByOpenCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), ! // this.benchmark,true, ! // currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! // currentDate, ! // this.numberOfEligibleTickers); ! // ! this.eligibleTickers = temporizedGroup.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfEligibleTickers, this.benchmark); ! return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); } *************** *** 244,248 **** { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; } --- 173,177 ---- { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; } --- NEW FILE: GenomeManagerForEfficientOTCPortfolio.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerForEfficientOTCPortfolio.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// This class implements IGenomeManager, in order to find efficient /// portfolios based on tickers' OpenToClose rates, using the /// GeneticOptimizer /// </summary> [Serializable] public class GenomeManagerForEfficientOTCPortfolio : GenomeManagerForWeightedEfficientPortfolio { public GenomeManagerForEfficientOTCPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance, PortfolioType portfolioType) :base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, targetPerformance, portfolioType) { this.retrieveData(); } protected override float[] getArrayOfRatesOfReturn(string ticker) { float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); returnValue = ExtendedDataTable.GetRatesOfReturnsFromColumns(tickerQuotes, "quClose", "quOpen"); this.numberOfExaminedReturns = returnValue.Length; return returnValue; } /*using LPM protected override double getFitnessValue_calculate() { double returnValue = 0; double a, b, c; a = 0.002; b = 2.0; c = 2.0; //returnValue = Math.Pow((a/this.Variance),b) * // Math.Pow((this.rateOfReturn - this.targetPerformance), // c); //this.lowerPartialMoment = AdvancedFunctions.LowerPartialMoment(this.portfolioRatesOfReturn, // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn), // 3.0); this.lowerPartialMoment = AdvancedFunctions.NegativeSemiVariance(this.portfolioRatesOfReturn); a = 1.0; returnValue = Math.Pow((a/this.lowerPartialMoment),b) * Math.Pow(Math.Max(0.0,(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; } */ /* protected override double getFitnessValue_calculate() { return this.RateOfReturn/Math.Sqrt(this.Variance); } */ } } --- NEW FILE: EndOfDayTimerHandlerOTCMultiAccount.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerOTCMultiAccount.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.ADT.Optimizing.Genetic; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Implements MarketOpenEventHandler, /// TwoMinutesBeforeMarketCloseEventHandler and OneHourAfterMarketCloseEventHandler /// These handlers contain the core strategy for the efficient open to close portfolio! /// </summary> [Serializable] public class EndOfDayTimerHandlerOTCMultiAccount : EndOfDayTimerHandler { protected int numDaysBetweenEachOptimization; private int numDaysElapsedSinceLastOptimization; protected int seedForRandomGenerator; private string[,] chosenTickersForAccounts; private int distanceForEachGenomeToTest; private Account[] accounts; private ArrayList[] ordersForAccounts; private string[,] lastOrderedTickersForAccounts; public EndOfDayTimerHandlerOTCMultiAccount(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account[] accounts, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, double targetReturn, PortfolioType portfolioType, int numDaysBetweenEachOptimization, int numberOfAccounts, int distanceForEachGenomeToTest): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, accounts[0], generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, targetReturn, portfolioType) { this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.numDaysElapsedSinceLastOptimization = 0; this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; this.chosenTickersForAccounts = new string[numberOfAccounts,numberOfTickersToBeChosen]; this.lastOrderedTickersForAccounts = new string[numberOfAccounts,numberOfTickersToBeChosen]; this.ordersForAccounts = new ArrayList[numberOfAccounts]; for(int i = 0; i<numberOfAccounts;i++) ordersForAccounts[i] = new ArrayList(); this.distanceForEachGenomeToTest = distanceForEachGenomeToTest; this.accounts = accounts; } private void addOrderForTickerForEachAccount(int accountNumber, string ticker ) { string tickerCode = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); double cashForSinglePosition = this.accounts[accountNumber].CashAmount / this.numberOfTickersToBeChosen; long quantity = Convert.ToInt64( Math.Floor( cashForSinglePosition / this.accounts[accountNumber].DataStreamer.GetCurrentBid( tickerCode ) ) ); Order order; if(this.portfolioType == PortfolioType.OnlyShort || (this.portfolioType == PortfolioType.ShortAndLong && ticker != tickerCode)) order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); else order = new Order( OrderType.MarketBuy, new Instrument( tickerCode ) , quantity ); this.ordersForAccounts[accountNumber].Add(order); } protected override void addChosenTickersToOrderList() { for(int i = 0; i<this.accounts.Length; i++) { for(int j = 0; j<this.numberOfTickersToBeChosen; j++) { string ticker = this.chosenTickersForAccounts[i,j]; if( ticker != null) { this.addOrderForTickerForEachAccount(i, ticker ); this.lastOrderedTickersForAccounts[i,j] = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); } } } } protected override void openPositions() { //add cash first for(int i = 0; i<this.accounts.Length; i++) { if(this.ordersForAccounts[i].Count == 0 && this.accounts[i].Transactions.Count == 0) this.accounts[i].AddCash(17000); } this.addChosenTickersToOrderList(); //execute orders actually for(int i = 0; i<this.accounts.Length; i++) { foreach(object item in this.ordersForAccounts[i]) this.accounts[i].AddOrder((Order)item); } } private void closePositions_closePositionForAccount(int accountNumber, string ticker) { this.accounts[accountNumber].ClosePosition(ticker); } protected override void closePositions() { string ticker; for(int i = 0; i<this.accounts.Length; i++) { for(int j = 0; j<this.numberOfTickersToBeChosen; j++) { ticker = this.lastOrderedTickersForAccounts[i,j]; if( ticker != null) { if(this.accounts[i].Portfolio[ticker]!=null) closePositions_closePositionForAccount(i, ticker ); } } } } /// <summary> /// Handles a "Market Open" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public override void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //temporarily the if condition //if(this.numDaysElapsedSinceLastOptimization == 0) this.openPositions(); } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //temporarily //if(this.numDaysElapsedSinceLastOptimization == // this.numDaysBetweenEachOptimization) this.closePositions(); } #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { /* SelectorByAverageRawOpenPrice selectorByOpenPrice = new SelectorByAverageRawOpenPrice(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers, this.minPriceForMinimumCommission, this.maxPriceForMinimumCommission, 0, 2); DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromTemporizedGroup = new SelectorByOpenCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), this.benchmark,true, currentDate.AddDays(-this.numDaysForOptimizationPeriod ), currentDate, this.numberOfEligibleTickers); this.eligibleTickers = lessCorrelatedFromTemporizedGroup.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), // false, currentDate.AddDays(-2), // currentDate, this.numberOfEligibleTickers/4); //return winners.GetTableOfSelectedTickers(); //SelectorByOpenCloseCorrelationToBenchmark lessCorrelated = // new SelectorByOpenCloseCorrelationToBenchmark(quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(), // this.benchmark, true, // currentDate.AddDays(-this.numDaysForLiquidity), // currentDate, this.numberOfEligibleTickers/2); return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); //return lessCorrelated.GetTableOfSelectedTickers(); } protected virtual void setTickers(DateTime currentDate, bool setGenomeCounter) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen { IGenomeManager genManEfficientOTCPortfolio = new GenomeManagerForEfficientOTCPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfTickersToBeChosen, this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientOTCPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, this.seedForRandomGenerator); if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); GO.Run(false); //this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), // currentDate); for(int i = 0; i<this.accounts.Length; i++) { for(int j = 0; j<this.numberOfTickersToBeChosen; j++) this.chosenTickersForAccounts[i,j] = ((string[])((Genome)GO.CurrentGeneration[GO.CurrentGeneration.Count - 1 -i*this.distanceForEachGenomeToTest]).Meaning)[j]; } } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member } protected void oneHourAfterMarketCloseEventHandler_updatePrices() { //min price for minimizing commission amount //according to IB Broker's commission scheme this.minPriceForMinimumCommission = this.account.CashAmount/(this.numberOfTickersToBeChosen*100); this.maxPriceForMinimumCommission = this.maxPriceForMinimumCommission; //just to avoid warning message } /// <summary> /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.seedForRandomGenerator++; foreach(ArrayList arrayList in this.ordersForAccounts) arrayList.Clear(); //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Open event this.numDaysElapsedSinceLastOptimization = 0; } else { this.numDaysElapsedSinceLastOptimization++; } } #endregion } } Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** RunEfficientCTOPortfolio.cs 28 Dec 2005 23:29:39 -0000 1.25 --- RunEfficientCTOPortfolio.cs 7 Jan 2006 10:35:39 -0000 1.26 *************** *** 49,56 **** /// Script to buy at open and sell at close /// the efficient close to open daily portfolio - /// The efficient portfolio's generation rules - /// (contained in the EndOfDayTimerHandler) are: - /// - choose the most liquid tickers; - /// - choose the most efficient portfolio among these tickers /// </summary> [Serializable] --- 49,52 ---- *************** *** 72,79 **** portfolioType, maxRunningHours) { ! //this.ScriptName = "OpenCloseScriptsSharpeRatioWithCoeff"; ! //this.ScriptName = "OpenCloseScriptsSharpeRatio"; ! this.ScriptName = "OpenCloseScriptsWithCoeff"; ! //this.ScriptName = "OpenCloseScripts"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } --- 68,72 ---- portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToOpenScriptsNoCoeff"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } *************** *** 89,96 **** this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor(this.endOfDayTimer , ! this.historicalQuoteProvider, ! ... [truncated message content] |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:35:51
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4080/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio Modified Files: RunTestingOptimizationOpenToClose.cs Log Message: Added files for the Open To Close daily strategy. These are now properly named. Old files, named with CTO, have been changed so to perform the Close To Open strategy. Index: RunTestingOptimizationOpenToClose.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio/RunTestingOptimizationOpenToClose.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RunTestingOptimizationOpenToClose.cs 8 Nov 2005 18:32:43 -0000 1.6 --- RunTestingOptimizationOpenToClose.cs 7 Jan 2006 10:35:39 -0000 1.7 *************** *** 260,265 **** DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(this.marketDate); ! IGenomeManager genManEfficientCTOPortfolio = ! new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, this.marketDate.AddDays(-this.numDaysForOptimization), this.marketDate, --- 260,265 ---- DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(this.marketDate); ! IGenomeManager genManEfficientOTCPortfolio = ! new GenomeManagerForEfficientOTCPortfolio(setOfTickersToBeOptimized, this.marketDate.AddDays(-this.numDaysForOptimization), this.marketDate, *************** *** 268,272 **** this.portfolioType); ! this.setFitnesses_setFitnessesActually(genManEfficientCTOPortfolio); } --- 268,272 ---- this.portfolioType); ! this.setFitnesses_setFitnessesActually(genManEfficientOTCPortfolio); } |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:30:17
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3370/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs Log Message: GetFitnessValue method has been declared virtual Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** GenomeManagerForEfficientPortfolio.cs 8 Nov 2005 18:32:25 -0000 1.21 --- GenomeManagerForEfficientPortfolio.cs 7 Jan 2006 10:30:00 -0000 1.22 *************** *** 195,199 **** } ! public double GetFitnessValue(Genome genome) { double returnValue = 0; --- 195,199 ---- } ! public virtual double GetFitnessValue(Genome genome) { double returnValue = 0; |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:29:08
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3224/b7_Scripts/TickerSelectionTesting/TestingOTCTypes Modified Files: RunEfficientOTCTypes.cs EndOfDayTimerHandlerOTCTypes.cs Log Message: Fixed bug in OTCTypes script: positions are now correctly computed for each type of strategy. Index: RunEfficientOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/RunEfficientOTCTypes.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunEfficientOTCTypes.cs 28 Dec 2005 23:22:50 -0000 1.1 --- RunEfficientOTCTypes.cs 7 Jan 2006 10:28:56 -0000 1.2 *************** *** 72,76 **** portfolioType, maxRunningHours) { ! this.ScriptName = "OTC_Types"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.accounts = new Account[4]; --- 72,76 ---- portfolioType, maxRunningHours) { ! this.ScriptName = "OTC_Types_SharpeRatioWithCoeff"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.accounts = new Account[4]; Index: EndOfDayTimerHandlerOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/EndOfDayTimerHandlerOTCTypes.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerOTCTypes.cs 28 Dec 2005 23:22:50 -0000 1.1 --- EndOfDayTimerHandlerOTCTypes.cs 7 Jan 2006 10:28:56 -0000 1.2 *************** *** 59,63 **** Account[] accounts): base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, accounts[0], generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, --- 59,63 ---- Account[] accounts): base(tickerGroupID, numberOfEligibleTickers, ! numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, *************** *** 104,110 **** } protected override void openPositions() { ! this.addChosenTickersToOrderList(); for(int i = 0; i<this.accounts.Length; i++) { --- 104,141 ---- } + protected void addOrderForTickerForTheGivenAccount(int tickerPosition, + int accountNumber ) + { + string tickerCode = + GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[tickerPosition]); + double cashForSinglePosition = + this.accounts[accountNumber].CashAmount * this.chosenTickersPortfolioWeights[tickerPosition]; + long quantity = + Convert.ToInt64( Math.Floor( cashForSinglePosition / this.accounts[accountNumber].DataStreamer.GetCurrentBid( tickerCode ) ) ); + Order order; + if(this.portfolioType == PortfolioType.OnlyShort || + (this.portfolioType == PortfolioType.ShortAndLong && + this.chosenTickers[tickerPosition] != tickerCode)) + order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); + else + order = new Order( OrderType.MarketBuy, new Instrument( tickerCode ) , quantity ); + + this.orders.Add(order); + } + protected void addChosenTickersToOrderListForTheGivenAccount(int accountNumber) + { + for( int i = 0; i<this.chosenTickers.Length; i++) + { + if(this.chosenTickers[i] != null) + { + this.addOrderForTickerForTheGivenAccount( i, accountNumber ); + this.lastOrderedTickers[i] = + GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[i]); + } + } + } protected override void openPositions() { ! for(int i = 0; i<this.accounts.Length; i++) { *************** *** 114,125 **** if(i<=1)//daily classical, and multiday - this.openPositions_openWhenPortfolioIsEmpty(i); - else if(i==2)//for the CTO OTC { ! this.closePositions_close(i); foreach(object item in this.orders) this.accounts[i].AddOrder((Order)item); } ! else if(i==3)//for the CTO, only at night { this.closePositions_close(i); --- 145,163 ---- if(i<=1)//daily classical, and multiday { ! this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); ! this.openPositions_openWhenPortfolioIsEmpty(i); ! } ! else if(i==2)//for the CTO OTC ! { ! this.closePositions_close(i); ! this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); foreach(object item in this.orders) this.accounts[i].AddOrder((Order)item); } ! else if(i==3)//for the CTO, no position is opened ! //at market open. Any open position is closed, instead { this.closePositions_close(i); *************** *** 169,173 **** this.reverseSignOfChosenTickers(); this.orders.Clear(); ! this.addChosenTickersToOrderList(); this.openPositions_openWhenPortfolioIsEmpty(i); this.reverseSignOfChosenTickers(); --- 207,211 ---- this.reverseSignOfChosenTickers(); this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); this.openPositions_openWhenPortfolioIsEmpty(i); this.reverseSignOfChosenTickers(); *************** *** 184,188 **** this.reverseSignOfChosenTickers(); this.orders.Clear(); ! this.addChosenTickersToOrderList(); this.openPositions_openWhenPortfolioIsEmpty(i); this.reverseSignOfChosenTickers(); --- 222,226 ---- this.reverseSignOfChosenTickers(); this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); this.openPositions_openWhenPortfolioIsEmpty(i); this.reverseSignOfChosenTickers(); *************** *** 284,289 **** { ! IGenomeManager genManEfficientCTOPortfolio = ! new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, --- 322,327 ---- { ! IGenomeManager genManEfficientOTCTypes = ! new GenomeManagerForEfficientOTCTypes(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, *************** *** 292,296 **** this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, --- 330,334 ---- this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientOTCTypes, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, |
|
From: Marco M. <mi...@us...> - 2006-01-07 10:26:21
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2849/b7_Scripts/TickerSelectionTesting/TestingOTCTypes Added Files: GenomeManagerForEfficientOTCTypes.cs Log Message: Added specific IGenomeManager for OTCTypes (multiaccount) script --- NEW FILE: GenomeManagerForEfficientOTCTypes.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerForEfficientOTCTypes.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// This class implements IGenomeManager, in order to find efficient /// portfolios based on tickers' OpenToClose rates, using the /// GeneticOptimizer /// </summary> [Serializable] public class GenomeManagerForEfficientOTCTypes : GenomeManagerForWeightedEfficientPortfolio { // private GenomeManagerForEfficientCTOPortfolio genManCTO; public GenomeManagerForEfficientOTCTypes(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance, PortfolioType portfolioType) :base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, targetPerformance, portfolioType) { this.retrieveData(); // this.genManCTO = new GenomeManagerForEfficientCTOPortfolio(setOfInitialTickers, // firstQuoteDate, // lastQuoteDate, // numberOfTickersInPortfolio, // targetPerformance, // portfolioType); } //rate of return = rawClose/rawOpen - 1 protected override float[] getArrayOfRatesOfReturn(string ticker) { float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); returnValue = ExtendedDataTable.GetRatesOfReturnsFromColumns(tickerQuotes, "quClose", "quOpen"); this.numberOfExaminedReturns = returnValue.Length; return returnValue; } public override double GetFitnessValue(Genome genome) { double returnValue = 0; this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); double averagePortfolioRateOfReturn = BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); double portfolioVariance = BasicFunctions.Variance(this.portfolioRatesOfReturn); if(!Double.IsInfinity(portfolioVariance) && !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(); // returnValue = this.getFitnessValue_calculate() - // this.genManCTO.GetFitnessValue(genome); } return returnValue; } protected override double getFitnessValue_calculate() { return this.RateOfReturn/Math.Sqrt(this.Variance); } } } |