tttarun commited on
Commit
cd5b322
1 Parent(s): 1bc66c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -77,8 +77,18 @@ def calculate_profit_loss(stock_data,days_to_monitor):
77
  'Profit/Loss (%)': profit_loss_percent,
78
  'No trigger': no_trigger
79
  })
 
 
 
 
 
 
 
 
 
 
80
 
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):
@@ -140,21 +150,21 @@ def get_stock_data(stock_name,rsi_window,days_to_monitor,previous_n_days,rsi_thr
140
 
141
  fstock = stock_data[stock_data['condition']==1].reset_index(drop=True)
142
 
143
- profit_data = calculate_profit_loss(stock_data,days_to_monitor)
144
 
145
  # Returning two dataframes: One for the full stock data, another for RSI values
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
155
  # profit_data['Date'] = pd.to_datetime(profit_data['Date']).dt.date
156
 
157
- return fstock, profit_data, csv_file_path
158
 
159
  # Create the Gradio interface
160
  with gr.Blocks() as demo:
@@ -183,11 +193,12 @@ with gr.Blocks() as demo:
183
  with gr.Column():
184
  gr.Markdown("<h3 style='text-align: center;'>Output</h3>")
185
  output_stock_data = gr.DataFrame(label="Dates where Conditions met", interactive=False)
186
- output_rsi_data = gr.DataFrame(label="Profit and Loss Statement", interactive=False)
 
187
  csv_download = gr.File(label="Download the full CSV")
188
 
189
  # When the button is clicked, show the two dataframes and provide a downloadable CSV
190
- 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])
191
 
192
  # Launch the Gradio interface
193
  demo.launch()
 
77
  'Profit/Loss (%)': profit_loss_percent,
78
  'No trigger': no_trigger
79
  })
80
+
81
+ dft = pd.DataFrame(buy_sell_actions)
82
+
83
+ dff = pd.DataFrame()
84
+ dff['+ve trade probability'] = len(dft[dft['Profit/Loss (%)'] > 0])
85
+ dff['Mean returns'] = dft['Profit/Loss (%)'].mean()
86
+ dff['Median returns'] = dft['Profit/Loss (%)'].median()
87
+ dff['Best return'] = dft['Profit/Loss (%)'].max()
88
+ dff['worst return'] = dft['Profit/Loss (%)'].min()
89
+
90
 
91
+ return dft, dff
92
 
93
  # Example function to simulate loading and processing stock data
94
  def get_stock_data(stock_name,rsi_window,days_to_monitor,previous_n_days,rsi_threshold1,rsi_threshold2):
 
150
 
151
  fstock = stock_data[stock_data['condition']==1].reset_index(drop=True)
152
 
153
+ profit_data, summary_data = calculate_profit_loss(stock_data,days_to_monitor)
154
 
155
  # Returning two dataframes: One for the full stock data, another for RSI values
156
+ return fstock, profit_data,summary_data
157
 
158
  # Function to save CSV file and return its path
159
  def save_to_csv(stock_input,rsi_window_slider,days_to_monitor,previous_n_days,rsi_threshold1,rsi_threshold2):
160
  stock_name = stock_name.upper()
161
+ fstock, profit_data,summary_data = get_stock_data(stock_name,rsi_window,days_to_monitor,previous_n_days,rsi_threshold1,rsi_threshold2)
162
  csv_file_path = f'{stock_name}.csv'
163
 
164
  # fstock['Date'] = pd.to_datetime(fstock['Date']).dt.date
165
  # profit_data['Date'] = pd.to_datetime(profit_data['Date']).dt.date
166
 
167
+ return fstock, profit_data, summary_data, csv_file_path
168
 
169
  # Create the Gradio interface
170
  with gr.Blocks() as demo:
 
193
  with gr.Column():
194
  gr.Markdown("<h3 style='text-align: center;'>Output</h3>")
195
  output_stock_data = gr.DataFrame(label="Dates where Conditions met", interactive=False)
196
+ output_pl_data = gr.DataFrame(label="Profit and Loss Statement", interactive=False)
197
+ output_summary_data = gr.DataFrame(label="Returns Summary", interactive=False)
198
  csv_download = gr.File(label="Download the full CSV")
199
 
200
  # When the button is clicked, show the two dataframes and provide a downloadable CSV
201
+ 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_pl_data, output_summary_data,csv_download])
202
 
203
  # Launch the Gradio interface
204
  demo.launch()