[R-SIG-Finance] Properly making a xts object from csv file

Joshua Ulrich josh.m.ulrich at gmail.com
Tue Nov 15 20:05:07 CET 2016


Hi Colton,

On Tue, Nov 15, 2016 at 12:50 PM, Colton Smith <coltonsmith321 at gmail.com> wrote:
> Hello,
>
> I'm currently wokring with a csv file that looks like this:
>
Pictures of data aren't particularly helpful.  Someone would have to
hand-enter those values to be able to do anything meaningful with the
data.

> I'm trying to make it an xts object so I can use it for backtesting. If I
> detach dplyr, errors happen on the stock() line and if I have dplyr attached
> errors happen initPortf()/initOrders().
>
Pictures of code are even less helpful than pictures of data.  No one
can copy/paste your picture into their R console to try and replicate
your results. ;)

> I'm aware of the frustrating interactions between dplyr and finance
> packages. I assume there is a proper way to go about this without using
> dplyr. If anybody could link me to an example or explain what I need to use,
> that'd be great!
>
Nothing in FinancialInstrument depends on dplyr, so there's no way
that *not* having dplyr attached could cause an issue with stock().
The problem is that you're passing an xts object as the 'primary_id',
when the documentation says:

primary_id: String describing the unique ID for the instrument. Most of
          the wrappers allow this to be a vector.

dplyr shouldn't cause issues with most package code, because most
packages should now protect themselves from the sort of badness in
dplyr (I'm looking at you, dplyr::lag).  But it will cause issues for
you at the top-level, because calling lag() on an xts object won't do
what you'd expect.

> Thanks,
> Colton Smith
>
> _______________________________________________
> 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.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2016 | www.rinfinance.com



More information about the R-SIG-Finance mailing list