pm6six commited on
Commit
10cb253
·
verified ·
1 Parent(s): ef15a78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -5,6 +5,7 @@ import matplotlib.pyplot as plt
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)
@@ -38,7 +39,7 @@ def sma_crossover_strategy(initial_budget, start_date, end_date, ticker):
38
  portfolio_value = cash + (shares * row['Close'])
39
  portfolio_values.append(portfolio_value)
40
 
41
- df = df.iloc[149:] # Skip rows without SMA values
42
  df['Portfolio Value'] = portfolio_values[149:]
43
 
44
  plt.figure(figsize=(14, 8))
@@ -70,6 +71,7 @@ def sma_crossover_strategy(initial_budget, start_date, end_date, ticker):
70
 
71
  return plot_file, results
72
 
 
73
  # Define Gradio App
74
  with gr.Blocks() as app:
75
  gr.Markdown("# SMA Crossover Trading Strategy Simulator")
@@ -93,7 +95,6 @@ with gr.Blocks() as app:
93
  outputs=[portfolio_graph, summary_text],
94
  )
95
 
96
- # Ensure only one app.launch() is called
97
  if __name__ == "__main__":
98
- app.launch()
99
 
 
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)
 
39
  portfolio_value = cash + (shares * row['Close'])
40
  portfolio_values.append(portfolio_value)
41
 
42
+ df = df.iloc[149:]
43
  df['Portfolio Value'] = portfolio_values[149:]
44
 
45
  plt.figure(figsize=(14, 8))
 
71
 
72
  return plot_file, results
73
 
74
+
75
  # Define Gradio App
76
  with gr.Blocks() as app:
77
  gr.Markdown("# SMA Crossover Trading Strategy Simulator")
 
95
  outputs=[portfolio_graph, summary_text],
96
  )
97
 
 
98
  if __name__ == "__main__":
99
+ app.launch(server_port=7861)
100