def fetch_data(self, period="1y", start_date=None, end_date=None): """ Fetches historical data for NIFTY 50.
try: ticker_obj = yf.Ticker(self.TICKER) yahoo nifty historical data
# Yahoo Finance ticker for NIFTY 50 is ^NSEI TICKER = "^NSEI" yahoo nifty historical data
: Use ^NSEI to find the standard Nifty 50 index. Other related tickers include NIFTY50.NS and various specialized indices like NIFTYALPHA50.NS . yahoo nifty historical data
# 2. Fetch data for the last 2 years # Note: You can also use specific dates: # nifty.fetch_data(start_date="2023-01-01", end_date="2023-12-31") nifty.fetch_data(period="2y")
if start_date and end_date: self.data = ticker_obj.history(start=start_date, end=end_date) else: self.data = ticker_obj.history(period=period)
# 3. Process data (Add indicators) nifty.calculate_moving_averages()