Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key.ratios for non-us exchanges #26

Closed
haohua opened this issue Mar 31, 2017 · 12 comments
Closed

key.ratios for non-us exchanges #26

haohua opened this issue Mar 31, 2017 · 12 comments

Comments

@haohua
Copy link

haohua commented Mar 31, 2017

Hi Matt,

Thank you so much for the great package.

I am trying to load some key financial ratios for China A shares.
Your base function for the key.ratios are hard coded with US exchanges. Do you have plan to make it generalized to non-US exchanges?
I can manually download the key ratios from financials.morningstar.com
here is an example http://financials.morningstar.com/income-statement/is.html?t=XSHE:200725&region=CHN&ops=clear

Thank you
andy

@haohua
Copy link
Author

haohua commented Mar 31, 2017

@mdancho84
Copy link
Collaborator

Great question, and the short answer is Yes! We are evaluating Morningstar for both key ratios and financials. Key ratios are already implemented, but as you point out the implementation could be improved by adding additional arguments such as region to allow the user a more flexible data retrieval.

For financials, we are evaluating the change from Google Finance to Morningstar, and allowing the user the flexibility to select statement_type, value_type, etc to make it more flexible and even more useful.

I'll leave this as an open issue until we implement the feature improvements. This way you'll be notified when the development version has the features incorporated.

@haohua
Copy link
Author

haohua commented Mar 31, 2017

Thank you Matt.

@robby81
Copy link

robby81 commented Apr 19, 2017

I have a similar problem with german stocks. e.g. Volkswagen have the url: http://financials.morningstar.com/valuation/price-ratio.html?t=XETR:VOW&region=DEU

However:
tq_get("VOW", get = "key.ratios")
[1] NA
Warning message:
x = 'VOW', get = 'key.ratios': Error in UseMethod("as_list"): no applicable method for 'as_list' applied to an object of class "NULL"

AND:

tq_get("XETR:VOW", get = "key.ratios")
[1] NA
Warning message:
x = 'XETRVOW', get = 'key.ratios': Error in UseMethod("as_list"): no applicable method for 'as_list' applied to an object of class "NULL"

Do you have a solution how to get these key.ratios?

@mdancho84
Copy link
Collaborator

Thanks for the heads up on this. I'll add this to the mix as well. I believe there's a solution to key in on the colon during the download and to handle the errors more gracefully.

@mwaldstein
Copy link

I was looking at some european stocks and ran into this limitation as well. My preliminary change is here: mwaldstein@3812ae4

I took a stab at allowing arbitrary exchange sources, but a lot of the later code is hard coded to USD for calculated ratios - e.g. historic P/E

It might be a good idea to split the "raw" key ratios fetched from morning star from the calculated ratios, at least as an intermediate step allowing the user to get the core data while the other components wait on a more robust solution to manage different currencies.

@mdancho84
Copy link
Collaborator

Just took a look at the code, and it looks great. I'd like to test it out though when I get a minute. We have a few things going on this week, but we'll be definitely including this improvement in the next major version coming soon.

@mwaldstein
Copy link

mwaldstein commented Jun 15, 2017

My code is pretty unsafe right now (and is why I didn't put in a pull request) - For instance I was specifically looking to pull in data on PINA:UBSFF, a french company, so all the financials are in EUR Mil, creating problems as USD is hard-coded later in the function (e.g. https://github.com/mwaldstein/tidyquant/blob/3812ae457674f3c635c92e7f3071dfe8b26bff91/R/tq_get.R#L591)

There is also a bit of a failure that I haven't investigated in fetching the stock prices (here: https://github.com/mwaldstein/tidyquant/blob/3812ae457674f3c635c92e7f3071dfe8b26bff91/R/tq_get.R#L583) since the collection of stock prices doesn't match...

A better solution, which I might take a stab at, is to split get="key.ratios" into two -

  • A "simple" wrapper/cleanup of the Morninstar raw data without any computation - this would need a new name - raw.ratios?
  • The existing key.ratios with the first half replaced by a call to the above. This way, the simpler function is still available for companies that fail at the calculation.

I may take a quick stab at the above refactoring - should help with testing / debugging as well...

tldr - for european companies, there are deeper problems that my simplistic solution doesn't fix.

@mdancho84
Copy link
Collaborator

Let me know what you find out. I'll certainly incorporate any code that makes the functions more accurate. I'm finding that it's difficult to account for all the possibilities in a global market.

I was thinking of potentially scrapping the P/E ratio calculation, or like you said have a mechanism to enable the user to have options. The big issue for me is if there is potential for the calculation to be done incorrectly due to currency. If this cannot be checked, then I don't want to see users get incorrect results.

@vikram-rawat
Copy link

can I get data of Indian Stock Exchanges Please.

@mdancho84
Copy link
Collaborator

Key Ratios should now at a minimum pull non-US exchange key ratios. The Valuation Ratio calculation may not be compatible with Yahoo Finance prices, and therefore will not be returned.

> tq_get(c("XETR:VOW", "AAPL"), get = "key.ratios")
# A tibble: 13 x 3
   symbol   section           data              
   <chr>    <chr>             <list>            
 1 XETR:VOW Financials        <tibble [150 x 5]>
 2 XETR:VOW Profitability     <tibble [170 x 5]>
 3 XETR:VOW Growth            <tibble [160 x 5]>
 4 XETR:VOW Cash Flow         <tibble [50 x 5]> 
 5 XETR:VOW Financial Health  <tibble [240 x 5]>
 6 XETR:VOW Efficiency Ratios <tibble [80 x 5]> 
 7 AAPL     Financials        <tibble [150 x 5]>
 8 AAPL     Profitability     <tibble [170 x 5]>
 9 AAPL     Growth            <tibble [160 x 5]>
10 AAPL     Cash Flow         <tibble [50 x 5]> 
11 AAPL     Financial Health  <tibble [240 x 5]>
12 AAPL     Efficiency Ratios <tibble [80 x 5]> 
13 AAPL     Valuation Ratios  <tibble [40 x 5]> 
Warning message:
VOW: simpleWarning in fun_transmute(eval(parse(text = x)), OHLC = FALSE, ...): missing values removed from data
 

@carsancheznew1999
Copy link

I have been trying to get key ratios for brazilian stocks but the following error message appears. Do you have any idea? I have already checked the Morningstar's web page and the symbol seems correct.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants