Skip to content

Commit

Permalink
Merge pull request #49 from alvarob96/dev
Browse files Browse the repository at this point in the history
merge dev branch into master before 0.9.6 release
  • Loading branch information
Álvaro Bartolomé del Canto authored Oct 2, 2019
2 parents c375dc8 + 6bdbab6 commit aac63e2
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 58 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,66 @@ Date
```

### Search Data

As financial data is really complex and sometimes both the product name and the country are unknown for the user, in
terms of what does investpy expect, every financial product listed in investpy (which currently includes equities,
funds, etfs, indices and currency crosses) has its own search function. Search functions allow the user to search among
all the available equities for example, whenever just one field is known (even though it is not the exact match). So on,
the usage of this functions is presented below with some samples:

#### The user just knows the ISIN code of an Equity

````python
import investpy

search_results = investpy.search_equities(by='isin', value='ES0113211835')

print(search_results.head())
````
```{r, engine='python', count_lines}
country name full_name isin currency symbol
0 mexico BBVA Banco Bilbao Vizcaya Argentaria SA ES0113211835 MXN BBVA
1 mexico BBVA Banco Bilbao Vizcaya Argentaria S.A. ES0113211835 MXN BBVA
2 belgium BBVA Banco Bilbao Vizcaya Argentaria SA ES0113211835 EUR BBVA
3 spain BBVA Banco Bilbao Vizcaya Argentaria S.A. ES0113211835 EUR BBVA
4 united kingdom BBVA Banco Bilbao Vizcaya Argentaria Sa ES0113211835 EUR BVAB
```

#### The user just knows the Symbol of an Index

````python
import investpy

search_results = investpy.search_indices(by='name', value='IBEX')

print(search_results.head())
````
```{r, engine='python', count_lines}
country name full_name symbol currency market
0 spain IBEX 35 IBEX 35 IBEX EUR world_indices
1 spain FTSE Latibex FTSE Latibex IBEXL EUR world_indices
2 spain IBEX Medium Cap IBEX Medium Cap IBEXC EUR world_indices
3 spain IBEX Small Cap IBEX Small Cap IBEXS EUR world_indices
4 spain IBEX 35 Banks IBEX 35 Banks IBEXIB EUR world_indices
```

#### The user just knows a keyword contained in the name of an ETF

````python
import investpy

search_results = investpy.search_etfs(by='name', value='bbva')

print(search_results.head())
````
```{r, engine='python', count_lines}
country name symbol currency
0 mexico BBVA-BMV Mexico Consumo Frecuente RT TRAC CONSUMO10 MXN
1 mexico BBVA-BMV Mexico Enlace RT TRAC ENLACE10 MXN
2 spain BBVA Accion DJ Eurostoxx 50 BBVAE EUR
```

### Additional Data

As Investing provides more data besides the historical one, some of that additional data can be fetched via investpy.
Expand Down
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_build/html/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion investpy/Data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

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


Expand Down
58 changes: 33 additions & 25 deletions investpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

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

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

name = element_.xpath(".//a")[0]
name = element_.xpath(".//a")[0].text.strip()

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

if turnover == '':
continue

if turnover.__contains__('K'):
turnover = int(float(turnover.replace('K', '').replace('.', '').replace(',', '.')) * 1000)
elif turnover.__contains__('M'):
Expand All @@ -2408,7 +2411,7 @@ def get_etfs_overview(country, as_json=False):
turnover = int(float(turnover.replace('.', '').replace(',', '.')))

data = {
"name": name.text.strip(),
"name": name,
"symbol": symbol,
"last": float(last.replace('.', '').replace(',', '.')),
"change": change,
Expand Down Expand Up @@ -2493,31 +2496,33 @@ def search_etfs(by, value):

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

return ic.indices_as_df(country=country)
Expand All @@ -2526,7 +2531,8 @@ def get_indices(country=None):
def get_indices_list(country=None):
"""
This function retrieves all the available indices and returns a list of each one of them.
All the available indices can be found at: https://es.investing.com/indices/
All the available world indices can be found at: https://es.investing.com/indices/world-indices, and the global
ones can be foud at: https://es.investing.com/indices/world-indices.
Args:
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.
Expand All @@ -2538,7 +2544,7 @@ def get_indices_list(country=None):
In case the information was successfully retrieved from the CSV file, the :obj:`list` will look like::
indices = [...]
indices = ['S&P Merval', 'S&P Merval Argentina', 'S&P/BYMA Argentina General', ...]
Raises:
ValueError: raised when the introduced arguments are not correct.
Expand All @@ -2551,8 +2557,9 @@ def get_indices_list(country=None):
def get_indices_dict(country=None, columns=None, as_json=False):
"""
This function retrieves all the available indices on Investing.com and returns them as a :obj:`dict` containing the
`country`, `name`, `full_name`, `symbol`, `tag` and `currency`. All the available indices can be found at:
https://es.investing.com/indices/
`country`, `name`, `full_name`, `symbol`, `tag` and `currency`. All the available world indices can be found at:
https://es.investing.com/indices/world-indices, and the global ones can be foud at:
https://es.investing.com/indices/global-indices.
Args:
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.
Expand All @@ -2573,7 +2580,8 @@ def get_indices_dict(country=None, columns=None, as_json=False):
'name': name,
'full_name': full_name,
'symbol': symbol,
'tag': tag
'tag': tag,
'id': id,
'currency': currency
}
Expand All @@ -2587,7 +2595,7 @@ def get_indices_dict(country=None, columns=None, as_json=False):

def get_index_countries():
"""
This function retrieves all the country names indexed in Investing.com with available global indices to retrieve data
This function retrieves all the country names indexed in Investing.com with available world indices to retrieve data
from, via reading the `index_countries.csv` file from the resources directory. So on, this function will
display a listing containing a set of countries, in order to let the user know which countries are taken into
consideration and also the return listing from this function can be used for country param check if needed.
Expand Down
4 changes: 1 addition & 3 deletions investpy/currency_crosses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

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

import json
Expand Down Expand Up @@ -399,8 +399,6 @@ def currency_crosses_as_df(base=None, second=None):
return currency_crosses
else:
raise ValueError("ERR#0053: the introduced currency " + str(second) + " does not exists.")
else:
return currency_crosses


def currency_crosses_as_list(base=None, second=None):
Expand Down
2 changes: 1 addition & 1 deletion investpy/equities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

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

import unidecode
Expand Down
2 changes: 1 addition & 1 deletion investpy/etfs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

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

import json
Expand Down
2 changes: 1 addition & 1 deletion investpy/funds.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

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

import json
Expand Down
42 changes: 25 additions & 17 deletions investpy/indices.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

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

import json
Expand All @@ -18,13 +18,13 @@

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

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

countries.append(obj)

if test_mode is True:
break

if len(countries) <= 0:
raise RuntimeError('ERR#0035: no countries could be retrieved!')

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

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

Expand Down Expand Up @@ -577,7 +583,8 @@ def indices_as_df(country=None):
def indices_as_list(country=None):
"""
This function retrieves all the available indices and returns a list of each one of them.
All the available indices can be found at: https://es.investing.com/indices/
All the available world indices can be found at: https://es.investing.com/indices/world-indices, and the global
ones can be foud at: https://es.investing.com/indices/world-indices.
Args:
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.
Expand Down Expand Up @@ -618,8 +625,9 @@ def indices_as_list(country=None):
def indices_as_dict(country=None, columns=None, as_json=False):
"""
This function retrieves all the available indices on Investing.com and returns them as a :obj:`dict` containing the
`country`, `name`, `full_name`, `symbol`, `tag` and `currency`. All the available indices can be found at:
https://es.investing.com/indices/
`country`, `name`, `full_name`, `symbol`, `tag` and `currency`. All the available world indices can be found at:
https://es.investing.com/indices/world-indices, and the global ones can be foud at:
https://es.investing.com/indices/global-indices.
Args:
country (:obj:`str`, optional): name of the country to retrieve all its available indices from.
Expand Down
2 changes: 1 addition & 1 deletion investpy/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python

# Copyright 2018-2019 Alvaro Bartolome
# Copyright 2018-2019 Alvaro Bartolome @ alvarob96 in GitHub
# See LICENSE for details.
2 changes: 1 addition & 1 deletion investpy/user_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

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

import random
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

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

from setuptools import setup, find_packages
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python

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

0 comments on commit aac63e2

Please sign in to comment.