[R-SIG-Finance] Problem using stl() on data from quantmod

Wind windspeedo at qq.com
Tue Dec 30 03:13:03 CET 2008


Thanks Jeff.
You made me fully understand this issue.

Regards,
Wind

 
 
------------------ Original ------------------
From:  "Jeff Ryan"<jeff.a.ryan at gmail.com>;
Date:  Tue, Dec 30, 2008 00:10 AM
To:  "Brian G. Peterson"<brian at braverock.com>; 
Cc:  "Wind"<windspeedo at qq.com>; "r-sig-finance"<r-sig-finance at stat.math.ethz.ch>; 
Subject:  Re: [R-SIG-Finance] Problem using stl() on data from quantmod

 
The issue is in stl which will convert (try) to ts internally:

> stl
function (x, s.window, s.degree = 0, t.window = NULL, t.degree = 1,
....
    x <- na.action(as.ts(x))
    if (is.matrix(x))
        stop("only univariate series are allowed")
    n <- length(x)
    period <- frequency(x)
    if (period < 2 || n <= 2 * period)
        stop("series is not periodic or has less than two periods")

Which will result in an object of freq=1, and thus throw an error.

Jeff

On Mon, Dec 29, 2008 at 9:49 AM, Brian G. Peterson <brian at braverock.com> wrote:
> Ok, I see no reason at all for using as.ts here.  Leave your data in xts.
>
> Wind <windspeedo at qq.com> wrote:
>
>>With the following code,
>>
>>getSymbols("^GSPC")
>>xx<-as.ts(GSPC[,4])
>>xx<-na.approx(xx)
>>plot(stl(log(xx),s.window="period"))
>>
>>There is an error:
>>Error in stl(log(xx), s.window = "period") :
>>  only univariate series are allowed
>>
>>> str(log(xx))
>> ts [1:724, 1] 7.26 7.26 7.25 7.25 7.25 ...
>> - attr(*, "dimnames")=List of 2
>>  ..$ : NULL
>>  ..$ : chr "GSPC.Close"
>> - attr(*, "tsp")= num [1:3] 13516 14239     1
>>
>>It seems that the structure of xx is a little complicated.   But I still don't know how to trim it to the simplest ts format.
>>
>>Regards,
>>Wind
>>
>>_______________________________________________
>>R-SIG-Finance at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>-- Subscriber-posting only.
>>-- If you want to post, subscribe first.
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list