[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Statistical Functions



PureBytes Links

Trading Reference Links


I got about a dozen requests for these functions, so here they go to
the list.

For some reason I could only find the old (worthless) correlation
formula, but I swear I saw it somewhere.   I will look for mine and
send it later.   Here are a few of the new statistical functions
included in TS 2ki

By the way, when browsing through the functions I seem to have
discovered that you can pass arrays into functions(?) can anyone
verify this?

{*******************************************************************
Description	: This Function returns Covariance
Provided By	: Omega Research, Inc. (c) Copyright 1999
********************************************************************}

Inputs: DependentVal(Numeric), IndependentVal(Numeric), Length(Numeric);
Variables: Ind_Average(0), Dep_Average(0), counter(0), Covr(0);

If Length <> 0 Then Begin
	Ind_Average = Average(IndependentVal, Length);
	Dep_Average = Average(DependentVal, Length);
	For counter = 0 To length - 1 Begin
		 covr = covr + (IndependentVal[counter] - Ind_Average) *
(DependentVal[counter] - Dep_Average);
	End;
	Covariance = Covr / Length;
End;


{*******************************************************************
Description	: This Function returns StdDevS (Sample)
Provided By	: Omega Research, Inc. (c) Copyright 1999
********************************************************************}

Inputs : Price(NumericSeries),Length(NumericSimple);
Variables : SumSqr(0), Avg(0), Counter(0);

If Length <> 0 Then Begin
	Avg = Average(Price, Length);
	SumSqr = 0;
	For Counter = 0 To Length - 1 Begin
		SumSqr = SumSqr + (Price[Counter] - Avg) * (Price[Counter] - Avg);
	End;
	StdDevS = SquareRoot(SumSqr / (Length - 1));
End
Else 
	StdDevS = 0;


{*******************************************************************
Description	: This Function returns Kurtosis
Provided By	: Omega Research, Inc. (c) Copyright 1999
********************************************************************}

Inputs: Price(numericSeries), Length(numeric);
Variables: P1(0), P2(0), P3(0), Avg(0), Std(0);

P1 = Length * (Length + 1) / ((Length - 1) * (Length - 2) * (Length -
3));
P2 = 0;
P3 = 3 * Square(Length - 1)/((Length - 2)*(Length - 3));

Avg = Average(Price, Length);
Std = StdDevS(Price, Length);

For value1 = 0 To Length - 1 Begin
	P2 = P2 + Power((Price[value1] - Avg) / Std, 4);
End;

Kurtosis = P1 * P2 - P3;

{*******************************************************************
Description	: This Function returns Skewness 
Provided By	: Omega Research, Inc. (c) Copyright 1999
********************************************************************}

Inputs: Price(Numeric), Length(Numeric);
Variables: Summ(0), Avg(0), Std(0), Y(0);

Avg = Average(Price, Length);
Std = StdDevS(Price, Length); 
Summ = 0;
Y = Length / ((Length - 1) * (Length - 2));

For value1 = 0 TO Length - 1 Begin
	Summ = Summ + Power((Price[value1] - Avg) / Std, 3);
End;

Skew = Y * Summ


{ *******************************************************************
Description	: This Function returns Normal Density
Provided By	: Omega Research, Inc. (c) Copyright 1999
********************************************************************}

Inputs: Price(Numeric), Mean(Numeric), Std(Numeric);
Variable: Pi(3.141593);

If Std <> 0 then
	NormalDensity = (1 / (SquareRoot(2 * Pi)* Std))*
ExpValue(-Square(Price - Mean)/(2 * Square(Std)));

{*******************************************************************
Description	: This Function returns Standard Cummulative Normal Density
Provided By	: Omega Research, Inc. (c) Copyright 1999
********************************************************************}

Inputs: Price(Numeric);
Variables: Answer(0), x(0), y(0), z(0);

y = 1 / (1 + .2316419 * AbsValue(Price));      
z = .3989423 *  Power(2.71828183, -(Price * Price) / 2);	
x = 1 - z * ((1.33027443 * Power(y, 5)) - (1.821256 * Power(y, 4)) +
(1.78147794 * Power(y, 3)) - (.3565638 * Power(y, 2)) + (.31938153 *
y));

If Price > 0 Then 
	Answer = x
Else 
	Answer = 1 - x;

NormalSCDensity = Answer;    



{*******************************************************************
Description	: This Function returns Cummulative Normal Density
Provided By	: Omega Research, Inc. (c) Copyright 1999
********************************************************************}

Inputs: Price(Numeric), Mean(Numeric), Std(Numeric);
Variables: Pr(0);

Pr = (Price - Mean) / Std;
NormalCumDensity = NormalSCDensity(Pr);



{*******************************************************************
Decription	: This Function returns Fisher
Provided By	: Omega Research, Inc. (c) Copyright 1999
********************************************************************}

Inputs: Price(Numeric);

IF Price > -1 AND Price < 1 Then
	Fisher = Log((1 + Price) / (1 - Price)) *.5
Else
	Fisher = -999;