Tyche Trading

Z Score

Bar Info

Debugging

Derivatives

Matrix Handling

Price Rounding

Regression Lines

Statistics

User Tracking

Example Strategies

Z Score

Description:

Calculates the Z Score of a value from a set of inputs, or calculates the Z Score of every value from the set of inputs.

 

Syntax:

ZScore(List<double> input, int x);
ZScore(List<double> input, double value);
ZScore(double[] input, int x);
ZScore(double[] input, double value);
ZScore(List<double> input);
ZScore(double[] input);

 

Arguments:

input: The set of inputs from the chart.

x: The index of the value whos Z Score is requested from the set of inputs.

value: A value not from the set of inputs whos Z Score is requested.

				
					/// <summary>
/// Calculates Z Score of a value from a list of inputs.
/// </summary>
/// <param name="input"> A list of values. </param>
/// <param name="x"> The index of the value used to find Z Score. </param>
/// <returns> Z Score of the desired value within the list. </returns>
private double ZScore(List<double> input, int x)
{
	double avg = input.Average();
	double sum = input.Sum(d => Math.Pow(d - avg, 2));
	double sd = Math.Sqrt(sum / input.Count - 1); // remove "- 1" if population
	double z = (input[x] - avg) / sd;

	return z;
}

/// <summary>
/// Calculates Z Score of a value from a list of inputs.
/// </summary>
/// <param name="input"> A list of values. </param>
/// <param name="value"> The value used to find Z Score. </param>
/// <returns> Z Score of the desired value within the list. </returns>
private double ZScore(List<double> input, double value)
{
	double avg = input.Average();
	double sum = input.Sum(d => Math.Pow(d - avg, 2));
	double sd = Math.Sqrt(sum / input.Count - 1); // remove "- 1" if population
	double z = (value - avg) / sd;

	return z;
}

/// <summary>
/// Calculates Z Score of a value from a 1d array of inputs.
/// </summary>
/// <param name="input"> A 1d array of values. </param>
/// <param name="x"> The index of the value used to find Z Score. </param>
/// <returns> Z Score of the desired value within the 1d array. </returns>
private double ZScore(double[] input, int x)
{
	double avg = input.Average();
	double sum = input.Sum(d => Math.Pow(d - avg, 2));
	double sd = Math.Sqrt(sum / input.Length - 1); // remove "- 1" if population
	double z = (input[x] - avg) / sd;

	return z;
}

/// <summary>
/// Calculates Z Score of a value from a 1d array of inputs.
/// </summary>
/// <param name="input"> A 1d array of values. </param>
/// <param name="value"> The value used to find Z Score. </param>
/// <returns> Z Score of the desired value within the 1d array. </returns>
private double ZScore(double[] input, double value)
{
	double avg = input.Average();
	double sum = input.Sum(d => Math.Pow(d - avg, 2));
	double sd = Math.Sqrt(sum / input.Length - 1); // remove "- 1" if population
	double z = (value - avg) / sd;

	return z;
}

/// <summary>
/// Calculates Z Score of every value within a list.
/// </summary>
/// <param name="input"> The list of inputs. </param>
/// <returns> A list of the Z Scores of each value. </returns>
private List<double> ZScore(List<double> input)
{
	double avg = input.Average();
	double sum = input.Sum(d => Math.Pow(d - avg, 2));
	double sd = Math.Sqrt(sum / input.Count - 1); // remove "- 1" if population

	List<double> z = new List<double>();
	foreach (double x in input)
		z.Add((x - avg) / sd);

	return z;
}

/// <summary>
/// Calculates Z Score of every value within a 1d array.
/// </summary>
/// <param name="input"> The 1d array of inputs. </param>
/// <returns> A 1d array of the Z Scores of each value. </returns>
private double[] ZScore(double[] input)
{
	double avg = input.Average();
	double sum = input.Sum(d => Math.Pow(d - avg, 2));
	double sd = Math.Sqrt(sum / input.Length - 1); // remove "- 1" if population

	int n = input.Length;
	double[] z = new double[n];
	for (int i = 0; i < n; i++)
		z[i] = (input[i] - avg) / sd;

	return z;
}