Complete this import yfinance as yf import pandas as pd Set the ticker symbol for Nifty…
- User
Complete this
import yfinance as yf import pandas as pd
Set the ticker symbol for Nifty futures and BN futures
nifty_symbol = "^NSEI" bn_symbol = "^NSEBANK"
Get the historical data for Nifty futures and BN futures
nifty_data = yf.download(nifty_fut, interval='15m', start='2023-03-01', end='2023-03-09') bn_data = yf.download(bn_fut, interval='15m', start='2023-03-01', end='2023-03-09')
Create a new dataframe to store the signals and other details
signals_df = pd.DataFrame(columns=['Date', 'Nifty Signal', 'BN Signal', '10AM Price', 'Open Price', 'High Price', 'Low Price', 'Close Price', '10AM - Close Price'])
Set the percentage threshold for signal identification
threshold = 0.0005
Loop through each day's data
for date in nifty_data.index.date.unique():
Get the data for the current day
nifty_day_data = nifty_data.loc[date] bn_day_data = bn_data.loc[date]
Check if there are at least 3 candles for the 10AM signal
if len(nifty_day_data) < 3 or len(bn_day_data) < 3: signals_df = signals_df.append({'Date': date, 'Nifty Signal': 'Neutral', 'BN Signal': 'Neutral'}, ignore_index=True) continue
Check for the 10AM signal
nifty_10am_signal = '' bn_10am_signal = '' nifty_10am_price = nifty_day_data.iloc[2]['Close'] bn_10am_price = bn_day_data.iloc[2]['Close'] nifty_open_price = nifty_day_data.iloc[0]['Open'] bn_open_price = bn_day_data.iloc[0]['Open'] nifty_high_price = nifty_day_data.iloc[0:3]['High'].max() bn_high_price = bn_day_data.iloc[0:3]['High'].max() nifty_low_price = nifty_day_data.iloc[0:3]['Low'].min() bn_low_price = bn_day_data.iloc[0:3]['Low'].min() nifty_close_price = nifty_day_data.iloc[-1]['Close'] bn_close_price = bn_day_data.iloc[-1]['Close'] nifty_diff = abs(nifty_10am_price - nifty_close_price) bn_diff = abs(bn_10am_price - bn_close_price)
if nifty_10am_price > nifty_high_price and bn_10am_price > bn_high_price and nifty_diff / nifty_close_price < threshold and bn_diff / bn_close_price < threshold: nifty_10am_signal = 'Bullish' bn_10am_signal = 'Bullish' elif nifty_10am_price < nifty_low_price and bn_10am_price < bn_low_price and nifty_diff / nifty_close_price < threshold and bn_diff / bn_close_price < threshold: nifty_10am_signal = 'Bearish' bn_10am_signal = 'Bearish'
Check for the 9:45AM signal
nifty_945_signal = """ bn_945_signal = """ nifty_945_price = nifty_day_data.iloc[1]['Close
- Assistant
'] # get the closing price of the 9:45 AM candle for Nifty futures bn_945_price = bn_day_data.iloc[1]['Close'] # get the closing price of the 9:45 AM candle for BN futures
python