Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -52,14 +52,22 @@ def buy_sell_signals(data, rsi, macd, signal_line):
|
|
52 |
return buy_signals, sell_signals
|
53 |
|
54 |
|
55 |
-
def
|
56 |
-
fig = make_subplots(rows=2, cols=1)
|
57 |
-
|
58 |
-
|
59 |
-
fig.add_trace(go.
|
60 |
-
|
61 |
-
fig.
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
def main_interface(ticker, period):
|
65 |
data = fetch_data(ticker, period)
|
@@ -72,7 +80,7 @@ def main_interface(ticker, period):
|
|
72 |
# Step 7: Set Up Gradio Interface with corrected type parameter
|
73 |
iface = gr.Interface(fn=main_interface,
|
74 |
inputs=[gr.Textbox(label="Asset Ticker"), gr.Textbox(label="Period: (e.g., 1y, 2y, 5y)")],
|
75 |
-
outputs=gr.
|
76 |
title="Stock Analysis Tool",
|
77 |
description="Enter a stock ticker and period to analyze buy/sell signals based on RSI and MACD.")
|
78 |
|
|
|
52 |
return buy_signals, sell_signals
|
53 |
|
54 |
|
55 |
+
def plot_with_gr_plot(data, buy_signals_rsi, sell_signals_rsi, buy_signals_macd, sell_signals_macd):
|
56 |
+
fig = make_subplots(rows=2, cols=1, shared_xaxes=True)
|
57 |
+
|
58 |
+
# Add the candlestick chart
|
59 |
+
fig.add_trace(go.Candlestick(x=data.index, open=data['Open'], high=data['High'], low=data['Low'], close=data['Close'], name='Market Data'), row=1, col=1)
|
60 |
+
|
61 |
+
fig.add_trace(go.Scatter(x=list(buy_signals_rsi.keys()), y=list(buy_signals_rsi.values()), mode='markers', marker_symbol='triangle-up', marker_color='green', name='Buy Signal RSI', text=["RSI Buy"]*len(buy_signals_rsi), hoverinfo='text+y'), row=1, col=1)
|
62 |
+
fig.add_trace(go.Scatter(x=list(sell_signals_rsi.keys()), y=list(sell_signals_rsi.values()), mode='markers', marker_symbol='triangle-down', marker_color='red', name='Sell Signal RSI', text=["RSI Sell"]*len(sell_signals_rsi), hoverinfo='text+y'), row=1, col=1)
|
63 |
+
|
64 |
+
fig.add_trace(go.Scatter(x=list(buy_signals_macd.keys()), y=list(buy_signals_macd.values()), mode='markers', marker=dict(symbol='triangle-up', color='blue', size=10), name='Buy Signal MACD', text=["MACD Buy"]*len(buy_signals_macd), hoverinfo='text+y'), row=1, col=1)
|
65 |
+
fig.add_trace(go.Scatter(x=list(sell_signals_macd.keys()), y=list(sell_signals_macd.values()), mode='markers', marker=dict(symbol='triangle-down', color='purple', size=10), name='Sell Signal MACD', text=["MACD Sell"]*len(sell_signals_macd), hoverinfo='text+y'), row=1, col=1)
|
66 |
+
|
67 |
+
# Update layout if needed
|
68 |
+
fig.update_layout(title='Stock Analysis with RSI and MACD Signals')
|
69 |
+
|
70 |
+
return fig
|
71 |
|
72 |
def main_interface(ticker, period):
|
73 |
data = fetch_data(ticker, period)
|
|
|
80 |
# Step 7: Set Up Gradio Interface with corrected type parameter
|
81 |
iface = gr.Interface(fn=main_interface,
|
82 |
inputs=[gr.Textbox(label="Asset Ticker"), gr.Textbox(label="Period: (e.g., 1y, 2y, 5y)")],
|
83 |
+
outputs=gr.Plot(type="filepath"), # Corrected type parameter
|
84 |
title="Stock Analysis Tool",
|
85 |
description="Enter a stock ticker and period to analyze buy/sell signals based on RSI and MACD.")
|
86 |
|