[Quantproject-developers] QuantProject/b4_Business/a2_Strategies/OutOfSample TestingPositions.cs,
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2010-03-28 14:39:28
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv26756/a2_Strategies/OutOfSample Modified Files: TestingPositions.cs Log Message: If the weightedPositions are null then hashCodeForTickerComposition is the empty string Index: TestingPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample/TestingPositions.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TestingPositions.cs 30 Aug 2009 15:58:30 -0000 1.5 --- TestingPositions.cs 28 Mar 2010 14:39:20 -0000 1.6 *************** *** 19,23 **** 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; --- 19,23 ---- 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; *************** *** 28,50 **** namespace QuantProject.Business.Strategies.OutOfSample { ! /// <summary> ! /// This is the base class representing positions that ! /// should be tested out of sample in a back test ! /// Every strategy should test out of sample an object ! /// of this type or an object derived from this class ! /// </summary> ! [Serializable] ! public class TestingPositions ! { ! private WeightedPositions weightedPositions; ! private string hashCodeForTickerComposition; ! private string hashCode; ! private double fitnessInSample; ! public WeightedPositions WeightedPositions { get{return this.weightedPositions;} } ! public double FitnessInSample { get{return this.fitnessInSample;} --- 28,50 ---- namespace QuantProject.Business.Strategies.OutOfSample { ! /// <summary> ! /// This is the base class representing positions that ! /// should be tested out of sample in a back test ! /// Every strategy should test out of sample an object ! /// of this type or an object derived from this class ! /// </summary> ! [Serializable] ! public class TestingPositions ! { ! private WeightedPositions weightedPositions; ! private string hashCodeForTickerComposition; ! private string hashCode; ! private double fitnessInSample; ! public WeightedPositions WeightedPositions { get{return this.weightedPositions;} } ! public double FitnessInSample { get{return this.fitnessInSample;} *************** *** 53,162 **** public string HashCodeForTickerComposition ! { ! get ! { ! if(this.hashCodeForTickerComposition == null && ! this.weightedPositions != null) ! //if hashCodeForTickerComposition has not been computed yet and ! //the current instance is not empty ! { ! ArrayList listOfTickers = ! new ArrayList(this.weightedPositions.SignedTickers.Tickers); ! listOfTickers.Sort(); ! foreach(string tickerCode in listOfTickers) ! this.hashCodeForTickerComposition += tickerCode + ";"; ! } ! return this.hashCodeForTickerComposition; } ! } /// <summary> ! /// Hash code for the current instance ! /// Two instances have the same Hash code iif ! /// they have the same tickers with the same signed weights ! /// </summary> public string HashCode ! { ! get ! { ! if(this.hashCode == null && ! this.weightedPositions != null) ! //if hashCode has not been computed yet and ! //the current instance is not empty ! { ! ArrayList listOfTickers = ! new ArrayList(this.weightedPositions.SignedTickers.Tickers); ! listOfTickers.Sort(); ! foreach(string tickerCode in listOfTickers) ! this.hashCode += ! tickerCode + "_" + ! this.weightedPositions.GetWeightedPosition(tickerCode).Weight.ToString() + ! ";"; ! } ! return this.hashCode; } ! } public bool OnlyLongPositions ! { ! get ! { ! bool returnValue = false; ! int numOfWeightedPositions = this.weightedPositions.Count; ! int numOfLongPositions = this.weightedPositions.NumberOfLongPositions; ! if(numOfLongPositions == numOfWeightedPositions) ! //there are only long positions ! returnValue = true; ! ! return returnValue; } ! } public bool OnlyShortPositions ! { ! get ! { ! bool returnValue = false; ! int numOfWeightedPositions = this.weightedPositions.Count; ! int numOfShortPositions = this.weightedPositions.NumberOfShortPositions; ! if(numOfShortPositions == numOfWeightedPositions) ! //there are only short positions ! returnValue = true; ! ! return returnValue; } ! } public bool BothLongAndShortPositions ! { ! get ! { ! bool returnValue = false; ! int numOfWeightedPositions = this.weightedPositions.Count; ! int numOfShortPositions = this.weightedPositions.NumberOfShortPositions; ! int numOfLongPositions = this.weightedPositions.NumberOfLongPositions; ! if(numOfShortPositions != numOfWeightedPositions && ! numOfLongPositions != numOfWeightedPositions) ! //there are both long and short positions ! returnValue = true; ! ! return returnValue; } ! } public TestingPositions(WeightedPositions weightedPositions) ! { ! this.weightedPositions = weightedPositions; ! this.fitnessInSample = double.MinValue; ! } public TestingPositions(WeightedPositions weightedPositions, double fitnessInSample) ! { ! this.weightedPositions = weightedPositions; ! this.fitnessInSample = fitnessInSample; ! } //it creates an empty TestingPositions public TestingPositions() ! { ! this.weightedPositions = null; ! this.fitnessInSample = double.MinValue; } } --- 53,168 ---- public string HashCodeForTickerComposition ! { ! get ! { ! if ( this.hashCodeForTickerComposition == null ) ! { ! if ( this.weightedPositions != null) ! //if hashCodeForTickerComposition has not been computed yet and ! //the current instance is not empty ! { ! ArrayList listOfTickers = ! new ArrayList(this.weightedPositions.SignedTickers.Tickers); ! listOfTickers.Sort(); ! foreach(string tickerCode in listOfTickers) ! this.hashCodeForTickerComposition += tickerCode + ";"; ! } ! else ! // hashCodeForTickerComposition has not been computed yet, but ! // the current instance is empty ! this.hashCodeForTickerComposition = ""; ! } ! return this.hashCodeForTickerComposition; } ! } /// <summary> ! /// Hash code for the current instance ! /// Two instances have the same Hash code iif ! /// they have the same tickers with the same signed weights ! /// </summary> public string HashCode ! { ! get ! { ! if(this.hashCode == null && ! this.weightedPositions != null) ! //if hashCode has not been computed yet and ! //the current instance is not empty ! { ! ArrayList listOfTickers = ! new ArrayList(this.weightedPositions.SignedTickers.Tickers); ! listOfTickers.Sort(); ! foreach(string tickerCode in listOfTickers) ! this.hashCode += ! tickerCode + "_" + ! this.weightedPositions.GetWeightedPosition(tickerCode).Weight.ToString() + ! ";"; ! } ! return this.hashCode; } ! } public bool OnlyLongPositions ! { ! get ! { ! bool returnValue = false; ! int numOfWeightedPositions = this.weightedPositions.Count; ! int numOfLongPositions = this.weightedPositions.NumberOfLongPositions; ! if(numOfLongPositions == numOfWeightedPositions) ! //there are only long positions ! returnValue = true; ! ! return returnValue; } ! } public bool OnlyShortPositions ! { ! get ! { ! bool returnValue = false; ! int numOfWeightedPositions = this.weightedPositions.Count; ! int numOfShortPositions = this.weightedPositions.NumberOfShortPositions; ! if(numOfShortPositions == numOfWeightedPositions) ! //there are only short positions ! returnValue = true; ! ! return returnValue; } ! } public bool BothLongAndShortPositions ! { ! get ! { ! bool returnValue = false; ! int numOfWeightedPositions = this.weightedPositions.Count; ! int numOfShortPositions = this.weightedPositions.NumberOfShortPositions; ! int numOfLongPositions = this.weightedPositions.NumberOfLongPositions; ! if(numOfShortPositions != numOfWeightedPositions && ! numOfLongPositions != numOfWeightedPositions) ! //there are both long and short positions ! returnValue = true; ! ! return returnValue; } ! } public TestingPositions(WeightedPositions weightedPositions) ! { ! this.weightedPositions = weightedPositions; ! this.fitnessInSample = double.MinValue; ! } public TestingPositions(WeightedPositions weightedPositions, double fitnessInSample) ! { ! this.weightedPositions = weightedPositions; ! this.fitnessInSample = fitnessInSample; ! } //it creates an empty TestingPositions public TestingPositions() ! { ! this.weightedPositions = null; ! this.fitnessInSample = double.MinValue; } } |