-2

I'm starting programming R. I use Quandl to download historical futures data (GCG1975, GCJ1975, GCM1975, GCQ1975, GCV1975, GCZ1975, GCG1976, GCJ1976, GCM1976, ..., GCZ2016).

Month codes:

G J M Q V Z

Years:

1975:2016

I want to download it all, but I don't want to tape it all, so I think I want a function that downloads a year with all the months and then the next year again all the months. As an example, to download the first year:

require(Quandl)
Quandl("CME/GCG1975")

Any tip about the function or functions that are needed to this question is useful for me. Also if someone knows how to do it in Python is fine.

Thanks,

RTA

Community
  • 1
  • 1
  • This question was asked before and this part was answered in a comment: http://stackoverflow.com/questions/40942717/r-quandl-loop#comment69116089_40942717 . You are supposed to use the edit facility if you have additions, deletions or clarifications.And I would note that in this version you left out that forward-slash that was in your prior question. – IRTFM Dec 03 '16 at 23:04
  • Yes. I'm new and I'm impatient so this is a reaction. The answer was posted or at least I was writing before I saw your answer. I'm closing this question in 10 minutes. Thanks. – Ramón Tarí Agulló Dec 03 '16 at 23:12
  • If you edit your question I can remove my downvote. – IRTFM Dec 03 '16 at 23:27
  • Okey, I would like to know what you really want, I don't understand your recommendation so tell me again more explicit. Really is not about the downvote, is about that I feel I'm lost here. – Ramón Tarí Agulló Dec 03 '16 at 23:40

1 Answers1

0

This answer assumes reading of the earlier question and comments so is not "code only".

 qt = expand.grid(Month=c("G","J","M","Q","V"), Year=1975:2016) 
 query_names_vec <- apply(qt, 1, 
                       function(x) paste0("CME/GC", paste0( x, collapse="") ) )

> head( query_names_vec )
[1] "CME/GCG1975" "CME/GCJ1975" "CME/GCM1975" "CME/GCQ1975"
[5] "CME/GCV1975" "CME/GCG1976"
Community
  • 1
  • 1
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Yes. Thanks for your answer, I was updating the page when I saw your answer, so I'm not going to delet it. When I type your code,in one hand it computes `CME/GCG` without years, and on the other hand it computes `CME/GC1975` without month codes. Here is a screenshot [https://www.dropbox.com/s/ejo6h6kp0yxrj9n/stackoverflow-1.png?dl=0] Thanks 42- – Ramón Tarí Agulló Dec 03 '16 at 23:35
  • EDIT: I want to delete the previous comment but I can't, so I post a new one.: Thanks, I'm not going to delete the post. This works and now I'm thinking about implementing it like in the other post. I want to ask the questions to you, but I don't think if I can, probably I can mention you. Thanks for your time @42- – Ramón Tarí Agulló Dec 03 '16 at 23:42
  • You can do something along the lines of: `list_of_quandls <- sapply( query_names_vec, Quandl)`. (Hint:If you don't upvote useful answers people will stop paying attention to your questions.) – IRTFM Dec 03 '16 at 23:52
  • When I click upvote, Stackoverflow says me "Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score". When you says -along the lines- means to put it in the code in some place. If I use this `sapply()` the output is: `Error in match.fun(FUN) : object 'Quandl' not found` but I suppose that you knows it. Thanks 42- – Ramón Tarí Agulló Dec 04 '16 at 00:06
  • Have you loaded Quandl package for this session? I jsut tried and got no such error, but I do now think it should be done with lapply to keep them separate. – IRTFM Dec 04 '16 at 00:12
  • Yes it was, this means I need to sleep (I'm in Spain). Loading `Quandl` package and `Quandl.api_key` and typing your `sapply()` function, the output is `Error: {"quandl_error":{"code":"QECx02","message":"You have submitted an incorrect Quandl code. Please check your Quandl codes and try again."}}` Also when I see `query_names_vec` all seems correct. I'm going to click the "tick" because it seems you have got a lot of them. Thanks 42- – Ramón Tarí Agulló Dec 04 '16 at 00:20
  • I ran it without difficulty using the first three items (and I don't have any apikey) – IRTFM Dec 04 '16 at 00:27
  • I don't know what's happening, so I will try to run and assimilate the information and your answers tomorrow. My Console is too long so I can't write it here, but I have take a screenshot [https://www.dropbox.com/s/2e3n7or5nd2x7kn/stackoverflow-2.png?dl=0]. Thanks for your time, tomorrow I'll come with "fresh" ideas. Thanks 42- – Ramón Tarí Agulló Dec 04 '16 at 00:43
  • When I try with the full vector I get an error: `"You have exceeded the API speed limit of 20 calls per 10 minutes. Please slow down your requests."` – IRTFM Dec 04 '16 at 00:56
  • Yes happens because there's a rate limit or speed limit for API usage: `anonymous users` has `20 calls / 10 minutes` and `logged-in free users` (like me) has `2000 calls / 10 minutes`. The -logged- in free- is to create an account on `Quandl` and add `Quandl.api_key("API-KEY")` in the code. The error is in `Quandl database` because `"CME/GCV1980"` doesn't exists so returns error. It can be avoided manually or automatic with a message to `alert` that I don't know how to do it. A visual confirmation is on [https://www.quandl.com/collections/futures/cme-gold-futures]. `lapply()` is better. Thnks – Ramón Tarí Agulló Dec 04 '16 at 12:14