From 0223cdd7ffff55c5cbbfb226f2096e107d9418cd Mon Sep 17 00:00:00 2001 From: Matt Judell Date: Wed, 18 Dec 2019 14:06:24 -0500 Subject: [PATCH 1/3] Added moments, partial moments, and some tests. --- arch/tests/univariate/test_moment.py | 65 ++++++++ arch/univariate/distribution.py | 239 ++++++++++++++++++++++++++- 2 files changed, 301 insertions(+), 3 deletions(-) create mode 100644 arch/tests/univariate/test_moment.py diff --git a/arch/tests/univariate/test_moment.py b/arch/tests/univariate/test_moment.py new file mode 100644 index 0000000000..41790b0380 --- /dev/null +++ b/arch/tests/univariate/test_moment.py @@ -0,0 +1,65 @@ +import pytest +from arch.univariate.distribution import (SkewStudent, Normal, StudentsT, + GeneralizedError) +from numpy import exp, inf, log, pi +from numpy.testing import assert_almost_equal +from scipy.integrate import quad +from scipy.special import gammaln + +DISTRIBUTIONS = [ + (SkewStudent(), [6, -0.1]), + (SkewStudent(), [6, -0.5]), + (SkewStudent(), [6, 0.1]), + (SkewStudent(), [6, 0.5]), + (GeneralizedError(), [1.5]), + (GeneralizedError(), [2.1]), + (StudentsT(), [6]), + (StudentsT(), [7]), + (Normal(), None)] + + +@pytest.mark.parametrize('dist, params', DISTRIBUTIONS) +def test_moment(dist, params): + """ + Ensures that Distribtion.moment and .partial_moment agree + with numeric integrals for order n=1,...,5 and z=+/-1,...,+/-5 + + Parameters + ---------- + dist : distribution.Distribution + The distribution whose moments are being checked + params : List + List of parameters + """ + + def f(x, n): + return (x**n) * exp(dist.loglikelihood(params, x, 1, True)) + + for n in range(1, 6): # moments 1-5 + + # complete moments + m_quad = quad(f, -inf, inf, args=n)[0] + m_method = dist.moment(n, params) + assert_almost_equal(m_quad, m_method) + + # partial moments at z=+/-1,...,+/-5 + # SkewT integral is broken up for numerical stability + for z in range(-5, 5): # partial moments at +-1,...,+-5 + if isinstance(dist, SkewStudent): + eta, lam = params + c = (gammaln((eta + 1) / 2) - gammaln(eta / 2) - + log(pi * (eta - 2)) / 2) + a = 4 * lam * exp(c) * (eta - 2) / (eta - 1) + b = (1 + 3 * lam ** 2 - a ** 2) ** .5 + loc = -a/b + if z < loc: + m_quad = quad(f, -inf, z, args=n)[0] + else: + m_quad = quad(f, -inf, loc-1e-9, args=n)[0] + \ + quad(f, loc+1e-9, z, args=n)[0] + + else: + m_quad = quad(f, -inf, z, args=n)[0] + + m_method = dist.partial_moment(n, z, params) + assert_almost_equal(m_quad, m_method) diff --git a/arch/univariate/distribution.py b/arch/univariate/distribution.py index ac75c1c1ae..189f4c6e44 100644 --- a/arch/univariate/distribution.py +++ b/arch/univariate/distribution.py @@ -5,10 +5,10 @@ """ from abc import abstractmethod -from numpy import (abs, array, asarray, empty, exp, isscalar, log, ones_like, - pi, sign, sqrt, sum) +from numpy import (abs, array, asarray, empty, exp, isscalar, log, nan, + ones_like, pi, sign, sqrt, sum) from numpy.random import RandomState -from scipy.special import gamma, gammaln +from scipy.special import comb, gamma, gammainc, gammaincc, gammaln import scipy.stats as stats from arch.utility.array import AbstractDocStringInheritor @@ -215,6 +215,59 @@ def cdf(self, resids, parameters=None): """ pass + @abstractmethod + def moment(self, n, parameters=None): + """ + Moment of order n + + Parameters + ---------- + n : int + Order of moment + parameters : ndarray, optional + Distribution parameters. Use None for parameterless distributions. + + Returns + ------- + float + Calculated moment + """ + pass + + @abstractmethod + def partial_moment(self, n, z=0, parameters=None): + r""" + Order n partial moment from -inf to z + + Parameters + ---------- + n : int + Order of partial moment + z : float, optional + Upper bound for partial moment integral + parameters : ndarray, optional + Distribution parameters. Use None for parameterless distributions. + + Returns + ------- + float + Partial moment + + References + ---------- + .. [1] Winkler et al. (1972) "The Determination of Partial Moments" + *Management Science* Vol. 19 No. 3 + + Notes + ----- + The order n partial moment to z is + + .. math:: + + \int_{-\infty}^{z}x^{n}f(x)dx + """ + pass + def __str__(self): return self._description() @@ -299,6 +352,20 @@ def ppf(self, pits, parameters=None): pits = asarray(pits) return stats.norm.ppf(pits) + def moment(self, n, parameters=None): + return stats.norm.moment(n) + + def partial_moment(self, n, z=0, parameters=None): + if n < 0: + return nan + elif n == 0: + return stats.norm.cdf(z) + elif n == 1: + return -stats.norm.pdf(z) + else: + return (-(z**(n-1)) * stats.norm.pdf(z) + + (n-1) * self.partial_moment(n-2, z, parameters)) + class StudentsT(Distribution): """ @@ -412,6 +479,58 @@ def ppf(self, pits, parameters=None): var = nu / (nu - 2) return stats.t(nu, scale=1.0 / sqrt(var)).ppf(pits) + def moment(self, n, parameters=None): + parameters = self._check_constraints(parameters) + nu = parameters[0] + var = nu / (nu - 2) + return stats.t.moment(n, nu, scale=1. / sqrt(var)) + + def partial_moment(self, n, z=0, parameters=None): + parameters = self._check_constraints(parameters) + nu = parameters[0] + var = nu / (nu - 2) + scale = 1. / sqrt(var) + moment = (scale**n) * self._ord_t_partial_moment(n, z/scale, nu) + return moment + + @staticmethod + def _ord_t_partial_moment(n, z, nu): + """ + Partial moments for ordinary parameterization of Students t df=nu + + Parameters + ---------- + n : int + Order of partial moment + z : float + Upper bound for partial moment integral + nu : float + Degrees of freedom + + Returns + ------- + float + Calculated moment + + References + ---------- + .. [1] Winkler et al. (1972) "The Determination of Partial Moments" + *Management Science* Vol. 19 No. 3 + """ + if n < 0 or n >= nu: + return nan + elif n == 0: + moment = stats.t.cdf(z, nu) + elif n == 1: + C = gamma(0.5*(nu+1)) / (sqrt(nu*pi) * gamma(0.5*nu)) + e = 0.5*(nu+1) + moment = (0.5 * (C * nu) / (1-e)) * ((1 + (z**2)/nu)**(1-e)) + else: + t1 = (z**(n-1)) * (nu + z**2) * stats.t.pdf(z, nu) + t2 = (n-1) * nu * StudentsT._ord_t_partial_moment(n-2, z, nu) + moment = (1/(n-nu)) * (t1 - t2) + return moment + class SkewStudent(Distribution): r""" @@ -650,6 +769,64 @@ def ppf(self, pits, parameters=None): icdf = icdf[0] return icdf + def moment(self, n, parameters=None): + parameters = self._check_constraints(parameters) + eta, lam = parameters + + if n < 0 or n >= eta: + return nan + + a = self.__const_a(parameters) + b = self.__const_b(parameters) + + loc = -a/b + lscale = sqrt(1 - 2/eta) * (1 - lam) / b + rscale = sqrt(1 - 2/eta) * (1 + lam) / b + + moment = 0. + for k in range(n+1): # binomial expansion around loc + # 0->inf right partial moment for ordinary t(eta) + r_pmom = 0.5 * (gamma(0.5*(k+1)) * gamma(0.5*(eta-k)) * + eta**(0.5*k)) / (sqrt(pi) * gamma(0.5*eta)) + l_pmom = ((-1)**k) * r_pmom + + lhs = (1-lam) * (lscale**k) * (loc**(n-k)) * l_pmom + rhs = (1+lam) * (rscale**k) * (loc**(n-k)) * r_pmom + moment += comb(n, k) * (lhs + rhs) + + return moment + + def partial_moment(self, n, z=0, parameters=None): + parameters = self._check_constraints(parameters) + eta, lam = parameters + + if n < 0 or n >= eta: + return nan + + a = self.__const_a(parameters) + b = self.__const_b(parameters) + + loc = -a/b + lscale = sqrt(1 - 2/eta) * (1 - lam) / b + rscale = sqrt(1 - 2/eta) * (1 + lam) / b + + moment = 0. + for k in range(n+1): # binomial expansion around loc + lbound = min(z, loc) + lhs = (1-lam) * (loc**(n-k)) * (lscale**k) * \ + StudentsT._ord_t_partial_moment(k, z=(lbound-loc)/lscale, nu=eta) + + if z > loc: + rhs = (1+lam) * (loc**(n-k)) * (rscale**k) * ( + StudentsT._ord_t_partial_moment(k, z=(z-loc)/rscale, nu=eta) - + StudentsT._ord_t_partial_moment(k, z=0., nu=eta)) + else: + rhs = 0. + + moment += comb(n, k) * (lhs + rhs) + + return moment + class GeneralizedError(Distribution): """ @@ -767,3 +944,59 @@ def cdf(self, resids, parameters=None): nu = parameters[0] var = stats.gennorm(nu).var() return stats.gennorm(nu, scale=1.0 / sqrt(var)).cdf(resids) + + def moment(self, n, parameters=None): + parameters = self._check_constraints(parameters) + nu = parameters[0] + var = stats.gennorm(nu).var() + return stats.gennorm.moment(n, nu, scale=1. / sqrt(var)) + + def partial_moment(self, n, z=0, parameters=None): + parameters = self._check_constraints(parameters) + nu = parameters[0] + scale = 1. / sqrt(stats.gennorm(nu).var()) + moment = (scale**n) * self._ord_gennorm_partial_moment(n, z/scale, nu) + return moment + + @staticmethod + def _ord_gennorm_partial_moment(n, z, beta): + r""" + Partial moment for ordinary generalized normal parameterization. + + Parameters + ---------- + n : int + Order of partial moment + z : float + Upper bound for partial moment integral + beta : float + Parameter of generalized normal + + Returns + ------- + float + Partial moment + + Notes + ----- + The standard parameterization follows: + + .. math:: + + f(x)=\frac{\beta}{2\Gamma(\beta^{-1})}\text{exp}\left(-|x|^{\beta}\right) + """ + w = 0.5 * beta / gamma((1/beta)) + + # integral over (-inf, min(z,0)) + lz = abs(min(z, 0))**beta + lterm = (w * ((-1)**n) * (1/beta) * gamma((n+1)/beta) * + gammaincc((n+1)/beta, lz)) + + # remaining integral + rz = max(0, z)**beta + rterm = (w * (1/beta) * gamma((n+1)/beta) * + gammainc((n+1)/beta, rz)) + + moment = lterm + rterm + + return moment From 9f8e9260bfdcb2a010919c989ddb9a59e15be7e1 Mon Sep 17 00:00:00 2001 From: Matt Judell Date: Thu, 19 Dec 2019 15:44:05 -0500 Subject: [PATCH 2/3] TST: increased coverage by testing invalid moments --- arch/tests/univariate/test_moment.py | 12 ++++++++---- arch/univariate/distribution.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/tests/univariate/test_moment.py b/arch/tests/univariate/test_moment.py index 41790b0380..8972fa269a 100644 --- a/arch/tests/univariate/test_moment.py +++ b/arch/tests/univariate/test_moment.py @@ -1,8 +1,8 @@ import pytest from arch.univariate.distribution import (SkewStudent, Normal, StudentsT, GeneralizedError) -from numpy import exp, inf, log, pi -from numpy.testing import assert_almost_equal +from numpy import exp, inf, log, nan, pi +from numpy.testing import assert_equal, assert_almost_equal from scipy.integrate import quad from scipy.special import gammaln @@ -22,7 +22,7 @@ def test_moment(dist, params): """ Ensures that Distribtion.moment and .partial_moment agree - with numeric integrals for order n=1,...,5 and z=+/-1,...,+/-5 + with numeric integrals for order n=0,...,5 and z=+/-1,...,+/-5 Parameters ---------- @@ -32,10 +32,14 @@ def test_moment(dist, params): List of parameters """ + assert_equal(dist.moment(-1, params), nan) + assert_equal(dist.partial_moment(-1, 0., params), nan) + + # verify moments that exist def f(x, n): return (x**n) * exp(dist.loglikelihood(params, x, 1, True)) - for n in range(1, 6): # moments 1-5 + for n in range(6): # moments 0-5 # complete moments m_quad = quad(f, -inf, inf, args=n)[0] diff --git a/arch/univariate/distribution.py b/arch/univariate/distribution.py index 189f4c6e44..6e8a07c6f6 100644 --- a/arch/univariate/distribution.py +++ b/arch/univariate/distribution.py @@ -353,6 +353,9 @@ def ppf(self, pits, parameters=None): return stats.norm.ppf(pits) def moment(self, n, parameters=None): + if n < 0: + return nan + return stats.norm.moment(n) def partial_moment(self, n, z=0, parameters=None): @@ -480,6 +483,9 @@ def ppf(self, pits, parameters=None): return stats.t(nu, scale=1.0 / sqrt(var)).ppf(pits) def moment(self, n, parameters=None): + if n < 0: + return nan + parameters = self._check_constraints(parameters) nu = parameters[0] var = nu / (nu - 2) @@ -946,6 +952,9 @@ def cdf(self, resids, parameters=None): return stats.gennorm(nu, scale=1.0 / sqrt(var)).cdf(resids) def moment(self, n, parameters=None): + if n < 0: + return nan + parameters = self._check_constraints(parameters) nu = parameters[0] var = stats.gennorm(nu).var() @@ -985,6 +994,9 @@ def _ord_gennorm_partial_moment(n, z, beta): f(x)=\frac{\beta}{2\Gamma(\beta^{-1})}\text{exp}\left(-|x|^{\beta}\right) """ + if n < 0: + return nan + w = 0.5 * beta / gamma((1/beta)) # integral over (-inf, min(z,0)) From 5a4aca869717ed21b597a211dc53c160f63f40a0 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Mon, 6 Jan 2020 14:41:07 +0000 Subject: [PATCH 3/3] DOC: Add final documentation Add final documentatio for moments and partial moments closes #329 --- arch/bootstrap/base.py | 37 ++--- arch/bootstrap/multiple_comparison.py | 36 +---- arch/unitroot/unitroot.py | 85 ----------- arch/univariate/base.py | 2 +- arch/univariate/distribution.py | 18 ++- doc/source/changes/4.0.txt | 5 +- doc/source/spelling_wordlist.txt | 207 +++++++++++++++++--------- 7 files changed, 178 insertions(+), 212 deletions(-) diff --git a/arch/bootstrap/base.py b/arch/bootstrap/base.py index c1e087b318..2d60d09612 100644 --- a/arch/bootstrap/base.py +++ b/arch/bootstrap/base.py @@ -126,8 +126,6 @@ class IIDBootstrap(object, metaclass=DocStringInheritor): Attributes ---------- - index : ndarray - The current index of the bootstrap data : tuple Two-element tuple with the pos_data in the first position and kw_data in the second (pos_data, kw_data) @@ -135,8 +133,6 @@ class IIDBootstrap(object, metaclass=DocStringInheritor): Tuple containing the positional arguments (in the order entered) kw_data : dict Dictionary containing the keyword arguments - random_state : RandomState - RandomState instance used by bootstrap Notes ----- @@ -242,7 +238,19 @@ def _repr_html(self): @property def random_state(self): - """Set or get the instance random state""" + """ + Set or get the instance random state + + Parameters + ---------- + random_state : RandomState + RandomState instance used by bootstrap + + Returns + ------- + RandomState + RandomState instance used by bootstrap + """ return self._random_state @random_state.setter @@ -254,7 +262,7 @@ def random_state(self, value): @property def index(self): """ - Returns the current index of the bootstrap + The current index of the bootstrap """ return self._index @@ -278,7 +286,6 @@ def set_state(self, state): state : RandomState state vector Array containing the state """ - return self.random_state.set_state(state) def seed(self, value): @@ -907,8 +914,6 @@ class IndependentSamplesBootstrap(IIDBootstrap): Attributes ---------- - index : ndarray - The current index of the bootstrap data : tuple Two-element tuple with the pos_data in the first position and kw_data in the second (pos_data, kw_data) @@ -916,8 +921,6 @@ class IndependentSamplesBootstrap(IIDBootstrap): Tuple containing the positional arguments (in the order entered) kw_data : dict Dictionary containing the keyword arguments - random_state : RandomState - RandomState instance used by bootstrap Notes ----- @@ -1064,8 +1067,6 @@ class CircularBlockBootstrap(IIDBootstrap): Attributes ---------- - index : ndarray - The current index of the bootstrap data : tuple Two-element tuple with the pos_data in the first position and kw_data in the second (pos_data, kw_data) @@ -1073,8 +1074,6 @@ class CircularBlockBootstrap(IIDBootstrap): Tuple containing the positional arguments (in the order entered) kw_data : dict Dictionary containing the keyword arguments - random_state : RandomState - RandomState instance used by bootstrap Notes ----- @@ -1167,8 +1166,6 @@ class StationaryBootstrap(CircularBlockBootstrap): Attributes ---------- - index : ndarray - The current index of the bootstrap data : tuple Two-element tuple with the pos_data in the first position and kw_data in the second (pos_data, kw_data) @@ -1176,8 +1173,6 @@ class StationaryBootstrap(CircularBlockBootstrap): Tuple containing the positional arguments (in the order entered) kw_data : dict Dictionary containing the keyword arguments - random_state : RandomState - RandomState instance used by bootstrap Notes ----- @@ -1245,8 +1240,6 @@ class MovingBlockBootstrap(CircularBlockBootstrap): Attributes ---------- - index : ndarray - The current index of the bootstrap data : tuple Two-element tuple with the pos_data in the first position and kw_data in the second (pos_data, kw_data) @@ -1254,8 +1247,6 @@ class MovingBlockBootstrap(CircularBlockBootstrap): Tuple containing the positional arguments (in the order entered) kw_data : dict Dictionary containing the keyword arguments - random_state : RandomState - RandomState instance used by bootstrap Notes ----- diff --git a/arch/bootstrap/multiple_comparison.py b/arch/bootstrap/multiple_comparison.py index db29edbf3d..94e03de449 100644 --- a/arch/bootstrap/multiple_comparison.py +++ b/arch/bootstrap/multiple_comparison.py @@ -49,7 +49,7 @@ def reset(self): def seed(self, value): """ - Seeds the bootstrap's random number generator + Seed the bootstrap's random number generator Parameters ---------- @@ -85,11 +85,6 @@ class MCS(MultipleComparison): 'circular' or 'cbb': Circular block bootstrap 'moving block' or 'mbb': Moving block bootstrap - Methods - ------- - compute - Compute the set ofmodels in the confidence set. - References ---------- Hansen, P. R., Lunde, A., & Nason, J. M. (2011). The model confidence set. @@ -156,7 +151,7 @@ def _format_pvalues(self, eliminated): def compute(self): """ - Computes the model confidence set + Compute the set of models in the confidence set. """ if self.method.lower() == 'r': self._compute_r() @@ -339,11 +334,6 @@ class StepM(MultipleComparison): studentization. Default is False. Note that this can be slow since the procedure requires k extra bootstraps. - Methods - ------- - compute - Compute the set of superior models. - References ---------- Romano, J. P., & Wolf, M. (2005). "Stepwise multiple testing as formalized @@ -388,7 +378,7 @@ def __init__(self, benchmark, models, size=0.05, block_size=None, def compute(self): """ - Computes the set of superior models + Compute the set of superior models. """ # 1. Run SPA self.spa.compute() @@ -461,19 +451,6 @@ class SPA(MultipleComparison, metaclass=DocStringInheritor): studentization. Default is False. Note that this can be slow since the procedure requires k extra bootstraps. - Methods - ------- - compute - Compute the bootstrap pvalue. Must be called before accessing the - pvalue - seed - Pass seed to bootstrap implementation - reset - Reset the bootstrap to its initial state - better_models - Produce a list of column indices or names (if models is a DataFrame) - that are rejected given a test size - References ---------- White, H. (2000). "A reality check for data snooping." Econometrica 68, @@ -535,7 +512,7 @@ def __init__(self, benchmark, models, block_size=None, reps=1000, def reset(self): """ - Reset the bootstrap to it's initial state. + Reset the bootstrap to its initial state. """ super(SPA, self).reset() self._pvalues = None @@ -555,8 +532,11 @@ def subset(self, selector): def compute(self): """ - Compute the bootstrap p-value + Compute the bootstrap pvalue. + Notes + ----- + Must be called before accessing the pvalue. """ # Plan # 1. Compute variances diff --git a/arch/unitroot/unitroot.py b/arch/unitroot/unitroot.py index ee7082b47d..cd83f636a9 100644 --- a/arch/unitroot/unitroot.py +++ b/arch/unitroot/unitroot.py @@ -537,20 +537,6 @@ class ADF(UnitRootTest, metaclass=DocStringInheritor): to be used in very long time series. If None, use automatic selection of algorithm. - Attributes - ---------- - stat - pvalue - critical_values - null_hypothesis - alternative_hypothesis - summary - regression - valid_trends - y - trend - lags - Notes ----- The null hypothesis of the Augmented Dickey-Fuller is that there is a unit @@ -684,20 +670,6 @@ class DFGLS(UnitRootTest, metaclass=DocStringInheritor): 'BIC' - Select the minimum of the Schwarz/Bayesian IC 't-stat' - Select the minimum of the Schwarz/Bayesian IC - Attributes - ---------- - stat - pvalue - critical_values - null_hypothesis - alternative_hypothesis - summary - regression - valid_trends - y - trend - lags - Notes ----- The null hypothesis of the Dickey-Fuller GLS is that there is a unit @@ -851,20 +823,6 @@ class PhillipsPerron(UnitRootTest, metaclass=DocStringInheritor): the t-stat and 'rho' uses a test based on nobs times the re-centered regression coefficient - Attributes - ---------- - stat - pvalue - critical_values - test_type - null_hypothesis - alternative_hypothesis - summary - valid_trends - y - trend - lags - Notes ----- The null hypothesis of the Phillips-Perron (PP) test is that there is a @@ -1025,19 +983,6 @@ class KPSS(UnitRootTest, metaclass=DocStringInheritor): 'c' - Include a constant (Default) 'ct' - Include a constant and linear time trend - Attributes - ---------- - stat - pvalue - critical_values - null_hypothesis - alternative_hypothesis - summary - valid_trends - y - trend - lags - Notes ----- The null hypothesis of the KPSS test is that the series is weakly @@ -1180,20 +1125,6 @@ class ZivotAndrews(UnitRootTest, metaclass=DocStringInheritor): 'BIC' - Select the minimum of the Schwarz/Bayesian IC 't-stat' - Select the minimum of the Schwarz/Bayesian IC - Attributes - ---------- - stat - pvalue - critical_values - null_hypothesis - alternative_hypothesis - summary - regression - valid_trends - y - trend - lags - Notes ----- H0 = unit root with a single structural break @@ -1360,22 +1291,6 @@ class VarianceRatio(UnitRootTest, metaclass=DocStringInheritor): Indicates whether to use a debiased version of the test. Default is True. Only applicable if overlap is True. - Attributes - ---------- - stat - pvalue - critical_values - null_hypothesis - alternative_hypothesis - summary - valid_trends - y - trend - lags - overlap - robust - debiased - Notes ----- The null hypothesis of a VR is that the process is a random walk, possibly diff --git a/arch/univariate/base.py b/arch/univariate/base.py index 37b6f0c52e..0ff4c2fe42 100644 --- a/arch/univariate/base.py +++ b/arch/univariate/base.py @@ -1625,7 +1625,7 @@ def convergence_flag(self): @property def optimization_result(self): """ - Information about the covergence of theloglikelihood optimization + Information about the covergence of the loglikelihood optimization Returns ------- diff --git a/arch/univariate/distribution.py b/arch/univariate/distribution.py index 6e8a07c6f6..ad725a5f23 100644 --- a/arch/univariate/distribution.py +++ b/arch/univariate/distribution.py @@ -237,7 +237,7 @@ def moment(self, n, parameters=None): @abstractmethod def partial_moment(self, n, z=0, parameters=None): r""" - Order n partial moment from -inf to z + Order n lower partial moment from -inf to z Parameters ---------- @@ -260,11 +260,13 @@ def partial_moment(self, n, z=0, parameters=None): Notes ----- - The order n partial moment to z is + The order n lower partial moment to z is .. math:: \int_{-\infty}^{z}x^{n}f(x)dx + + See [1]_ for more details. """ pass @@ -501,7 +503,7 @@ def partial_moment(self, n, z=0, parameters=None): @staticmethod def _ord_t_partial_moment(n, z, nu): - """ + r""" Partial moments for ordinary parameterization of Students t df=nu Parameters @@ -522,6 +524,16 @@ def _ord_t_partial_moment(n, z, nu): ---------- .. [1] Winkler et al. (1972) "The Determination of Partial Moments" *Management Science* Vol. 19 No. 3 + + Notes + ----- + The order n lower partial moment to z is + + .. math:: + + \int_{-\infty}^{z}x^{n}f(x)dx + + See [1]_ for more details. """ if n < 0 or n >= nu: return nan diff --git a/doc/source/changes/4.0.txt b/doc/source/changes/4.0.txt index 94fbf01c75..109892a663 100644 --- a/doc/source/changes/4.0.txt +++ b/doc/source/changes/4.0.txt @@ -4,7 +4,10 @@ Version 4 Since 4.11 ========== -Fixed a bug that produced an OverflowError when a time series has no variance (:issue:`331`). +- Added methods to compute moment and lower partial moments for standardized residuals. See, + for example, :func:`~arch.univariate.SkewStudent.moment` and + :func:`~arch.univariate.SkewStudent.partial_moment` (:issue:`329`). +- Fixed a bug that produced an OverflowError when a time series has no variance (:issue:`331`). Release 4.11 ============ diff --git a/doc/source/spelling_wordlist.txt b/doc/source/spelling_wordlist.txt index 95eefc0bc0..2754980a0d 100644 --- a/doc/source/spelling_wordlist.txt +++ b/doc/source/spelling_wordlist.txt @@ -1,101 +1,166 @@ -arch -stationarity -Statistica -Statsmodel -StepM -Stepwise -studentization -studentize -Studentized -subclassing -univariate -unstandardized -VolatilityProcess -VaR -regressand -regressor -reproducibility -resampled -resamples -rescaled -resids -semidefinite -Semiparametric -skewness -skewstudent -skewt -sqrt -Familywise -forecastable -ftol -func -GARCH -gaussian -GLS -heteroskedasticity -iid -Nonparametric -nonrobust -nparam ADF -ARCHModel -Autoregression -Autoregressions -Autoregressive -BCa -Covariance -Datetimes +aic +al +andrews annualize +arch +ARCHModel +ARCHModelFixedResult +ARCHModelResult +args +arx autocorrelation autocorrelations autolag +Autoregression +Autoregressions +Autoregressive +ba backcast backcasting +bartlett bashtage +bc +BCa +bca +bic cbb +cdf Centerings +centerings +CircularBlockBootstrap cointegration -arx +conf +ConstantMean +ConstantVariance +cov +Covariance +covariance +covariances +covergence +ctt +datetime +Datetimes +debiased +dependant +detrending +DF +DFGLS +differencing +disp +econometrics +EGARCH +eps +EWMAVariance +expon +Familywise +familywise +FIGARCH +FixedVariance +forecastable +ftol +func +GARCH +gaussian +ged +GeneralizedError +GLS +HARCH +HARX +heteroskedasticity +iid +IIDBootstrap +IndependentSamplesBootstrap ith jit jth kmax +KPSS kurtosis +kwargs +len +lm loadings Loglikelihood +loglikelihood maxiter maxlag mbb +MCS +MIDASHyperbolic +MovingBlockBootstrap NaN +nan +nc ndarray +ndarrays +Nonparametric +nonparametric +nonrobust +nparam +num +nw +param +parameterless +params +parzen +PhillipsPerron +pos +ppf +pre +Probit pvalue pvalues +qs quantiles quartile -Probit +Rabba +regressand +regressor +reproducibility +resampled +resamples +rescaled +resid +resids +RiskMetrics +rng +rsquared +sb +scipy +semidefinite +Semiparametric +semiparametric +skewness +skewstudent +SkewStudent +skewt +sqrt +stationarity +StationaryBootstrap +Statistica +Statsmodel +StepM +Stepwise +stepwise +studentization +studentize +Studentized +studentized studentst -covariances -datetime -debiased -dependant -detrending -DF -differencing -cov -disp +StudentsT +subclassing +th +tvalues +unitroot +univariate +unstandardized +VaR +VarianceRatio +VolatilityProcess +vr +Winkler zag +ZeroMean zig -al -nan -nonparametric -studentized -stepwise -th -expon -pos -semiparametric -familywise -covariance -pre -centerings - +ZivotAndrews