Extracting and Analyzing Live Stock Data in Excel (2024)

Downloading and analyzing real-time stock data

In my previous article, Beginner’s Guide for Stock Option Analysis Using Excel I have covered in detail about option chain analysis in Excel. I had mentioned that I would discuss about how to analyze real-time stock data in Excel. So in this article I am explaining about how to extract data from the NSE website, refresh it periodically, perform various analysis, and build your portfolio in Excel.

I will show how to pull option data to Excel and build custom reports based on option strategies. These reports will in turn help you to predict trends for option trading. Same technique can be applied for other stock analysis as well.

Importing Options Data in Excel

I will show in this section how to load option chain data in Excel. Once the data is loaded you will learn various strategies to analyze this data and predict trends.

You can link to live data on the NSE website to analyze stocks data in real time. The data is in JSON format that has to be parsed from the NSE website. Following steps details this process:

  1. Open the link www.nseindia.com in Chrome.
  2. Navigate to Market Date > Option Chain
  3. Right-click and select the Inspect option to open the Diagnostics pane.
  4. Click the Network tab.
  5. Reload the page.
  6. Click the Name specific to the data you want to parse for example, option chain for NIFTY.
  7. In the Network pane select the row related to option chain (refer the screenshot).
Extracting and Analyzing Live Stock Data in Excel (2)

8. Make a note of the fields required to store the cookie values for this page. These values are available under the Response Headers section. They are bm_sv value under cookie, accept-encoding value, accept-language value, and user-agent value.

These are the steps related to establishing connection with the NSE website specific to the page that you want to parse the data. Same steps has to be followed for parsing data from any other section in the website.

Next follow these steps to download the data into the Excel file:

  1. Open an Excel worksheet and create a column by name “Cookie”.
  2. Copy and paste the cookie value from the Headers section into this column. Only copy the cookie value stored in the variable bm_sv.
  3. Convert this column in Excel to Table by selecting Data > From Table/Range.
  4. Open Power Query Editor and name the query as “Cookies” under Properties. Open Advanced Editor to convert this column to a function. Paste this in the Advanced Editor:
    let Cookies = () =>
    let
    Source = Excel.CurrentWorkbook(){[Name=”Table3"]}[Content],
    #”Changed Type” = Table.TransformColumnTypes(Source,{{“Cookie”, type text}}),
    Cookie = #”Changed Type”{0}[Cookie]
    in
    Cookie
    in
    Cookies
  5. Close the Power Query Editor.
  6. Under the Data tab in Excel, select From Web and select Advanced.
  7. Enter the URL of the NSE website from where you want to parse the data (copy the Request URL from the Headers section in the Diagnostic pane).
  8. Paste the values for accept-encoding, accept-language, and user-agent under HTTP request header parameters. For Cookie parameter enter the function name i.e. Cookies(). If the parameter value is not available in the drop-down then you can enter it manually.
Extracting and Analyzing Live Stock Data in Excel (3)

This setup will simulate browser like connection in Excel and load the data from the URL given. A pop-up window with the confirmation to establish the connection displays. Once you confirm, the connection with the website is established. The data is loaded in JSON format.

Extracting and Analyzing Live Stock Data in Excel (4)

If you are downloading stocks data then the format will be slightly different. As here I have downloaded option chain data the format has two rows, records and filtered data. Records has all the data whereas filtered has only data for selected expiry date.

Double-click the data that you want to open. Here I have opted to download the records data. The data expands to a list of records. Convert this list of records to table by clicking the button Into Table at the top right corner. Expand the column to view all the data extracted. You can choose the columns that you want to download. After all the columns are expanded you can load the data to the Excel sheet by clicking Close & Load button at the top right corner. The entire option chain data loads in the Excel sheet.

Extracting and Analyzing Live Stock Data in Excel (5)

As this data is connected to the NSE website it can be frequently refreshed for real-time updates. To extract data from other sources, you only have to update the URL in the Advanced Editor, Source = Json.Document(Web.Contents(“https://www.nseindia.com/api/option-chain-indices?symbol=NIFTY")

For example, if the source URL is changed to, https://www.nseindia.com/api/option-chain-equities?symbol=WIPRO then data for Wipro stocks is extracted.

Conclusion

Now that the data is downloaded, you can analyze based on the steps and strategies explained in the article, Beginner’s Guide for Stock Option Analysis Using Excel. I will soon roll out another article in this series on automating the Excel worksheet for dynamic data analysis.

Extracting and Analyzing Live Stock Data in Excel (2024)

FAQs

How to use Excel to analyze stocks? ›

Yes you can. You just need to fill in the information or a ticker, and by selecting the 'stocks' option under the data menu. It will seek the information online and input it into the sheet for you. Is it better to use software or plug-ins for your spreadsheets?

How good is Excel for data analysis? ›

Despite its ease of use, Excel is equipped with pretty robust tools that can perform complex data analysis, especially if we consider some add-ins, making it suitable for both novice and experienced professionals. 1. It solves the problem: unless you are a statistician, Excel can satisfy 99% of your needs.

How do you extract stock data? ›

To web scrape stock data, you typically need to choose a reliable data source, use a programming language like Python, and select a scraping tool or library. The process involves sending requests to the target website, parsing the HTML or JSON data, and extracting the needed information.

Is Excel good for stocks? ›

Excel: an easy-to-use solution for managing your stock

Excel is a versatile management solution, too. It can be used both for accounting and stock management: or for keeping files on customers or suppliers, for example.

How to analyze stock data? ›

A very, very basic example of stock analysis would include looking at a stock's share price, comparing it to its historical averages and moving averages, overall market conditions, and looking at the company's financial statements to try and gauge where it might move next.

Can you be a data analyst with just Excel? ›

Regardless, a data analyst must have more skills than in just Excel. Business knowledge, statistics and communication skills are also important. Excel is a start, but you'll need more to become a data analyst.

Why not use Excel for data analysis? ›

Spreadsheet results can be unreliable when working with large datasets and/or performing complex calculations. If absolute accuracy is required, a spreadsheet may not suffice. Instead, a different, more reliably accurate tool should be considered.

Can I become a data analyst with just Excel? ›

A: Data analysts commonly use spreadsheet programs such as Microsoft Excel or Google Sheets to organize and analyze data. They may also use statistical analysis software, such as SAS or SPSS, to conduct more complex analyses.

What is an example of data analysis? ›

For example, a researcher wants to study children and achievement in math. The research will compile data such as age, gender, grade level, and mathematics grades. This raw data is then interpreted through specific statistical programs to show relationships between the different variables.

How do you summarize data in Excel? ›

If you want an easy way to create simple summaries of numbers in Excel quickly, then use AutoSum! You can find this function on the Home tab > Number section > AutoSum button.

Is Excel or Python better for data analysis? ›

Scalability and Efficiency

Data scientists prefer Python over Excel due to its ability to handle large data sets, as well as incorporate machine learning and modeling. When handling large amounts of data, Excel takes longer to finish calculations compared to Python.

What are the pros and cons of using Excel for data analysis? ›

Excel's strength lies in its ability to process large datasets, perform complex calculations, and be compatible with various other software and platforms. However, it's not without drawbacks, ranging from issues in version control to limitations in data visualization tools.

Top Articles
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 5650

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.