1/5 – Fundamental Financial Analysis: Using Python for Efficient Stock Evaluation


Fundamental analysis is one of the most important aspects of a company’s financial analysis. It tells us whether to invest in a company in the long run. We will also learn how to compare two companies in terms of finances. It is generally required for competitive analysis or when comparing companies in the same sector. Essentially, we can divide Fundamental analysis into Quantitative and Qualitative analysis.

For qualitative analysis, the company’s annual report is the only source. For example, if you want to examine SAIL’s ( Steel Authority of India Ltd. ) annual report, you can go to its website and download it.

A company’s annual report provides details about its management and how efficiently it functions. Another thing that you should look into is whether the company’s management perspective aligns with what is happening in the industry. Another important aspect is whether the company under observation is leaning politically towards a party. All these aspects and others come under qualitative analysis.

This article series will focus on a company’s quantitative aspects. We will learn how to download the financial statements, i.e., balance sheet, income statement, and cash flow statement, in Excel format and import them into Python. We will learn how to utilize the data found in these financial statements. We will also learn to utilize Yahoo Finance with Python to get our data. In the subsequent articles, we will learn different ways of performing financial analysis and what insights to draw from them.

Recommended: (4/5) MACD Indicator: Python Implementation and Technical Analysis

Recommended: (3/5) Relative Strength Index (RSI): A Powerful Trading Indicator Implemented in Python

How to Download a Company’s Annual Report

As mentioned in the previous section, we need financial statements to perform financial analysis. We can download this data from a company’s annual report. I have attached SAIL’s annual report for your reference.

Annual Report of SAIL for the year 2021-2022.

You can get all the financial statements from the report itself. We can get all the financial statements from page 195 of the Annual Report.

SAIL Content
SAIL Content

Getting these data from the annual report into Excel format is a manual and hectic task. You can visit screener.com to download readymade Excel files.

Downloading of Excel from screener

Screener is a website that provides readymade Excel files. Let’s look into how we can utilize this website for our benefit. We can go to its website and search for the company for whom we want to perform financial analysis.

Screener Search
Screener Search

The above image shows that SAIL data is available in the dropdown. We can click on it to enquire for further information.

On further follow-up, you must have received the following window.

Screener SAIL
Screener SAIL

You can click on the export to Excel for further analysis in Python.

Analyzing Financial Data with Python

Now that we have learned how to download an Excel file containing information about a particular company let’s import the data and view it using Pandas.

Pandas are a powerful and widely used library in Python programming languages. They are used to visualize different kinds of data, perform operations, and draw insights. Below is Python code that will let you use pandas to access your data from the downloaded Excel sheet.

import pandas as pd

  # Replace 'your_file.xlsx' with the actual path to your Excel file
  data = pd.read_excel('your_file.xlsx')

  # Print the first 5 rows of the data (assuming you have data)

  # Access a specific sheet, handling potential errors gracefully
    sheet_name = 'Cash Flow'  # Replace with your desired sheet name
    data_sheet = pd.read_excel('your_file.xlsx', sheet_name=sheet_name)
    print(f"\nData from sheet '{sheet_name}':")
  except Exception as e:
    print(f"\nError accessing sheet '{sheet_name}': {e}")

except Exception as e:
  print(f"Error reading Excel file: {e}")

In the above code, what we have done is that we have imported pandas and essentially passed an Excel file that we downloaded from Screener. Thereafter, we found the sheet named Cash Flow and printed its information.

Another way of getting financial data is from Yahoo Finance. Let us look at its code as well and understand how to import data.

import yfinance as yf

def get_income_statement(ticker):
    # Fetch income statement data from Yahoo Finance
    stock = yf.Ticker(ticker)
    income_statement = stock.financials.loc['Net Income']
    return income_statement

def analyze_income_statement(income_statement):
    # Calculate metrics or perform analysis
    # Example: calculate average net income over the last 5 years
    avg_net_income = income_statement.mean()
    return avg_net_income

if __name__ == "__main__":
    # Example usage
    ticker_symbol = "AAPL"  # Apple Inc. as an example
    income_statement = get_income_statement(ticker_symbol)
    avg_net_income = analyze_income_statement(income_statement)
    print("Average Net Income:", avg_net_income)

In the above code, we have imported yfinance as yf. We then retrieve Apple’s income statement and calculate the average net income for the last five years. The ticker symbol is ‘AAPL’ for Apple Inc. Let us look at the output.

Apple Operating Income
Apple Operating Income


In this article, we have learned to gather and analyze a wealth of financial data that can inform your investment strategies. From downloading comprehensive financial reports to extracting key financial indicators using Python, you are better equipped to perform sophisticated fundamental analyses. What new insights will you uncover about your next investment opportunity using these methods?

Recommended: Step-by-Step Guide to Checking Out a Commit ID with GitPython

Recommended: (1/5) Understanding Technical Analysis and Indicators using Python