API Reference
ARFIMA
ARFIMA\((p, d, q)\) Estimator.
Models time series data featuring long-memory processes through fractional integration, where the difference parameter \(d\) is non-integer, solving the general equation \(\phi(L)(1-L)^dy_t=\theta(L)w_t\)
Source code in src\arfima\core.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
fit(time_series, p_list, q_list, method='L-BFGS-B', criterion='aic', returns=True)
Evaluates combinations of AR and MA lags to minimize the selected information criterion. Upon convergence, calculates the inverse Hessian matrix to derive standard errors, t-statistics, and p-values for statistical inference.
Parameters
time_series : NDArray The 1D time series data object to fit. p_list : list[int] A list of autoregressive (AR) lag orders to test (e.g., [0, 1, 2]). q_list : list[int] A list of moving average (MA) lag orders to test (e.g., [0, 1]). method : str, default="L-BFGS-B" The SciPy optimization algorithm to use. Options:
* "L-BFGS-B" (Default, highly recommended for bounded parameters)
* "TNC"
* "SLSQP"
* "Powell"
criterion : str, default="aic" The information criterion used to penalize model complexity. Options:
* "aic" : Akaike Information Criterion
* "bic" : Bayesian Information Criterion
* "hqic" : Hannan-Quinn Information Criterion
* "aicc" : Corrected AIC
Source code in src\arfima\core.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
predict(steps=0)
Forecasts future values of the time series out-of-sample.
Mathematically projects the series forward by assuming all future random shocks (\(w_t\)) are exactly zero. The projected shocks are then fractionally integrated using \(-d\) to restore the original scale of the data.
Parameters
steps : int, default=0 The number of future time periods to forecast.
Returns
np.ndarray
A 1D array of length steps containing the out-of-sample forecasted values.
Raises
ValueError If the method is called before the model has been successfully fitted.
Source code in src\arfima\core.py
predict_in_sample()
Generates in-sample fitted values for the historical data.
Reconstructs the model's historical fit by calculating the exact historical residuals via linear filtering, and subtracting those residuals from the raw input data.
Returns
np.ndarray A 1D array of fitted values, equal in length to the input time series.
Raises
ValueError If the method is called before the model has been successfully fitted.
Source code in src\arfima\core.py
summary(returns=True)
Prints a formatted statistical regression table for the fitted model.
Outputs the estimated parameters (fractional differencing \(d\), AR, and MA coefficients), along with their corresponding standard errors, t-statistics, and two-tailed p-values derived from the inverse Hessian matrix.
Returns
None This method prints directly to the console and does not return any objects.
Prints
str A formatted ASCII table containing the model structure and statistical inference metrics.
Source code in src\arfima\core.py
FIGARCH
Source code in src\arfima\core.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
fit(squared_residuals, p_list, q_list, method='L-BFGS-B', criterion='aic')
Fits the optimal FIGARCH structure using Maximum Likelihood Estimation.
Parameters
squared_residuals : NDArray[np.float64] The squared white noise shocks (\(\epsilon_t^2\)) extracted from the mean equation. p_list : list[int] List of ARCH lag orders to test. q_list : list[int] List of GARCH lag orders to test. method : str, default="L-BFGS-B" The SciPy optimization algorithm to use. Options:
* "L-BFGS-B" (Default, highly recommended for bounded parameters)
* "TNC"
* "SLSQP"
* "Powell"
criterion : str, default="aic" The information criterion used to penalize model complexity. Options:
* "aic" : Akaike Information Criterion
* "bic" : Bayesian Information Criterion
* "hqic" : Hannan-Quinn Information Criterion
* "aicc" : Corrected AIC
Source code in src\arfima\core.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
predict(steps=0)
Forecasts future conditional variance out-of-sample.
Mathematically projects volatility forward iteratively. Because future squared shocks (\(\epsilon_{t+k}^2\)) are unobservable, the model substitutes them with their expected value, which is the forecasted conditional variance (\(\sigma_{t+k}^2\)).
Parameters
steps : int, default=0 The number of future time periods to forecast.
Returns
np.ndarray
A 1D array of length steps containing the forecasted conditional variances.
Raises
ValueError If the method is called before the model has been successfully fitted.
Source code in src\arfima\core.py
predict_in_sample()
Generates in-sample conditional variances for the historical data.
Reconstructs the model's historical volatility fit by calculating the ARCH(\(\infty\)) decay weights and convoluting them with the actual historical squared shocks.
Returns
np.ndarray A 1D array of conditional variances (\(\sigma_t^2\)), equal in length to the input time series.
Raises
ValueError If the method is called before the model has been successfully fitted.
Source code in src\arfima\core.py
summary(returns=True)
Prints a formatted statistical regression table for the fitted FIGARCH model.
Outputs the estimated parameters (baseline variance \(\omega\), fractional variance differencing \(d_v\), ARCH, and GARCH coefficients), along with their corresponding standard errors, t-statistics, and two-tailed p-values derived from the inverse Hessian matrix.
Source code in src\arfima\core.py
_arma_generate(shocks, ar_coeffs, ma_coeffs)
Generates time series data \(y_t\) from given residuals \(w_t\).
Acts as the inverse of _fast_residuals by solving \((1 - \phi)y_t = (1 + \theta L)w_t\) for \(y_t\).
Parameters
shocks : NDArray[np.float64] The array of residuals. ar_coeffs : list[float] The autoregressive coefficients (\(\phi\)). ma_coeffs : list[float] The moving average coefficients (\(\theta\)).
Returns
np.ndarray A 1D array of generated ARMA values.
Source code in src\arfima\core.py
_dynamic_variance(squared_shocks, omega, weights)
Calculates the conditional variance array (\(\sigma_t^2\)) using FFT convolution.
Applies the pre-calculated ARCH(\(\infty\)) decay weights to the historical squared shocks via Fast Fourier Transform convolution to efficiently construct the dynamic variance path. Applies a strict mathematical floor to prevent variance from dropping below zero.
Parameters
squared_shocks : NDArray[np.float64] The array of squared residuals (\(\epsilon_t^2\)) extracted from the mean equation. omega : float The adjusted baseline variance constant (\(\omega^*\)). weights : NDArray[np.float64] The array of ARCH(\(\infty\)) decay weights.
Returns
np.ndarray A 1D array of conditional variances (\(\sigma_t^2\)) equal in length to the input shocks.
Source code in src\arfima\core.py
_fast_residuals(diff_data, ar_coeffs, ma_coeffs)
Returns the residuals \(w_t\) from differenced data using linear filtering.
Solves the ARMA equation \((1 - \phi)y_t = (1 + \theta)w_t\) for \(w_t\).
Parameters
diff_data : NDArray[np.float64] The fractionally differenced time series (\(y_t\)). ar_coeffs : list[float] The autoregressive coefficients (\(\phi\)). ma_coeffs : list[float] The moving average coefficients (\(\theta\)).
Returns
np.ndarray A 1D array of residuals.
Source code in src\arfima\core.py
_figarch_score_function(params, squared_shocks, p, q)
Evaluates the Gaussian negative log-likelihood for dynamic volatility.
Extracts the FIGARCH parameters, constructs the conditional variance path (\(\sigma_t^2\)), and calculates the likelihood score used by the optimizer. Implements strict penalty boundaries to reject non-stationary GARCH parameter combinations or invalid variance arrays.
Solves: \(-\ln(L) = 0.5 * \sum[ ln(\sigma_t^2) + (\epsilon_t^2 / \sigma_t^2)]\)
Parameters
params : list[float] The optimization parameters containing omega, \(d_v\), followed by ARCH and GARCH coefficients. squared_shocks : NDArray[np.float64] The 1D array of squared residuals (\(\epsilon_t^2\)). p : int The ARCH lag order. q : int The GARCH lag order.
Returns
float The negative log-likelihood scalar, or a penalty value (\(1^{10}\)) if bounds are violated.
Source code in src\arfima\core.py
_figarch_weights(d_v, arch_coeffs, garch_coeffs, n)
Computes the ARCH(infinity) representation weights for the FIGARCH process.
Expands the fractional differencing polynomial \((1-L)^d_v\) up to lag n and filters it through the ARCH and GARCH polynomials to derive the decay weights \(\lambda_i\) for the conditional variance equation: \(\lambda(L) = 1 - [\phi(L) / \beta(L)] * (1-L)^{d_v}\).
Parameters
\(d_v\) : float The fractional integration parameter for volatility. arch_coeffs : list[float] The autoregressive conditional heteroskedasticity (ARCH) coefficients. garch_coeffs : list[float] The generalized autoregressive conditional heteroskedasticity (GARCH) coefficients. n : int The length of the time series (the truncation point for the infinite expansion).
Returns
np.ndarray A 1D array of length n containing the ARCH(\(\infty\)) decay weights.
Source code in src\arfima\core.py
_frac_diff(time_series, d)
Applies the fractional differencing operator \((1-L)^d\) using Fast Fourier Transform (FFT).
Parameters
time_series : NDArray[np.float64] The 1D time series array to difference. d : float The fractional integration parameter. Pass \(-d\) for inverse differencing (integration).
Returns
np.ndarray A 1D array of the fractionally differenced time series.
Source code in src\arfima\core.py
_gph_estimator(time_series, bandwidth_power=0.5)
Approximates d(fractional differencing parameter) using the Geweke and Porter Hudak(GPH) semiparametric estimator.
Parameters
time_series: NDArray[np.float64] | np.ndarray 1D time series array bandwidth_power: float (default = 0.5) determines the number of periodogram frequencies included in the regression. Ideally between 0.5 and 0.7
Returns
float returns the estimated fractional difference parameter d. d is clipped between -0.49 and 0.49.
Source code in src\arfima\core.py
_score_function(params, time_series, p)
Calculates negative log-likelihood for a given set of ARFIMA parameters.
Parameters
params : list[float] The optimization parameters containing \(d\), followed by AR and MA coefficients. time_series : NDArray[np.float64] The 1D input time series data. p : int The autoregressive (AR) lag order. Returns
float The negative log-likelihood value, or scalar (\(1^{10}\)) for invalid variances.