Skip to content

Commit aac63e2

Browse files
author
Álvaro Bartolomé del Canto
authored
Merge pull request #49 from alvarob96/dev
merge dev branch into master before 0.9.6 release
2 parents c375dc8 + 6bdbab6 commit aac63e2

File tree

16 files changed

+149
-58
lines changed

16 files changed

+149
-58
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,66 @@ Date
244244
245245
```
246246

247+
### Search Data
248+
249+
As financial data is really complex and sometimes both the product name and the country are unknown for the user, in
250+
terms of what does investpy expect, every financial product listed in investpy (which currently includes equities,
251+
funds, etfs, indices and currency crosses) has its own search function. Search functions allow the user to search among
252+
all the available equities for example, whenever just one field is known (even though it is not the exact match). So on,
253+
the usage of this functions is presented below with some samples:
254+
255+
#### The user just knows the ISIN code of an Equity
256+
257+
````python
258+
import investpy
259+
260+
search_results = investpy.search_equities(by='isin', value='ES0113211835')
261+
262+
print(search_results.head())
263+
````
264+
```{r, engine='python', count_lines}
265+
country name full_name isin currency symbol
266+
0 mexico BBVA Banco Bilbao Vizcaya Argentaria SA ES0113211835 MXN BBVA
267+
1 mexico BBVA Banco Bilbao Vizcaya Argentaria S.A. ES0113211835 MXN BBVA
268+
2 belgium BBVA Banco Bilbao Vizcaya Argentaria SA ES0113211835 EUR BBVA
269+
3 spain BBVA Banco Bilbao Vizcaya Argentaria S.A. ES0113211835 EUR BBVA
270+
4 united kingdom BBVA Banco Bilbao Vizcaya Argentaria Sa ES0113211835 EUR BVAB
271+
```
272+
273+
#### The user just knows the Symbol of an Index
274+
275+
````python
276+
import investpy
277+
278+
search_results = investpy.search_indices(by='name', value='IBEX')
279+
280+
print(search_results.head())
281+
````
282+
```{r, engine='python', count_lines}
283+
country name full_name symbol currency market
284+
0 spain IBEX 35 IBEX 35 IBEX EUR world_indices
285+
1 spain FTSE Latibex FTSE Latibex IBEXL EUR world_indices
286+
2 spain IBEX Medium Cap IBEX Medium Cap IBEXC EUR world_indices
287+
3 spain IBEX Small Cap IBEX Small Cap IBEXS EUR world_indices
288+
4 spain IBEX 35 Banks IBEX 35 Banks IBEXIB EUR world_indices
289+
```
290+
291+
#### The user just knows a keyword contained in the name of an ETF
292+
293+
````python
294+
import investpy
295+
296+
search_results = investpy.search_etfs(by='name', value='bbva')
297+
298+
print(search_results.head())
299+
````
300+
```{r, engine='python', count_lines}
301+
country name symbol currency
302+
0 mexico BBVA-BMV Mexico Consumo Frecuente RT TRAC CONSUMO10 MXN
303+
1 mexico BBVA-BMV Mexico Enlace RT TRAC ENLACE10 MXN
304+
2 spain BBVA Accion DJ Eurostoxx 50 BBVAE EUR
305+
```
306+
247307
### Additional Data
248308

249309
As Investing provides more data besides the historical one, some of that additional data can be fetched via investpy.
0 Bytes
Binary file not shown.

docs/_build/html/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

investpy/Data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.
55

66

investpy/__init__.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.
55

66
__author__ = 'Alvaro Bartolome <alvarob96@usal.es>'
@@ -2389,7 +2389,7 @@ def get_etfs_overview(country, as_json=False):
23892389
id_ = element_.get('id').replace('pair_', '')
23902390
symbol = element_.xpath(".//td[contains(@class, 'symbol')]")[0].get('title')
23912391

2392-
name = element_.xpath(".//a")[0]
2392+
name = element_.xpath(".//a")[0].text.strip()
23932393

23942394
last_path = ".//td[@class='" + 'pid-' + str(id_) + '-last' + "']"
23952395
last = element_.xpath(last_path)[0].text_content()
@@ -2400,6 +2400,9 @@ def get_etfs_overview(country, as_json=False):
24002400
turnover_path = ".//td[contains(@class, '" + 'pid-' + str(id_) + '-turnover' + "')]"
24012401
turnover = element_.xpath(turnover_path)[0].text_content()
24022402

2403+
if turnover == '':
2404+
continue
2405+
24032406
if turnover.__contains__('K'):
24042407
turnover = int(float(turnover.replace('K', '').replace('.', '').replace(',', '.')) * 1000)
24052408
elif turnover.__contains__('M'):
@@ -2408,7 +2411,7 @@ def get_etfs_overview(country, as_json=False):
24082411
turnover = int(float(turnover.replace('.', '').replace(',', '.')))
24092412

24102413
data = {
2411-
"name": name.text.strip(),
2414+
"name": name,
24122415
"symbol": symbol,
24132416
"last": float(last.replace('.', '').replace(',', '.')),
24142417
"change": change,
@@ -2493,31 +2496,33 @@ def search_etfs(by, value):
24932496

24942497
def get_indices(country=None):
24952498
"""
2496-
This function retrieves all the available countries to retrieve indices from, as the listed countries are the ones
2497-
indexed on Investing.com. This function is intended to show the user the data contained in `indices.csv` in order
2498-
to help him to later use that data in order to retrieve historical data, if the country is specified a filtering
2499-
parameter is applied so just the indices from the specified country are retrieved.
2499+
This function retrieves all the available `indices` from Investing.com and returns them as a :obj:`pandas.DataFrame`,
2500+
which contains not just the index names, but all the fields contained on the indices file.
2501+
All the available indices can be found at: https://es.investing.com/indices/world-indices and at
2502+
https://es.investing.com/indices/world-indices, since both world and global indices are retrieved.
25002503
25012504
Args:
25022505
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.
25032506
25042507
Returns:
2505-
:obj:`pandas.DataFrame` - indices:
2506-
The resulting :obj:`pandas.DataFrame` contains all the indices basic information stored on `indices.csv`,
2507-
since it was previously retrieved in `investpy.indices.retrieve_indices()`. Unless the country is
2508-
specified, all the available indices indexed on Investing.com is returned, but if it is specified, just the
2509-
indices from that country are returned.
2508+
:obj:`pandas.DataFrame` - indices_df:
2509+
The resulting :obj:`pandas.DataFrame` contains all the indices basic information retrieved from Investing.com,
2510+
some of which is not useful for the user, but for the inner package functions, such as the `tag` field,
2511+
for example.
25102512
2511-
In the case that the file reading of `indices.csv` or the retrieval process from Investing.com was
2512-
successfully completed, the resulting :obj:`pandas.DataFrame` will look like::
2513+
In case the information was successfully retrieved, the :obj:`pandas.DataFrame` will look like::
2514+
2515+
country | name | full_name | tag | id | symbol | currency
2516+
--------|------|-----------|-----|----|--------|----------
2517+
xxxxxxx | xxxx | xxxxxxxxx | xxx | xx | xxxxxx | xxxxxxxx
25132518
2514-
country | name | symbol | tag | id
2515-
--------|------|--------|-----|----
2516-
xxxxxxx | xxxx | xxxxxx | xxx | xx
2519+
Just like `investpy.indices.retrieve_indices()`, the output of this function is a :obj:`pandas.DataFrame`,
2520+
but instead of generating the CSV file, this function just reads it and loads it into a
2521+
:obj:`pandas.DataFrame` object.
25172522
25182523
Raises:
2519-
ValueError: raised when any of the input arguments is not valid.
2520-
IOError: raised when `indices.csv` file is missing.
2524+
ValueError: raised if any of the introduced parameters is missing or errored.
2525+
IOError: raised if the indices file from `investpy` is missing or errored.
25212526
"""
25222527

25232528
return ic.indices_as_df(country=country)
@@ -2526,7 +2531,8 @@ def get_indices(country=None):
25262531
def get_indices_list(country=None):
25272532
"""
25282533
This function retrieves all the available indices and returns a list of each one of them.
2529-
All the available indices can be found at: https://es.investing.com/indices/
2534+
All the available world indices can be found at: https://es.investing.com/indices/world-indices, and the global
2535+
ones can be foud at: https://es.investing.com/indices/world-indices.
25302536
25312537
Args:
25322538
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.
@@ -2538,7 +2544,7 @@ def get_indices_list(country=None):
25382544
25392545
In case the information was successfully retrieved from the CSV file, the :obj:`list` will look like::
25402546
2541-
indices = [...]
2547+
indices = ['S&P Merval', 'S&P Merval Argentina', 'S&P/BYMA Argentina General', ...]
25422548
25432549
Raises:
25442550
ValueError: raised when the introduced arguments are not correct.
@@ -2551,8 +2557,9 @@ def get_indices_list(country=None):
25512557
def get_indices_dict(country=None, columns=None, as_json=False):
25522558
"""
25532559
This function retrieves all the available indices on Investing.com and returns them as a :obj:`dict` containing the
2554-
`country`, `name`, `full_name`, `symbol`, `tag` and `currency`. All the available indices can be found at:
2555-
https://es.investing.com/indices/
2560+
`country`, `name`, `full_name`, `symbol`, `tag` and `currency`. All the available world indices can be found at:
2561+
https://es.investing.com/indices/world-indices, and the global ones can be foud at:
2562+
https://es.investing.com/indices/global-indices.
25562563
25572564
Args:
25582565
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.
@@ -2573,7 +2580,8 @@ def get_indices_dict(country=None, columns=None, as_json=False):
25732580
'name': name,
25742581
'full_name': full_name,
25752582
'symbol': symbol,
2576-
'tag': tag
2583+
'tag': tag,
2584+
'id': id,
25772585
'currency': currency
25782586
}
25792587
@@ -2587,7 +2595,7 @@ def get_indices_dict(country=None, columns=None, as_json=False):
25872595

25882596
def get_index_countries():
25892597
"""
2590-
This function retrieves all the country names indexed in Investing.com with available global indices to retrieve data
2598+
This function retrieves all the country names indexed in Investing.com with available world indices to retrieve data
25912599
from, via reading the `index_countries.csv` file from the resources directory. So on, this function will
25922600
display a listing containing a set of countries, in order to let the user know which countries are taken into
25932601
consideration and also the return listing from this function can be used for country param check if needed.

investpy/currency_crosses.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.
55

66
import json
@@ -399,8 +399,6 @@ def currency_crosses_as_df(base=None, second=None):
399399
return currency_crosses
400400
else:
401401
raise ValueError("ERR#0053: the introduced currency " + str(second) + " does not exists.")
402-
else:
403-
return currency_crosses
404402

405403

406404
def currency_crosses_as_list(base=None, second=None):

investpy/equities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.
55

66
import unidecode

investpy/etfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.
55

66
import json

investpy/funds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.
55

66
import json

investpy/indices.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.
55

66
import json
@@ -18,13 +18,13 @@
1818

1919
def retrieve_indices(test_mode=False):
2020
"""
21-
This function retrieves all the available `equities` indexed on Investing.com, so to
22-
retrieve data from them which will be used later for inner functions for data retrieval.
23-
All the equities available can be found at: https://es.investing.com/equities/. Additionally,
24-
when equities are retrieved all the meta-information is both returned as a :obj:`pandas.DataFrame`
25-
and stored on a CSV file on a package folder containing all the available resources.
26-
Note that maybe some of the information contained in the resulting :obj:`pandas.DataFrame` is useless as it is
27-
just used for inner function purposes.
21+
This function retrieves all the available `indices` indexed on Investing.com, so to retrieve data from them which
22+
will be used later in inner functions for data retrieval. All the world indices available can be found at:
23+
https://es.investing.com/indices/, and the global indices at: https://es.investing.com/global-indices/.
24+
Additionally, when indices are retrieved all the meta-information is both returned as a :obj:`pandas.DataFrame`
25+
and stored on a CSV file on a package folder containing all the available resources. Note that maybe some of the
26+
information contained in the resulting :obj:`pandas.DataFrame` is useless as it is just used for inner function
27+
purposes.
2828
2929
Args:
3030
test_mode (:obj:`bool`):
@@ -45,7 +45,8 @@ def retrieve_indices(test_mode=False):
4545
4646
Raises:
4747
ValueError: raised if any of the introduced arguments is not valid.
48-
FileNotFoundError: raised if `index_countries.csv` file does not exists or is empty.
48+
FileNotFoundError:
49+
raised if `index_countries.csv` or `global_indices_countries.csv` files do not exist or are empty.
4950
ConnectionError: raised if GET requests did not return 200 status code.
5051
IndexError: raised if indices information was unavailable or not found.
5152
"""
@@ -275,7 +276,7 @@ def retrieve_index_info(tag):
275276
276277
Raises:
277278
ConnectionError: raised if GET requests does not return 200 status code.
278-
IndexError: raised if fund information was unavailable or not found.
279+
IndexError: raised if index information was unavailable or not found.
279280
"""
280281

281282
url = "https://www.investing.com/indices/" + tag
@@ -394,8 +395,8 @@ def retrieve_index_countries(test_mode=False):
394395
def retrieve_global_indices_countries(test_mode=False):
395396
"""
396397
This function retrieves all the country names & tags indexed in Investing.com with available indices to
397-
retrieve data from, via Web Scraping https://www.investing.com/global-indices/ where the available countries are
398-
listed, and from their names the specific indices website of every country is retrieved in order to get the tag
398+
retrieve data from, via Web Scraping https://www.investing.com/indices/global-indices. where the available countries
399+
are listed, and from their names the specific indices website of every country is retrieved in order to get the tag
399400
which will later be used when retrieving all the information from the available indices in every country.
400401
401402
Args:
@@ -446,6 +447,9 @@ def retrieve_global_indices_countries(test_mode=False):
446447

447448
countries.append(obj)
448449

450+
if test_mode is True:
451+
break
452+
449453
if len(countries) <= 0:
450454
raise RuntimeError('ERR#0035: no countries could be retrieved!')
451455

@@ -463,7 +467,7 @@ def retrieve_global_indices_countries(test_mode=False):
463467

464468
def index_countries_as_list():
465469
"""
466-
This function retrieves all the country names indexed in Investing.com with available global indices to retrieve data
470+
This function retrieves all the country names indexed in Investing.com with available world indices to retrieve data
467471
from, via reading the `index_countries.csv` file from the resources directory. So on, this function will
468472
display a listing containing a set of countries, in order to let the user know which countries are taken into
469473
consideration and also the return listing from this function can be used for country param check if needed.
@@ -527,7 +531,8 @@ def indices_as_df(country=None):
527531
"""
528532
This function retrieves all the available `indices` from Investing.com and returns them as a :obj:`pandas.DataFrame`,
529533
which contains not just the index names, but all the fields contained on the indices file.
530-
All the available indices can be found at: https://es.investing.com/indices/
534+
All the available indices can be found at: https://es.investing.com/indices/world-indices and at
535+
https://es.investing.com/indices/world-indices, since both world and global indices are retrieved.
531536
532537
Args:
533538
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.
@@ -549,6 +554,7 @@ def indices_as_df(country=None):
549554
:obj:`pandas.DataFrame` object.
550555
551556
Raises:
557+
ValueError: raised if any of the introduced parameters is missing or errored.
552558
IOError: raised if the indices file from `investpy` is missing or errored.
553559
"""
554560

@@ -577,7 +583,8 @@ def indices_as_df(country=None):
577583
def indices_as_list(country=None):
578584
"""
579585
This function retrieves all the available indices and returns a list of each one of them.
580-
All the available indices can be found at: https://es.investing.com/indices/
586+
All the available world indices can be found at: https://es.investing.com/indices/world-indices, and the global
587+
ones can be foud at: https://es.investing.com/indices/world-indices.
581588
582589
Args:
583590
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.
@@ -618,8 +625,9 @@ def indices_as_list(country=None):
618625
def indices_as_dict(country=None, columns=None, as_json=False):
619626
"""
620627
This function retrieves all the available indices on Investing.com and returns them as a :obj:`dict` containing the
621-
`country`, `name`, `full_name`, `symbol`, `tag` and `currency`. All the available indices can be found at:
622-
https://es.investing.com/indices/
628+
`country`, `name`, `full_name`, `symbol`, `tag` and `currency`. All the available world indices can be found at:
629+
https://es.investing.com/indices/world-indices, and the global ones can be foud at:
630+
https://es.investing.com/indices/global-indices.
623631
624632
Args:
625633
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.

investpy/resources/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.

investpy/user_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.
55

66
import random

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.
55

66
from setuptools import setup, find_packages

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2018-2019 Alvaro Bartolome
3+
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
44
# See LICENSE for details.

0 commit comments

Comments
 (0)