[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting EndOfDayTimerHandlerCTO.cs,
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-02-06 20:14:12
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2069/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerCTO.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientPortfolio.cs RunEfficientCTCPortfolio.cs RunEfficientCTOPortfolio.cs Log Message: Resolved minor conflicts, fixed some bugs (in OpenToClose script) and used the ObjectArchiver methods for serializing and deserializing accounts at the end of the scripts Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerCTO.cs 30 Jan 2005 19:53:12 -0000 1.1 --- EndOfDayTimerHandlerCTO.cs 6 Feb 2005 20:14:01 -0000 1.2 *************** *** 41,49 **** /// These handlers contain the core strategy for the efficient close to open portfolio! /// </summary> public class EndOfDayTimerHandlerCTO { private DataTable eligibleTickers; private string[] chosenTickers; ! //private string[] lastChosenTickers; private string tickerGroupID; --- 41,50 ---- /// These handlers contain the core strategy for the efficient close to open portfolio! /// </summary> + [Serializable] public class EndOfDayTimerHandlerCTO { private DataTable eligibleTickers; private string[] chosenTickers; ! private string[] lastChosenTickers; private string tickerGroupID; *************** *** 51,54 **** --- 52,56 ---- private int numberOfTickersToBeChosen; private int generationNumberForGeneticOptimizer; + private int populationSizeForGeneticOptimizer; private Account account; *************** *** 67,71 **** public EndOfDayTimerHandlerCTO(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, Account account, ! int generationNumberForGeneticOptimizer) { this.tickerGroupID = tickerGroupID; --- 69,74 ---- public EndOfDayTimerHandlerCTO(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, Account account, ! int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer) { this.tickerGroupID = tickerGroupID; *************** *** 74,80 **** this.account = account; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.orders = new ArrayList(); this.chosenTickers = new string[numberOfTickersToBeChosen]; ! //this.lastChosenTickers = new string[numberOfTickersToBeChosen]; } --- 77,84 ---- this.account = account; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; + this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.orders = new ArrayList(); this.chosenTickers = new string[numberOfTickersToBeChosen]; ! this.lastChosenTickers = new string[numberOfTickersToBeChosen]; } *************** *** 94,101 **** --- 98,110 ---- private void marketOpenEventHandler_orderChosenTickers_addToOrderList() { + int idx = 0; foreach ( string ticker in this.chosenTickers ) { if(ticker != null) + { marketOpenEventHandler_orderChosenTickers_addToOrderList_forTicker( ticker ); + this.lastChosenTickers[idx] = ticker; + } + idx++; } } *************** *** 135,141 **** private void marketCloseEventHandler_closePositions() { ! if(this.chosenTickers != null) { ! foreach( string ticker in this.chosenTickers) { for(int i = 0; i<this.account.Portfolio.Keys.Count; i++) --- 144,150 ---- private void marketCloseEventHandler_closePositions() { ! if(this.lastChosenTickers != null) { ! foreach( string ticker in this.lastChosenTickers) { for(int i = 0; i<this.account.Portfolio.Keys.Count; i++) *************** *** 176,182 **** private void setTickers(DateTime currentDate) { ! //this.lastChosenTickers = this.chosenTickers; DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count >= this.chosenTickers.Length) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen --- 185,191 ---- private void setTickers(DateTime currentDate) { ! 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 *************** *** 189,192 **** --- 198,202 ---- //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; + GO.PopulationSize = this.populationSizeForGeneticOptimizer; GO.Run(false); this.chosenTickers = (string[])GO.BestGenome.Meaning; Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManagerForEfficientPortfolio.cs 30 Jan 2005 19:53:11 -0000 1.2 --- GenomeManagerForEfficientPortfolio.cs 6 Feb 2005 20:14:01 -0000 1.3 *************** *** 110,115 **** NormalDistribution normal = new NormalDistribution(portfolioRateOfReturn, Math.Sqrt(portfolioVariance)); ! //returnValue = normal.GetProbability(this.targetPerformance*0.5,this.targetPerformance*1.5); ! returnValue = 1 - normal.GetProbability(this.targetPerformance); return returnValue; } --- 110,115 ---- NormalDistribution normal = new NormalDistribution(portfolioRateOfReturn, Math.Sqrt(portfolioVariance)); ! returnValue = normal.GetProbability(this.targetPerformance*0.75,this.targetPerformance*1.25); ! //returnValue = 1 - normal.GetProbability(this.targetPerformance); return returnValue; } *************** *** 227,241 **** Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); - //float[] ratesOfReturns = new float[allAdjValues.Length/this.intervalLength + 1]; float[] ratesOfReturns = new float[allAdjValues.Length]; int i = 0; //index for ratesOfReturns array ! /* ! for(int idx = 0; idx + this.intervalLength < allAdjValues.Length; idx += this.intervalLength ) ! { ! ratesOfReturns[i] = allAdjValues[idx+this.intervalLength]/ ! allAdjValues[idx] - 1; ! i++; ! } ! */ for(int idx = 0; idx < allAdjValues.Length; idx++) { --- 227,233 ---- Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); float[] ratesOfReturns = new float[allAdjValues.Length]; int i = 0; //index for ratesOfReturns array ! for(int idx = 0; idx < allAdjValues.Length; idx++) { Index: RunEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTCPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunEfficientCTCPortfolio.cs 6 Feb 2005 18:19:10 -0000 1.3 --- RunEfficientCTCPortfolio.cs 6 Feb 2005 20:14:01 -0000 1.4 *************** *** 63,67 **** --- 63,69 ---- private EndOfDayDateTime startDateTime; private EndOfDayDateTime endDateTime; + // private int numIntervalDays;// number of days for the equity line graph + private IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); *************** *** 81,88 **** this.reportTable = new ReportTable( "Summary_Reports" ); this.startDateTime = new EndOfDayDateTime( ! new DateTime( 2000 , 1 , 1 ) , EndOfDaySpecificTime.MarketOpen ); this.endDateTime = new EndOfDayDateTime( ! new DateTime( 2000 , 1 , 20 ) , EndOfDaySpecificTime.MarketClose ); ! // this.numIntervalDays = 3; //for report } #region Run --- 83,91 ---- this.reportTable = new ReportTable( "Summary_Reports" ); this.startDateTime = new EndOfDayDateTime( ! new DateTime( 2004 , 1 , 1 ) , EndOfDaySpecificTime.MarketOpen ); this.endDateTime = new EndOfDayDateTime( ! new DateTime( 2004 , 3 , 31 ) , EndOfDaySpecificTime.MarketClose ); ! //this.numIntervalDays = 3; //for report ! } #region Run Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GenomeManagerForEfficientCTOPortfolio.cs 30 Jan 2005 19:53:10 -0000 1.3 --- GenomeManagerForEfficientCTOPortfolio.cs 6 Feb 2005 20:14:01 -0000 1.4 *************** *** 86,91 **** protected override float[] getArrayOfRatesOfReturn(string ticker) { Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! return ExtendedDataTable.GetArrayOfFloatFromRatioOfColumns(tickerQuotes, "quClose", "quOpen"); } --- 86,97 ---- protected override float[] getArrayOfRatesOfReturn(string ticker) { + float[] returnValue; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = ExtendedDataTable.GetArrayOfFloatFromRatioOfColumns(tickerQuotes, "quClose", "quOpen"); ! for(int idx = 0; idx!= returnValue.Length; idx++) ! { ! returnValue[idx] = returnValue[idx] - 1; ! } ! return returnValue; } Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** RunEfficientCTOPortfolio.cs 30 Jan 2005 19:53:11 -0000 1.10 --- RunEfficientCTOPortfolio.cs 6 Feb 2005 20:14:01 -0000 1.11 *************** *** 26,29 **** --- 26,30 ---- using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; + using QuantProject.ADT.FileManaging; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; *************** *** 51,55 **** /// - choose the most efficient portfolio among these tickers /// </summary> ! public class RunEfficientCTOPorfolio : Script { //DateTime lastDate = DateTime.Now.Date; --- 52,57 ---- /// - choose the most efficient portfolio among these tickers /// </summary> ! [Serializable] ! public class RunEfficientCTOPorfolio : Script { //DateTime lastDate = DateTime.Now.Date; *************** *** 59,67 **** DateTime firstDate = new DateTime(2004,9,25); // ! private ReportTable reportTable; private EndOfDayDateTime startDateTime; private EndOfDayDateTime endDateTime; ! private int numIntervalDays;// number of days for the equity line graph private IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalRawQuoteProvider(); --- 61,74 ---- DateTime firstDate = new DateTime(2004,9,25); // ! private string tickerGroupID; ! private int numberOfEligibleTickers; ! private int numberOfTickersToBeChosen; ! private int generationNumberForGeneticOptimizer; ! private int populationSizeForGeneticOptimizer; ! private ReportTable reportTable; private EndOfDayDateTime startDateTime; private EndOfDayDateTime endDateTime; ! //private int numIntervalDays;// number of days for the equity line graph private IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalRawQuoteProvider(); *************** *** 76,88 **** private IEndOfDayTimer endOfDayTimer; ! public RunEfficientCTOPorfolio() { //this.progressBarForm = new ProgressBarForm(); this.reportTable = new ReportTable( "Summary_Reports" ); this.startDateTime = new EndOfDayDateTime( ! new DateTime( 2002 , 1 , 1 ) , EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); this.endDateTime = new EndOfDayDateTime( ! new DateTime( 2002 , 1 , 20 ) , EndOfDaySpecificTime.OneHourAfterMarketClose ); ! this.numIntervalDays = 2; } #region Run --- 83,102 ---- private IEndOfDayTimer endOfDayTimer; ! public RunEfficientCTOPorfolio(string tickerGroupID, int numberOfEligibleTickers, ! int numberOfTickersToBeChosen, int generationNumberForGeneticOptimizer, ! int populationSizeForGeneticOptimizer) { //this.progressBarForm = new ProgressBarForm(); + this.tickerGroupID = tickerGroupID; + this.numberOfEligibleTickers = numberOfEligibleTickers; + this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; + this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; + this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.reportTable = new ReportTable( "Summary_Reports" ); this.startDateTime = new EndOfDayDateTime( ! new DateTime( 1999 , 1 , 1 ) , EndOfDaySpecificTime.FiveMinutesBeforeMarketClose ); this.endDateTime = new EndOfDayDateTime( ! new DateTime( 2004 , 10 , 31 ) , EndOfDaySpecificTime.OneHourAfterMarketClose ); ! //this.numIntervalDays = 3; } #region Run *************** *** 124,128 **** private void run_initializeEndOfDayTimerHandler() { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTO("STOCKMI",70,5,this.account,10); } /* --- 138,149 ---- private void run_initializeEndOfDayTimerHandler() { ! this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTO(this.tickerGroupID, ! this.numberOfEligibleTickers, ! this.numberOfTickersToBeChosen, ! this.account, ! this.generationNumberForGeneticOptimizer, ! this.populationSizeForGeneticOptimizer); ! ! } /* *************** *** 172,183 **** private void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! Report report; if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime ) { this.endOfDayTimer.Stop(); ! report = new Report( this.account , this.historicalQuoteProvider ); ! report.Show("CTO_Portfolio" , this.numIntervalDays , this.endDateTime , "^MIBTEL" ); ! } --- 193,209 ---- private void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! //Report report; if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime ) { this.endOfDayTimer.Stop(); ! //report = new Report( this.account , this.historicalQuoteProvider ); ! //report.Show("CTO_Portfolio" , this.numIntervalDays , this.endDateTime , "^MIBTEL" ); ! ObjectArchiver.Archive(this.account, ! "C:\\Documents and Settings\\Marco\\Documenti\\ProgettiOpenSource\\Quant\\SavedAccounts\\OpenCloseScripts\\" + ! "From"+this.numberOfEligibleTickers + "Portfolio" + ! this.numberOfTickersToBeChosen + "GenNum" + ! this.generationNumberForGeneticOptimizer + ! "PopSize" + this.populationSizeForGeneticOptimizer + ".qP"); } |