Stock Analysis in Python

The yfinance module has the download method which can be used to download the stock market data. To get the stock market data of multiple stock tickers, you can create a list of tickers and call the yfinance download method for each stock ticker. Stock Market Analysis means analyzing the current and historical trends in the stock market to make future buying and selling decisions. Stock market analysis is one of the best use cases of Data Science in finance. So, if you want to learn to analyze the stock market, this article is for you. In this article, I will take you through the task of Stock Market Analysis using Python. After you get your key, assign the variable QUANDL_API_KEY with that key.

How can I get data from NSE?

  1. Download and save the zip file on your system.
  2. Extract the files using 7-zip.
  3. Open the new spreadsheet and drag or drop the file there in, else.
  4. Open the file using spreadsheet directly.
  5. Alternatively, the file can be opened in 'note pad'

To analyse the performance, you can use the pyfolio tear sheet as shown below. Quandl also provides paid data source of minute and lower frequencies. According to the graph above, the price of TCS has skyrocketed significantly higher than that of Tata Steel and Tata Motors. TCS’s pricing trajectory has been generally upward from its beginning, whereas Tata Steel and Tata Motors have been more on a consolidation trend.

Scraping data from other websites

If you do not have 64 bit Python, but do have a 64bit operating system, get 64 bit Python, it’ll help you a bit later. If you’re on a 32 bit operating system, I am sorry for your situation, but you should be fine to follow most of this anyway. Yf is a CLI tool that allows for quick and easy access to Yahoo! Finance market data. 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. High ROE indicates that the company is good in converting its earnings into profits. Using the beautiful soup package, the contents of the given url can be read into a tree object.

Just incase you don’t know, a stock is a share of ownership of a company, and the ticker is the “symbol” used to reference the company in the stock exchange that it’s on. Markowitzify will implement a variety of portfolio and stock/cryptocurrency analysis methods to optimize portfolios or trading strategies. So this is how you can use the Python programming language to analyze the stock market interactively.


In this case, you can use the pandas resample method to convert the stock market data to the frequency of your choice. The implementation of these is shown below where a 1-minute frequency data is converted to 10-minute frequency data. The below code fetches the stock market data for MSFT for the past 5 days of 1-minute frequency.

How do I get all stock data in Python?

  1. import pandas_datareader as pdr. # Request data via Yahoo public API. data = pdr. get_data_yahoo('NVDA')
  2. import yfinance as yf. # Request historical data for past 5 years. data = yf. Ticker("NVDA").
  3. import quandl. # Get data via Quandl API. data = quandl.
  4. # Necessary imports. import pandas_datareader as pdr. # Request Data.

It’s just a table of rows and columns, you have an index, and column names. The index should be something that relates to all of the columns. If you’d like to learn more on Pandas, check out the Data Analysis with Pandas tutorial series. 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. 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.

Article was published on: 09/29/22

Author: Viktor Nikolaev

Victor is a professional crypto investor and stockbroker, specializing in such areas as trading on the stock exchange, cryptov currencies, forex, stocks and bonds. In this blog he shares the secrets of trading, current currency indices, crypt currency rates and tells about the best forex brokers. If you have any questions, you can always contact

Leave a Reply