Skip to content
Related Articles

Related Articles

NseTools – Getting Average Price of Comapny Stock
  • Last Updated : 18 Aug, 2020

In this article we will see how we can get the average price of given company using nsetools. Nsetools is a library for collecting real time data from National Stock Exchange of India. A stock quote is the price of a stock as quoted on an exchange. A basic quote for a specific stock provides information, such as its bid and ask price, last traded price, and volume traded. For a given stock, add up the total purchase price for all shares, then add in any dividends that have been reinvested, and divide that total by the total number of shares owned. This will give you an average cost per share.

Steps to get the Stock Quote
1. Import the Nse from nsetools
2. Create a Nse object
3. From the Nse object get the stock quote with the help of get_quote method with the NSE Stock code of the company
4. Get the average price from the quote with the help of ‘averagePrice’ key
5. Print the average price value

Below is the implementation

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing nse from nse tools
from nsetools import Nse
  
# creating a Nse object
nse = Nse()
  
# nse stock code for wipro
code = "wipro"
  
# getting stock quote 
quote = nse.get_quote(code)
  
# getting average price
value = quote['averagePrice']
  
# printing average price
print("Average Price  : " + str(value))

chevron_right


Output :

Average Price  : 280.4

Another example



filter_none

edit
close

play_arrow

link
brightness_4
code

# importing nse from nse tools
from nsetools import Nse
  
# creating a Nse object
nse = Nse()
  
# nse stock code for sbi
code = "sbin"
  
# getting stock quote 
quote = nse.get_quote(code)
  
# getting average price
value = quote['averagePrice']
  
# printing average price
print("Average Price  : " + str(value))

chevron_right


Output :

Average Price  : 193.9

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :