How to get R DataFrame from quantmod into Julia

76 views
Skip to first unread message

Reuben

unread,
Sep 3, 2016, 6:43:57 PM9/3/16
to julia-stats
HI,

I am trying to use the quantmod "getFinancials" and "viewFinancials" functions to easily get financial statements into julia.

using RCall, DataFrames

reval("library(\"quantmod\")")

r= reval("getFinancials('GOOGL')")

t = reval("viewFinancials(GOOGL.f, type = 'IS', period = 'Q')")

When I all do this in a julia notebook, get a decent looking table of what i am looking for: https://www.dropbox.com/s/uqd42wm4jwq8mz3/Screenshot%202016-09-03%2017.41.20.png?dl=0

However, when I try to display this information in a julia dataframe, i just end up with a collection of julia arrays: https://www.dropbox.com/s/taobxhqc26jc7tk/Screenshot%202016-09-03%2017.42.15.png?dl=0

Perhaps the issue is the R dataframe not being exactly in the format Julia is expecting; I'm not familiar with the R side much. The data is there, this is basically working, but it would be nice to get a full fledged Julia DataFrame with proper row labels.

-Reuben

Reuben

unread,
Sep 3, 2016, 8:16:05 PM9/3/16
to julia-stats
Actually, for clarification, what i am really looking for is a way to use a dictionarly-like indexing to get data based on the row label name. Whether i ever get it looking pretty in the notebook is not significant.

Milan Bouchet-Valat

unread,
Sep 4, 2016, 5:22:15 AM9/4/16
to julia...@googlegroups.com
Indeed, the result of viewFinancials() is not a data.frame, but a
matrix with names. Looks like names are currently not preserved, I've
file an issue:
https://github.com/JuliaStats/RCall.jl/issues/144

As a workaround, you can convert the results to a data.frame before
passing them to Julia. Though you also need to move the row names into
a column to preserve them:
rcopy("cbind(Names=rownames(t), as.data.frame(t))")


Regards


> -Reuben
> -- 
> You received this message because you are subscribed to the Google
> Groups "julia-stats" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to julia-stats...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reuben

unread,
Sep 4, 2016, 11:42:57 AM9/4/16
to julia-stats
Thank you Milan. Was able to work around based on your comment:

reval("library(\"quantmod\")")

r = reval("getFinancials('GOOGL')")
t = reval("viewFinancials(GOOGL.f, type = 'IS', period = 'Q')")
@rput t
u = rcopy("rownames(t)")
w = rcopy("colnames(t)")
v = @rget t

uf = DataFrame()
uf[:Field_Names] = u  
for i=1:length(w)
    uf[symbol(w[i])] = v[:,i]
end
uf
Reply all
Reply to author
Forward
0 new messages