R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("fSeries-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('fSeries') Loading required package: fBasics Rmetrics, (C) 1999-2005, Diethelm Wuertz, GPL fBasics: Markets, Basic Statistics, Date and Time Loading required package: fCalendar Rmetrics, (C) 1999-2005, Diethelm Wuertz, GPL fCalendar: Markets, Basic Statistics, Date and Time Rmetrics, (C) 1999-2005, Diethelm Wuertz, GPL fSeries: The Dynamical Process Behind Financial Markets > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "A1-ArmaModelling" > > ### * A1-ArmaModelling > > flush(stderr()); flush(stdout()) > > ### Name: ArmaModelling > ### Title: Integrated ARMA Time Series Modelling > ### Aliases: ArmaModelling fARMA fARMA-class armaSim armaFit predict.fARMA > ### print.fARMA plot.fARMA summary.fARMA fitted.values.fARMA > ### residuals.fARMA armaRoots armaTrueacf armaToeplitz armaFischer > ### Keywords: models > > ### ** Examples > > ## armaSim/armaFit - > xmpSeries("\nStart: Simulate an ARMA(2, 1) process > ") > x = armaSim(model = list(ar = c(0.5, -0.5), ma = 0.1), n = 1000) > Continue = xmpSeries("Press any key > ") > # Estimate the parameters: > fit = armaFit(x ~ arma(2, 1)) > print(fit) Title: ARIMA Modelling Call: armaFit(formula = x ~ arma(2, 1)) Model: Coefficient(s): ar1 ar2 ma1 intercept 0.51435 -0.53338 0.04575 -0.01257 Description: Wed Jul 13 14:12:25 2005 > Continue = xmpSeries("Press any key > ") > # Diagnostic Analysis: > par(mfrow = c(3, 2), cex = 0.7) > summary(fit) Title: ARIMA Modelling Call: armaFit(formula = x ~ arma(2, 1)) Model: ARMA(2,1) with method: CSS Coefficient(s): ar1 ar2 ma1 intercept 0.51435 -0.53338 0.04575 -0.01257 Residuals: Min 1Q Median 3Q Max -3.01814 -0.67632 -0.02842 0.69149 3.85310 Skewness Kurtosis -0.02863 -0.00850 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ar1 0.51435 0.05051 10.183 <2e-16 *** ar2 -0.53338 0.03124 -17.074 <2e-16 *** ma1 0.04575 0.06046 0.757 0.449 intercept -0.01257 0.03419 -0.368 0.713 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 sigma^2 estimated as: 1.07 Conditional Sum-of-Squares: 1066.73 Description: Wed Jul 13 14:12:25 2005 > Continue = xmpSeries("Press any key > ") > # 5 Steps ahead Forecasts: > predict(fit, 5) Time Series: Start = 1001 End = 1005 Frequency = 1 Low 95 Low 80 Forecast High 80 High 95 1001 -2.0399 -1.3382 -0.0126 1.3130 2.0148 1002 -2.3363 -1.5319 -0.0126 1.5068 2.3111 1003 -2.3889 -1.5663 -0.0126 1.5412 2.3637 1004 -2.5402 -1.6653 -0.0126 1.6402 2.5151 1005 -2.5464 -1.6694 -0.0126 1.6443 2.5213 > > ## armaFit - > xmpSeries("\nNext: Estimate the parameters > ") > # Now use the arima fitting method with d=0: > fit = armaFit(x ~ arima(2, 0, 1)) > print(fit) Title: ARIMA Modelling Call: armaFit(formula = x ~ arima(2, 0, 1)) Model: Coefficient(s): ar1 ar2 ma1 intercept 0.51373 -0.53237 0.04588 -0.01274 Description: Wed Jul 13 14:12:25 2005 > Continue = xmpSeries("Press any key > ") > # Diagnostic Analysis: > par(mfrow = c(3, 2), cex = 0.7) > summary(fit) Title: ARIMA Modelling Call: armaFit(formula = x ~ arima(2, 0, 1)) Model: ARIMA(2,0,1) with method: CSS-ML Coefficient(s): ar1 ar2 ma1 intercept 0.51373 -0.53237 0.04588 -0.01274 Residuals: Min 1Q Median 3Q Max -3.01803 -0.67428 -0.02905 0.69121 3.85258 Skewness Kurtosis -0.027096 -0.004248 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ar1 0.51373 0.05055 10.162 <2e-16 *** ar2 -0.53237 0.03123 -17.048 <2e-16 *** ma1 0.04588 0.06053 0.758 0.448 intercept -0.01274 0.03356 -0.380 0.704 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 sigma^2 estimated as: 1.067 log likelihood: -1451.79 AIC Criterion: 2913.59 Description: Wed Jul 13 14:12:25 2005 > Continue = xmpSeries("Press any key > ") > # 5 Step ahead Forecasts: > predict(fit, n.ahead = 5) Time Series: Start = 1001 End = 1005 Frequency = 1 Low 95 Low 80 Forecast High 80 High 95 1001 -1.8868 -1.1860 0.1378 1.4616 2.1624 1002 -1.7983 -0.9953 0.5217 2.0387 2.8418 1003 -2.1907 -1.3696 0.1817 1.7329 2.5541 1004 -2.7202 -1.8469 -0.1974 1.4521 2.3254 1005 -2.7401 -1.8647 -0.2111 1.4425 2.3178 > > ## armaRoots - > xmpSeries("\nNext: Roots of the Characteristic Polynomial > ") > # Calculate and plot the of an ARMA process: > par(mfrow = c(2, 2), cex = 0.7) > coefficients = c(-0.5, 0.9, -0.1, -0.5) > armaRoots(coefficients) re im dist 1 1.0291 0.7284 1.2608 2 -1.0000 0.0000 1.0000 3 -1.2582 0.0000 1.2582 4 1.0291 -0.7284 1.2608 > > ## armaTrueacf - > xmpSeries("\nNext: True ACF of an ARMA Process > ") > model = list(ar = c(0.3, +0.3), ma = 0.1) > armaTrueacf(model) lag acf 0 0 1.000000000 1 1 0.525423729 2 2 0.457627119 3 3 0.294915254 4 4 0.225762712 5 5 0.156203390 6 6 0.114589831 7 7 0.081237966 8 8 0.058748339 9 9 0.041995892 10 10 0.030223269 11 11 0.021665748 12 12 0.015566705 13 13 0.011169736 14 14 0.008020932 15 15 0.005757201 16 16 0.004133440 17 17 0.002967192 18 18 0.002130190 19 19 0.001529215 20 20 0.001097821 > model = list(ar = c(0.3, -0.3), ma = 0.1) > armaTrueacf(model) lag acf 0 0 1.000000e+00 1 1 2.935178e-01 2 2 -2.119446e-01 3 3 -1.516387e-01 4 4 1.809177e-02 5 5 5.091916e-02 6 6 9.848216e-03 7 7 -1.232128e-02 8 8 -6.650849e-03 9 9 1.701130e-03 10 10 2.505594e-03 11 11 2.413392e-04 12 12 -6.792764e-04 13 13 -2.761847e-04 14 14 1.209275e-04 15 15 1.191337e-04 16 16 -5.381576e-07 17 17 -3.590154e-05 18 18 -1.060902e-05 19 19 7.587758e-06 20 20 5.459032e-06 > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "A2-GarchModelling" > > ### * A2-GarchModelling > > flush(stderr()); flush(stdout()) > > ### Name: GarchModelling > ### Title: Univariate GARCH Time Series Modelling > ### Aliases: GarchModelling fGARCH fAPARCH fGARCH-class fAPARCH-class > ### garchSim garchFit aparchSim aparchFit predict.fGARCH print.fGARCH > ### summary.fGARCH print.summary.fGARCH plot.fGARCH fitted.values.fGARCH > ### residuals.fGARCH predict.fAPARCH print.fAPARCH summary.fAPARCH > ### print.summary.fAPARCH plot.fAPARCH > ### Keywords: models > > ### ** Examples > > ## garchSim - > ## garchFit - > xmpSeries("\nStart: Model Bollerslev's GARCH(1,1) Process >") > # Simulate a time series of length 1000: > ts = garchSim(model = list(omega = 1.0e-6, alpha = 0.1, beta = 0.8, + h0 = 1.0e-7), n = 1000) > xmpSeries("\nNext: Estimate the parameters >") > fit = garchFit(ts, order = c(1, 1)) /// TUNER5.... V(30) = 0.750E+00 SHOULD BE BETWEEN 0.503-314 AND NAN /// AFCTOL.... V(31) = 0.100E-19 SHOULD BE BETWEEN 0.518-317 AND NAN /// LMAX0..... V(35) = 0.100E+01 SHOULD BE BETWEEN 0.518-317 AND NAN /// LMAXS..... V(36) = 0.100E+01 SHOULD BE BETWEEN 0.518-317 AND NAN /// DINIT..... V(38) = -0.100E+01 SHOULD BE BETWEEN -0.100E+02 AND NAN /// DTINIT.... V(39) = 0.100E-05 SHOULD BE BETWEEN 0.000E+00 AND NAN /// D0INIT.... V(40) = 0.100E+01 SHOULD BE BETWEEN 0.000E+00 AND NAN > print(fit) Call: garchFit(x = ts, order = c(1, 1)) Coefficient(s): omega a1 b1 1.057e-05 5.000e-02 5.000e-02 > xmpSeries("\nNext: Summary and Diagnostic Analysis >") > summary(fit) Call: garchFit(x = ts, order = c(1, 1)) Model: GARCH(1,1) Residuals: Min 1Q Median 3Q Max -3.37005 -0.68193 -0.03158 0.66444 4.68940 Coefficient(s): Estimate Std. Error t value Pr(>|t|) omega 1.057e-05 NA NA NA a1 5.000e-02 NA NA NA b1 5.000e-02 NA NA NA Fit: sigma^2 estimated as: 0.9948 AIC Criterion: 2838.67 > > ## aparchSim - > ## aparchFit - > xmpSeries("\nNext: Subset TS-GARCH(1,5[1,5]), delta fixed >") > # Simulate a time series of length 1000: > ts = aparchSim(model = list(omega = 1e-6, alpha = 0.1, gamma = 0, + alpha.lags=1, beta = c(0.5, 0.3), beta.lags = c(1, 5), delta = 1), + innov = rnorm(5000), start.innov = rnorm(1000)) > par(mfrow = c(2, 2), cex = 0.6) > ts.plot(ts, main = "Subset TS GARCH(1,5) - Mormal") > acf(abs(ts), lag.max = 20) > xmpSeries("\nNext: Estimate the parameters >") > aparchFit(ts, order = list(alpha.lags = 1, beta.lags = c(1, 5), + delta = 1), opt = list(gamma = FALSE, delta = FALSE, disparm = FALSE), + doprint = FALSE) Call: aparchFit(x = ts, order = list(alpha.lags = 1, beta.lags = c(1, 5), delta = 1), opt = list(gamma = FALSE, delta = FALSE, disparm = FALSE), doprint = FALSE) Coefficient(s): [1] 2.253e-06 8.473e-02 0.000e+00 3.723e-01 2.958e-01 1.000e+00 1.000e+00 > # For more examples type: xmpfSeries() ... > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "A4-LongMemoryModelling" > > ### * A4-LongMemoryModelling > > flush(stderr()); flush(stdout()) > > ### Name: LongMemoryModelling > ### Title: Long Memory Behaviour of Time Series > ### Aliases: LongMemoryModelling fbmSim fgnSim farimaSim ckFGN0 gkFGN0 > ### ckFARIMA0 gkFARIMA0 fHURST fHURST-class show.fHURST > ### show,fHURST-method aggvarFit diffvarFit absvalFit higuchiFit pengFit > ### rsFit perFit boxperFit whittleFit waveletFit > ### Keywords: models > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > ## SOURCE("fSeries.A3-LongMemoryModelling") > > ## fgnSim - > par(mfrow = c(3, 1), cex = 0.75) > # Beran's Method: > plot(fgnSim(n = 200, H = 0.75), type = "l", + ylim = c(-3, 3), xlab = "time", ylab = "x(t)", main = "Beran") > # Durbin's Method: > plot(fgnSim(n = 200, H = 0.75, method = "durbin"), type = "l", + ylim = c(-3, 3), xlab = "time", ylab = "x(t)", main = "Durbin") > # Paxson's Method: > plot(fgnSim(n = 200, H = 0.75, method = "paxson"), type = "l", + ylim = c(-3, 3), xlab = "time", ylab = "x(t)", main = "Paxson") > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "A5-ChaoticTimeSeries" > > ### * A5-ChaoticTimeSeries > > flush(stderr()); flush(stdout()) > > ### Name: ChaoticTimeSeries > ### Title: Chaotic Time Series Modelling > ### Aliases: ChaoticTimeSeries henonSim ikedaSim logisticSim lorentzSim > ### roesslerSim > ### Keywords: models > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > ## SOURCE("fBasics.B4-TestsClass") > ## SOURCE("fSeries.A4-TseriesTests") > > ## bdsTest - > xmpSeries("\nNext: Brock-Dechert-Sheinkman Test for iid Series >") > # iid Time Series: > par(mfrow = c(3, 1)) > x = rnorm(100) > plot(x, type = "l", main = "iid Time Series") > bdsTest(x, m = 3) Title: BDS Test Test Results: PARAMETER: Max Embedding Dimension: 3 eps[1]: 0.449 eps[2]: 0.898 eps[3]: 1.347 eps[4]: 1.796 STATISTIC: eps[1] m=2: -1.2151 eps[1] m=3: -3.0937 eps[2] m=2: -1.7399 eps[2] m=3: -1.8985 eps[3] m=2: -1.6477 eps[3] m=3: -1.9449 eps[4] m=2: -2.0174 eps[4] m=3: -1.9759 P VALUE: eps[1] m=2: 0.2243 eps[1] m=3: 0.001977 eps[2] m=2: 0.08187 eps[2] m=3: 0.05763 eps[3] m=2: 0.09942 eps[3] m=3: 0.05179 eps[4] m=2: 0.04365 eps[4] m=3: 0.04817 Description: Wed Jul 13 14:12:28 2005 > # Non Identically Distributed Time Series: > x = c(rnorm(50), runif(50)) > plot(x, type = "l", main = "Non-iid Time Series") > bdsTest(x, m = 3) Title: BDS Test Test Results: PARAMETER: Max Embedding Dimension: 3 eps[1]: 0.373 eps[2]: 0.746 eps[3]: 1.119 eps[4]: 1.492 STATISTIC: eps[1] m=2: 8.6357 eps[1] m=3: 14.9978 eps[2] m=2: 5.1644 eps[2] m=3: 9.6187 eps[3] m=2: 2.0464 eps[3] m=3: 5.3121 eps[4] m=2: 0.3572 eps[4] m=3: 3.4352 P VALUE: eps[1] m=2: < 2.2e-16 eps[1] m=3: < 2.2e-16 eps[2] m=2: 2.412e-07 eps[2] m=3: < 2.2e-16 eps[3] m=2: 0.04072 eps[3] m=3: 1.084e-07 eps[4] m=2: 0.7209 eps[4] m=3: 0.0005921 Description: Wed Jul 13 14:12:28 2005 > # Non Independent Innovations from Quadratic Map: > x = rep(0.2, 100) > for (i in 2:100) x[i] = 4*(1-x[i-1])*x[i-1] > plot(x, type = "l", main = "Quadratic Map") > bdsTest(x, m = 3) Title: BDS Test Test Results: PARAMETER: Max Embedding Dimension: 3 eps[1]: 0.179 eps[2]: 0.357 eps[3]: 0.536 eps[4]: 0.715 STATISTIC: eps[1] m=2: 547.6341 eps[1] m=3: 743.4724 eps[2] m=2: 123.2873 eps[2] m=3: 115.3152 eps[3] m=2: 2.0759 eps[3] m=3: -2.1764 eps[4] m=2: -9.3362 eps[4] m=3: -7.926 P VALUE: eps[1] m=2: < 2.2e-16 eps[1] m=3: < 2.2e-16 eps[2] m=2: < 2.2e-16 eps[2] m=3: < 2.2e-16 eps[3] m=2: 0.03791 eps[3] m=3: 0.02953 eps[4] m=2: < 2.2e-16 eps[4] m=3: 2.263e-15 Description: Wed Jul 13 14:12:28 2005 > > ## tnnTest - > xmpSeries("\nNext: Teraesvirta NN test for Neglected Nonlinearity >") > # Time Series Non-linear in "mean" regression > par(mfrow = c(2, 1)) > n = 1000 > x = runif(1000, -1, 1) > tnnTest(x) Title: Teraesvirta Neural Network Test Test Results: PARAMETER: lag: 1 m|df: 2 t-lag-m|df: 997 STATISTIC: Chi-squared: 0.1462 F: 0.0729 P VALUE: Chi-squared: 0.9295 F: 0.9297 Description: Wed Jul 13 14:12:28 2005 > # Generate time series which is nonlinear in "mean" > x[1] = 0.0 > for (i in (2:n)) { + x[i] = 0.4*x[i-1] + tanh(x[i-1]) + rnorm (1, sd = 0.5) } > plot(x, main = "Teraesvirta Test", type = "l") > tnnTest(x) Title: Teraesvirta Neural Network Test Test Results: PARAMETER: lag: 1 m|df: 2 t-lag-m|df: 997 STATISTIC: Chi-squared: 110.1181 F: 58.0303 P VALUE: Chi-squared: < 2.2e-16 F: < 2.2e-16 Description: Wed Jul 13 14:12:28 2005 > > ## wnnTest - > xmpSeries("\nNext: White NN test for Neglected Nonlinearity >") > # Time Series Non-Linear in "mean" Regression > par(mfrow = c(2, 1)) > n = 1000 > x = runif(1000, -1, 1) > wnnTest(x) Title: White Neural Network Test Test Results: PARAMETER: lag: 1 q: 10 range: 4 qstar|df: 2 t-lag-qstar|df: 997 STATISTIC: Chi-squared: 1.4394 F: 0.718 P VALUE: Chi-squared: 0.4869 F: 0.488 Description: Wed Jul 13 14:12:28 2005 > # Generate time series which is nonlinear in "mean" > x[1] = 0.0 > for (i in (2:n)) { + x[i] = 0.4*x[i-1] + tanh(x[i-1]) + rnorm (1, sd = 0.5) } > plot(x, main = "White Test", type = "l") > wnnTest(x) Title: White Neural Network Test Test Results: PARAMETER: lag: 1 q: 10 range: 4 qstar|df: 2 t-lag-qstar|df: 997 STATISTIC: Chi-squared: 61.8031 F: 31.7808 P VALUE: Chi-squared: 3.797e-14 F: 4.174e-14 Description: Wed Jul 13 14:12:28 2005 > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "A6-PortableRandomInnovations" > > ### * A6-PortableRandomInnovations > > flush(stderr()); flush(stdout()) > > ### Name: PortableRandomInnovations > ### Title: Generator for Portable Random Innovations > ### Aliases: PortableRandomInnovations set.lcgseed get.lcgseed runif.lcg > ### rnorm.lcg rt.lcg > ### Keywords: programming > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > ## SOURCE("fSeries.A7-RandomInnovations") > > ## set.lcgseed - > xmpSeries("\nStart: Set Initial Seed >") > set.lcgseed(seed = 65890) > > ## runif.lcg - rnorm.lcg - rt.lcg - > xmpSeries("\nNext: Create Random Numbers >") > cbind(runif.lcg(10), rnorm.lcg(10), rt.lcg(10, df = 4)) [,1] [,2] [,3] [1,] 0.4125252 0.1343111 2.04846215 [2,] 0.4008696 0.6894022 -0.51108298 [3,] 0.6922567 -1.0722959 1.74930732 [4,] 0.3915458 -0.2155675 -1.97028909 [5,] 0.3328643 -1.0960369 0.19380579 [6,] 0.3609585 0.4220095 -1.80223886 [7,] 0.0872767 0.3471476 0.08012026 [8,] 0.4352189 0.8073492 1.69154270 [9,] 0.5179752 -1.0614631 -1.40535393 [10,] 0.1761661 -0.5147036 0.99432970 > > ## get.lcgseed - > xmpSeries("\nNext: What is the current value of the seed? >") > get.lcgseed() [1] 1743389204 > > ## Note, to overwrite rnorm, use > # rnorm = rnorm.lcg > # Going back to rnorm > # rm(rnorm) > > > > cleanEx(); ..nameEx <- "B1-TimeSeriesTests" > > ### * B1-TimeSeriesTests > > flush(stderr()); flush(stdout()) > > ### Name: TimeSeriesTests > ### Title: Time Series Tests > ### Aliases: TimeSeriesTests tsTest bdsTest tnnTest wnnTest > ### Keywords: htest > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > ## SOURCE("fBasics.B4-TestsClass") > ## SOURCE("fSeries.A4-TseriesTests") > > ## bdsTest - > xmpSeries("\nNext: Brock-Dechert-Sheinkman Test for iid Series >") > # iid Time Series: > par(mfrow = c(3, 1)) > x = rnorm(100) > plot(x, type = "l", main = "iid Time Series") > bdsTest(x, m = 3) Title: BDS Test Test Results: PARAMETER: Max Embedding Dimension: 3 eps[1]: 0.449 eps[2]: 0.898 eps[3]: 1.347 eps[4]: 1.796 STATISTIC: eps[1] m=2: -1.2151 eps[1] m=3: -3.0937 eps[2] m=2: -1.7399 eps[2] m=3: -1.8985 eps[3] m=2: -1.6477 eps[3] m=3: -1.9449 eps[4] m=2: -2.0174 eps[4] m=3: -1.9759 P VALUE: eps[1] m=2: 0.2243 eps[1] m=3: 0.001977 eps[2] m=2: 0.08187 eps[2] m=3: 0.05763 eps[3] m=2: 0.09942 eps[3] m=3: 0.05179 eps[4] m=2: 0.04365 eps[4] m=3: 0.04817 Description: Wed Jul 13 14:12:28 2005 > # Non Identically Distributed Time Series: > x = c(rnorm(50), runif(50)) > plot(x, type = "l", main = "Non-iid Time Series") > bdsTest(x, m = 3) Title: BDS Test Test Results: PARAMETER: Max Embedding Dimension: 3 eps[1]: 0.373 eps[2]: 0.746 eps[3]: 1.119 eps[4]: 1.492 STATISTIC: eps[1] m=2: 8.6357 eps[1] m=3: 14.9978 eps[2] m=2: 5.1644 eps[2] m=3: 9.6187 eps[3] m=2: 2.0464 eps[3] m=3: 5.3121 eps[4] m=2: 0.3572 eps[4] m=3: 3.4352 P VALUE: eps[1] m=2: < 2.2e-16 eps[1] m=3: < 2.2e-16 eps[2] m=2: 2.412e-07 eps[2] m=3: < 2.2e-16 eps[3] m=2: 0.04072 eps[3] m=3: 1.084e-07 eps[4] m=2: 0.7209 eps[4] m=3: 0.0005921 Description: Wed Jul 13 14:12:28 2005 > # Non Independent Innovations from Quadratic Map: > x = rep(0.2, 100) > for (i in 2:100) x[i] = 4*(1-x[i-1])*x[i-1] > plot(x, type = "l", main = "Quadratic Map") > bdsTest(x, m = 3) Title: BDS Test Test Results: PARAMETER: Max Embedding Dimension: 3 eps[1]: 0.179 eps[2]: 0.357 eps[3]: 0.536 eps[4]: 0.715 STATISTIC: eps[1] m=2: 547.6341 eps[1] m=3: 743.4724 eps[2] m=2: 123.2873 eps[2] m=3: 115.3152 eps[3] m=2: 2.0759 eps[3] m=3: -2.1764 eps[4] m=2: -9.3362 eps[4] m=3: -7.926 P VALUE: eps[1] m=2: < 2.2e-16 eps[1] m=3: < 2.2e-16 eps[2] m=2: < 2.2e-16 eps[2] m=3: < 2.2e-16 eps[3] m=2: 0.03791 eps[3] m=3: 0.02953 eps[4] m=2: < 2.2e-16 eps[4] m=3: 2.263e-15 Description: Wed Jul 13 14:12:29 2005 > > ## tnnTest - > xmpSeries("\nNext: Teraesvirta NN test for Neglected Nonlinearity >") > # Time Series Non-linear in "mean" regression > par(mfrow = c(2, 1)) > n = 1000 > x = runif(1000, -1, 1) > tnnTest(x) Title: Teraesvirta Neural Network Test Test Results: PARAMETER: lag: 1 m|df: 2 t-lag-m|df: 997 STATISTIC: Chi-squared: 0.1462 F: 0.0729 P VALUE: Chi-squared: 0.9295 F: 0.9297 Description: Wed Jul 13 14:12:29 2005 > # Generate time series which is nonlinear in "mean" > x[1] = 0.0 > for (i in (2:n)) { + x[i] = 0.4*x[i-1] + tanh(x[i-1]) + rnorm (1, sd = 0.5) } > plot(x, main = "Teraesvirta Test", type = "l") > tnnTest(x) Title: Teraesvirta Neural Network Test Test Results: PARAMETER: lag: 1 m|df: 2 t-lag-m|df: 997 STATISTIC: Chi-squared: 110.1181 F: 58.0303 P VALUE: Chi-squared: < 2.2e-16 F: < 2.2e-16 Description: Wed Jul 13 14:12:29 2005 > > ## wnnTest - > xmpSeries("\nNext: White NN test for Neglected Nonlinearity >") > # Time Series Non-Linear in "mean" Regression > par(mfrow = c(2, 1)) > n = 1000 > x = runif(1000, -1, 1) > wnnTest(x) Title: White Neural Network Test Test Results: PARAMETER: lag: 1 q: 10 range: 4 qstar|df: 2 t-lag-qstar|df: 997 STATISTIC: Chi-squared: 1.4394 F: 0.718 P VALUE: Chi-squared: 0.4869 F: 0.488 Description: Wed Jul 13 14:12:29 2005 > # Generate time series which is nonlinear in "mean" > x[1] = 0.0 > for (i in (2:n)) { + x[i] = 0.4*x[i-1] + tanh(x[i-1]) + rnorm (1, sd = 0.5) } > plot(x, main = "White Test", type = "l") > wnnTest(x) Title: White Neural Network Test Test Results: PARAMETER: lag: 1 q: 10 range: 4 qstar|df: 2 t-lag-qstar|df: 997 STATISTIC: Chi-squared: 61.8031 F: 31.7808 P VALUE: Chi-squared: 3.797e-14 F: 4.174e-14 Description: Wed Jul 13 14:12:29 2005 > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "B2-UnitrootDistribution" > > ### * B2-UnitrootDistribution > > flush(stderr()); flush(stdout()) > > ### Name: UnitrootDistribution > ### Title: Unit Root Distribution > ### Aliases: UnitrootDistribution punitroot qunitroot > ### Keywords: distribution > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > ## SOURCE("fSeries.A5-UnitrootDistribution") > > ## qunitroot - > # Asymptotic quantile of t-statistic > qunitroot(0.95, trend = "nc", statistic = "t") [1] 1.283601 > > ## qunitroot - > # Finite sample quantile of n-statistic > qunitroot(0.95, n.sample = 100, trend = "nc", statistic = "n") [1] 1.301431 > > ## punitroot - > # Asymptotic cumulative probability of t-statistic > punitroot(1.2836, trend = "nc", statistic = "t") [1] 0.9499998 > > ## punitroot - > # Finite sample cumulative probability of n-statistic > punitroot(1.2836, n.sample = 100, trend = "nc", statistic = "n") [1] 0.948171 > > > > cleanEx(); ..nameEx <- "B3-UnitrootTests" > > ### * B3-UnitrootTests > > flush(stderr()); flush(stdout()) > > ### Name: UnitrootTests > ### Title: Unit Root Time Series Tests > ### Aliases: UnitrootTests urTest adfTest unitrootTest urersTest urkpssTest > ### urppTest urspTest urzaTest > ### Keywords: htest > > ### ** Examples > > ## Not run: > ##D ## SOURCE("fBasics.A0-SPlusCompatibility") > ##D ## SOURCE("fSeries.A5-UnitrootDistribution") > ##D ## SOURCE("fSeries.A6-UnitrootTests") > ##D > ##D ## adfTest - > ##D xmpSeries("\nStart: Augmented Dickey-Fuller Test for Unit Roots >") > ##D # A time series which contains no unit-root: > ##D x = rnorm(1000) > ##D adfTest(x) > ##D # A time series which contains a unit-root: > ##D y = cumsum(c(0, x)) > ##D adfTest(y) > ##D > ##D ## unitrootTest - > ##D xmpSeries("\nNext: ADF Test using McKinnon's Tables >") > ##D # A time series which contains no unit-root: > ##D x = rnorm(1000) > ##D unitrootTest(x) > ##D # A time series which contains a unit-root: > ##D y = cumsum(c(0, x)) > ##D unitrootTest(y) > ##D > ##D ## Unit Root Tests build on Bernhard Pfaff's Implementation: > ##D > ##D ## ur*Test - > ##D # Examples can be found in the demo file "xmpTestUnitRoots". > ## End(Not run) > > > > > cleanEx(); ..nameEx <- "C1-HeavisideFunction" > > ### * C1-HeavisideFunction > > flush(stderr()); flush(stdout()) > > ### Name: HeavisideFunction > ### Title: Haviside and Related Functions > ### Aliases: HeavisideFunction H Sign Delta Boxcar Ramp > ### Keywords: programming > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > ## SOURCE("fSeries1.B1-HeavisideFunction") > > ## H - > x = sort(round(c(-1, -0.5, 0, 0.5, 1, 5*rnorm(5)), 2)) > h = H(x) > > ## Sign - > s = Sign(x) > > ## Delta - > d = Delta(x) > > ## Boxcar - > Pi = Boxcar(x) > > ## ramp - > r = Ramp(x) > cbind(x = x, Step = h, Signum = s, Delta = d, Pi = Pi, R = r) x Step Signum Delta Pi R [1,] -4.18 0.0 -1 0 0.0 0.00 [2,] -3.13 0.0 -1 0 0.0 0.00 [3,] -1.00 0.0 -1 0 0.0 0.00 [4,] -0.50 0.0 -1 0 -0.5 0.00 [5,] 0.00 0.5 0 Inf -1.0 0.00 [6,] 0.50 1.0 1 0 -0.5 0.50 [7,] 0.92 1.0 1 0 0.0 0.92 [8,] 1.00 1.0 1 0 0.0 1.00 [9,] 1.65 1.0 1 0 0.0 1.65 [10,] 7.98 1.0 1 0 0.0 7.98 > > > > cleanEx(); ..nameEx <- "C2-GarchDistributions" > > ### * C2-GarchDistributions > > flush(stderr()); flush(stdout()) > > ### Name: GarchDistributions > ### Title: GARCH Distributions > ### Aliases: GarchDistributions dsnorm psnorm qsnorm rsnorm dstd pstd qstd > ### rstd dsstd psstd qsstd rsstd dged pged qged rged dsged psged qsged > ### rsged > ### Keywords: distribution > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > ## SOURCE("fSeries.C1-HeavisideFunction") > ## SOURCE("fSeries.C2-GarchDistributions") > > ## snorm - > xmpSeries("\nStart: Skew Normal Distribuion: > ") > par(mfrow = c(2, 2), cex = 0.75) > set.seed(1953) > r = rsnorm(n = 1000, mean = 1, sd = 0.5, xi = 1.5) > plot(r, type = "l", main = "snorm: xi = 1.5") > # Plot empirical density and compare with true density: > hist(r, n = 25, probability = TRUE, border = "white", col = "steelblue4") > x = seq(-4, 6, 0.1) > lines(x, dsnorm(x = x, mean = 1, sd = 0.5, xi = 1.5)) > # Plot df and compare with true df: > plot(sort(r), (1:1000/1000), main = "Probability", col = "steelblue4") > lines(x, psnorm(x, mean = 1, sd = 0.5, xi = 1.5)) > # Compute quantiles: > qsnorm(psnorm(q = -4:6, mean = 1, sd = 0.5, xi = 1.5), + mean = 1, sd = 0.5, xi = 1.5) [1] -4.00000 -3.00000 -2.00000 -1.00000 0.00000 1.00000 2.00000 3.00000 [9] 4.00000 5.00000 5.99934 > > ## sstd - > xmpSeries("\nStart: Skew Student-t Distribution: > ") > par(mfrow = c(2, 2), cex = 0.75) > set.seed(1953) > r = rsstd(n = 1000, nu = 4, xi = 1.5) > # Print Variance: > var(r) [1] 1.067219 > plot(r, type = "l", main = "sstd: xi = 1.5") > # Plot empirical density and compare with true density: > hist(r, n = 30, xlim = c(-5, 5), probability = TRUE, + border = "white", col = "steelblue4") > x = seq(-5, 5, 0.1) > lines(x, dsnorm(x = x, xi = 1.5)) > # Plot df and compare with true df: > plot(sort(r), (1:1000/1000), main = "Probability", col = "steelblue4") > lines(x, psstd(x, xi = 1.5)) > # Compute quantiles: > qsstd(psstd(q = -5:5, xi = 1.5), xi = 1.5) [1] -5.000000e+00 -4.000000e+00 -3.000000e+00 -2.000000e+00 -1.000000e+00 [6] -9.666251e-17 1.000000e+00 2.000000e+00 3.000000e+00 4.000000e+00 [11] 5.000000e+00 > > ## sged - > xmpSeries("\nStart: Skew Generalized Error Distribuion: > ") > par(mfrow = c(2, 2), cex = 0.75) > set.seed(1953) > r = rsged(n = 1000, mean = 1, sd = 0.5, xi = 1.5) > plot(r, type = "l", main = "sged: xi = 1.5") > # Plot empirical density and compare with true density: > hist(r, n = 25, probability = TRUE, border = "white", col = "steelblue4") > x = seq(-1, 5, 0.1) > lines(x, dsged(x = x, mean = 1, sd = 0.5, xi = 1.5)) > # Plot df and compare with true df: > plot(sort(r), (1:1000/1000), main = "Probability", col = "steelblue4") > lines(x, psged(x, mean = 1, sd = 0.5, xi = 1.5)) > # Compute quantiles: > qsged(psged(q = -1:5, mean = 1, sd = 0.5, xi = 1.5), + mean = 1, sd = 0.5, xi = 1.5) [1] -1.000000e+00 -2.220446e-16 1.000000e+00 2.000000e+00 3.000000e+00 [6] 4.000000e+00 5.000000e+00 > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "C3-GarchDistributionFits" > > ### * C3-GarchDistributionFits > > flush(stderr()); flush(stdout()) > > ### Name: GarchDistributionFits > ### Title: Parameter Fit of a Distribution > ### Aliases: GarchDistributionFits normFit snormFit stdFit sstdFit gedFit > ### sgedFit > ### Keywords: distribution > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > ## SOURCE("fSeries.D1-HeavisideFunction") > ## SOURCE("fSeries.D2-SkewNormalDistribution") > ## SOURCE("fSeries.D3-SkewStudentDistribution") > ## SOURCE("fSeries.D4-SkewGedDistribution") > ## SOURCE("fSeries.D5-GarchDistributionFits") > > ## snormFit - > xmpSeries("\nStart: MLE Fit to skew Normal Density > ") > options(warn = -1) # suppress negative logs from nlm > normFit(rnorm(1000)) $minimum [1] 1452.758 $estimate [1] -0.01164852 1.03439830 $gradient [1] 0.0001177796 0.0010529019 $code [1] 1 $iterations [1] 2 > snormFit(rnorm(1000)) $minimum [1] 1457.624 $estimate [1] -0.01623993 1.03946071 1.00856643 $gradient [1] -0.0014063062 0.0004027040 -0.0012629285 $code [1] 1 $iterations [1] 4 > > ## sstdFit - > xmpSeries("\nNext: MLE Fit to skew Student-t Density > ") > sstdFit(rsstd(1000, mean = 1, sd = 1.5, nu = 7, xi = 2/3)) $minimum [1] 1759.154 $estimate [1] 0.9709045 1.4888523 8.7478080 0.6651250 $gradient [1] 4.251888e-05 4.398262e-05 3.534922e-06 1.818989e-06 $code [1] 1 $iterations [1] 21 > > ## sgedFit - > xmpSeries("\nNext: MLE Fit to skew Generalized Error Density > ") > sgedFit(rsged(1000, mean = -1, sd = 0.5, nu = 3, xi = 3/2), + print.level = 2) iteration = 0 Step: [1] 0 0 0 0 Parameter: [1] -0.9837748 0.5119396 2.0000000 1.0000000 Function Value [1] 748.89 Gradient: [1] 1.908234e-03 1.957167e+00 -1.544653e+01 -1.252646e+02 iteration = 1 Step: [1] -9.521080e-06 -9.765230e-03 7.707004e-02 6.250044e-01 Parameter: [1] -0.9837843 0.5021744 2.0770700 1.6250044 Function Value [1] 726.0183 Gradient: [1] 120.31418 -240.79536 -22.47830 25.17328 iteration = 2 Step: [1] -0.010166077 0.019724343 0.006798048 0.037600486 Parameter: [1] -0.9939504 0.5218987 2.0838681 1.6626049 Function Value [1] 723.6674 Gradient: [1] -0.9050626 -0.6451371 -17.3913986 12.6664299 iteration = 3 Step: [1] 0.006120905 -0.002638098 0.066102505 -0.054749377 Parameter: [1] -0.9878295 0.5192606 2.1499706 1.6078555 Function Value [1] 722.1056 Gradient: [1] 18.146392 -3.518621 -14.357526 8.170372 iteration = 4 Step: [1] -0.01364459 -0.01101766 0.05634921 -0.04113325 Parameter: [1] -1.001474 0.508243 2.206320 1.566722 Function Value [1] 721.4228 Gradient: [1] -29.904060 -42.876867 -11.615265 4.605409 iteration = 5 Step: [1] 0.018499875 0.001881084 0.212282135 -0.096591723 Parameter: [1] -0.9829742 0.5101241 2.4186019 1.4701305 Function Value [1] 719.769 Gradient: [1] 11.717483 -9.039478 -3.797501 -7.564318 iteration = 6 Step: [1] -0.001654032 0.002430996 0.036306425 0.034637357 Parameter: [1] -0.9846282 0.5125551 2.4549084 1.5047679 Function Value [1] 719.4371 Gradient: [1] 2.345881 8.589157 -2.599977 -4.235335 iteration = 7 Step: [1] -1.873361e-03 8.987463e-05 7.873441e-02 3.324424e-02 Parameter: [1] -0.9865016 0.5126449 2.5336428 1.5380121 Function Value [1] 719.2499 Gradient: [1] -4.8138003 3.3424431 -0.2936236 -0.4070366 iteration = 8 Step: [1] 0.0010041986 0.0001169852 0.0119608918 0.0019718948 Parameter: [1] -0.9854974 0.5127619 2.5456037 1.5399840 Function Value [1] 719.2451 Gradient: [1] -0.53272561 0.98544388 -0.03795441 0.03484538 iteration = 9 Step: [1] 9.953778e-05 -9.467461e-05 1.665686e-03 -6.114848e-04 Parameter: [1] -0.9853978 0.5126672 2.5472693 1.5393725 Function Value [1] 719.245 Gradient: [1] -0.0184523969 -0.0663178525 -0.0004792462 0.0162967087 iteration = 10 Step: [1] 1.432229e-05 3.498378e-06 1.488627e-05 -1.120072e-04 Parameter: [1] -0.9853835 0.5126707 2.5472842 1.5392605 Function Value [1] 719.245 Gradient: [1] 0.0104018909 -0.0128587772 -0.0005359689 0.0022379000 iteration = 11 Step: [1] -8.854399e-07 8.071144e-08 1.084462e-05 -1.255403e-05 Parameter: [1] -0.9853844 0.5126708 2.5472951 1.5392480 Function Value [1] 719.245 Gradient: [1] 1.395847e-03 -2.033403e-03 -1.073808e-04 9.978309e-05 iteration = 12 Parameter: [1] -0.9853845 0.5126709 2.5472981 1.5392480 Function Value [1] 719.245 Gradient: [1] 4.490630e-05 -5.150014e-05 -6.382142e-06 -8.419890e-06 Relative gradient close to zero. Current iterate is probably solution. $minimum [1] 719.245 $estimate [1] -0.9853845 0.5126709 2.5472981 1.5392480 $gradient [1] 4.490630e-05 -5.150014e-05 -6.382142e-06 -8.419890e-06 $code [1] 1 $iterations [1] 12 > > > > cleanEx(); ..nameEx <- "X1-SeriesData" > > ### * X1-SeriesData > > flush(stderr()); flush(stdout()) > > ### Name: SeriesData > ### Title: fSeries Data Sets > ### Aliases: SeriesData nyseres recession dem2gbp cac40 sp500dge ibmbj > ### nelsonplosser surex1.ts rf.30day black.ts klein kmenta > ### Keywords: datasets > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > > ## NYSE Residuals: > data(nyseres) > ts.plot(nyseres, xlab = "Index", ylab = "log-Returns", + main = "NYSE: log-Returns") > > > > cleanEx(); ..nameEx <- "X2-MillsData" > > ### * X2-MillsData > > flush(stderr()); flush(stdout()) > > ### Name: MillsData > ### Title: Terence Mill's Data Sets > ### Aliases: MillsData RS R20 RSQ R20Q RSQREAL FTAPRICE FTADIV FTARET RPI > ### EXCHD EXCHQ SP500 SP500R SP500D FT30 FTSE100 CTLD LGEN PRU > ### Keywords: datasets > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > > ## RS.txt - > data(RS) > plot(as.ts(RS)) > > > > cleanEx(); ..nameEx <- "Z1-SeriesTools" > > ### * Z1-SeriesTools > > flush(stderr()); flush(stdout()) > > ### Name: SeriesTools > ### Title: fSeries Tools > ### Aliases: SeriesTools xmpSeries xmpfSeries > ### Keywords: programming > > ### ** Examples > > ## SOURCE("fBasics.A0-SPlusCompatibility") > > ## Not run: > ##D ## xmpfSeries - > ##D # Popup the examples menu: > ##D xmpfSeries() > ## End(Not run) > > > > ### *