quantproject-developers Mailing List for QuantProject (Page 109)
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...> - 2005-05-26 23:17:51
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23365/b3_Data Modified Files: b3_Data.csproj Log Message: DataProviders\Caching\MissingQuoteException.cs had been removed Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** b3_Data.csproj 26 May 2005 22:58:16 -0000 1.27 --- b3_Data.csproj 26 May 2005 23:17:43 -0000 1.28 *************** *** 198,206 **** /> <File - RelPath = "DataProviders\Caching\MissingQuoteException.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "DataTables\GroupQuotes.cs" SubType = "Component" --- 198,201 ---- |
|
From: Glauco S. <gla...@us...> - 2005-05-26 22:58:34
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19451/b3_Data Modified Files: b3_Data.csproj Log Message: - DataProviders\Caching\Cache.cs has been added - DataProviders\Caching\CachePage.cs has been added - DataProviders\Caching\EarlyDateException.cs has been added - DataProviders\Caching\MissingQuoteException.cs has been added Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** b3_Data.csproj 17 May 2005 23:06:00 -0000 1.26 --- b3_Data.csproj 26 May 2005 22:58:16 -0000 1.27 *************** *** 183,186 **** --- 183,206 ---- /> <File + RelPath = "DataProviders\Caching\Cache.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "DataProviders\Caching\CachePage.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "DataProviders\Caching\EarlyDateException.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "DataProviders\Caching\MissingQuoteException.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "DataTables\GroupQuotes.cs" SubType = "Component" |
|
From: Glauco S. <gla...@us...> - 2005-05-26 22:56:07
|
Update of /cvsroot/quantproject/QuantProject/b5_Presentation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19045/b5_Presentation Modified Files: b5_Presentation.csproj Log Message: Automatic changes Index: b5_Presentation.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b5_Presentation/b5_Presentation.csproj,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** b5_Presentation.csproj 29 Mar 2005 15:03:17 -0000 1.22 --- b5_Presentation.csproj 26 May 2005 22:55:59 -0000 1.23 *************** *** 141,145 **** Name = "NPlot" AssemblyName = "NPlot" ! HintPath = "..\..\QuantDownloader\Downloader\bin\Debug\NPlot.dll" /> </References> --- 141,145 ---- Name = "NPlot" AssemblyName = "NPlot" ! HintPath = "bin\Debug\NPlot.dll" /> </References> |
|
From: Glauco S. <gla...@us...> - 2005-05-26 22:55:07
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18731/b1_ADT Added Files: IndexOfKeyOrPreviousException.cs Log Message: Exception thrown when the key to find is less than the first object --- NEW FILE: IndexOfKeyOrPreviousException.cs --- using System; using System.Windows.Forms; namespace QuantProject.ADT { /// <summary> /// Exception thrown when the key to find is less than the first object /// </summary> public class IndexOfKeyOrPreviousException : Exception { public IndexOfKeyOrPreviousException( IComparable firstKeyInTheAdvancedSortedList , Object key ) { string message = "The given key is less than the first object " + "in the AdvancedSortedList"; message = message; // MessageBox.Show( this.message ); } } } |
|
From: Glauco S. <gla...@us...> - 2005-05-26 22:52:49
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18148/b1_ADT Modified Files: b1_ADT.csproj Log Message: IndexOfKeyOrPreviousException.cs has been added Index: b1_ADT.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/b1_ADT.csproj,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** b1_ADT.csproj 17 Apr 2005 11:57:57 -0000 1.14 --- b1_ADT.csproj 26 May 2005 22:52:28 -0000 1.15 *************** *** 118,121 **** --- 118,126 ---- /> <File + RelPath = "IndexOfKeyOrPreviousException.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "IProgressNotifier.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2005-05-17 23:15:59
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader/TickerSelectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19437/Downloader/TickerSelectors Modified Files: TickerSelectorForm.cs Log Message: Updated visual interface for ITickerSelector objects Index: TickerSelectorForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerSelectors/TickerSelectorForm.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** TickerSelectorForm.cs 19 Apr 2005 18:44:52 -0000 1.14 --- TickerSelectorForm.cs 17 May 2005 23:15:45 -0000 1.15 *************** *** 89,92 **** --- 89,93 ---- this.comboBoxAvailableSelectionRules.Items.Add("AverageRawOpenPrice"); this.comboBoxAvailableSelectionRules.Items.Add("WinningOpenToClose"); + this.comboBoxAvailableSelectionRules.Items.Add("OpenCloseCorrelationToBenchmark"); } *************** *** 591,594 **** --- 592,606 ---- this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); + } + else if (this.comboBoxAvailableSelectionRules.Text == "OpenCloseCorrelationToBenchmark") + { + if(this.textBoxGroupID.Text != "") + returnValue = new SelectorByOpenCloseCorrelationToBenchmark(this.textBoxGroupID.Text, this.textBoxMarketIndex.Text, + this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, + this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); + else + returnValue = new SelectorByOpenCloseCorrelationToBenchmark(this.tableOfSelectedTickers, this.textBoxMarketIndex.Text, + this.checkBoxASCMode.Checked, this.dateTimePickerFirstDate.Value, + this.dateTimePickerLastDate.Value, Int32.Parse(this.textBoxMaxNumOfReturnedTickers.Text)); } return returnValue; *************** *** 616,620 **** private void comboBoxAvailableSelectionRules_SelectedValueChanged(object sender, System.EventArgs e) { ! if(this.comboBoxAvailableSelectionRules.Text == "QuotedAtEachMarketDay") { this.setVisibilityForControls_QuotedAtEachMarketDay(true); --- 628,633 ---- private void comboBoxAvailableSelectionRules_SelectedValueChanged(object sender, System.EventArgs e) { ! if(this.comboBoxAvailableSelectionRules.Text == "QuotedAtEachMarketDay" || ! this.comboBoxAvailableSelectionRules.Text == "OpenCloseCorrelationToBenchmark") { this.setVisibilityForControls_QuotedAtEachMarketDay(true); |
|
From: Marco M. <mi...@us...> - 2005-05-17 23:13:34
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18849/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandlerCTOTest.cs RunEfficientCTCPortfolio.cs RunEfficientPortfolio.cs Log Message: Updated files for the EfficientPortfolio script: - new call for the genetic optimizer; - added new parameter for the CloseToClose RunEfficientPortfolio (main.cs may be changed manually); - added minimal changes Index: EndOfDayTimerHandlerCTOTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTOTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerCTOTest.cs 4 May 2005 18:21:07 -0000 1.1 --- EndOfDayTimerHandlerCTOTest.cs 17 May 2005 23:13:25 -0000 1.2 *************** *** 155,159 **** SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers/2); //SelectorByOpenToCloseVolatility lessVolatile = // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), --- 155,159 ---- SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers); //SelectorByOpenToCloseVolatility lessVolatile = // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), *************** *** 166,170 **** new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers/2, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), --- 166,170 ---- new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), *************** *** 194,198 **** this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; --- 194,200 ---- this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; Index: RunEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTCPortfolio.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RunEfficientCTCPortfolio.cs 11 Apr 2005 18:52:31 -0000 1.5 --- RunEfficientCTCPortfolio.cs 17 May 2005 23:13:25 -0000 1.6 *************** *** 60,63 **** --- 60,64 ---- { private int numDayOfPortfolioLife; + private double maxAcceptableCloseToCloseDrawdown; public RunEfficientCTCPorfolio(string tickerGroupID, int numberOfEligibleTickers, *************** *** 67,71 **** DateTime startDate, DateTime endDate, int numDaysOfPortfolioLife, double targetReturn, ! PortfolioType portfolioType): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, --- 68,72 ---- DateTime startDate, DateTime endDate, int numDaysOfPortfolioLife, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, *************** *** 77,80 **** --- 78,82 ---- this.ScriptName = "CloseToCloseScripts"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; + this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; } #region Run *************** *** 89,93 **** this.populationSizeForGeneticOptimizer, this.benchmark, this.numDayOfPortfolioLife, this.targetReturn, ! this.portfolioType); } --- 91,95 ---- this.populationSizeForGeneticOptimizer, this.benchmark, this.numDayOfPortfolioLife, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } Index: RunEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientPortfolio.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RunEfficientPortfolio.cs 4 May 2005 18:30:54 -0000 1.6 --- RunEfficientPortfolio.cs 17 May 2005 23:13:25 -0000 1.7 *************** *** 53,57 **** public class RunEfficientPorfolio { ! public static double MaxNumberOfHoursForScript = 6; //if MaxNumberOfHoursForScript has elapsed and the script //is still running, it will be stopped. --- 53,57 ---- public class RunEfficientPorfolio { ! public static double MaxNumberOfHoursForScript = 5; //if MaxNumberOfHoursForScript has elapsed and the script //is still running, it will be stopped. *************** *** 87,91 **** protected DateTime startingTimeForScript; ! public virtual string ScriptName { --- 87,91 ---- protected DateTime startingTimeForScript; ! public virtual string ScriptName { *************** *** 93,97 **** set{this.scriptName = value;} } ! public RunEfficientPorfolio(string tickerGroupID, int numberOfEligibleTickers, --- 93,101 ---- set{this.scriptName = value;} } ! ! public DateTime TimerLastDate ! { ! get{return this.endOfDayTimer.GetCurrentTime().DateTime ;} ! } public RunEfficientPorfolio(string tickerGroupID, int numberOfEligibleTickers, *************** *** 160,173 **** protected virtual void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { - //Report report; - if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || DateTime.Now >= this.startingTimeForScript.AddHours(RunEfficientPorfolio.MaxNumberOfHoursForScript)) //last date is reached by the timer or MaxNumberOfHoursForScript hours //are elapsed from the time script started ! { ! this.endOfDayTimer.Stop(); ! ! string fileName = "From"+this.numberOfEligibleTickers + "LiqDays" + this.numDaysForLiquidity + "Portfolio" + this.numberOfTickersToBeChosen + "GenNum" + --- 164,177 ---- protected virtual void checkDateForReport(Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || DateTime.Now >= this.startingTimeForScript.AddHours(RunEfficientPorfolio.MaxNumberOfHoursForScript)) //last date is reached by the timer or MaxNumberOfHoursForScript hours //are elapsed from the time script started ! this.SaveScriptResults(); ! } ! ! public virtual void SaveScriptResults() ! { ! string fileName = "From"+this.numberOfEligibleTickers + "LiqDays" + this.numDaysForLiquidity + "Portfolio" + this.numberOfTickersToBeChosen + "GenNum" + *************** *** 176,197 **** "Target" + Convert.ToString(this.targetReturn) + Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveAccounts = System.Configuration.ConfigurationSettings.AppSettings["AccountsArchive"] + ! "\\" + this.ScriptName + "\\"; ! //default report with numIntervalDays = 1 ! AccountReport accountReport = this.account.CreateReport(fileName,1,this.endDateTime,this.benchmark, ! new HistoricalAdjustedQuoteProvider()); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".rep"); ! ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! ObjectArchiver.Archive(this.account, ! dirNameWhereToSaveAccounts + ! fileName + ".acc"); ! } } public virtual void Run() { --- 180,206 ---- "Target" + Convert.ToString(this.targetReturn) + Convert.ToString(this.portfolioType); ! string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; ! string dirNameWhereToSaveAccounts = System.Configuration.ConfigurationSettings.AppSettings["AccountsArchive"] + ! "\\" + this.ScriptName + "\\"; ! //default report with numIntervalDays = 1 ! AccountReport accountReport = this.account.CreateReport(fileName,1, ! this.endOfDayTimer.GetCurrentTime(), ! this.benchmark, ! new HistoricalAdjustedQuoteProvider()); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ! ObjectArchiver.Archive(accountReport, ! dirNameWhereToSaveReports + ! fileName + ".rep"); ! this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveAccounts); ! ObjectArchiver.Archive(this.account, ! dirNameWhereToSaveAccounts + ! fileName + ".acc"); ! ! this.endOfDayTimer.Stop(); ! } + + public virtual void Run() { Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** EndOfDayTimerHandlerCTC.cs 4 May 2005 18:30:54 -0000 1.6 --- EndOfDayTimerHandlerCTC.cs 17 May 2005 23:13:25 -0000 1.7 *************** *** 46,49 **** --- 46,54 ---- private int numDaysOfPortfolioLife; private int daysCounter; + private double maxAcceptableCloseToCloseDrawdown; + private bool stopLossConditionReached; + private double currentAccountValue; + private double previousAccountValue; + public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, *************** *** 54,58 **** int numDaysOfPortfolioLife, double targetReturn, ! PortfolioType portfolioType): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, account, --- 59,63 ---- int numDaysOfPortfolioLife, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, account, *************** *** 64,67 **** --- 69,76 ---- this.numDaysOfPortfolioLife = numDaysOfPortfolioLife; this.daysCounter = 0; + this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; + this.stopLossConditionReached = false; + this.currentAccountValue = 0.0; + this.previousAccountValue = 0.0; } *************** *** 72,81 **** currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers/2); this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedInEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity),currentDate, ! this.numberOfEligibleTickers/2, this.benchmark); return quotedInEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } --- 81,90 ---- currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers); this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedInEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity),currentDate, ! this.numberOfEligibleTickers, this.benchmark); return quotedInEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } *************** *** 101,105 **** this.numDaysOfPortfolioLife, this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; --- 110,116 ---- this.numDaysOfPortfolioLife, this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTCPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; *************** *** 126,129 **** --- 137,141 ---- this.orders.Clear(); } + this.updateStopLossCondition(); } #endregion *************** *** 181,190 **** } } ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.daysCounter++; ! if(this.daysCounter == this.numDaysOfPortfolioLife) //it's time to change portfolio { --- 193,218 ---- } } ! ! private void updateStopLossCondition() ! { ! this.previousAccountValue = this.currentAccountValue; ! this.currentAccountValue = this.account.GetMarketValue(); ! if((this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) ! { ! this.stopLossConditionReached = true; ! } ! else ! { ! this.stopLossConditionReached = false; ! } ! } ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.daysCounter++; ! if(this.daysCounter == this.numDaysOfPortfolioLife || ! this.stopLossConditionReached) //it's time to change portfolio { Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** EndOfDayTimerHandlerCTO.cs 4 May 2005 18:30:54 -0000 1.10 --- EndOfDayTimerHandlerCTO.cs 17 May 2005 23:13:25 -0000 1.11 *************** *** 149,153 **** SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers/2); //SelectorByOpenToCloseVolatility lessVolatile = // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), --- 149,153 ---- SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers); //SelectorByOpenToCloseVolatility lessVolatile = // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), *************** *** 160,164 **** new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers/2, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), --- 160,164 ---- new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), *************** *** 186,190 **** this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; --- 186,192 ---- this.targetReturn, this.portfolioType); ! GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio, ! this.populationSizeForGeneticOptimizer, ! this.generationNumberForGeneticOptimizer); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; |
|
From: Marco M. <mi...@us...> - 2005-05-17 23:06:11
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17337/b3_Data/Selectors Modified Files: SelectionType.cs Added Files: SelectorByOpenCloseCorrelationToBenchmark.cs Log Message: Added new ITickerSelector for selecting tickers by OpenToClose correlation to benchmark --- NEW FILE: SelectorByOpenCloseCorrelationToBenchmark.cs --- /* QuantProject - Quantitative Finance Library SelectorByOpenCloseCorrelationToBenchmark.cs Copyright (C) 2005 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 open close correlation to /// a given benchmark /// </summary> public class SelectorByOpenCloseCorrelationToBenchmark : TickerSelector, ITickerSelector { private string benchmark; public SelectorByOpenCloseCorrelationToBenchmark(DataTable setOfTickersToBeSelected, string benchmark, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers): base(setOfTickersToBeSelected, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { this.benchmark = benchmark; } public SelectorByOpenCloseCorrelationToBenchmark(string groupID, string benchmark, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers): base(groupID, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { this.benchmark = benchmark; } public DataTable GetTableOfSelectedTickers() { if(this.setOfTickersToBeSelected == null) return QuantProject.Data.DataTables.Quotes.GetTickersByOpenCloseCorrelationToBenchmark(this.isOrderedInASCMode, this.groupID,this.benchmark, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers); else return QuantProject.Data.DataTables.Quotes.GetTickersByOpenCloseCorrelationToBenchmark(this.isOrderedInASCMode, this.setOfTickersToBeSelected,this.benchmark, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers); } public void SelectAllTickers() { ; } } } Index: SelectionType.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Selectors/SelectionType.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** SelectionType.cs 14 Apr 2005 18:33:06 -0000 1.10 --- SelectionType.cs 17 May 2005 23:06:01 -0000 1.11 *************** *** 41,45 **** QuotedAtEachMarketDay, AverageRawOpenPrice, ! WinningOpenToClose } } --- 41,46 ---- QuotedAtEachMarketDay, AverageRawOpenPrice, ! WinningOpenToClose, ! OpenCloseCorrelationToBenchmark } } |
|
From: Marco M. <mi...@us...> - 2005-05-17 23:06:10
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17337/b3_Data/DataTables Modified Files: Quotes.cs Log Message: Added new ITickerSelector for selecting tickers by OpenToClose correlation to benchmark Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Quotes.cs 19 Apr 2005 18:30:48 -0000 1.15 --- Quotes.cs 17 May 2005 23:06:00 -0000 1.16 *************** *** 4,7 **** --- 4,8 ---- using System.Text; using QuantProject.ADT; + using QuantProject.ADT.Statistics; using QuantProject.ADT.Histories; using QuantProject.DataAccess; *************** *** 364,367 **** --- 365,420 ---- } + private static float[] getArrayOfCloseToOpenRatios(string ticker, + DateTime firstQuoteDate, + DateTime lastQuoteDate) + { + float[] returnValue; + Quotes tickerQuotes = new Quotes(ticker, firstQuoteDate, lastQuoteDate); + returnValue = ExtendedDataTable.GetArrayOfFloatFromRatioOfColumns(tickerQuotes, "quClose", "quOpen"); + return returnValue; + + } + + /// <summary> + /// returns tickers of a given group ordered by open - close + /// correlation to a given benchmark + /// </summary> + public static DataTable GetTickersByOpenCloseCorrelationToBenchmark( bool orderByASC, + string groupID, string benchmark, + DateTime firstQuoteDate, + DateTime lastQuoteDate, + long maxNumOfReturnedTickers) + { + DataTable tickersOfGroup = new Tickers_tickerGroups(groupID); + return GetTickersByOpenCloseCorrelationToBenchmark(orderByASC, tickersOfGroup, benchmark, + firstQuoteDate, lastQuoteDate, + maxNumOfReturnedTickers); + } + + /// <summary> + /// returns tickers of a given set of tickers ordered by open - close + /// correlation to a given benchmark + /// </summary> + public static DataTable GetTickersByOpenCloseCorrelationToBenchmark( bool orderByASC, + DataTable setOfTickers, string benchmark, + DateTime firstQuoteDate, + DateTime lastQuoteDate, + long maxNumOfReturnedTickers) + { + if(!setOfTickers.Columns.Contains("OpenCloseCorrelationToBenchmark")) + setOfTickers.Columns.Add("OpenCloseCorrelationToBenchmark", System.Type.GetType("System.Double")); + float[] benchmarkRatios = getArrayOfCloseToOpenRatios(benchmark, firstQuoteDate, lastQuoteDate); + foreach(DataRow row in setOfTickers.Rows) + { + float[] tickerRatios = getArrayOfCloseToOpenRatios((string)row[0], + firstQuoteDate, lastQuoteDate); + if(tickerRatios.Length == benchmarkRatios.Length) + row["OpenCloseCorrelationToBenchmark"] = + BasicFunctions.PearsonCorrelationCoefficient(benchmarkRatios, tickerRatios); + } + DataTable tableToReturn = ExtendedDataTable.CopyAndSort(setOfTickers,"OpenCloseCorrelationToBenchmark", orderByASC); + ExtendedDataTable.DeleteRows(tableToReturn, maxNumOfReturnedTickers); + return tableToReturn; + } private History history; |
|
From: Marco M. <mi...@us...> - 2005-05-17 23:06:08
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17337/b3_Data Modified Files: Data.prjx b3_Data.csproj Log Message: Added new ITickerSelector for selecting tickers by OpenToClose correlation to benchmark Index: Data.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Data.prjx,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Data.prjx 14 Apr 2005 18:36:46 -0000 1.4 --- Data.prjx 17 May 2005 23:06:00 -0000 1.5 *************** *** 33,36 **** --- 33,37 ---- <File name=".\QuantProject.Applications.Downloader.TickerSelectors.TickerSelectorForm.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" /> <File name=".\Selectors\SelectorByWinningOpenToClose.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\Selectors\SelectorByOpenCloseCorrelationToBenchmark.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** b3_Data.csproj 14 Apr 2005 18:33:22 -0000 1.25 --- b3_Data.csproj 17 May 2005 23:06:00 -0000 1.26 *************** *** 193,196 **** --- 193,201 ---- /> <File + RelPath = "DataTables\Quotes.resx" + DependentUpon = "Quotes.cs" + BuildAction = "EmbeddedResource" + /> + <File RelPath = "DataTables\TickerDataTable.cs" SubType = "Component" *************** *** 198,201 **** --- 203,211 ---- /> <File + RelPath = "DataTables\TickerDataTable.resx" + DependentUpon = "TickerDataTable.cs" + BuildAction = "EmbeddedResource" + /> + <File RelPath = "DataTables\Tickers_tickerGroups.cs" SubType = "Component" *************** *** 268,271 **** --- 278,286 ---- /> <File + RelPath = "Selectors\SelectorByOpenCloseCorrelationToBenchmark.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Selectors\SelectorByOpenToCloseLinearCorrelation.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2005-05-17 23:03:45
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16968/b1_ADT/Optimizing/Genetic Modified Files: Genome.cs Log Message: Added IComparable implementation Index: Genome.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/Genome.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Genome.cs 1 Dec 2004 22:36:11 -0000 1.1 --- Genome.cs 17 May 2005 23:03:36 -0000 1.2 *************** *** 31,35 **** /// provided by biology /// </summary> ! public class Genome { private int[] genes; --- 31,35 ---- /// provided by biology /// </summary> ! public class Genome : IComparable { private int[] genes; *************** *** 68,72 **** --- 68,84 ---- get{return this.maxValueForGenes;} } + + //implementation of IComparable interface + public int CompareTo(object obj) { + if(obj is Genome) { + Genome genome = (Genome)obj; + return this.Fitness.CompareTo(genome.Fitness); + } + + throw new ArgumentException("Object is not a Genome"); + } + //end of implementation of IComparable interface + /// <summary> /// It creates a new genome object initialized by a IGenomeManager |
|
From: Marco M. <mi...@us...> - 2005-05-17 23:02:44
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16734/b1_ADT/Optimizing/Genetic Modified Files: GenomeComparer.cs Log Message: IComparer implementation is clearer, now Index: GenomeComparer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeComparer.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenomeComparer.cs 1 Dec 2004 22:36:11 -0000 1.1 --- GenomeComparer.cs 17 May 2005 23:02:35 -0000 1.2 *************** *** 36,48 **** public int Compare( object x, object y) { ! if ( !(x is Genome) || !(y is Genome)) ! throw new ArgumentException("Not of type Genome"); ! ! if (((Genome) x).Fitness > ((Genome) y).Fitness) ! return 1; ! else if (((Genome) x).Fitness == ((Genome) y).Fitness) ! return 0; else ! return -1; } } --- 36,57 ---- public int Compare( object x, object y) { ! int returnValue = 0; ! ! if((x is Genome) && (y is Genome)) ! { ! if ( ((Genome) x).Fitness > ((Genome) y).Fitness ) ! returnValue = 1; ! else if ( ((Genome) x).Fitness < ((Genome) y).Fitness ) ! returnValue = -1; ! } else ! throw new ArgumentException("Both objects to compare must be genomes!"); ! //old implementation ! //else if ( !(x is Genome) && (y is Genome)) ! //returnValue = -1; ! //else if ((x is Genome) && !(y is Genome)) ! //returnValue = 1; ! ! return returnValue; } } |
|
From: Marco M. <mi...@us...> - 2005-05-17 23:01:07
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16343/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: Fixed bug: population size and generation number are now properly initialized by a new constructor Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GeneticOptimizer.cs 14 Dec 2004 21:26:54 -0000 1.2 --- GeneticOptimizer.cs 17 May 2005 23:00:57 -0000 1.3 *************** *** 129,138 **** /// IGenomeManager interface /// Default GO parameters: crossoverRate = 0.85, mutationRate = 0.02, elitismRate = 0.01, - /// populationSize = 1000, generationNumber = 100 /// keepOnRunningUntilConvergenceIsReached = false, minConvergenceRate = 0.80 /// </summary> ! public GeneticOptimizer(IGenomeManager genomeManager) { this.genomeManager = genomeManager; this.commonInitialization(); --- 129,140 ---- /// IGenomeManager interface /// Default GO parameters: crossoverRate = 0.85, mutationRate = 0.02, elitismRate = 0.01, /// keepOnRunningUntilConvergenceIsReached = false, minConvergenceRate = 0.80 /// </summary> ! public GeneticOptimizer(IGenomeManager genomeManager, int populationSize, ! int generationNumber) { this.genomeManager = genomeManager; + this.populationSize = populationSize; + this.generationNumber = generationNumber; this.commonInitialization(); *************** *** 325,329 **** i--) { ! this.currentEliteToTransmitToNextGeneration.Add((Genome)this.currentGeneration[i]); } } --- 327,332 ---- i--) { ! if(this.currentGeneration[i] is Genome) ! this.currentEliteToTransmitToNextGeneration.Add((Genome)this.currentGeneration[i]); } } *************** *** 332,340 **** { for(int i = 0; ! i < this.currentEliteToTransmitToNextGeneration.Count-1; i++) { ! this.nextGeneration.Add(this.currentEliteToTransmitToNextGeneration[i]); } } --- 335,343 ---- { for(int i = 0; ! i < this.currentEliteToTransmitToNextGeneration.Count; i++) { ! this.nextGeneration.Add((Genome)this.currentEliteToTransmitToNextGeneration[i]); } } *************** *** 408,415 **** { this.currentGeneration.Clear(); ! // Note that next generation is greater than current: // due to the population size, genomes with lowest fitness are abandoned for (int i = 1 ; i <= this.populationSize; i++) ! this.currentGeneration.Add(this.nextGeneration[this.nextGeneration.Count - i]); } --- 411,419 ---- { this.currentGeneration.Clear(); ! int numOfNextGeneration = this.nextGeneration.Count; ! // Note that next generation is greater than current: // due to the population size, genomes with lowest fitness are abandoned for (int i = 1 ; i <= this.populationSize; i++) ! this.currentGeneration.Add(this.nextGeneration[numOfNextGeneration - i]); } |
|
From: marco\.milletti\@l <mar...@li...> - 2005-05-05 13:22:08
|
> At 06:25 PM 5/4/2005 +0000, you wrote: > > >! if( dt.Rows[0]= ["CloseToOpenStandDev"] is double ) > >! //cast is possible > >= ! returnValue =3D (double)dt.Rows[0]["CloseToOpenStandDev"];=0D = > >! } > >! return returnValue; > > Millo, sei sicuro che= sia un approccio corretto? Cosa succede se > dt.Rows[0]["CloseToOpenSt= andDev"] non e' un double? la dt.Rows[0]["CloseToOpenStandDev"] is do= uble =E8 false >Quando puo' succedere? Questa =E8 una bella domanda= ... Se lo sapessi non avrei aggiunto l'if ma avrei corretto il codice ..= . :-) > Forse mi manca un pezzo, ma sarei tentato di pensare che una= bell'exception > sia la cosa migliore. Meglio l'exception. Ma quand= o hai il prurito di vedere le curve buone, vuoi che lo script che dura 10= ore venga eseguito ... a mali estremi, estremi rimedi (almeno temporanea= mente) > Nell'ordine, gli errori e' meglio che siano: > - rilevabili= dal compilatore (caso preferibile) > - rilevabili dal run time (caso me= dio) > - logici (caso peggiore) > > Evitando l'eccezione, non e' che,= per caso, ci spostiamo dal caso due al > caso tre? E' senz'altro co= s=EC. E quando l'errore =E8 "logico" ti ritrovi un'altra eccezione (magar= i, com'e' facile, per lo stesso motivo della prima che viene dribblata) d= a qualche altra parte. Come mi =E8 appena capitato ... :-(( Ciao Mi= llo > Ciao! > > > > -------------------------------------------= ------------ > This SF.Net email is sponsored by: NEC IT Guy Games. > G= et your fingers limbered up and give it your best shot. 4 great events, 4= > opportunities to win big! Highest score wins.NEC IT Guy Games. Play t= o > win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=3D20=0D = > _______________________________________________ > Quantproject-develop= ers mailing list > Qua...@li... > http= s://lists.sourceforge.net/lists/listinfo/quantproject-developers > =0A=0A= =0A=0A____________________________________________________________=0ANavi= ghi a 4 MEGA e i primi 3 mesi sono GRATIS. =0AScegli Libero Adsl Flat sen= za limiti su http://www.libero.it=0A |
|
From: Glauco S. <gl...@my...> - 2005-05-04 19:41:03
|
At 06:25 PM 5/4/2005 +0000, you wrote: >! if( dt.Rows[0]["CloseToOpenStandDev"] is double ) >! //cast is possible >! returnValue = (double)dt.Rows[0]["CloseToOpenStandDev"]; >! } >! return returnValue; Millo, sei sicuro che sia un approccio corretto? Cosa succede se dt.Rows[0]["CloseToOpenStandDev"] non e' un double? Quando puo' succedere? Forse mi manca un pezzo, ma sarei tentato di pensare che una bell'exception sia la cosa migliore. Nell'ordine, gli errori e' meglio che siano: - rilevabili dal compilatore (caso preferibile) - rilevabili dal run time (caso medio) - logici (caso peggiore) Evitando l'eccezione, non e' che, per caso, ci spostiamo dal caso due al caso tre? Ciao! |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8274/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandlerCTO.cs RunEfficientCTOPortfolio.cs RunEfficientPortfolio.cs Log Message: Updated files for the EfficientPortfolio script: minimal changes Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EndOfDayTimerHandlerCTO.cs 26 Apr 2005 19:02:12 -0000 1.9 --- EndOfDayTimerHandlerCTO.cs 4 May 2005 18:30:54 -0000 1.10 *************** *** 146,168 **** DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ ! /*SelectorByWinningOpenToClose selectorByWinningOpenToClose = ! new SelectorByWinningOpenToClose(this.tickerGroupID, false, currentDate, ! currentDate, this.numberOfEligibleTickers); ! DataTable winningOpenToCloseTickers = selectorByWinningOpenToClose.GetTableOfSelectedTickers(); ! */ SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers/2); ! SelectorByOpenToCloseVolatility lessVolatile = ! new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, ! this.numberOfEligibleTickers/4); ! this.eligibleTickers = lessVolatile.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers/4, this.benchmark); return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } --- 146,169 ---- DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ ! SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers/2); ! //SelectorByOpenToCloseVolatility lessVolatile = ! // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), ! // true, currentDate.AddDays(-this.numDaysForLiquidity/3), ! // currentDate, ! // this.numberOfEligibleTickers/4); ! this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers/2, this.benchmark); ! //SelectorByWinningOpenToClose winners = ! // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), ! // false, currentDate.AddDays(-2), ! // currentDate, this.numberOfEligibleTickers/4); ! //return winners.GetTableOfSelectedTickers(); return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } Index: RunEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientPortfolio.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RunEfficientPortfolio.cs 26 Apr 2005 19:02:14 -0000 1.5 --- RunEfficientPortfolio.cs 4 May 2005 18:30:54 -0000 1.6 *************** *** 53,57 **** public class RunEfficientPorfolio { ! public static double MaxNumberOfHoursForScript = 10; //if MaxNumberOfHoursForScript has elapsed and the script //is still running, it will be stopped. --- 53,57 ---- public class RunEfficientPorfolio { ! public static double MaxNumberOfHoursForScript = 6; //if MaxNumberOfHoursForScript has elapsed and the script //is still running, it will be stopped. *************** *** 129,132 **** --- 129,133 ---- this.endOfDayTimer = new IndexBasedEndOfDayTimer( this.startDateTime, this.benchmark ); + } *************** *** 206,209 **** --- 207,211 ---- this.checkDateForReport); + //in inherited classes'override method: //add here TimerHandler's handlers to timer's events //example Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** EndOfDayTimerHandlerCTC.cs 26 Apr 2005 19:02:11 -0000 1.5 --- EndOfDayTimerHandlerCTC.cs 4 May 2005 18:30:54 -0000 1.6 *************** *** 70,79 **** { SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID,false, ! currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers); this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedInEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity),currentDate, ! this.numberOfEligibleTickers, this.benchmark); return quotedInEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } --- 70,81 ---- { SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID,false, ! currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, ! this.numberOfEligibleTickers/2); this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedInEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity),currentDate, ! this.numberOfEligibleTickers/2, this.benchmark); return quotedInEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } *************** *** 150,154 **** { if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(15000); this.marketCloseEventHandler_orderChosenTickers(); --- 152,156 ---- { if(this.orders.Count == 0 && this.account.Transactions.Count == 0) ! this.account.AddCash(17000); this.marketCloseEventHandler_orderChosenTickers(); Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** RunEfficientCTOPortfolio.cs 11 Apr 2005 18:52:32 -0000 1.17 --- RunEfficientCTOPortfolio.cs 4 May 2005 18:30:54 -0000 1.18 *************** *** 99,103 **** this.targetReturn, this.portfolioType); ! } --- 99,103 ---- this.targetReturn, this.portfolioType); ! } |
|
From: Marco M. <mi...@us...> - 2005-05-04 18:29:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7317/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientPortfolio.cs Log Message: the variance and the average rate of return of portfolio are now computed in a different way (that seems to be right, now ...) Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenomeManagerForEfficientPortfolio.cs 26 Apr 2005 19:02:13 -0000 1.7 --- GenomeManagerForEfficientPortfolio.cs 4 May 2005 18:29:00 -0000 1.8 *************** *** 167,188 **** { double returnValue = 0; ! double portfolioVariance = this.getPortfolioVariance(genome.Genes()); ! double portfolioRateOfReturn = this.getPortfolioRateOfReturn(genome.Genes()); ! ! if(!Double.IsInfinity(portfolioVariance) || ! !Double.IsInfinity(portfolioRateOfReturn) || ! !Double.IsNaN(portfolioVariance) || ! !Double.IsNaN(portfolioRateOfReturn)) ! //variance and rate of return are ! //double values computed in the right way { this.variance = portfolioVariance; ! this.rateOfReturn = portfolioRateOfReturn; ! NormalDistribution normal = new NormalDistribution(portfolioRateOfReturn, Math.Sqrt(portfolioVariance)); if(this.portfolioType == PortfolioType.OnlyLong || this.portfolioType == PortfolioType.ShortAndLong) //the genome fitness is evaluated as if //the portfolio was long ! //ALTERNATIVE: returnValue = normal.GetProbability(this.targetPerformance*0.75,this.targetPerformance*1.25); returnValue = 1.0 - normal.GetProbability(this.targetPerformance); else//only short orders are permitted --- 167,197 ---- { double returnValue = 0; ! //OLD IMPLEMENTATION double portfolioRateOfReturn = this.getPortfolioRateOfReturn(genome.Genes()); ! //OLD IMPLEMENTATION double portfolioVariance = this.getPortfolioVariance(genome.Genes()); ! double[] portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! double averagePortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(portfolioRatesOfReturn); ! ! double portfolioVariance = ! BasicFunctions.Variance(portfolioRatesOfReturn); ! ! if(!Double.IsInfinity(portfolioVariance) && ! !Double.IsInfinity(averagePortfolioRateOfReturn) && ! !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn)) ! //both variance and rate of return are ! //double values computed in the right way: ! // so it's possible to assign fitness using normal distribution class { this.variance = portfolioVariance; ! this.rateOfReturn = averagePortfolioRateOfReturn; ! NormalDistribution normal = ! new NormalDistribution(this.rateOfReturn, ! Math.Sqrt(this.variance)); if(this.portfolioType == PortfolioType.OnlyLong || this.portfolioType == PortfolioType.ShortAndLong) //the genome fitness is evaluated as if //the portfolio was long ! //returnValue = normal.GetProbability(this.targetPerformance*0.75,this.targetPerformance*1.25); returnValue = 1.0 - normal.GetProbability(this.targetPerformance); else//only short orders are permitted *************** *** 250,277 **** protected double getPortfolioVariance(int[] tickerIdx) { ! double sumOfVariances = this.getSumOfVariances(tickerIdx); ! double sumOfCovariances = this.getSumOfCovariances(tickerIdx); double returnValue = sumOfVariances + sumOfCovariances; return returnValue; } ! protected double getSumOfVariances(int[] tickerIdx) { double returnValue = 0; ! double tickerCoeff = 1.0/this.genomeSize; foreach(int idx in tickerIdx) { ! returnValue += BasicFunctions.Variance((float[])this.setOfTickers.Rows[idx]["ArrayOfRatesOfReturn"]); } - returnValue = returnValue * tickerCoeff * tickerCoeff; return returnValue; } ! protected double getSumOfCovariances(int[] tickerIdx) { double returnValue = 0; float[] ticker_i; float[] ticker_j; ! double tickerCoeff = 1.0/this.genomeSize; for(int i = 0; i<this.genomeSize ; i++) { --- 259,286 ---- protected double getPortfolioVariance(int[] tickerIdx) { ! double sumOfVariances = this.getWeightedSumOfVariances(tickerIdx); ! double sumOfCovariances = this.getWeightedSumOfCovariances(tickerIdx); double returnValue = sumOfVariances + sumOfCovariances; return returnValue; } ! protected double getWeightedSumOfVariances(int[] tickerIdx) { double returnValue = 0; ! double tickerCoeff = 1.0/this.genomeSize; foreach(int idx in tickerIdx) { ! returnValue += tickerCoeff * tickerCoeff * ! BasicFunctions.Variance((float[])this.setOfTickers.Rows[idx]["ArrayOfRatesOfReturn"]); } return returnValue; } ! protected double getWeightedSumOfCovariances(int[] tickerIdx) { double returnValue = 0; float[] ticker_i; float[] ticker_j; ! double tickerCoeff = 1.0/this.genomeSize; for(int i = 0; i<this.genomeSize ; i++) { *************** *** 282,290 **** { ticker_j = (float[])this.setOfTickers.Rows[j]["ArrayOfRatesOfReturn"]; ! returnValue += BasicFunctions.CoVariance(ticker_i, ticker_j); } } } - returnValue = returnValue * tickerCoeff * tickerCoeff; return returnValue; } --- 291,299 ---- { ticker_j = (float[])this.setOfTickers.Rows[j]["ArrayOfRatesOfReturn"]; ! returnValue += tickerCoeff * tickerCoeff * ! BasicFunctions.CoVariance(ticker_i, ticker_j); } } } return returnValue; } *************** *** 321,328 **** return ratesOfReturns; } ! ! ! ! protected double getPortfolioRateOfReturn(int[] tickerIdx) { --- 330,334 ---- return ratesOfReturns; } ! protected double getPortfolioRateOfReturn(int[] tickerIdx) { *************** *** 330,338 **** foreach(int idx in tickerIdx) { ! returnValue += BasicFunctions.SimpleAverage((float[])this.setOfTickers.Rows[idx]["ArrayOfRatesOfReturn"]); } //the investment is assumed to be equally divided return (returnValue/this.GenomeSize); } } --- 336,365 ---- foreach(int idx in tickerIdx) { ! returnValue += ! BasicFunctions.SimpleAverage((float[])this.setOfTickers.Rows[idx]["ArrayOfRatesOfReturn"]); } //the investment is assumed to be equally divided return (returnValue/this.GenomeSize); + + } + + protected double[] getPortfolioRatesOfReturn(int[] tickerIdx) + { + int numberOfExaminedReturns = + ((float[])this.setOfTickers.Rows[tickerIdx[0]]["ArrayOfRatesOfReturn"]).Length; + double[] returnValue = new double[numberOfExaminedReturns]; + for(int i = 0; i<returnValue.Length; i++) + { + foreach(int idx in tickerIdx) + { + float[] tickerRatesOfReturn = (float[])this.setOfTickers.Rows[idx]["ArrayOfRatesOfReturn"]; + returnValue[i] += tickerRatesOfReturn[i]/this.genomeSize; + //the investment is assumed to be equally divided for each ticker + } + } + return returnValue; + } + } |
|
From: Marco M. <mi...@us...> - 2005-05-04 18:26:00
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6416/b2_DataAccess/Tables Modified Files: Quotes.cs Log Message: Added to some methods the "if" clause with "is" operator before casting, in order to avoid noisy exception. Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Quotes.cs,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Quotes.cs 19 Apr 2005 18:30:40 -0000 1.24 --- Quotes.cs 4 May 2005 18:25:51 -0000 1.25 *************** *** 721,724 **** --- 721,726 ---- { + double returnValue = Double.MaxValue; + DataTable dt; string sql = "SELECT quotes.quTicker, " + *************** *** 730,737 **** " GROUP BY quotes.quTicker"; dt = SqlExecutor.GetDataTable( sql ); ! if(dt.Rows.Count==0) ! return 0; ! else ! return (double)dt.Rows[0]["CloseToOpenStandDev"]; } --- 732,742 ---- " GROUP BY quotes.quTicker"; dt = SqlExecutor.GetDataTable( sql ); ! if(dt.Rows.Count > 0) ! { ! if( dt.Rows[0]["CloseToOpenStandDev"] is double ) ! //cast is possible ! returnValue = (double)dt.Rows[0]["CloseToOpenStandDev"]; ! } ! return returnValue; } *************** *** 745,749 **** { ! DataTable dt; string sql = "SELECT quotes.quTicker, tickers.tiCompanyName, " + "Avg(quotes.quOpen) AS AverageRawOpenPrice " + --- 750,755 ---- { ! double returnValue = 0; ! DataTable dt; string sql = "SELECT quotes.quTicker, tickers.tiCompanyName, " + "Avg(quotes.quOpen) AS AverageRawOpenPrice " + *************** *** 755,762 **** "GROUP BY quotes.quTicker, tickers.tiCompanyName"; dt = SqlExecutor.GetDataTable( sql ); ! if(dt.Rows.Count==0) ! return 0; ! else ! return (double)dt.Rows[0]["AverageRawOpenPrice"]; } --- 761,772 ---- "GROUP BY quotes.quTicker, tickers.tiCompanyName"; dt = SqlExecutor.GetDataTable( sql ); ! if(dt.Rows.Count > 0) ! { ! if( dt.Rows[0]["AverageRawOpenPrice"] is double ) ! //cast is possible ! returnValue = (double)dt.Rows[0]["AverageRawOpenPrice"]; ! } ! return returnValue; ! } *************** *** 770,774 **** { ! DataTable dt; string sql = "SELECT quotes.quTicker, tickers.tiCompanyName, " + "StDev(quotes.quOpen) AS RawOpenPriceStdDev " + --- 780,785 ---- { ! double returnValue = Double.MaxValue; ! DataTable dt; string sql = "SELECT quotes.quTicker, tickers.tiCompanyName, " + "StDev(quotes.quOpen) AS RawOpenPriceStdDev " + *************** *** 780,787 **** "GROUP BY quotes.quTicker, tickers.tiCompanyName"; dt = SqlExecutor.GetDataTable( sql ); ! if(dt.Rows.Count==0) ! return 0; ! else ! return (double)dt.Rows[0]["RawOpenPriceStdDev"]; } --- 791,801 ---- "GROUP BY quotes.quTicker, tickers.tiCompanyName"; dt = SqlExecutor.GetDataTable( sql ); ! if(dt.Rows.Count > 0) ! { ! if( dt.Rows[0]["RawOpenPriceStdDev"] is double ) ! //cast is possible ! returnValue = (double)dt.Rows[0]["RawOpenPriceStdDev"]; ! } ! return returnValue; } *************** *** 805,810 **** dt = SqlExecutor.GetDataTable( sql ); if(dt.Rows.Count > 0) ! returnValue = (int)dt.Rows[0][0]; ! return returnValue; } --- 819,826 ---- dt = SqlExecutor.GetDataTable( sql ); if(dt.Rows.Count > 0) ! { ! if(dt.Rows[0][0] is int) ! returnValue = (int)dt.Rows[0][0]; ! } return returnValue; } |
|
From: Marco M. <mi...@us...> - 2005-05-04 18:21:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5145/b7_Scripts Modified Files: Scripts.prjx b7_Scripts.csproj Log Message: Added classes to test optimization process for the efficient portfolio Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** b7_Scripts.csproj 24 Apr 2005 15:49:03 -0000 1.25 --- b7_Scripts.csproj 4 May 2005 18:21:01 -0000 1.26 *************** *** 169,172 **** --- 169,177 ---- /> <File + RelPath = "TickerSelectionTesting\EndOfDayTimerHandlerCTOTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\GenomeManagerForEfficientCTCPortfolio.cs" SubType = "Code" *************** *** 204,207 **** --- 209,217 ---- /> <File + RelPath = "TickerSelectionTesting\RunTestOptimizedCTOPortfolio.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\MSFTwalkForward\TsMSFTwalkForward.cs" SubType = "Code" Index: Scripts.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts.prjx,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Scripts.prjx 26 Apr 2005 18:54:52 -0000 1.3 --- Scripts.prjx 4 May 2005 18:21:01 -0000 1.4 *************** *** 30,33 **** --- 30,35 ---- <File name=".\TickerSelectionTesting\PortfolioType.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\WalkForwardTesting\WalkForwardOneRank\IWalkForwardProgressNotifier.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="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-05-04 18:21:16
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5145/b7_Scripts/TickerSelectionTesting Added Files: EndOfDayTimerHandlerCTOTest.cs RunTestOptimizedCTOPortfolio.cs Log Message: Added classes to test optimization process for the efficient portfolio --- NEW FILE: RunTestOptimizedCTOPortfolio.cs --- /* QuantProject - Quantitative Finance Library RunTestOptimizedCTOPorfolio.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.Data; using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.ADT.FileManaging; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Accounting.Reporting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Scripting; using QuantProject.Business.Strategies; using QuantProject.Business.Testing; using QuantProject.Business.Timing; using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// Script to test optimization process /// in choosing the best open/close portfolio /// </summary> [Serializable] public class RunTestOptimizedCTOPorfolio : RunEfficientPorfolio { public RunTestOptimizedCTOPorfolio(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, double targetReturn, PortfolioType portfolioType): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, targetReturn, portfolioType) { this.ScriptName = "TestOptimizedCTOPortfolio"; } protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerCTOTest(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForLiquidity, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.targetReturn, this.portfolioType); } protected override void run_initializeHistoricalQuoteProvider() { this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); } public override void Run() { run_initializeHistoricalQuoteProvider(); run_initializeEndOfDayTimer(); run_initializeAccount(); run_initializeEndOfDayTimerHandler(); this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.endOfDayTimerHandler.MarketOpenEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.endOfDayTimerHandler.MarketCloseEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.checkDateForReport); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); this.endOfDayTimer.Start(); ((EndOfDayTimerHandlerCTOTest)this.endOfDayTimerHandler).Reset(); } } } --- NEW FILE: EndOfDayTimerHandlerCTOTest.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerCTOTest.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 EndOfDayTimerHandlerCTOTest : EndOfDayTimerHandler { private static bool optimized; public EndOfDayTimerHandlerCTOTest(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForLiquidity, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, double targetReturn, PortfolioType portfolioType): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForLiquidity, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, targetReturn, portfolioType) { } #region MarketOpenEventHandler private void marketOpenEventHandler_orderChosenTickers_addToOrderList() { int idx = 0; foreach ( string ticker in this.chosenTickers ) { if(ticker != null) { this.addOrderForTicker( ticker ); this.lastChosenTickers[idx] = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); } idx++; } } private void marketOpenEventHandler_orderChosenTickers() { this.marketOpenEventHandler_orderChosenTickers_addToOrderList(); } /// <summary> /// Handles a "Market Open" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public override void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.orders.Count == 0 && this.account.Transactions.Count == 0) this.account.AddCash(17000); this.marketOpenEventHandler_orderChosenTickers(); foreach(object item in this.orders) { this.account.AddOrder((Order)item); } } #endregion #region MarketCloseEventHandler private void marketCloseEventHandler_closePosition( string ticker ) { this.account.ClosePosition( ticker ); } private void marketCloseEventHandler_closePositions() { if(this.lastChosenTickers != null) { foreach( string ticker in this.lastChosenTickers) { for(int i = 0; i<this.account.Portfolio.Keys.Count; i++) { if(this.account.Portfolio[ticker]!=null) marketCloseEventHandler_closePosition( ticker ); } } } } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.marketCloseEventHandler_closePositions(); } #endregion public void Reset() { EndOfDayTimerHandlerCTOTest.optimized = false; } #region OneHourAfterMarketCloseEventHandler private DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { /* SelectorByAverageRawOpenPrice selectorByOpenPrice = new SelectorByAverageRawOpenPrice(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers, this.minPriceForMinimumCommission, this.maxPriceForMinimumCommission, 0, 2); DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers/2); //SelectorByOpenToCloseVolatility lessVolatile = // new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), // true, currentDate.AddDays(-this.numDaysForLiquidity/3), // currentDate, // this.numberOfEligibleTickers/4); this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers/2, this.benchmark); //SelectorByWinningOpenToClose winners = // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), // false, currentDate.AddDays(-2), // currentDate, this.numberOfEligibleTickers/4); //return winners.GetTableOfSelectedTickers(); return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } private void setTickers(DateTime currentDate) { if(!EndOfDayTimerHandlerCTOTest.optimized) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate.AddDays(this.numDaysForLiquidity)); if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is possible only if the initial set of tickers is //as large as the number of tickers to be chosen { IGenomeManager genManEfficientCTOPortfolio = new GenomeManagerForEfficientCTOPortfolio(setOfTickersToBeOptimized, currentDate, currentDate.AddDays(this.numDaysForLiquidity), this.numberOfTickersToBeChosen, this.targetReturn, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(genManEfficientCTOPortfolio); //GO.KeepOnRunningUntilConvergenceIsReached = true; GO.GenerationNumber = this.generationNumberForGeneticOptimizer; GO.PopulationSize = this.populationSizeForGeneticOptimizer; GO.Run(false); this.chosenTickers = (string[])GO.BestGenome.Meaning; EndOfDayTimerHandlerCTOTest.optimized = true; //this.lastChosenTickers = this.chosenTickers; } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member } } private void oneHourAfterMarketCloseEventHandler_updatePrices() { //min price for minimizing commission amount //according to IB Broker's commission scheme this.minPriceForMinimumCommission = this.account.CashAmount/(this.numberOfTickersToBeChosen*100); this.maxPriceForMinimumCommission = this.maxPriceForMinimumCommission; //just to avoid warning message } /// <summary> /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //this.oneHourAfterMarketCloseEventHandler_updatePrices(); this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Open event this.orders.Clear(); } #endregion } } |
|
From: Marco M. <mi...@us...> - 2005-04-26 19:03:42
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9010/b3_Data/DataTables Modified Files: GroupQuotes.cs Log Message: Added static method for computation of Adj close to close ratios for an entire group of tickers Index: GroupQuotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/GroupQuotes.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GroupQuotes.cs 6 Jan 2005 18:43:57 -0000 1.2 --- GroupQuotes.cs 26 Apr 2005 19:03:32 -0000 1.3 *************** *** 37,40 **** --- 37,52 ---- private string groupID; + //Static method for computing close to close ratios + //of all tickers belonging to a given group + static public void ComputeCloseToCloseRatios(string groupID) + { + DataTable tickers = + QuantProject.DataAccess.Tables.Tickers_tickerGroups.GetTickers(groupID); + foreach(DataRow row in tickers.Rows) + { + QuantProject.DataAccess.Tables.Quotes.ComputeAndCommitCloseToCloseRatios((string)row[0]); + } + } + public GroupQuotes( string groupID, DateTime startDate, DateTime endDate) { |
|
From: Marco M. <mi...@us...> - 2005-04-26 19:02:35
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8284/b7_Scripts/TickerSelectionTesting Modified Files: EndOfDayTimerHandler.cs EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandlerCTO.cs GenomeManagerForEfficientCTCPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientPortfolio.cs PortfolioType.cs RunEfficientPortfolio.cs Log Message: Updated files for the EfficientPortfolio script: - Fixed bug: now co-variance is computed; - It is now possible to find efficient portfolios in which short or long positions can be taken on the behalf of genetic optimization's results . Index: PortfolioType.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/PortfolioType.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PortfolioType.cs 11 Apr 2005 18:52:32 -0000 1.1 --- PortfolioType.cs 26 Apr 2005 19:02:14 -0000 1.2 *************** *** 32,36 **** { OnlyLong, ! OnlyShort } } --- 32,37 ---- { OnlyLong, ! OnlyShort, ! ShortAndLong } } Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** EndOfDayTimerHandlerCTO.cs 14 Apr 2005 18:38:28 -0000 1.8 --- EndOfDayTimerHandlerCTO.cs 26 Apr 2005 19:02:12 -0000 1.9 *************** *** 71,75 **** { this.addOrderForTicker( ticker ); ! this.lastChosenTickers[idx] = ticker; } idx++; --- 71,76 ---- { this.addOrderForTicker( ticker ); ! this.lastChosenTickers[idx] = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); } idx++; *************** *** 145,159 **** DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ ! SelectorByWinningOpenToClose selectorByWinningOpenToClose = new SelectorByWinningOpenToClose(this.tickerGroupID, false, currentDate, currentDate, this.numberOfEligibleTickers); DataTable winningOpenToCloseTickers = selectorByWinningOpenToClose.GetTableOfSelectedTickers(); ! SelectorByLiquidity mostLiquid = new SelectorByLiquidity(winningOpenToCloseTickers, false, ! currentDate.AddDays(-this.numDaysForLiquidity), currentDate, this.numberOfEligibleTickers); ! this.eligibleTickers = mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers, this.benchmark); return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } --- 146,168 ---- DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); */ ! /*SelectorByWinningOpenToClose selectorByWinningOpenToClose = new SelectorByWinningOpenToClose(this.tickerGroupID, false, currentDate, currentDate, this.numberOfEligibleTickers); DataTable winningOpenToCloseTickers = selectorByWinningOpenToClose.GetTableOfSelectedTickers(); ! */ ! SelectorByLiquidity mostLiquid = new SelectorByLiquidity(this.tickerGroupID, false, ! currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers/2); ! SelectorByOpenToCloseVolatility lessVolatile = ! new SelectorByOpenToCloseVolatility(mostLiquid.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, ! this.numberOfEligibleTickers/4); ! ! this.eligibleTickers = lessVolatile.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, false, currentDate.AddDays(-this.numDaysForLiquidity), ! currentDate, this.numberOfEligibleTickers/4, this.benchmark); return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenomeManagerForEfficientCTOPortfolio.cs 11 Apr 2005 18:52:31 -0000 1.7 --- GenomeManagerForEfficientCTOPortfolio.cs 26 Apr 2005 19:02:13 -0000 1.8 *************** *** 87,98 **** { 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; } } --- 87,102 ---- { float[] returnValue; ! float coefficient = this.getCoefficient(ticker); ! string tickerCode = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! Quotes tickerQuotes = new Quotes(tickerCode, this.firstQuoteDate, this.lastQuoteDate); returnValue = ExtendedDataTable.GetArrayOfFloatFromRatioOfColumns(tickerQuotes, "quClose", "quOpen"); + for(int idx = 0; idx!= returnValue.Length; idx++) { ! returnValue[idx] = coefficient*(returnValue[idx] - 1); } return returnValue; } + } Index: RunEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientPortfolio.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RunEfficientPortfolio.cs 17 Apr 2005 13:36:37 -0000 1.4 --- RunEfficientPortfolio.cs 26 Apr 2005 19:02:14 -0000 1.5 *************** *** 53,57 **** public class RunEfficientPorfolio { ! protected string tickerGroupID; protected int numberOfEligibleTickers; --- 53,59 ---- public class RunEfficientPorfolio { ! public static double MaxNumberOfHoursForScript = 10; ! //if MaxNumberOfHoursForScript has elapsed and the script ! //is still running, it will be stopped. protected string tickerGroupID; protected int numberOfEligibleTickers; *************** *** 83,86 **** --- 85,90 ---- protected PortfolioType portfolioType; + + protected DateTime startingTimeForScript; public virtual string ScriptName *************** *** 115,118 **** --- 119,123 ---- this.targetReturn = targetReturn; this.portfolioType = portfolioType; + this.startingTimeForScript = DateTime.Now; //this.numIntervalDays = 3; } *************** *** 157,164 **** if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! File.Exists(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf('\\')) ! + @"\StopScript.txt")) ! //If you want to stop timer and save script until now, create ! //in bin dir a file named "StopScript.txt" { this.endOfDayTimer.Stop(); --- 162,168 ---- if(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime>=this.endDateTime.DateTime || ! DateTime.Now >= this.startingTimeForScript.AddHours(RunEfficientPorfolio.MaxNumberOfHoursForScript)) ! //last date is reached by the timer or MaxNumberOfHoursForScript hours ! //are elapsed from the time script started { this.endOfDayTimer.Stop(); Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerCTC.cs 14 Apr 2005 18:38:27 -0000 1.4 --- EndOfDayTimerHandlerCTC.cs 26 Apr 2005 19:02:11 -0000 1.5 *************** *** 134,138 **** foreach ( string ticker in this.chosenTickers ) { ! this.lastChosenTickers[idx] = ticker; if(ticker != null) this.addOrderForTicker( ticker ); --- 134,139 ---- foreach ( string ticker in this.chosenTickers ) { ! this.lastChosenTickers[idx] = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); if(ticker != null) this.addOrderForTicker( ticker ); Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManagerForEfficientCTCPortfolio.cs 11 Apr 2005 18:52:31 -0000 1.2 --- GenomeManagerForEfficientCTCPortfolio.cs 26 Apr 2005 19:02:12 -0000 1.3 *************** *** 79,83 **** protected override float[] getArrayOfRatesOfReturn(string ticker) { ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); float[] ratesOfReturns = new float[allAdjValues.Length/this.numDaysOfPortfolioLife + 1]; --- 79,85 ---- protected override float[] getArrayOfRatesOfReturn(string ticker) { ! float coefficient = this.getCoefficient(ticker); ! string tickerCode = GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! Quotes tickerQuotes = new Quotes(tickerCode, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); float[] ratesOfReturns = new float[allAdjValues.Length/this.numDaysOfPortfolioLife + 1]; *************** *** 86,91 **** for(int idx = 0; idx + this.numDaysOfPortfolioLife < allAdjValues.Length; idx += this.numDaysOfPortfolioLife ) { ! ratesOfReturns[i] = allAdjValues[idx+this.numDaysOfPortfolioLife]/ ! allAdjValues[idx] - 1; i++; } --- 88,93 ---- for(int idx = 0; idx + this.numDaysOfPortfolioLife < allAdjValues.Length; idx += this.numDaysOfPortfolioLife ) { ! ratesOfReturns[i] = (allAdjValues[idx+this.numDaysOfPortfolioLife]/ ! allAdjValues[idx] - 1)*coefficient; i++; } Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GenomeManagerForEfficientPortfolio.cs 19 Apr 2005 18:33:43 -0000 1.6 --- GenomeManagerForEfficientPortfolio.cs 26 Apr 2005 19:02:13 -0000 1.7 *************** *** 28,32 **** using QuantProject.Data; using QuantProject.Data.DataTables; ! namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios --- 28,32 ---- using QuantProject.Data; using QuantProject.Data.DataTables; ! using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios *************** *** 43,46 **** --- 43,47 ---- protected DataTable setOfTickers; + protected int originalNumOfTickers; protected DateTime firstQuoteDate; protected DateTime lastQuoteDate; *************** *** 50,53 **** --- 51,66 ---- protected PortfolioType portfolioType; + static public string GetCleanTickerCode(string tickerModifiedCode) + { + if(tickerModifiedCode.StartsWith("-")) + //if the first char is "-" + //each element of the array of rates of return is + //multiplied by -1 + return tickerModifiedCode.Substring(1,tickerModifiedCode.Length -1); + else + return tickerModifiedCode; + + } + //IGenomeManager implementation for properties public int GenomeSize *************** *** 92,96 **** { this.setOfTickers = setOfInitialTickers; ! if(!this.setOfTickers.Columns.Contains("ArrayOfRatesOfReturn")) this.setOfTickers.Columns.Add("ArrayOfRatesOfReturn", System.Type.GetType("System.Array")); --- 105,109 ---- { this.setOfTickers = setOfInitialTickers; ! this.originalNumOfTickers = setOfInitialTickers.Rows.Count; if(!this.setOfTickers.Columns.Contains("ArrayOfRatesOfReturn")) this.setOfTickers.Columns.Add("ArrayOfRatesOfReturn", System.Type.GetType("System.Array")); *************** *** 99,108 **** this.targetPerformance = targetPerformance; this.genomeSize = numberOfTickersInPortfolio; //each genes is the index for the setOfTickers table this.minValueForGenes = 0; ! this.maxValueForGenes = this.setOfTickers.Rows.Count - 1; ! this.portfolioType = portfolioType; } public virtual double GetFitnessValue(Genome genome) { --- 112,167 ---- this.targetPerformance = targetPerformance; this.genomeSize = numberOfTickersInPortfolio; + this.portfolioType = portfolioType; + this.setMinAndMaxValueForGenes(); + this.set_SetOfInitialTickers(); + + } + + + private void set_SetOfInitialTickers() + { + + if(this.portfolioType == PortfolioType.ShortAndLong) + { + for(int i = 0;i<this.originalNumOfTickers;i++) + { + string ticker = (string)this.setOfTickers.Rows[i][0]; + DataRow newRow = this.setOfTickers.NewRow(); + newRow[0] = "-" + ticker; + this.setOfTickers.Rows.Add(newRow); + //so, if row[i][0]="TICKER" + //row[i+originalNumOfTickers][0]="-TICKER" + } + } + } + + private void setMinAndMaxValueForGenes() + { //each genes is the index for the setOfTickers table this.minValueForGenes = 0; ! ! if(this.portfolioType == PortfolioType.OnlyLong || ! this.portfolioType == PortfolioType.OnlyShort) ! this.maxValueForGenes = this.setOfTickers.Rows.Count - 1; ! else//ShortAndLong ! this.maxValueForGenes = this.setOfTickers.Rows.Count*2 - 1; ! } ! ! protected float getCoefficient(string ticker) ! { ! float returnValue; ! if(ticker.StartsWith("-")) ! //if the first char is "-" ! //each element of the array of rates of return is ! //multiplied by -1 ! returnValue = -1; ! else ! returnValue = 1; ! ! return returnValue; ! } + public virtual double GetFitnessValue(Genome genome) { *************** *** 121,126 **** this.rateOfReturn = portfolioRateOfReturn; NormalDistribution normal = new NormalDistribution(portfolioRateOfReturn, Math.Sqrt(portfolioVariance)); ! if(this.portfolioType == PortfolioType.OnlyLong) ! //returnValue = normal.GetProbability(this.targetPerformance*0.75,this.targetPerformance*1.25); returnValue = 1.0 - normal.GetProbability(this.targetPerformance); else//only short orders are permitted --- 180,188 ---- this.rateOfReturn = portfolioRateOfReturn; NormalDistribution normal = new NormalDistribution(portfolioRateOfReturn, Math.Sqrt(portfolioVariance)); ! if(this.portfolioType == PortfolioType.OnlyLong || ! this.portfolioType == PortfolioType.ShortAndLong) ! //the genome fitness is evaluated as if ! //the portfolio was long ! //ALTERNATIVE: returnValue = normal.GetProbability(this.targetPerformance*0.75,this.targetPerformance*1.25); returnValue = 1.0 - normal.GetProbability(this.targetPerformance); else//only short orders are permitted *************** *** 142,146 **** int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); ! while(genome.HasGene(returnValue)) { returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, --- 204,211 ---- int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); ! while(genome.HasGene(returnValue) || ! genome.HasGene(returnValue + this.originalNumOfTickers)) ! //the portfolio can't have a long position and a short position ! // for the same ticker { returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, *************** *** 208,212 **** float[] ticker_i; float[] ticker_j; ! double tickerCoeff = 1/this.genomeSize; for(int i = 0; i<this.genomeSize ; i++) { --- 273,277 ---- float[] ticker_i; float[] ticker_j; ! double tickerCoeff = 1.0/this.genomeSize; for(int i = 0; i<this.genomeSize ; i++) { Index: EndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandler.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** EndOfDayTimerHandler.cs 14 Apr 2005 18:38:27 -0000 1.11 --- EndOfDayTimerHandler.cs 26 Apr 2005 19:02:11 -0000 1.12 *************** *** 102,114 **** protected virtual void addOrderForTicker(string ticker ) { ! double cashForSinglePosition = this.account.CashAmount / this.numberOfTickersToBeChosen; long quantity = ! Convert.ToInt64( Math.Floor( cashForSinglePosition / this.account.DataStreamer.GetCurrentBid( ticker ) ) ); Order order; ! if(this.portfolioType == PortfolioType.OnlyLong) ! order = new Order( OrderType.MarketBuy, new Instrument( ticker ) , quantity ); ! else// only short orders are permitted ! order = new Order( OrderType.MarketSellShort, new Instrument( ticker ) , quantity ); this.orders.Add(order); --- 102,117 ---- protected virtual void addOrderForTicker(string ticker ) { ! string tickerCode = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); double cashForSinglePosition = this.account.CashAmount / this.numberOfTickersToBeChosen; long quantity = ! Convert.ToInt64( Math.Floor( cashForSinglePosition / this.account.DataStreamer.GetCurrentBid( tickerCode ) ) ); Order order; ! if(this.portfolioType == PortfolioType.OnlyShort || ! (this.portfolioType == PortfolioType.ShortAndLong && ! ticker != tickerCode)) ! order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); ! else ! order = new Order( OrderType.MarketBuy, new Instrument( tickerCode ) , quantity ); this.orders.Add(order); |
|
From: Marco M. <mi...@us...> - 2005-04-26 18:55:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4679/b7_Scripts Modified Files: Scripts.prjx Log Message: Updated SharpDevelop project file. Index: Scripts.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts.prjx,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Scripts.prjx 11 Apr 2005 18:45:49 -0000 1.2 --- Scripts.prjx 26 Apr 2005 18:54:52 -0000 1.3 *************** *** 29,32 **** --- 29,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=".\WalkForwardTesting\WalkForwardOneRank\IWalkForwardProgressNotifier.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Glauco S. <gla...@us...> - 2005-04-24 16:26:21
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25814/b7_Scripts/WalkForwardTesting/WalkForwardOneRank Modified Files: ComparableAccount.cs Log Message: New goodness computation: now it is based on the PercentageWinningPeriods account report summary value Index: ComparableAccount.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/ComparableAccount.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ComparableAccount.cs 30 Mar 2005 23:42:59 -0000 1.7 --- ComparableAccount.cs 24 Apr 2005 16:26:13 -0000 1.8 *************** *** 39,42 **** --- 39,44 ---- private double maxAcceptableDrawDown = 30; + private double minAcceptableWinningPeriods = 30; + private IHistoricalQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); *************** *** 66,69 **** --- 68,73 ---- this.EndOfDayTimer.GetCurrentTime() , this.Key , this.historicalQuoteProvider ); + + // old goodness computation if ( ( this.accountReport.Summary.MaxEquityDrawDown >= this.maxAcceptableDrawDown ) || ( this.accountReport.Summary.TotalPnl <= this.accountReport.Summary.BenchmarkPercentageReturn ) ) *************** *** 73,76 **** --- 77,87 ---- returnValue = this.accountReport.Summary.ReturnOnAccount - this.accountReport.Summary.BenchmarkPercentageReturn; + + // new goodness computation + if ( this.accountReport.Summary.NumberWinningPeriods < this.minAcceptableWinningPeriods ) + returnValue = Double.MinValue; + else + returnValue = Convert.ToDouble( this.accountReport.Summary.PercentageWinningPeriods ); + return returnValue; } |
|
From: Glauco S. <gla...@us...> - 2005-04-24 16:23:59
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24156/b7_Scripts/WalkForwardTesting/WalkForwardOneRank Modified Files: ProgressBarForm.cs Log Message: - rewritten to work with any IWalkForwardProgressNotifier - rewritten to work in its own thread (different from the main thread) Index: ProgressBarForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank/ProgressBarForm.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ProgressBarForm.cs 29 Nov 2004 14:34:26 -0000 1.1 --- ProgressBarForm.cs 24 Apr 2005 16:23:50 -0000 1.2 *************** *** 5,8 **** --- 5,10 ---- using System.Windows.Forms; + using QuantProject.ADT; + namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardOneRank { *************** *** 33,37 **** } ! public ProgressBarForm() { // --- 35,39 ---- } ! public ProgressBarForm( IWalkForwardProgressNotifier walkForwardProgressNotifier ) { // *************** *** 45,50 **** --- 47,86 ---- this.progressBarOutOfSample.Maximum = 100; this.progressBarInSample.Maximum = 100; + walkForwardProgressNotifier.InSampleNewProgress += + new NewProgressEventHandler( this.inSampleNewProgressEventHandler ); + walkForwardProgressNotifier.OutOfSampleNewProgress += + new NewProgressEventHandler( this.outOfSampleNewProgressEventHandler ); } + private void inSampleNewProgressEventHandler( + object sender , NewProgressEventArgs newProgressEventArgs ) + { + if ( this.InvokeRequired ) + { + // we're not in the UI thread, so we need to call BeginInvoke + this.BeginInvoke( new NewProgressEventHandler( this.inSampleNewProgressEventHandler ) , + new object[]{ sender , newProgressEventArgs }); + } + else + // we are in the UI thread + { + this.progressBarInSample.Value = newProgressEventArgs.CurrentProgress; + } + } + private void outOfSampleNewProgressEventHandler( + object sender , NewProgressEventArgs newProgressEventArgs ) + { + if ( this.InvokeRequired ) + { + // we're not in the UI thread, so we need to call BeginInvoke + this.BeginInvoke( new NewProgressEventHandler( this.outOfSampleNewProgressEventHandler ) , + new object[]{ sender , newProgressEventArgs }); + } + else + // we are in the UI thread + { + this.progressBarOutOfSample.Value = newProgressEventArgs.CurrentProgress; + } + } /// <summary> /// Clean up any resources being used. |