Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tq_get() Quandl data is returned newest to oldest #32

Closed
DavisVaughan opened this issue Apr 10, 2017 · 0 comments
Closed

tq_get() Quandl data is returned newest to oldest #32

DavisVaughan opened this issue Apr 10, 2017 · 0 comments
Labels

Comments

@DavisVaughan
Copy link
Collaborator

DavisVaughan commented Apr 10, 2017

Most tq_get sources return data oldest to newest, and many functions rely on this format. Quandl data is not returned that way.

(Thanks to Rick for the example)

library(tidyquant)

CL_F1 = tq_get('CHRIS/CME_GC1', get = 'quandl')

ggplot(subset(CL_F1,date > '2016-01-01'),aes(x = date, y = settle)) +
  geom_line() +                  
  geom_ma(ma_fun = EMA, n = 126)

The EMA is thrown off and calculated backwards because of this. Arrange quandl data using something like:

CL_F1_multi = tq_get(x = c('CHRIS/CME_GC1', 'CHRIS/CME_C10'),
               get = 'quandl')
CL_F1_multi_sorted <- CL_F1_multi %>%
    mutate(symbol = forcats::as_factor(symbol)) %>%
    arrange(symbol, date) %>%
    mutate(symbol = as.character(symbol))

Converting to factor will take care of arrange attempting to order symbol alphabetically and ruining the user defined order.

EDIT: Going to overwrite the Quandl option order = "asc" instead.

DavisVaughan pushed a commit that referenced this issue Apr 16, 2017
Fixes #32 - Quandl now returns data oldest to newest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant