예제 #1
0
        /// <summary>Calculates the probability density function of the stable distribution in S1 parametrization.</summary>
        /// <param name="x">Argument.</param>
        /// <param name="alpha">Characteristic exponent of the distribution, in the range (0,2].</param>
        /// <param name="beta">Skewness parameter of the distribution, in the range [-1,1].</param>
        /// <param name="abe">Parameter to specify beta with higher accuracy around -1 and 1. Is defined as 1-beta for beta&gt;=0 or as 1+beta for beta&lt;0.</param>
        /// <param name="scale">Scaling parameter (broadness) of the distribution, &gt;0.</param>
        /// <param name="location">Location parameter of the distribution.</param>
        /// <param name="tempStorage">Temporary storage. For the first call, provide null as parameter. For subsequent calls, you can provide the object returned in the first call to speed up calculation.</param>
        /// <param name="precision">The required relative precision of calculation.</param>
        /// <returns>Probability density at <paramref name="x"/>.</returns>
        public static double PDF(double x, double alpha, double beta, double abe, double scale, double location, ref object tempStorage, double precision)
        {
            // Test for special case of symmetric destribution, this can be handled much better
            if (beta == 0)
            {
                return(StableDistributionSymmetric.PDF((x - location) / scale, alpha, ref tempStorage, precision) / scale);
            }

            // test input parameter
            if (!(alpha > 0 && alpha <= 2))
            {
                throw new ArgumentOutOfRangeException(string.Format("Alpha must be in the range (0,2], but was: {0}", alpha));
            }
            if (!(beta >= -1 && beta <= 1))
            {
                throw new ArgumentOutOfRangeException(string.Format("Beta must be in the range [-1,1], but was: {0}", beta));
            }

            if (alpha != 1)
            {
                ParameterConversionS1ToFeller(alpha, beta, abe, scale, location, out var gamma, out var aga, out var sigmaf, out var muf);
                return(StableDistributionFeller.PDF((x - muf) / sigmaf, alpha, gamma, aga) / sigmaf);
            }
            else
            {
                double mu0 = location + scale * beta * 2 * Math.Log(scale) / Math.PI;
                return(StableDistributionS0.PDFMethodAlphaOne((x - mu0) / scale, beta, abe, ref tempStorage, precision) / scale);
            }
        }
예제 #2
0
        public static double PDF(double x, double alpha, double beta, double abe, ref object tempStorage, double precision)
        {
            // Test for special case of symmetric destribution, this can be handled much better
            if (beta == 0)
            {
                return(StableDistributionSymmetric.PDF(x, alpha, ref tempStorage, precision));
            }

            // test input parameter
            if (!(alpha > 0 && alpha <= 2))
            {
                throw new ArgumentOutOfRangeException(string.Format("Alpha must be in the range (0,2], but was: {0}", alpha));
            }
            if (!(beta >= -1 && beta <= 1))
            {
                throw new ArgumentOutOfRangeException(string.Format("Beta must be in the range [-1,1], but was: {0}", beta));
            }

            if (alpha < 1)
            {
                ParameterConversionS0ToFeller(alpha, beta, abe, 1, 0, out var gamma, out var aga, out var sigmaf, out var muf);
                return(StableDistributionFeller.PDF((x - muf) / sigmaf, alpha, gamma, aga) / sigmaf);

                /*
                 *                      PdfEvaluationMethod method = GetEvaluationMethod(alpha, (x - muf) / sigmaf, abe == 0, beta < 0);
                 *                      switch (method)
                 *                      {
                 *                              case PdfEvaluationMethod.Integration:
                 *                      }
                 */
            }
            else if (alpha > 1)
            {
                ParameterConversionS0ToFeller(alpha, beta, abe, 1, 0, out var gamma, out var aga, out var sigmaf, out var muf);
                return(StableDistributionFeller.PDF((x - muf) / sigmaf, alpha, gamma, aga) / sigmaf);
            }
            else
            {
                return(PDFMethodAlphaOne(x, beta, abe, ref tempStorage, precision));
            }
        }
예제 #3
0
        public static double CDF(double x, double alpha, double beta, double abe, double scale, double location, ref object tempStorage, double precision)
        {
            // test input parameter
            if (!(alpha > 0 && alpha <= 2))
            {
                throw new ArgumentOutOfRangeException(string.Format("Alpha must be in the range (0,2], but was: {0}", alpha));
            }
            if (!(beta >= -1 && beta <= 1))
            {
                throw new ArgumentOutOfRangeException(string.Format("Beta must be in the range [-1,1], but was: {0}", beta));
            }

            if (alpha != 1)
            {
                ParameterConversionS0ToFeller(alpha, beta, abe, scale, location, out var gamma, out var aga, out var sigmaf, out var muf);
                return(StableDistributionFeller.CDF((x - muf) / sigmaf, alpha, gamma, aga, ref tempStorage, precision));
            }
            else
            {
                return(CDFMethodAlphaOne((x - location) / scale, beta, abe, ref tempStorage, precision));
            }
        }