Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,11 +27,11 @@ def load_sp500_tickers():
|
|
27 |
|
28 |
|
29 |
|
30 |
-
def load_data(ticker):
|
31 |
-
"""Load stock data using yfinance."""
|
32 |
end_date = datetime.today()
|
33 |
start_date = end_date - timedelta(days=365) # Get 1 year of data
|
34 |
-
data = yf.download(ticker, start=start_date, end=end_date)
|
35 |
return data
|
36 |
|
37 |
|
@@ -148,16 +148,16 @@ def next_business_day(date):
|
|
148 |
|
149 |
|
150 |
|
151 |
-
def gradio_scan_sp500(top_n, progress=gr.Progress()):
|
152 |
progress(0, desc="Downloading Data")
|
153 |
tickers = load_sp500_tickers()
|
154 |
tickers.append("QQQ")
|
155 |
|
156 |
progress(0.3, desc="Running Scanner")
|
157 |
-
results = scan_sp500(top_n, progress)
|
158 |
|
159 |
# Get the last date of the data and find the next business day
|
160 |
-
last_data = load_data(results[0][0]) # Load data for the first ticker in results
|
161 |
last_date = last_data.index[-1].date()
|
162 |
next_market_day = next_business_day(last_date)
|
163 |
date_created = next_market_day.strftime("%Y-%m-%d")
|
@@ -170,12 +170,16 @@ def gradio_scan_sp500(top_n, progress=gr.Progress()):
|
|
170 |
|
171 |
iface = gr.Interface(
|
172 |
fn=gradio_scan_sp500,
|
173 |
-
inputs=
|
|
|
|
|
|
|
174 |
outputs="text",
|
175 |
title="S&P 500 Stock Scanner",
|
176 |
description="Scan S&P 500 stocks and display top N stocks based on today's candle score.",
|
177 |
allow_flagging="never",
|
178 |
)
|
179 |
|
|
|
180 |
if __name__ == "__main__":
|
181 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
27 |
|
28 |
|
29 |
|
30 |
+
def load_data(ticker, interval="1d"):
|
31 |
+
"""Load stock data using yfinance with a specified interval."""
|
32 |
end_date = datetime.today()
|
33 |
start_date = end_date - timedelta(days=365) # Get 1 year of data
|
34 |
+
data = yf.download(ticker, start=start_date, end=end_date, interval=interval)
|
35 |
return data
|
36 |
|
37 |
|
|
|
148 |
|
149 |
|
150 |
|
151 |
+
def gradio_scan_sp500(top_n, interval, progress=gr.Progress()):
|
152 |
progress(0, desc="Downloading Data")
|
153 |
tickers = load_sp500_tickers()
|
154 |
tickers.append("QQQ")
|
155 |
|
156 |
progress(0.3, desc="Running Scanner")
|
157 |
+
results = scan_sp500(top_n, interval, progress)
|
158 |
|
159 |
# Get the last date of the data and find the next business day
|
160 |
+
last_data = load_data(results[0][0], interval) # Load data for the first ticker in results
|
161 |
last_date = last_data.index[-1].date()
|
162 |
next_market_day = next_business_day(last_date)
|
163 |
date_created = next_market_day.strftime("%Y-%m-%d")
|
|
|
170 |
|
171 |
iface = gr.Interface(
|
172 |
fn=gradio_scan_sp500,
|
173 |
+
inputs=[
|
174 |
+
gr.Slider(minimum=1, maximum=100, step=1, label="Number of top stocks to display", value=25),
|
175 |
+
gr.Dropdown(choices=["1d", "1wk", "1mo"], label="Data Interval", value="1d"),
|
176 |
+
],
|
177 |
outputs="text",
|
178 |
title="S&P 500 Stock Scanner",
|
179 |
description="Scan S&P 500 stocks and display top N stocks based on today's candle score.",
|
180 |
allow_flagging="never",
|
181 |
)
|
182 |
|
183 |
+
|
184 |
if __name__ == "__main__":
|
185 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|