Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

While investigating Intraday patterns in FX returns and order flow paper I have faced the problem with timezone. I had 3 data sources with different timezones (GMT, CET, CEST). Most confusing thing was, that I didn’t know, how to deal with summer time.
But why did I have the data with summer time in the first place?  Well, I use IBrokers package to get latest Forex data and turns out, that it is impossible to specify timezone parameter within reqHistoricalData function. Once the data is received, it assigns default timezone of R (in my case GMT), but the requested data comes with OS timezone (CET/CEST in my case). It took for while to realize that, but the real challenge was how to convert CET/CEST to GMT.

The answer – don’t use CET/CEST, but instead of that use something like ‘Europe/Paris’ or ‘Europe/Berlin’. This approach takes into account summer time issue and you don’t need to worry about it. Once you have the data in ‘Europe/Paris’ or ‘Europe/Berlin’ format you can easily convert it:

?View Code RSPLUS
 Sys.setenv(TZ="Europe/Paris") eur.usd=reqHistoricalData(tws,currency,whatToShow='MIDPOINT',barSize='1 hour') Sys.setenv(TZ="GMT") eur.usd=xts(Op(eur.usd),tz='GMT')

or you can change the index:

?View Code RSPLUS
  format(eur.usd, tz="GMT",usetz=TRUE)