Geek Culture
Published in

Geek Culture

Fundamental Analysis of Stocks using Python

Fundamental Analysis using Python (Image by Author)

WHAT IS FUNDAMENTAL ANALYSIS?

Fundamental analysis guides us in reaching a decision point on whether a particular company’s stock is worth buying or not and if its stock price has the right valuation. To perform this analysis it uses the company level factors such as the company’s market capitalization, balance sheet, profit/loss statement, shareholder pattern, cash flow etc

WEB SCRAPING

Copying the data manually from the website is a cumbersome task. Web scraping is a technique that automates this process by extracting data from a website or an online source. Once the required data is pulled from the website it can then be used to perform any kind of data analysis or data manipulation activity.

Steps involved in web scraping

STEP 1: Identify the url to pull the data

Scraping data from other websites

A note of caution on using other websites for web scraping. Please ensure that only publicly available data is scraped.

LET’S SCRAPE IT!!

With most of the data required for fundamental analysis directly available on the web, it is easer to scrape this information and use it for further analysis.

FETCHING THE FUNDAMENTAL DATA

For this analysis we will be considering the following IT stocks from the National Stock Exchange (NSE): INFY, HCLTECH, LTI, TCS, LTTS, WIPRO

Infosys — Fetch the market cap using web scraping

As an example let us try to extract the market cap for the Infosys stock from the screener webpage using the 3 steps outlined earlier.

Fetching other fundamental details of stocks

The other parameters of the stock can also be fetched with a similar approach. This can be repeated for any number of stocks. Here we have fetched the data for 6 different IT stocks.

Summary of extracted stock data
  • Market_Cap — the total market value of the company’s outstanding shares
  • Price — the current market price of the share
  • High — 52-week high of the share
  • Low — 52-week low of the share
  • PE — Price to Earnings ratio
  • ROE — Return on Equity
  • ROCE — Return on Capital Employed
  • Dividend — Dividend yield of the company

ANALYSING THE STOCKS

Once the data is fetched, it is time to explore the data.

COMPARING STOCKS OF THE SAME SECTOR

Fundamental analysis is normally used to compare the stocks of the same sector. The PE ratio, ROE and ROCE are some of the common parameters used for comparison.

Comparison of PE-ROE-ROCE parameters (Image by Author)
  • PE ratio is normally not used in isolation. It is either compared with other companies from the same industry (Eg: PE of INFY is compared with the PE of HCL, LTI, TCS etc) or compared with the industry PE (PE of Infy is compared with PE of IT sector)
  • Higher PE indicates that the stock is priced highly. Lower PE indicates a good investment opportunity (provided the other fundamentals of the company is good)
  • High ROE indicates that the company is good in converting its earnings into profits.
  • A higher ROCE indicates that the company is generating higher returns for the debt holders than for the equity holders. The higher the value of the ROCE ratio, the better are the chances of profits.
  • ROE considers the returns from equity shareholder’s point of view only whereas ROCE considers the debt and other liabilities as well. This provides a better indication of financial performance for companies with significant debt.
  • If the ROCE value is higher than the ROE value, it implies that the company is efficiently using its debts to reduce the cost of capital.
  • Mr. Warren Buffet, one of the most successful investors of the 20th century, prefers companies where the ROE and ROCE values are almost close to each other and both are above 20%

CREATING CUSTOM-MADE STRATEGIES

It is also possible to apply our own strategies on the fundamental data to decide whether to buy a stock or not.

Profit-Loss Strategy

This is one of the strategies in which the profit/loss data from the past ‘n’ years of a company’s is used along with its current market price to check whether it is a worthy stock to buy now or not. This is how the strategy works

  • Net profit for the company has been increasing consistently in the last few years
  • Current market price is atleast 10% below the 52-week high (stock is not trading around its all time high)
PROFIT-LOSS STRATEGY — IT STOCKS
VISUALIZING PROFIT-LOSS STRATEGY — IT STOCKS
Details of strategy applied on Infy and HCL stocks

PUTTING THEM TOGETHER

Refer to the following github repo to get access to the complete code used to scrape the web and perform the fundamental analysis, : Fundamental Analyzer

Final Words….

In this article, we covered only one strategy to make the BUY/WAIT recommendation. Similarly other strategies (fundamental or technical) can be implemented for a particular stock. The consolidated results from all the strategies can be used to make the final BUY/WAIT/SELL decision.

IF “PYTHON+TRADING” FASCINATES YOU THEN CHECK THESE OUT…

--

--

A new tech publication by Start it up (https://medium.com/swlh).

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store