[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting RunTestOptimizedOTCPortfoli
Brought to you by:
glauco_1
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] |