investpy.indices
ΒΆ
-
investpy.indices.
get_index_countries
()ΒΆ This function retrieves all the country names indexed in Investing.com with available indices to retrieve data from, via reading the indices.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 available for indices data retrieval.
- Returns
The resulting
list
contains all the available countries with indices as indexed in Investing.com- Return type
list
- countries- Raises
FileNotFoundError β raised if the indices.csv file was not found.
IOError β raised if the indices.csv file is missing or errored.
-
investpy.indices.
get_index_historical_data
(index, country, from_date, to_date, as_json=False, order='ascending', interval='Daily')ΒΆ This function retrieves historical data of the introduced index (from the specified country, note that both index and country should match since if the introduced index is not listed in the indices of that country, the function will raise an error). The retrieved historical data are the OHLC values plus the Volume and the Currency in which those values are specified, from the introduced date range if valid. So on, the resulting data can it either be stored in a
pandas.DataFrame
or in ajson
file.- Parameters
index (
str
) β name of the index to retrieve recent historical data from.country (
str
) β name of the country from where the index is.from_date (
str
) β date as str formatted as dd/mm/yyyy, from where data is going to be retrieved.to_date (
str
) β date as str formatted as dd/mm/yyyy, until where data is going to be retrieved.as_json (
bool
, optional) β optional argument to determine the format of the output data (pandas.DataFrame
orjson
).interval (
str
, optional) β value to define the historical data interval to retrieve, by default Daily, but it can also be Weekly or Monthly.
- Returns
The function returns either a
pandas.DataFrame
or ajson
file containing the retrieved historical data from the specified index via argument. The dataset contains the open, high, low, close and volume values for the selected index on market days, additionally the currency in which those values are specified is returned.The returned data is case we use default arguments will look like:
Date || Open | High | Low | Close | Volume | Currency -----||------|------|-----|-------|--------|---------- xxxx || xxxx | xxxx | xxx | xxxxx | xxxxxx | xxxxxxxx
but if we define as_json=True, then the output will be:
{ name: name, historical: [ { date: dd/mm/yyyy, open: x, high: x, low: x, close: x, volume: x, currency: x }, ... ] }
- Return type
pandas.DataFrame
orjson
- Raises
ValueError β raised if there was an argument error.
IOError β raised if indices object/file was not found or unable to retrieve.
RuntimeError β raised if the introduced index does not match any of the indexed ones.
ConnectionError β raised if GET requests does not return 200 status code.
IndexError β raised if index information was unavailable or not found.
Examples
>>> data = investpy.get_index_historical_data(index='ibex 35', country='spain', from_date='01/01/2018', to_date='01/01/2019') >>> data.head() Open High Low Close Volume Currency Date 2018-01-02 15128.2 15136.7 14996.6 15096.8 10340000 EUR 2018-01-03 15145.0 15186.9 15091.9 15106.9 12800000 EUR 2018-01-04 15105.5 15368.7 15103.7 15368.7 17070000 EUR 2018-01-05 15353.9 15407.5 15348.6 15398.9 11180000 EUR 2018-01-08 15437.1 15448.7 15344.0 15373.3 12890000 EUR
-
investpy.indices.
get_index_information
(index, country, as_json=False)ΒΆ This function retrieves fundamental financial information from the specified index. The retrieved information from the index can be valuable as it is additional information that can be used combined with OHLC values, so to determine financial insights from the company which holds the specified index.
- Parameters
index (
str
) β name of the index to retrieve recent historical data from.country (
str
) β name of the country from where the index is.as_json (
bool
, optional) β optional argument to determine the format of the output data (dict
orjson
).
- Returns
The resulting
pandas.DataFrame
contains the information fields retrieved from Investing.com from the specified index; it can also be returned as adict
, if argument as_json=True.If any of the information fields could not be retrieved, that field/s will be filled with None values. If the retrieval process succeeded, the resulting
dict
will look like:index_information = { "Index Name": "S&P Merval", "Prev. Close": 36769.59, "Volume": None, "Todays Range": "36,769.59 - 37,894.32", "Open": 36769.59, "Average Vol. (3m)": None, "52 wk Range": "22,484.4 - 44,470.76", "1-Year Change": "18.19%" }
- Return type
pandas.DataFrame
ordict
- index_information- Raises
ValueError β raised if any of the introduced arguments is not valid or errored.
FileNotFoundError β raised if indices.csv file was not found or errored.
IOError β raised if indices.csv file is empty or errored.
RuntimeError β raised if scraping process failed while running.
ConnectionError β raised if the connection to Investing.com errored (did not return HTTP 200)
-
investpy.indices.
get_index_recent_data
(index, country, as_json=False, order='ascending', interval='Daily')ΒΆ This function retrieves recent historical data from the introduced index from Investing via Web Scraping. The resulting data can it either be stored in a
pandas.DataFrame
or in ajson
file, with ascending or descending order.- Parameters
index (
str
) β name of the index to retrieve recent historical data from.country (
str
) β name of the country from where the index is.as_json (
bool
, optional) β optional argument to determine the format of the output data (pandas.DataFrame
orjson
).order (
str
, optional) β optional argument to define the order of the retrieved data (ascending, asc or descending, desc).interval (
str
, optional) β value to define the historical data interval to retrieve, by default Daily, but it can also be Weekly or Monthly.
- Returns
The function returns either a
pandas.DataFrame
or ajson
file containing the retrieved recent data from the specified index via argument. The dataset contains the open, high, low, close and volume values for the selected index on market days, additionally the currency value is returned.The returned data is case we use default arguments will look like:
Date || Open | High | Low | Close | Volume | Currency -----||------|------|-----|-------|--------|---------- xxxx || xxxx | xxxx | xxx | xxxxx | xxxxxx | xxxxxxxx
but if we define as_json=True, then the output will be:
{ name: name, recent: [ { date: dd/mm/yyyy, open: x, high: x, low: x, close: x, volume: x, currency: x }, ... ] }
- Return type
pandas.DataFrame
orjson
- Raises
ValueError β raised if there was an argument error.
IOError β raised if indices object/file was not found or unable to retrieve.
RuntimeError β raised if the introduced index does not match any of the indexed ones.
ConnectionError β raised if GET requests does not return 200 status code.
IndexError β raised if index information was unavailable or not found.
Examples
>>> data = investpy.get_index_recent_data(index='ibex 35', country='spain') >>> data.head() Open High Low Close Volume Currency Date 2019-08-26 12604.7 12646.3 12510.4 12621.3 4770000 EUR 2019-08-27 12618.3 12723.3 12593.6 12683.8 8230000 EUR 2019-08-28 12657.2 12697.2 12585.1 12642.5 7300000 EUR 2019-08-29 12637.2 12806.6 12633.8 12806.6 5650000 EUR 2019-08-30 12767.6 12905.9 12756.9 12821.6 6040000 EUR
-
investpy.indices.
get_indices
(country=None)ΒΆ This function retrieves all the available indices from Investing.com as previously listed in investpy, and returns them as a
pandas.DataFrame
with all the information of every available index. If the country filtering is applied, just the indices from the introduced country are going to be returned. All the available indices can be found at: https://www.investing.com/indices/world-indices and at https://www.investing.com/indices/world-indices, since both world and global indices are retrieved.- Parameters
country (
str
, optional) β name of the country to retrieve all its available indices from.- Returns
The resulting
pandas.DataFrame
contains all the indices information retrieved from Investing.com, as previously listed by investpy.In case the information was successfully retrieved, the
pandas.DataFrame
will look like:country | name | full_name | symbol | currency | class | market --------|------|-----------|--------|----------|-------|-------- xxxxxxx | xxxx | xxxxxxxxx | xxxxxx | xxxxxxxx | xxxxx | xxxxxx
- Return type
pandas.DataFrame
- indices_df- Raises
ValueError β raised if any of the introduced parameters is missing or errored.
FileNotFoundError β raised if the indices.csv file was not found.
IOError β raised if the indices.csv file from investpy is missing or errored.
-
investpy.indices.
get_indices_dict
(country=None, columns=None, as_json=False)ΒΆ This function retrieves all the available indices from Investing.com as previously listed in investpy, and returns them as a
dict
with all the information of every available index. If the country filtering is applied, just the indices from the introduced country are going to be returned. Additionally, the columns to retrieve data from can be specified as a parameter formatted as alist
. All the available indices can be found at: https://www.investing.com/indices/world-indices and at https://www.investing.com/indices/world-indices, since both world and global indices are retrieved.- Parameters
country (
str
, optional) β name of the country to retrieve all its available indices from.columns (
list
ofstr
, optional) β description alist
containing the column names from which the data is going to be retrieved.as_json (
bool
, optional) β description value to determine the format of the output data (dict
orjson
).
- Returns
The resulting
dict
contains the retrieved data if found, if not, the corresponding fields are filled with None values.In case the information was successfully retrieved, the
dict
will look like:indices_dict = { 'country': country, 'name': name, 'full_name': full_name, 'symbol': symbol, 'currency': currency, 'class': class, 'market': market }
- Return type
dict
orjson
- indices_dict- Raises
ValueError β raised whenever any of the introduced arguments is not valid or errored.
FileNotFoundError β raised if the indices.csv file was not found.
IOError β raised if the indices.csv file is missing or errored.
-
investpy.indices.
get_indices_list
(country=None)ΒΆ This function retrieves all the available indices from Investing.com as previously listed in investpy, and returns them as a
list
with the names of every available index. If the country filtering is applied, just the indices from the introduced country are going to be returned. All the available indices can be found at: https://www.investing.com/indices/world-indices and at https://www.investing.com/indices/world-indices, since both world and global indices are retrieved.- Parameters
country (
str
, optional) β name of the country to retrieve all its available indices from.- Returns
The resulting
list
contains the retrieved data, which corresponds to the index names of every index listed in Investing.com.In case the information was successfully retrieved, the
list
will look like:indices = ['S&P Merval', 'S&P Merval Argentina', 'S&P/BYMA Argentina General', ...]
- Return type
list
- indices_list- Raises
ValueError β raised whenever any of the introduced arguments is not valid or errored.
FileNotFoundError β raised if the indices.csv file was not found.
IOError β raised if the indices.csv file is missing or errored.
-
investpy.indices.
get_indices_overview
(country, as_json=False, n_results=100)ΒΆ This function retrieves an overview containing all the real time data available for the main indices from a country, such as the names, symbols, current value, etc. as indexed in Investing.com. So on, the main usage of this function is to get an overview on the main indices from a country, so to get a general view. Note that since this function is retrieving a lot of information at once, by default just the overview of the Top 100 indices is being retrieved, but an additional parameter called n_results can be specified so to retrieve N results.
- Parameters
country (
str
) β name of the country to retrieve the indices overview from.as_json (
bool
, optional) β optional argument to determine the format of the output data (pandas.DataFrame
orjson
).n_results (
int
, optional) β number of results to be displayed on the overview table (0-1000).
- Returns
The resulting
pandas.DataFrame
contains all the data available in Investing.com of the main indices from a country in order to get an overview of it.If the retrieval process succeeded, the resulting
pandas.DataFrame
should look like:country | name | last | high | low | change | change_percentage | currency --------|------|------|------|-----|--------|-------------------|---------- xxxxxxx | xxxx | xxxx | xxxx | xxx | xxxxxx | xxxxxxxxxxxxxxxxx | xxxxxxxx
- Return type
pandas.DataFrame
- indices_overview- Raises
ValueError β raised if any of the introduced arguments is not valid or errored.
FileNotFoundError β raised when indices.csv file is missing.
IOError β raised if data could not be retrieved due to file error.
RuntimeError β raised either if the introduced country does not match any of the listed ones or if no overview results could be retrieved from Investing.com.
ConnectionError β raised if GET requests does not return 200 status code.
-
investpy.indices.
search_indices
(by, value)ΒΆ This function searches indices by the introduced value for the specified field. This means that this function is going to search if there is a value that matches the introduced value for the specified field which is the indices.csv column name to search in. Available fields to search indices are βnameβ, βfull_nameβ and βsymbolβ.
- Parameters
by (
str
) β name of the field to search for, which is the column name (βnameβ, βfull_nameβ or βsymbolβ).value (
str
) β value of the field to search for, which is the str that is going to be searched.
- Returns
The resulting pandas.DataFrame contains the search results from the given query (the specified value in the specified field). If there are no results and error will be raised, but otherwise this pandas.DataFrame will contain all the available field values that match the introduced query.
- Return type
pandas.DataFrame
- search_result- Raises
ValueError β raised if any of the introduced params is not valid or errored.
FileNotFoundError β raised if indices.csv file is missing.
IOError β raised if data could not be retrieved due to file error.
RuntimeError β raised if no results were found for the introduced value in the introduced field.