rsi / app.py
riteshcp's picture
Update app.py
2303b3d verified
raw
history blame
7.45 kB
import streamlit as st
import pandas as pd
import numpy as np
import datetime as dt
import yfinance as yf
import ta
# List of all futures stocks
futures_stocks = [
"ACC.NS", "ADANIENT.NS", "ADANIPORTS.NS", "AMBUJACEM.NS", "APOLLOHOSP.NS",
"ASHOKLEY.NS", "ASIANPAINT.NS", "AXISBANK.NS", "BAJAJ-AUTO.NS", "BAJFINANCE.NS",
"BAJAJFINSV.NS", "BALKRISIND.NS", "BANDHANBNK.NS", "BANKBARODA.NS", "BANKINDIA.NS",
"BERGEPAINT.NS", "BHARATFORG.NS", "BPCL.NS", "BHARTIARTL.NS", "BIOCON.NS",
"BOSCHLTD.NS", "BRITANNIA.NS", "CANBK.NS", "CHOLAFIN.NS", "CIPLA.NS",
"COALINDIA.NS", "CONCOR.NS", "CUMMINSIND.NS", "DABUR.NS", "DELTACORP.NS",
"DIVISLAB.NS", "DLF.NS", "DRREDDY.NS", "EICHERMOT.NS", "FEDERALBNK.NS",
"GAIL.NS", "GLENMARK.NS", "GMRINFRA.NS", "GODREJCP.NS", "GODREJPROP.NS",
"GRANULES.NS", "GRASIM.NS", "HAVELLS.NS", "HCLTECH.NS",
"HDFCAMC.NS", "HDFCBANK.NS", "HDFCLIFE.NS", "HEROMOTOCO.NS", "HINDALCO.NS",
"HINDCOPPER.NS", "HINDPETRO.NS", "HINDUNILVR.NS", "IBULHSGFIN.NS", "ICICIBANK.NS",
"ICICIGI.NS", "ICICIPRULI.NS", "IDEA.NS", "IDFCFIRSTB.NS", "INDHOTEL.NS",
"INDIACEM.NS", "INDIAMART.NS", "INDIGO.NS", "INDUSINDBK.NS", "INFY.NS",
"IRCTC.NS", "ITC.NS", "JINDALSTEL.NS", "JSWSTEEL.NS", "JUBLFOOD.NS",
"KOTAKBANK.NS", "L&TFH.NS", "LALPATHLAB.NS", "LAURUSLABS.NS", "LICHSGFIN.NS",
"LT.NS", "LUPIN.NS", "M&M.NS", "M&MFIN.NS", "MANAPPURAM.NS",
"MARICO.NS", "MARUTI.NS", "MCDOWELL-N.NS", "MCX.NS", "METROPOLIS.NS",
"MFSL.NS", "MGL.NS", "MINDTREE.NS", "MOTHERSUMI.NS", "MPHASIS.NS",
"MRF.NS", "MUTHOOTFIN.NS", "NAM-INDIA.NS", "NATIONALUM.NS", "NAUKRI.NS",
"NAVINFLUOR.NS", "NBCC.NS", "NESTLEIND.NS", "NMDC.NS", "NTPC.NS",
"ONGC.NS", "PAGEIND.NS", "PEL.NS", "PETRONET.NS", "PFC.NS",
"PFIZER.NS", "PIDILITIND.NS", "PIIND.NS", "PNB.NS", "POLYCAB.NS",
"POWERGRID.NS", "PVR.NS", "RAMCOCEM.NS", "RBLBANK.NS", "RECLTD.NS",
"RELIANCE.NS", "SAIL.NS", "SBICARD.NS", "SBILIFE.NS", "SBIN.NS",
"SHREECEM.NS", "SIEMENS.NS", "SRF.NS", "SRTRANSFIN.NS", "SUNPHARMA.NS",
"SUNTV.NS", "TATACHEM.NS", "TATACOMM.NS", "TATACONSUM.NS", "TATAMOTORS.NS",
"TATAPOWER.NS", "TATASTEEL.NS", "TCS.NS", "TECHM.NS", "TITAN.NS",
"TORNTPHARM.NS", "TORNTPOWER.NS", "TRENT.NS", "TVSMOTOR.NS", "UBL.NS",
"ULTRACEMCO.NS", "UPL.NS", "VBL.NS", "VEDL.NS", "VOLTAS.NS",
"WHIRLPOOL.NS", "WIPRO.NS", "ZEEL.NS"
]
# Predefined setups
predefined_setups = {
"Custom": None,
"Conservative Approach": {
"RSI Threshold": 40, "RSI Length": 20, "Stochastic RSI Threshold": 0.30,
"Stochastic Length": 20, "OBV Change Threshold": 1.00
},
"Aggressive Approach": {
"RSI Threshold": 25, "RSI Length": 10, "Stochastic RSI Threshold": 0.10,
"Stochastic Length": 10, "OBV Change Threshold": 5.00
},
"Swing Trading Setup": {
"RSI Threshold": 30, "RSI Length": 14, "Stochastic RSI Threshold": 0.20,
"Stochastic Length": 14, "OBV Change Threshold": 2.00
},
"Reversal Trading": {
"RSI Threshold": 20, "RSI Length": 14, "Stochastic RSI Threshold": 0.15,
"Stochastic Length": 14, "OBV Change Threshold": 3.00
},
"Momentum Trading": {
"RSI Threshold": 50, "RSI Length": 9, "Stochastic RSI Threshold": 0.50,
"Stochastic Length": 9, "OBV Change Threshold": 4.00
},
"Day Trading Setup": {
"RSI Threshold": 35, "RSI Length": 7, "Stochastic RSI Threshold": 0.25,
"Stochastic Length": 7, "OBV Change Threshold": 2.50
},
"Trend Following Setup": {
"RSI Threshold": 50, "RSI Length": 20, "Stochastic RSI Threshold": 0.50,
"Stochastic Length": 20, "OBV Change Threshold": 1.50
},
"Volatility Setup": {
"RSI Threshold": 30, "RSI Length": 12, "Stochastic RSI Threshold": 0.35,
"Stochastic Length": 12, "OBV Change Threshold": 5.00
},
"Long-Term Investment Setup": {
"RSI Threshold": 60, "RSI Length": 30, "Stochastic RSI Threshold": 0.40,
"Stochastic Length": 30, "OBV Change Threshold": 0.50
},
"Short Squeeze Setup": {
"RSI Threshold": 20, "RSI Length": 5, "Stochastic RSI Threshold": 0.10,
"Stochastic Length": 5, "OBV Change Threshold": 7.00
}
}
# The fetch_and_calculate_indicators and filter_stocks_by_indicators functions remain unchanged
def main():
st.title("Indian Stock Market Scanner: RSI, Stochastic RSI, and OBV")
start_date = st.date_input("Start Date", dt.date(2020, 1, 1))
end_date = st.date_input("End Date", dt.date.today())
setup_choice = st.selectbox("Choose a predefined setup or customize", list(predefined_setups.keys()))
if setup_choice == "Custom":
indicator_choice = st.radio("Choose Indicator", ('RSI', 'StochRSI', 'OBV', 'All'))
col1, col2, col3 = st.columns(3)
with col1:
rsi_threshold = st.slider("RSI Threshold", 0, 100, 30)
rsi_length = st.number_input("RSI Length", value=14, min_value=1, max_value=100)
with col2:
stoch_rsi_threshold = st.slider("Stochastic RSI Threshold", 0.0, 1.0, 0.2)
stoch_length = st.number_input("Stochastic Length", value=14, min_value=1, max_value=100)
with col3:
obv_threshold = st.slider("OBV Change Threshold (%)", -10.0, 10.0, 2.0)
k_period = st.number_input("K Period", value=3, min_value=1, max_value=20)
d_period = st.number_input("D Period", value=3, min_value=1, max_value=20)
else:
setup = predefined_setups[setup_choice]
indicator_choice = 'All'
rsi_threshold = setup["RSI Threshold"]
rsi_length = setup["RSI Length"]
stoch_rsi_threshold = setup["Stochastic RSI Threshold"]
stoch_length = setup["Stochastic Length"]
obv_threshold = setup["OBV Change Threshold"]
k_period = 3 # Default value
d_period = 3 # Default value
st.write(f"Selected setup: {setup_choice}")
st.write(f"RSI Threshold: {rsi_threshold}, RSI Length: {rsi_length}")
st.write(f"Stochastic RSI Threshold: {stoch_rsi_threshold}, Stochastic Length: {stoch_length}")
st.write(f"OBV Change Threshold: {obv_threshold}%")
output_filename = st.text_input("Enter output filename (with .csv extension):", "filtered_stocks.csv")
if st.button("Start Scanning", key="start_scanning_button"):
st.write(f"Scanning for stocks based on selected criteria...")
filtered_stocks = filter_stocks_by_indicators(
futures_stocks, start_date, end_date, rsi_threshold, stoch_rsi_threshold, obv_threshold,
indicator_choice, rsi_length, stoch_length, k_period, d_period
)
if filtered_stocks:
st.success(f"Found {len(filtered_stocks)} stocks meeting the criteria:")
df = pd.DataFrame(filtered_stocks)
st.dataframe(df)
csv_data = df.to_csv(index=False).encode('utf-8')
st.download_button(
label="Download CSV",
data=csv_data,
file_name=output_filename,
mime='text/csv',
)
st.success(f"Click the button above to download the filtered stocks with RSI, StochRSI, and OBV Change data.")
else:
st.warning(f"No stocks found meeting the selected criteria.")
if __name__ == "__main__":
main()