SelmaNajih001 commited on
Commit
223743e
·
verified ·
1 Parent(s): c0b03d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -25
app.py CHANGED
@@ -203,31 +203,71 @@ def show_company_data(selected_companies, aggregation="Day"):
203
  )
204
 
205
  return None, fig_strat, fig_price
206
-
207
- # --- INTERFACCIA GRADIO ---
208
- demo = gr.Interface(
209
- fn=show_company_data,
210
- inputs=[
211
- gr.Dropdown(
212
- choices=companies,
213
- value=["Microsoft", "Tesla, Inc."],
214
- multiselect=True,
215
- label="Select Companies"
216
- ),
217
- gr.Radio(
218
- choices=["Day", "Month", "Year"],
219
- value="Day",
220
- label="Aggregation Level"
221
- )
222
- ],
223
- outputs=[
224
- gr.Dataframe(label="Data Preview", type="pandas"),
225
- gr.Plot(label="Strategies"),
226
- gr.Plot(label="Prices")
227
- ],
228
- title="Portfolio Evolution",
229
- description="Compare Custom Sentiment, Regression, and FinBERT strategies alongside stock prices."
230
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
  demo.launch()
233
 
 
 
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
+ # --- INTERFACCIA GRADIO A COLONNE ---
243
+ with gr.Blocks() as demo:
244
+ gr.Markdown("# Portfolio Strategy Dashboard")
245
+
246
+ with gr.Row():
247
+ # Colonna a sinistra: Markdown
248
+ with gr.Column(scale=1):
249
+ gr.Markdown(description_text)
250
+
251
+ # Colonna a destra: Input
252
+ with gr.Column(scale=2):
253
+ dropdown_companies = gr.Dropdown(
254
+ choices=companies,
255
+ value=["Microsoft", "Tesla, Inc."],
256
+ multiselect=True,
257
+ label="Select Companies"
258
+ )
259
+
260
+ radio_aggregation = gr.Radio(
261
+ choices=["Day", "Month", "Year"],
262
+ value="Day",
263
+ label="Aggregation Level"
264
+ )
265
+
266
+ # Output sotto le colonne
267
+ gr.Dataframe(label="Data Preview", type="pandas")
268
+ gr.Plot(label="Strategies")
269
+ gr.Plot(label="Prices")
270
 
271
  demo.launch()
272
 
273
+