quantproject-developers Mailing List for QuantProject (Page 45)
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...> - 2008-04-27 17:50:58
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21167/b7_Scripts/WalkForwardTesting/PairsTrading Modified Files: PairsTradingMain.cs Log Message: OutOfSampleChooser(s) have been introduced for a more sophisticated out of sample choice, among the most correlated couples Index: PairsTradingMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/PairsTradingMain.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** PairsTradingMain.cs 20 Apr 2008 17:08:05 -0000 1.11 --- PairsTradingMain.cs 27 Apr 2008 17:50:53 -0000 1.12 *************** *** 99,102 **** --- 99,104 ---- { int numberOfBestTestingPositionsToBeReturned = 50; + // uncomment the following line for a faster script + // numberOfBestTestingPositionsToBeReturned = 5; IDecoderForTestingPositions decoderForWeightedPositions = *************** *** 138,146 **** int inSampleDays = 180; // uncomment the following line for a faster script ! // inSampleDays = 5; // inSampleDays = 60; IIntervalsSelector intervalsSelector = new OddIntervalsSelector( 1 , 1 , this.benchmark ); IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = new PairsTradingStrategy( --- 140,156 ---- int inSampleDays = 180; // uncomment the following line for a faster script ! // inSampleDays = 5; ! // inSampleDays = 60; IIntervalsSelector intervalsSelector = new OddIntervalsSelector( 1 , 1 , this.benchmark ); + OutOfSampleChooser outOfSampleChooser = + new OutOfSampleChooserForSingleLongAndShort( + 0.006 , 0.99 , 0.006 , 0.99 ); + outOfSampleChooser = + new OutOfSampleChooserForExactNumberOfBestLongPositions( + 2 , 0.006 , 0.99 , 0.006 , 0.99 ); + IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = new PairsTradingStrategy( *************** *** 149,160 **** this.historicalQuoteProviderForInSample , this.historicalQuoteProviderForChosingPositionsOutOfSample , ! 0.006 , 0.99 , 0.006 , 0.99 ); ! endOfDayStrategyForBacktester = ! new LongOnlyPairsTradingStrategy( ! 7 , inSampleDays , intervalsSelector , ! eligiblesSelector , inSampleChooser , ! this.historicalQuoteProviderForInSample , ! this.historicalQuoteProviderForChosingPositionsOutOfSample , ! 0.006 , 0.99 , 0.006 , 0.99 ); return endOfDayStrategyForBacktester; } --- 159,177 ---- this.historicalQuoteProviderForInSample , this.historicalQuoteProviderForChosingPositionsOutOfSample , ! outOfSampleChooser ); ! // IEndOfDayStrategyForBacktester endOfDayStrategyForBacktester = ! // new PairsTradingStrategy( ! // 7 , inSampleDays , intervalsSelector , ! // eligiblesSelector , inSampleChooser , ! // this.historicalQuoteProviderForInSample , ! // this.historicalQuoteProviderForChosingPositionsOutOfSample , ! // 0.006 , 0.99 , 0.006 , 0.99 ); ! // endOfDayStrategyForBacktester = ! // new LongOnlyPairsTradingStrategy( ! // 7 , inSampleDays , intervalsSelector , ! // eligiblesSelector , inSampleChooser , ! // this.historicalQuoteProviderForInSample , ! // this.historicalQuoteProviderForChosingPositionsOutOfSample , ! // 0.006 , 0.02 , 0.006 , 0.02 ); return endOfDayStrategyForBacktester; } *************** *** 168,172 **** DateTime firstDateTime = new DateTime( 2001 , 1 , 1 ); DateTime lastDateTime = new DateTime( 2004 , 12 , 31 ); ! double maxRunningHours = 5; EndOfDayStrategyBackTester endOfDayStrategyBackTester = --- 185,192 ---- DateTime firstDateTime = new DateTime( 2001 , 1 , 1 ); DateTime lastDateTime = new DateTime( 2004 , 12 , 31 ); ! // uncomment the following line for a faster script ! // lastDateTime = new DateTime( 2001 , 1 , 31 ); ! ! double maxRunningHours = 7; EndOfDayStrategyBackTester endOfDayStrategyBackTester = |
|
From: Glauco S. <gla...@us...> - 2008-04-27 17:49:07
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EndOfDayStrategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv20018/b4_Business/a2_Strategies/EndOfDayStrategies Modified Files: BasicEndOfDayStrategyForBacktester.cs Log Message: inSampleReturnsManager is now a protected field of the class (it was a local variable in the previous version) This way, the inSampleReturnsManager is not lost out after the in sample optimization and it can be further used to take some decision out of sample Index: BasicEndOfDayStrategyForBacktester.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EndOfDayStrategies/BasicEndOfDayStrategyForBacktester.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BasicEndOfDayStrategyForBacktester.cs 1 Apr 2008 21:25:32 -0000 1.4 --- BasicEndOfDayStrategyForBacktester.cs 27 Apr 2008 17:49:01 -0000 1.5 *************** *** 58,64 **** protected DateTime lastOptimizationDateTime; protected ReturnIntervals returnIntervals; - private Account account; protected TestingPositions[] bestTestingPositionsInSample; --- 58,65 ---- protected DateTime lastOptimizationDateTime; protected ReturnIntervals returnIntervals; private Account account; + protected ReturnsManager inSampleReturnsManager; + protected TestingPositions[] bestTestingPositionsInSample; *************** *** 275,284 **** this.eligiblesSelector.GetEligibleTickers( inSampleReturnIntervals.BordersHistory ); ! ReturnsManager returnsManager = new ReturnsManager( inSampleReturnIntervals , this.historicalQuoteProviderForInSample ); this.bestTestingPositionsInSample = (TestingPositions[])this.inSampleChooser.AnalyzeInSample( ! eligibleTickers , returnsManager ); this.checkQualityFor_bestTestingPositionsInSample(); --- 276,285 ---- this.eligiblesSelector.GetEligibleTickers( inSampleReturnIntervals.BordersHistory ); ! this.inSampleReturnsManager = new ReturnsManager( inSampleReturnIntervals , this.historicalQuoteProviderForInSample ); this.bestTestingPositionsInSample = (TestingPositions[])this.inSampleChooser.AnalyzeInSample( ! eligibleTickers , this.inSampleReturnsManager ); this.checkQualityFor_bestTestingPositionsInSample(); |
|
From: Glauco S. <gla...@us...> - 2008-04-27 17:45:56
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18624/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: - WalkForwardTesting\PairsTrading\Strategies\LongOnlyPairsTradingStrategy.cs has been removed - WalkForwardTesting\PairsTrading\OutOfSampleChoosers\OutOfSampleChooser.cs has been added - WalkForwardTesting\PairsTrading\OutOfSampleChoosers\OutOfSampleChooserForExactNumberOfBestLongPositions.cs has been added - WalkForwardTesting\PairsTrading\OutOfSampleChoosers\OutOfSampleChooserForSingleLongAndShort.cs has been added Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** b7_Scripts.csproj 26 Apr 2008 09:57:00 -0000 1.95 --- b7_Scripts.csproj 27 Apr 2008 17:45:52 -0000 1.96 *************** *** 965,969 **** /> <File ! RelPath = "WalkForwardTesting\PairsTrading\Strategies\LongOnlyPairsTradingStrategy.cs" SubType = "Code" BuildAction = "Compile" --- 965,979 ---- /> <File ! RelPath = "WalkForwardTesting\PairsTrading\OutOfSampleChoosers\OutOfSampleChooser.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "WalkForwardTesting\PairsTrading\OutOfSampleChoosers\OutOfSampleChooserForExactNumberOfBestLongPositions.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "WalkForwardTesting\PairsTrading\OutOfSampleChoosers\OutOfSampleChooserForSingleLongAndShort.cs" SubType = "Code" BuildAction = "Compile" |
|
From: Glauco S. <gla...@us...> - 2008-04-27 17:44:03
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17742 Added Files: OutOfSampleChooserForExactNumberOfBestLongPositions.cs Log Message: Selects an exact number of long position to be used out of sample: given the inefficient couples, the long positons returned are those belonging to the highest correlated couples --- NEW FILE: OutOfSampleChooserForExactNumberOfBestLongPositions.cs --- /* QuantProject - Quantitative Finance Library OutOfSampleChooserForExactNumberOfBestLongPositions.cs Copyright (C) 2008 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.Collections; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading { /// <summary> /// Selects an exact number of long position to be used out of sample: /// Given the inefficient couples, the long positons /// returned are those belonging to the highest correlated couples /// </summary> public class OutOfSampleChooserForExactNumberOfBestLongPositions : OutOfSampleChooser { private int exactNumberOfBestLongPositionsToBeReturned; /// <summary> /// Returns exactNumberOfBestLongPositions long positions, if at /// least exactNumberOfBestLongPositions inefficient couples /// were found. Given the inefficient couples, the long positons /// returned are those belonging to the highest correlated couples /// </summary> /// <param name="exactNumberOfBestLongPositions"></param> /// <param name="minThresholdForGoingLong"></param> /// <param name="maxThresholdForGoingLong"></param> /// <param name="minThresholdForGoingShort"></param> /// <param name="maxThresholdForGoingShort"></param> public OutOfSampleChooserForExactNumberOfBestLongPositions( int exactNumberOfBestLongPositionsToBeReturned , double minThresholdForGoingLong , double maxThresholdForGoingLong , double minThresholdForGoingShort , double maxThresholdForGoingShort ) : base( minThresholdForGoingLong , maxThresholdForGoingLong , minThresholdForGoingShort , maxThresholdForGoingShort ) { this.exactNumberOfBestLongPositionsToBeReturned = exactNumberOfBestLongPositionsToBeReturned; } #region getPositionsToBeOpened // WeightedPositions getLongWeightedPositionsFromSingleTicker( // string ticker ) // { // double[] weights = { 1 }; // string[] tickers = { ticker }; // WeightedPositions weightedPositionsToBeReturned = // new WeightedPositions( weights , tickers ); // return weightedPositionsToBeReturned; // } #region getWeights private double[] getNotNormalizedEqualWeights() { double[] notNormalizedWeights = new double[ this.exactNumberOfBestLongPositionsToBeReturned ]; for ( int i = 0 ; i < this.exactNumberOfBestLongPositionsToBeReturned ; i++ ) notNormalizedWeights[ i ] = 1; return notNormalizedWeights; } private double[] getWeights() { double[] notNormalizedWeights = this.getNotNormalizedEqualWeights(); double[] normalizedWeights = WeightedPositions.GetNormalizedWeights( notNormalizedWeights ); return normalizedWeights; } #endregion getWeights private WeightedPositions getPositionsToBeOpened( string[] longPositionTickers ) { double[] weights = this.getWeights(); string[] tickers = StringArrayManager.SubArray( longPositionTickers , 0 , this.exactNumberOfBestLongPositionsToBeReturned ); WeightedPositions weightedPositionsToOpened = new WeightedPositions( weights , tickers ); return weightedPositionsToOpened; } protected override WeightedPositions getPositionsToBeOpened( WeightedPositions[] inefficientCouples , ReturnsManager inSampleReturnsManager ) { WeightedPositions weightedPositionsToBeOpened = null; string[] longPositionTickers = this.getLongPositionTickers( inefficientCouples ); if ( longPositionTickers.Length >= this.exactNumberOfBestLongPositionsToBeReturned ) // at least a long position has been found in the inefficient couples weightedPositionsToBeOpened = this.getPositionsToBeOpened( longPositionTickers ); // weightedPositionsToBeOpened = // this.getLongWeightedPositionsFromSingleTicker( // longPositionTickers[ 0 ] ); return weightedPositionsToBeOpened; } #endregion getPositionsToBeOpened } } |
|
From: Glauco S. <gla...@us...> - 2008-04-27 17:43:36
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17705/WalkForwardTesting/PairsTrading/OutOfSampleChoosers Added Files: OutOfSampleChooserForSingleLongAndShort.cs Log Message: Selects a single couple with a long and a short position --- NEW FILE: OutOfSampleChooserForSingleLongAndShort.cs --- /* QuantProject - Quantitative Finance Library OutOfSampleChooserForSingleLongAndShort.cs Copyright (C) 2008 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.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading { /// <summary> /// Selects a single couple with a long and a short position /// </summary> public class OutOfSampleChooserForSingleLongAndShort : OutOfSampleChooser { /// <summary> /// Selects a single couple with a long and a short position /// </summary> public OutOfSampleChooserForSingleLongAndShort( double minThresholdForGoingLong , double maxThresholdForGoingLong , double minThresholdForGoingShort , double maxThresholdForGoingShort ) : base( minThresholdForGoingLong , maxThresholdForGoingLong , minThresholdForGoingShort , maxThresholdForGoingShort ) { } protected override WeightedPositions getPositionsToBeOpened( WeightedPositions[] inefficientCouples , ReturnsManager inSampleReturnsManager ) { WeightedPositions positionsToBeOpened = null; if ( ( inefficientCouples != null ) && ( inefficientCouples.Length > 0 ) ) // at least an inefficient couple has been found positionsToBeOpened = inefficientCouples[ 0 ]; return positionsToBeOpened; } } } |
|
From: Glauco S. <gla...@us...> - 2008-04-27 17:42:56
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17228 Added Files: OutOfSampleChooser.cs Log Message: Given the in sample TestingPositions candidates, this class selects the positions to be opened --- NEW FILE: OutOfSampleChooser.cs --- /* QuantProject - Quantitative Finance Library OutOfSampleChooser.cs Copyright (C) 2008 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.Collections; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Timing; namespace QuantProject.Scripts.WalkForwardTesting.PairsTrading { /// <summary> /// Given the in sample TestingPositions candidates, /// this class selects the positions to be opened /// </summary> public abstract class OutOfSampleChooser { private double minThresholdForGoingLong; private double maxThresholdForGoingLong; private double minThresholdForGoingShort; private double maxThresholdForGoingShort; public OutOfSampleChooser( double minThresholdForGoingLong , double maxThresholdForGoingLong , double minThresholdForGoingShort , double maxThresholdForGoingShort ) { this.minThresholdForGoingLong = minThresholdForGoingLong; this.maxThresholdForGoingLong = maxThresholdForGoingLong; this.minThresholdForGoingShort = minThresholdForGoingShort; this.maxThresholdForGoingShort = maxThresholdForGoingShort; } /// <summary> /// returns the positions to be opened /// </summary> /// <param name="inefficientCouples">a collection of couples that /// are strongly correlated in sample, but were not so /// correlated in the latest second phase interval</param> /// <param name="inSampleReturnsManager"></param> /// <returns></returns> protected abstract WeightedPositions getPositionsToBeOpened( WeightedPositions[] inefficientCouples , ReturnsManager inSampleReturnsManager ); #region GetPositionsToBeOpened #region getInefficientCouples #region getReturnsManagerForLastSecondPhaseInterval private EndOfDayDateTime getIntervalBeginForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals ) { // this method will be invoked only if (this.returnIntervals.Count >= 2) int secondLastIntervalIndex = outOfSampleReturnIntervals.Count - 2; ReturnInterval secondLastInterval = outOfSampleReturnIntervals[ secondLastIntervalIndex ]; return secondLastInterval.End; } private EndOfDayDateTime getIntervalEndForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals ) { return outOfSampleReturnIntervals.LastInterval.Begin; } private ReturnInterval getReturnIntervalForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals ) { EndOfDayDateTime intervalBegin = this.getIntervalBeginForLastSecondPhaseInterval( outOfSampleReturnIntervals ); EndOfDayDateTime intervalEnd = this.getIntervalEndForLastSecondPhaseInterval( outOfSampleReturnIntervals ); ReturnInterval returnIntervalForLastSecondPhaseInterval = new ReturnInterval( intervalBegin , intervalEnd ); return returnIntervalForLastSecondPhaseInterval; } private ReturnIntervals getReturnIntervalsForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals ) { ReturnInterval returnIntervalForLastSecondPhaseInterval = this.getReturnIntervalForLastSecondPhaseInterval( outOfSampleReturnIntervals ); ReturnIntervals returnIntervalsForLastSecondPhaseInterval = new ReturnIntervals( returnIntervalForLastSecondPhaseInterval ); return returnIntervalsForLastSecondPhaseInterval; } private ReturnsManager getReturnsManagerForLastSecondPhaseInterval( ReturnIntervals outOfSampleReturnIntervals , IHistoricalQuoteProvider historicalQuoteProviderForChosingPositionsOutOfSample ) { ReturnIntervals returnIntervals = this.getReturnIntervalsForLastSecondPhaseInterval( outOfSampleReturnIntervals ); // ReturnsManager returnsManager = // new ReturnsManager( returnIntervals , // this.historicalAdjustedQuoteProvider ); ReturnsManager returnsManager = new ReturnsManager( returnIntervals , historicalQuoteProviderForChosingPositionsOutOfSample ); return returnsManager; } #endregion getReturnsManagerForLastSecondPhaseInterval private double getReturnForTheLastSecondPhaseInterval( ReturnsManager returnsManagerForLastSecondPhaseInterval , WeightedPositions weightedPositions ) { // returnsManager should contain a single ReturnInterval, and // this ReturnInterval should be the last second phase interval double returnForTheLastSecondPhaseInterval = weightedPositions.GetReturn( 0 , returnsManagerForLastSecondPhaseInterval ); return returnForTheLastSecondPhaseInterval; } /// <summary> /// Inverts one of the two positions /// </summary> /// <param name="weightedPositions"></param> /// <returns></returns> private WeightedPositions getCandidateForPortfolio( WeightedPositions weightedPositions ) { double[] weights = new double[ 2 ]; weights[ 0 ] = ((WeightedPosition)weightedPositions[ 0 ]).Weight; weights[ 1 ] = -((WeightedPosition)weightedPositions[ 1 ]).Weight; string[] tickers = new String[ 2 ]; tickers[ 0 ] = ((WeightedPosition)weightedPositions[ 0 ]).Ticker; tickers[ 1 ] = ((WeightedPosition)weightedPositions[ 1 ]).Ticker; WeightedPositions candidateForPortfolio = new WeightedPositions( weights , tickers ); return candidateForPortfolio; } // if the currentWeightedPositions' return satisfies the thresholds // then this method returns the WeightedPositions that might be opened. // Otherwise (currentWeightedPositions' return does NOT // satisfy the thresholds) this method returns null private WeightedPositions getPositionsIfInefficiencyIsInTheRange( ReturnsManager returnsManagerForLastSecondPhaseInterval , WeightedPositions currentWeightedPositions ) { WeightedPositions weightedPositionsToBeOpened = null; try { double returnForTheLastSecondPhaseInterval = this.getReturnForTheLastSecondPhaseInterval( returnsManagerForLastSecondPhaseInterval , currentWeightedPositions ); if ( ( returnForTheLastSecondPhaseInterval >= this.minThresholdForGoingLong ) && ( returnForTheLastSecondPhaseInterval <= this.maxThresholdForGoingLong ) ) // it looks like there has been an inefficiency that // might be recovered, by going short weightedPositionsToBeOpened = currentWeightedPositions.Opposite; if ( ( -returnForTheLastSecondPhaseInterval >= this.minThresholdForGoingShort ) && ( -returnForTheLastSecondPhaseInterval <= this.maxThresholdForGoingShort ) ) // it looks like there has been an inefficiency that // might be recovered, by going long weightedPositionsToBeOpened = currentWeightedPositions; } catch( TickerNotExchangedException ex ) { string dummy = ex.Message; } return weightedPositionsToBeOpened; } private void addPositionsIfInefficiencyForCurrentCoupleIsInTheRange( TestingPositions[] bestTestingPositionsInSample , ReturnsManager returnsManagerForLastSecondPhaseInterval , int currentTestingPositionsIndex , ArrayList inefficientCouples ) { WeightedPositions currentWeightedPositions = bestTestingPositionsInSample[ currentTestingPositionsIndex ].WeightedPositions; WeightedPositions candidateForPortfolio = this.getCandidateForPortfolio( currentWeightedPositions ); WeightedPositions weightedPositionsThatMightBeOpended = this.getPositionsIfInefficiencyIsInTheRange( returnsManagerForLastSecondPhaseInterval , candidateForPortfolio ); if ( weightedPositionsThatMightBeOpended != null ) // the current couple has not an inefficiency that's in the range inefficientCouples.Add( weightedPositionsThatMightBeOpended ); } protected ArrayList getInefficientCouples( TestingPositions[] bestTestingPositionsInSample , ReturnsManager returnsManagerForLastSecondPhaseInterval ) { ArrayList inefficientCouples = new ArrayList(); for ( int currentTestingPositionsIndex = 0 ; currentTestingPositionsIndex < bestTestingPositionsInSample.Length ; currentTestingPositionsIndex++ ) this.addPositionsIfInefficiencyForCurrentCoupleIsInTheRange( bestTestingPositionsInSample , returnsManagerForLastSecondPhaseInterval , currentTestingPositionsIndex , inefficientCouples ); // // while ( ( weightedPositionsToBeOpended == null ) // && ( currentTestingPositionsIndex < bestTestingPositionsInSample.Length ) ) // { // weightedPositionsToBeOpended = // this.getPositionsToBeOpenedWithRespectToCurrentWeightedPositions( // bestTestingPositionsInSample , // returnsManagerForLastSecondPhaseInterval , // currentTestingPositionsIndex ); // currentTestingPositionsIndex++; // } // return weightedPositionsToBeOpended; return inefficientCouples; } private ArrayList getArrayListOfInefficientCouples( TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , IHistoricalQuoteProvider historicalQuoteProviderForChosingPositionsOutOfSample ) { ReturnsManager returnsManagerForLastSecondPhaseInterval = this.getReturnsManagerForLastSecondPhaseInterval( outOfSampleReturnIntervals , historicalQuoteProviderForChosingPositionsOutOfSample ); ArrayList inefficientCouples = this.getInefficientCouples( bestTestingPositionsInSample , returnsManagerForLastSecondPhaseInterval ); return inefficientCouples; } #region getInefficientCouplesFromArrayList private WeightedPositions[] getInefficientCouplesFromArrayList_actually( ArrayList arrayListOfInefficientCouples ) { WeightedPositions[] inefficientCouples = new WeightedPositions[ arrayListOfInefficientCouples.Count ]; for ( int i = 0 ; i < arrayListOfInefficientCouples.Count ; i++ ) inefficientCouples[ i ] = (WeightedPositions)arrayListOfInefficientCouples[ i ]; return inefficientCouples; } private WeightedPositions[] getInefficientCouplesFromArrayList( ArrayList arrayListOfInefficientCouples ) { WeightedPositions[] inefficientCouples = null; if ( arrayListOfInefficientCouples.Count > 0 ) // at least a couple was found, with an inefficiency in the range inefficientCouples = this.getInefficientCouplesFromArrayList_actually( arrayListOfInefficientCouples ); return inefficientCouples; } #endregion getInefficientCouplesFromArrayList private WeightedPositions[] getInefficientCouples_withAtLeastASecondPhaseInterval( TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , IHistoricalQuoteProvider historicalQuoteProviderForChosingPositionsOutOfSample ) { ArrayList arrayListOfInefficientCouples = this.getArrayListOfInefficientCouples( bestTestingPositionsInSample , outOfSampleReturnIntervals , historicalQuoteProviderForChosingPositionsOutOfSample ); WeightedPositions[] inefficientCouples = this.getInefficientCouplesFromArrayList( arrayListOfInefficientCouples ); return inefficientCouples; } // private WeightedPositions // getInfefficientCouples_withAtLeastASecondPhaseInterval( // TestingPositions[] bestTestingPositionsInSample , // ReturnIntervals outOfSampleReturnIntervals , // IHistoricalQuoteProvider // historicalQuoteProviderForChosingPositionsOutOfSample ) // { // WeightedPositions weightedPositions = // this.getPositionsToBeOpened_withAtLeastASecondPhaseInterval_actually( // bestTestingPositionsInSample , // outOfSampleReturnIntervals , // historicalQuoteProviderForChosingPositionsOutOfSample ); //// WeightedPositions weightedPositionsToBeReturned = null; //// if ( weightedPositions != null ) //// // at least one of the BestTestingPositions shows an inefficiency //// // above the threshold //// weightedPositionsToBeReturned = //// selectWeightedPositions( weightedPositions ); //// return weightedPositionsToBeReturned; // return weightedPositions; // } private WeightedPositions[] getInefficientCouples( TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , IHistoricalQuoteProvider historicalQuoteProviderForChosingPositionsOutOfSample ) { WeightedPositions[] inefficientCouples = null; if ( outOfSampleReturnIntervals.Count >= 2 ) // at least a second phase interval exists inefficientCouples = this.getInefficientCouples_withAtLeastASecondPhaseInterval( bestTestingPositionsInSample , outOfSampleReturnIntervals , historicalQuoteProviderForChosingPositionsOutOfSample ); return inefficientCouples; } #endregion getInefficientCouples /// <summary> /// Selects the WeghtedPositions to actually be opened /// </summary> /// <param name="bestTestingPositionsInSample">most correlated couples, /// in sample</param> /// <param name="outOfSampleReturnIntervals">return intervals for /// the current backtest</param> /// <param name="minThreshold">min requested inefficiency</param> /// <param name="maxThreshold">max allowed inefficiency</param> /// <param name="inSampleReturnsManager"></param> /// <returns></returns> public virtual WeightedPositions GetPositionsToBeOpened( TestingPositions[] bestTestingPositionsInSample , ReturnIntervals outOfSampleReturnIntervals , IHistoricalQuoteProvider historicalQuoteProviderForChosingPositionsOutOfSample , ReturnsManager inSampleReturnsManager ) { WeightedPositions positionsToBeOpened = null; WeightedPositions[] inefficientCouples = this.getInefficientCouples( bestTestingPositionsInSample , outOfSampleReturnIntervals , historicalQuoteProviderForChosingPositionsOutOfSample ); if ( inefficientCouples != null ) // at least an inefficient couple has been found positionsToBeOpened = this.getPositionsToBeOpened( inefficientCouples , inSampleReturnsManager ); return positionsToBeOpened; } #endregion GetPositionsToBeOpened #region getLongPositionTickers #region getArrayListOfLongPositionTickers private void checkParameters_forCurrentCouple( WeightedPositions inefficientCouple ) { if ( inefficientCouple.Count != 2 ) throw new Exception( "The method getLongPositionTickers() expects " + "an array of WeightedPositions, each of wich contains exactly " + "two positions!" ); } private void addPositionIfLong( WeightedPosition weightedPosition , Set alreadyAddedLongPositionTickers , ArrayList arrayListOfLongPositionTickers ) { if ( ( weightedPosition.IsLong ) && ( !alreadyAddedLongPositionTickers.Contains( weightedPosition.Ticker ) ) ) // the given weightedPosition is long and its ticker has not // yet been added to the set of tickers for long positions { arrayListOfLongPositionTickers.Add( weightedPosition.Ticker ); alreadyAddedLongPositionTickers.Add( weightedPosition.Ticker ); } } private void addLongPositions( WeightedPositions inefficientCouple , Set alreadyAddedLongPositionTickers , ArrayList arrayListOfLongPositionTickers ) { this.checkParameters_forCurrentCouple( inefficientCouple ); this.addPositionIfLong( inefficientCouple[ 0 ] , alreadyAddedLongPositionTickers , arrayListOfLongPositionTickers ); this.addPositionIfLong( inefficientCouple[ 1 ] , alreadyAddedLongPositionTickers , arrayListOfLongPositionTickers ); } private ArrayList getArrayListOfLongPositionTickers( WeightedPositions[] inefficientCouples ) { Set alreadyAddedLongPositionTickers = new Set(); ArrayList arrayListOfLongPositionTickers = new ArrayList(); foreach( WeightedPositions weightedPositions in inefficientCouples ) this.addLongPositions( weightedPositions , alreadyAddedLongPositionTickers , arrayListOfLongPositionTickers ); return arrayListOfLongPositionTickers; } #endregion getArrayListOfLongPositionTickers private string[] getLongPositionTickers( ArrayList arrayListOfLongPositionTickers ) { string[] longPositionTickers = new string[ arrayListOfLongPositionTickers.Count ]; for( int i = 0; i < arrayListOfLongPositionTickers.Count ; i++ ) longPositionTickers[ i ] = (string)arrayListOfLongPositionTickers[ i ]; return longPositionTickers; } /// <summary> /// returns a set of tickers for long positions in the /// inefficient couples /// </summary> /// <param name="inefficientCouples"></param> /// <returns></returns> protected string[] getLongPositionTickers( WeightedPositions[] inefficientCouples ) { ArrayList arrayListOfLongPositionTickers = this.getArrayListOfLongPositionTickers( inefficientCouples ); string[] longPositionTickers = this.getLongPositionTickers( arrayListOfLongPositionTickers ); return longPositionTickers; } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2008-04-27 17:42:13
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17118/OutOfSampleChoosers Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/OutOfSampleChoosers added to the repository |
|
From: Glauco S. <gla...@us...> - 2008-04-27 17:40:18
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv15772/b7_Scripts/WalkForwardTesting/PairsTrading/Strategies Removed Files: LongOnlyPairsTradingStrategy.cs Log Message: It has been replaced by WalkForwardTesting\PairsTrading\OutOfSampleChoosers\OutOfSampleChooserForExactNumberOfBestLongPositions.cs Now a single strategy is used, with an OutOfSampleChooser given as a parameter --- LongOnlyPairsTradingStrategy.cs DELETED --- |
|
From: Glauco S. <gla...@us...> - 2008-04-27 17:36:59
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13324/b1_ADT Modified Files: b1_ADT.csproj Log Message: Collections\StringArrayManager.cs has been added Index: b1_ADT.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/b1_ADT.csproj,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** b1_ADT.csproj 30 Mar 2008 15:21:30 -0000 1.30 --- b1_ADT.csproj 27 Apr 2008 17:36:54 -0000 1.31 *************** *** 183,186 **** --- 183,191 ---- /> <File + RelPath = "Collections\StringArrayManager.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "FileManaging\ObjectArchiver.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2008-04-27 17:33:34
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Collections In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv11779/b1_ADT/Collections Added Files: StringArrayManager.cs Log Message: This class provides methods to manage arrays of string --- NEW FILE: StringArrayManager.cs --- /* QuantProject - Quantitative Finance Library StringArrayManager.cs Copyright (C) 2008 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; namespace QuantProject.ADT.Collections { /// <summary> /// This class provides methods to manage arrays of string /// </summary> public class StringArrayManager { public StringArrayManager() { // // TODO: Add constructor logic here // } #region SubArray private static void subArray_checkParameters( string[] arrayOfString , int firstPosition , int numberOfElementsToBeSelected ) { if ( firstPosition < 0 ) throw new Exception( "firstPosition is less than zero!" ); if ( firstPosition >= arrayOfString.Length ) throw new Exception( "firstPosition is >= than arrayOfInt.Length!" ); if ( numberOfElementsToBeSelected < 0 ) throw new Exception( "numberOfElementsToBeSelected is less than zero!" ); if ( firstPosition + numberOfElementsToBeSelected > arrayOfString.Length ) throw new Exception( "firstPosition + numberOfElementsToBeSelected is >= arrayOfInt.Length !!" ); } /// <summary> /// Returns a subarray of arrayOfString /// </summary> /// <param name="arrayOfString"></param> /// <param name="firstPosition"></param> /// <param name="numberOfElementsToBeSelected"></param> /// <returns></returns> public static string[] SubArray( string[] arrayOfString , int firstPosition , int numberOfElementsToBeSelected ) { subArray_checkParameters( arrayOfString , firstPosition , numberOfElementsToBeSelected ); string[] subArray = new string[ numberOfElementsToBeSelected ]; for ( int i = 0 ; i < numberOfElementsToBeSelected ; i++ ) { int currentPosition = firstPosition + i; subArray[ i ] = arrayOfString[ currentPosition ]; } return subArray; } #endregion SubArray } } |
|
From: Marco M. <mi...@us...> - 2008-04-26 09:57:05
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2111/b7_Scripts Modified Files: b7_Scripts.csproj Scripts_SD.csproj Log Message: Updated sharpeDevelop and VS net project's files Index: Scripts_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts_SD.csproj,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Scripts_SD.csproj 20 Apr 2008 17:15:54 -0000 1.24 --- Scripts_SD.csproj 26 Apr 2008 09:57:00 -0000 1.25 *************** *** 75,78 **** --- 75,79 ---- <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_CTCCorrelationChooser.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_OTCCorrelationChooser.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_OTCCTOCorrelationChooser.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenomeManager.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOLogItem.cs" /> *************** *** 84,87 **** --- 85,89 ---- <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCMain.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCStrategy.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCStrategyLessCorrelated.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\EndOfDayTimerHandlerWeightedPVO.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\GenomeManagerWeightedPVO.cs" /> *************** *** 114,118 **** <Compile Include="WalkForwardTesting\PairsTrading\Logging\TesterForPairsTradingTestingPositions.cs" /> <Compile Include="WalkForwardTesting\PairsTrading\PairsTradingMain.cs" /> - <Compile Include="WalkForwardTesting\PairsTrading\PairsTradingStrategy.cs" /> <Compile Include="WalkForwardTesting\PairsTrading\PairsTradingTestingPositions.cs" /> <Compile Include="WalkForwardTesting\PairsTrading\Strategies\PairsTradingStrategy.cs" /> --- 116,119 ---- Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** b7_Scripts.csproj 20 Apr 2008 16:35:59 -0000 1.94 --- b7_Scripts.csproj 26 Apr 2008 09:57:00 -0000 1.95 *************** *** 355,358 **** --- 355,363 ---- /> <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCStrategyLessCorrelated.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenomeManager.cs" SubType = "Code" *************** *** 430,433 **** --- 435,443 ---- /> <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_OTCCTOCorrelationChooser.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOChooserFromSavedBackTestLog.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2008-04-26 09:57:05
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2111/b4_Business Modified Files: b4_Business.csproj Business_SD.csproj Log Message: Updated sharpeDevelop and VS net project's files Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Business_SD.csproj 20 Apr 2008 17:13:27 -0000 1.23 --- Business_SD.csproj 26 Apr 2008 09:57:00 -0000 1.24 *************** *** 64,71 **** <Compile Include="a1_Financial\a2_Accounting\AccountProviding\InteractiveBrokerAccountProvider.cs" /> <Compile Include="a1_Financial\a2_Accounting\AccountProviding\SimpleAccountProvider.cs" /> ! <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnMonday.cs" /> <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\SummaryRows\AverageNumberOfTransactionsPerDay.cs" /> <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\Tables\StatisticsSummary.cs" /> <Compile Include="a2_Strategies\Benchmark.cs" /> <Compile Include="a2_Strategies\Eligibles\DummyEligibleSelector.cs" /> <Compile Include="a2_Strategies\Eligibles\ByPriceMostLiquidAlwaysQuoted.cs" /> --- 64,78 ---- <Compile Include="a1_Financial\a2_Accounting\AccountProviding\InteractiveBrokerAccountProvider.cs" /> <Compile Include="a1_Financial\a2_Accounting\AccountProviding\SimpleAccountProvider.cs" /> ! <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnDayOfWeekWithOpenPositions.cs" /> ! <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnDayWithOpenPositions.cs" /> ! <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnFridayWithOpenPositions.cs" /> ! <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnMondayWithOpenPositions.cs" /> ! <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnThursdayWithOpenPositions.cs" /> ! <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnTuesdayWithOpenPositions.cs" /> ! <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnWednesdayWithOpenPositions.cs" /> <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\SummaryRows\AverageNumberOfTransactionsPerDay.cs" /> <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\Tables\StatisticsSummary.cs" /> <Compile Include="a2_Strategies\Benchmark.cs" /> + <Compile Include="a2_Strategies\Eligibles\ByPriceLessVolatileOTCAlwaysQuoted.cs" /> <Compile Include="a2_Strategies\Eligibles\DummyEligibleSelector.cs" /> <Compile Include="a2_Strategies\Eligibles\ByPriceMostLiquidAlwaysQuoted.cs" /> *************** *** 103,106 **** --- 110,114 ---- <Compile Include="a2_Strategies\returnsManagement\time\CloseToOpenIntervals.cs" /> <Compile Include="a2_Strategies\returnsManagement\time\DailyOpenToCloseIntervals.cs" /> + <Compile Include="a2_Strategies\returnsManagement\time\IntervalsType.cs" /> <Compile Include="a2_Strategies\returnsManagement\time\OpenToCloseCloseToOpenIntervals.cs" /> <Compile Include="a2_Strategies\returnsManagement\time\ReturnInterval.cs" /> *************** *** 112,115 **** --- 120,124 ---- <Compile Include="a2_Strategies\TickersRelationships\CorrelationProvider.cs" /> <Compile Include="a2_Strategies\TickersRelationships\MissingCorrelationException.cs" /> + <Compile Include="a2_Strategies\TickersRelationships\OpenToCloseCloseToOpenCorrelationProvider.cs" /> <Compile Include="a2_Strategies\TickersRelationships\OpenToCloseCorrelationProvider.cs" /> <Compile Include="a2_Strategies\TickersRelationships\TickersPearsonCorrelation.cs" /> Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** b4_Business.csproj 13 Apr 2008 16:24:16 -0000 1.65 --- b4_Business.csproj 26 Apr 2008 09:56:59 -0000 1.66 *************** *** 380,384 **** /> <File ! RelPath = "a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnMonday.cs" SubType = "Code" BuildAction = "Compile" --- 380,414 ---- /> <File ! RelPath = "a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnDayOfWeekWithOpenPositions.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnDayWithOpenPositions.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnFridayWithOpenPositions.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnMondayWithOpenPositions.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnThursdayWithOpenPositions.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnTuesdayWithOpenPositions.cs" ! SubType = "Code" ! BuildAction = "Compile" ! /> ! <File ! RelPath = "a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnWednesdayWithOpenPositions.cs" SubType = "Code" BuildAction = "Compile" *************** *** 700,703 **** --- 730,738 ---- /> <File + RelPath = "a2_Strategies\Eligibles\ByPriceLessVolatileOTCAlwaysQuoted.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a2_Strategies\Eligibles\ByPriceMostLiquidAlwaysQuoted.cs" SubType = "Code" *************** *** 890,893 **** --- 925,933 ---- /> <File + RelPath = "a2_Strategies\returnsManagement\time\IntervalsType.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a2_Strategies\returnsManagement\time\OpenToCloseCloseToOpenIntervals.cs" SubType = "Code" *************** *** 935,938 **** --- 975,983 ---- /> <File + RelPath = "a2_Strategies\TickersRelationships\OpenToCloseCloseToOpenCorrelationProvider.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a2_Strategies\TickersRelationships\OpenToCloseCorrelationProvider.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2008-04-26 09:53:57
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv815/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVO_OTCMain.cs Log Message: Updated the main file for the PVO_OTC strategy Index: PVO_OTCMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCMain.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PVO_OTCMain.cs 13 Apr 2008 17:10:07 -0000 1.4 --- PVO_OTCMain.cs 26 Apr 2008 09:53:54 -0000 1.5 *************** *** 86,101 **** bool temporizedGroup = true; ! int numDaysForAverageRawOpenPriceComputation = 20; ! double minPrice = 20; ! double maxPrice = 7000; IEligiblesSelector eligiblesSelector = ! new ByPriceMostLiquidAlwaysQuoted( tickersGroupId , temporizedGroup , maxNumberOfEligiblesToBeChosen , numDaysForAverageRawOpenPriceComputation , minPrice , maxPrice ); ! eligiblesSelector = ! new DummyEligibleSelector(); return eligiblesSelector; } --- 86,108 ---- bool temporizedGroup = true; ! int numDaysForAverageRawOpenPriceComputation = 10; ! double minPrice = 30; ! double maxPrice = 75; + // IEligiblesSelector eligiblesSelector = + // new ByPriceMostLiquidAlwaysQuoted( + // tickersGroupId , temporizedGroup , + // maxNumberOfEligiblesToBeChosen , + // numDaysForAverageRawOpenPriceComputation , + // minPrice , maxPrice ); IEligiblesSelector eligiblesSelector = ! new ByPriceLessVolatileOTCAlwaysQuoted( tickersGroupId , temporizedGroup , maxNumberOfEligiblesToBeChosen , numDaysForAverageRawOpenPriceComputation , minPrice , maxPrice ); ! // eligiblesSelector = ! // new DummyEligibleSelector(); ! return eligiblesSelector; } *************** *** 116,120 **** double maxCorrelationAllowed = 0.96; ! int numberOfBestTestingPositionsToBeReturned = 10; bool balancedWeightsOnVolatilityBase = true; float minimumAbsoluteReturnValue = 0.000001f; --- 123,128 ---- double maxCorrelationAllowed = 0.96; ! int numberOfBestTestingPositionsToBeReturned = 200; ! numberOfBestTestingPositionsToBeReturned = 200; bool balancedWeightsOnVolatilityBase = true; float minimumAbsoluteReturnValue = 0.000001f; *************** *** 126,132 **** maxCorrelationAllowed , balancedWeightsOnVolatilityBase, minimumAbsoluteReturnValue , maximumAbsoluteReturnValue); ! inSampleChooser = ! new PVOChooserFromSavedBackTestLog( ! @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2008_04_07_12_17_18_PVO_OTC_from_2001_01_01_to_2001_03_31_annlRtrn_232,37_maxDD_5,04\2008_04_07_12_17_18_PVO_OTC_from_2001_01_01_to_2001_03_31_annlRtrn_232,37_maxDD_5,04.qpL"); return inSampleChooser; } --- 134,151 ---- maxCorrelationAllowed , balancedWeightsOnVolatilityBase, minimumAbsoluteReturnValue , maximumAbsoluteReturnValue); ! // IInSampleChooser inSampleChooser = ! // new PVO_OTCCTOCorrelationChooser(numberOfBestTestingPositionsToBeReturned, ! // maxCorrelationAllowed , balancedWeightsOnVolatilityBase, ! // minimumAbsoluteReturnValue , maximumAbsoluteReturnValue); ! // //office ! // inSampleChooser = ! // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2008_04_14_18_21_45_PVO_OTC_from_2001_01_01_to_2004_12_31_annlRtrn_182,80_maxDD_8,57\2008_04_14_18_21_45_PVO_OTC_from_2001_01_01_to_2004_12_31_annlRtrn_182,80_maxDD_8,57.qpL", ! // numberOfBestTestingPositionsToBeReturned); ! //home ! // inSampleChooser = ! // new PVOChooserFromSavedBackTestLog( ! // @"C:\Utente\MarcoVarie\Vari\qP\LogArchive\2008_04_13_12_03_16_PVO_OTC_from_2001_01_01_to_2004_12_31_annlRtrn_183.39_maxDD_8.71\2008_04_13_12_03_16_PVO_OTC_from_2001_01_01_to_2004_12_31_annlRtrn_183.39_maxDD_8.71.qpL", ! // numberOfBestTestingPositionsToBeReturned); return inSampleChooser; } *************** *** 137,147 **** // uncomment the following line for a faster script //inSampleDays = 50; ! int numDaysBetweenEachOptimization = 7; ! double oversoldThreshold = 0.006; ! double overboughtThreshold = 0.006; ! IEndOfDayStrategyForBacktester endOfDayStrategy = ! new PVO_OTCStrategy(eligiblesSelector ,inSampleChooser , inSampleDays , benchmark , numDaysBetweenEachOptimization , ! oversoldThreshold , overboughtThreshold , historicalQuoteProvider); return endOfDayStrategy; } --- 156,171 ---- // uncomment the following line for a faster script //inSampleDays = 50; ! int numDaysBetweenEachOptimization = 5; ! int numOfClosingsBeforeExit = 0; ! double oversoldThreshold = 0.01; ! double overboughtThreshold = 0.01; ! IEndOfDayStrategyForBacktester endOfDayStrategy ! // = new PVO_OTCStrategyLessCorrelated(eligiblesSelector ,inSampleChooser , ! // inSampleDays , benchmark , numDaysBetweenEachOptimization , ! // oversoldThreshold , overboughtThreshold , historicalQuoteProvider); ! // ! = new PVO_OTCStrategy(eligiblesSelector ,inSampleChooser , inSampleDays , benchmark , numDaysBetweenEachOptimization , ! numOfClosingsBeforeExit, oversoldThreshold , overboughtThreshold , historicalQuoteProvider); return endOfDayStrategy; } *************** *** 153,163 **** DateTime firstDateTime = new DateTime( 2001 , 1 , 1 ); ! DateTime lastDateTime = new DateTime( 2001 , 3, 31 ); ! double maxRunningHours = 3; ! EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( backTestId , this.endOfDayStrategy , ! historicalQuoteProvider , accountProvider , firstDateTime , lastDateTime , this.benchmark , cashToStart , maxRunningHours ); --- 177,190 ---- DateTime firstDateTime = new DateTime( 2001 , 1 , 1 ); ! DateTime lastDateTime = new DateTime( 2004 , 12, 31 ); ! double maxRunningHours = 10; ! HistoricalQuoteProvider quoteProviderForBackTester = ! this.historicalQuoteProvider; ! quoteProviderForBackTester = ! new HistoricalRawQuoteProvider(); EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( backTestId , this.endOfDayStrategy , ! quoteProviderForBackTester , accountProvider , firstDateTime , lastDateTime , this.benchmark , cashToStart , maxRunningHours ); |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv788/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers Modified Files: PVO_CTCCorrelationChooser.cs PVO_OTCCorrelationChooser.cs Log Message: IntervalsType property is now used Index: PVO_OTCCorrelationChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVO_OTCCorrelationChooser.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PVO_OTCCorrelationChooser.cs 8 Apr 2008 21:53:03 -0000 1.2 --- PVO_OTCCorrelationChooser.cs 26 Apr 2008 09:53:14 -0000 1.3 *************** *** 30,33 **** --- 30,34 ---- using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; + using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; *************** *** 64,68 **** 1, maxCorrelationValue, ! balancedWeightsOnVolatilityBase) { this.minimumAbsoluteReturnValue = minimumAbsoluteReturnValue; --- 65,70 ---- 1, maxCorrelationValue, ! balancedWeightsOnVolatilityBase, ! IntervalsType.DailyOpenToCloseIntervals) { this.minimumAbsoluteReturnValue = minimumAbsoluteReturnValue; Index: PVO_CTCCorrelationChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVO_CTCCorrelationChooser.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PVO_CTCCorrelationChooser.cs 8 Apr 2008 21:53:03 -0000 1.2 --- PVO_CTCCorrelationChooser.cs 26 Apr 2008 09:53:14 -0000 1.3 *************** *** 30,33 **** --- 30,34 ---- using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; + using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; *************** *** 58,62 **** closeToCloseReturnIntervalLength, maxCorrelationValue, ! balancedWeightsOnVolatilityBase) { --- 59,64 ---- closeToCloseReturnIntervalLength, maxCorrelationValue, ! balancedWeightsOnVolatilityBase, ! IntervalsType.CloseToCloseIntervals_OneDay) { |
|
From: Marco M. <mi...@us...> - 2008-04-26 09:52:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv383/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVO_OTCLogItem.cs Log Message: A new parameter is needed for the PVO_OTCStrategy Index: PVO_OTCLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCLogItem.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PVO_OTCLogItem.cs 8 Apr 2008 21:58:24 -0000 1.2 --- PVO_OTCLogItem.cs 26 Apr 2008 09:52:44 -0000 1.3 *************** *** 88,91 **** --- 88,92 ---- benchmark , int.MaxValue , + 0 , ((PVOPositions)positionsToTest[0]).OversoldThreshold, ((PVOPositions)positionsToTest[0]).OverboughtThreshold, |
|
From: Marco M. <mi...@us...> - 2008-04-26 09:51:27
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32398/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: PVO_OTCStrategy.cs Log Message: The updateReturnsManager method's implementation now depends on ReturnIntervalsType property. It is now possible to choose how many MarketClosings are to be crossed before closing all positions. Index: PVO_OTCStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVO_OTCStrategy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PVO_OTCStrategy.cs 8 Apr 2008 22:03:00 -0000 1.3 --- PVO_OTCStrategy.cs 26 Apr 2008 09:51:23 -0000 1.4 *************** *** 45,48 **** --- 45,49 ---- using QuantProject.Data.DataTables; using QuantProject.ADT.Optimizing.Genetic; + using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; *************** *** 85,89 **** set { this.account = value; } } ! private string description_GetDescriptionForChooser() { --- 86,92 ---- set { this.account = value; } } ! private int numOfClosingsToCrossBeforeExit; ! private int numOfClosingsWithOpenPositions; ! private string description_GetDescriptionForChooser() { *************** *** 123,134 **** --- 126,140 ---- Benchmark benchmark, int numDaysBetweenEachOptimization, + int numOfClosingsToCrossBeforeExit, double oversoldThreshold, double overboughtThreshold, HistoricalQuoteProvider historicalQuoteProvider) { + this.numOfClosingsWithOpenPositions = 0; this.eligiblesSelector = eligiblesSelector; this.inSampleDays = inSampleDays; this.benchmark = benchmark; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; + this.numOfClosingsToCrossBeforeExit = numOfClosingsToCrossBeforeExit; this.oversoldThreshold = oversoldThreshold; this.overboughtThreshold = overboughtThreshold; *************** *** 141,144 **** --- 147,151 ---- Benchmark benchmark, int numDaysBetweenEachOptimization, + int numOfClosingsToCrossBeforeExit, double oversoldThreshold, double overboughtThreshold, *************** *** 147,151 **** { this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , ! oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.inSampleChooser = inSampleChooser; --- 154,158 ---- { this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , ! numOfClosingsToCrossBeforeExit, oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.inSampleChooser = inSampleChooser; *************** *** 157,160 **** --- 164,168 ---- Benchmark benchmark, int numDaysBetweenEachOptimization, + int numOfClosingsToCrossBeforeExit, double oversoldThreshold, double overboughtThreshold, *************** *** 163,167 **** { this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , ! oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.chosenPVOPositions = chosenPVOPositions; } --- 171,175 ---- { this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , ! numOfClosingsToCrossBeforeExit, oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.chosenPVOPositions = chosenPVOPositions; } *************** *** 278,282 **** { if(this.account.Portfolio.Count > 0) ! AccountManager.ClosePositions(this.account); } --- 286,297 ---- { if(this.account.Portfolio.Count > 0) ! { ! this.numOfClosingsWithOpenPositions++; ! if(this.numOfClosingsWithOpenPositions > this.numOfClosingsToCrossBeforeExit) ! { ! AccountManager.ClosePositions(this.account); ! this.numOfClosingsWithOpenPositions = 0; ! } ! } } *************** *** 286,293 **** EndOfDayDateTime lastEndOfDayDateTime) { ! this.returnsManager = ! new ReturnsManager( new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker ) , ! this.historicalQuoteProvider); } --- 301,346 ---- EndOfDayDateTime lastEndOfDayDateTime) { ! ReturnIntervals returnIntervals = ! new DailyOpenToCloseIntervals( firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker ); ! if( this.inSampleChooser is PVOCorrelationChooser ) ! { ! switch ( ((PVOCorrelationChooser)this.inSampleChooser).IntervalsType ) ! { ! case IntervalsType.CloseToCloseIntervals_OneDay: ! returnIntervals = new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker, 1); ! break; ! case IntervalsType.CloseToCloseIntervals_TwoDays: ! returnIntervals = new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker, 2); ! break; ! case IntervalsType.CloseToCloseIntervals_FiveDays: ! returnIntervals = new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker, 5); ! break; ! case IntervalsType.CloseToOpenIntervals: ! returnIntervals = new CloseToOpenIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker); ! break; ! case IntervalsType.DailyOpenToCloseIntervals: ! returnIntervals = new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker ); ! break; ! case IntervalsType.OpenToCloseCloseToOpenIntervals: ! returnIntervals = new OpenToCloseCloseToOpenIntervals( ! firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker); ! break; ! default: ! // it should never be reached ! returnIntervals = new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, ! this.benchmark.Ticker ); ! break; ! } ! } ! ! this.returnsManager = ! new ReturnsManager( returnIntervals , this.historicalQuoteProvider); ! } |
|
From: Marco M. <mi...@us...> - 2008-04-26 09:45:03
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv29299/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers Modified Files: PVOChooserFromSavedBackTestLog.cs Log Message: The chooser now makes possible to select the number of testingPositions you like (if this number is not greater than the testingPositions saved in each logItem of the backTestLog) Index: PVOChooserFromSavedBackTestLog.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVOChooserFromSavedBackTestLog.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVOChooserFromSavedBackTestLog.cs 8 Apr 2008 21:33:23 -0000 1.1 --- PVOChooserFromSavedBackTestLog.cs 26 Apr 2008 09:44:58 -0000 1.2 *************** *** 48,54 **** public PVOChooserFromSavedBackTestLog( ! string backTestLogFullPath) ! : base(backTestLogFullPath) { } --- 48,59 ---- public PVOChooserFromSavedBackTestLog( ! string backTestLogFullPath, int numberOfBestTestingPositionsToBeReturned) ! : base(backTestLogFullPath , numberOfBestTestingPositionsToBeReturned) { + int maxNumberOfTestingPositionsFromBackTestLogItems = + ((PVOLogItem)this.backTestLog[0]).BestPVOPositionsInSample.Length; + if(numberOfBestTestingPositionsToBeReturned > maxNumberOfTestingPositionsFromBackTestLogItems) + throw new Exception("Number of TestingPositions to be returned " + + "is too high for the given BackTestLog"); } *************** *** 56,66 **** { TestingPositions[] testingPositions = ! new TestingPositions[((PVOLogItem)this.backTestLog[0]).BestPVOPositionsInSample.Length]; ! for( int i = 0; i<this.backTestLog.Count ; i++ ) { if( this.backTestLog[i].SimulatedCreationTime.DateTime == lastInSampleDateOfOptimizedTestingPositions.DateTime ) { ! testingPositions = ((PVOLogItem)this.backTestLog[i]).BestPVOPositionsInSample; i = this.backTestLog.Count; } --- 61,74 ---- { TestingPositions[] testingPositions = ! new TestingPositions[this.numberOfBestTestingPositionsToBeReturned]; ! for( int i = 0; ! i < this.backTestLog.Count; ! i++ ) { if( this.backTestLog[i].SimulatedCreationTime.DateTime == lastInSampleDateOfOptimizedTestingPositions.DateTime ) { ! Array.Copy( ((PVOLogItem)this.backTestLog[i]).BestPVOPositionsInSample , ! 0, testingPositions, 0, numberOfBestTestingPositionsToBeReturned ); i = this.backTestLog.Count; } |
|
From: Marco M. <mi...@us...> - 2008-04-26 09:41:32
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv27862/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers Modified Files: PVOCorrelationChooser.cs Log Message: Added property IntervalsType; other minor changes. Index: PVOCorrelationChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVOCorrelationChooser.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PVOCorrelationChooser.cs 8 Apr 2008 21:53:06 -0000 1.4 --- PVOCorrelationChooser.cs 26 Apr 2008 09:41:26 -0000 1.5 *************** *** 31,34 **** --- 31,35 ---- using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; + using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.OutOfSample; *************** *** 52,55 **** --- 53,57 ---- //correlations greater than this value are discarded protected bool balancedWeightsOnVolatilityBase; + protected IntervalsType intervalsType; public virtual string Description *************** *** 68,71 **** --- 70,81 ---- } + public IntervalsType IntervalsType + { + get + { + return this.intervalsType; + } + } + /// <summary> /// PVOCorrelationChooser to be used for *************** *** 88,92 **** int numDaysForOscillatingPeriod, double maxCorrelationValue, ! bool balancedWeightsOnVolatilityBase) { this.numberOfBestTestingPositionsToBeReturned = numberOfBestTestingPositionsToBeReturned; --- 98,103 ---- int numDaysForOscillatingPeriod, double maxCorrelationValue, ! bool balancedWeightsOnVolatilityBase, ! IntervalsType intervalsType) { this.numberOfBestTestingPositionsToBeReturned = numberOfBestTestingPositionsToBeReturned; *************** *** 94,97 **** --- 105,109 ---- this.maxCorrelationValue = maxCorrelationValue; this.balancedWeightsOnVolatilityBase = balancedWeightsOnVolatilityBase; + this.intervalsType = intervalsType; } *************** *** 105,110 **** "only " + eligibleTickers.Count + " elements, while NumberOfDrivingPositions is 2"); ! if (this.maxCorrelationValue < 0.50 || this.maxCorrelationValue > 1.0 ) ! throw new OutOfRangeException( "maxCorrelationValue", 0.5, 1.0); } --- 117,122 ---- "only " + eligibleTickers.Count + " elements, while NumberOfDrivingPositions is 2"); ! if (this.maxCorrelationValue < 0.0 || this.maxCorrelationValue > 1.0 ) ! throw new OutOfRangeException( "maxCorrelationValue", 0.0, 1.0); } |
|
From: Marco M. <mi...@us...> - 2008-04-26 09:17:51
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16154/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers Added Files: PVO_OTCCTOCorrelationChooser.cs Log Message: Added PVO_OTCCTOCorrelationChooser: this chooser selects tickers with the highest correlation of open to close - close to open returns --- NEW FILE: PVO_OTCCTOCorrelationChooser.cs --- /* QuantProject - Quantitative Finance Library PVO_OTCCTOCorrelationChooser.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Messaging; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers { /// <summary> /// PVO_OTCCTOCorrelationChooser to be used for /// in sample optimization /// By means of correlation, the AnalyzeInSample method returns the /// requested number of PVOPositions (positions for the PVO strategy) /// </summary> public class PVO_OTCCTOCorrelationChooser : PVOCorrelationChooser { private float minimumAbsoluteReturnValue; private float maximumAbsoluteReturnValue; //correlation is computed only for returns //between minimum and maximum /// <summary> /// PVO_OTCCorrelationChooser to be used for /// in sample optimization /// </summary> /// <param name="numberOfBestTestingPositionsToBeReturned"> /// The number of PVOPositions that the /// AnalyzeInSample method will return /// </param> public PVO_OTCCTOCorrelationChooser(int numberOfBestTestingPositionsToBeReturned, double maxCorrelationValue, bool balancedWeightsOnVolatilityBase, float minimumAbsoluteReturnValue, float maximumAbsoluteReturnValue) : base(numberOfBestTestingPositionsToBeReturned, 1, maxCorrelationValue, balancedWeightsOnVolatilityBase, IntervalsType.OpenToCloseCloseToOpenIntervals) { this.minimumAbsoluteReturnValue = minimumAbsoluteReturnValue; this.maximumAbsoluteReturnValue = maximumAbsoluteReturnValue; } protected override void setCorrelationProvider(EligibleTickers eligibleTickers , ReturnsManager returnsManager) { this.correlationProvider = new OpenToCloseCloseToOpenCorrelationProvider(eligibleTickers.Tickers, returnsManager, this.minimumAbsoluteReturnValue , this.maximumAbsoluteReturnValue); } } } |
|
From: Marco M. <mi...@us...> - 2008-04-26 09:13:17
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv14258/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Added Files: PVO_OTCStrategyLessCorrelated.cs Log Message: Added PVO_OTCStrategyLessCorrelated: it is the PVO OTC strategy with less correlated tickers (just for testing) --- NEW FILE: PVO_OTCStrategyLessCorrelated.cs --- /* QuantProject - Quantitative Finance Library PVO_OTCStrategyLessCorrelated.cs Copyright (C) 2008 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.Messaging; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Data; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Implements MarketOpenEventHandler and MarketCloseEventHandler /// These handlers contain the core strategy for the Portfolio Value /// Oscillator /// </summary> [Serializable] public class PVO_OTCStrategyLessCorrelated : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; public event NewMessageEventHandler NewMessage; //initialized by the constructor protected int inSampleDays; protected int numDaysBetweenEachOptimization; protected IInSampleChooser inSampleChooser; protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; protected HistoricalQuoteProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; //initialized after constructor's call protected int numDaysElapsedSinceLastOptimization; protected ReturnsManager returnsManager; protected TestingPositions[] chosenPVOPositions; //chosen in sample: these are the eligible positions for out //of sample testing protected PVOPositions pvoPositionsForOutOfSample; protected DateTime lastCloseDate; protected DateTime lastOptimizationDateTime; protected Account account; public Account Account { get { return this.account; } set { this.account = value; } } private string description_GetDescriptionForChooser() { if(this.inSampleChooser == null) return "ConstantChooser"; else return this.inSampleChooser.Description; } public string Description { get { string description = "PVO_OTC\n" + "Tickers_" + "2\n" + "_inSampleDays_" + this.inSampleDays.ToString() + "\n" + this.eligiblesSelector.Description + "\n" + "oversoldThreshold_" + this.oversoldThreshold.ToString() + "\n" + "overboughtThreshold_" + this.overboughtThreshold.ToString() + "\n" + this.description_GetDescriptionForChooser() + "\n" + "Optimization each " + this.numDaysBetweenEachOptimization.ToString() + " days"; return description; } } public bool StopBacktestIfMaxRunningHoursHasBeenReached { get { return true; } } private void pvo_otcStrategy(IEligiblesSelector eligiblesSelector, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, HistoricalQuoteProvider historicalQuoteProvider) { this.eligiblesSelector = eligiblesSelector; this.inSampleDays = inSampleDays; this.benchmark = benchmark; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.oversoldThreshold = oversoldThreshold; this.overboughtThreshold = overboughtThreshold; this.historicalQuoteProvider = historicalQuoteProvider; } public PVO_OTCStrategyLessCorrelated(IEligiblesSelector eligiblesSelector, IInSampleChooser inSampleChooser, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, HistoricalQuoteProvider historicalQuoteProvider) { this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.inSampleChooser = inSampleChooser; } public PVO_OTCStrategyLessCorrelated(IEligiblesSelector eligiblesSelector, TestingPositions[] chosenPVOPositions, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, HistoricalQuoteProvider historicalQuoteProvider) { this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.chosenPVOPositions = chosenPVOPositions; } #region MarketOpenEventHandler protected virtual EndOfDayDateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { EndOfDayDateTime today = timer.GetCurrentTime(); EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = PVOPositionsStatus.InTheMiddle; for(int i = 0; i<this.chosenPVOPositions.Length; i++) { if(this.chosenPVOPositions[i] != null) currentStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, this.benchmark.Ticker, this.historicalQuoteProvider); if(currentStatus == PVOPositionsStatus.Oversold || currentStatus == PVOPositionsStatus.Overbought ) { this.pvoPositionsForOutOfSample = (PVOPositions)this.chosenPVOPositions[i]; i = this.chosenPVOPositions.Length;//exit from for } } return currentStatus; } protected void marketOpenEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { PVOPositionsStatus pvoPositionsStatus = PVOPositionsStatus.InTheMiddle; if(timer.CurrentDateArrayPosition >= 1) pvoPositionsStatus = this.marketOpenEventHandler_openPositions_getStatus(timer); switch (pvoPositionsStatus) { case PVOPositionsStatus.Overbought: { #region manage Overbought case this.pvoPositionsForOutOfSample.WeightedPositions.Reverse(); try { AccountManager.OpenPositions( this.pvoPositionsForOutOfSample.WeightedPositions, this.account ); } catch(Exception ex) { ex = ex; } finally { this.pvoPositionsForOutOfSample.WeightedPositions.Reverse(); } #endregion break; } case PVOPositionsStatus.Oversold: { AccountManager.OpenPositions( this.pvoPositionsForOutOfSample.WeightedPositions, this.account ); break; } case PVOPositionsStatus.InTheMiddle://that is { //pvoPositionsForOutOfSample has not been set break; } default: { //it should never been reached break; } } } public virtual void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Portfolio.Count == 0 && this.chosenPVOPositions != null ) //portfolio is empty and optimization has //been already launched { try{ this.marketOpenEventHandler_openPositions( (IndexBasedEndOfDayTimer)sender ); } catch(TickerNotExchangedException ex) {ex=ex;} } } #endregion public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } private EndOfDayDateTime now() { return this.account.EndOfDayTimer.GetCurrentTime(); } public virtual void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) AccountManager.ClosePositions(this.account); } #region OneHourAfterMarketCloseEventHandler protected virtual void updateReturnsManager(EndOfDayDateTime firstEndOfDayDateTime, EndOfDayDateTime lastEndOfDayDateTime) { this.returnsManager = new ReturnsManager( new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ) , this.historicalQuoteProvider); } private PVO_OTCLogItem getLogItem( EligibleTickers eligibleTickers ) { PVO_OTCLogItem logItem = new PVO_OTCLogItem( this.now() , this.inSampleDays ); logItem.BestPVOPositionsInSample = this.chosenPVOPositions; logItem.NumberOfEligibleTickers = eligibleTickers.Count; logItem.FitnessOfFirst = this.chosenPVOPositions[0].FitnessInSample; logItem.FitnessOfLast = this.chosenPVOPositions[this.chosenPVOPositions.Length - 1].FitnessInSample; // logItem.GenerationOfFirst = // ((IGeneticallyOptimizable)this.chosenPVOPositions[0]).Generation; // logItem.GenerationOfLast = // ((IGeneticallyOptimizable)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).Generation; logItem.ThresholdsOfFirst = ((PVOPositions)this.chosenPVOPositions[0]).OversoldThreshold.ToString() + ";" + ((PVOPositions)this.chosenPVOPositions[0]).OverboughtThreshold.ToString(); logItem.ThresholdsOfLast = ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OversoldThreshold.ToString() + ";" + ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OverboughtThreshold.ToString(); logItem.TickersOfFirst = this.chosenPVOPositions[0].HashCodeForTickerComposition; logItem.TickersOfLast = this.chosenPVOPositions[this.chosenPVOPositions.Length - 1].HashCodeForTickerComposition; return logItem; } private void raiseNewLogItem( EligibleTickers eligibleTickers ) { PVO_OTCLogItem logItem = this.getLogItem( eligibleTickers ); NewLogItemEventArgs newLogItemEventArgs = new NewLogItemEventArgs( logItem ); this.NewLogItem( this , newLogItemEventArgs ); } private void notifyMessage( EligibleTickers eligibleTickers ) { string message = "Number of Eligible tickers: " + eligibleTickers.Count; NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if ( this.NewMessage != null ) this.NewMessage( this , newMessageEventArgs ); } private void logOptimizationInfo( EligibleTickers eligibleTickers ) { this.raiseNewLogItem( eligibleTickers ); this.notifyMessage( eligibleTickers ); } private void updateTestingPositions_updateThresholds() { for(int i = 0; i<this.chosenPVOPositions.Length; i++) { ((PVOPositions)this.chosenPVOPositions[i]).OversoldThreshold = this.oversoldThreshold; ((PVOPositions)this.chosenPVOPositions[i]).OverboughtThreshold = this.overboughtThreshold; } } private TestingPositions[] getReversedTestingPositions() { int arrayLength = this.chosenPVOPositions.Length; TestingPositions[] reversedTestingPositions = new TestingPositions[arrayLength]; for(int i = 0; i < arrayLength ; i++) { reversedTestingPositions[arrayLength - i - 1] = this.chosenPVOPositions[i]; } return reversedTestingPositions; } protected virtual void updateTestingPositions(DateTime currentDate) { EndOfDayHistory endOfDayHistory = this.benchmark.GetEndOfDayHistory( new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), EndOfDaySpecificTime.MarketOpen), new EndOfDayDateTime(currentDate, EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = this.eligiblesSelector.GetEligibleTickers(endOfDayHistory); this.updateReturnsManager(endOfDayHistory.FirstEndOfDayDateTime, endOfDayHistory.LastEndOfDayDateTime); if(this.inSampleChooser != null) this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager); this.updateTestingPositions_updateThresholds(); this.chosenPVOPositions = this.getReversedTestingPositions(); this.logOptimizationInfo(eligibles); } private bool optimalTestingPositionsAreToBeUpdated() { bool areToBeUpdated = false; if(this.inSampleChooser != null) { DateTime dateTimeForNextOptimization = this.lastOptimizationDateTime.AddDays( this.numDaysBetweenEachOptimization ); areToBeUpdated = ( ( ( this.account.Portfolio.Count == 0 ) && ( ( this.lastOptimizationDateTime == DateTime.MinValue ) ) ) || ( this.now().DateTime >= dateTimeForNextOptimization ) ); } return areToBeUpdated; } /// <summary> /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public virtual void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.numDaysElapsedSinceLastOptimization++; //OLD - numDaysBetweenEachOptimization --> market days // if( this.account.Transactions.Count <= 1 || // (this.numDaysElapsedSinceLastOptimization == // this.numDaysBetweenEachOptimization) ) //num days without optimization has elapsed or //no transaction, except for adding cash, has been executed //NEW - numDaysBetweenEachOptimization --> calendar days if ( this.optimalTestingPositionsAreToBeUpdated() ) { this.updateTestingPositions(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; this.lastOptimizationDateTime = this.now().DateTime; } } #endregion } } |
|
From: Marco M. <mi...@us...> - 2008-04-25 17:28:11
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/TickersRelationships In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24068/b4_Business/a2_Strategies/TickersRelationships Added Files: OpenToCloseCloseToOpenCorrelationProvider.cs Log Message: Added OpenToCloseCloseToOpenCorrelationProvider --- NEW FILE: OpenToCloseCloseToOpenCorrelationProvider.cs --- /* QuantProject - Quantitative Finance Library OpenToCloseCloseToOpenCorrelationProvider.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT.Statistics; using QuantProject.Business.DataProviders; using QuantProject.Business.Timing; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; namespace QuantProject.Business.Strategies.TickersRelationships { /// <summary> /// Class that provides open to close - close to open /// correlation's indexes two by two within a /// given set of tickers /// </summary> [Serializable] public class OpenToCloseCloseToOpenCorrelationProvider : CorrelationProvider { /// <summary> /// Creates the provider for the open to close - close to open correlation /// </summary> /// <param name="tickersToAnalyze">Array of tickers to be analyzed</param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="minimumAbsoluteReturnValue">Both current tickers' returns /// have to be greater than minimumAbsoluteReturnValue for being considered /// significant and so computed in the correlation formula</param> /// <param name="maximumAbsoluteReturnValue">Both current tickers' returns /// have to be less than maximumAbsoluteReturnValue</param> /// <param name="benchmark">The benchmark used for computation /// of returns</param> public OpenToCloseCloseToOpenCorrelationProvider(string[] tickersToAnalyze, DateTime startDate, DateTime endDate, float minimumAbsoluteReturnValue, float maximumAbsoluteReturnValue, string benchmark) : base(tickersToAnalyze, startDate, endDate, minimumAbsoluteReturnValue, maximumAbsoluteReturnValue, benchmark) { } /// <summary> /// Creates the provider for the open to close close to open /// correlation /// </summary> /// <param name="tickersToAnalyze">Array of tickers to be analyzed</param> /// <param name="returnsManager"></param> /// <param name="minimumAbsoluteReturnValue">Both current tickers' returns /// have to be greater than minimumAbsoluteReturnValue for being considered /// significant and so computed in the correlation formula</param> /// <param name="maximumAbsoluteReturnValue">Both current tickers' returns /// have to be less than maximumAbsoluteReturnValue</param> public OpenToCloseCloseToOpenCorrelationProvider( string[] tickersToAnalyze, ReturnsManager returnsManager, float minimumAbsoluteReturnValue, float maximumAbsoluteReturnValue ) : base(tickersToAnalyze, returnsManager, minimumAbsoluteReturnValue, maximumAbsoluteReturnValue) { } protected override void setEndOfDayDatesTime(DateTime startDate, DateTime endDate) { this.firstEndOfDayDateTime = new EndOfDayDateTime(startDate, EndOfDaySpecificTime.MarketOpen); this.lastEndOfDayDateTime = new EndOfDayDateTime(endDate, EndOfDaySpecificTime.MarketClose); } protected override void setReturnsManager() { OpenToCloseCloseToOpenIntervals openToCloseCloseToOpenIntervals = new OpenToCloseCloseToOpenIntervals(this.firstEndOfDayDateTime, this.lastEndOfDayDateTime, this.benchmark); this.returnsManager = new ReturnsManager(openToCloseCloseToOpenIntervals, new HistoricalAdjustedQuoteProvider() ); } } // end of class } |
|
From: Marco M. <mi...@us...> - 2008-04-25 17:24:13
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement/time In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22118/b4_Business/a2_Strategies/returnsManagement/time Added Files: IntervalsType.cs Log Message: IntervalsType enum has been added (for people not using IIntervalsSelector ...) --- NEW FILE: IntervalsType.cs --- /* QuantProject - Quantitative Finance Library IntervalsType.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Business.Strategies.ReturnsManagement.Time { /// <summary> /// Intervals types: enum for definition of types of intervals /// to be used in strategies and in sample choosers /// </summary> public enum IntervalsType { CloseToCloseIntervals_OneDay, CloseToCloseIntervals_TwoDays, CloseToCloseIntervals_FiveDays, CloseToOpenIntervals, DailyOpenToCloseIntervals, OpenToCloseCloseToOpenIntervals } } |
|
From: Marco M. <mi...@us...> - 2008-04-25 17:22:17
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21466/b4_Business/a2_Strategies/Eligibles Added Files: ByPriceLessVolatileOTCAlwaysQuoted.cs Log Message: Added ByPriceLessVolatileOTCAlwaysQuoted selector. It is just the same as the ByPriceMostLiquidAlwaysQuoted selector, with only this difference: at the same point of selection, less volatile (open to close returns) tickers are chosen instead of most liquid tickers --- NEW FILE: ByPriceLessVolatileOTCAlwaysQuoted.cs --- /* QuantProject - Quantitative Finance Library ByPriceLessVolatileOTCAlwaysQuoted.cs Copyright (C) 2008 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 QuantProject.ADT.Messaging; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Timing; using QuantProject.Data.Selectors; namespace QuantProject.Business.Strategies.Eligibles { /// <summary> /// Implements IEligiblesSelector for selecting a given max number of tickers through /// the following step-by-step selecting process: /// -step 1: all tickers belonging to a given group /// are selected (the group can be "temporized": that is tickers /// are returned depending on the time the selection is requested: /// the group SP 500 should be like that); /// -step 2: from tickers selected by step 1, the less volatile (open to close) /// are selected (not more than a given max number); /// -step 3: from tickers selected by step 2, the ones that are /// always quoted at all market days are selected (not more than a given max number); /// </summary> public class ByPriceLessVolatileOTCAlwaysQuoted : IEligiblesSelector { public event NewMessageEventHandler NewMessage; private bool temporizedGroup; private string tickersGroupID; private int maxNumberOfEligibleTickersToBeChosen; private int numOfDaysForAverageOpenRawPriceComputation; private double minPrice; private double maxPrice; public string Description { get{ return "From_" + this.tickersGroupID + " (temporized: " + this.temporizedGroup.ToString() + ")\n" + "MaxNumOfEligibles_" + this.maxNumberOfEligibleTickersToBeChosen.ToString() + "\n" + "AverageRawOpenPriceRange(computed for the last " + this.numOfDaysForAverageOpenRawPriceComputation.ToString() + "):\n" + "From_" + this.minPrice + "_to_" + this.maxPrice + "\n" + "Most Liquid and Always Quoted at each market day (^GSPC) for the in sample time frame"; } } public ByPriceLessVolatileOTCAlwaysQuoted( string tickersGroupID , bool temporizedGroup, int maxNumberOfEligibleTickersToBeChosen, int numOfDaysForAverageOpenRawPriceComputation, double minPrice, double maxPrice) { this.temporizedGroup = temporizedGroup; this.tickersGroupID = tickersGroupID; this.maxNumberOfEligibleTickersToBeChosen = maxNumberOfEligibleTickersToBeChosen; this.numOfDaysForAverageOpenRawPriceComputation = numOfDaysForAverageOpenRawPriceComputation; this.minPrice = minPrice; this.maxPrice = maxPrice; } private EligibleTickers getEligibleTickers_actually( EndOfDayHistory endOfDayHistory ) { DateTime currentDate = endOfDayHistory.LastEndOfDayDateTime.DateTime; SelectorByGroup group; if(this.temporizedGroup) //the group is "temporized": returned set of tickers // depend on time group = new SelectorByGroup(this.tickersGroupID, currentDate); else//the group is not temporized group = new SelectorByGroup(this.tickersGroupID); DataTable tickersFromGroup = group.GetTableOfSelectedTickers(); int numOfTickersInGroupAtCurrentDate = tickersFromGroup.Rows.Count; SelectorByAverageRawOpenPrice byPrice = new SelectorByAverageRawOpenPrice(tickersFromGroup,false, currentDate.AddDays(-this.numOfDaysForAverageOpenRawPriceComputation), currentDate, numOfTickersInGroupAtCurrentDate, this.minPrice,this.maxPrice, 0.00001, double.MaxValue); DataTable dataTableByPrice = byPrice.GetTableOfSelectedTickers(); SelectorByOpenToCloseVolatility lessVolatileSelector = new SelectorByOpenToCloseVolatility( dataTableByPrice , true, endOfDayHistory.FirstEndOfDayDateTime.DateTime, currentDate, this.maxNumberOfEligibleTickersToBeChosen); DataTable dataTableLessVolatile = lessVolatileSelector.GetTableOfSelectedTickers(); // DataSet dataSet = new DataSet(); // dataSet.Tables.Add( dataTableLessVolatile ); // dataSet.WriteXml( "c:\\qpReports\\pairsTrading\\eligiblesCon_ByPriceLessVolatileOTCAlwaysQuoted.xml" ); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromLastSelection = new SelectorByQuotationAtEachMarketDay( dataTableLessVolatile , false, endOfDayHistory.History, this.maxNumberOfEligibleTickersToBeChosen); DataTable dataTableToBeReturned = quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers(); return new EligibleTickers( dataTableToBeReturned ); } private void getEligibleTickers_sendNewMessage( EligibleTickers eligibleTickers ) { string message = "Number of Eligible tickers: " + eligibleTickers.Count; NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if(this.NewMessage != null) this.NewMessage( this , newMessageEventArgs ); } /// <summary> /// Returns the eligible tickers /// </summary> /// <returns></returns> public EligibleTickers GetEligibleTickers( EndOfDayHistory endOfDayHistory ) { EligibleTickers eligibleTickers = this.getEligibleTickers_actually( endOfDayHistory ); this.getEligibleTickers_sendNewMessage( eligibleTickers ); return eligibleTickers; } } } |
|
From: Marco M. <mi...@us...> - 2008-04-25 17:17:34
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19178/b4_Business/a2_Strategies/InSample Modified Files: BasicChooserFromSavedBackTestLog.cs Log Message: Added if for avoiding run time error when null events are fired Index: BasicChooserFromSavedBackTestLog.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample/BasicChooserFromSavedBackTestLog.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BasicChooserFromSavedBackTestLog.cs 10 Apr 2008 23:11:32 -0000 1.2 --- BasicChooserFromSavedBackTestLog.cs 25 Apr 2008 17:17:19 -0000 1.3 *************** *** 46,49 **** --- 46,51 ---- public event NewMessageEventHandler NewMessage; + protected int numberOfBestTestingPositionsToBeReturned; + protected TestingPositions[] bestTestingPositionsInSample; protected string backTestLogFullPath; protected BackTestLog backTestLog; *************** *** 58,61 **** --- 60,77 ---- } + private void setBackTestLog() + { + if( this.backTestLog == null ) + { + object savedObject = ObjectArchiver.Extract( + this.backTestLogFullPath); + if( savedObject is BackTestLog ) + this.backTestLog = (BackTestLog)savedObject; + else // savedObject is not a BackTestLog + throw new Exception("The loaded object is not " + + " a BackTestLog!"); + } + } + /// <summary> /// Abstract BasicChooserFromSavedBackTestLog to be used for *************** *** 64,70 **** /// </summary> public BasicChooserFromSavedBackTestLog( ! string backTestLogFullPath) { this.backTestLogFullPath = backTestLogFullPath; } --- 80,89 ---- /// </summary> public BasicChooserFromSavedBackTestLog( ! string backTestLogFullPath, int numberOfBestTestingPositionsToBeReturned) { this.backTestLogFullPath = backTestLogFullPath; + this.numberOfBestTestingPositionsToBeReturned = + numberOfBestTestingPositionsToBeReturned; + this.setBackTestLog(); } *************** *** 72,89 **** EndOfDayDateTime lastInSampleDateOfOptimizedTestingPositions ); ! protected void analyzeInSample_setBackTestLog() { ! if( this.backTestLog == null ) ! { ! object savedObject = ObjectArchiver.Extract( ! this.backTestLogFullPath); ! if( savedObject is BackTestLog ) ! this.backTestLog = (BackTestLog)savedObject; ! else // savedObject is not a BackTestLog ! throw new Exception("The loaded object is not " + ! " a BackTestLog!"); ! } } ! /// <summary> /// Returns the best TestingPositions --- 91,104 ---- EndOfDayDateTime lastInSampleDateOfOptimizedTestingPositions ); ! private void analyzeInSample_fireEvents() { ! if(this.NewProgress != null) ! this.NewProgress( this , ! new NewProgressEventArgs( 1 , 1 ) ); ! if(this.NewMessage != null) ! this.NewMessage( this , ! new NewMessageEventArgs( "AnalyzeInSample is complete" ) ); } ! /// <summary> /// Returns the best TestingPositions *************** *** 96,107 **** ReturnsManager returnsManager ) { ! this.analyzeInSample_setBackTestLog(); ! TestingPositions[] bestTestingPositionsInSample = this.getTestingPositionsFromBackTestLog( returnsManager.ReturnIntervals.LastEndOfDayDateTime ); ! this.NewProgress( this , ! new NewProgressEventArgs( 1 , 1 ) ); ! this.NewMessage( this , ! new NewMessageEventArgs( "AnalyzeInSample is complete" ) ); return bestTestingPositionsInSample; } --- 111,118 ---- ReturnsManager returnsManager ) { ! this.bestTestingPositionsInSample = this.getTestingPositionsFromBackTestLog( returnsManager.ReturnIntervals.LastEndOfDayDateTime ); ! this.analyzeInSample_fireEvents(); return bestTestingPositionsInSample; } |
|
From: Marco M. <mi...@us...> - 2008-04-25 17:13:53
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting/Tables In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17325/b4_Business/a1_Financial/a2_Accounting/h5_Reporting/Tables Modified Files: StatisticsSummary.cs Log Message: AverageReturnOnMonday has been replaced by AverageReturnOnMondayWithOpenPositions Added the classes for average return computation on days with open positions (with distinction by day of week) Index: StatisticsSummary.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting/Tables/StatisticsSummary.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StatisticsSummary.cs 6 Feb 2008 20:40:23 -0000 1.1 --- StatisticsSummary.cs 25 Apr 2008 17:13:42 -0000 1.2 *************** *** 21,26 **** private IHistoricalQuoteProvider historicalQuoteProvider; ! private AverageReturnOnMonday averageReturnOnMonday; ! public AccountReport AccountReport { --- 21,31 ---- private IHistoricalQuoteProvider historicalQuoteProvider; ! private AverageReturnOnMondayWithOpenPositions averageReturnOnMondayWithOpenPositions; ! private AverageReturnOnTuesdayWithOpenPositions averageReturnOnTuesdayWithOpenPositions; ! private AverageReturnOnWednesdayWithOpenPositions averageReturnOnWednesdayWithOpenPositions; ! private AverageReturnOnThursdayWithOpenPositions averageReturnOnThursdayWithOpenPositions; ! private AverageReturnOnFridayWithOpenPositions averageReturnOnFridayWithOpenPositions; ! private AverageReturnOnDayWithOpenPositions averageReturnOnDayWithOpenPositions; ! public AccountReport AccountReport { *************** *** 28,34 **** } ! public AverageReturnOnMonday AverageReturnOnMonday { ! get { return this.averageReturnOnMonday; } } --- 33,64 ---- } ! public AverageReturnOnMondayWithOpenPositions AverageReturnOnMondayWithOpenPositions { ! get { return this.averageReturnOnMondayWithOpenPositions; } ! } ! ! public AverageReturnOnTuesdayWithOpenPositions AverageReturnOnTuesdayWithOpenPositions ! { ! get { return this.averageReturnOnTuesdayWithOpenPositions; } ! } ! ! public AverageReturnOnWednesdayWithOpenPositions AverageReturnOnWednesdayWithOpenPositions ! { ! get { return this.averageReturnOnWednesdayWithOpenPositions; } ! } ! ! public AverageReturnOnThursdayWithOpenPositions AverageReturnOnThursdayWithOpenPositions ! { ! get { return this.averageReturnOnThursdayWithOpenPositions; } ! } ! ! public AverageReturnOnFridayWithOpenPositions AverageReturnOnFridayWithOpenPositions ! { ! get { return this.averageReturnOnFridayWithOpenPositions; } ! } ! ! public AverageReturnOnDayWithOpenPositions AverageReturnOnDayWithOpenPositions ! { ! get { return this.averageReturnOnDayWithOpenPositions; } } *************** *** 112,116 **** throw new Exception( "A StatisticsSummary computation has been requested, but the equity line is empty" ); ! this.averageReturnOnMonday = new AverageReturnOnMonday(this); } --- 142,152 ---- throw new Exception( "A StatisticsSummary computation has been requested, but the equity line is empty" ); ! this.averageReturnOnMondayWithOpenPositions = new AverageReturnOnMondayWithOpenPositions(this); ! this.averageReturnOnTuesdayWithOpenPositions = new AverageReturnOnTuesdayWithOpenPositions(this); ! this.averageReturnOnWednesdayWithOpenPositions = new AverageReturnOnWednesdayWithOpenPositions(this); ! this.averageReturnOnThursdayWithOpenPositions = new AverageReturnOnThursdayWithOpenPositions(this); ! this.averageReturnOnFridayWithOpenPositions = new AverageReturnOnFridayWithOpenPositions(this); ! this.averageReturnOnDayWithOpenPositions = ! new AverageReturnOnDayWithOpenPositions(this); } |