[Quantproject-developers] QuantProject/b1_ADT/Histories Stat.cs,NONE,1.1
Brought to you by:
glauco_1
|
From: <mi...@us...> - 2003-12-02 19:09:19
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Histories
In directory sc8-pr-cvs1:/tmp/cvs-serv19019/b1_ADT/Histories
Added Files:
Stat.cs
Log Message:
Added a simple library for some basic statistical function
--- NEW FILE: Stat.cs ---
/*
QuantProject - Quantitative Finance Library
History.cs
Copyright (C) 2003
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
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;
namespace QuantProject.ADT.Histories
{
/// <summary>
/// Implements some basic statistical functions
/// </summary>
public class Stat
{
static public double Sum( double[] data )
{
double sum = 0;
for( int i = 0; i < data.Length ; i ++ )
{
sum += data[ i ];
}
return sum;
}
static public double SumOfSquares( double[] data )
{
double sumOfSquares = 0;
for( int i = 0; i < data.Length ; i ++ )
{
sumOfSquares += data[ i ]*data[ i ];
}
return sumOfSquares;
}
static public double SimpleAverage( double[] data )
{
return Stat.Sum(data)/data.Length;
}
static public double Variance( double[] data )
{
double sum = Stat.Sum(data);
double sumOfSquares = Stat.SumOfSquares(data);
return (sumOfSquares - sum*sum/data.Length)/data.Length;
}
static public double StdDev( double[] data )
{
return System.Math.Sqrt(Stat.Variance(data));
}
}
}
|