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 a json 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 or json).

  • 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 a json 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 or json

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 or json).

Returns

The resulting pandas.DataFrame contains the information fields retrieved from Investing.com from the specified index; it can also be returned as a dict, 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 or dict- 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 a json 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 or json).

  • 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 a json 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 or json

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 a list. 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 of str, optional) – description a list 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 or json).

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 or json - 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 or json).

  • 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.