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

Ulrich Staudinger ustaudinger at activequant.com
Mon Feb 4 14:04:42 CET 2013


Am confirming what Phil said ...
>  getSymbols("SPY", src="yahoo", from="2012-06-01")
[1] "SPY"
> to.monthly(SPY) # looks correct
         SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
Jun 2012   129.41   136.27  127.14    136.10 3644670300       134.42
Jul 2012   136.48   139.34  132.60    137.71 2864743300       136.01
Aug 2012   138.70   143.09  135.58    141.16 2413590900       139.42
Sep 2012   141.04   148.11  140.13    143.97 2391233500       142.96
Oct 2012   144.52   147.16  140.39    141.35 2719915500       140.35
Nov 2012   141.65   143.72  134.70    142.15 3032769100       141.15
Dec 2012   142.80   145.58  139.54    142.41 2889875900       142.41
Jan 2013   145.11   150.94  144.73    149.70 2587140200       149.70
Jan 2013   150.65   151.42  150.39    151.24  131148500       151.24
> indexTZ(SPY) <- "America/Chicago"
> to.monthly(SPY) # Missing January Print
         SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
May 2012   129.41   131.50  128.16    128.16  253240900       125.93
Jun 2012   128.39   136.27  127.14    136.10 3391429400       134.42
Jul 2012   136.48   139.34  132.60    137.59 3003037100       135.90
Aug 2012   136.55   143.09  135.58    141.16 2275297100       139.42
Sep 2012   141.04   148.11  140.13    144.35 2527144700       143.33
Oct 2012   144.92   147.16  140.39    142.83 2684999900       141.82
Nov 2012   143.68   143.72  134.70    142.15 2931773500       141.15
Dec 2012   142.80   145.58  139.54    142.41 2889875900       142.41
Jan 2013   145.11   151.42  144.73    151.24 2718288700       151.24
Warning message:
timezone of object (America/Chicago) is different than current timezone ().
> SPY[endpoints(SPY, "months")] # Same thing here
           SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2012-05-31   129.41   131.50  128.16    128.16  253240900       125.93
2012-06-28   135.20   136.27  134.85    136.10  212250900       134.42
2012-07-31   138.70   138.73  137.40    137.59  138293800       135.90
2012-08-30   141.29   141.82  140.36    141.16  151970400       139.42
2012-09-30   144.52   145.69  144.01    144.35  135911200       143.33
2012-10-31   141.65   143.01  141.52    142.83  100995600       141.82
2012-11-29   142.14   142.42  141.66    142.15  136568300       141.15
2012-12-30   139.66   142.56  139.54    142.41  243935200       142.41
2013-01-31   150.65   151.42  150.39    151.24  131148500       151.24
>


So, it must be some sort of a timezone issue?



On Mon, Feb 4, 2013 at 1:55 PM, Phil Elsasser <paelsasser1 at gmail.com> wrote:
> I am having a very similar issue.
>
> I believe.  Here is some code to reproduce it.
>
>
>  getSymbols("SPY", src="yahoo", from="2012-06-01")
> to.monthly(SPY) # looks correct
> indexTZ(SPY) <- "America/Chicago"
> to.monthly(SPY) # Missing January Print
>
> SPY[endpoints(SPY, "months")] # Same thing here
>
>  packageVersion("xts")
> [1] ‘0.9.2’
>
>
> On Mon, Feb 4, 2013 at 5:00 AM,  <r-sig-finance-request at r-project.org> wrote:
>> Send R-SIG-Finance mailing list submissions to
>>         r-sig-finance at r-project.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>         https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> or, via email, send a message with subject or body 'help' to
>>         r-sig-finance-request at r-project.org
>>
>> You can reach the person managing the list at
>>         r-sig-finance-owner at r-project.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of R-SIG-Finance digest..."
>>
>>
>> Today's Topics:
>>
>>    1. bug on to.monthly? (Ulrich Staudinger)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Mon, 4 Feb 2013 11:58:15 +0100
>> From: Ulrich Staudinger <ustaudinger at activequant.com>
>> To: R-SIG-Finance <r-sig-finance at r-project.org>
>> Subject: [R-SIG-Finance] bug on to.monthly?
>> Message-ID:
>>         <CAMrz3D1_x4-g2P7xfh7PRJe-DoAHRbAwk8ASPfhCJezYUzd=Hg at mail.gmail.com>
>> Content-Type: text/plain; charset=UTF-8
>>
>> 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 mailing list
>> R-SIG-Finance at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>
>>
>> End of R-SIG-Finance Digest, Vol 105, Issue 4
>> *********************************************
>
> _______________________________________________
> 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