Course Name: Python for Trading: Basic, Section No: 5, Unit No: 7, Unit type: Notebook
I TRIED data=yf.download('TCS')
AND yf.download('infy') i am getting price in us dollars.They are also traded in us exchanges.
and yf.download('NSE:TCS'),yf.download('NSE:INFY) i am getting error.
how can i imports indian stocks that traded in NSE?
Hi Sridhar,
You can use the symbols from the yahoo finance website.
For e.g. to get an NSE stock like ONGC, you can run the following command:
import yfinance as yf
data = yf.download("ONGC.NS", start="2021-01-01", end="2021-03-01")
Hope this helps!
how to get past option data through python language
plz give me idea
i tried too many times
from nsepy , but i didnt get anything
Try the below lines of code to fetch Nifty Options data from NSEpy.
from nsepy import get_history
from datetime import date
nifty_options = get_history(symbol='NIFTY',
start=date(2020, 2, 1),
end=date(2021, 5, 27),
index=True,
expiry_date=date(2021, 5, 27),
option_type='CE',
strike_price=15500,
)
You need to be careful in passing the expiry_date and strike price of the security. Can refer to the options chain for that.
Refer to the NSEpy documentation for more details.