Bar Info
Menu
Debugging
Menu
Derivatives
Menu
Matrix Handling
Menu
Price Rounding
Menu
Regression Lines
Menu
Statistics
Menu
User Tracking
Menu
Example Strategies
Menu
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.
///
/// Calculates Z Score of a value from a list of inputs.
///
/// A list of values.
/// The index of the value used to find Z Score.
/// Z Score of the desired value within the list.
private double ZScore(List 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;
}
///
/// Calculates Z Score of a value from a list of inputs.
///
/// A list of values.
/// The value used to find Z Score.
/// Z Score of the desired value within the list.
private double ZScore(List 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;
}
///
/// Calculates Z Score of a value from a 1d array of inputs.
///
/// A 1d array of values.
/// The index of the value used to find Z Score.
/// Z Score of the desired value within the 1d array.
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;
}
///
/// Calculates Z Score of a value from a 1d array of inputs.
///
/// A 1d array of values.
/// The value used to find Z Score.
/// Z Score of the desired value within the 1d array.
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;
}
///
/// Calculates Z Score of every value within a list.
///
/// The list of inputs.
/// A list of the Z Scores of each value.
private List ZScore(List 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 z = new List();
foreach (double x in input)
z.Add((x - avg) / sd);
return z;
}
///
/// Calculates Z Score of every value within a 1d array.
///
/// The 1d array of inputs.
/// A 1d array of the Z Scores of each value.
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;
}