Skip to content

Properly making a xts object from csv file

2 messages · Colton Smith, Joshua Ulrich

#
Hello,

I'm currently wokring with a csv file that looks like this:
[image: Inline image 1]
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().
[image: Inline image 1]
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!

Thanks,
Colton Smith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20161115/ade1a1d1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 21163 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20161115/ade1a1d1/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 69809 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20161115/ade1a1d1/attachment-0001.png>
#
Hi Colton,
On Tue, Nov 15, 2016 at 12:50 PM, Colton Smith <coltonsmith321 at gmail.com> wrote:
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.
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. ;)
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.