[R-SIG-Finance] bug on to.monthly?

Joshua Ulrich josh.m.ulrich at gmail.com
Mon Feb 4 18:11:24 CET 2013


Works fine for me, even with your timezone.

> Lines <- "2013-01-30;100
+ 2013-01-31;101
+ 2013-02-01;102"
>
> library(xts)
> Sys.setenv(TZ="Europe/Berlin")
> x1 <- read.zoo(con <- textConnection(Lines), sep=";")
> close(con)
> as.POSIXct(index(x1))
[1] "2013-01-30 01:00:00 CET" "2013-01-31 01:00:00 CET"
[3] "2013-02-01 01:00:00 CET"
> to.monthly(x1)
         x1.Open x1.High x1.Low x1.Close
Jan 2013     100     101    100      101
Feb 2013     102     102    102      102
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets
[6] methods   base

other attached packages:
[1] xts_0.9-3 zoo_1.7-9

loaded via a namespace (and not attached):
[1] grid_2.15.2     lattice_0.20-10
>

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

R/Finance 2013: Applied Finance with R  | www.RinFinance.com


On Mon, Feb 4, 2013 at 4:58 AM, Ulrich Staudinger
<ustaudinger at activequant.com> wrote:
> Gents,
>
> I want to convert the following xts NAV series from daily to monthly.
>
> Browse[1]> navSeries
> [..]
> 2013-01-21 1089.233
> 2013-01-22 1088.627
> 2013-01-23 1086.648
> 2013-01-24 1095.522
> 2013-01-25 1100.402
> 2013-01-28 1098.846
> 2013-01-29 1105.938
> 2013-01-30 1102.504
> 2013-01-31 1102.386
> 2013-02-01 1111.651
>
> So I call ...
> monthlyNAV = to.monthly(navSeries)[,4]
>
> and it yields:
>
> Oct 2012        1034.037
> Nov 2012        1039.267
> Dec 2012        1055.666
> Jan 2013        1102.386
> Jan 2013        1111.651
> Browse[1]>
>
>
> As you can see, the Jan2013 exists twice!
>
> I also had a look at the index already:
> Browse[1]> tail(index(navSeries))
> [1] "2013-01-25 CET" "2013-01-28 CET" "2013-01-29 CET" "2013-01-30 CET"
> [5] "2013-01-31 CET" "2013-02-01 CET"
> Browse[1]>
>
>
> For reproduction, I made a little script:
>
> Here's test.csv:
> 2013-01-30;100
> 2013-01-31;101
> 2013-02-01;102
>
>> x1 = read.zoo("/opt/reports/etl/test.csv", sep=";")
>> index(x1)
> [1] "2013-01-30" "2013-01-31" "2013-02-01"
>> as.POSIXct(index(x1))
> [1] "2013-01-30 01:00:00 CET" "2013-01-31 01:00:00 CET"
> [3] "2013-02-01 01:00:00 CET"
>> to.monthly(x1)
>          x1.Open x1.High x1.Low x1.Close
> Jan 2013     100     101    100      101
> Jan 2013     102     102    102      102
> Warning message:
> In zoo(xx, order.by = index(x), ...) :
>   some methods for “zoo” objects do not work if the index entries in
> ‘order.by’ are not unique
>>
>
> Can someone shed some light?
>
> Thanks
> Ulrich
>
>
>
>
>
> --
> Ulrich Staudinger
>
> P: +41 79 702 05 95
> E: ustaudinger at activequant.com
>
> http://www.activequant.com
>
> AQ-R user? Join our mailing list:
> http://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/aqr-user
>
> _______________________________________________
> 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