Distribution |
Distribution represents a main distribution characteristic determinator. For time series queue listener please use DistributionListener class. It will be useful for finding quantiles, averages, moments, distribution function, etc. It uses AvlTree, so it is useful only on on-line dynamic value, where count of elements is more than 50.
The following constructor creates an instance of Distribution class:
Contains properties:
Property | Description |
---|---|
cumulative distribution function | Get estimation of Distribution Function. |
count | Get the number of elements stored in the set. |
max | Get max of the container's values. |
min | Get min of the container's values. |
range | Get range of the container's values. |
sum | Get sum of the container's values. |
sum of absolute values | Get sum of absolute container's values. |
sum of squares | Get sum of squares of the container's values. |
expected value | Get estimation of distribution's Expected Value. |
arithmetic mean | Get arithmetic mean of the container's values. |
geometric mean | Get geometric mean of the container's values. |
harmonic mean | Get harmonic mean of the container's values. |
quadratic mean | Get quadratic mean of the container's values. |
median | Get median of the container's values. |
midrange | Get midrange of the container's values. |
variance | Get variance of the container's values. |
sample variance | Get sample variance of the container's values. |
population variance | Get population variance of the container's values. |
standard deviation | Get standard deviation of the container's values. |
sample standard deviation | Get sample standard deviation of the container's values. |
population standard deviation | Get population standard deviation of the container's values. |
raw moments | Get raw moments of the container's values. |
central moments | Get central moments of the container's values. |
skewness | Get skewness of the container's values. |
kurtosis | Get kurtosis of the container's values. |
coefficient of variation | Get coefficient of variation of the container's values. |
Methods:
Method | Description |
---|---|
add | Add new element to Distribution. Initializes new element to Distribution. |
remove | Drop element from set. |
cumulative distribution | Get estimation of Distribution Function |
quantile | The p-th quantile, where p is between 0 and 1, is the value that has a proportion p of the data below the value. Get additional value associated with quantile. |
order statistic | Order statistic allows to get element by its order in the series when values are ordered from the smallest one to the greatest one. Get additional value associated with Order Statistic. |
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using FinAnalysis.Base; 6using FinAnalysis.Listeners; 7using FinAnalysis.TA; 8 9namespace DistributionSample 10{ 11 class DistributionSample 12 { 13 const int ElementsCount = 0xFF; 14 const int Steps = 0xFF; 15 const int QueueCapacity = 12; 16 17 static void Main(string[] args) 18 { 19 Random r = new Random(); 20 21 Console.WriteLine("Distribution Sample"); 22 23 Distribution distribution = new Distribution(); 24 25 for (int i = 0; i < ElementsCount; ++i) 26 { 27 distribution.Add(r.NextDouble(), "Info" + i.ToString("000")); 28 } 29 30 for (int i = 0; i < ElementsCount; ++i) 31 { 32 Console.WriteLine("Order Statistic #{0} = {1:0.00}, Additional Info = {2:0.00}", i, distribution.GetOrderStatistic(i), distribution.GetOrderStatisticAdditionalInfo(i)); 33 } 34 35 for (double x = 0; x <= 1; x += 0.1) 36 { 37 Console.WriteLine("Quantile {0:0.00} = {1:0.00}, Additional Info = {2:0.00}", x, distribution.GetQuantile(x), distribution.GetQuantileAdditionalInfo(x)); 38 } 39 40 Console.WriteLine("Elements Count = {0}", distribution.Count); 41 Console.WriteLine("Arithmetic Mean = {0:0.00}", distribution.ArithmeticMean); 42 Console.WriteLine("Coefficient Of Variation = {0:0.00}", distribution.CoefficientOfVariation); 43 Console.WriteLine("Expected Value = {0:0.00}", distribution.ExpectedValue); 44 Console.WriteLine("First Raw Moment = {0:0.00}", distribution.FirstRawMoment); 45 Console.WriteLine("Fourth Central Moment = {0:0.00}", distribution.FourthCentralMoment); 46 Console.WriteLine("Fourth Raw Moment = {0:0.00}", distribution.FourthRawMoment); 47 Console.WriteLine("Geometric Mean = {0:0.00}", distribution.GeometricMean); 48 49 Console.WriteLine("Harmonic Mean = {0:0.00}", distribution.HarmonicMean); 50 Console.WriteLine("Kurtosis = {0:0.00}", distribution.Kurtosis); 51 Console.WriteLine("Max = {0:0.00}", distribution.Max); 52 Console.WriteLine("Median = {0:0.00}", distribution.Median); 53 Console.WriteLine("Midrange = {0:0.00}", distribution.Midrange); 54 Console.WriteLine("Min = {0:0.00}", distribution.Min); 55 56 Console.WriteLine("Quadratic Mean = {0:0.00}", distribution.QuadraticMean); 57 Console.WriteLine("Range = {0:0.00}", distribution.Range); 58 Console.WriteLine("Second Central Moment = {0:0.00}", distribution.SecondCentralMoment); 59 Console.WriteLine("Second Raw Moment = {0:0.00}", distribution.SecondRawMoment); 60 Console.WriteLine("Skewness = {0:0.00}", distribution.Skewness); 61 Console.WriteLine("Standard Deviation = {0:0.00}", distribution.StandardDeviation); 62 Console.WriteLine("Standard Deviation Population = {0:0.00}", distribution.StandardDeviationPopulation); 63 Console.WriteLine("Standard Deviation Sample = {0:0.00}", distribution.StandardDeviationSample); 64 Console.WriteLine("Sum = {0:0.00}", distribution.Sum); 65 66 Console.WriteLine("Sum Of Absolute Values = {0:0.00}", distribution.SumOfAbsoluteValues); 67 Console.WriteLine("Sum Of Squares = {0:0.00}", distribution.SumOfSquares); 68 Console.WriteLine("Third Central Moment = {0:0.00}", distribution.ThirdCentralMoment); 69 Console.WriteLine("Third Raw Moment = {0:0.00}", distribution.ThirdRawMoment); 70 Console.WriteLine("Variance = {0:0.00}", distribution.Variance); 71 Console.WriteLine("Variance Population = {0:0.00}", distribution.VariancePopulation); 72 Console.WriteLine("Variance Sample = {0:0.00}", distribution.VarianceSample); 73 Console.WriteLine(); 74 75 76 Console.WriteLine("Distribution Listener Sample"); 77 78 DistributionListener listener = new DistributionListener(); 79 SimpleDataQueue dataQueue = new SimpleDataQueue(QueueCapacity); 80 dataQueue.SetQueueListener(listener); 81 82 for (int i = 0; i < Steps; ++i) 83 { 84 dataQueue.Put(r.NextDouble(), DateTime.Now); 85 } 86 87 88 for (int i = 0; i < QueueCapacity; ++i) 89 { 90 Console.WriteLine("Order Statistic #{0} = {1:0.00}", i, listener.GetOrderStatistic(i).Data); 91 } 92 93 for (double x = 0; x <= 1; x += 0.1) 94 { 95 Console.WriteLine("Quantile {0:0.00} = {1:0.00}", x, listener.GetQuantile(x).Data); 96 } 97 98 Console.WriteLine("Elements Count = {0}", listener.Count); 99 Console.WriteLine("Arithmetic Mean = {0:0.00}", listener.ArithmeticMean); 100 Console.WriteLine("Coefficient Of Variation = {0:0.00}", listener.CoefficientOfVariation); 101 Console.WriteLine("Expected Value = {0:0.00}", listener.ExpectedValue); 102 Console.WriteLine("First Raw Moment = {0:0.00}", listener.FirstRawMoment); 103 Console.WriteLine("Fourth Central Moment = {0:0.00}", listener.FourthCentralMoment); 104 Console.WriteLine("Fourth Raw Moment = {0:0.00}", listener.FourthRawMoment); 105 Console.WriteLine("Geometric Mean = {0:0.00}", listener.GeometricMean); 106 107 Console.WriteLine("Harmonic Mean = {0:0.00}", listener.HarmonicMean); 108 Console.WriteLine("Kurtosis = {0:0.00}", listener.Kurtosis); 109 Console.WriteLine("Max = {0:0.00}", listener.Max); 110 Console.WriteLine("Median = {0:0.00}", listener.Median); 111 Console.WriteLine("Midrange = {0:0.00}", listener.Midrange); 112 Console.WriteLine("Min = {0:0.00}", listener.Min); 113 114 Console.WriteLine("Quadratic Mean = {0:0.00}", listener.QuadraticMean); 115 Console.WriteLine("Range = {0:0.00}", listener.Range); 116 Console.WriteLine("Second Central Moment = {0:0.00}", listener.SecondCentralMoment); 117 Console.WriteLine("Second Raw Moment = {0:0.00}", listener.SecondRawMoment); 118 Console.WriteLine("Skewness = {0:0.00}", listener.Skewness); 119 Console.WriteLine("Standard Deviation = {0:0.00}", listener.StandardDeviation); 120 Console.WriteLine("Standard Deviation Population = {0:0.00}", listener.StandardDeviationPopulation); 121 Console.WriteLine("Standard Deviation Sample = {0:0.00}", listener.StandardDeviationSample); 122 Console.WriteLine("Sum = {0:0.00}", listener.Sum); 123 124 Console.WriteLine("Sum Of Absolute Values = {0:0.00}", listener.SumOfAbsoluteValues); 125 Console.WriteLine("Sum Of Squares = {0:0.00}", listener.SumOfSquares); 126 Console.WriteLine("Third Central Moment = {0:0.00}", listener.ThirdCentralMoment); 127 Console.WriteLine("Third Raw Moment = {0:0.00}", listener.ThirdRawMoment); 128 Console.WriteLine("Variance = {0:0.00}", listener.Variance); 129 Console.WriteLine("Variance Population = {0:0.00}", listener.VariancePopulation); 130 Console.WriteLine("Variance Sample = {0:0.00}", listener.VarianceSample); 131 132 133 } 134 } 135}