Question about rugarch

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about rugarch

AndreasBr
Dear Sir or Madam,


I am trying to fit an AR-t-(E)GARCH model in stock log return data using the rugarch package.

My code is :

install.packages("rugarch")
library(rugarch)
data <- read.csv2("C:/Users/bregi/Desktop/Thesis/R/euro.csv",header = TRUE,sep=";")
lr.AEX<- diff(log(data$AEX))  ## log returns of stock market index AEX
egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
                       mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
egarcht.fit = ugarchfit(egarcht.spec, lr.AEX)

The problem is that I want to transform my standardized residuals to follow uniform distribution. But when I run the following:
res<-residuals(egarcht.fit, standardize=TRUE)
ecdf(res)
plot.ecdf(res)
I realized that they have not transformed. I think that I found the problem but I don't know how to fix it.
When I run residuals(egarcht.fit, standardize=TRUE) I get data in the following form:
1970-01-02 01:00:00 -0.3766309  instead of just -0.3766309.

After that, I tried to solve this problem by doing:

require(xts)
time <- date[2:3914]
lrAEX.xts <- na.omit(xts(x = lr.AEX, order.by = time))

egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
                       mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
egarcht.fit = ugarchfit(egarcht.spec, data=lrAEX.xts)

residuals(egarcht.fit,standardize=TRUE)[1]

But the only improvement is that I receive the real dates of my data

                 [,1]
2001-01-02 -0.3766309

However, my goal is to receive only the residuals ( so only -0.3766309).


Could you please tell me if you know how I can achieve this?

Thank you in advance.

Kind regards,
Andreas


        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Question about rugarch

ibrahim ergen

Standardized residuals would be approx. normally distributed. Those are the shocks. Standardization here means filetering of vol clustering. So you get the garch shocks which are approx normal. You can use pnorm function to transform them to uniform distribution.

Best
Ibrahim

Sent from my iPhone

