Update app.py
Browse files
app.py
CHANGED
|
@@ -414,87 +414,6 @@ def plot_combined_signals(df, ticker):
|
|
| 414 |
|
| 415 |
return fig
|
| 416 |
|
| 417 |
-
def plot_individual(df, ticker):
|
| 418 |
-
# Create a figure
|
| 419 |
-
fig = go.Figure()
|
| 420 |
-
|
| 421 |
-
# Add closing price line
|
| 422 |
-
fig.add_trace(go.Scatter(
|
| 423 |
-
x=df.index, y=df['Close'],
|
| 424 |
-
mode='lines',
|
| 425 |
-
name='Closing Price',
|
| 426 |
-
line=dict(color='#36A2EB', width=2)
|
| 427 |
-
))
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
# Refined neon colors for signal indicators
|
| 432 |
-
signal_colors = {
|
| 433 |
-
'MACD_Signal': {'buy': '#39FF14', 'sell': '#FF073A'}, # Neon green for buy, neon red for sell
|
| 434 |
-
'RSI_Signal': {'buy': '#39FF14', 'sell': '#FF073A'}, # Neon green for buy, neon red for sell
|
| 435 |
-
'BB_Signal': {'buy': '#39FF14', 'sell': '#FF073A'}, # Neon green for buy, neon red for sell
|
| 436 |
-
'Stochastic_Signal': {'buy': '#39FF14', 'sell': '#FF073A'}, # Neon green for buy, neon red for sell
|
| 437 |
-
'CMF_Signal': {'buy': '#39FF14', 'sell': '#FF073A'}, # Neon green for buy, neon red for sell
|
| 438 |
-
'CCI_Signal': {'buy': '#39FF14', 'sell': '#FF073A'} # Neon green for buy, neon red for sell
|
| 439 |
-
}
|
| 440 |
-
|
| 441 |
-
# Add buy/sell signals for each indicator
|
| 442 |
-
signal_names = ['MACD_Signal', 'RSI_Signal', 'BB_Signal',
|
| 443 |
-
'Stochastic_Signal', 'CMF_Signal',
|
| 444 |
-
'CCI_Signal']
|
| 445 |
-
|
| 446 |
-
for signal in signal_names:
|
| 447 |
-
buy_signals = df[df[signal] == 1]
|
| 448 |
-
sell_signals = df[df[signal] == -1]
|
| 449 |
-
|
| 450 |
-
fig.add_trace(go.Scatter(
|
| 451 |
-
x=buy_signals.index, y=buy_signals['Close'],
|
| 452 |
-
mode='markers',
|
| 453 |
-
marker=dict(
|
| 454 |
-
symbol='triangle-up',
|
| 455 |
-
size=12,
|
| 456 |
-
color=signal_colors[signal]['buy']
|
| 457 |
-
),
|
| 458 |
-
name=f'{signal} Buy Signal'
|
| 459 |
-
))
|
| 460 |
-
|
| 461 |
-
fig.add_trace(go.Scatter(
|
| 462 |
-
x=sell_signals.index, y=sell_signals['Close'],
|
| 463 |
-
mode='markers',
|
| 464 |
-
marker=dict(
|
| 465 |
-
symbol='triangle-down',
|
| 466 |
-
size=12,
|
| 467 |
-
color=signal_colors[signal]['sell']
|
| 468 |
-
),
|
| 469 |
-
name=f'{signal} Sell Signal'
|
| 470 |
-
))
|
| 471 |
-
|
| 472 |
-
fig.update_layout(
|
| 473 |
-
title=f'{ticker}: Individual Trading Signals',
|
| 474 |
-
xaxis=dict(
|
| 475 |
-
title='Date',
|
| 476 |
-
showgrid=True,
|
| 477 |
-
gridcolor="rgba(255,255,255,0.1)"
|
| 478 |
-
),
|
| 479 |
-
yaxis=dict(
|
| 480 |
-
title='Price',
|
| 481 |
-
side='left',
|
| 482 |
-
showgrid=True,
|
| 483 |
-
gridcolor="rgba(255,255,255,0.1)"
|
| 484 |
-
),
|
| 485 |
-
plot_bgcolor='#111111',
|
| 486 |
-
paper_bgcolor='#111111',
|
| 487 |
-
font=dict(color='white', size=12),
|
| 488 |
-
legend=dict(
|
| 489 |
-
bgcolor="rgba(0,0,0,0.8)",
|
| 490 |
-
bordercolor="white",
|
| 491 |
-
borderwidth=1
|
| 492 |
-
),
|
| 493 |
-
margin=dict(l=40, r=40, t=50, b=40)
|
| 494 |
-
)
|
| 495 |
-
|
| 496 |
-
return fig
|
| 497 |
-
|
| 498 |
def plot_individual_signals(df, ticker, x_range=None):
|
| 499 |
fig = go.Figure()
|
| 500 |
|
|
@@ -536,7 +455,7 @@ def plot_individual_signals(df, ticker, x_range=None):
|
|
| 536 |
))
|
| 537 |
|
| 538 |
fig.update_layout(
|
| 539 |
-
title=f'{ticker}
|
| 540 |
xaxis=dict(
|
| 541 |
title='Date',
|
| 542 |
showgrid=True,
|
|
@@ -589,8 +508,25 @@ def technical_analysis(ticker, start_date, end_date):
|
|
| 589 |
except Exception as e:
|
| 590 |
return f"Error: {str(e)}", f"Error: {str(e)}"
|
| 591 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
# Create Gradio interface
|
| 593 |
-
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 594 |
gr.Markdown("# Advanced Stock Analysis & Forecasting App")
|
| 595 |
gr.Markdown("Enter a stock ticker, start date, and end date to analyze and forecast stock prices.")
|
| 596 |
|
|
|
|
| 414 |
|
| 415 |
return fig
|
| 416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
def plot_individual_signals(df, ticker, x_range=None):
|
| 418 |
fig = go.Figure()
|
| 419 |
|
|
|
|
| 455 |
))
|
| 456 |
|
| 457 |
fig.update_layout(
|
| 458 |
+
title=f'{ticker}',
|
| 459 |
xaxis=dict(
|
| 460 |
title='Date',
|
| 461 |
showgrid=True,
|
|
|
|
| 508 |
except Exception as e:
|
| 509 |
return f"Error: {str(e)}", f"Error: {str(e)}"
|
| 510 |
|
| 511 |
+
|
| 512 |
+
# Custom CSS for better appearance
|
| 513 |
+
custom_css = """
|
| 514 |
+
.gradio-container {
|
| 515 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 516 |
+
}
|
| 517 |
+
.container {
|
| 518 |
+
max-width: 1200px;
|
| 519 |
+
margin: auto;
|
| 520 |
+
}
|
| 521 |
+
button#analyze-btn {
|
| 522 |
+
background-color: #003366;
|
| 523 |
+
color: white;
|
| 524 |
+
border: none;
|
| 525 |
+
}
|
| 526 |
+
"""
|
| 527 |
+
|
| 528 |
# Create Gradio interface
|
| 529 |
+
with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo:
|
| 530 |
gr.Markdown("# Advanced Stock Analysis & Forecasting App")
|
| 531 |
gr.Markdown("Enter a stock ticker, start date, and end date to analyze and forecast stock prices.")
|
| 532 |
|