[Quantproject-developers] QuantProject/b4_Business/a2_Strategies/OutOfSample TestingPositions.cs,
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2009-08-30 15:58:41
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv23451/b4_Business/a2_Strategies/OutOfSample Modified Files: TestingPositions.cs Log Message: Some useful properties have been added Index: TestingPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample/TestingPositions.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TestingPositions.cs 7 Mar 2008 23:27:13 -0000 1.4 --- TestingPositions.cs 30 Aug 2009 15:58:30 -0000 1.5 *************** *** 39,42 **** --- 39,43 ---- private WeightedPositions weightedPositions; private string hashCodeForTickerComposition; + private string hashCode; private double fitnessInSample; *************** *** 60,64 **** //the current instance is not empty { ! ArrayList listOfTickers = new ArrayList(this.weightedPositions.SignedTickers.Tickers); listOfTickers.Sort(); --- 61,65 ---- //the current instance is not empty { ! ArrayList listOfTickers = new ArrayList(this.weightedPositions.SignedTickers.Tickers); listOfTickers.Sort(); *************** *** 69,72 **** --- 70,143 ---- } } + /// <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) *************** *** 89,92 **** this.fitnessInSample = double.MinValue; } ! } } --- 160,163 ---- this.fitnessInSample = double.MinValue; } ! } } |