[Quantproject-developers] QuantProject/b1_ADT/Histories History.cs,1.1.1.1,1.2
Brought to you by:
glauco_1
|
From: <mi...@us...> - 2003-12-02 19:07:47
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Histories
In directory sc8-pr-cvs1:/tmp/cvs-serv18518/b1_ADT/Histories
Modified Files:
History.cs
Log Message:
Added GetSimpleAverage and GetStandardDeviation methods to History Class
Index: History.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Histories/History.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** History.cs 13 Oct 2003 21:57:45 -0000 1.1.1.1
--- History.cs 2 Dec 2003 19:07:43 -0000 1.2
***************
*** 25,28 ****
--- 25,29 ----
using QuantProject.ADT;
+
namespace QuantProject.ADT.Histories
{
***************
*** 75,78 ****
--- 76,163 ----
return (DateTime) this.GetKey( this.IndexOfKeyOrPrevious( dateTime ) + 1 );
}
+
+ #region "Millo_1 - SimpleAverage and StandardDeviation"
+
+ public History GetSimpleAverage( int onEachPeriodOf , DateTime startDateTime , DateTime endDateTime )
+ {
+ History simpleAverage = new History();
+ int index = this.IndexOfKeyOrPrevious(startDateTime);
+ double[] data = new double[onEachPeriodOf];
+ double checkValue = 0;
+ int i = 0;
+ while (
+ ( index < this.Count ) &&
+ ( ((IComparable)this.GetKey( index )).CompareTo( endDateTime ) <= 0 ) )
+ {
+ DateTime dateTime = (DateTime)this.GetKey( index );
+ if (Math.Floor(index/onEachPeriodOf) == checkValue &&
+ i < onEachPeriodOf)
+ {
+ data[i] = Convert.ToDouble(this.GetByIndex(index));
+ i++;
+ //simpleAverage.Add(this.GetKey( index ), null);
+ }
+ else //Changes the period
+ {
+ i = 0;
+ simpleAverage.Add( dateTime , Stat.SimpleAverage(data) );
+ }
+ index++;
+ checkValue = Math.Floor(index/onEachPeriodOf);//update checkValue
+ }
+
+ return simpleAverage;
+ }
+
+ public History GetStandardDeviation( int onEachPeriodOf , DateTime startDateTime , DateTime endDateTime )
+ {
+ History stdDev = new History();
+ int index = this.IndexOfKeyOrPrevious(startDateTime);
+ double[] data = new double[onEachPeriodOf];
+ double checkValue = 0;
+ int i = 0;
+ while (
+ ( index < this.Count ) &&
+ ( ((IComparable)this.GetKey( index )).CompareTo( endDateTime ) <= 0 ) )
+ {
+ DateTime dateTime = (DateTime)this.GetKey( index );
+ if (Math.Floor(index/onEachPeriodOf) == checkValue &&
+ i < onEachPeriodOf)
+ {
+ data[i] = Convert.ToDouble(this.GetByIndex(index));
+ i++;
+ //stdDev.Add(this.GetKey( index ), null);
+ }
+ else //Changes the period
+ {
+ i = 0;
+ stdDev.Add( dateTime , Stat.StdDev (data) );
+ }
+ index++;
+ checkValue = Math.Floor(index/onEachPeriodOf);//update checkValue
+ }
+
+ return stdDev ;
+ }
+ public bool IsDecreased(DateTime dateTime)
+ {
+ bool isDecreased;
+ int index = this.IndexOfKey(dateTime);
+ if ( index <= 0 )
+ isDecreased = false;
+ else
+ {
+ isDecreased = Convert.ToDouble( this[ dateTime ]) <
+ Convert.ToDouble( this.GetByIndex(index - 1) );
+ }
+ return isDecreased;
+
+
+ }
+
+
+ #endregion
+
+
#region "GetSimpleMovingAverage( int , DateTime , int )"
|