Last data update: 2014.03.03

R: Equally Weighted Moving Average (EqWMA) of the pth....
eqwmaR Documentation

Equally Weighted Moving Average (EqWMA) of the pth. exponentiated values

Description

The function eqwma returns an Equally Weighted Moving Average (EqWMA) of the pth. exponentiated values lagged. Optionally, the absolute values are computed before averaging, and the log of is returned. The function leqwma is essentially a wrapper to eqwma in which the absolute values are used and the logarithm is applied.

If x is financial return (possibly mean-corrected) and p=2, then this gives the socalled 'historical' model, also known as an integrated ARCH model where the ARCH coefficients all have the same value with sum equal to one. In the log-variance specification the lag of log(EqWMA) is thus a financial volatility proxy. It may be an imperfect proxy compared with high-frequency data (which can also be included as regressors), but - in contrast to high-frequency data - is always available and easy to compute

Usage

eqwma(x, length = 5, lag = 1, start = 1, p = 1, log = FALSE, abs = FALSE,
  as.vector = TRUE)
leqwma(x, length = 5, lag = 1, start = 1, p = 2, as.vector=FALSE)

Arguments

x

numeric vector, time-series or zoo object. Missing values in the beginning and/or at the end of the series is allowed, as they are removed with the na.trim command

length

integer or vector of integers each equal to or greater than 1. The length or lengths of the moving window or windows of averages

lag

integer equal to or greater than 0. If 0, then the moving averages are not lagged

start

integer equal to or greater than 1 (default: start=1, i.e. the first observation). Where to start the moving windows of averages

p

numeric value greater than zero. The exponent p in x^p for eqwma and in abs(x)^p for leqwma

log

logical. If TRUE, then the logarithm of the moving average is returned. If FALSE (default), then the logarithm is not applied

abs

logical. If TRUE, then x is transformed to absolute values before x is exponentiated

as.vector

logical. If TRUE, then a univariate series is returned as a vector. If FALSE, then a univariate series is returnes as a matrix. Note: multivariate series are always returned as a matrix

Details

The intended primary use of eqwma is to construct mixed frequency regressors for the mean specification.

The intended primary use of leqwma is to construct volatility proxies in for the log-variance specification. The default is the lagged log of an equally weighted moving average of the squared residuals, where each average is made up of m observations. This is equivalent to an integrated ARCH(p) model where the p coefficients are all equal. For further details on the use of log(EqWMA) as a volatility proxy, see Sucarrat and Escribano (2012)

Value

numeric vector, time series or zoo object

Author(s)

Genaro Sucarrat, http://www.sucarrat.net/

References

Genaro Sucarrat and Alvaro Escribano (2012): 'Automated Financial Model Selection: General-to-Specific Modelling of the Mean and Volatility Specifications', Oxford Bulletin of Economics and Statistics 74, Issue no. 5 (October), pp. 716-735

See Also

zoo, sm, gets.mean, gets.vol

Examples

##generate an iid normal series:
set.seed(123)
x <- rnorm(100)

##compute lag of EqWMA(20) for x^2:
eqwma(x, p=2)

##compute lag of EqWMA(5) and lag of EqWMA(10) for x:
eqwma(x, length=c(5,10))

##compute lag of log(EqWMA(20)) for x^2:
leqwma(x)

#compute lag of log(EqWMA(5)) and lag of log(EqWMA(8))
#for abs(x)^2:
leqwma(x, length=c(4,8))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

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 an HTML browser interface to help.
Type 'q()' to quit R.

> library(AutoSEARCH)
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: lgarch
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/AutoSEARCH/eqwma.Rd_%03d_medium.png", width=480, height=480)
> ### Name: eqwma
> ### Title: Equally Weighted Moving Average (EqWMA) of the pth.
> ###   exponentiated values
> ### Aliases: eqwma leqwma
> ### Keywords: Statistical Models Time Series Financial Econometrics
> 
> ### ** Examples
> 
> ##generate an iid normal series:
> set.seed(123)
> x <- rnorm(100)
> 
> ##compute lag of EqWMA(20) for x^2:
> eqwma(x, p=2)
  [1]         NA 0.31413295 0.18355731 0.93222875 0.70041442 0.56367460
  [7] 1.08913759 1.12103000 0.95519167 1.04855075 1.08493060 0.79631627
 [13] 0.77972072 0.49176828 0.39986505 0.42193400 0.76087047 0.78454829
 [19] 1.52594135 1.62187123 1.60478570 1.19422348 1.15415508 0.59117549
 [25] 0.59905196 0.63248043 0.97341781 1.10429262 0.89846026 1.05127491
 [31] 1.28755046 0.75493794 0.63197395 0.78751928 0.68267183 0.50326055
 [37] 0.56173128 0.60568280 0.44619942 0.31069837 0.20465091 0.20632939
 [43] 0.15361036 0.47308933 1.39524069 1.65812350 1.81387452 1.83769184
 [49] 1.56099969 0.74179481 0.45135046 0.21190993 0.17960968 0.13642381
 [55] 0.38936914 0.39817356 0.84527613 1.32484019 1.39282727 1.02128080
 [61] 1.02041244 0.58930105 0.16003977 0.11389056 0.31832174 0.53874288
 [67] 0.52834358 0.51805621 0.49641267 0.45902896 1.06985112 1.09964751
 [73] 2.12592129 2.32766140 2.25813908 1.51224081 1.67437782 0.62414477
 [79] 0.71987312 0.62585417 0.53504116 0.32468848 0.33815754 0.06760497
 [85] 0.14407500 0.14993971 0.17194892 0.38287188 0.39327070 0.33147275
 [91] 0.58570167 0.76109580 0.58063248 0.55415446 0.61176139 0.71808462
 [97] 0.59273695 1.48947423 1.94785473 1.88011245
