Fundamentals package

Submodules

Fundamentals.BSE module

Fundamentals.MoneyControl module

class Fundamentals.MoneyControl.MoneyControl[source]

Bases: CustomSession

A class to control money-related operations.

Attributes:

No Attributes

Methods:

__init__(): Initializes the MoneyControl class. get_ticker(search_text: str) -> tuple: Retrieve the ticker for a given search text.

_get_all_extracted_urls(main_url: str): Retrieve all extracted URLs from the main URL. _common_complete_sheet_data_extractor(company_mc_url, statement_type, report_data, pages): Extracts data from the given URL and returns a DataFrame. get_india_vix(interval: str) -> pd.DataFrame: Retrieves India Vix data for a given interval. get_overview_mini_statement(ticker: str, statement_type: str = ‘consolidated’, statement_frequency: int = 12): Retrieve the overview mini statement for a given ticker. get_income_mini_statement(ticker: str, statement_type: str = ‘consolidated’, statement_frequency: int = 12): Retrieves the income mini statement for a given ticker. get_balance_sheet_mini_statement(ticker: str, statement_type: str = ‘consolidated’): Retrieves the balance sheet mini statement for a given ticker.

get_balance_sheet_mini_statement(ticker: str, statement_type: str = 'consolidated') DataFrame[source]

This will give highly extracted and most commonly used data from quarterly/annual reports this is good for quick comparisons, as it suggests it will give mini statements which means it will give data only for few time periods (quarterly/annual/6months/9months)

Parameters:
  • self – Represent the instance of the class.

  • ticker – The moneycontrol ticker symbol of the company.

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘consolidated’.

Returns:

The company balance sheet data in a DataFrame format.

get_cash_flow_mini_statement(ticker: str, statement_type: str = 'consolidated') DataFrame[source]

This will give highly extracted and most commonly used data from quarterly/annual reports this is good for quick comparisons, as it suggests it will give mini statements which means it will give data only for few time periods (quarterly/annual/6months/9months)

Parameters:
  • self – Represent the instance of the class.

  • ticker – The moneycontrol ticker symbol of the company.

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘consolidated’.

Returns:

The company’s cash flow statements data in a DataFrame format.

get_complete_balance_sheet(company_mc_url: str, statement_type: str = 'standalone', num_years: int = 5) DataFrame[source]

This will give complete data of quarterly/annual reports. This is a complete report that can be used any fundamental deep analysis

Parameters:
  • self – Represent the instance of the class.

  • company_mc_url – Company’s main MoneyControl url (this can be taken from get_ticker() function)

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘standalone’. :param num_years: (Optional) Number of years for which balance sheet data is required (min 5, and it should be multiple of 5)

Returns:

Complete balance sheet data in the DataFrame format.

get_complete_capital_structure_statement(company_mc_url: str) DataFrame[source]

This will give complete data of quarterly/annual reports. This is a complete report that can be used any fundamental deep analysis

Parameters:
  • self – Represent the instance of the class.

  • company_mc_url – Company’s main MoneyControl url (this can be taken from get_ticker() function)

Returns:

Complete capital Structure data in the DataFrame format.

get_complete_cashflow_statement(company_mc_url: str, statement_type: str = 'standalone', num_years: int = 5) DataFrame[source]

This will give complete data of quarterly/annual reports. This is a complete report that can be used any fundamental deep analysis

Parameters:
  • self – Represent the instance of the class.

  • company_mc_url – Company’s main MoneyControl url (this can be taken from get_ticker() function)

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘standalone’. :param num_years: (Optional) The Number of annual reports is required (min 5, and it should be multiple of 5)

Returns:

Complete cash-flow statements data in the DataFrame format.

get_complete_half_yearly_results(company_mc_url: str, statement_type: str = 'standalone', num_half_years: int = 5) DataFrame[source]

This will give complete data of quarterly/annual reports. This is a complete report that can be used any fundamental deep analysis

Parameters:
  • self – Represent the instance of the class.

  • company_mc_url – Company’s main MoneyControl url (this can be taken from get_ticker() function)

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘standalone’. :param num_half_years: (Optional) Number of 6months data is required (min 5, and it should be multiple of 5)

Returns:

Complete half-yearly (50th percentile of the year) results data in the DataFrame format.

get_complete_nine_months_results(company_mc_url: str, statement_type: str = 'standalone', num_nine_months: int = 5) DataFrame[source]

