quantproject-developers Mailing List for QuantProject (Page 97)
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-11-22 16:25:31
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23225 Modified Files: b7_Scripts.csproj Log Message: IWalkForwardProgressNotifier has been moved in the WalkForwardTesting script root Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** b7_Scripts.csproj 17 Nov 2005 21:40:58 -0000 1.44 --- b7_Scripts.csproj 22 Nov 2005 16:25:15 -0000 1.45 *************** *** 349,352 **** --- 349,357 ---- /> <File + RelPath = "WalkForwardTesting\IWalkForwardProgressNotifier.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\GenomeRepresentation.cs" SubType = "Code" *************** *** 439,463 **** /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\BestPerformingTickers.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\ChosenTickers.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\ComparableAccount.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\EligibleTickers.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\IWalkForwardProgressNotifier.cs" SubType = "Code" BuildAction = "Compile" --- 444,478 ---- /> <File ! RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\ReportDebugger\WFMultiOneRankDebugEndOfDayTimerHandler.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\ReportDebugger\WFMultiOneRankDebugInSample.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\ReportDebugger\WFMultiOneRankReportDebugger.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\BestPerformingTickers.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\ChosenTickers.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\ComparableAccount.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\EligibleTickers.cs" SubType = "Code" BuildAction = "Compile" |
|
From: Glauco S. <gla...@us...> - 2005-11-19 13:46:18
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31753/b7_Scripts/WalkForwardTesting Added Files: IWalkForwardProgressNotifier.cs Log Message: IWalkForwardProgressNotifier.cs has been moved to the folder WalkForwardTesting\WalkForwardOneRank\ to the folder WalkForwardTesting\ --- NEW FILE: IWalkForwardProgressNotifier.cs --- /* QuantProject - Quantitative Finance Library IWalkForwardProgressNotifier.cs Copyright (C) 2004 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT; namespace QuantProject.Scripts.WalkForwardTesting { /// <summary> /// Interface to be implemented by time consuming walk forwarding scripts /// </summary> public interface IWalkForwardProgressNotifier { event NewProgressEventHandler InSampleNewProgress; event NewProgressEventHandler OutOfSampleNewProgress; } } |
|
From: Glauco S. <gla...@us...> - 2005-11-19 13:46:18
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31753/b7_Scripts/WalkForwardTesting/WalkForwardOneRank Removed Files: IWalkForwardProgressNotifier.cs Log Message: IWalkForwardProgressNotifier.cs has been moved to the folder WalkForwardTesting\WalkForwardOneRank\ to the folder WalkForwardTesting\ --- IWalkForwardProgressNotifier.cs DELETED --- |
|
From: Glauco S. <gl...@my...> - 2005-11-17 23:34:36
|
At 09:41 PM 11/17/2005 +0000, you wrote: >Now the project file points properly to IWalkForwardProgressNotifier.cs >(to directory WalkForwardTesting\WalkForwardOneRank\) Millo, magari ero ubriaco, ma credo proprio di averti scritto che il file va sotto WalkForwardTesting (cosi' e' qua da me ed e' giusto che sia li') e non sotto WalkForwardTesting\WalkForwardOneRank\ E' un interfaccia che vale per tutti gli script walk forward, non solo per la one rank. Fammi sapere, ok? |
|
From: Marco M. <mi...@us...> - 2005-11-17 21:41:52
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19640/b3_Data Modified Files: Data.prjx Log Message: Updated #develop project files Index: Data.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Data.prjx,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Data.prjx 8 Nov 2005 18:43:18 -0000 1.9 --- Data.prjx 17 Nov 2005 21:41:39 -0000 1.10 *************** *** 38,41 **** --- 38,42 ---- <File name=".\DataProviders\Caching\MissingQuoteException.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\Selectors\SelectorByGroup.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> + <File name=".\Selectors\SelectorByCloseToCloseCorrelationToBenchmark.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-11-17 21:41:52
|
Update of /cvsroot/quantproject/QuantProject/b91_QuantProject In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19640/b91_QuantProject Modified Files: QuantProject.prjx Log Message: Updated #develop project files Index: QuantProject.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b91_QuantProject/QuantProject.prjx,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** QuantProject.prjx 11 Apr 2005 18:45:49 -0000 1.4 --- QuantProject.prjx 17 Nov 2005 21:41:39 -0000 1.5 *************** *** 6,9 **** --- 6,10 ---- <File name=".\app.config" subtype="Code" buildaction="Nothing" dependson="" data="" /> <File name=".\App.ico" subtype="Code" buildaction="Nothing" dependson="" data="" /> + <File name=".\QuantProject.Principale.Principale.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-11-17 21:41:10
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19483/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: Now the project file points properly to IWalkForwardProgressNotifier.cs (to directory WalkForwardTesting\WalkForwardOneRank\) Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** b7_Scripts.csproj 12 Nov 2005 18:35:02 -0000 1.43 --- b7_Scripts.csproj 17 Nov 2005 21:40:58 -0000 1.44 *************** *** 349,357 **** /> <File - RelPath = "WalkForwardTesting\IWalkForwardProgressNotifier.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "WalkForwardTesting\LinearCombination\GenomeRepresentation.cs" SubType = "Code" --- 349,352 ---- *************** *** 464,467 **** --- 459,467 ---- /> <File + RelPath = "WalkForwardTesting\WalkForwardOneRank\IWalkForwardProgressNotifier.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\WalkForwardOneRank\MyEndOfDayTimerHandler.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2005-11-17 21:37:33
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18464/b7_Scripts/TickerSelectionTesting Modified Files: RunTestOptimizedCTCPortfolio.cs RunEfficientCTOPortfolio.cs RunEfficientCTCPortfolio.cs GenomeManagerForWeightedEfficientPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientCTCPortfolio.cs EndOfDayTimerHandlerCTCTest.cs EndOfDayTimerHandlerCTC.cs Log Message: Updated script files Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GenomeManagerForEfficientCTOPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.14 --- GenomeManagerForEfficientCTOPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.15 *************** *** 97,104 **** */ ! protected override double getFitnessValue_calculate() ! { ! return this.RateOfReturn/Math.Sqrt(this.Variance); ! } --- 97,104 ---- */ ! // protected override double getFitnessValue_calculate() ! // { ! // return this.RateOfReturn/Math.Sqrt(this.Variance); ! // } Index: RunEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTCPortfolio.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RunEfficientCTCPortfolio.cs 18 Sep 2005 21:13:36 -0000 1.11 --- RunEfficientCTCPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.12 *************** *** 62,65 **** --- 62,66 ---- protected int numDaysForReturnCalculation; protected double maxAcceptableCloseToCloseDrawdown; + protected int numDaysBetweenEachOptimization; public RunEfficientCTCPortfolio(string tickerGroupID, int numberOfEligibleTickers, *************** *** 71,75 **** double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, --- 72,76 ---- double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, *************** *** 79,86 **** portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScripts"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; } --- 80,89 ---- portfolioType, maxRunningHours) { ! this.ScriptName = "CloseToCloseScriptsDiscontinuos"; ! //this.ScriptName = "CloseToCloseScriptsDiscontinuosWithCoeff"; this.numDayOfPortfolioLife = numDaysOfPortfolioLife; this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; + this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } *************** *** 96,100 **** this.numDayOfPortfolioLife, this.numDaysForReturnCalculation, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } --- 99,104 ---- this.numDayOfPortfolioLife, this.numDaysForReturnCalculation, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, ! this.numDaysBetweenEachOptimization); } Index: RunTestOptimizedCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunTestOptimizedCTCPortfolio.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RunTestOptimizedCTCPortfolio.cs 18 Sep 2005 21:13:36 -0000 1.7 --- RunTestOptimizedCTCPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.8 *************** *** 69,73 **** double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, --- 69,73 ---- double targetReturn, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! double maxRunningHours, int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, *************** *** 78,82 **** targetReturn, portfolioType, maxAcceptableCloseToCloseDrawdown, ! maxRunningHours) { this.ScriptName = "TestOptimizedCTCPortfolio"; --- 78,82 ---- targetReturn, portfolioType, maxAcceptableCloseToCloseDrawdown, ! maxRunningHours, numDaysBetweenEachOptimization) { this.ScriptName = "TestOptimizedCTCPortfolio"; *************** *** 94,98 **** this.numDaysForReturnCalculation, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } --- 94,99 ---- this.numDaysForReturnCalculation, this.targetReturn, ! this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, ! this.numDaysBetweenEachOptimization); } Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GenomeManagerForEfficientCTCPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.10 --- GenomeManagerForEfficientCTCPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.11 *************** *** 62,84 **** this.retrieveData(); } protected override float[] getArrayOfRatesOfReturn(string ticker) { ! float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); returnValue = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; int i = 0; //index for ratesOfReturns array ! for(int idx = 0; idx + this.numDaysForReturnCalculation < allAdjValues.Length; idx += this.numDaysForReturnCalculation ) ! { ! returnValue[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ ! allAdjValues[idx] - 1); ! i++; ! } this.numberOfExaminedReturns = returnValue.Length; return returnValue; } ! /* protected override double getFitnessValue_calculate() { --- 62,131 ---- this.retrieveData(); } + // old implementation, where a "continuos" adjusted close to close ratio, + // based on a particular fixed interval of days, is considered + // In this case, there is no discontinuity between the returned ratesOfReturn + // + // protected override float[] getArrayOfRatesOfReturn(string ticker) + // { + // float[] returnValue = null; + // Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); + // float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); + // returnValue = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; + // int i = 0; //index for ratesOfReturns array + // for(int idx = 0; idx + this.numDaysForReturnCalculation < allAdjValues.Length; idx += this.numDaysForReturnCalculation ) + // { + // returnValue[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ + // allAdjValues[idx] - 1); + // i++; + // } + // this.numberOfExaminedReturns = returnValue.Length; + // + // return returnValue; + // } + // new implementation, where a "discontinuos" adjusted close to close ratio, + // based on a particular fixed interval of days, is considered + // In this case, there is a discontinuity between each pair of ratesOfReturn, + // equal to the given interval of days protected override float[] getArrayOfRatesOfReturn(string ticker) { ! /* ! float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); returnValue = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; int i = 0; //index for ratesOfReturns array ! int lastIdxAccessed = 0; ! for(int idx = 0; ! (idx + this.numDaysForReturnCalculation) < allAdjValues.Length; ! idx += this.numDaysForReturnCalculation ) ! { ! if(idx-lastIdxAccessed>numDaysForReturnCalculation || idx == 0) ! //there is a discontinuity, as wanted ! { ! returnValue[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ ! allAdjValues[idx] - 1); ! lastIdxAccessed = idx; ! i++; ! } ! } this.numberOfExaminedReturns = returnValue.Length; return returnValue; + */ + float[] returnValue = null; + returnValue = + QuantProject.Data.DataTables.Quotes.GetArrayOfCloseToCloseRatios(ticker, + this.firstQuoteDate, + this.lastQuoteDate, + this.numDaysForReturnCalculation); + + this.numberOfExaminedReturns = returnValue.Length; + + return returnValue; + } ! ! /*LPM as fitness protected override double getFitnessValue_calculate() { Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** EndOfDayTimerHandlerCTC.cs 8 Nov 2005 18:36:48 -0000 1.17 --- EndOfDayTimerHandlerCTC.cs 17 Nov 2005 21:37:19 -0000 1.18 *************** *** 47,54 **** --- 47,57 ---- protected int numDaysForReturnCalculation; protected int daysCounter; + protected int daysWithNoPositions; protected double maxAcceptableCloseToCloseDrawdown; protected bool stopLossConditionReached; protected double currentAccountValue; protected double previousAccountValue; + protected int numDaysBetweenEachOptimization; + private int numDaysElapsedSinceLastOptimization; public EndOfDayTimerHandlerCTC(string tickerGroupID, int numberOfEligibleTickers, *************** *** 61,65 **** int numDaysForReturnCalculation, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, --- 64,69 ---- int numDaysForReturnCalculation, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, *************** *** 76,79 **** --- 80,84 ---- this.currentAccountValue = 0.0; this.previousAccountValue = 0.0; + this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } *************** *** 101,105 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! bool positionsJustClosed = false; this.updateStopLossCondition(); if(this.account.Portfolio.Count > 0) --- 106,110 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! //bool positionsJustClosed = false; this.updateStopLossCondition(); if(this.account.Portfolio.Count > 0) *************** *** 114,129 **** this.closePositions(); this.daysCounter = 0; ! positionsJustClosed = true; } } ! ! if(this.account.Portfolio.Count == 0 && ! !positionsJustClosed) ! //portfolio is empty but it has not been closed ! //at the current close { ! this.openPositions(); ! this.daysCounter = 0; ! } } --- 119,145 ---- this.closePositions(); this.daysCounter = 0; ! //positionsJustClosed = true; } } ! //old ! // if(this.account.Portfolio.Count == 0 && ! // !positionsJustClosed) ! // //portfolio is empty but it has not been closed ! // //at the current close ! // { ! // this.openPositions(); ! // this.daysCounter = 0; ! // } ! ! if(this.account.Portfolio.Count == 0) ! //portfolio is empty { ! this.daysWithNoPositions++; ! if(this.daysWithNoPositions>this.numDaysOfPortfolioLife) ! { ! this.openPositions(); ! this.daysWithNoPositions = 0; ! } ! } } *************** *** 136,141 **** SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! ! this.eligibleTickers = temporizedGroup.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, --- 152,168 ---- SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! ! SelectorByCloseToCloseCorrelationToBenchmark lessCorrelatedFromTemporized = ! new SelectorByCloseToCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), ! this.benchmark,true, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! currentDate, ! this.numberOfEligibleTickers, ! this.numDaysForReturnCalculation); ! ! ! ! ! this.eligibleTickers = lessCorrelatedFromTemporized.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = new SelectorByQuotationAtEachMarketDay(this.eligibleTickers, *************** *** 194,202 **** { ConstantsProvider.SeedForRandomGenerator++; ! if(this.account.Portfolio.Count == 0 ) { - this.orders.Clear(); this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! //it sets tickers to be chosen at next close } } --- 221,243 ---- { ConstantsProvider.SeedForRandomGenerator++; ! //old ! // if(this.account.Portfolio.Count == 0 ) ! // { ! // this.orders.Clear(); ! // this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! // //it sets tickers to be chosen at next close ! // } ! this.orders.Clear(); ! //this.oneHourAfterMarketCloseEventHandler_updatePrices(); ! if(this.numDaysElapsedSinceLastOptimization == ! this.numDaysBetweenEachOptimization - 1) { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); ! //sets tickers to be chosen next Market Open event ! this.numDaysElapsedSinceLastOptimization = 0; ! } ! else ! { ! this.numDaysElapsedSinceLastOptimization++; } } Index: GenomeManagerForWeightedEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForWeightedEfficientPortfolio.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenomeManagerForWeightedEfficientPortfolio.cs 8 Nov 2005 18:34:02 -0000 1.1 --- GenomeManagerForWeightedEfficientPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.2 *************** *** 123,132 **** #endregion - public override Genome[] GetChilds(Genome parent1, Genome parent2) - { - return - GenomeManipulator.MixGenesWithoutDuplicates(parent1, parent2); - } - public override int GetNewGeneValue(Genome genome, int genePosition) { --- 123,126 ---- Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** RunEfficientCTOPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.23 --- RunEfficientCTOPortfolio.cs 17 Nov 2005 21:37:19 -0000 1.24 *************** *** 71,76 **** portfolioType, maxRunningHours) { ! this.ScriptName = "OpenCloseScriptsSharpeRatioWithCoeff"; //this.ScriptName = "OpenCloseScriptsSharpeRatio"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } --- 71,77 ---- portfolioType, maxRunningHours) { ! //this.ScriptName = "OpenCloseScriptsSharpeRatioWithCoeff"; //this.ScriptName = "OpenCloseScriptsSharpeRatio"; + this.ScriptName = "OpenCloseScriptsWithCoeff"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } Index: EndOfDayTimerHandlerCTCTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCTest.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerCTCTest.cs 18 Sep 2005 21:13:36 -0000 1.4 --- EndOfDayTimerHandlerCTCTest.cs 17 Nov 2005 21:37:19 -0000 1.5 *************** *** 56,60 **** int numDaysForReturnCalculation, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, --- 56,61 ---- int numDaysForReturnCalculation, double targetReturn, ! PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, ! int numDaysBetweenEachOptimization): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, *************** *** 66,70 **** numDaysForReturnCalculation, targetReturn, ! portfolioType, maxAcceptableCloseToCloseDrawdown) { --- 67,72 ---- numDaysForReturnCalculation, targetReturn, ! portfolioType, maxAcceptableCloseToCloseDrawdown, ! numDaysBetweenEachOptimization) { |
|
From: Marco M. <mi...@us...> - 2005-11-17 21:34:50
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17897/b3_Data Modified Files: b3_Data.csproj Log Message: Added SelectorByCloseToCloseCorrelationToBenchmark to the project. Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** b3_Data.csproj 21 Oct 2005 18:26:43 -0000 1.32 --- b3_Data.csproj 17 Nov 2005 21:34:40 -0000 1.33 *************** *** 278,281 **** --- 278,286 ---- /> <File + RelPath = "Selectors\SelectorByCloseToCloseCorrelationToBenchmark.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Selectors\SelectorByCloseToCloseLinearCorrelation.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2005-11-17 21:34:49
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17897/b3_Data/DataTables Modified Files: Quotes.cs Log Message: Added SelectorByCloseToCloseCorrelationToBenchmark to the project. Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Quotes.cs 18 Sep 2005 21:03:43 -0000 1.18 --- Quotes.cs 17 Nov 2005 21:34:40 -0000 1.19 *************** *** 448,451 **** --- 448,528 ---- } + public static float[] GetArrayOfCloseToCloseRatios(string ticker, + DateTime firstQuoteDate, + DateTime lastQuoteDate, + int numDaysBetweenEachClose) + { + float[] returnValue = null; + Quotes tickerQuotes = new Quotes(ticker, firstQuoteDate, lastQuoteDate); + float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); + returnValue = new float[allAdjValues.Length/(numDaysBetweenEachClose + 1)]; + int i = 0; //index for ratesOfReturns array + int lastIdxAccessed = 0; + for(int idx = 0; + (idx + numDaysBetweenEachClose) < allAdjValues.Length; + idx += numDaysBetweenEachClose ) + { + if(idx-lastIdxAccessed>numDaysBetweenEachClose || idx == 0) + //there is a discontinuity, as wanted + { + returnValue[i] = (allAdjValues[idx+numDaysBetweenEachClose]/ + allAdjValues[idx] - 1); + lastIdxAccessed = idx; + i++; + } + } + return returnValue; + } + + /// <summary> + /// returns tickers of a given set of tickers ordered by close to close + /// correlation to a given benchmark + /// </summary> + public static DataTable GetTickersByCloseToCloseCorrelationToBenchmark( bool orderByASC, + DataTable setOfTickers, string benchmark, + DateTime firstQuoteDate, + DateTime lastQuoteDate, + long maxNumOfReturnedTickers, int numDaysBetweenEachClose) + { + if(!setOfTickers.Columns.Contains("CloseToCloseCorrelationToBenchmark")) + setOfTickers.Columns.Add("CloseToCloseCorrelationToBenchmark", System.Type.GetType("System.Double")); + float[] benchmarkRatios = GetArrayOfCloseToCloseRatios(benchmark, firstQuoteDate, lastQuoteDate, numDaysBetweenEachClose); + foreach(DataRow row in setOfTickers.Rows) + { + float[] tickerRatios = GetArrayOfCloseToCloseRatios((string)row[0], + firstQuoteDate, lastQuoteDate, numDaysBetweenEachClose ); + if(tickerRatios.Length == benchmarkRatios.Length) + row["CloseToCloseCorrelationToBenchmark"] = + Math.Abs(BasicFunctions.PearsonCorrelationCoefficient(benchmarkRatios, tickerRatios)); + } + DataTable tableToReturn = ExtendedDataTable.CopyAndSort(setOfTickers, + "CloseToCloseCorrelationToBenchmark>=0.0", + "CloseToCloseCorrelationToBenchmark", + orderByASC); + ExtendedDataTable.DeleteRows(tableToReturn, maxNumOfReturnedTickers); + return tableToReturn; + } + + /// <summary> + /// returns tickers of a given set of tickers ordered by close to close + /// correlation to a given benchmark + /// </summary> + public static DataTable GetTickersByCloseToCloseCorrelationToBenchmark( bool orderByASC, + string groupID, string benchmark, + DateTime firstQuoteDate, + DateTime lastQuoteDate, + long maxNumOfReturnedTickers, + int numDaysBetweenEachClose) + { + DataTable tickersOfGroup = new Tickers_tickerGroups(groupID); + return GetTickersByCloseToCloseCorrelationToBenchmark(orderByASC, + tickersOfGroup, benchmark, + firstQuoteDate, + lastQuoteDate, + maxNumOfReturnedTickers, + numDaysBetweenEachClose); + } + + private History history; |
|
From: Marco M. <mi...@us...> - 2005-11-17 21:34:49
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17897/b3_Data/Selectors Added Files: SelectorByCloseToCloseCorrelationToBenchmark.cs Log Message: Added SelectorByCloseToCloseCorrelationToBenchmark to the project. --- NEW FILE: SelectorByCloseToCloseCorrelationToBenchmark.cs --- /* QuantProject - Quantitative Finance Library SelectorByCloseToCloseCorrelationToBenchmark.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 close to close absolute correlation to /// a given benchmark /// </summary> public class SelectorByCloseToCloseCorrelationToBenchmark : TickerSelector, ITickerSelector { private string benchmark; private int numDaysBetweenEachClose; public SelectorByCloseToCloseCorrelationToBenchmark(DataTable setOfTickersToBeSelected, string benchmark, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers, int numDaysBetweenEachClose): base(setOfTickersToBeSelected, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { this.benchmark = benchmark; this.numDaysBetweenEachClose = numDaysBetweenEachClose; } public SelectorByCloseToCloseCorrelationToBenchmark(string groupID, string benchmark, bool orderInASCmode, DateTime firstQuoteDate, DateTime lastQuoteDate, long maxNumOfReturnedTickers, int numDaysBetweenEachClose): base(groupID, orderInASCmode, firstQuoteDate, lastQuoteDate, maxNumOfReturnedTickers) { this.benchmark = benchmark; this.numDaysBetweenEachClose = numDaysBetweenEachClose; } public DataTable GetTableOfSelectedTickers() { if(this.setOfTickersToBeSelected == null) return QuantProject.Data.DataTables.Quotes.GetTickersByCloseToCloseCorrelationToBenchmark(this.isOrderedInASCMode, this.groupID,this.benchmark, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers, this.numDaysBetweenEachClose); else return QuantProject.Data.DataTables.Quotes.GetTickersByCloseToCloseCorrelationToBenchmark(this.isOrderedInASCMode, this.setOfTickersToBeSelected,this.benchmark, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers, this.numDaysBetweenEachClose); } public void SelectAllTickers() { ; } } } |
|
From: Glauco S. <gla...@us...> - 2005-11-12 19:03:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22267 Added Files: WFMultiOneRankGenomeManager.cs Log Message: This class implements IGenomeManager, in order to find the best position group with respect to the one rank strategy --- NEW FILE: WFMultiOneRankGenomeManager.cs --- /* QuantProject - Quantitative Finance Library WFMultiOneRankChosenTickers.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.Data; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.ADT.Statistics; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardMultiOneRank { /// <summary> /// This class implements IGenomeManager, in order to find the /// best position group with respect to the one rank strategy /// </summary> public class WFMultiOneRankGenomeManager : IGenomeManager { private DataTable eligibleTickers; private DateTime firstQuoteDate; private DateTime lastQuoteDate; private double targetPerformance; private int numberOfTickersInPortfolio; private int numberOfEligibleTickers; private GeneticOptimizer currentGeneticOptimizer; private CandidateProperties[] setOfCandidates; public int GenomeSize { get { return this.numberOfTickersInPortfolio; } } public int MinValueForGenes { get { return -this.numberOfEligibleTickers; } } public int MaxValueForGenes { get { return this.numberOfEligibleTickers - 1; } } public GeneticOptimizer CurrentGeneticOptimizer { get{ return this.currentGeneticOptimizer; } set{ this.currentGeneticOptimizer = value; } } public WFMultiOneRankGenomeManager( DataTable eligibleTickers , DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance ) { this.eligibleTickers = eligibleTickers; this.numberOfEligibleTickers = eligibleTickers.Rows.Count; this.firstQuoteDate = firstQuoteDate; this.lastQuoteDate = lastQuoteDate; this.numberOfTickersInPortfolio = numberOfTickersInPortfolio; this.targetPerformance = targetPerformance; GenomeManagement.SetRandomGenerator(QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator); this.retrieveData(); } #region retrieveData private float[] getArrayOfRatesOfReturn( string ticker ) { float[] returnValue = null; Quotes tickerQuotes = new Quotes( ticker , this.firstQuoteDate , this.lastQuoteDate ); float[] allAdjValues = QuantProject.Data.ExtendedDataTable.GetArrayOfFloatFromColumn( tickerQuotes , "quAdjustedClose"); returnValue = new float[ allAdjValues.Length ]; int i = 0; //index for ratesOfReturns array for( int idx = 0 ; idx < allAdjValues.Length - 1 ; idx++ ) { returnValue[ i ] = allAdjValues[ idx + 1 ] / allAdjValues[ idx ] - 1; i++; } return returnValue; } private void retrieveData() { this.setOfCandidates = new CandidateProperties[ this.eligibleTickers.Rows.Count ]; for(int i = 0; i<this.eligibleTickers.Rows.Count; i++) { string ticker = (string)this.eligibleTickers.Rows[i][0]; this.setOfCandidates[i] = new CandidateProperties( ticker, this.getArrayOfRatesOfReturn( ticker ) ); } } #endregion #region GetFitnessValue #region getFitnessValue_getLinearCombinationReturns private int getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray( int geneValueForTickerIdx ) { int position = geneValueForTickerIdx; if( geneValueForTickerIdx < 0 ) position = Math.Abs(geneValueForTickerIdx + 1); return position; } private float getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray( int tickerIdx, int arrayElementPosition ) { // bool longReturns = false; // if( tickerIdx > 0 ) // //the tickerIdx points to a ticker for which long returns are to be examined // longReturns = true; int position = this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInArray(tickerIdx); // this.setOfCandidates[position].LongRatesOfReturn = longReturns; float[] arrayOfRatesOfReturn = this.setOfCandidates[ position ].ArrayOfRatesOfReturn; //the investment is assumed to be equally divided for each ticker return ( arrayOfRatesOfReturn[ arrayElementPosition ] / this.GenomeSize ); } private double[] getFitnessValue_getLinearCombinationReturns( int[] tickersIdx ) { double[] returnValue = new double[ this.setOfCandidates[ 0 ].ArrayOfRatesOfReturn.Length ]; for( int i = 0; i < returnValue.Length ; i++ ) { foreach( int tickerIdx in tickersIdx ) returnValue[ i ] += this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray( tickerIdx , i ); } return returnValue; } #endregion private double[] getFitnessValue_getStrategyReturnForCurrentCandidates( double[] linearCombinationReturns ) { // strategyReturns contains one element less than linearCombinationReturns, // because there is no strategy for the very first period (at least // one day signal is needed) double[] strategyReturns = new double[ linearCombinationReturns.Length - 1 ]; for ( int i = 0 ; i < linearCombinationReturns.Length - 1 ; i++ ) if ( linearCombinationReturns[ i ] < 0 ) // the current linear combination of tickers, at period i // has a negative return // go short tomorrow strategyReturns[ i ] = -linearCombinationReturns[ i + 1 ]; else // the current linear combination of tickers, at period i // has a positive return // go long tomorrow strategyReturns[ i ] = linearCombinationReturns[ i + 1 ]; return strategyReturns; } public double GetFitnessValue( Genome genome ) { ICollection tickers = ( ICollection )this.Decode( genome ); double[] linearCombinationReturns = this.getFitnessValue_getLinearCombinationReturns( genome.Genes() ); double[] strategyReturns = this.getFitnessValue_getStrategyReturnForCurrentCandidates( linearCombinationReturns ); double fitnessValue = AdvancedFunctions.GetSharpeRatio( strategyReturns ); return fitnessValue; } #endregion public Genome[] GetChilds( Genome parent1 , Genome parent2 ) { return GenomeManipulator.MixGenesWithoutDuplicates(parent1, parent2); } public void Mutate( Genome genome , double mutationRate ) { // in this implementation only one gene is mutated // the new value has to be different from all the other genes of the genome int newValueForGene = GenomeManagement.RandomGenerator.Next( genome.MinValueForGenes , genome.MaxValueForGenes + 1 ); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next( genome.Size ); while( GenomeManipulator.IsTickerContainedInGenome( newValueForGene , genome ) ) // the portfolio, in this implementation, // can't have a long position and a short position // for the same ticker { newValueForGene = GenomeManagement.RandomGenerator.Next( genome.MinValueForGenes , genome.MaxValueForGenes + 1 ); } GenomeManagement.MutateOneGene( genome , mutationRate , genePositionToBeMutated , newValueForGene ); } #region Decode private string decode_getTickerCodeForLongOrShortTrade(int geneValue) { string initialCharForTickerCode = ""; int position = geneValue; if( geneValue < 0 ) { position = Math.Abs( geneValue ) - 1; initialCharForTickerCode = "-"; } return initialCharForTickerCode + ( string )this.eligibleTickers.Rows[ position ][ 0 ]; } public virtual object Decode(Genome genome) { string[] arrayOfTickers = new string[genome.Genes().Length]; int indexOfTicker; for(int index = 0; index < genome.Genes().Length; index++) { indexOfTicker = (int)genome.Genes().GetValue(index); arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } // MeaningForGenome meaning = new MeaningForGenome(arrayOfTickers, // this.PortfolioRatesOfReturn[this.portfolioRatesOfReturn.Length - 1], // this.RateOfReturn, // this.Variance); return arrayOfTickers; } #endregion public int GetNewGeneValue( Genome genome , int i ) { // in this implementation new gene values must be different from // the others already stored in the given genome int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); while(GenomeManipulator.IsTickerContainedInGenome(returnValue, genome) ) //the portfolio can't have a long position and a short one for the same ticker { returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); } return returnValue; } } } |
|
From: Glauco S. <gla...@us...> - 2005-11-12 19:01:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21464 Added Files: WFMultiOneRankEndOfDayTimerHandler.cs Log Message: Implements OneHourAfterMarketCloseEventHandler and FiveMinutesBeforeMarketCloseEventHandler. This is the core strategy! --- NEW FILE: WFMultiOneRankEndOfDayTimerHandler.cs --- /* QuantProject - Quantitative Finance Library WFMultiOneRankEndOfDayTimerHandler.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT; using QuantProject.Business.DataProviders; 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.Scripts.SimpleTesting; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardMultiOneRank { public delegate void InSampleNewProgressEventHandler( Object sender , NewProgressEventArgs eventArgs ); /// <summary> /// Implements OneHourAfterMarketCloseEventHandler and FiveMinutesBeforeMarketCloseEventHandler. /// This is the core strategy! /// </summary> public class WFMultiOneRankEndOfDayTimerHandler { private WFMultiOneRankEligibleTickers eligibleTickers; private WFMultiOneRankChosenTickers chosenTickers; private string tickerGroupID; private int numberEligibleTickers; private int numberOfPositionsToBeChosen; private int inSampleWindowDays; private int outOfSampleWindowDays; private Account account; private int generationNumberForGeneticOptimizer; private int populationSizeForGeneticOptimizer; private DateTime lastOptimizationDate; private HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider; public event InSampleNewProgressEventHandler InSampleNewProgress; public int NumberEligibleTickers { get { return this.numberEligibleTickers; } } public int NumberOfTickersToBeChosen { get { return this.numberOfPositionsToBeChosen; } } public Account Account { get { return this.account; } } /// <summary> /// /// </summary> /// <param name="numberEligibleTickers">number of tickers to be chosen with the first selection: /// the best performers will be chosen among these first selected instruments</param> /// <param name="numberBestPeformingTickers">number of instruments to be chosen, as the best /// performers, among the eligible tickers</param> /// <param name="numberOfTickersToBeChosen">number of instruments to be chosen, /// among the best performers</param> /// <param name="windowDays">number of days between two consecutive /// best performing ticker calculation</param> public WFMultiOneRankEndOfDayTimerHandler( string tickerGroupID , int numberEligibleTickers , int numberOfPositionsToBeChosen , int inSampleWindowDays , int outOfSampleWindowDays , Account account , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer ) { this.tickerGroupID = tickerGroupID; this.numberEligibleTickers = numberEligibleTickers; this.numberOfPositionsToBeChosen = numberOfPositionsToBeChosen; this.inSampleWindowDays = inSampleWindowDays; this.outOfSampleWindowDays = outOfSampleWindowDays; this.account = account; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.eligibleTickers = new WFMultiOneRankEligibleTickers( this.tickerGroupID , numberEligibleTickers , inSampleWindowDays , this.account.EndOfDayTimer ); this.chosenTickers = new WFMultiOneRankChosenTickers( this.eligibleTickers , this.numberOfPositionsToBeChosen , this.inSampleWindowDays , this.account.EndOfDayTimer , this.generationNumberForGeneticOptimizer , this. populationSizeForGeneticOptimizer ); this.chosenTickers.NewProgress += new NewProgressEventHandler( this.bestPerformingNewProgress ); this.historicalAdjustedQuoteProvider = new HistoricalAdjustedQuoteProvider(); this.lastOptimizationDate = DateTime.MinValue; } private EndOfDayDateTime now() { return this.account.EndOfDayTimer.GetCurrentTime(); } private void bestPerformingNewProgress( Object sender , NewProgressEventArgs eventArgs ) { this.InSampleNewProgress( sender , eventArgs ); } // #region OneHourAfterMarketCloseEventHandler // private void oneHourAfterMarketCloseEventHandler_orderChosenTickers_closePositions( // IEndOfDayTimer endOfDayTimer ) // { // foreach ( Position position in this.account.Portfolio ) // if ( this.chosenTickers.Contains( position.Instrument.Key ) ) // { // this.account.ClosePosition( position ); // } // } // private void oneHourAfterMarketCloseEventHandler_orderChosenTickers_openPositions_forTicker( // string ticker ) // { // double cashForSinglePosition = this.account.CashAmount / this.numberOfTickersToBeChosen; // long quantity = // Convert.ToInt64( Math.Floor( cashForSinglePosition / this.account.DataStreamer.GetCurrentBid( ticker ) ) ); // Order order = new Order( OrderType.MarketBuy , new Instrument( ticker ) , quantity ); // this.account.AddOrder( order ); // } // private void oneHourAfterMarketCloseEventHandler_orderChosenTickers_openPositions() // { // foreach ( string ticker in this.chosenTickers.Keys ) // if ( !this.account.Contains( ticker ) ) // { // oneHourAfterMarketCloseEventHandler_orderChosenTickers_openPositions_forTicker( ticker ); // } // } // private void oneHourAfterMarketCloseEventHandler_orderChosenTickers( // IEndOfDayTimer endOfDayTimer ) // { // this.oneHourAfterMarketCloseEventHandler_orderChosenTickers_closePositions( endOfDayTimer ); // this.oneHourAfterMarketCloseEventHandler_orderChosenTickers_openPositions(); // } private bool areBestTickersToBeChosen() { bool returnValue = ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDate == DateTime.MinValue ) ) ) || ( this.now().DateTime >= this.lastOptimizationDate.AddDays( this.outOfSampleWindowDays ) ) ); return returnValue; } /// <summary> /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.areBestTickersToBeChosen() ) // the portfolio is empty and // either the lastOptimizationDate has not been set yet // or outOfSampleWindowDays elapsed since last optimization { // this.eligibleTickers.SetTickers( endOfDayTimingEventArgs.EndOfDayDateTime.DateTime ); this.eligibleTickers.SetTickers(); this.chosenTickers.SetTickers( this.eligibleTickers ); this.lastOptimizationDate = this.now().DateTime; } // oneHourAfterMarketCloseEventHandler_orderChosenTickers( ( IEndOfDayTimer ) sender ); } // #endregion #region FiveMinutesBeforeMarketCloseEventHandler private void fiveMinutesBeforeMarketCloseEventHandler_closePosition( string ticker ) { this.account.ClosePosition( ticker ); } private void fiveMinutesBeforeMarketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); foreach ( string ticker in this.account.Portfolio.Keys ) tickers.Add( ticker ); foreach ( string ticker in tickers ) fiveMinutesBeforeMarketCloseEventHandler_closePosition( ticker ); } private bool todayHigherThanYesterday( string ticker ) { double todayMarketValueAtClose = this.account.DataStreamer.GetCurrentBid( ticker ); EndOfDayDateTime yesterdayAtClose = new EndOfDayDateTime( this.account.EndOfDayTimer.GetCurrentTime().DateTime.AddDays( - 1 ) , EndOfDaySpecificTime.MarketClose ); double yesterdayMarketValueAtClose = this.historicalAdjustedQuoteProvider.GetMarketValue( ticker , yesterdayAtClose ); bool returnValue = ( todayMarketValueAtClose > yesterdayMarketValueAtClose ); return returnValue; } private void fiveMinutesBeforeMarketCloseEventHandler_openPosition( string ticker ) { double maxPositionValue = this.account.GetMarketValue() / this.numberOfPositionsToBeChosen; long sharesToBeTraded = OneRank.MaxBuyableShares( ticker , maxPositionValue , this.account.DataStreamer ); if ( this.todayHigherThanYesterday( ticker ) ) // today close value for ticker is higher than yesterday // close for ticker this.account.AddOrder( new Order( OrderType.MarketBuy , new Instrument( ticker ) , sharesToBeTraded ) ); else // today close value for ticker is not higher than yesterday // close for ticker this.account.AddOrder( new Order( OrderType.MarketSellShort , new Instrument( ticker ) , sharesToBeTraded ) ); } private string getTicker( string signedTicker ) { string returnValue; if ( signedTicker.IndexOf( "-" ) == 0 ) returnValue = signedTicker.Substring( 1 , signedTicker.Length - 1 ); else returnValue = signedTicker; return returnValue; } private void fiveMinutesBeforeMarketCloseEventHandler_openPositions() { foreach ( string signedTicker in this.chosenTickers.Keys ) this.fiveMinutesBeforeMarketCloseEventHandler_openPosition( this.getTicker( signedTicker ) ); } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.fiveMinutesBeforeMarketCloseEventHandler_closePositions(); fiveMinutesBeforeMarketCloseEventHandler_openPositions(); } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2005-11-12 18:40:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16448 Added Files: WFMultiOneRankEligibleTickers.cs Log Message: Selects the tickers to among which best performers will be searched --- NEW FILE: WFMultiOneRankEligibleTickers.cs --- /* QuantProject - Quantitative Finance Library WFMultiOneRankEligibleTickers.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.Data; using QuantProject.Business.Timing; using QuantProject.Data.Selectors; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardMultiOneRank { /// <summary> /// Selects the tickers to among which best performers will be searched /// </summary> public class WFMultiOneRankEligibleTickers { string tickerGroupID; private int numberEligibleTickersToBeChosen; private int numberDaysForPerformanceCalculation; private IEndOfDayTimer endOfDayTimer; private DataTable eligibleTickers; // private int numDaysToComputeLiquidity = 10; public DataTable EligibleTickers { get { return this.eligibleTickers; } } public WFMultiOneRankEligibleTickers( string tickerGroupID , int numberEligibleTickersToBeChosen , int numberDaysForPerformanceCalculation , IEndOfDayTimer endOfDayTimer ) { this.tickerGroupID = tickerGroupID; this.numberEligibleTickersToBeChosen = numberEligibleTickersToBeChosen; this.numberDaysForPerformanceCalculation = numberDaysForPerformanceCalculation; this.endOfDayTimer = endOfDayTimer; this.eligibleTickers = new DataTable(); } #region SetTickers private DataTable setTickers_build_getSelectedTickers() { DateTime dateTime = this.endOfDayTimer.GetCurrentTime().DateTime; // SelectorByGroup selectorByGroup = // new SelectorByGroup( "SP500" , dateTime ); // use the following for fast test SelectorByGroup selectorByGroup = new SelectorByGroup( this.tickerGroupID , dateTime ); DataTable eligibleTickers = selectorByGroup.GetTableOfSelectedTickers(); // SelectorByLiquidity mostLiquid = // new SelectorByLiquidity("Test", false , dateTime.AddDays( - this.numDaysToComputeLiquidity ) , dateTime , // this.numberEligibleTickersToBeChosen ); // DataTable mostLiquidTickers = // mostLiquid.GetTableOfSelectedTickers(); SelectorByQuotationAtEachMarketDay quotedInEachMarketDay = new SelectorByQuotationAtEachMarketDay( eligibleTickers, false, dateTime.AddDays( - this.numberDaysForPerformanceCalculation ) , dateTime, this.numberEligibleTickersToBeChosen,"^SPX"); return quotedInEachMarketDay.GetTableOfSelectedTickers(); } private DataTable setTickers_buildQuickly_getSelectedTickers() { DataTable returnValue = new QuantProject.Data.DataTables.Tickers_tickerGroups( "millo" ); returnValue.Columns[ 0 ].ColumnName = "tiTicker"; return returnValue; } private void setTickers_build() { // for fast debug, comment the following line this.eligibleTickers = setTickers_build_getSelectedTickers(); // for fast debug, uncomment the following line // DataTable selectedTickers = setTickers_buildQuickly_getSelectedTickers(); // foreach ( DataRow dataRow in this.eligibleTickers.Rows ) // this.Add( dataRow[ "TickerId" ].ToString() , // dataRow[ "TickerId" ].ToString() ); } /// <summary> /// Populates the collection of eligible tickers /// </summary> /// <param name="dateTime"></param> public void SetTickers() { this.eligibleTickers.Clear(); setTickers_build(); } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2005-11-12 18:39:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16354 Added Files: WFMultiOneRankChosenTickers.cs Log Message: Chooses the best linear combination of positions, with respect to the one rank strateg --- NEW FILE: WFMultiOneRankChosenTickers.cs --- /* QuantProject - Quantitative Finance Library WFMultiOneRankChosenTickers.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Timing; using QuantProject.Scripts.WalkForwardTesting; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardMultiOneRank { /// <summary> /// Chooses the best linear combination of positions, with respect /// to the one rank strategy /// </summary> public class WFMultiOneRankChosenTickers : Hashtable , IProgressNotifier { private WFMultiOneRankEligibleTickers eligibleTickers; private int numberOfTickersInPortfolio; private int inSampleDays; private IEndOfDayTimer endOfDayTimer; private int generationNumberForGeneticOptimizer; private int populationSizeForGeneticOptimizer; // private ICollection chosenTickers; public WFMultiOneRankChosenTickers( WFMultiOneRankEligibleTickers eligibleTickers , int numberOfTickersInPortfolio , int inSampleDays , IEndOfDayTimer endOfDayTimer , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer ) { this.eligibleTickers = eligibleTickers; this.numberOfTickersInPortfolio = numberOfTickersInPortfolio; this.inSampleDays = inSampleDays; this.endOfDayTimer = endOfDayTimer; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; } public event NewProgressEventHandler NewProgress; #region SetTickers private void newGenerationEventHandler( object sender , NewGenerationEventArgs e ) { this.NewProgress( sender , new NewProgressEventArgs( e.GenerationCounter , e.GenerationNumber ) ); } private void setTickers_setTickersFromGenome( WFMultiOneRankGenomeManager genomeManager , Genome genome ) { string[] genomeMeaning = ( string[] )genomeManager.Decode( genome ); foreach ( string signedTicker in genomeMeaning ) this.Add( signedTicker , signedTicker ); } public void SetTickers( WFMultiOneRankEligibleTickers eligibleTickers ) { this.Clear(); DateTime firstDate = this.endOfDayTimer.GetCurrentTime().DateTime.AddDays( -( this.inSampleDays - 1 ) ); WFMultiOneRankGenomeManager genomeManager = new WFMultiOneRankGenomeManager( eligibleTickers.EligibleTickers , firstDate , this.endOfDayTimer.GetCurrentTime().DateTime , this.numberOfTickersInPortfolio , 0.0 ); GeneticOptimizer geneticOptimizer = new GeneticOptimizer( genomeManager , this.populationSizeForGeneticOptimizer , this.generationNumberForGeneticOptimizer , ConstantsProvider.SeedForRandomGenerator ); geneticOptimizer.NewGeneration += new NewGenerationEventHandler( this.newGenerationEventHandler ); geneticOptimizer.Run( false ); this.setTickers_setTickersFromGenome( genomeManager , geneticOptimizer.BestGenome ); } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2005-11-12 18:37:48
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16012 Added Files: RunWalkForwardMultiOneRank.cs Log Message: Script to test the One Rank strategy on many tickers, chosing the best group when a fixed time span has elapsed. --- NEW FILE: RunWalkForwardMultiOneRank.cs --- /* QuantProject - Quantitative Finance Library RunWalkForwardOneRank.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.Data; using System.Drawing; using System.Threading; using System.Windows.Forms; using QuantProject.ADT; 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.Data.DataProviders; using QuantProject.Presentation.Reporting.WindowsForm; using QuantProject.Scripts.SimpleTesting; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardMultiOneRank { /// <summary> /// Script to test the One Rank strategy on many tickers, chosing the best group /// when a fixed time span has elapsed. /// </summary> public class RunWalkForwardMultiOneRank : Script { private IHistoricalQuoteProvider historicalQuoteProvider; private ReportTable reportTable; private string tickerGroupID; private int numberEligibleTickers; private int numberOfPositionsToBeChosen; private int numberDaysForInSampleOptimization; private int numDaysBetweenEachOptimization; private int generationNumberForGeneticOptimizer; private int populationSizeForGeneticOptimizer; private string benchmark; private DateTime firstDateTime; private DateTime lastDateTime; private double maxRunningHours; private WFMultiOneRankEndOfDayTimerHandler endOfDayTimerHandler; private Account account; private IEndOfDayTimer endOfDayTimer; public RunWalkForwardMultiOneRank( string tickerGroupID , int numberEligibleTickers , int numberOfPositionsToBeChosen , int numberDaysForInSampleOptimization , int numDaysBetweenEachOptimization , int generationNumberForGeneticOptimizer , int populationSizeForGeneticOptimizer , string benchmark , DateTime firstDateTime , DateTime lastDateTime , double maxRunningHours ) { this.tickerGroupID = tickerGroupID; this.numberEligibleTickers = numberEligibleTickers; this.numberOfPositionsToBeChosen = numberOfPositionsToBeChosen; this.numberDaysForInSampleOptimization = numberDaysForInSampleOptimization; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.generationNumberForGeneticOptimizer = generationNumberForGeneticOptimizer; this.populationSizeForGeneticOptimizer = populationSizeForGeneticOptimizer; this.benchmark = benchmark; this.firstDateTime = firstDateTime; this.lastDateTime = lastDateTime; this.maxRunningHours = maxRunningHours; this.reportTable = new ReportTable( "Summary_Reports" ); } public event NewProgressEventHandler InSampleNewProgress; // public event NewProgressEventHandler OutOfSampleNewProgress; #region Run private void run_initializeHistoricalQuoteProvider() { this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } private void run_initializeEndOfDayTimer() { EndOfDayDateTime endOfDayDateTime = new EndOfDayDateTime( firstDateTime , EndOfDaySpecificTime.MarketOpen ); this.endOfDayTimer = new IndexBasedEndOfDayTimer( endOfDayDateTime , this.benchmark ); } private void run_initializeAccount() { this.account = new Account( "WalkForwardOneRank" , this.endOfDayTimer , new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , this.historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , this.historicalQuoteProvider ) ); } private void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new WFMultiOneRankEndOfDayTimerHandler( this.tickerGroupID , this.numberEligibleTickers , this.numberOfPositionsToBeChosen , this.numberDaysForInSampleOptimization , this.numDaysBetweenEachOptimization , this.account , this.generationNumberForGeneticOptimizer , this.populationSizeForGeneticOptimizer ); // this.endOfDayTimerHandler = new EndOfDayTimerHandler( 4 , 3 , 2 , 100 , 30 , // this.account ); } private void inSampleNewProgressEventHandler( Object sender , NewProgressEventArgs eventArgs ) { if ( !(this.InSampleNewProgress == null) ) this.InSampleNewProgress( this , eventArgs ); Console.WriteLine( eventArgs.CurrentProgress.ToString() + " / " + eventArgs.Goal.ToString() + " - " + DateTime.Now.ToString() ); } // private void run_initializeProgressBar_newThread() // { // this.progressBarForm = new ProgressBarForm( this ); // this.progressBarForm.ShowDialog(); // } // private void run_initializeProgressBar() // { // Thread thread = new Thread(new ThreadStart(run_initializeProgressBar_newThread)); //// thread.IsBackground = true; // thread.Start(); // } private void run_initializeProgressHandlers() { this.endOfDayTimerHandler.InSampleNewProgress += new InSampleNewProgressEventHandler( this.inSampleNewProgressEventHandler ); } #region oneHourAfterMarketCloseEventHandler // private void oneHourAfterMarketCloseEventHandler_handleProgessBarForm( // IEndOfDayTimer endOfDayTimer ) // { // long elapsedDays = Convert.ToInt64( ((TimeSpan)( endOfDayTimer.GetCurrentTime().DateTime - // this.startDateTime.DateTime )).TotalDays ); // double totalDays = Convert.ToDouble( ((TimeSpan)( this.endDateTime.DateTime - // this.startDateTime.DateTime )).TotalDays + 1); // if ( Math.Floor( elapsedDays / totalDays * 100 ) > // Math.Floor( ( elapsedDays - 1 ) / totalDays * 100 ) ) // { // // a new out of sample time percentage point has been elapsed // int currentProgress = Convert.ToInt16( Math.Floor( elapsedDays / totalDays * 100 ) ); // NewProgressEventArgs newProgressEventArgs = // new NewProgressEventArgs( currentProgress , 100 ); // this.OutOfSampleNewProgress( this , newProgressEventArgs ); // } // } private void oneHourAfterMarketCloseEventHandler_handleProgessBarForm( IEndOfDayTimer endOfDayTimer ) { string progress = "Current out of sample date:" + endOfDayTimer.GetCurrentTime().DateTime.ToString() + " - " + "First date:" + this.firstDateTime.ToString() + " - " + "Last date:" + this.lastDateTime.ToString(); Console.WriteLine( progress ); } public void marketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Transactions.Count == 0 ) this.account.AddCash( 30000 ); } #region oneHourAfterMarketCloseEventHandler private void showOneRankForm( object sender , MouseEventArgs eventArgs ) { DataGrid dataGrid = (DataGrid)sender; Point point = new Point( eventArgs.X , eventArgs.Y ); DataGrid.HitTestInfo hitTestInfo = dataGrid.HitTest( point ); DataTable dataTable = (DataTable)dataGrid.DataSource; DataRow dataRow = dataTable.Rows[ hitTestInfo.Row ]; // MessageBox.Show( dataRow[ "DateTime" ].ToString() ); DateTime rowDateTime = (DateTime)dataRow[ "DateTime" ]; string rowTicker = (string)dataRow[ "InstrumentKey"]; OneRankForm oneRankForm = new OneRankForm(); oneRankForm.FirstDateTime = rowDateTime.AddDays( -this.numberDaysForInSampleOptimization ); oneRankForm.LastDateTime = rowDateTime; oneRankForm.Ticker = rowTicker; oneRankForm.Show(); } private void mouseEventHandler( object sender , MouseEventArgs eventArgs ) { if ( eventArgs.Button == MouseButtons.Right ) this.showOneRankForm( sender , eventArgs ); } #endregion public void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( ( ( IEndOfDayTimer )sender ).GetCurrentTime().DateTime > this.lastDateTime ) { // the simulation has reached the ending date this.account.EndOfDayTimer.Stop(); // this.progressBarForm.Close(); // ObjectArchiver.Archive( this.account , // @"C:\Documents and Settings\Glauco\Desktop\reports\final.qP" ); Report report = new Report( this.account , this.historicalQuoteProvider ); report.Create( "WFT One Rank" , 1 , new EndOfDayDateTime( this.lastDateTime , EndOfDaySpecificTime.OneHourAfterMarketClose ) , this.benchmark ); report.TransactionGrid.MouseUp += new MouseEventHandler( this.mouseEventHandler ); report.Show(); } else // the simulation has not reached the ending date, yet this.oneHourAfterMarketCloseEventHandler_handleProgessBarForm( ( IEndOfDayTimer )sender ); } #endregion private void run_addEventHandlers() { this.endOfDayTimer.MarketOpen += new MarketOpenEventHandler( this.marketOpenEventHandler ); this.endOfDayTimer.FiveMinutesBeforeMarketClose += new FiveMinutesBeforeMarketCloseEventHandler( this.endOfDayTimerHandler.FiveMinutesBeforeMarketCloseEventHandler ); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler ); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.oneHourAfterMarketCloseEventHandler ); } public override void Run() { run_initializeHistoricalQuoteProvider(); run_initializeEndOfDayTimer(); run_initializeAccount(); run_initializeEndOfDayTimerHandler(); // run_initializeProgressBar(); run_initializeProgressHandlers(); run_addEventHandlers(); // this.progressBarForm.Show(); this.endOfDayTimer.Start(); } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2005-11-12 18:37:00
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15846/WalkForwardMultiOneRank Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardMultiOneRank added to the repository |
|
From: Glauco S. <gla...@us...> - 2005-11-12 18:35:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15393/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: The walk forward one rank on multiple tickers has been added. Namely: - WalkForwardTesting\WalkForwardMultiOneRank\RunWalkForwardMultiOneRank.cs has been added - WalkForwardTesting\WalkForwardMultiOneRank\WFMultiOneRankChosenTickers.cs has been added - WalkForwardTesting\WalkForwardMultiOneRank\WFMultiOneRankEligibleTickers.cs has been added - WalkForwardTesting\WalkForwardMultiOneRank\WFMultiOneRankEndOfDayTimerHandler.cs has been added - WalkForwardTesting\WalkForwardMultiOneRank\WFMultiOneRankGenomeManager.cs has been added Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** b7_Scripts.csproj 8 Nov 2005 18:59:02 -0000 1.42 --- b7_Scripts.csproj 12 Nov 2005 18:35:02 -0000 1.43 *************** *** 349,352 **** --- 349,357 ---- /> <File + RelPath = "WalkForwardTesting\IWalkForwardProgressNotifier.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\GenomeRepresentation.cs" SubType = "Code" *************** *** 414,438 **** /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\BestPerformingTickers.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\ChosenTickers.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\ComparableAccount.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\EligibleTickers.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\IWalkForwardProgressNotifier.cs" SubType = "Code" BuildAction = "Compile" --- 419,463 ---- /> <File ! RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\RunWalkForwardMultiOneRank.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\WFMultiOneRankChosenTickers.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\WFMultiOneRankEligibleTickers.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\WFMultiOneRankEndOfDayTimerHandler.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\WFMultiOneRankGenomeManager.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\BestPerformingTickers.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\ChosenTickers.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\ComparableAccount.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "WalkForwardTesting\WalkForwardOneRank\EligibleTickers.cs" SubType = "Code" BuildAction = "Compile" |
|
From: Marco M. <mi...@us...> - 2005-11-08 18:59:10
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31995/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: Added GenomeManagerForWeightedEfficientPortfolio to the project. Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** b7_Scripts.csproj 23 Oct 2005 19:04:29 -0000 1.41 --- b7_Scripts.csproj 8 Nov 2005 18:59:02 -0000 1.42 *************** *** 244,247 **** --- 244,252 ---- /> <File + RelPath = "TickerSelectionTesting\GenomeManagerForWeightedEfficientPortfolio.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TickerSelectionTesting\GenomeManipulator.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2005-11-08 18:43:26
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26929/b3_Data Modified Files: Data.prjx Log Message: Updated #develop project files Index: Data.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Data.prjx,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Data.prjx 3 Aug 2005 18:59:57 -0000 1.8 --- Data.prjx 8 Nov 2005 18:43:18 -0000 1.9 *************** *** 32,36 **** <File name=".\Selectors\SelectorByAverageRawOpenPrice.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\Selectors\TickerSelector.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> - <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="" /> --- 32,35 ---- |
|
From: Marco M. <mi...@us...> - 2005-11-08 18:43:26
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26929/b7_Scripts Modified Files: Scripts.prjx Log Message: Updated #develop project files Index: Scripts.prjx =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts.prjx,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Scripts.prjx 21 Oct 2005 18:07:45 -0000 1.14 --- Scripts.prjx 8 Nov 2005 18:43:18 -0000 1.15 *************** *** 70,74 **** <File name=".\TickerSelectionTesting\SimpleSelection\RunSimpleSelection.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\WalkForwardTesting\WalkForwardOneRank\MyEndOfDayTimerHandler.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> ! <File name=".\TickerSelectionTesting\MeaningForGenome.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> --- 70,75 ---- <File name=".\TickerSelectionTesting\SimpleSelection\RunSimpleSelection.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\WalkForwardTesting\WalkForwardOneRank\MyEndOfDayTimerHandler.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> ! <File name=".\TickerSelectionTesting\GenomeMeaning.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> ! <File name=".\TickerSelectionTesting\GenomeManagerForWeightedEfficientPortfolio.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References> |
|
From: Marco M. <mi...@us...> - 2005-11-08 18:38:18
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25246/b1_ADT Modified Files: ConstantsProvider.cs Log Message: Adde constant for minimum weight for tickers chosen by GeneticOptimizer based on IGenomeManager deriving from GenomeManagerForEfficientPortfolio. Index: ConstantsProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ConstantsProvider.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ConstantsProvider.cs 27 Aug 2005 19:20:26 -0000 1.14 --- ConstantsProvider.cs 8 Nov 2005 18:38:07 -0000 1.15 *************** *** 39,43 **** public static DateTime DefaultDateForTickersAddedToGroups = new DateTime(1980,1,1); //conventional date for new tickers added to groups ! } --- 39,44 ---- public static DateTime DefaultDateForTickersAddedToGroups = new DateTime(1980,1,1); //conventional date for new tickers added to groups ! public static double MinimumPortfolioWeightForTicker = 0.10; ! //default minimum weight for ticker, used by GenomeManagerForWeightedEfficientPortfolio } |
|
From: Marco M. <mi...@us...> - 2005-11-08 18:37:01
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24791/b7_Scripts/TickerSelectionTesting Modified Files: RunEfficientCTOPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientCTCPortfolio.cs EndOfDayTimerHandlerOTCMultiday.cs EndOfDayTimerHandlerOTCCTO.cs EndOfDayTimerHandlerCTO.cs EndOfDayTimerHandlerCTCWeekly.cs EndOfDayTimerHandlerCTC.cs EndOfDayTimerHandler.cs Log Message: Added GenomeManagerForWeightedEfficientPortfolio to the project. Updated script files for managing weights returned by the new Meaning implementation for genomes. Index: EndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandler.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** EndOfDayTimerHandler.cs 18 Sep 2005 21:13:36 -0000 1.17 --- EndOfDayTimerHandler.cs 8 Nov 2005 18:36:48 -0000 1.18 *************** *** 46,49 **** --- 46,50 ---- protected DataTable eligibleTickers; protected string[] chosenTickers; + protected double[] chosenTickersPortfolioWeights; protected string[] lastOrderedTickers; *************** *** 118,121 **** --- 119,123 ---- this.targetReturn = targetReturn; this.portfolioType = portfolioType; + this.setDefaultChosenTickersPortfolioWeights(); } *************** *** 134,144 **** this.lastOrderedTickers = new string[chosenTickers.Length]; this.portfolioType = portfolioType; } ! 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 ) ) ); --- 136,155 ---- this.lastOrderedTickers = new string[chosenTickers.Length]; this.portfolioType = portfolioType; + this.setDefaultChosenTickersPortfolioWeights(); } ! private void setDefaultChosenTickersPortfolioWeights() ! { ! this.chosenTickersPortfolioWeights = new double[this.chosenTickers.Length]; ! for(int i = 0;i<this.chosenTickers.Length;i++) ! this.chosenTickersPortfolioWeights[i]=1.0/this.chosenTickers.Length; ! } ! ! protected virtual void addOrderForTicker(int tickerPosition ) { string tickerCode = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[tickerPosition]); ! double cashForSinglePosition = ! this.account.CashAmount * this.chosenTickersPortfolioWeights[tickerPosition]; long quantity = Convert.ToInt64( Math.Floor( cashForSinglePosition / this.account.DataStreamer.GetCurrentBid( tickerCode ) ) ); *************** *** 146,150 **** if(this.portfolioType == PortfolioType.OnlyShort || (this.portfolioType == PortfolioType.ShortAndLong && ! ticker != tickerCode)) order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); else --- 157,161 ---- if(this.portfolioType == PortfolioType.OnlyShort || (this.portfolioType == PortfolioType.ShortAndLong && ! this.chosenTickers[tickerPosition] != tickerCode)) order = new Order( OrderType.MarketSellShort, new Instrument( tickerCode ) , quantity ); else *************** *** 180,193 **** protected virtual void addChosenTickersToOrderList() { ! int idx = 0; ! foreach ( string ticker in this.chosenTickers ) { ! if(ticker != null) { ! this.addOrderForTicker( ticker ); ! this.lastOrderedTickers[idx] = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); } - idx++; } } --- 191,202 ---- protected virtual void addChosenTickersToOrderList() { ! for( int i = 0; i<this.chosenTickers.Length; i++) { ! if(this.chosenTickers[i] != null) { ! this.addOrderForTicker( i ); ! this.lastOrderedTickers[i] = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[i]); } } } Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GenomeManagerForEfficientCTCPortfolio.cs 27 Jul 2005 22:30:55 -0000 1.9 --- GenomeManagerForEfficientCTCPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.10 *************** *** 109,112 **** --- 109,120 ---- } */ + + //sharpe ratio as fitness + /* + protected override double getFitnessValue_calculate() + { + return this.RateOfReturn/Math.Sqrt(this.Variance); + } + */ } Index: EndOfDayTimerHandlerOTCCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCCTO.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerOTCCTO.cs 21 Oct 2005 18:07:45 -0000 1.1 --- EndOfDayTimerHandlerOTCCTO.cs 8 Nov 2005 18:36:48 -0000 1.2 *************** *** 106,110 **** this.reverseSignOfChosenTickers(); this.openPositions(); ! } --- 106,110 ---- this.reverseSignOfChosenTickers(); this.openPositions(); ! this.reverseSignOfChosenTickers(); } *************** *** 179,183 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = (string[])GO.BestGenome.Meaning; } //else it will be buyed again the previous optimized portfolio --- 179,183 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; } //else it will be buyed again the previous optimized portfolio Index: EndOfDayTimerHandlerOTCMultiday.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerOTCMultiday.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerOTCMultiday.cs 23 Oct 2005 19:09:04 -0000 1.2 --- EndOfDayTimerHandlerOTCMultiday.cs 8 Nov 2005 18:36:48 -0000 1.3 *************** *** 182,188 **** this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! //this.chosenTickers = ((MeaningForGenome)GO.BestGenome.Meaning).Tickers; ! this.chosenTickers = ! this.setTickers_getBestTickersLosingAtLastDay(genManEfficientCTOPortfolio); } //else it will be buyed again the previous optimized portfolio --- 182,189 ---- this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate); ! this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; ! //this.chosenTickers = ! // this.setTickers_getBestTickersLosingAtLastDay(genManEfficientCTOPortfolio); } //else it will be buyed again the previous optimized portfolio Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** GenomeManagerForEfficientCTOPortfolio.cs 25 Jul 2005 22:49:54 -0000 1.13 --- GenomeManagerForEfficientCTOPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.14 *************** *** 38,42 **** /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForEfficientPortfolio { --- 38,42 ---- /// </summary> [Serializable] ! public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForWeightedEfficientPortfolio { *************** *** 67,71 **** return returnValue; } ! /* protected override double getFitnessValue_calculate() { --- 67,71 ---- return returnValue; } ! /*using LPM protected override double getFitnessValue_calculate() { *************** *** 96,99 **** --- 96,106 ---- } */ + + protected override double getFitnessValue_calculate() + { + return this.RateOfReturn/Math.Sqrt(this.Variance); + } + + } Index: EndOfDayTimerHandlerCTO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTO.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** EndOfDayTimerHandlerCTO.cs 23 Oct 2005 19:09:04 -0000 1.20 --- EndOfDayTimerHandlerCTO.cs 8 Nov 2005 18:36:48 -0000 1.21 *************** *** 163,166 **** --- 163,167 ---- currentDate); this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; + this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio Index: EndOfDayTimerHandlerCTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTC.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** EndOfDayTimerHandlerCTC.cs 23 Oct 2005 19:09:04 -0000 1.16 --- EndOfDayTimerHandlerCTC.cs 8 Nov 2005 18:36:48 -0000 1.17 *************** *** 178,181 **** --- 178,182 ---- currentDate); this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; + this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio Index: RunEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/RunEfficientCTOPortfolio.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** RunEfficientCTOPortfolio.cs 18 Sep 2005 21:13:36 -0000 1.22 --- RunEfficientCTOPortfolio.cs 8 Nov 2005 18:36:48 -0000 1.23 *************** *** 71,75 **** portfolioType, maxRunningHours) { ! this.ScriptName = "OpenCloseScripts"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } --- 71,76 ---- portfolioType, maxRunningHours) { ! this.ScriptName = "OpenCloseScriptsSharpeRatioWithCoeff"; ! //this.ScriptName = "OpenCloseScriptsSharpeRatio"; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } *************** *** 105,110 **** protected override void run_initializeHistoricalQuoteProvider() { ! this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! //this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } --- 106,111 ---- protected override void run_initializeHistoricalQuoteProvider() { ! //this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } Index: EndOfDayTimerHandlerCTCWeekly.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandlerCTCWeekly.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerCTCWeekly.cs 23 Oct 2005 19:09:04 -0000 1.4 --- EndOfDayTimerHandlerCTCWeekly.cs 8 Nov 2005 18:36:48 -0000 1.5 *************** *** 153,156 **** --- 153,157 ---- GO.Run(false); this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; + this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio |
|
From: Marco M. <mi...@us...> - 2005-11-08 18:34:11
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23922/b7_Scripts/TickerSelectionTesting Added Files: GenomeManagerForWeightedEfficientPortfolio.cs Log Message: Added GenomeManagerForWeightedEfficientPortfolio to the project. --- NEW FILE: GenomeManagerForWeightedEfficientPortfolio.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerForWeightedEfficientPortfolio.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.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios { /// <summary> /// This is the base class implementing IGenomeManager, in order to find /// efficient portfolios in which tickers are weighted differently /// </summary> [Serializable] public class GenomeManagerForWeightedEfficientPortfolio : GenomeManagerForEfficientPortfolio { public GenomeManagerForWeightedEfficientPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance, PortfolioType portfolioType):base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, targetPerformance, portfolioType) { this.genomeSize = 2*this.genomeSize; //at even position the gene is used for finding //the coefficient for the ticker represented at the next odd position } #region override getPortfolioRatesOfReturn protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) { double totalReturnedByWeights = (1.0-ConstantsProvider.MinimumPortfolioWeightForTicker*genes.Length/2)/ConstantsProvider.MinimumPortfolioWeightForTicker; int totalOfAbsoluteValuesForWeightsInGenes = 0; for(int j = 0; j<genes.Length; j++) { if(j%2==0) //ticker weight is contained in genes at even position totalOfAbsoluteValuesForWeightsInGenes += (int)Math.Abs(genes[j]); } double min = ConstantsProvider.MinimumPortfolioWeightForTicker; return min*(1.0 + totalReturnedByWeights * Math.Abs(genes[tickerPositionInGenes-1])/totalOfAbsoluteValuesForWeightsInGenes); } protected override double[] getPortfolioRatesOfReturn(int[] genes) { double[] returnValue = new double[this.numberOfExaminedReturns]; for(int i = 0; i<returnValue.Length; i++) { for(int j = 0; j<genes.Length; j++) { if(j%2==1) //ticker ID is contained in genes at odd position returnValue[i] += this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(genes,j,i); } } return returnValue; } #endregion #region override Decode public override object Decode(Genome genome) { string[] arrayOfTickers = new string[genome.Genes().Length/2]; double[] arrayOfTickersWeights = new double[genome.Genes().Length/2]; int indexOfTicker; int i = 0;//for the arrayOfTickers for(int index = 0; index < genome.Genes().Length; index++) { if(index%2==1) //indexForTicker is contained in genes at odd position { indexOfTicker = (int)genome.Genes().GetValue(index); arrayOfTickers[i] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); arrayOfTickersWeights[i] = this.getTickerWeight(genome.Genes(), index); i++; } } GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, arrayOfTickersWeights, this.PortfolioRatesOfReturn[this.portfolioRatesOfReturn.Length - 1], this.RateOfReturn, this.Variance); return meaning; } #endregion public override Genome[] GetChilds(Genome parent1, Genome parent2) { return GenomeManipulator.MixGenesWithoutDuplicates(parent1, parent2); } public override int GetNewGeneValue(Genome genome, int genePosition) { // in this implementation only new gene values pointing to tickers // must be different from the others already stored (in odd positions of genome) int returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); while(genePosition%2 == 1 && GenomeManipulator.IsTickerContainedInGenome(returnValue,genome)) //while in the given position has to be stored //a new gene pointing to a ticker and //the proposed returnValue points to a ticker //already stored in the given genome { // a new returnValue has to be generated returnValue = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); } return returnValue; } public override void Mutate(Genome genome, double mutationRate) { // in this implementation only one gene is mutated int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes +1); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); while(genePositionToBeMutated%2 == 1 && GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome)) //while in the proposed genePositionToBeMutated has to be stored //a new gene pointing to a ticker and //the proposed newValueForGene points to a ticker //already stored in the given genome { newValueForGene = GenomeManagement.RandomGenerator.Next(genome.MinValueForGenes, genome.MaxValueForGenes + 1); } GenomeManagement.MutateOneGene(genome, mutationRate, genePositionToBeMutated, newValueForGene); } } } |
|
From: Marco M. <mi...@us...> - 2005-11-08 18:32:59
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23365/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio Modified Files: RunTestingOptimizationOpenToClose.cs Log Message: no message Index: RunTestingOptimizationOpenToClose.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/EvaluatingOptimizationTechnique/EfficientPortfolio/RunTestingOptimizationOpenToClose.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RunTestingOptimizationOpenToClose.cs 23 Oct 2005 19:05:37 -0000 1.5 --- RunTestingOptimizationOpenToClose.cs 8 Nov 2005 18:32:43 -0000 1.6 *************** *** 136,145 **** } DateTime dateOutOfSample = this.marketDate.AddDays(this.numDaysAfterLastOptimizationDay); ! Quotes tickerQuotes = new Quotes(ticker, dateOutOfSample, ! dateOutOfSample); ! returnValue += ! (tickerQuotes.GetFirstValidRawClose(dateOutOfSample)/ ! tickerQuotes.GetFirstValidRawOpen(dateOutOfSample) - 1.0)*coefficient; ! } return returnValue/genome.Size; --- 136,163 ---- } DateTime dateOutOfSample = this.marketDate.AddDays(this.numDaysAfterLastOptimizationDay); ! //returnValue is the single return for the numDaysAfterLastOptimizationDay - th day ! //after the given market date ! ! //Quotes tickerQuotes = new Quotes(ticker, dateOutOfSample, ! // dateOutOfSample); ! ! //returnValue += ! // (tickerQuotes.GetFirstValidRawClose(dateOutOfSample)/ ! // tickerQuotes.GetFirstValidRawOpen(dateOutOfSample) - 1.0)*coefficient; ! // ! //returnValue is the average return for the interval between ! //the given market date and the numDaysAfterLastOptimizationDay - th ! //day after the given market date ! Quotes tickerQuotes = new Quotes(ticker, this.marketDate, ! dateOutOfSample); ! double close, open; ! for(int i = 0; i<this.numDaysAfterLastOptimizationDay; i++) ! { ! close = tickerQuotes.GetFirstValidRawClose(this.marketDate.AddDays(i)); ! open = tickerQuotes.GetFirstValidRawOpen(this.marketDate.AddDays(i)); ! returnValue += ! (close/open - 1.0)*coefficient/this.numDaysAfterLastOptimizationDay; ! ! } } return returnValue/genome.Size; |