EWMA Tutorial
EWMA Tutorial
Afterreceivingseveralinquiriesabouttheexponentialweightedmovingaverage(EWMA)functionin
NumXL,wedecidedtodedicatethisissuetoexploringthissimplefunctioningreaterdepth.
ThemainobjectiveofEWMAistoestimatethenextday(orperiod)volatilityofatimeseriesandclosely
trackthevolatilityasitchanges.
Background
Define
n
o asthevolatilityofamarketvariableondayn,asestimatedattheendofday 1 n .The
variancerateisThesquareofvolatility,
2
n
o ,ondayn.
Supposethevalueofthemarketvariableattheendofday i is
i
S .Thecontinuouslycompoundedrate
ofreturnduringdayI(betweenendofpriorday(i.e. 1 i )andendofday i )isexpressedas:
1
ln
i
i
i
S
r
S
=
Next,usingthestandardapproachtoestimate
n
o fromhistoricaldata,wellusethemostrecentm
observationstocomputeanunbiasedestimatorofthevariance:
2
2 1
( )
1
m
n i
i
n
r r
m
o
=
=
Where r isthemeanof
i
r :
1
m
n i
i
r
r
m
=
=
Next,letsassume 0 r = andusethemaximumlikelihoodestimateofthevariancerate:
2
2 1
m
n i
i
n
r
m
o
=
=
EWMATutorial 2 SpiderFinancialCorp,2013
Sofar,wehaveappliedequalweightstoall
2
n i
r
,sothedefinitionaboveisoftenreferredtoasthe
equallyweightedvolatilityestimate.
Earlier,westatedourobjectivewastoestimatethecurrentlevelofvolatility
n
o ,soitmakessenseto
givehigherweightstorecentdatathantoolderones.Todoso,letsexpresstheweightedvariance
estimateasfollows:
2 2
1
m
n i n i
i
r o o
=
=
Where:
-
i
o istheamountofweightgiventoanobservationidaysago.
- 0
i
o >
-
1
1
m
i
i
o
=
=
So,togivehigherweighttorecentobservations,
1 i i
o o
+
>
Longrun average variance
Apossibleextensionoftheideaaboveistoassumethereisalongrunaveragevariance
L
V ,andthatit
shouldbegivensomeweight:
2 2
1
m
n L i n i
i
V r o o
=
= +
Where:
-
1
1
m
i
i
o
=
+ =
- 0
L
V >
ThemodelaboveisknownastheARCH(m)model,proposedbyEnglein1994.
2 2
1
m
n i n i
i
r o e o
=
= +
EWMA
EWMAisaspecialcaseoftheequationabove.Inthiscase,wemakeitsothattheweightsofvariable
i
o
decreaseexponentiallyaswemovebackthroughtime.
EWMATutorial 3 SpiderFinancialCorp,2013
2 1
1 1
....
n
i i i i n
o o o o
+
+
= = = =
Unliketheearlierpresentation,theEWMAincludesallpriorobservations,butwithexponentially
decliningweightsthroughouttime.
Next,weapplythesumofweightssuchthattheyequaltheunityconstraint:
1
1 0
1
i
i
i i
o o
= =
= =
For 1 < ,thevalueof
1
1 o =
Nowweplugthosetermsbackintotheequation.Forthe
2
1 n
o
estimate:
1
2 2 2 2 3 2
1 1 1 2 1 3 1 1
1
2 2 2 3 2
1 2 3 1
...
(1 )( ... )
n
n
n i n i n n
i
n
n n n
r r r r
r r r
o o o o o
o
= = + + +
= + + +
Andthe
2
n
o estimatecanbeexpressedasfollows:
2 2 2 2 2
1 2 1
2 2 2 2 3 2
1 2 3 1
2 2 2
1 1
(1 )( ... )
(1 ) (1 )( ... )
(1 )
n
n n n
n
n n n n
n n n
r r r
r r r r
r
o
o
o o
= + + +
= + + + +
= +
Now,tounderstandtheequationbetter:
2 2 2
1 1
2 2 2 2
1 2 2
2 2 2 2 2 3 2
1 2 3 3
2 2 2 2 2 1 2 2 2
1 2 3
(1 )
(1 ) ((1 ) )
(1 ) (1 ) (1 )
(1 )( ... )
n n n
n n n n
n n n n n
m m
n n n n n m n m
r
r r
r r r
r r r r
o o
o o
o o
o o
+ +
= +
= + +
= + + +
= + + + + +
Foralargerdataset,the
2 2 m
n m
o
+
issufficientlysmalltobeignoredfromtheequation.
TheEWMAapproachhasoneattractivefeature:itrequiresrelativelylittlestoreddata.Toupdateour
estimateatanypoint,weonlyneedapriorestimateofthevariancerateandthemostrecent
observationvalue.
AsecondaryobjectiveofEWMAistotrackchangesinthevolatility.Forsmall values,recent
observationsaffecttheestimatepromptly.For valuesclosertoone,theestimatechangesslowly
basedonrecentchangesinthereturnsoftheunderlyingvariable.
EWMATutorial 4 SpiderFinancialCorp,2013
TheRiskMetricsdatabase(producedbyJPMorganandmadepublicavailable)usestheEWMAwith
0.94 = forupdatingdailyvolatility.
IMPORTANT:TheEWMAformuladoesassumealongrunaveragevariancelevel.Thus,theconceptof
volatilitymeanreversionisnotcapturedbytheEWMA.TheARCH/GARCHmodelsarebettersuitedfor
thispurpose.
Lambda ()
AsecondaryobjectiveofEWMAistotrackchangesinthevolatility,soforsmall values,recent
observationaffecttheestimatepromptly,andfor valuesclosertoone,theestimatechangesslowlyto
recentchangesinthereturnsoftheunderlyingvariable.
TheRiskMetricsdatabase(producedbyJPMorgan)andmadepublicavailablein1994,usestheEWMA
modelwith 0.94 = forupdatingdailyvolatilityestimate.Thecompanyfoundthatacrossarangeof
marketvariables,thisvalueof givesforecastofthevariancethatcomeclosesttorealizedvariance
rate.Therealizedvarianceratesonaparticulardaywascalculatedasanequallyweightedaverageof
2
i
r
onthesubsequent25days.
24
2
2 0
25
n i
i
n
r
o
+
=
=
Similarly,tocomputetheoptimalvalueoflambdaforourdataset,weneedtocalculatetherealized
volatilityateachpoint.Thereareseveralmethods,sopickone.Next,calculatethesumofsquared
errors(SSE)betweenEWMAestimateandrealizedvolatility.Finally,minimizetheSSEbyvaryingthe
lambdavalue.
Soundssimple?Itis.Thebiggestchallengeistoagreeonanalgorithmtocomputerealizedvolatility.For
instance,thefolksatRiskMetricschosethesubsequent25daytocomputerealizedvariancerate.In
yourcase,youmaychooseanalgorithmthatutilizesDailyVolume,HI/LOand/orOPENCLOSEprices.
FAQ
Q1:CanweuseEWMAtoestimate(orforecast)volatilitymorethanonestepahead?
TheEWMAvolatilityrepresentationdoesnotassumealongrunaveragevolatility,andthus,forany
forecasthorizonbeyondonestep,theEWMAreturnsaconstantvalue:
2 2 2
1 1
2 2 2 2 2 2
1
2 2
(1 )
[ ] [(1 ) ] (1 ) [ ]
[ ]
n n n
n n n n n n
n m n
r
E E r E r
E
o o
o o o o
o o
+
+
= +
= + = + =
=
EWMATutorial 5 SpiderFinancialCorp,2013
Q2:Whatistheinitialvalueofthevariance(i.e.
2
1
o )intheNumXLEWMAfunction?CanIseta
differentvalue?
Currently,wesetthevaluetozero,butwesetthevarianceattheendoffirstperiodequaltothesquare
ofreturnonthatperiodtostarttheEWMA.
2
0
2 2
1 1
2 2 2 2
2 1 1 1
2 2 2
3 2 2
2 2 2
1 1
0
(1 )
(1 )
...
(1 )
n n n
r
r r
r
r
o
o
o o
o o
o o
=
=
= + =
= +
= +
Foralargedataset,thevaluehasverylittleimpactonthecalculatedvalue.
Goingforward,weareplanningtoavailanargumenttoacceptuserdefinedinitialvolatilityvalue.
Q3:WhatisEWMAsrelationshiptoARCH/GARCHModel?
EWMAisbasicallyaspecialformofanARCH()model,withthefollowingcharacteristics:
1. TheARCHorderisequaltothesampledatasize.
2. Theweightsareexponentiallydecliningatrate throughouttime.
Q4:DoesEWMAreverttothemean?
NO.EWMAdoesnothaveatermforthelongrunvarianceaverage;thus,itdoesnotreverttoanyvalue.
Q5Whatisthevarianceestimateforhorizonbeyondoneday(orstep)ahead?
AsinQ1,theEWMAfunctionreturnsaconstantvalueequaltotheonestepestimatevalue.
Q6Ihaveweekly/monthly/annualdata.Whichvalueof Ishoulduse?
Youmaystilluse0.94asadefaultvalue,butifyouwishtofindtheoptimalvalue,youdneedtosetup
anoptimizationproblemforminimizingtheSSEorMSEbetweenEWMAandrealizedvolatility.
Seeourvolatility101tutorialinTipsandHintsonourwebsiteformoredetailsandexamples.
Q7:ifmydatadoesnothaveazeromean,howcanIusethefunction?
EWMATutorial 6 SpiderFinancialCorp,2013
Fornow,usetheDETRENDfunctiontoremovethemeanfromthedatabeforeyoupassittotheEWMA
functions.
InfutureNumXLreleases,theEWMAwillremovethemeanautomaticallyonyourbehalf.