[R] Fwd: Reg: Frequency in declaring time series data

Eric Berger er|cjberger @end|ng |rom gm@||@com
Tue Jan 17 17:51:59 CET 2023


Hi Upananda,
A few comments:
1. As you know, CRAN has thousands of packages. One of the ways to
learn about the packages you might care about is to use the CRAN
views. A 'view' is an attempt to provide some information on a certain
subset of the packages related to a particular area.
See a list of the views at: https://cran.r-project.org/web/views/
2. In your case, you might be interested in the 'Time Series' view:
https://cran.r-project.org/web/views/TimeSeries.html
3. On that page, the subsection 'Time Series Classes' mentions two
packages, 'tsbox' and 'timetk' which provide tools to convert between
different representations of time series used in different packages. I
have not used either of these packages, but perhaps they could be of
use to you.
4. For financial time series, it is often useful to have the exact
dates. Rui mentioned the zoo package. I often use the xts package.
xts = eXtensible Time Series. The xts package is an extension of the
zoo package.
5. If your data is coming from market prices, and you have daily data
corresponding to market prices, then presumably you don't have weekend
or holiday prices (when the markets are closed). This leads to about
250 or 252 trading days per year (52 weeks X 5 days/wk = 260, minus
8-10 holidays). It is standard in financial calculations to annualize
based on 250 or 252. So, you might want to specify a frequency of 250
or 252 in your time series when creating a ts object.

I hope that helps,
Eric


On Tue, Jan 17, 2023 at 6:29 PM Upananda Pani <upananda.pani using gmail.com> wrote:
>
> Hi Rui,
>
> Thank you so much for your help. As I have to fit a Markov Switching Model
> using  MSwM package.
>
> May I know whether i can convert from zoo object to a time series object.
>
> As I have to use several packages which uses ts so I am not able to decide
> how to do it.
>
> Grateful to you for your help and support.
>
> With sincere regards,
> Upananda
>
> On Tue, 17 Jan, 2023, 01:40 Rui Barradas, <ruipbarradas using sapo.pt> wrote:
>
> > Às 16:39 de 16/01/2023, Upananda Pani escreveu:
> > > Dear All,
> > >
> > > I have a time series daily data with date are stored ( %dd-%mm-%yy
> > format )
> > > from 22-01-20 to 03-08-21. In total I have 560 observations. I am using
> > the
> > > following command to declare as a time series object. Here the the data
> > set
> > > is 7 days a week.
> > > oil <- read_xlsx("crudefinal.xlsx")
> > > pricet=ts(oil$price, start = c(2020, 22), freq = 365)
> > > roilt=ts(diff(log(oil$price))*100,start=c(2020,22), freq=365)
> > >
> > > Shall I have to declare the dates here?  I want to know also if it is a 5
> > > day trading a week, how to declare the frequency.
> > >
> > > Looking forward to your reply
> > >
> > > Regards,
> > > Upananda Pani
> > >
> > > Looking forward to your suggestions.
> > >
> > >       [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> > Hello,
> >
> > Package zoo is the best way of having dates in a time series. The
> > package comes with several vignettes that can get you started quickly.
> > See the difference between classes ts and zoo below.
> >
> > # make up some test data
> > oil <- data.frame(price = cumsum(rnorm(560)))
> > oil$date <- seq(as.Date("2020-01-22"), by = "1 day", length.out = 560)
> >
> > # base R
> > pricet <- ts(oil$price, start = c(2020, 22), freq = 365)
> > time(pricet)
> > index(pricet)
> > plot(pricet)
> >
> > #---
> >
> > library(zoo)
> > library(ggplot2)
> >
> > pricez <- zoo(oil$price, order.by = oil$date)
> > time(pricez)
> > index(pricez)
> > autoplot(pricez)
> >
> > vignette(package = "zoo")
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> >
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list