> 
> ##compute lag of EqWMA(5) and lag of EqWMA(10) for x:
> eqwma(x, length=c(5,10))
            EqWMA(5)    EqWMA(10)
  [1,]            NA           NA
  [2,] -0.5604756466 -0.560475647
  [3,] -0.3953265680 -0.395326568
  [4,]  0.2560183927  0.256018393
  [5,]  0.2096408924  0.209640892
  [6,]  0.1935702609  0.193570261
  [7,]  0.6486783876  0.447152715
  [8,]  0.7868971267  0.449118928
  [9,]  0.2221432170  0.234846408
 [10,]  0.0706709683  0.132435379
 [11,] -0.0443189727  0.074625644
 [12,] -0.1425156106  0.253081388
 [13,] -0.1627360864  0.312080520
 [14,]  0.1704304506  0.196286834
 [15,]  0.3299375642  0.200304266
 [16,]  0.3079017313  0.131791379
 [17,]  0.4204679991  0.138976194
 [18,]  0.4480753294  0.142669621
 [19,] -0.0254023921  0.072514029
 [20,]  0.0927322450  0.211334905
 [21,]  0.1093421904  0.208621961
 [22,] -0.4616051781 -0.020568589
 [23,] -0.6047702567 -0.078347464
 [24,] -0.4166477150 -0.221025054
 [25,] -0.7026971412 -0.304982448
 [26,] -0.7331467132 -0.311902261
 [27,] -0.8569206342 -0.659262906
 [28,] -0.6457682423 -0.625269250
 [29,] -0.4098927291 -0.413270222
 [30,] -0.4917418707 -0.597219506
 [31,] -0.1159710329 -0.424558873
 [32,]  0.3066604736 -0.275130080
 [33,]  0.0800887681 -0.282839737
 [34,]  0.2284392767 -0.090726726
 [35,]  0.6316933616  0.069975745
 [36,]  0.5452465937  0.214637780
 [37,]  0.5976818003  0.452171137
 [38,]  0.7674796276  0.423784198
 [39,]  0.5760721532  0.402255715
 [40,]  0.3392529230  0.485473142
 [41,]  0.0988425065  0.322044550
 [42,] -0.1778269401  0.209927430
 [43,] -0.3301939265  0.218642851
 [44,] -0.5708908547  0.002590649
 [45,] -0.0759071288  0.131672897
 [46,]  0.2417794710  0.170310989
 [47,]  0.1560991502 -0.010863895
 [48,]  0.1171056387 -0.106544144
 [49,]  0.2768538383 -0.147018508
 [50,] -0.0009443311 -0.038425730
 [51,] -0.2592105441 -0.008715537
 [52,]  0.0160748754  0.086087013
 [53,]  0.0909424914  0.104024065
 [54,]  0.1756994706  0.226276654
 [55,]  0.2934269038  0.146241286
 [56,]  0.2649465199  0.002867988
 [57,]  0.5175769380  0.266825907
 [58,]  0.2135357283  0.152239110
 [59,]  0.3390325696  0.257366020
 [60,]  0.0900829616  0.191754933
 [61,]  0.1784254725  0.221685996
 [62,] -0.0489407518  0.234318093
 [63,]  0.1603451184  0.186940423
 [64,] -0.0232191083  0.157906731
 [65,] -0.2517050337 -0.080811036
 [66,] -0.5092515927 -0.165413060
 [67,] -0.5244737610 -0.286707256
 [68,] -0.3343671146 -0.087010998
 [69,] -0.2571247926 -0.140171950
 [70,]  0.1310437776 -0.060330628
 [71,]  0.7554189601  0.123083684
 [72,]  0.5965069986  0.036016619
 [73,]  0.0450312677 -0.144667923
 [74,]  0.2355781273 -0.010773333
 [75,] -0.0907155188  0.020164129
 [76,] -0.6383341793  0.058542390
 [77,] -0.3350136721  0.130746663
 [78,]  0.0698655016  0.057448385
 [79,] -0.3754257457 -0.069923809
 [80,] -0.1973248973 -0.144020208
 [81,] -0.0875014465 -0.362917813
 [82,] -0.2914628832 -0.313238278
 [83,] -0.1574522016 -0.043793350
 [84,]  0.0125593345 -0.181433206
 [85,]  0.1051739483 -0.046075475
 [86,]  0.0888549084  0.000676731
 [87,]  0.1540584640 -0.068702210
 [88,]  0.2963701864  0.069458992
 [89,]  0.4575384909  0.235048913
 [90,]  0.2634768641  0.184325406
 [91,]  0.5373357002  0.313095304
 [92,]  0.6696800786  0.411869271
 [93,]  0.5599916678  0.428180927
 [94,]  0.5207017167  0.489120104
 [95,]  0.4603068186  0.361891841
 [96,]  0.5026757846  0.520005742
 [97,]  0.1839230960  0.426801587
 [98,]  0.5117103027  0.535850985
 [99,]  0.7704860809  0.645593899
[100,]  0.8489272243  0.654617021
> 
> ##compute lag of log(EqWMA(20)) for x^2:
> leqwma(x)
       logEqWMA(5)
  [1,]          NA
  [2,] -1.15793897
  [3,] -1.69522832
  [4,] -0.07017706
  [5,] -0.35608309
  [6,] -0.57327815
  [7,]  0.08538618
  [8,]  0.11424791
  [9,] -0.04584326
 [10,]  0.04740897
 [11,]  0.08151602
 [12,] -0.22775885
 [13,] -0.24881948
 [14,] -0.70974764
 [15,] -0.91662816
 [16,] -0.86290636
 [17,] -0.27329215
 [18,] -0.24264716
 [19,]  0.42261150
 [20,]  0.48358056
 [21,]  0.47299023
 [22,]  0.17749617
 [23,]  0.14336854
 [24,] -0.52564236
 [25,] -0.51240694
 [26,] -0.45810599
 [27,] -0.02694189
 [28,]  0.09920497
 [29,] -0.10707281
 [30,]  0.05000363
 [31,]  0.25274155
 [32,] -0.28111973
 [33,] -0.45890710
 [34,] -0.23886742
 [35,] -0.38174102
 [36,] -0.68664725
 [37,] -0.57673168
 [38,] -0.50139886
 [39,] -0.80698929
 [40,] -1.16893271
 [41,] -1.58644962
 [42,] -1.57828141
 [43,] -1.87333604
 [44,] -0.74847105
 [45,]  0.33306694
 [46,]  0.50568654
 [47,]  0.59546517
 [48,]  0.60851035
 [49,]  0.44532645
 [50,] -0.29868260
 [51,] -0.79551117
 [52,] -1.55159394
 [53,] -1.71696923
 [54,] -1.99198899
 [55,] -0.94322745
 [56,] -0.92086728
 [57,] -0.16809193
 [58,]  0.28129184
 [59,]  0.33133569
 [60,]  0.02105752
 [61,]  0.02020690
 [62,] -0.52881810
 [63,] -1.83233292
 [64,] -2.17251732
 [65,] -1.14469263
 [66,] -0.61851686
 [67,] -0.63800849
 [68,] -0.65767153
 [69,] -0.70034771
 [70,] -0.77864197
 [71,]  0.06751950
 [72,]  0.09498968
 [73,]  0.75420526
 [74,]  0.84486407
 [75,]  0.81454106
 [76,]  0.41359253
 [77,]  0.51544164
 [78,] -0.47137293
 [79,] -0.32868030
 [80,] -0.46863789
 [81,] -0.62541160
 [82,] -1.12488909
 [83,] -1.08424339
 [84,] -2.69407382
 [85,] -1.93742125
 [86,] -1.89752202
 [87,] -1.76055785
 [88,] -0.96005486
 [89,] -0.93325711
 [90,] -1.10420968
 [91,] -0.53494471
 [92,] -0.27299604
 [93,] -0.54363728
 [94,] -0.59031181
 [95,] -0.49141295
 [96,] -0.33116786
 [97,] -0.52300457
 [98,]  0.39842319
 [99,]  0.66672863
[100,]  0.63133159
> 
> #compute lag of log(EqWMA(5)) and lag of log(EqWMA(8))
> #for abs(x)^2:
> leqwma(x, length=c(4,8))
        logEqWMA(4) logEqWMA(8)
  [1,]           NA          NA
  [2,] -1.157938974 -1.15793897
  [3,] -1.695228325 -1.69522832
  [4,] -0.070177060 -0.07017706
  [5,] -0.356083095 -0.35608309
  [6,] -0.468309051 -0.57327815
  [7,]  0.298752989 -0.04085309
  [8,] -0.230804569 -0.15878396
  [9,]  0.176258820 -0.05489919
 [10,]  0.267359159 -0.03429666
 [11,] -0.476744253 -0.01563263
 [12,] -0.059448138 -0.14146046
 [13,] -0.554157855 -0.12369273
 [14,] -0.699630862 -0.10354092
 [15,] -0.798112965 -0.62457405
 [16,] -1.878471984 -0.60229433
 [17,] -0.084772156 -0.29217381
 [18,] -0.061310753 -0.33038113
 [19,]  0.644148103  0.16319891
 [20,]  0.667880243  0.05018093
 [21,]  0.188732205  0.06130160
 [22,]  0.358244618  0.17031076
 [23,] -0.742761703  0.17402142
 [24,] -0.484517498  0.24923754
 [25,] -0.366823379 -0.05095151
 [26,] -0.682130734 -0.03234022
 [27,]  0.186391589 -0.17394152
 [28,]  0.110820625 -0.14318421
 [29,] -0.009793082 -0.17245832
 [30,]  0.195916323 -0.14968180
 [31,] -0.107357511  0.05026455
 [32,] -0.263704320 -0.05900976
 [33,] -0.243235788 -0.11971791
 [34,] -0.414667047 -0.06348026
 [35,] -0.775818562 -0.38674298
 [36,] -0.538526172 -0.39170393
 [37,] -0.385078370 -0.31164427
 [38,] -0.585565306 -0.49646983
 [39,] -1.007941011 -0.88515975
 [40,] -1.515837855 -0.91225906
 [41,] -1.985898083 -0.89446246
 [42,] -1.708123283 -0.99696330
 [43,] -1.655195615 -1.28009036
 [44,] -0.565707151 -0.93193437
 [45,]  0.535241899 -0.08060362
 [46,]  0.668854448  0.06447858
 [47,]  0.813830782  0.20195686
 [48,]  0.640172374  0.20894977
 [49,] -0.254689532  0.21632775
 [50,] -0.575452200  0.22890707
 [51,] -1.390925672  0.22529348
 [52,] -1.494733527  0.05879527
 [53,] -1.771543436 -0.74947691
 [54,] -3.993050538 -1.23633444
 [55,] -0.723660372 -1.00264051
 [56,] -0.730486941 -1.04131165
 [57,]  0.054858789 -0.48901380
 [58,]  0.504157908 -0.17791081
 [59,]  0.241192508 -0.12911837
 [60,]  0.234168839 -0.13608766
 [61,] -0.355825619 -0.12954722
 [62,] -1.988011593 -0.10950338
 [63,] -2.166251579 -0.36573556
 [64,] -1.976681165 -0.35497204
 [65,] -0.951284716 -0.60987345
 [66,] -0.450362483 -0.94885968
 [67,] -0.515256659 -1.03288963
 [68,] -0.478336699 -0.96976839
 [69,] -1.018484376 -0.98432018
 [70,] -1.249660461 -0.77219130
 [71,]  0.273290120 -0.04519155
 [72,]  0.280911495 -0.02832239
 [73,]  0.977084469  0.41139454
 [74,]  0.992114988  0.39996150
 [75,]  0.572087436  0.43380749
 [76,]  0.604328597  0.45563828
 [77,] -0.274559158  0.53550057
 [78,] -0.639979053  0.47754881
 [79,] -0.256054251  0.24140068
 [80,] -0.409505139  0.22074141
 [81,] -0.901766003 -0.53977451
 [82,] -0.952989260 -0.78428690
 [83,] -2.992557440 -0.88641770
 [84,] -2.573233456 -0.99389123
 [85,] -1.741421634 -1.23593943
 [86,] -1.674422791 -1.25001149
 [87,] -1.726950310 -2.17162310
 [88,] -0.811384384 -1.34605281
 [89,] -0.947309151 -1.26752667
 [90,] -0.910837241 -1.22145187
 [91,] -0.350114690 -0.81821940
 [92,] -0.429851356 -0.60253124
 [93,] -0.387952056 -0.62902003
 [94,] -0.406262580 -0.62705744
 [95,] -0.832956513 -0.56267234
 [96,] -0.429486375 -0.42966885
 [97,] -0.406861505 -0.39736209
 [98,]  0.613884566  0.22862045
 [99,]  0.848547894  0.32606610
[100,]  0.635145539  0.23828439
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>