tttarun commited on
Commit
c1e4972
1 Parent(s): d3497fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -81,7 +81,7 @@ def calculate_profit_loss(stock_data,days_to_monitor):
81
  return pd.DataFrame(buy_sell_actions)
82
 
83
  # Example function to simulate loading and processing stock data
84
- def get_stock_data(stock_name,rsi_window,days_to_monitor,previous_n_days,):
85
  stock_name = stock_name.upper()
86
 
87
  get_data(stock_name)
@@ -133,9 +133,9 @@ def get_stock_data(stock_name,rsi_window,days_to_monitor,previous_n_days,):
133
 
134
  ## Applying the condition
135
  for i in range(previous_n_days, len(stock_data)):
136
- prev_30_days_rsi = stock_data['Daily RSI'][i-previous_n_days:i]
137
 
138
- if all(prev_30_days_rsi < 65) and 65 <= stock_data['Daily RSI'].iloc[i] <= 70:
139
  stock_data.at[i, 'condition'] = 1
140
 
141
  fstock = stock_data[stock_data['condition']==1].reset_index(drop=True)
@@ -146,9 +146,9 @@ def get_stock_data(stock_name,rsi_window,days_to_monitor,previous_n_days,):
146
  return fstock, profit_data
147
 
148
  # Function to save CSV file and return its path
149
- def save_to_csv(stock_name,rsi_window):
150
  stock_name = stock_name.upper()
151
- fstock, profit_data = get_stock_data(stock_name,rsi_window)
152
  csv_file_path = f'{stock_name}.csv'
153
 
154
  # fstock['Date'] = pd.to_datetime(fstock['Date']).dt.date
@@ -172,7 +172,11 @@ with gr.Blocks() as demo:
172
  days_to_monitor = gr.Slider(minimum=1, maximum=30, value=8, label="Days to monitor stock once condition is met", step=1)
173
  previous_n_days = gr.Slider(minimum=1, maximum=180, value=30, label="Previous n days RSI threshold to check", step=1)
174
  rsi_threshold1 = gr.Slider(minimum=1, maximum=100, value=65, label="Previous RSI threshold", step=1)
175
- rsi_threshold12= RangeSlider(label="Current RSI Range", minimum=0, maximum=100, value=[65, 70])
 
 
 
 
176
  submit_button = gr.Button("Submit", variant="primary")
177
 
178
  with gr.Column():
@@ -182,7 +186,7 @@ with gr.Blocks() as demo:
182
  csv_download = gr.File(label="Download the full CSV")
183
 
184
  # When the button is clicked, show the two dataframes and provide a downloadable CSV
185
- submit_button.click(save_to_csv, inputs=[stock_input,rsi_window_slider], outputs=[output_stock_data, output_rsi_data, csv_download])
186
 
187
  # Launch the Gradio interface
188
  demo.launch()
 
81
  return pd.DataFrame(buy_sell_actions)
82
 
83
  # Example function to simulate loading and processing stock data
84
+ def get_stock_data(stock_name,rsi_window,days_to_monitor,previous_n_days,rsi_threshold1,rsi_threshold2):
85
  stock_name = stock_name.upper()
86
 
87
  get_data(stock_name)
 
133
 
134
  ## Applying the condition
135
  for i in range(previous_n_days, len(stock_data)):
136
+ prev_n_days_rsi = stock_data['Daily RSI'][i-previous_n_days:i]
137
 
138
+ if all(prev_n_days_rsi < rsi_threshold1) and rsi_threshold2[0] <= stock_data['Daily RSI'].iloc[i] <= rsi_threshold2[1]:
139
  stock_data.at[i, 'condition'] = 1
140
 
141
  fstock = stock_data[stock_data['condition']==1].reset_index(drop=True)
 
146
  return fstock, profit_data
147
 
148
  # Function to save CSV file and return its path
149
+ def save_to_csv(stock_input,rsi_window_slider,days_to_monitor,previous_n_days,rsi_threshold1,rsi_threshold2):
150
  stock_name = stock_name.upper()
151
+ fstock, profit_data = get_stock_data(stock_name,rsi_window,days_to_monitor,previous_n_days,rsi_threshold1,rsi_threshold2)
152
  csv_file_path = f'{stock_name}.csv'
153
 
154
  # fstock['Date'] = pd.to_datetime(fstock['Date']).dt.date
 
172
  days_to_monitor = gr.Slider(minimum=1, maximum=30, value=8, label="Days to monitor stock once condition is met", step=1)
173
  previous_n_days = gr.Slider(minimum=1, maximum=180, value=30, label="Previous n days RSI threshold to check", step=1)
174
  rsi_threshold1 = gr.Slider(minimum=1, maximum=100, value=65, label="Previous RSI threshold", step=1)
175
+ rsi_threshold2 = RangeSlider(label="Current RSI Range", minimum=0, maximum=100, value=[65, 70])
176
+ range_ = gr.Markdown(value=text.format(min=0, max=100))
177
+ rsi_threshold2.change(lambda s: text.format(min=s[0], max=s[1]), range_slider, range_,
178
+ show_progress="hide", trigger_mode="always_last")
179
+
180
  submit_button = gr.Button("Submit", variant="primary")
181
 
182
  with gr.Column():
 
186
  csv_download = gr.File(label="Download the full CSV")
187
 
188
  # When the button is clicked, show the two dataframes and provide a downloadable CSV
189
+ submit_button.click(save_to_csv, inputs=[stock_input,rsi_window_slider,days_to_monitor,previous_n_days,rsi_threshold1,rsi_threshold2], outputs=[output_stock_data, output_rsi_data, csv_download])
190
 
191
  # Launch the Gradio interface
192
  demo.launch()