[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/LinearRegression/InSampleChoos
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2011-01-06 18:56:34
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearRegression/InSampleChoosers/Decoding In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv19385/b7_Scripts/WalkForwardTesting/LinearRegression/InSampleChoosers/Decoding Modified Files: DecoderForLinearRegressionTestingPositions.cs Log Message: The behavior of the decoder has been changed. Now the genome is decoded as follows: a given number of tickers is used to decode a trading portfolio. Then, a given number of signaling portfolios are created, each with a given number of contained signaling tickers. Index: DecoderForLinearRegressionTestingPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearRegression/InSampleChoosers/Decoding/DecoderForLinearRegressionTestingPositions.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DecoderForLinearRegressionTestingPositions.cs 28 Mar 2010 16:02:47 -0000 1.1 --- DecoderForLinearRegressionTestingPositions.cs 6 Jan 2011 18:56:26 -0000 1.2 *************** *** 34,39 **** /// <summary> /// Simple decoder for the Linear Regression strategy. ! /// The genome is decoded as follows: the first two tickers are used to decode /// a trading portfolio. /// For each of the other tickers is created a portfolio with that single ticker and /// such portfolio is used as a signaling portfolio. --- 34,41 ---- /// <summary> /// Simple decoder for the Linear Regression strategy. ! /// The genome is decoded as follows: a given number of tickers is used to decode /// a trading portfolio. + /// Then, a given number of signaling portfolios are created, each with its number + /// of contained tickers. /// For each of the other tickers is created a portfolio with that single ticker and /// such portfolio is used as a signaling portfolio. *************** *** 45,78 **** public class DecoderForLinearRegressionTestingPositions // : IDecoderForTestingPositions { ! // private int numberOfTickersForTrading; ! // public int NumberOfTickersForTrading { ! // get { return this.numberOfTickersForTrading; } ! get { return 2; } } // - private int numberOfSignalingPortfolios; // public int NumberOfSignalingPortfolios { ! get { return this.numberOfSignalingPortfolios; } } private BasicDecoderForTestingPositions basicDecoderForTestingPositions; ! public DecoderForLinearRegressionTestingPositions( int numberOfSignalingPortfolios ) ! // int numberOfTickersForTrading , int numberOfTickersForSignaling ) { ! // this.numberOfTickersForTrading = numberOfTickersForTrading; ! this.numberOfSignalingPortfolios = numberOfSignalingPortfolios; this.basicDecoderForTestingPositions = new BasicDecoderForTestingPositions(); } #region Decode ! private void decode_checkParameters( int[] genome ) { ! int numberOfExpectedGenes = this.numberOfSignalingPortfolios + 2; ! if ( genome.Length != numberOfExpectedGenes ) throw new Exception( ! "The given genom contains " + genome.Length + " genes, but " + ! numberOfExpectedGenes + " where expected!" ); } private int[] getSubGenome( int[] genome , int startingPosition , int length ) --- 47,92 ---- public class DecoderForLinearRegressionTestingPositions // : IDecoderForTestingPositions { ! private int numberOfTickersForTrading; ! ! private int[] numberOfTickersInEachSignalingPortfolio; ! public int NumberOfTickersForTrading { ! get { return this.numberOfTickersForTrading; } } // // public int NumberOfSignalingPortfolios { ! get { return this.numberOfTickersInEachSignalingPortfolio.Length; } } + private BasicDecoderForTestingPositions basicDecoderForTestingPositions; + protected int expectedNumberOfGeneValues; ! public DecoderForLinearRegressionTestingPositions( ! int numberOfTickersForTrading , int[] numberOfTickersInEachSignalingPortfolio ) { ! this.numberOfTickersForTrading = numberOfTickersForTrading; ! this.numberOfTickersInEachSignalingPortfolio = ! numberOfTickersInEachSignalingPortfolio; ! this.basicDecoderForTestingPositions = new BasicDecoderForTestingPositions(); + this.setExpectedNumberOfGeneValues(); + } + + private void setExpectedNumberOfGeneValues() + { + this.expectedNumberOfGeneValues = this.numberOfTickersForTrading; + for( int i = 0 ; i < this.NumberOfSignalingPortfolios ; i++ ) + this.expectedNumberOfGeneValues += + this.numberOfTickersInEachSignalingPortfolio[ i ]; } #region Decode ! virtual protected void decode_checkParameters( int[] genome ) { ! if ( genome.Length != this.expectedNumberOfGeneValues ) throw new Exception( ! "The given genome contains " + genome.Length + " genes, but " + ! this.expectedNumberOfGeneValues + " where expected!" ); } private int[] getSubGenome( int[] genome , int startingPosition , int length ) *************** *** 90,94 **** int[] encodedForTradingTickers = // this.getSubGenome( encoded , 0 , this.numberOfTickersForTrading ); ! this.getSubGenome( encoded , 0 , 2 ); WeightedPositions weightedPositionsForTrading = this.basicDecoderForTestingPositions.Decode( --- 104,108 ---- int[] encodedForTradingTickers = // this.getSubGenome( encoded , 0 , this.numberOfTickersForTrading ); ! this.getSubGenome( encoded , 0 , this.numberOfTickersForTrading ); WeightedPositions weightedPositionsForTrading = this.basicDecoderForTestingPositions.Decode( *************** *** 105,109 **** this.getSubGenome( // encoded , this.numberOfTickersForTrading , this.numberOfTickersForSignaling ); ! encoded , 2 , encoded.Length - 2 ); WeightedPositions weightedPositionsForSignaling = this.basicDecoderForTestingPositions.Decode( --- 119,124 ---- this.getSubGenome( // encoded , this.numberOfTickersForTrading , this.numberOfTickersForSignaling ); ! encoded , this.numberOfTickersForTrading , ! encoded.Length - this.numberOfTickersForTrading ); WeightedPositions weightedPositionsForSignaling = this.basicDecoderForTestingPositions.Decode( *************** *** 130,133 **** --- 145,158 ---- #region getTradingPortfolio + + #region getSignedTickersForTradingPortfolio + private SignedTicker[] getSignedTickersArray( + WeightedPositions weightedPositionsForTrading ) + { + SignedTicker[] signedTickersArray = new SignedTicker[ weightedPositionsForTrading.Count ]; + for( int i = 0 ; i < weightedPositionsForTrading.Count ; i++ ) + signedTickersArray[ i ] = weightedPositionsForTrading.SignedTickers[ i ]; + return signedTickersArray; + } protected virtual SignedTickers getSignedTickersForTradingPortfolio( WeightedPositions weightedPositionsForTrading , *************** *** 135,143 **** { SignedTickers signedTickersForTradingPortfolio = new SignedTickers( ! new SignedTicker[] { ! weightedPositionsForTrading.SignedTickers[ 0 ] , ! weightedPositionsForTrading.SignedTickers[ 1 ] } ); return signedTickersForTradingPortfolio; } private WeightedPositions getTradingPortfolio( WeightedPositions weightedPositionsForTrading , --- 160,171 ---- { SignedTickers signedTickersForTradingPortfolio = new SignedTickers( ! this.getSignedTickersArray( weightedPositionsForTrading ) ); ! // new SignedTicker[] { ! // weightedPositionsForTrading.SignedTickers[ 0 ] , ! // weightedPositionsForTrading.SignedTickers[ 1 ] } ); return signedTickersForTradingPortfolio; } + #endregion getSignedTickersForTradingPortfolio + private WeightedPositions getTradingPortfolio( WeightedPositions weightedPositionsForTrading , *************** *** 224,229 **** /// <summary> ! /// The genome is decoded as follows: the first two tickers are used to decode /// a trading portfolio. /// For each of the other tickers is created a portfolio with that single ticker and /// such portfolio is used as a signaling portfolio. --- 252,260 ---- /// <summary> ! /// Simple decoder for the Linear Regression strategy. ! /// The genome is decoded as follows: a given number of tickers is used to decode /// a trading portfolio. + /// Then, a given number of signaling portfolios are created, each with its number + /// of contained tickers. /// For each of the other tickers is created a portfolio with that single ticker and /// such portfolio is used as a signaling portfolio. |