> On Mar 1, 2018, at 11:32 AM, Andreas Bregiannis <[hidden email]> wrote:
>
> Dear Sir or Madam,
>
>
> I am trying to fit an AR-t-(E)GARCH model in stock log return data using the rugarch package.
>
> My code is :
>
> install.packages("rugarch")
> library(rugarch)
> data <- read.csv2("C:/Users/bregi/Desktop/Thesis/R/euro.csv",header = TRUE,sep=";")
> lr.AEX<- diff(log(data$AEX))  ## log returns of stock market index AEX
> egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
>                       mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
> egarcht.fit = ugarchfit(egarcht.spec, lr.AEX)
>
> The problem is that I want to transform my standardized residuals to follow uniform distribution. But when I run the following:
> res<-residuals(egarcht.fit, standardize=TRUE)
> ecdf(res)
> plot.ecdf(res)
> I realized that they have not transformed. I think that I found the problem but I don't know how to fix it.
> When I run residuals(egarcht.fit, standardize=TRUE) I get data in the following form:
> 1970-01-02 01:00:00 -0.3766309  instead of just -0.3766309.
>
> After that, I tried to solve this problem by doing:
>
> require(xts)
> time <- date[2:3914]
> lrAEX.xts <- na.omit(xts(x = lr.AEX, order.by = time))
>
> egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
>                       mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
> egarcht.fit = ugarchfit(egarcht.spec, data=lrAEX.xts)
>
> residuals(egarcht.fit,standardize=TRUE)[1]
>
> But the only improvement is that I receive the real dates of my data
>
>                 [,1]
> 2001-01-02 -0.3766309
>
> However, my goal is to receive only the residuals ( so only -0.3766309).
>
>
> Could you please tell me if you know how I can achieve this?
>
> Thank you in advance.
>
> Kind regards,
> Andreas
>
>
>    [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Απ: Question about rugarch

AndreasBr
Dear Ibrahim,


First of all, I would like to sincerely thank you for your reply!

Indeed, standardized residuals are approx. normally distributed in my model.

If I understood correctly, I should do the following to transform them in uniform: pnorm(residuals(egarcht.fit,standardize=TRUE)). I just did it and I checked through a histogram that indeed they look like uniform.

Thank you very much!

So, do you think that my code, in general, is right? Is it reasonable that in the output of the standardized residuals, I received also the dates? I am asking because I also used fgarch package and in the output I received just the standardized residuals without the dates, so after that I just use the ecdf and I convert them.


Best regards,

Andreas



________________________________
���: ibrahim ergen <[hidden email]>
��������: ������, 1 ������� 2018 6:49 ��
����: Andreas Bregiannis
����.: [hidden email]
����: Re: [R-SIG-Finance] Question about rugarch


Standardized residuals would be approx. normally distributed. Those are the shocks. Standardization here means filetering of vol clustering. So you get the garch shocks which are approx normal. You can use pnorm function to transform them to uniform distribution.

Best
Ibrahim

Sent from my iPhone

> On Mar 1, 2018, at 11:32 AM, Andreas Bregiannis <[hidden email]> wrote:
>
> Dear Sir or Madam,
>
>
> I am trying to fit an AR-t-(E)GARCH model in stock log return data using the rugarch package.
>
> My code is :
>
> install.packages("rugarch")
> library(rugarch)
> data <- read.csv2("C:/Users/bregi/Desktop/Thesis/R/euro.csv",header = TRUE,sep=";")
> lr.AEX<- diff(log(data$AEX))  ## log returns of stock market index AEX
> egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
>                       mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
> egarcht.fit = ugarchfit(egarcht.spec, lr.AEX)
>
> The problem is that I want to transform my standardized residuals to follow uniform distribution. But when I run the following:
> res<-residuals(egarcht.fit, standardize=TRUE)
> ecdf(res)
> plot.ecdf(res)
> I realized that they have not transformed. I think that I found the problem but I don't know how to fix it.
> When I run residuals(egarcht.fit, standardize=TRUE) I get data in the following form:
> 1970-01-02 01:00:00 -0.3766309  instead of just -0.3766309.
>
> After that, I tried to solve this problem by doing:
>
> require(xts)
> time <- date[2:3914]
> lrAEX.xts <- na.omit(xts(x = lr.AEX, order.by = time))
>
> egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
>                       mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
> egarcht.fit = ugarchfit(egarcht.spec, data=lrAEX.xts)
>
> residuals(egarcht.fit,standardize=TRUE)[1]
>
> But the only improvement is that I receive the real dates of my data
>
>                 [,1]
> 2001-01-02 -0.3766309
>
> However, my goal is to receive only the residuals ( so only -0.3766309).
>
>
> Could you please tell me if you know how I can achieve this?
>
> Thank you in advance.
>
> Kind regards,
> Andreas
>
>
>    [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
R-SIG-Finance Info Page<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
stat.ethz.ch
To see the collection of prior postings to the list, visit the R-SIG-Finance Archives. Using R-SIG-Finance: To post a message to all the list members ...



> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.

        [[alternative HTML version deleted]]


_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Απ: Question about rugarch

alexios
Andreas, you can just extract the numeric values from the output :
Either coredata() or as.numeric().

rugarch was designed to work with xts as it was the author’s opinion at the time that it was the gold standard for working with timeseries data in the context of GARCH models and greatly simplified design decisions.

Regards,

Alexios

> On Mar 1, 2018, at 10:37 AM, Andreas Bregiannis <[hidden email]> wrote:
>
> Dear Ibrahim,
>
>
> First of all, I would like to sincerely thank you for your reply!
>
> Indeed, standardized residuals are approx. normally distributed in my model.
>
> If I understood correctly, I should do the following to transform them in uniform: pnorm(residuals(egarcht.fit,standardize=TRUE)). I just did it and I checked through a histogram that indeed they look like uniform.
>
> Thank you very much!
>
> So, do you think that my code, in general, is right? Is it reasonable that in the output of the standardized residuals, I received also the dates? I am asking because I also used fgarch package and in the output I received just the standardized residuals without the dates, so after that I just use the ecdf and I convert them.
>
>
> Best regards,
>
> Andreas
>
>
>
> ________________________________
> Áðü: ibrahim ergen <[hidden email]>
> ÓôÜëèçêå: ÐÝìðôç, 1 Ìáñôßïõ 2018 6:49 ìì
> Ðñïò: Andreas Bregiannis
> Êïéí.: [hidden email]
> ÈÝìá: Re: [R-SIG-Finance] Question about rugarch
>
>
> Standardized residuals would be approx. normally distributed. Those are the shocks. Standardization here means filetering of vol clustering. So you get the garch shocks which are approx normal. You can use pnorm function to transform them to uniform distribution.
>
> Best
> Ibrahim
>
> Sent from my iPhone
>
>> On Mar 1, 2018, at 11:32 AM, Andreas Bregiannis <[hidden email]> wrote:
>>
>> Dear Sir or Madam,
>>
>>
>> I am trying to fit an AR-t-(E)GARCH model in stock log return data using the rugarch package.
>>
>> My code is :
>>
>> install.packages("rugarch")
>> library(rugarch)
>> data <- read.csv2("C:/Users/bregi/Desktop/Thesis/R/euro.csv",header = TRUE,sep=";")
>> lr.AEX<- diff(log(data$AEX))  ## log returns of stock market index AEX
>> egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
>>                      mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
>> egarcht.fit = ugarchfit(egarcht.spec, lr.AEX)
>>
>> The problem is that I want to transform my standardized residuals to follow uniform distribution. But when I run the following:
>> res<-residuals(egarcht.fit, standardize=TRUE)
>> ecdf(res)
>> plot.ecdf(res)
>> I realized that they have not transformed. I think that I found the problem but I don't know how to fix it.
>> When I run residuals(egarcht.fit, standardize=TRUE) I get data in the following form:
>> 1970-01-02 01:00:00 -0.3766309  instead of just -0.3766309.
>>
>> After that, I tried to solve this problem by doing:
>>
>> require(xts)
>> time <- date[2:3914]
>> lrAEX.xts <- na.omit(xts(x = lr.AEX, order.by = time))
>>
>> egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
>>                      mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
>> egarcht.fit = ugarchfit(egarcht.spec, data=lrAEX.xts)
>>
>> residuals(egarcht.fit,standardize=TRUE)[1]
>>
>> But the only improvement is that I receive the real dates of my data
>>
>>                [,1]
>> 2001-01-02 -0.3766309
>>
>> However, my goal is to receive only the residuals ( so only -0.3766309).
>>
>>
>> Could you please tell me if you know how I can achieve this?
>>
>> Thank you in advance.
>>
>> Kind regards,
>> Andreas
>>
>>
>>   [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> R-SIG-Finance Info Page<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
> stat.ethz.ch
> To see the collection of prior postings to the list, visit the R-SIG-Finance Archives. Using R-SIG-Finance: To post a message to all the list members ...
>
>
>
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions should go.
>
>    [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Απ: Απ: Question about rugarch

AndreasBr
Yes, that worked great!

Thank you so much for all your assistance!


Best regards,

Andreas

________________________________
Από: Alexios Ghalanos <[hidden email]>
Στάλθηκε: Πέμπτη, 1 Μαρτίου 2018 8:08 μμ
Προς: Andreas Bregiannis
Κοιν.: ibrahim ergen; [hidden email]
Θέμα: Re: [R-SIG-Finance] Απ: Question about rugarch

Andreas, you can just extract the numeric values from the output :
Either coredata() or as.numeric().

rugarch was designed to work with xts as it was the author’s opinion at the time that it was the gold standard for working with timeseries data in the context of GARCH models and greatly simplified design decisions.

Regards,

Alexios

> On Mar 1, 2018, at 10:37 AM, Andreas Bregiannis <[hidden email]> wrote:
>
> Dear Ibrahim,
>
>
> First of all, I would like to sincerely thank you for your reply!
>
> Indeed, standardized residuals are approx. normally distributed in my model.
>
> If I understood correctly, I should do the following to transform them in uniform: pnorm(residuals(egarcht.fit,standardize=TRUE)). I just did it and I checked through a histogram that indeed they look like uniform.
>
> Thank you very much!
>
> So, do you think that my code, in general, is right? Is it reasonable that in the output of the standardized residuals, I received also the dates? I am asking because I also used fgarch package and in the output I received just the standardized residuals without the dates, so after that I just use the ecdf and I convert them.
>
>
> Best regards,
>
> Andreas
>
>
>
> ________________________________
> Áðü: ibrahim ergen <[hidden email]>
> ÓôÜëèçêå: ÐÝìðôç, 1 Ìáñôßïõ 2018 6:49 ìì
> Ðñïò: Andreas Bregiannis
> Êïéí.: [hidden email]
> ÈÝìá: Re: [R-SIG-Finance] Question about rugarch
>
>
> Standardized residuals would be approx. normally distributed. Those are the shocks. Standardization here means filetering of vol clustering. So you get the garch shocks which are approx normal. You can use pnorm function to transform them to uniform distribution.
>
> Best
> Ibrahim
>
> Sent from my iPhone
>
>> On Mar 1, 2018, at 11:32 AM, Andreas Bregiannis <[hidden email]> wrote:
>>
>> Dear Sir or Madam,
>>
>>
>> I am trying to fit an AR-t-(E)GARCH model in stock log return data using the rugarch package.
>>
>> My code is :
>>
>> install.packages("rugarch")
>> library(rugarch)
>> data <- read.csv2("C:/Users/bregi/Desktop/Thesis/R/euro.csv",header = TRUE,sep=";")
>> lr.AEX<- diff(log(data$AEX))  ## log returns of stock market index AEX
>> egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
>>                      mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
>> egarcht.fit = ugarchfit(egarcht.spec, lr.AEX)
>>
>> The problem is that I want to transform my standardized residuals to follow uniform distribution. But when I run the following:
>> res<-residuals(egarcht.fit, standardize=TRUE)
>> ecdf(res)
>> plot.ecdf(res)
>> I realized that they have not transformed. I think that I found the problem but I don't know how to fix it.
>> When I run residuals(egarcht.fit, standardize=TRUE) I get data in the following form:
>> 1970-01-02 01:00:00 -0.3766309  instead of just -0.3766309.
>>
>> After that, I tried to solve this problem by doing:
>>
>> require(xts)
>> time <- date[2:3914]
>> lrAEX.xts <- na.omit(xts(x = lr.AEX, order.by = time))
>>
>> egarcht.spec=ugarchspec(variance.model=list(model="eGARCH",garchOrder=c(2,1)),
>>                      mean.model=list(armaOrder=c(1,0)),distribution.model = "std")
>> egarcht.fit = ugarchfit(egarcht.spec, data=lrAEX.xts)
>>
>> residuals(egarcht.fit,standardize=TRUE)[1]
>>
>> But the only improvement is that I receive the real dates of my data
>>
>>                [,1]
>> 2001-01-02 -0.3766309
>>
>> However, my goal is to receive only the residuals ( so only -0.3766309).
>>
>>
>> Could you please tell me if you know how I can achieve this?
>>
>> Thank you in advance.
>>
>> Kind regards,
>> Andreas
>>
>>
>>   [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
R-SIG-Finance Info Page<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
stat.ethz.ch
To see the collection of prior postings to the list, visit the R-SIG-Finance Archives. Using R-SIG-Finance: To post a message to all the list members ...



> R-SIG-Finance Info Page<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
R-SIG-Finance Info Page<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
stat.ethz.ch
To see the collection of prior postings to the list, visit the R-SIG-Finance Archives. Using R-SIG-Finance: To post a message to all the list members ...



> stat.ethz.ch
> To see the collection of prior postings to the list, visit the R-SIG-Finance Archives. Using R-SIG-Finance: To post a message to all the list members ...
>
>
>
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions should go.
>
>    [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
R-SIG-Finance Info Page<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
stat.ethz.ch
To see the collection of prior postings to the list, visit the R-SIG-Finance Archives. Using R-SIG-Finance: To post a message to all the list members ...



> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.


        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.