How to access rugarch output object ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to access rugarch output object ?

John Writer
Hi There,

I am trying to write a script which is essentially a "for loop" where I run
rugarch and then pick specific parameter values from it and feed them to
another vector/function. This needs to happen several times.

As of now, I can see that the ugarchfit (rugarch) output is broken into
section and I can access a specific section using the $ operator. But I
could not access the specfic parameter value. To be more specific, how do I
pick the alpha1 value from the ugarchfit output object via an R script ?

More generally, is this possible for other R packages (e.g. pick the VaR
value from PerformanceAnalytics package) ?

Please advise.

Thanks.

        [[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: How to access rugarch output object ?

Eric Berger
Hi John,
Regarding your specific question about alpha1 it is possible.
In general it should be possible to get the values you want from other R
packages *if* those packages return it somewhere in the object (ok that's a
tautology).

I don't have huge experience with the rugarch package but I did the
following "poking around" and solved your issue. Here's the general
approach.

> foo <- somefunc()  # grab the output of the function you care about (e.g.
ugarchfit() )
> str(foo)  # dump information about the output (str = 'structure')
> summary(foo) # dump more information, if it exists

look for what you need and see if you can isolate it.

In the ugarchfit case there was a lot of output so I did the following
> sink("tmpfile")
> str(foo)
> summary(foo)
> sink()

to get the output into a text file. Then I searched for 'alpha1' in the
text file. I found it in the 'model' section of the summary output.
I then searched for 'model' and found it is a slot in the output structure
of ugarchfit. (which is an S4 object)

After a few attempts the following works. FYI I used the example in the
help page of the ugarchfit() function. (The first three lines, to set the
output to the variable 'fit' instead of 'foo').

> irow <- match("alpha1", rownames(fit@model$pars))
> alpha1 <- fit@model$pars[irow,1]

That's it.
HTH,
Eric



On Mon, Nov 26, 2018 at 4:57 PM John Writer <[hidden email]> wrote:

> Hi There,
>
> I am trying to write a script which is essentially a "for loop" where I run
> rugarch and then pick specific parameter values from it and feed them to
> another vector/function. This needs to happen several times.
>
> As of now, I can see that the ugarchfit (rugarch) output is broken into
> section and I can access a specific section using the $ operator. But I
> could not access the specfic parameter value. To be more specific, how do I
> pick the alpha1 value from the ugarchfit output object via an R script ?
>
> More generally, is this possible for other R packages (e.g. pick the VaR
> value from PerformanceAnalytics package) ?
>
> Please advise.
>
> Thanks.
>
>         [[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.
>

        [[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: How to access rugarch output object ?

John Writer
Hi Eric,

Thanks a lot for your time and effort. 😀


On Mon, Nov 26, 2018 at 9:05 PM Eric Berger <[hidden email]> wrote:

> Hi John,
> Regarding your specific question about alpha1 it is possible.
> In general it should be possible to get the values you want from other R
> packages *if* those packages return it somewhere in the object (ok that's a
> tautology).
>
> I don't have huge experience with the rugarch package but I did the
> following "poking around" and solved your issue. Here's the general
> approach.
>
> > foo <- somefunc()  # grab the output of the function you care about
> (e.g. ugarchfit() )
> > str(foo)  # dump information about the output (str = 'structure')
> > summary(foo) # dump more information, if it exists
>
> look for what you need and see if you can isolate it.
>
> In the ugarchfit case there was a lot of output so I did the following
> > sink("tmpfile")
> > str(foo)
> > summary(foo)
> > sink()
>
> to get the output into a text file. Then I searched for 'alpha1' in the
> text file. I found it in the 'model' section of the summary output.
> I then searched for 'model' and found it is a slot in the output structure
> of ugarchfit. (which is an S4 object)
>
> After a few attempts the following works. FYI I used the example in the
> help page of the ugarchfit() function. (The first three lines, to set the
> output to the variable 'fit' instead of 'foo').
>
> > irow <- match("alpha1", rownames(fit@model$pars))
> > alpha1 <- fit@model$pars[irow,1]
>
> That's it.
> HTH,
> Eric
>
>
>
> On Mon, Nov 26, 2018 at 4:57 PM John Writer <[hidden email]>
> wrote:
>
>> Hi There,
>>
>> I am trying to write a script which is essentially a "for loop" where I
>> run
>> rugarch and then pick specific parameter values from it and feed them to
>> another vector/function. This needs to happen several times.
>>
>> As of now, I can see that the ugarchfit (rugarch) output is broken into
>> section and I can access a specific section using the $ operator. But I
>> could not access the specfic parameter value. To be more specific, how do
>> I
>> pick the alpha1 value from the ugarchfit output object via an R script ?
>>
>> More generally, is this possible for other R packages (e.g. pick the VaR
>> value from PerformanceAnalytics package) ?
>>
>> Please advise.
>>
>> Thanks.
>>
>>         [[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.
>>
>

        [[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.