In this sense I don't see any difference between using eikon library in Python and eikonapir library in R. In both cases the API documentation describes only the methods available in the library. And metadata discovery (finding field names and parameters to retrieve specific data items) is done using GUI tools available in Eikon. Take a look at this tutorial, which talks at length about metadata discovery for use with Eikon Data APIs.
I'm not sure what the purpose of this exercise could possibly be. If you'd like to use data retrieved from Eikon in R, you could retrieve the data directly into R using this library.If for whatever reason you need to retrieve data using Python and then use this data in R, you can easily save a pandas dataframe to a csv file and import the latter into R. This sounds like an obvious solution, which makes me feel I might be missing something here. Would you care to elaborate on what challenge you're trying to solve?
I want to get data from Eikon API, which is python, but I'm more familiar coding in R. I tried to use eikonapir package in R, but seems like the data downloading capability is limited/not much documentation. For example, how do you convert the following python code to R using eikonapir?
data_grid, err = ek.get_data(
tickerString,
fields = ['TR.TotalReturn1Mo.date','TR.TotalReturn1Mo','TR.PE','TR.PriceToCFPerShare',
'TR.PriceToBVPerShare','TR.EVToEBITDA','TR.FwdPE','TR.FwdEVToEBITDA','TR.FwdNetDebtToEBITDA'],
parameters={'SDate':'2007-12-31','EDate':'2010-11-30','Frq':'M','CH':'Fd'})
Eventually, I learned to save the result to be read in R with the following:
path = 'C:/Users/.../eikon4.feather'
feather.write_dataframe(data_grid, path)
But if you could teach me how to download the above data directly with R, it would same me a lot of trouble.
Thanks!
@helenyzha I use directly the R package `reticulate` to call the Python functions directly from R. It goes as follows:
```
library(reticulate)
ek <- import("eikon")
ek$set_app_key('YOURKEY')
Then you can use any function such as `get_data` directly: `ek$get_data(...)` with same parameters as in Python. You can then use `reticulate::py_to_r` to parse some Python datastructures to R. Data in R is parsed to the JSON format, see the library `jsonlite` for more details.
I suggest that you use this approach, then you can build your own library to query from Eikon from R.
Thank you @melvin.kian ! I tried, the following worked:
But I still don't know how to make this following line to work:
"IBM",
fields = ['TR.TotalReturn1D.date','TR.TotalReturn1D'],
parameters={'SDate':'2010-02-01','EDate':'2019-10-03','Frq':'M','CH':'Fd'})
I tried:
ek$get_data(
but didn't work.
Thank you so much!
Try
ek$get_data("IBM",
fields = list('TR.TotalReturn1D.date','TR.TotalReturn1D'),
parameters=list(SDate='2010-02-01',EDate='2019-10-03', Frq='M',CH='Fd')
)
Best!
melvin.kian
I don't think I understand what the challenge is in using eikonapir library. The design of the library follows very closely that of the eikon Python library. There are only minor differences in syntax mandated by the language conventions. The documentation for eikonapir library available on Github describes each method available in the library and illustrates it with examples. Here's how you can retrieve the history of 1 day total return for a stock on the last trading day of each month between two dates (which is what the Python example posted by @helenyzha earlier today does) using eikonapir.
library(eikonapir)set_app_id('your_app_key')get_data('IBM',list('TR.TotalReturn1D.date','TR.TotalReturn1D'),list(SDate='2010-02-01',EDate='2019-10-03', Frq='M'))
Alex Putkov! My challenge with eikonapir is that there is not much documentation on it. I don't know how to write code to get data. All documentation I have is this https://github.com/ahmedmohamedali/eikonapir/tree/master/man, where I couldn't find how to set SDate and EDate. Thanks for teaching me this. Do you have more documentation or examples? Thanks!