[R] How to set frequncy?
R. Michael Weylandt
michael.weylandt at gmail.com
Mon Apr 22 13:16:07 CEST 2013
On Mon, Apr 22, 2013 at 9:54 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
> If stock prices are daily data, use frequency = 1.
The frequency attribute for a "ts" class time series is somewhat
subtle. It's the amount of observations per seasonal period / relevant
cycle, where relevant is a bit of a judgement call.
E.g., suppose I have hourly readings of some sort of astronomical
data. If it's one sort solar data, I might want to have my frequency
equal to 24, being the number of hours in a daily. If it's based on
moon things, I might want to have my frequency being 24*28 (roughly
the hours in a lunar cycle). And if it's based on the movement of the
earth through it's orbit, perhaps 24*365 makes sense. Still, this is
all "hourly" data....
The assumption underlying this then is that there's a single major
structural frequency to your data and that you want modelling
functions to respect this frequency.
If the OP has daily data, either 21 or 252 might make sense, depending
on whether we're trying to model monthly or yearly cycles. (Or perhaps
some other frequency, such as quarterly giving 84 for a frequency if
we're looking at something driven by earnings announcements or the
Ultimately, the base "ts" series isn't great for financial data. 252
trading days is not uniform across all markets and assets, nor will
"daily" data be truly uniform. (weekends, holidays, etc) There's also
some interesting research on what one might call "non-linear time" for
modelling financial data, but that's now getting somewhat out of the
scope of the original question.
In short, I'd advise the OP use "xts" instead which uses truly time
stamped (and quite likely irregular) data.
More information about the R-help