The purpose of this blog is to happily share my learning and ideas to help people, who actively seek solutions for the day-to-day problems faced.

Recent Posts

"Python + Finance" - Indian Stock Market data analysis

Day 1 - I think I can find it, let me try..
Day 2 - I must try hard now, I can..
Day 3 - Uff.. Why am I not able to get that..
Day 7 - I am going to spend a whole day.. will find for sure..
.
.
.
Day 45 - Nah, Looks like its not available let me find some alternate way.. 
.
.
.
Day 'n' - Whoooh... Yes I did it.. this is how the journey was when I try to get a working API for Indian Stock Market Data. (Unfortunately, Google Finance stopped its API support long back)

Though my search for this API is for a different purpose, found an alternate way to achieve my goal (more on this later in a separate blog post). Right now I'm interested in give you all an overview on what and all can be achieved from this NSE (National Stock Exchange) module.

So before explaining about the NSE module, I have used Jupyter Notebooks here since it helps me to easily plot the graph with desired data set so that I can edit and see the changes on the go.


HAVELLS INDIA - One Year Price Graph

From the above image, we could see I have used nsepy module to get the historical data for "HAVELLS" scrip and later used pyplot method from matplotlib module to plot the graph of "HAVELLS" scrip using its historical closing price for the last one year.


Also the support is not just limited to regular stock price changes, we have even support for derivatives such as Options and Futures.


get_history details

The above documentation clearly explains about the list of arguments present and its expected values, so with this details I have plotted the Options and Futures graph for "ITC" scrip


ITC - Options Graph

Similarly for "ITC" Futures Graph is as follows,
ITC - Futures Graph

Covering below are the other important scrip data we get,

  1. Previous Closing Price
  2. Open Price
  3. High
  4. Low
  5. Last
  6. Close Price
  7. VWAP(Volume Weighted Average Price)
  8. Volume
  9. Turnover
  10. Trades
  11. Deliverable Volume
  12. Delivery % etc
Scrip data
As I write this post, I'm very much excited so I might have missed to address some of your queries, please feel free to post your doubts on comment section. I will get it addressed as soon as I can.

Also I will explore more on this module and keep you all posted with all my new findings. Fingers Crossed

Source Code:
Please click on the below git hub link for the source code explained using python,

9 comments:

  1. Good work!!
    Can you pass multiple share names and other params as an array in the single request?

    ReplyDelete
    Replies
    1. Thanks Himanshu. Right now the "symbol" argument can take only one share name at a time. For multiple share results we can create an array of share names and can iterate through each as shown below,

      import matplotlib.pyplot as plt
      from datetime import date
      from nsepy import get_history
      symbols = ["HAVELLS","ITC"]
      for symbol in symbols:
      stock_opt = get_history(symbol=symbol,
      start=date(2019,9,10),
      end=date(2019,9,14))
      print(stock_opt)

      Delete
  2. Replies
    1. Ah, No.. not right now. Thanks for reaching me out.

      Delete
  3. Thank you for sharing a bunch of this quality contents, I have bookmarked your blog. Please also explore advice from my site. I will be back for more quality contents. best-laptop-for-medical-billing-and-coding

    ReplyDelete
  4. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. Analisa Saham

    ReplyDelete

  5. Personal finances aren't about cashing your paycheck , paying your bills and meeting all of your monthly obligations. it's about having enough money saved so as to satisfy all of your financial goals in life.
    finance

    ReplyDelete
  6. It seems is not working now for unknown reasons did you find any alternative way for the same

    ReplyDelete
    Replies
    1. Yes, you can also check "alpha_vantage" package for indian stocks. I will cover it in a blog post in near future.

      Delete