Page 1 of 1

Estimating co-variance using Range Based EWMA

Posted: Wed Dec 07, 2016 8:03 am
by Vik_pa
Dear Tom,

I am trying to estimate co-variance of two time series using range based EWMA proposed by Harris & Yilmaz(2010) (Estimation of the conditional variance–covariance matrix of returns using the intraday range).
Here first I have calculated the range-based variance of both the time series as follows

Code: Select all

set range = (1/4*log(2))*(PH-PL)^2+(PO-PC{1})^2
esmooth(alpha=0.06,smoothed=ewmarange) range 
Then, I have calculated the the return variance using EWMA as

Code: Select all

ret = log(PC/PC{1})
retsqr = ret^2
esmooth(alpha=0.06,smoothed=ewmaret) retsqr
where PH,PL,PO and PC are high, low, open and close prices of a security.

And in the final step, the return co-variance of the two time series will be estimated using the cov ewma. Is it possible in RATS to estimate the covariance using ewma with predefined alpha(in this case 0.06)? In the GARCHMV.RPF example, the for MV=ewma, the alpha is also estimated.
Can you please explain how to estimate it.

Re: Estimating co-variance using Range Based EWMA

Posted: Wed Dec 07, 2016 9:03 am
by TomDoan
Do you assume zero means in the returns? If so, you can use something like

GARCH(MV=EWMA,NOMEAN,INITIAL=.06(or whatever),HMATRICES=EWMAH) / myr1 myr2

Re: Estimating co-variance using Range Based EWMA

Posted: Sat Dec 10, 2016 4:11 am
by Vik_pa
The estimation result still gives the estimated alpha. What I want is to estimate the covariance using ewma with alpha as 0.06.

Re: Estimating co-variance using Range Based EWMA

Posted: Sat Dec 10, 2016 6:18 am
by TomDoan
Sorry. Also add METHOD=EVALUATE.

Re: Estimating co-variance using Range Based EWMA

Posted: Wed Dec 14, 2016 3:17 am
by Vik_pa
Thanks.

I have tried to do the coding for the range based ewma as per Harris & Yilmaz(2010) paper (Estimation of the conditional variance–covariance matrix of returns using the intraday range). My code is

Code: Select all

OPEN DATA "C:\Users\Desktop\123.xlsx"
CALENDAR(D) 1999:1:4
DATA(FORMAT=XLSX,ORG=COLUMNS) 1999:01:04 2008:12:31 FL FO FH FLO CL CO CH CLO

* range for FTSE 100
set frnge = 100*((1/(4*log(2)))*(log(fh)-log(flo))^2+(log(fo)-log(fl{1}))^2)

* FTSE100 Ret calc.
set fret = 100*(log(fl)-log(fl{1}))

*CAC Range
set crnge = 100*((1/(4*log(2)))*(log(ch)-log(clo))^2+(log(co)-log(cl{1}))^2)

*CAC Ret
set cret = 100*(log(cl)-log(cl{1}))

*EWMA for FTSE and CAC range 
esmooth(alpha=0.06,smoothed=ewmafrnge) frnge
esmooth(alpha=0.06,smoothed=ewmacrnge) crnge

*EWMA Cov estimation for FTSE100 and CAC ret

GARCH(MV=EWMA,NOMEAN,INITIAL=.06,hmatrice=EWMAH,method=evaluate) / cret fret

*correlation between FTSE and CAC
set cc = ewmah(t)(1,2)/(sqrt(ewmah(t)(1,1))*sqrt(ewmah(t)(2,2)))
*Hybrid EWMA
set hewma = cc*sqrt(ewmafrnge)*sqrt(ewmacrnge)
But I am not sure how to use the code in rolling forecast with 500 days width. Can you please help me in this?

Thanks

Re: Estimating co-variance using Range Based EWMA

Posted: Wed Dec 14, 2016 8:40 am
by TomDoan
There's no real point is doing "rolling" samples with an EWMA model---it basically "rolls" on its own since the long past observations have no effect on current values.

Re: Estimating co-variance using Range Based EWMA

Posted: Wed Dec 14, 2016 9:53 am
by Vik_pa
As the paper mentioned, "The sample is divided into an initial estimation period of 500 observations and a forecast period of 2112 observations.The hybrid EWMA model is first used to generate forecasts of the conditional variance–covariance matrix for day 501. The estimation period is then rolled forward one day, and the models are re-estimated and used to generate forecasts of the variance–covariance matrix for day 502, and so on until the end of the sample is reached. This yields a series of 2112 out-of-sample forecasts of the conditional variance–covariance matrix.
Then the performance of the EMWA model was evaluated against a benchmark covariance matrices using RMSE and MAE.
Can you pls suggest a way through which I can modify my code to include the above analysis?

