milktrader / Quandl.jl

Julia api to Quandl open source financial, economic and social datasets
Other
67 stars 31 forks source link

to change quandlget() to accept any AbstractString, and not only ASCIIString. #91

Closed cndesantana closed 8 years ago

cndesantana commented 8 years ago

After some discussions at julia-users list (https://groups.google.com/forum/#!topic/julia-users/_J9-6CeACW8) I was suggested to create this issue.

I am using the function quandlget(id::ASCIIString) and everything works fine when I use it in a straightforward way:

julia> mydat = quandl("GOOG/NASDAQ_GOOG",rows=100,format="DataFrame") 100x6 DataFrames.DataFrame Row Date Open High Low Close Volume
1 2015-07-08 521.05 522.73 516.11 516.83 1.2967e6
2 2015-07-09 523.12 523.77 520.35 520.68 1.84235e6
3 2015-07-10 526.29 532.56 525.55 530.13 1.95668e6

or when I do:

julia> myid = "GOOG/NASDAQ_GOOG" "GOOG/NASDAQ_GOOG"

julia> typeof(myid) ASCIIString

julia> mydat = quandl(myid,rows=100,format="DataFrame") 100x6 DataFrames.DataFrame Row Date Open High Low Close Volume
1 2015-07-08 521.05 522.73 516.11 516.83 1.2967e6
2 2015-07-09 523.12 523.77 520.35 520.68 1.84235e6
3 2015-07-10 526.29 532.56 525.55 530.13 1.95668e6

However, I get an error when I read my data from an external file. Assume I have an ascii file containing only one line:

$ echo "GOOG/NASDAQ_GOOG" > portfolio.txt

$ cat portfolio.txt GOOG/NASDAQ_GOOG

I just read the content of this file by using readdlm and try to use it to call the same function quandl, but it does not work.

julia> myportfolio = readdlm("./portfolio.txt",'\n') 1x1 Array{Any,2}: "GOOG/NASDAQ_GOOG"

julia> typeof(myportfolio[1]) SubString{ASCIIString}

julia> mydat = quandl(myportfolio[1],rows=100,format="DataFrame") ERROR: MethodError: quandlget has no method matching quandlget(::SubString{ASCIIString})

The easiest way I found to solve this problem was to call a "cast" of myportfolio[1] to ASCIIString, like this:

julia> mydat = quandl(ASCIIString (myportfolio[1]),rows=100,format="DataFrame")

WARNING: deprecated syntax "ASCIIString (". Use "ASCIIString(" instead. 100x6 DataFrames.DataFrame Row Date Open High Low Close Volume
1 2015-07-09 523.12 523.77 520.35 520.68 1.84235e6
2 2015-07-10 526.29 532.56 525.55 530.13 1.95668e6
3 2015-07-13 532.88 547.11 532.4 546.55 2.20648e6

However, I think a good solution could be to change the quandl function to accept any AbstracStstring, and not only ASCIIString as a parameter. Would it be possible?

Thanks!

milktrader commented 8 years ago

Did you try it to see if it works yet?

milktrader commented 8 years ago

Yeah, it works. I'll change this.