{"id":62628,"date":"2024-05-31T08:09:23","date_gmt":"2024-05-31T08:09:23","guid":{"rendered":"https:\/\/www.askpython.com\/?p=62628"},"modified":"2025-04-10T20:26:38","modified_gmt":"2025-04-10T20:26:38","slug":"fundamental-financial-analysis-python","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python\/fundamental-financial-analysis-python","title":{"rendered":"1\/5 &#8211; Fundamental Financial Analysis: Using Python for Efficient Stock Evaluation"},"content":{"rendered":"\n<p>Fundamental analysis is one of the most important aspects of a company&#8217;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.<\/p>\n\n\n\n<p>For qualitative analysis, the company&#8217;s annual report is the only source. For example, if you want to examine SAIL&#8217;s ( Steel Authority of India Ltd. ) annual report, you can go to its website and download it.<\/p>\n\n\n\n<p>A company&#8217;s annual report provides details about its management and how efficiently it functions. Another thing that you should look into is whether the company&#8217;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.<\/p>\n\n\n\n<p>This article series will focus on a company&#8217;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.<\/p>\n\n\n\n<p><strong><em>Recommended: <a href=\"https:\/\/www.askpython.com\/python\/examples\/macd-indicator-python\">(4\/5) MACD Indicator: Python Implementation and Technical Analysis<\/a><\/em><\/strong><\/p>\n\n\n\n<p><strong><em>Recommended: <a href=\"https:\/\/www.askpython.com\/python\/examples\/relative-strength-index-rsi\">(3\/5) Relative Strength Index (RSI): A Powerful Trading Indicator Implemented in Python<\/a><\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Download a Company\u2019s Annual Report<\/h2>\n\n\n\n<p>As mentioned in the previous section, we need financial statements to perform financial analysis. We can download this data from a company&#8217;s annual report. I have attached SAIL&#8217;s annual report for your reference.<\/p>\n\n\n\n<p><a href=\"https:\/\/sail.co.in\/sites\/default\/files\/2024-03\/Sail-Annual-Report_2021-22-%281%29_3.pdf\" target=\"_blank\" rel=\"noopener\">Annual Report of SAIL for the year 2021-2022.<\/a><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"942\" height=\"907\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/SAIL-Content.png\" alt=\"SAIL Content\" class=\"wp-image-62629\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/SAIL-Content.png 942w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/SAIL-Content-300x289.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/SAIL-Content-768x739.png 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><figcaption class=\"wp-element-caption\"><strong><em>SAIL Content<\/em><\/strong><\/figcaption><\/figure>\n\n\n\n<p>Getting these data from the annual report into Excel format is a manual and hectic task. You can visit <a href=\"https:\/\/www.screener.in\/\" target=\"_blank\" rel=\"noopener\">screener.com<\/a> to download readymade Excel files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Downloading of Excel from screener<\/h2>\n\n\n\n<p>Screener is a website that provides readymade Excel files. Let&#8217;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.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"569\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-search-1024x569.png\" alt=\"Screener Search\" class=\"wp-image-62630\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-search-1024x569.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-search-300x167.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-search-768x427.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-search-1536x854.png 1536w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-search.png 1919w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"><strong><em>Screener Search<\/em><\/strong><\/figcaption><\/figure>\n\n\n\n<p>The above image shows that SAIL data is available in the dropdown. We can click on it to enquire for further information.<\/p>\n\n\n\n<p>On further follow-up, you must have received the following window.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"534\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-SAIL-1024x534.png\" alt=\"Screener SAIL\" class=\"wp-image-62631\" style=\"width:789px;height:auto\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-SAIL-1024x534.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-SAIL-300x156.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-SAIL-768x400.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-SAIL-1536x801.png 1536w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Screener-SAIL.png 1916w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"><strong><em>Screener SAIL<\/em><\/strong><\/figcaption><\/figure>\n\n\n\n<p>You can click on the export to Excel for further analysis in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Analyzing Financial Data with Python<\/h2>\n\n\n\n<p>Now that we have learned how to download an Excel file containing information about a particular company let&#8217;s import the data and view it using Pandas.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport pandas as pd\n\ntry:\n  # Replace &#039;your_file.xlsx&#039; with the actual path to your Excel file\n  data = pd.read_excel(&#039;your_file.xlsx&#039;)\n\n  # Print the first 5 rows of the data (assuming you have data)\n  print(data.head())\n\n  # Access a specific sheet, handling potential errors gracefully\n  try:\n    sheet_name = &#039;Cash Flow&#039;  # Replace with your desired sheet name\n    data_sheet = pd.read_excel(&#039;your_file.xlsx&#039;, sheet_name=sheet_name)\n    print(f&quot;\\nData from sheet &#039;{sheet_name}&#039;:&quot;)\n    print(data_sheet.head())\n  except Exception as e:\n    print(f&quot;\\nError accessing sheet &#039;{sheet_name}&#039;: {e}&quot;)\n\nexcept Exception as e:\n  print(f&quot;Error reading Excel file: {e}&quot;)\n\n<\/pre><\/div>\n\n\n<p>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.<\/p>\n\n\n\n<p>Another way of getting financial data is from Yahoo Finance. Let us look at its code as well and understand how to import data.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport yfinance as yf\n\ndef get_income_statement(ticker):\n    # Fetch income statement data from Yahoo Finance\n    stock = yf.Ticker(ticker)\n    income_statement = stock.financials.loc&#x5B;&#039;Net Income&#039;]\n    return income_statement\n\ndef analyze_income_statement(income_statement):\n    # Calculate metrics or perform analysis\n    # Example: calculate average net income over the last 5 years\n    avg_net_income = income_statement.mean()\n    return avg_net_income\n\nif __name__ == &quot;__main__&quot;:\n    # Example usage\n    ticker_symbol = &quot;AAPL&quot;  # Apple Inc. as an example\n    income_statement = get_income_statement(ticker_symbol)\n    avg_net_income = analyze_income_statement(income_statement)\n    print(&quot;Average Net Income:&quot;, avg_net_income)\n\n<\/pre><\/div>\n\n\n<p>In the above code, we have imported yfinance as yf. We then retrieve Apple&#8217;s income statement and calculate the average net income for the last five years. The ticker symbol is &#8216;AAPL&#8217; for Apple Inc. Let us look at the output.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"590\" height=\"64\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Apple-Operating-Income.png\" alt=\"Apple Operating Income\" class=\"wp-image-62650\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Apple-Operating-Income.png 590w, https:\/\/www.askpython.com\/wp-content\/uploads\/2024\/05\/Apple-Operating-Income-300x33.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><figcaption class=\"wp-element-caption\"><strong><em>Apple Operating Income<\/em><\/strong><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>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?<\/p>\n\n\n\n<p><strong><em>Recommended: <a href=\"https:\/\/www.askpython.com\/python\/examples\/gitpython-git-checkout-commit-id\">Step-by-Step Guide to Checking Out a Commit ID with GitPython<\/a><\/em><\/strong><\/p>\n\n\n\n<p><strong><em>Recommended: <a href=\"https:\/\/www.askpython.com\/python\/examples\/technical-analysis-basics\">(1\/5) Understanding Technical Analysis and Indicators using Python<\/a><\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fundamental analysis is one of the most important aspects of a company&#8217;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. [&hellip;]<\/p>\n","protected":false},"author":80,"featured_media":63845,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,9],"tags":[],"class_list":["post-62628","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-examples"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/62628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/80"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=62628"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/62628\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/63845"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=62628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=62628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=62628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}