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

Ulrich Staudinger ustaudinger at activequant.com
Mon Feb 4 21:25:26 CET 2013


Here's my session info.
I'll upgrade XTS and will let you know if I progress.

sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C                 LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] quantmod_0.3-17 TTR_0.21-1      xts_0.8-6       zoo_1.7-8
[5] Defaults_1.1-1

loaded via a namespace (and not attached):
[1] grid_2.15.1    lattice_0.20-6




On Mon, Feb 4, 2013 at 6:11 PM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
> 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.
>
> _______________________________________________
> 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.



-- 
Ulrich Staudinger, Managing Director and Sr. Software Engineer, ActiveQuant GmbH

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



More information about the R-SIG-Finance mailing list