This will give complete data of quarterly/annual reports. This is a complete report that can be used any fundamental deep analysis

Parameters:
  • self – Represent the instance of the class.

  • company_mc_url – Company’s main MoneyControl url (this can be taken from get_ticker() function)

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘standalone’. :param num_nine_months: (Optional) Number of 9months data is required (min 5, and it should be multiple of 5)

Returns:

Complete nine-months (75th percentile of the year) data in the DataFrame format.

get_complete_profit_loss(company_mc_url: str, statement_type: str = 'standalone', num_years: int = 5) DataFrame[source]

This will give complete data of quarterly/annual reports. This is a complete report that can be used any fundamental deep analysis

Parameters:
  • self – Represent the instance of the class.

  • company_mc_url – Company’s main MoneyControl url (this can be taken from get_ticker() function)

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘standalone’. :param num_years: (Optional) Number of years for which a P&L statement is required (min 5, and it should be multiple of 5)

Returns:

Complete P&L statement data in the DataFrame format.

get_complete_quarterly_results(company_mc_url: str, statement_type: str = 'standalone', num_quarters: int = 5) DataFrame[source]

This will give complete data of quarterly/annual reports. This is a complete report that can be used any fundamental deep analysis

Parameters:
  • self – Represent the instance of the class.

  • company_mc_url – Company’s main MoneyControl url (this can be taken from get_ticker() function)

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘standalone’. :param num_quarters: (Optional) Number of quarters for which quarterly results are required (min 5, and it should be multiple of 5)

Returns:

Complete quarterly (25th percentile of the year) results data in the DataFrame format.

get_complete_ratios_data(company_mc_url: str, statement_type: str = 'standalone', num_years: int = 5) DataFrame[source]

This will give complete data of quarterly/annual reports. This is a complete report that can be used any fundamental deep analysis

Parameters:
  • self – Represent the instance of the class.

  • company_mc_url – Company’s main MoneyControl url (this can be taken from get_ticker() function)

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘standalone’. :param num_years: (Optional) The number of annual reports is required (min 5, and it should be multiple of 5)

Returns:

Complete key ratios data in the DataFrame format.

get_complete_yearly_results(company_mc_url: str, statement_type: str = 'standalone', num_years: int = 5) DataFrame[source]

This will give complete data of quarterly/annual reports. This is a complete report that can be used any fundamental deep analysis

Parameters:
  • self – Represent the instance of the class.

  • company_mc_url – Company’s main MoneyControl url (this can be taken from get_ticker() function)

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘standalone’. :param num_years: (Optional) The Number of annual reports is required (min 5, and it should be multiple of 5)

Returns:

Complete annual (100th percentile of the year) report data in the DataFrame format.

get_income_mini_statement(ticker: str, statement_type: str = 'consolidated', statement_frequency: int = 12) DataFrame[source]

This will give highly extracted and most commonly used data from quarterly/annual reports this is good for quick comparisons, as it suggests it will give mini statements which means it will give data only for few time periods (quarterly/annual/6months/9months)

Parameters:
  • self – Represent the instance of the class.

  • ticker – The moneycontrol ticker symbol of the company.

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘consolidated’. :param statement_frequency: (Optional) The frequency of the statement. Defaults to 12.

Returns:

The company income data in a DataFrame format.

get_india_vix(interval: str) DataFrame[source]

This will fetch the OHLCV datapoints of the INDIA Volatility Index.

Parameters:
  • self – Represent the instance of the class.

  • interval – Time interval for the data (‘1d’ for daily qnd ‘1’ for 1min)

Returns:

DataFrame containing the India VIX data for last 2months or ~1780 OHLCV datapoints

get_overview_mini_statement(ticker: str, statement_type: str = 'consolidated', statement_frequency: int = 12) DataFrame[source]

This will give highly extracted and most commonly used data from quarterly/annual reports this is good for quick comparisons, as it suggests it will give mini statements which means it will give data only for few time periods (quarterly/annual/6months/9months)

Parameters:
  • self – Represent the instance of the class.

  • ticker – The moneycontrol ticker symbol of the company.

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘consolidated’. :param statement_frequency: (Optional) The frequency of the statement. Defaults to 12.

Returns:

The processed data in a DataFrame format.

get_ratios_mini_statement(ticker: str, statement_type: str = 'consolidated') DataFrame[source]

