pm6six commited on
Commit
c1ee835
·
verified ·
1 Parent(s): 6f66e43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -5,14 +5,13 @@ import matplotlib.pyplot as plt
5
  import io
6
  import gradio as gr
7
 
8
-
9
  def sma_crossover_strategy(initial_budget, start_date, end_date, ticker):
10
  try:
11
  df = yf.download(ticker, start=start_date, end=end_date, progress=False)
12
  if df.empty:
13
- return None, "No data available for the specified ticker and date range."
14
  except Exception as e:
15
- return None, f"Error fetching data: {str(e)}"
16
 
17
  df = df[['Close']]
18
  df['SMA_50'] = df['Close'].rolling(window=50).mean()
@@ -69,9 +68,9 @@ def sma_crossover_strategy(initial_budget, start_date, end_date, ticker):
69
  Percentage Return: {percentage_return:.2f}%
70
  """
71
 
72
- return plot_file, results
73
-
74
 
 
75
  with gr.Blocks() as app:
76
  gr.Markdown("# SMA Crossover Trading Strategy Simulator")
77
 
@@ -88,6 +87,7 @@ with gr.Blocks() as app:
88
  portfolio_graph = gr.Image(label="Portfolio Value Over Time")
89
  summary_text = gr.Textbox(label="Simulation Summary", lines=8)
90
 
 
91
  run_button.click(
92
  sma_crossover_strategy,
93
  inputs=[initial_budget, start_date, end_date, ticker],
 
5
  import io
6
  import gradio as gr
7
 
 
8
  def sma_crossover_strategy(initial_budget, start_date, end_date, ticker):
9
  try:
10
  df = yf.download(ticker, start=start_date, end=end_date, progress=False)
11
  if df.empty:
12
+ return None, "No data available for the specified ticker and date range.", None
13
  except Exception as e:
14
+ return None, f"Error fetching data: {str(e)}", None
15
 
16
  df = df[['Close']]
17
  df['SMA_50'] = df['Close'].rolling(window=50).mean()
 
68
  Percentage Return: {percentage_return:.2f}%
69
  """
70
 
71
+ return plot_file, results, None
 
72
 
73
+ # Gradio Blocks Context
74
  with gr.Blocks() as app:
75
  gr.Markdown("# SMA Crossover Trading Strategy Simulator")
76
 
 
87
  portfolio_graph = gr.Image(label="Portfolio Value Over Time")
88
  summary_text = gr.Textbox(label="Simulation Summary", lines=8)
89
 
90
+ # Ensure run_button.click() is defined here
91
  run_button.click(
92
  sma_crossover_strategy,
93
  inputs=[initial_budget, start_date, end_date, ticker],