Thanks

Re: Estimating co-variance using Range Based EWMA

Posted: Wed Dec 14, 2016 11:31 am
by TomDoan
Rolling samples are covered in the User's Guide. However, you don't need rolling samples with EWMA. If you aren't convinced, take .94^500 to see what the weight is on the data point that would be going out of the window if you slide the sample. Just do the GARCH through the whole sample and save the covariance matrices. Those are your one-step forecasts of the covariances.

Re: Estimating co-variance using Range Based EWMA

Posted: Thu Dec 15, 2016 8:34 am
by Vik_pa
Thanks. Just One question. Can you please help me to code a loop which will estimate the EWMA for the series with a moving window of 500 observations. Example it first calculate the ewma from 1 to first 500 points and then move to 2nd observation to 501 point and estimate the ewma and save and so on. Similarly for the MVGARCH option.

Re: Estimating co-variance using Range Based EWMA

Posted: Thu Dec 15, 2016 9:04 am
by TomDoan
I just answered those.

Re: Estimating co-variance using Range Based EWMA

Posted: Thu Dec 15, 2016 10:09 am
by Vik_pa
TomDoan wrote:Rolling samples are covered in the User's Guide. However, you don't need rolling samples with EWMA. If you aren't convinced, take .94^500 to see what the weight is on the data point that would be going out of the window if you slide the sample.

I didn't get this point. Please explain.
Just do the GARCH through the whole sample and save the covariance matrices. Those are your one-step forecasts of the covariances.

But this will be based on the whole sample. H(501) will be one step ahead forecast of first 500 observations and H(1000) will be the forecast of 999 observations. It will not give the rolling forecast with a window of 500 observations? Correct me if I am wrong.

Thanks

Re: Estimating co-variance using Range Based EWMA

Posted: Thu Dec 15, 2016 10:37 am
by TomDoan
Vik_pa wrote:
TomDoan wrote:Rolling samples are covered in the User's Guide. However, you don't need rolling samples with EWMA. If you aren't convinced, take .94^500 to see what the weight is on the data point that would be going out of the window if you slide the sample.

I didn't get this point. Please explain.
You can write EWMA as an exponentially weighted sum of past data. Beyond a certain point (and 500 is way past that point), the weights on early data are trivially small. Thus, doing EWMA from (say) entry 1 to 10000 and doing it from 9501 to 10000 will give the same value to any reasonable number of decimal places for T=10000.
Vik_pa wrote:
Just do the GARCH through the whole sample and save the covariance matrices. Those are your one-step forecasts of the covariances.

But this will be based on the whole sample. H(501) will be one step ahead forecast of first 500 observations and H(1000) will be the forecast of 999 observations. It will not give the rolling forecast with a window of 500 observations? Correct me if I am wrong.

Thanks
I'm not sure what you mean. H(501) is the one-step forecast of T=501 and H(1000) is the one step forecast of T=1000. That's true for any type of GARCH model (the whole point of a GARCH model is to generate that). For other types of GARCH models, there will be a difference between estimating H(1000) using an estimation which starts at T=1 and one that starts with T=501 because the different windows will give you different coefficients---if the coefficients were the same, the results for H would be (effectively) the same as well. An EWMA doesn't have any free coefficients to estimate, so there's no reason for "rolling sample" estimates.

Re: Estimating co-variance using Range Based EWMA

Posted: Thu Dec 15, 2016 11:11 am
by Vik_pa
I think I am not very clear in my questions. Really sorry for that.
Please have a look at the methodology section in the paper mentioned in the article and also look at my code. I was trying to code this hybrid ewma model. There are three steps involved.
In step one the range based variances are estimated using the EWMA methodology for two series.
In the second step the correlation between the two series are calculated as the ratio of covariance (EWMA covariance between two series returns) and their respective std deviations( which is also estimated using the ewma with the returns).
And, in the last step, the hybrid ewma is estimated as the product of the correlation(estimated in the second step) with the std deviations (estimated in the first step using the range based ewma).

I am really sorry for asking too many question.

Re: Estimating co-variance using Range Based EWMA

Posted: Thu Dec 15, 2016 11:52 am
by TomDoan
I hope you understand that we don't see it as part of our job to read and interpret papers that individual users find interesting. However, based upon the calculations you're showing, there is still no reason for rolling windows. Exponential smoothing has exactly the same type of behavior as the EWMA. If you need a second opinion, you can always contact the authors. Note that there's no harm in doing rolling windows, it just isn't necessary. If despite everything you still feel the need to do rolling windows, read the section that I referenced in the User's Guide and throw all the calculations in a loop the way that describes.