This will give highly extracted and most commonly used data from quarterly/annual reports this is good for quick comparisons, as it suggests it will give mini statements which means it will give data only for few time periods (quarterly/annual/6months/9months)

Parameters:
  • self – Represent the instance of the class.

  • ticker – The moneycontrol ticker symbol of the company.

  • statement_type – (Optional) The type of statement to retrieve (consolidated / standalone).

Defaults to ‘consolidated’.

Returns:

The company’s key performance ratios in DataFrame format.

get_ticker(search_text: str) tuple[source]

Get ticker information for a given search text.

Parameters:
  • self – Represent the instance of the class.

  • search_text – The text to search for.

Returns:

A tuple containing the stock ID and the corresponding object (raw data).

Fundamentals.Screener module

Fundamentals.TickerTape module

class Fundamentals.TickerTape.Tickertape(custom_headers: dict | None = None, custom_cookies: dict | None = None)[source]

Bases: CustomSession

A class to interact with the Tickertape API.

Attributes:

valid_horizons : list of valid time horizons for financial data valid_search_places: list of valid search places for ticker search

Methods:

__init__ : Initialize the Tickertape class get_ticker : Get the ticker symbol and raw response for a given hint and search place _get_url_of_the_ticker : Get the URL of the ticker get_all_nifty_50_ticker : Get a list of tickers for the Nifty 50 index get_all_constituents_of_index : Get a list of tickers for a given index get_income_data : Get income data for a given ticker and time horizon get_balance_sheet_data : Get balance sheet data for a given ticker get_cash_flow_data : Get cash flow data for a given ticker peers_comparison : Get peer comparison data for a given ticker and comparison type get_score_card : Get the scorecard for a given ticker get_share_holding_pattern : Get the share holding pattern for a given ticker get_mutual_fund_holdings : Get the mutual fund holdings for a given ticker

get_all_constituents_of_index(index: str) DataFrame[source]

This will give all equities that are part of an index.

Parameters:
  • self – Represents the instance of the class

  • index – The index name; for example .NSEI (nifty 50), .NIFTY500 (nifty 500)

Returns:

A list of tickers

get_all_etfs_under_index(index: str) DataFrame[source]

Get all ETFs under a specific index.

Parameters:
  • self – Represents the instance of the class

  • index – A valid index traded on Indian Exchange.

Returns:

A DataFrame containing the ETF data.

get_all_nifty_50_ticker() list[source]

The get_nifty_50_ticker function returns a list of tickers for the Nifty-50 index. The function uses the hit_and_get_data function to get a response from https://api.tickertape.in/indices/constituents/.NSEI, which is an API that provides data on constituents of various indices in India, including the Nifty 50 index.

Parameters:

self – Represents the instance of the class

Returns:

A list of tickers

get_balance_sheet_data(ticker: str, num_time_periods: int = 10, growth: bool = False) DataFrame[source]

Get balance sheet data for a given ticker.

Parameters:
  • self – Represents the instance of the class

  • ticker – The ticker symbol of the stock

  • num_time_periods – The number of time periods to retrieve. Default to 10.

  • growth – Boolean flag tell the report is normal type or growth type.

Returns:

The DataFrame containing balance sheet data

get_cash_flow_data(ticker: str, num_time_periods: int = 10, growth: bool = False) DataFrame[source]

Get cash flow data for a given ticker.

Parameters:
  • self – Represents the instance of the class

  • ticker – The ticker symbol of the stock

  • num_time_periods – The number of time periods to retrieve. Default to 10.

  • growth – Boolean flag tell the report is normal type or growth type.

Returns:

The DataFrame containing cash flow data

get_dividends_history(stock_slug_endpoint: str) DataFrame[source]

Gets the dividend history for a given stock ticker.

Parameters:
  • self – Represents the instance of the class

  • stock_slug_endpoint – It’s the part of url expect base url which navigates to the stock profile in the website. You can get this from search url raw data. For example, if stock url is https://www.tickertape.in/stocks/hdfc-bank-HDBK then stocks/hdfc-bank-HDBK is the slug url.

Returns:

The DataFrame contains the dividend history

get_equity_screener_all_filters() dict[source]

The get_equity_screener_all_filters function returns a dictionary of all the filters available for equity screener. The key is the display name and value is label name.

Parameters:

self – Represent the instance of the class.

Returns:

A dictionary of all the filters that can be used in the equity screener.

get_equity_screener_data(filters: list, sortby: str | None = None, number_of_records: int | None = None) DataFrame[source]

