SelmaNajih001 commited on
Commit
5856d0c
Β·
verified Β·
1 Parent(s): 4b237f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -20
app.py CHANGED
@@ -203,51 +203,52 @@ def show_company_data(selected_companies, aggregation="Day"):
203
  )
204
 
205
  return None, fig_strat, fig_price
206
- # --- MARKDOWN DESCRITTIVO ---
 
 
207
  description_text = """
208
  ### Portfolio Strategy Comparison Dashboard
209
-
210
  This dashboard allows you to compare the performance of three sentiment models in driving trading strategies for Microsoft and Tesla.
211
-
212
  - **Strategy logic**: Each model's score (or regression value) is used as a buy/sell signal.
213
  - If the score exceeds 0.8 β†’ buy
214
  - If the score is below -0.8 β†’ sell
215
  - Otherwise β†’ no trade
216
  - For the regression model, thresholds are +1 and -1.
217
-
218
  - **Dataset and preprocessing**:
219
  - Closing prices and daily percent changes are calculated for each company.
220
  - News articles mentioning Microsoft or Tesla are merged with the price data.
221
  - Negative/Down scores are multiplied by -1, Neutral scores set to 0.
222
  - Daily strategy value = daily percent change Γ— stock price.
223
  - Cumulative value = sum of daily strategy values over time.
224
-
225
  - **Model comparison**:
226
  - Regression is fine-tuned separately for Tesla and Microsoft.
227
  - FinBERT is used as a baseline.
228
  - The custom model incorporates actual stock movements and company-specific signals.
229
-
230
  - **Results overview**:
231
  - Tesla: Regression often performs better, though some losses occur.
232
  - Microsoft: Regression closely follows market trends; FinBERT is less accurate.
233
  - Regression aligns better with real stock movements by interpreting news contextually.
234
-
235
  - **Caveats**:
236
  - Multiple news per day may generate buy/sell signals that cancel each other.
237
  - Strategy uses next-day price changes; no multi-day logic is applied.
238
  - Simplified testing, but useful to compare model behavior.
239
-
240
  """
241
 
 
 
 
 
 
 
 
 
242
 
243
- # --- INTERFACCIA GRADIO CON DROPDOWN SOTTO IL TESTO ---
244
  with gr.Blocks() as demo:
245
  gr.Markdown("# Portfolio Strategy Dashboard")
246
-
247
- # Markdown in alto
248
  gr.Markdown(description_text)
249
 
250
- # Input sotto il Markdown
251
  with gr.Row():
252
  dropdown_companies = gr.Dropdown(
253
  choices=companies,
@@ -255,18 +256,24 @@ with gr.Blocks() as demo:
255
  multiselect=True,
256
  label="Select Companies"
257
  )
258
-
259
  radio_aggregation = gr.Radio(
260
  choices=["Day", "Month", "Year"],
261
  value="Day",
262
  label="Aggregation Level"
263
  )
264
-
265
- # Output sotto gli input
266
- gr.Dataframe(label="Data Preview", type="pandas")
267
- gr.Plot(label="Strategies")
268
- gr.Plot(label="Prices")
 
 
 
 
 
 
 
 
269
 
270
  demo.launch()
271
-
272
-
 
203
  )
204
 
205
  return None, fig_strat, fig_price
206
+ import gradio as gr
207
+
208
+ # --- Markdown descrittivo ---
209
  description_text = """
210
  ### Portfolio Strategy Comparison Dashboard
 
211
  This dashboard allows you to compare the performance of three sentiment models in driving trading strategies for Microsoft and Tesla.
 
212
  - **Strategy logic**: Each model's score (or regression value) is used as a buy/sell signal.
213
  - If the score exceeds 0.8 β†’ buy
214
  - If the score is below -0.8 β†’ sell
215
  - Otherwise β†’ no trade
216
  - For the regression model, thresholds are +1 and -1.
 
217
  - **Dataset and preprocessing**:
218
  - Closing prices and daily percent changes are calculated for each company.
219
  - News articles mentioning Microsoft or Tesla are merged with the price data.
220
  - Negative/Down scores are multiplied by -1, Neutral scores set to 0.
221
  - Daily strategy value = daily percent change Γ— stock price.
222
  - Cumulative value = sum of daily strategy values over time.
 
223
  - **Model comparison**:
224
  - Regression is fine-tuned separately for Tesla and Microsoft.
225
  - FinBERT is used as a baseline.
226
  - The custom model incorporates actual stock movements and company-specific signals.
 
227
  - **Results overview**:
228
  - Tesla: Regression often performs better, though some losses occur.
229
  - Microsoft: Regression closely follows market trends; FinBERT is less accurate.
230
  - Regression aligns better with real stock movements by interpreting news contextually.
 
231
  - **Caveats**:
232
  - Multiple news per day may generate buy/sell signals that cancel each other.
233
  - Strategy uses next-day price changes; no multi-day logic is applied.
234
  - Simplified testing, but useful to compare model behavior.
 
235
  """
236
 
237
+ # --- INPUT OPTIONS ---
238
+ companies = ["Microsoft", "Tesla, Inc."]
239
+
240
+ # --- FUNZIONE DI ESECUZIONE ---
241
+ def show_strategy(selected_companies, aggregation):
242
+ # Qui chiami la funzione del tuo modello per generare i grafici e il dataframe
243
+ # Ad esempio: return df, fig_strategies, fig_prices
244
+ return None, None, None # sostituire con output reali
245
 
246
+ # --- INTERFACCIA GRADIO ---
247
  with gr.Blocks() as demo:
248
  gr.Markdown("# Portfolio Strategy Dashboard")
 
 
249
  gr.Markdown(description_text)
250
 
251
+ # Input
252
  with gr.Row():
253
  dropdown_companies = gr.Dropdown(
254
  choices=companies,
 
256
  multiselect=True,
257
  label="Select Companies"
258
  )
 
259
  radio_aggregation = gr.Radio(
260
  choices=["Day", "Month", "Year"],
261
  value="Day",
262
  label="Aggregation Level"
263
  )
264
+ submit_btn = gr.Button("Submit") # bottone per inviare
265
+
266
+ # Output
267
+ data_table = gr.Dataframe(label="Data Preview", type="pandas")
268
+ strategies_plot = gr.Plot(label="Strategies")
269
+ prices_plot = gr.Plot(label="Prices")
270
+
271
+ # Collega bottone agli output
272
+ submit_btn.click(
273
+ fn=show_strategy,
274
+ inputs=[dropdown_companies, radio_aggregation],
275
+ outputs=[data_table, strategies_plot, prices_plot]
276
+ )
277
 
278
  demo.launch()
279
+ `