[Quantproject-developers] QuantProject/b1_ADT/Histories History.cs,1.6,1.7
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2005-01-20 01:22:42
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Histories In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4478/b1_ADT/Histories Modified Files: History.cs Log Message: The method MultiplyBy has been added Index: History.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Histories/History.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** History.cs 11 Jan 2004 19:09:11 -0000 1.6 --- History.cs 20 Jan 2005 01:22:31 -0000 1.7 *************** *** 82,85 **** --- 82,122 ---- } + + #region MultiplyBy + private double multiplyBy_getCurrentValue( DateTime key ) + { + double returnValue; + try + { + returnValue = Convert.ToDouble( this[ key ] ); + } + catch ( Exception exception ) + { + string errorMessage = "The current History object contains a value " + + "that cannot be converted to a double. The wrong value is at the date " + + key.ToString() + ".\nOriginal error message: " + exception.Message; + throw new Exception( errorMessage ); + } + return returnValue; + } + /// <summary> + /// Returns an history where each value is multiplied by the given factor. + /// The History instance must contain only numeric values + /// </summary> + /// <param name="factor"></param> + /// <returns></returns> + public History MultiplyBy( double factor ) + { + if ( factor == 0.0 ) + throw new Exception( "factor can not be equal to zero" ); + History returnValue = new History(); + foreach ( DateTime key in this.Keys ) + { + double currentValue = this.multiplyBy_getCurrentValue( key ); + returnValue.Add( key , currentValue * factor ); + } + return returnValue; + } + #endregion public DateTime GetNextDay( DateTime dateTime ) { |