[R-SIG-Finance] Transforming Price Timeseries
alexios
alexios at 4dscape.com
Thu Apr 21 22:42:28 CEST 2011
You can do this with base R:
Assuming your data is called "dat", and it is in the format you
presented, then the following code should work:
# create 4 digit hour (note that 2400 is 0000).
tm = c(paste(0,seq(100,900,by=100),sep = ""), seq(1000,2300,by = 100),
"0000")
# date column assuming character vector
dt = as.character( dat[,1] )
# the 24 price columns
price = as.matrix( dat[,-1] )
# create a composite date-time character vector
newdt = as.vector( apply(as.data.frame(dt), 1, FUN = function(x)
as.character(strptime(paste(x," ", tm,sep = ""), "%Y-%m-%d %H"))) )
# transform from matrix to vector by row
newprice = as.vector(price)
newdat = data.frame(Date = newdt, price = newprice)
See the ?DateTimeClasses for more information and also timezone codes.
Hope that helps.
Best,
Alexios
On 21/04/2011 20:55, Johannes Lips wrote:
> Hello,
>
> I have a little problem for which I don't have a solution. I have
> electricity prices for each hour of the day, since that's the normal
> form of contracts traded at energy exchanges.
>
> The current format looks like this:
> Date EEXHR01 EEXHR02 EEXHR03 ... EEXHR22 EEXHR23 EEXHR24
> 1 2000-06-16 12.43 12.40 12.40 ... 15.45 14.57 14.57
> 2 2000-06-17 10.06 10.04 10.04 ... 12.82 12.83 12.82
> 3 2000-06-18 10.08 10.08 9.00 ... 11.78 11.80 11.78
> 4 2000-06-19 12.05 12.05 10.05 ... 16.42 14.95 14.95
>
> I now would to transform this daily data into hourly data and make a
> 'continous' time series. Something like:
> Date EEXPrice
> 2000-06-16-01:00 12.43
> 2000-06-16-02:00 12.40
> . .
> . .
> . .
> 2000-06-16-24:00 14.57
>
> Is this possible with R or should I use something different?
> If you need more information, just ask, pleas.
>
> Thanks in advance!
>
> Best Regards,
>
> Johannes
>
> _______________________________________________
> 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