!! Carefully call this function because this is a heavy and time-consuming function. Save the data once you get the data to save resource and time !!

The get_equity_screener_data function is used to retrieve equity screener data from the

https://api.kite.trade/screener/query endpoint of the Kite Connect API.

Parameters:
  • self – Represent the instance of the class

  • filters – list: Define the columns that you want to be returned in your dataframe you can pass all

filters which are non-premium aka values list of get_equity_screener_all_filters function returned dictionary. :param sortby: str: Sort the dataframe by a specific column if you don’t pass this it will consider the 1st value of filters list. :param number_of_records: int: Limit the number of records that are returned :return: A pandas dataframe with the all data you asked in the filters field. You can save this data df and use it for your research

get_income_data(ticker: str, time_horizon: str = 'interim', num_time_periods: int = 10, view_type: str = 'normal') DataFrame[source]

Get income data for a given ticker.

Parameters:
  • self – Represents the instance of the class

  • ticker – The ticker symbol of the stock

  • time_horizon – The time horizon of the income data (interim / annual). Defaults to ‘interim’

  • num_time_periods – The number of time periods to retrieve. Default to 10.

  • view_type – The view type of the income data (normal / growth). Defaults to ‘normal’.

Returns:

The DataFrame containing income data

get_key_ratios(stock_slug_endpoint: str) DataFrame[source]

Get key ratios for a given stock ticker.

Parameters:
  • self – Represents the instance of the class

  • stock_slug_endpoint – It’s the part of url expect base url which navigates to the stock profile in the website. You can get this from search url raw data. For example, if stock url is https://www.tickertape.in/stocks/hdfc-bank-HDBK then stocks/hdfc-bank-HDBK is the slug url.

Returns:

A transposed DataFrame containing the key ratios for the stock.

get_mutual_fund_holdings(stock_slug_endpoint: str) DataFrame[source]

Get mutual fund holdings for a given ticker.

Parameters:
  • self – Represents the instance of the class

  • stock_slug_endpoint – It’s the part of url expect base url which navigates to the stock profile in the website. You can get this from search url raw data. For example, if stock url is https://www.tickertape.in/stocks/hdfc-bank-HDBK then stocks/hdfc-bank-HDBK is the slug url.

Returns:

The DataFrame contains the mutual fund holdings.

get_score_card(ticker) DataFrame[source]

Get the scorecard for a given ticker.

Parameters:
  • self – Represents the instance of the class

  • ticker – The ticker symbol of the stock

Returns:

The DataFrame contains all key flags like valuation, technical, growth red flags, etc.

get_share_holding_pattern(stock_slug_endpoint: str) DataFrame[source]

Get the share holding pattern for a given ticker.

Parameters:
  • self – Represents the instance of the class

  • stock_slug_endpoint – It’s the part of url expect base url which navigates to the stock profile in the website. You can get this from search url raw data. For example, if stock url is https://www.tickertape.in/stocks/hdfc-bank-HDBK then stocks/hdfc-bank-HDBK is the slug url.

Returns:

The DataFrame contains the share holding pattern.

get_smallcase_holdings(stock_slug_endpoint: str) DataFrame[source]

Get smallcase holdings for a given ticker.

Parameters:
  • self – Represents the instance of the class

  • stock_slug_endpoint – It’s the part of url expect base url which navigates to the stock profile in the website. You can get this from search url raw data. For example, if stock url is https://www.tickertape.in/stocks/hdfc-bank-HDBK then stocks/hdfc-bank-HDBK is the slug url.

Returns:

The DataFrame containing smallcase holdings for the given ticker

get_ticker(hint, search_place='all') tuple[source]

The get_ticker function takes a hint and search_place as arguments. The hint is the name of the company you are looking for, and search_place can be one of:

  • all (default)

  • stocks

  • funds # mutual funds, ETFs etc.

Parameters:
  • self – Represent the instance of the class

  • hint – Search for the ticker

  • search_place – Specify the type of search you want to perform

Returns:

A tuple with the first hit and all hits

peers_comparison(ticker: str, comparison_type: str = 'valuation') DataFrame[source]

Fetches and returns comparison data for a given ticker.

Parameters:
  • self – Represents the instance of the class

  • ticker – The ticker symbol of the stock

  • comparison_type – Type of comparison (valuation/technical). Defaults to ‘valuation’.

Returns:

The DataFrame containing the peers comparison result

Module contents