[R-SIG-Finance] rugarch and missing data

alexios alexios at 4dscape.com
Thu Jan 26 20:35:26 CET 2012


I have to agree with Pat that you need to be very careful in the presence of
lots of zeros...perhaps try aggregating to the 5-min level instead.

You might also find the timeSeries package useful: it provides
the 'interpNA', 'removeNA' and 'substituteNA' functions.

Regards,
Alexios

On 26/01/12 19:12, Patrick Burns wrote:
> I would think that the thing to do
> would be 'locf' last observation
> carried forward (on prices).  If there
> is no activity, then presume that the
> price hasn't changed.  You then want to
> get returns.  So you'll end up with a
> number of zeros.
>
> There are other issues that make intraday
> garch modeling "interesting".  There is
> typical seasonality of the volatility
> through the day.  Doing it "right" is hard.
> Doing it well enough to add value, might
> not be terribly hard.
>
> Pat
>
>
> On 26/01/2012 18:53, Ted Byers wrote:
>> Thanks Alexios
>>
>> It is easy enough to extract a vector of unnamed numeric values.
>>
>> But that leaves the question, what is the best option for filling in 
>> missing
>> values with some suitable default value (which obviously will have to 
>> change
>> through the day).
>>
>> Is there something in a related package that will provide a suitable
>> interpolation?
>>
>> Thanks again,
>>
>> Ted
>>
>>> -----Original Message-----
>>> From: alexios [mailto:alexios at 4dscape.com]
>>> Sent: January-26-12 1:48 PM
>>> To: Ted Byers
>>> Cc: r-sig-finance at r-project.org
>>> Subject: Re: [R-SIG-Finance] rugarch and missing data
>>>
>>> Hi Ted,
>>>
>>> 1. rugarch does not handle missing values.
>>> 2. you should pass tick/intraday data as unnamed numeric (rugarch 
>>> does not
>>> specifically handle intraday formatted data, so unnamed numeric is 
>>> the the
>>> best option).
>>> 3. rmgarch is available from r-forge under the rgarch project.
>>> and can be installed by stating that in the 'repos' argument of the
>>> install.packages i.e.
>>> install.packages("rmgarch",repos="http://r-forge.r-project.org")
>>> You'll need to manually install some of the required dependencies.
>>>
>>> Regards,
>>> Alexios
>>>
>>>
>>> On 26/01/2012 18:32, Ted Byers wrote:
>>>> Hi all,
>>>>
>>>>
>>>>
>>>> I seek enlightenment.
>>>>
>>>>
>>>>
>>>> I am beginning to study rugarch, to get a better sense of what it can
>> do.
>>>>
>>>>
>>>>
>>>> The data I am tying first is tick data for futures contracts, but I
>>>> suppose any tick data will have similar issues.
>>>>
>>>>
>>>>
>>>> Here is how I am setting up my data:
>>>>
>>>>
>>>>
>>>> x = read.table("quotes_M11.dat", header = FALSE, sep="\t", skip=0)
>>>>
>>>> dt<-sprintf("%s %04d",x$V2,x$V4)
>>>>
>>>> dt<-as.POSIXlt(dt,format="%Y-%m-%d %H%M")
>>>>
>>>> y<- data.frame(dt,x$V5)
>>>>
>>>> colnames(y)<- c("tickdate","price")
>>>>
>>>> z<- xts(y[,2],y[,1])
>>>>
>>>> alpha<- to.minutes(z, OHLC=TRUE)
>>>>
>>>> colnames(alpha)<- c("Open","High","Low","Close")
>>>>
>>>>
>>>>
>>>> So, x has the raw tick data.  NB: I can get the same data, with the
>>>> same structure, using SQL from my DB, but didn't want to complicate
>>>> things.  This data file has but a small subsample of all the data I 
>>>> can
>> work
>>> with.
>>>>
>>>>
>>>>
>>>> dt gets the date and time data into a single field, as a datetime
>>>> object that to.minutes will accept.
>>>>
>>>>
>>>>
>>>> y gets a data.frame in which the first column is the datetime and the
>>>> second is the price, and z gets an xts object from that.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Finally, alpha gets one minute  OHLC data.  Not surprisingly, alpha
>>>> does not have values for every minute of every day for which there is
>>>> data in quotes_M11.dat
>>>>
>>>>
>>>>
>>>> I use alpha successfully for an analysis I do using rollapply.  That
>>>> works great, and it doesn't seem to care that there are minutes 
>>>> without
>>> values.
>>>> (I don't know that package well enough to know why, so a little
>>>> enlightenment would be great).
>>>>
>>>>
>>>>
>>>> The problem I have is this.
>>>>
>>>>
>>>>
>>>> spec = ugarchspec(variance.model = list(model = "eGARCH", garchOrder =
>>>> c(1, 1)), mean.model = list(armaOrder = c(1, 1), arfima = FALSE),
>>>> distribution.model = "std")
>>>>
>>>> fit = ugarchfit(spec = spec, data = alpha$Close, out.sample = 0,
>>>> solver = "solnp", solver.control = list(trace = 0))
>>>>
>>>> Error in if (all(dte[, i]<= 12)) m = i :
>>>>
>>>>     missing value where TRUE/FALSE needed
>>>>
>>>> In addition: There were 50 or more warnings (use warnings() to see the
>>>> first
>>>> 50)
>>>>
>>>>
>>>>
>>>> My reaction to this is, well of course there's missing values.  The
>>>> warnings are about NAs being produced (In FUN(newX[, i], ...) : NAs
>>>> introduced by coercion).
>>>>
>>>>
>>>>
>>>> So, I understand the error message and why it happens.  The question
>>>> is, "What can I do about it?"
>>>>
>>>>
>>>>
>>>> Are any of the steps I show in my data manipulation unnecessary?  (I
>>>> expect that they can be condensed into fewer statements, but I like to
>>>> see precisely what each step does before I condense the code.)
>>>>
>>>>
>>>>
>>>> Is there another step in my data manipulation that I need to add?
>>>>
>>>>
>>>>
>>>> Can any of the methods in the rugarch handle raw tick data directly?
>>>>
>>>>
>>>>
>>>> As an aside, I saw mention of rmgarch in the documentation, but when I
>>>> select "Install packages" from the Packages submenu, I do not see it
>> listed.
>>>> Is it not yet available?  If so, is rgarch the principle alternative
>>>> for multivariate analyses (and if so, with what caveats)?
>>>>
>>>>
>>>>
>>>> Any enlightenment beyond what I found in the manual would be greatly
>>>> appreciated.
>>>>
>>>>
>>>>
>>>> Thanks
>>>>
>>>>
>>>>
>>>> Ted
>>>>
>>>>
>>>>     [[alternative HTML version deleted]]
>>>>
>>>> _______________________________________________
>>>> R-SIG-Finance at r-project.org 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.
>>>>
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org 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.
>>
>



More information about the R-SIG-Finance mailing list