0% found this document useful (0 votes)
79 views4 pages

Nano - Course - On - Python - Thread - by - Indian - Quant - Jan 22, 22 - From - Rattibha

The document summarizes a Python code that downloads the past 5 years of daily stock price data for all Nifty50 stocks from the NSE (National Stock Exchange) of India using the NSEpy library. The code is able to download data for all 50 stocks in under 2 minutes. Each stock's data is saved in a separate CSV file named after the stock ticker. In the next module, the document notes that it will demonstrate how to use this historical data to create and test trading strategies.

Uploaded by

vivekchandern
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views4 pages

Nano - Course - On - Python - Thread - by - Indian - Quant - Jan 22, 22 - From - Rattibha

The document summarizes a Python code that downloads the past 5 years of daily stock price data for all Nifty50 stocks from the NSE (National Stock Exchange) of India using the NSEpy library. The code is able to download data for all 50 stocks in under 2 minutes. Each stock's data is saved in a separate CSV file named after the stock ticker. In the next module, the document notes that it will demonstrate how to use this historical data to create and test trading strategies.

Uploaded by

vivekchandern
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Indian Quant

@indian_quant

8 Tweets • 2022-01-22 05:11:19 UTC •  See on Twitter


rattibha.com 

Nano Course On Python For Trading


==========================
Module 2

In this post, I will attempt to show a simple Python code to download the past 5
years' Nifty50 stocks EOD Data using the NSEpy library in less than 2 minutes.

The first few lines are simple to import statements. Pulling public library NSEpy
that we can use to extract historical and real-time data from NSE’s website. Then, we
import the most popular pandas library.

https://nsepy.xyz/

Then I define a function "fetchData" that fetches the data using the built-in
get_history function of the nsepy library. I adjust the original data frame to store
open, high, low and close prices. The original data frame sends more columns -
Volume, Turnover, %Deliverable, etc.
I then go ahead and put all Nifty50 tickers in a Python list named nifty50list. I also
set our start-date (2014-01-01), end-date(2022-01-21) in the YYYY-MM-DD format,
and the path where I want to save my files on my PC.

Finally, I loop through all the Nifty50 tickers calling the fetchData function on each
of them and saving them in the path specified above in the CSV format e.g.
ADANIPORTS.csv, which came first. This process is repeated for each and every
symbol in Nifty50.

The result is 2 minutes to download 50 stocks worth of data! Each ticker's data is
saved in a file named Ticker.csv You can visit this colab notebook and try out your
hands with the code
https://colab.research.google.com/drive/1u6gqWQ0Ozl84ULBEm_sRqWiPnXWEZp8Z?
usp=sharing

In Module 3, we will learn to use this data to create and test some trading strategies.
Until then, take care and have a great time learning.
Note: NSE website official Terms of Use section 22.f reads as below:

22. Specific Prohibited Uses:

The Site may be used only for lawful purposes by individuals for personal, non-
commercial use only. NSE specifically prohibits any other use of the Site.

These pages were created and arranged by Rattibha services (https://www.rattibha.com)


The contents of these pages, including all images, videos, attachments and external links published
(collectively referred to as "this publication"), were created at the request of a user (s) from
Twitter. Rattibha provides an automated service, without human intervention, to copy the contents of
tweets from Twitter and publish them in an article style, and create PDF pages that can be printed and
shared, at the request of Twitter user (s). Please note that the views and all contents in this
publication are those of the author and do not necessarily represent the views of Rattibha. Rattibha
assumes no responsibility for any damage or breaches of any law resulting from the contents of this
publication.

You might also like