Equally Weighted Moving Average (EqWMA) of the pth. exponentiated values
eqwma.Rd
The function eqwma
returns an Equally Weighted Moving Average (EqWMA) of the pth. exponentiated values lagged k
times (the default of k
is 1). Optionally, the absolute values are computed before averaging if abs=TRUE
, and the natural log of the values is returned if log=TRUE
. The function leqwma
is a wrapper to eqwma
with abs=TRUE
and log=TRUE
.
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, k=1, p=1, abs=FALSE, log=FALSE, as.vector=FALSE,
lag=NULL, start=NULL)
leqwma(x, length=5, k=1, p=2, as.vector=FALSE, lag=NULL, start=NULL)
Arguments
- x
numeric vector, time-series or
zoo
object- 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
- k
integer that determines how many periods the term(s) should be lagged. If 0 (or smaller), then the moving averages are not lagged
- p
numeric value. The exponent p in x^p when
abs=FALSE
, and in abs(x)^p whenabs=TRUE
- log
logical with default
FALSE
. IfTRUE
, then the logarithm of the moving average is returned- abs
logical with default
FALSE
. IfTRUE
, then x is transformed to absolute values before x is exponentiated- as.vector
logical with default
FALSE
. IfTRUE
, and iflength(length)==1
, then the result is returned as a vector. Otherwise the returned value is always a matrix- lag
deprecated
- start
deprecated
Details
The intended primary use of eqwma
is to construct mixed frequency regressors for the mean specification of an arx
model.
The intended primary use of leqwma
is to construct volatility proxies for the log-variance specification in an arx
model. In the latter case, 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).
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
Pretis, Felix, Reade, James and Sucarrat, Genaro (2018): 'Automated General-to-Specific (GETS) Regression Modeling and Indicator Saturation for Outliers and Structural Breaks'. Journal of Statistical Software 86, Number 3, pp. 1-44
Author
Genaro Sucarrat, http://www.sucarrat.net/
Examples
##generate an iid normal series:
set.seed(123)
x <- rnorm(100)
##compute lag of EqWMA(20) for x^2:
eqwma(x, p=2)
#> EqWMA(5)
#> [1,] NA
#> [2,] NA
#> [3,] NA
#> [4,] NA
#> [5,] NA
#> [6,] 0.56367460
#> [7,] 1.08913759
#> [8,] 1.12103000
#> [9,] 0.95519167
#> [10,] 1.04855075
#> [11,] 1.08493060
#> [12,] 0.79631627
#> [13,] 0.77972072
#> [14,] 0.49176828
#> [15,] 0.39986505
#> [16,] 0.42193400
#> [17,] 0.76087047
#> [18,] 0.78454829
#> [19,] 1.52594135
#> [20,] 1.62187123
#> [21,] 1.60478570
#> [22,] 1.19422348
#> [23,] 1.15415508
#> [24,] 0.59117549
#> [25,] 0.59905196
#> [26,] 0.63248043
#> [27,] 0.97341781
#> [28,] 1.10429262
#> [29,] 0.89846026
#> [30,] 1.05127491
#> [31,] 1.28755046
#> [32,] 0.75493794
#> [33,] 0.63197395
#> [34,] 0.78751928
#> [35,] 0.68267183
#> [36,] 0.50326055
#> [37,] 0.56173128
#> [38,] 0.60568280
#> [39,] 0.44619942
#> [40,] 0.31069837
#> [41,] 0.20465091
#> [42,] 0.20632939
#> [43,] 0.15361036
#> [44,] 0.47308933
#> [45,] 1.39524069
#> [46,] 1.65812350
#> [47,] 1.81387452
#> [48,] 1.83769184
#> [49,] 1.56099969
#> [50,] 0.74179481
#> [51,] 0.45135046
#> [52,] 0.21190993
#> [53,] 0.17960968
#> [54,] 0.13642381
#> [55,] 0.38936914
#> [56,] 0.39817356
#> [57,] 0.84527613
#> [58,] 1.32484019
#> [59,] 1.39282727
#> [60,] 1.02128080
#> [61,] 1.02041244
#> [62,] 0.58930105
#> [63,] 0.16003977
#> [64,] 0.11389056
#> [65,] 0.31832174
#> [66,] 0.53874288
#> [67,] 0.52834358
#> [68,] 0.51805621
#> [69,] 0.49641267
#> [70,] 0.45902896
#> [71,] 1.06985112
#> [72,] 1.09964751
#> [73,] 2.12592129
#> [74,] 2.32766140
#> [75,] 2.25813908
#> [76,] 1.51224081
#> [77,] 1.67437782
#> [78,] 0.62414477
#> [79,] 0.71987312
#> [80,] 0.62585417
#> [81,] 0.53504116
#> [82,] 0.32468848
#> [83,] 0.33815754
#> [84,] 0.06760497
#> [85,] 0.14407500
#> [86,] 0.14993971
#> [87,] 0.17194892
#> [88,] 0.38287188
#> [89,] 0.39327070
#> [90,] 0.33147275
#> [91,] 0.58570167
#> [92,] 0.76109580
#> [93,] 0.58063248
#> [94,] 0.55415446
#> [95,] 0.61176139
#> [96,] 0.71808462
#> [97,] 0.59273695
#> [98,] 1.48947423
#> [99,] 1.94785473
#> [100,] 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,] NA NA
#> [3,] NA NA
#> [4,] NA NA
#> [5,] NA NA
#> [6,] 0.1935702609 NA
#> [7,] 0.6486783876 NA
#> [8,] 0.7868971267 NA
#> [9,] 0.2221432170 NA
#> [10,] 0.0706709683 NA
#> [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,] NA
#> [3,] NA
#> [4,] NA
#> [5,] NA
#> [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,] NA NA
#> [3,] NA NA
#> [4,] NA NA
#> [5,] -0.356083095 NA
#> [6,] -0.468309051 NA
#> [7,] 0.298752989 NA
#> [8,] -0.230804569 NA
#> [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