How to get R DataFrame from quantmod into Julia

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to get R DataFrame from quantmod into Julia

Reuben
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

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get R DataFrame from quantmod into Julia

Reuben
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.

On Saturday, September 3, 2016 at 5:43:57 PM UTC-5, Reuben wrote:
HI,

I am trying to use the <a href="http://www.quantmod.com/documentation/getFinancials.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.quantmod.com%2Fdocumentation%2FgetFinancials.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwL9bFV9t26S2JHHbdTky9Fz1Mpw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.quantmod.com%2Fdocumentation%2FgetFinancials.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwL9bFV9t26S2JHHbdTky9Fz1Mpw&#39;;return true;">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: <a href="https://www.dropbox.com/s/uqd42wm4jwq8mz3/Screenshot%202016-09-03%2017.41.20.png?dl=0" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.dropbox.com%2Fs%2Fuqd42wm4jwq8mz3%2FScreenshot%25202016-09-03%252017.41.20.png%3Fdl%3D0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHlYAASARqtCoZOr8Vs9jFwRlhujg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.dropbox.com%2Fs%2Fuqd42wm4jwq8mz3%2FScreenshot%25202016-09-03%252017.41.20.png%3Fdl%3D0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHlYAASARqtCoZOr8Vs9jFwRlhujg&#39;;return true;">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: <a href="https://www.dropbox.com/s/taobxhqc26jc7tk/Screenshot%202016-09-03%2017.42.15.png?dl=0" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.dropbox.com%2Fs%2Ftaobxhqc26jc7tk%2FScreenshot%25202016-09-03%252017.42.15.png%3Fdl%3D0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEJtkmA7ktzNqf1gCcrtpMcrwRQjw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.dropbox.com%2Fs%2Ftaobxhqc26jc7tk%2FScreenshot%25202016-09-03%252017.42.15.png%3Fdl%3D0\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEJtkmA7ktzNqf1gCcrtpMcrwRQjw&#39;;return true;">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

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get R DataFrame from quantmod into Julia

Milan Bouchet-Valat
In reply to this post by Reuben
Le samedi 03 septembre 2016 à 15:43 -0700, Reuben a écrit :

> 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/Scre
> enshot%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.
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 [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get R DataFrame from quantmod into Julia

Reuben
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

On Sunday, September 4, 2016 at 4:22:15 AM UTC-5, Milan Bouchet-Valat wrote:
Le samedi 03 septembre 2016 à 15:43 -0700, Reuben a écrit :

> 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: <a href="https://www.dropbox.com/s/uqd42wm4jwq8mz3/Scre" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.dropbox.com%2Fs%2Fuqd42wm4jwq8mz3%2FScre\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHodf6yhcGSfUCQbu9kE6q0Uh898w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.dropbox.com%2Fs%2Fuqd42wm4jwq8mz3%2FScre\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHodf6yhcGSfUCQbu9kE6q0Uh898w&#39;;return true;">https://www.dropbox.com/s/uqd42wm4jwq8mz3/Scre
> enshot%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: <a href="https://www.dropbox" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.dropbox\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG5VXOC-fz_pAC053byHapX8IP2Vw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.dropbox\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG5VXOC-fz_pAC053byHapX8IP2Vw&#39;;return true;">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.
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:
<a href="https://github.com/JuliaStats/RCall.jl/issues/144" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FJuliaStats%2FRCall.jl%2Fissues%2F144\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGkBXMvT04ys450JK2AfmBxdBt6TA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FJuliaStats%2FRCall.jl%2Fissues%2F144\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGkBXMvT04ys450JK2AfmBxdBt6TA&#39;;return true;">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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="mZrZyyhzAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">julia-stats...@googlegroups.com.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...