Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 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 |
+
|