Click or drag to resize

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:

methodDistribution

Contains properties:

Property

Description

cumulative distribution function

Get estimation of Distribution Function.

DCdf

PropertyItemDouble

count

Get the number of elements stored in the set.

PropertyCount

max

Get max of the container's values.

DSMax

PropertyMax

min

Get min of the container's values.

DSMin

PropertyMin

range

Get range of the container's values.

DSRange

PropertyRange

sum

Get sum of the container's values.

DSSum

PropertySum

sum of absolute values

Get sum of absolute container's values.

DSSum Magn

PropertySumOfAbsoluteValues

sum of squares

Get sum of squares of the container's values.

DSSum Squares

PropertySumOfSquares

expected value

Get estimation of distribution's Expected Value.

DSMean

PropertyExpectedValue

arithmetic mean

Get arithmetic mean of the container's values.

DSAMean

PropertyArithmeticMean

geometric mean

Get geometric mean of the container's values.

DSGMean

PropertyGeometricMean

harmonic mean

Get harmonic mean of the container's values.

DSHMean

PropertyHarmonicMean

quadratic mean

Get quadratic mean of the container's values.

DSQMean

PropertyQuadraticMean

median

Get median of the container's values.

PropertyMedian

midrange

Get midrange of the container's values.

DSMidrange

PropertyMidrange

variance

Get variance of the container's values.

DSVariance

PropertyVariance

sample variance

Get sample variance of the container's values.

DSSample Var

PropertyVarianceSample

population variance

Get population variance of the container's values.

DSPop Var

PropertyVariancePopulation

standard deviation

Get standard deviation of the container's values.

DSStd Deviation

PropertyStandardDeviation

sample standard deviation

Get sample standard deviation of the container's values.

DSSample Std Dev

PropertyStandardDeviationSample

population standard deviation

Get population standard deviation of the container's values.

DSPop Std Dev

PropertyStandardDeviationPopulation

raw moments

Get raw moments of the container's values.

DSRM 1

PropertyFirstRawMoment

DSRM 2

PropertySecondRawMoment

DSRM 3

PropertyThirdRawMoment

DSRM 4

PropertyFourthRawMoment

central moments

Get central moments of the container's values.

DSM 2

PropertySecondCentralMoment

DSM 3

PropertyThirdCentralMoment

DSM 4

PropertyFourthCentralMoment

skewness

Get skewness of the container's values.

DSSkewness

PropertySkewness

kurtosis

Get kurtosis of the container's values.

DSKurtosis

PropertyKurtosis

coefficient of variation

Get coefficient of variation of the container's values.

PropertyCoefficientOfVariation

Methods:

Method

Description

add

Add new element to Distribution.

methodAdd(Double)

Initializes new element to Distribution.

methodAdd(Double, Object)

remove

Drop element from set.

methodRemove(Double)

cumulative distribution

Get estimation of Distribution Function

methodCumulativeDistribution(Double)

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.

DSQuantile

methodGetQuantile(Double)

Get additional value associated with quantile.

methodGetQuantileAdditionalInfo(Double)

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.

DSOrder Stat

methodGetOrderStatistic(Int32)

Get additional value associated with Order Statistic.

methodGetOrderStatisticAdditionalInfo(Int32)

Code Sample
C#
  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}