varwg.time_series_analysis package¶
Submodules¶
varwg.time_series_analysis.distributions module¶
- class varwg.time_series_analysis.distributions.Beta[source]¶
Bases:
DistBeta distribution on the interval [l, u].
- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 4¶
- name = 'beta'¶
- parameter_names = ('alpha', 'beta', 'l', 'u')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Cauchy[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 2¶
- name = 'cauchy'¶
- parameter_names = ('x0', 'gamma')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Censored(distribution, lc=-inf, uc=inf)[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
constraints
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 0¶
- name = 'censored'¶
- parameter_names = ()¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Dist[source]¶
Bases:
objectMimics part of the interface of stats.rv_continuous. Comes with a few extra goodies.
- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- class Result(x, supplements, success)¶
Bases:
tupleMethods
count(value, /)Return number of occurrences of value.
index(value[, start, stop])Return first index of value.
- success¶
Alias for field number 2
- supplements¶
Alias for field number 1
- x¶
Alias for field number 0
- isscipy = False¶
- n_pars = 0¶
- name = 'dist'¶
- parameter_names = ()¶
- property scipy_¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.DistMeta(name, bases, cls_dict)[source]¶
Bases:
ABCMetaAssure some class attributes are set, so that life is easier later on.
Methods
__call__(*args, **kwargs)Call self as a function.
mro(/)Return a type's method resolution order.
register(subclass)Register a virtual subclass of an ABC.
- class varwg.time_series_analysis.distributions.Expon[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 2¶
- name = 'expon'¶
- parameter_names = ('x0', 'lambd')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.ExponTwo[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 4¶
- name = 'expontwo'¶
- parameter_names = ('x0', 'q0', 'lambda1', 'lambda2')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Frozen(dist, *params)[source]¶
Bases:
object- Attributes:
meanCrude estimation of the expected value.
- median
- parameter_dict
Methods
plot_fit([values, n_classes])Display a combined plot of a histogram, fitted pdf, empirical cdf and fitted cdf.
plot_qq(values, *args, **kwds)A qq-plot.
cdf
pdf
ppf
sample
- property mean¶
Crude estimation of the expected value. Heavy tails break this!
- property median¶
- property parameter_dict¶
- class varwg.time_series_analysis.distributions.Gamma[source]¶
Bases:
DistGamma distribution.
- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 2¶
- name = 'gamma'¶
- parameter_names = ('k', 'theta')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Gamma1[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 3¶
- name = 'gamma1'¶
- parameter_names = ('a', 'loc', 'scale')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.JohnsonSU[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 4¶
- name = 'johnsonsu'¶
- parameter_names = ('a', 'b', 'loc', 'scale')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Kumaraswamy[source]¶
Bases:
DistResembles the Beta distribution, but does not need a transcendental function.
- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 4¶
- name = 'kumaraswamy'¶
- parameter_names = ('a', 'b', 'l', 'u')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.LogNormal[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 2¶
- name = 'lognormal'¶
- parameter_names = ('mu', 'sigma')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.MDFt[source]¶
Bases:
objectMultiple degrees of freedom t distribution.
The marginals have different degrees of freedom, therefore this is not a “true” Multivariate t distribution. See Serban et al 2007.
Methods
fit
loglikelihood
sample
- class varwg.time_series_analysis.distributions.NoncentralLaplace[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 3¶
- name = 'noncentrallaplace'¶
- parameter_names = ('x0', 'q0', 'lambd')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.NoncentralT[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 3¶
- name = 'noncentralt'¶
- parameter_names = ('df', 'nc', 'mu')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Normal[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 2¶
- name = 'normal'¶
- parameter_names = ('mu', 'sigma')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Rain(distribution, threshold=0.0001)[source]¶
Bases:
_Rain- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 1¶
- name = 'rain'¶
- parameter_names = ('rain_prob',)¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.RainMix(distribution, threshold=0.0015, q_thresh_lower=0.6, q_thresh_upper=0.95)[source]¶
Bases:
_KDE,_Rain- Attributes:
- scipy_
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
fit_ml(x[, x0, bounds])This is a lie, we don't fit rainmix with ML.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_kde
fit_ks
median
pdf
ppf
sample
- fit_ml(x, x0=None, bounds=None, *args, **kwds)[source]¶
This is a lie, we don’t fit rainmix with ML.
- n_pars = 2¶
- name = 'rainmix'¶
- parameter_names = ('q_thresh', 'rain_prob', 'kernel_width', 'kernel_data', 'f_thresh', 'q_kde_eval', 'x_eval')¶
- supplements_names = ('q_thresh', 'f_thresh', 'kernel_data', 'q_kde_eval', 'x_eval')¶
- class varwg.time_series_analysis.distributions.StudentT[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 2¶
- name = 'studentt'¶
- parameter_names = ('mu', 'df')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Truncated(distribution, lc=-inf, uc=inf)[source]¶
Bases:
DistWraps around any other distribution found here to truncate its upper and/or lower tail.
- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
constraints
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 0¶
- name = 'truncated'¶
- parameter_names = ()¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.TruncatedNormal[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 4¶
- name = 'truncatednormal'¶
- parameter_names = ('mu', 'sigma', 'lc', 'uc')¶
- supplements_names = None¶
- class varwg.time_series_analysis.distributions.Weibull[source]¶
Bases:
Dist- Attributes:
- scipy_
- supplements_names
Methods
Result(x, supplements, success)__call__(*params)Call self as a function.
mean(*args, **kwds)Crude estimation of the expected value.
cdf
fit
fit_fsum
fit_ks
fit_ml
median
pdf
ppf
sample
- n_pars = 2¶
- name = 'weibull'¶
- parameter_names = ('alpha', 'beta')¶
- supplements_names = None¶
- varwg.time_series_analysis.distributions.max_likelihood(density_func, x0, values=None, opt_func=None, disp=False, weights=None, method='BFGS', bounds=None, *args, **kwds)[source]¶
Fits parameters of a density function to data, using the log-maximum- likelihood approach.
varwg.time_series_analysis.models module¶
Various functions for time series anlysis. If not specified differently, references are given on Luetkepohl “New Introduction to Multiple Time Series Analysis”.
Least-Squares parameter estimation for a vector auto-regressive model of the form Y = B*Z + U. |
|
Based on a least squares estimator, simulate a time-series of the form ..math::y(t) = nu + A1*y(t-1) + . |
|
Least-Squares parameter estimation for a vector auto-regressive model of the form |
|
Based on a least squares estimator, simulate a time-series of the form ..math::y(t) = A1*y(t-1) + . |
|
Order selection for VAR processes to allow parsimonious parameterization. |
|
Based on a least squares estimator, predict a time-series of the form ..math::y(t) = nu + A1*y(t-1) + . |
|
Akaike Information Criterion for order selection of a VAR process. |
|
Final prediction error. |
|
Hannan-Quinn for VAR_LS order selection (p.150). |
|
Schwarz criterion for VAR_LS order selection (p.150). |
- varwg.time_series_analysis.models.AIC(sigma_u, p, T)[source]¶
Akaike Information Criterion for order selection of a VAR process. See p.147
- varwg.time_series_analysis.models.HQ(sigma_u, p, T)[source]¶
Hannan-Quinn for VAR_LS order selection (p.150). To be minimized.
- varwg.time_series_analysis.models.MGARCH_ML(residuals, q, m)[source]¶
Estimating MGARCH parameters by numerically maximizing the log-likelihood.
- varwg.time_series_analysis.models.MGARCH_sim(params, T, sigma0, epsilon=None, n_presim_steps=100)[source]¶
- varwg.time_series_analysis.models.SC(sigma_u, p, T)[source]¶
Schwarz criterion for VAR_LS order selection (p.150). To be minimized.
- varwg.time_series_analysis.models.SVAR_LS(data, doys, p=2, doy_width=60, fft_order=3, var_names=None, verbose=True)[source]¶
Seasonal version of the least squares estimator.
- varwg.time_series_analysis.models.SVAR_LS_fill(Bs, sigma_us, doys, Y, A=None, m=None, ia=None, m_trend=None, n_presim_steps=100, fixed_data=None, p_kwds=None)[source]¶
- varwg.time_series_analysis.models.SVAR_LS_sim(Bs, sigma_us, doys, m=None, ia=None, m_trend=None, u=None, n_presim_steps=100, fixed_data=None, phase_randomize=False, rphases=None, return_rphases=False, p_kwds=None, taboo_period_min=None, taboo_period_max=None, verbose=False)[source]¶
- varwg.time_series_analysis.models.VAREX_LS(data, p, ex)[source]¶
Least-Squares parameter estimation for a vector auto-regressive model of the form
..math::y_t = A_1 y_{t-1} + … + A_p y_{t-p} + C x_t + u_t
Records containing nans are excluded. Refer to the Least-Squares Estimator example 3.2.3 p.78. for method and variable names.
- Parameters:
- data(K, T) ndarray
K is the number of variables, T the number of timesteps
- ex(T,) ndarray
An external variable
- pint
Autoregressive order of the process.
- Returns:
- Barray
Parameters of the fitted VAR-process. B := (A_1, …, A_p, C)
- sigma_u: array
Covariance matrix of the residuals of the data.
See also
VAR_order_selectionHelps to find a p for parsimonious estimation.
VAR_residualsReturns the residuals based on given data and LS estimator
VAR_LS_simSimulation based on LS estimator.
VAR_LS_predictPredict given prior data and LS estimator.
- varwg.time_series_analysis.models.VAREX_LS_sim(B, sigma_u, T, ex, m=None, ia=None, m_trend=None, u=None, n_presim_steps=100, prev_data=None, ex_kwds=None)[source]¶
Based on a least squares estimator, simulate a time-series of the form ..math::y(t) = A1*y(t-1) + … + Ap*y(t-p) + C*x(t-1) + ut B contains (A1, …, Ap, C). See p. 707f
- Parameters:
- B(K, K*p+1) ndarray
Parameters of the VAR-process as returned from VAR_LS. K is the number of variables, p the autoregressive order.
- sigma_u(K, K) ndarray
Covariance matrix of the residuals as returned from VAR_LS.
- ex(T,) ndarray or function
External variable. If given as a function, ex_t will be generated by calling ex(Y[:t], **ex_kwds), with Y being the simulated values.
- Tint
Number of timesteps to simulate.
- m(K,) ndarray, optional
Process means (will be scaled according to B).
- ia(K, T) ndarray, optional
Interannual variability. Additional time-varying disturbance to the process means (will be scaled according to B).
- m_trend(K,) ndarray, optional
Change in means, that will be applied linearly so that this change is reached after the T timesteps.
- u(K, T) ndarray, optional
Residuals to be used instead of multivariate gaussian serially independent random numbers.
- n_presim_stepsint, optional
Number of presimulation timesteps that will be thrown away.
- ex_kwdsdict, optional
Keyword arguments to be passed to ex.
- Returns:
- Y(K, T) ndarray
Simulated values.
- ex_out(T,) ndarray
External variable.
See also
VAR_LSLeast-squares estimator (to get B and sigma_u).
VAR_order_selectionHelps to find a p for parsimonious estimation.
VAR_residualsReturns the residuals based on given data and LS estimator
VAR_LS_predictPredict given prior data and LS estimator.
- varwg.time_series_analysis.models.VARMA_LS(data, p, q, rel_change=0.001)[source]¶
Implementation of the scoring algorithm to fit a VARMA model. p.470ff
- varwg.time_series_analysis.models.VARMA_LS_prelim(data, p, q)[source]¶
Preliminary version of the general simple least-squares vector autoregressive estimator for a vector autoregressive moving-average process. See p.474ff
- varwg.time_series_analysis.models.VARMA_LS_sim(AM, p, q, sigma_u, means, T, S=None, m=None, ia=None, m_trend=None, n_sim_multiple=2, fixed_data=None)[source]¶
Generates a time series based on the VARMA-parameters AM. S and m should be sequences of length K. S is a variable-discerning multiplier and m a adder, respectively.
- Parameters:
- AM(K,K*(p+q)) array
The parameters of the VARMA-process. The first p columns are interpreted as the Ai-matrices of the auto regressive part. The last q columns as the Mi-matrices of the moving average part. K is the number of variables simulated.
- pinteger
Order of the auto regressive process.
- qinteger
Order of the moving average process.
- sigma_u(K,K) array
Covariance matrix of the residuals.
- means(K,) array
Process means. Used as starting values.
- Tinteger
Desired length of the output time series.
- S(K,K) array, optional
Used as multiplicative change of the disturbance vector to increase the variance of the output.
- m(K,T) array_like, optional
Used as additive change during simulation to increase mean of the output.
- n_sim_multipleinteger
Generate n_sim_multiple * T timesteps. Only the last T timesteps will be returned.
- ia(K,T) array_like, optional
Interannual variability. Used as an additive change during simulation to get time-dependent disturbances.
- m_trend(K,) array_like, optional
Used as additive change gradient during simulation to increase mean of the output gradually.
- fixed_data(K,T) array_like, optional
Keeps the provided time-series fixed. Use np.nans to signify values that are not fixed. Can be used to simulate hierarchically.
- Returns:
- out(K, T) ndarray
K-dimensional simulated time series.
- varwg.time_series_analysis.models.VARMA_order_selection(data, p_max=5, q_max=5, criterion=<function SC>, plot_table=False, *args, **kwds)[source]¶
Returns p and q, the orders of a VARMA process that allows for parsimonious parameterization. Naive extension of VAR_order_selection without a theoretical basis!
- varwg.time_series_analysis.models.VAR_LS(data, p=2, biased=True)[source]¶
Least-Squares parameter estimation for a vector auto-regressive model of the form Y = B*Z + U. Records containing nans are excluded. Refer to the Least-Squares Estimator example 3.2.3 p.78. for method and variable names.
- Parameters:
- data(K, T) ndarray
K is the number of variables, T the number of timesteps
- pint
Autoregressive order of the process.
- Returns:
- Barray
Parameters of the fitted VAR-process.
- sigma_uarray
Covariance matrix of the residuals.
- biasedbool, optional
If true, use the number of non-nan observations (n_obs) to ‘unbias’ sigma_u. Otherwise, use n_obs - K * p - 1.
See also
VAR_order_selectionHelps to find a p for parsimonious estimation.
VAR_residualsReturns the residuals based on given data and LS estimator
VAR_LS_simSimulation based on LS estimator.
VAR_LS_predictPredict given prior data and LS estimator.
- varwg.time_series_analysis.models.VAR_LS_asy(data, skewed_i, p=None)[source]¶
Skewness of the differences of the residuals.
- varwg.time_series_analysis.models.VAR_LS_extro(data, data_trans, transforms, backtransforms, p=2)[source]¶
- varwg.time_series_analysis.models.VAR_LS_predict(data_past, B, sigma_u, T=1, n_realizations=1)[source]¶
Based on a least squares estimator, predict a time-series of the form ..math::y(t) = nu + A1*y(t-1) + … + Ap*y(t-p) + ut B contains (nu, A1, …, Ap).
- Parameters:
- data_past(K, p) ndarray
- B(K, p * K + 1) ndarray
Parameters of the VAR-process of order p.
- sigma_u(K, K) ndarray
Covariance matrix of the residuals of the VAR-process.
- Tint
Number of timesteps to predict.
- n_realizationsint
Number of realizations. If > 1, gaussian disturbances are added. So if n_realizations=1, the prediction is a best guess.
- Returns:
- Y(K, T) or (K, T, n_realizations) ndarray
References
See p. 707f
- varwg.time_series_analysis.models.VAR_LS_sim(B, sigma_u, T, m=None, ia=None, m_trend=None, u=None, n_presim_steps=100, fixed_data=None, prev_data=None, transform=None, phase_randomize=False, rphases=None, return_rphases=False, p_kwds=None, taboo_period_min=None, taboo_period_max=None)[source]¶
Based on a least squares estimator, simulate a time-series of the form ..math::y(t) = nu + A1*y(t-1) + … + Ap*y(t-p) + ut B contains (nu, A1, …, Ap). See p. 707f
- Parameters:
- B(K, K*p+1) ndarray
Parameters of the VAR-process as returned from VAR_LS. K is the number of variables, p the autoregressive order.
- sigma_u(K, K) ndarray
Covariance matrix of the residuals as returned from VAR_LS.
- Tint
Number of timesteps to simulate.
- m(K,) ndarray, optional
Process means (will be scaled according to B).
- ia(K, T) ndarray, optional
Interannual variability. Additional time-varying disturbance to the process means (will be scaled according to B).
- m_trend(K,) ndarray, optional
Change in means, that will be applied linearly so that this change is reached after the T timesteps.
- u(K, T) ndarray, optional
Residuals to be used instead of multivariate gaussian serially independent random numbers.
- n_presim_stepsint, optional
Number of presimulation timesteps that will be thrown away.
- fixed_data(K, T) ndarray, optional
Data that will be fixed, i.e. at each timestep, these will be put in instead of the actual simulated values. Where fixed_data is nan, the simulated values will not be overwritten.
- transformcallable, optional
On-the-fly transformation that accepts a sequence of length K (values of all variables at one time step) and the time index t.
- Returns:
- Y(K, T) ndarray
Simulated values.
See also
VAR_LSLeast-squares estimator (to get B and sigma_u).
VAR_order_selectionHelps to find a p for parsimonious estimation.
VAR_residualsReturns the residuals based on given data and LS estimator
VAR_LS_predictPredict given prior data and LS estimator.
- varwg.time_series_analysis.models.VAR_LS_sim_asy(B, sigma_u, T, data, p, skewed_i, n_presim_steps=100, verbose=False, var_names=None, *args, **kwds)[source]¶
- varwg.time_series_analysis.models.VAR_YW(data, p=2)[source]¶
Yule-Walker parameter estimation for a vector auto-regressive model of the form Y^0 = A*X + U Refer to p. 83ff. Here we assume that the data is already mean-adjusted!
- varwg.time_series_analysis.models.VAR_YW_sim(A, sigma_u, T)[source]¶
Based on a Yule-Walker estimator, simulate a time-series of the form ..math:: y(t) = A_1*y(t-1) + … + A_p*y(t-p) + u(t) A contains (A1, …, Ap). See p. 707f
- varwg.time_series_analysis.models.VAR_order_selection(data, p_max=10, criterion=<function SC>, estimator=<function VAR_LS>, est_kwds=None)[source]¶
Order selection for VAR processes to allow parsimonious parameterization.
- Parameters:
- data(K, T) ndarray
Input data with K variables and T timesteps.
- p_maxint, optional
Maximum number of autoregressive order to evaluate.
- criterionfunction, optional
Information criterion that accepts sigma_u, p, and T and returns something that gives small values for a parsimonious set of these parameters.
- Returns:
- pint
Suggested autoregressive order.
See also
AICAkaike Information criterion
FPEFinal Prediction Error
HQHannan-Quinn information criterion
SCSchwartz Criterion
VAR_LSLeast-squares estimator.
VAR_residualsReturns the residuals based on given data and LS estimator
VAR_LS_simSimulation based on LS estimator.
VAR_LS_predictPredict given prior data and LS estimator.
- class varwg.time_series_analysis.models.mgarch_param_factory(gamma0, Gammas, Gs, cov_residuals)¶
Bases:
tupleMethods
count(value, /)Return number of occurrences of value.
index(value[, start, stop])Return first index of value.
- Gammas¶
Alias for field number 1
- Gs¶
Alias for field number 2
- cov_residuals¶
Alias for field number 3
- gamma0¶
Alias for field number 0
- varwg.time_series_analysis.models.sqrtm(A)[source]¶
Square root of a positive-definite Matrix.
>>> A = np.array([[4., 0, 0], [0, 9., 0], [0, 0, 16.]]) >>> sqrtm(A) array([[2., 0., 0.], [0., 3., 0.], [0., 0., 4.]])
Notes
See Appendix 9.4.
- varwg.time_series_analysis.models.unvec(sequence, K)[source]¶
The inverse of vec.
>>> a = list(range(6)) >>> a [0, 1, 2, 3, 4, 5] >>> unvec(a, K=2) array([[0, 2, 4], [1, 3, 5]]) >>> A = np.array([[0, 3, 1, 4, 2, 5]]).T >>> unvec(A, K=2) array([[0, 1, 2], [3, 4, 5]])
- varwg.time_series_analysis.models.unvech(sequence, K)[source]¶
The inverse of vech.
>>> a = np.array([0, 2, 3]) >>> unvech(a, K=2) array([[0., 2.], [2., 3.]])
varwg.time_series_analysis.optimize module¶
- varwg.time_series_analysis.optimize.simulated_annealing(func, x0, args=(), k=0.99, M=None, step_length=None, T0=None, step_length0=5, feps=1e-05, constraints=None, callback=None)[source]¶
Simulated Annealing algorithm with support for constraints, estimation for acceptance rate based initial temperature and gradient based calculation of the step lengths.
varwg.time_series_analysis.phase_randomization module¶
varwg.time_series_analysis.seasonal module¶
This provides common ground for seasonal_distributions and seasonal_kde.
- class varwg.time_series_analysis.seasonal.Seasonal(data, datetimes, kill_leap=False)[source]¶
Bases:
object- Attributes:
- hours
- hours_per_day
- n_years
Methods
doys2doys_ii(doys)Doys indices from doy values.
duplicate_feb28(doys)Put doys in the range [1, 365] by duplicating February 28th and decrementing all following doys of the year.
qq_shift(theta_incr, trig_pars[, x, doys])Empirical estimation of shift in std-normal for given theta_incr.
rain_probs
- duplicate_feb28(doys)[source]¶
Put doys in the range [1, 365] by duplicating February 28th and decrementing all following doys of the year.
- property hours¶
- property hours_per_day¶
- property n_years¶
- class varwg.time_series_analysis.seasonal.Torus(hour_neighbors)[source]¶
Bases:
Seasonal- Attributes:
doy_hour_weightsTo be used as a kernel to weight distances in the doy-hour domain.
- hours
- hours_per_day
- n_years
- torus
Methods
doys2doys_ii(doys)Doys indices from doy values.
duplicate_feb28(doys)Put doys in the range [1, 365] by duplicating February 28th and decrementing all following doys of the year.
qq_shift(theta_incr, trig_pars[, x, doys])Empirical estimation of shift in std-normal for given theta_incr.
rain_probs
smooth_torus
torus_fft
- property doy_hour_weights¶
To be used as a kernel to weight distances in the doy-hour domain.
- property torus¶
varwg.time_series_analysis.seasonal_kde module¶
- class varwg.time_series_analysis.seasonal_kde.SeasonalHourlyKDE(data, dtimes, solution=None, doy_width=5, hour_neighbors=4, *args, **kwds)[source]¶
Bases:
SeasonalKDE,TorusEstimates kernel densities for time series exhibiting seasonalities in daily cycles.
- Attributes:
- cdf_interp_per_day
data_boundsHere for optimization: We do not let lower and upper bound make a long loop over the data for min and max resp.
- density_grid
doy_hour_weightsTo be used as a kernel to weight distances in the doy-hour domain.
doy_maskReturns a (n_unique_doys, len(data)) ndarray
- doy_mask_dict
- hours
- hours_per_day
- kernel_widths
- n_years
- ppf_interp_per_day
- quantile_grid
- solution
- torus
- x_grid
Methods
chi2_test([k])Chi-square goodness-of-fit test. H0: The given data x follows distribution with parameters aquired by
func::SeasonalDist.fitTo side-step complications arising from having a different distribution for every doy, we test whether the quantiles (which are deseasonalized) are uniformly distributed.doys2doys_ii(doys)Doys indices from doy values.
duplicate_feb28(doys)Put doys in the range [1, 365] by duplicating February 28th and decrementing all following doys of the year.
fit([silverman, order])qq_shift(theta_incr, trig_pars[, x, doys])Empirical estimation of shift in std-normal for given theta_incr.
scotts_rule([n_data, n_dim])Scott's rule of thumb for kernel bandwidth.
sum_log_density(kernel_width, data)objective function to optimize kernel width with MLM leave one out
cdf
density_per_doy
lower_bound
median
pdf
ppf
rain_probs
scatter_cdf
scatter_pdf
smooth_torus
torus_fft
upper_bound
- property data_bounds¶
Here for optimization: We do not let lower and upper bound make a long loop over the data for min and max resp. We do it here once and cache it.
- property density_grid¶
- fit(silverman=False, order=4)[source]¶
- Parameters:
- silvermanboolean or callable, optional
Use rule of silverman instead of leave-one-out maximum likelihood estimation. Callable is executed with (n_data, n_dim).
- property solution¶
- class varwg.time_series_analysis.seasonal_kde.SeasonalKDE(data, datetimes, solution=None, doy_width=15, nx=1000.0, fixed_pars=None, verbose=True, freibord=0, smooth_len=None, kill_leap=False)[source]¶
Bases:
Seasonal- Attributes:
- cdf_interp_per_day
data_boundsHere for optimization: We do not let lower and upper bound make a long loop over the data for min and max resp.
- density_grid
doy_maskReturns a (n_unique_doys, len(data)) ndarray
- doy_mask_dict
- hours
- hours_per_day
- kernel_widths
- n_years
- ppf_interp_per_day
- quantile_grid
- solution
- x_grid
Methods
chi2_test([k])Chi-square goodness-of-fit test. H0: The given data x follows distribution with parameters aquired by
func::SeasonalDist.fitTo side-step complications arising from having a different distribution for every doy, we test whether the quantiles (which are deseasonalized) are uniformly distributed.doys2doys_ii(doys)Doys indices from doy values.
duplicate_feb28(doys)Put doys in the range [1, 365] by duplicating February 28th and decrementing all following doys of the year.
fit([silverman])This estimates the kernel widths per doy AND returns the interpolating functions for cdf and ppf.
qq_shift(theta_incr, trig_pars[, x, doys])Empirical estimation of shift in std-normal for given theta_incr.
sum_log_density(kernel_width, data, doys, ...)objective function to optimize kernel width with MLM leave one out
cdf
density_per_doy
lower_bound
median
pdf
ppf
rain_probs
scatter_cdf
scatter_pdf
upper_bound
- property cdf_interp_per_day¶
- chi2_test(k=5)[source]¶
Chi-square goodness-of-fit test. H0: The given data x follows distribution with parameters
aquired by
func::SeasonalDist.fitTo side-step complications arising from having a different distribution for every doy, we test whether the quantiles (which are deseasonalized) are uniformly distributed.
- Parameters:
- kint
Number of classes (bins)
- Returns:
- p_valuefloat
- property data_bounds¶
Here for optimization: We do not let lower and upper bound make a long loop over the data for min and max resp. We do it here once and cache it.
- property density_grid¶
- property doy_mask¶
Returns a (n_unique_doys, len(data)) ndarray
- property doy_mask_dict¶
- fit(silverman=False)[source]¶
This estimates the kernel widths per doy AND returns the interpolating functions for cdf and ppf.
- property kernel_widths¶
- property ppf_interp_per_day¶
- property quantile_grid¶
- scatter_pdf(solution, n_sumup=24, figsize=None, title=None, opacity=0.25, plot_kernel_width=False, s_kwds=None)[source]¶
- property solution¶
- sum_log_density(kernel_width, data, doys, doy_middle)[source]¶
objective function to optimize kernel width with MLM leave one out
- property x_grid¶
- varwg.time_series_analysis.seasonal_kde.doy_hour_fft(data, dtimes, order=4)[source]¶
Remove yearly and daily cycle.
- Parameters:
- data1d array
- dtimes1d array of datetime objects
- orderint, optional
number of frequencies to use
- Returns:
- xx1d array
- fft_pars24d array
fast fourier parameters for each hour.
- varwg.time_series_analysis.seasonal_kde.fft2par(fft_pars, doys, ifft_func=None, period_length=None, lower_bound=None)[source]¶
Converts from the frequency into the time domain. The output is repeated for as many periods underlying the doys (think of years).
- Parameters:
- fft_parsndarray
As returned from numpy.fft.fft (or its siblings).
- doysfloat 1d array
Doys associated with the output.
- ifft_funccallable or None, optional
Function to use for frequency-time-domain transformation. If None, np.fft.irfft will be used.
- period_lengthint or None, optional
Length of period.
- lower_boundfloat or None, optional
Smallest desired value of trans.
- Returns:
- trans1d array with len = len(doys)