alvarobartt / investpy

Financial Data Extraction from Investing.com with Python
https://investpy.readthedocs.io/
MIT License
1.59k stars 375 forks source link

different currency for get_stock_financial_summary and get_stock_information #381

Closed zinovevvv closed 3 years ago

zinovevvv commented 3 years ago

Can u help me with this issue, when I get information about market cup and others I can understand what the currency in use with search_stocks in column 'currency':

In [3]: investpy.search_stocks('symbol', 'BTI')
Out[3]: 
         country                          name                         full_name          isin currency symbol
0         canada      biOasis Technologies Inc          biOasis Technologies Inc  CA09064N1033      CAD    BTI
1  united states  British American Tobacco ADR  British American Tobacco PLC ADR  US1104481072      USD    BTI
2      australia       Bailador Technology Inv           Bailador Technology Inv  AU000000BTI4      AUD    BTI
3   south africa      British American Tobacco      British American Tobacco PLC  GB0002875804      ZAR   BTIJ
In [4]: investpy.get_stock_information('BTI', 'united states')
Out[4]: 
  Stock Symbol  Prev. Close Todays Range       Revenue   Open 52 wk Range  ...  Average Vol. (3m)  P/E Ratio  Beta 1-Year Change  Shares Outstanding  Next Earnings Date
0          BTI        38.67   38.6-38.95  3.523000e+10  38.81  31.6-41.58  ...          3158926.0       9.98  0.88        -3.52%        2.294616e+09          28/07/2021
[1 rows x 16 columns]

It's true, currencies are same!

Screenshot 2021-06-01 at 21 03 46

But when I used get_stock_financial_summary i found that currency was not same, and there was no place where I could got it:

In [8]: investpy.get_stock_financial_summary('BTI', 'united states', 'cash_flow_statement','quarterly')
Out[8]: 
            Cash From Operating Activities  Cash From Investing Activities  Cash From Financing Activities  Net Change in Cash
Date                                                                                                                          
2020-12-31                          9786.0                          -783.0                         -7897.0               853.0
2020-06-30                          3484.0                          -217.0                          -962.0              2314.0
2019-12-31                          8996.0                          -639.0                         -8593.0              -293.0
2019-06-30                          2288.0                          -208.0                         -1968.0                58.0

I thank that this numbers was in USD but they was in GBP:

Screenshot 2021-06-01 at 21 05 52
alvarobartt commented 3 years ago

Hi @Mrziiz, thanks for spotting this issue!

You are indeed right, I should also include the currency value in the investpy.get_stock_financial_summary function, since it's not the same as the one retrieved for the stock... This seems to be an inconsistency from Investing.com as the user should expect the data on the same page to use the same currency among all the displayed data I guess... 😖

Anyway, thanks for spotting this, I'll solve this bug ASAP! :hugs:

alvarobartt commented 3 years ago

Hi again @Mrziiz! :hugs:

I've already implemented a function to retrieve the default currency of every SearchObj after calling investpy.search_quotes so that you can just use the following piece of code:

>>> import investpy
>>> search_result = investpy.search_quotes(text='apple', n_results=1)
>>> print(search_result)
{"id_": 6408, "name": "Apple Inc", "symbol": "AAPL", "country": "united states", "tag": "/equities/apple-computer-inc", "pair_type": "stocks", "exchange": "NASDAQ"}
>>> currency = search_result.retrieve_currency()
>>> print(currency)
USD
>>> print(search_result.default_currency)
USD

Also see below that it's pretty simple but efficient and the elapsed time to retrieve the currency is less than 300ms, which is something nice too!

/workspace/investpy $ time python -c "import investpy;data = investpy.search_quotes('apple', n_results=1);curr = data.retrieve_currency()"

real    0m1.384s
user    0m0.841s
sys     0m0.736s
/workspace/investpy $ time python -c "import investpy;data = investpy.search_quotes('apple', n_results=1)"

real    0m1.094s
user    0m0.824s
sys     0m0.871s
alvarobartt commented 3 years ago

Even though the issue with the currency used for the financials is still not solved, since I need to figure out how to include that value, since it's usually "in Millions of X (with some exception)" so it may not be as straight forward as multiplying the values per 1M and then setting that currency as the default one...

Anyway, you can already retrieve the default currency for every financial product from the result of investpy.search_quotes(), that as you may know it internally uses the Investing.com search engine.

alvarobartt commented 3 years ago

It seems that as it happened before with SearchObj.retrieve_information, as described in #395, Investing.com has different HTML templates for the stocks, since the stocks/equities pages are already using the new templates, all the other financial products are still using the old one, so we need to define a way to either use one parser or another based on the product type :confounded:

Hopefully the current version I developed for SearchObj.retrieve_information can be re-used as it should be consistent to new changes and easy to update to adapt to the new changes on the different financial product HTMLs :+1:

alvarobartt commented 3 years ago

Hi @Mrziiz, the new release is already out! :fire:

You can already install it using either pip install investpy==1.0.7 or just update the current version that you are using with pip install investpy --upgrade. Thanks a lot for your support! :+1:

For more information about this new release, you should check investpy v1.0.7 Release :balloon: