SelmaNajih001 commited on
Commit
8cc04fc
·
verified ·
1 Parent(s): 3422997

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -1158
app.py CHANGED
@@ -1,1028 +1,30 @@
1
  import pandas as pd
 
2
  from datasets import load_dataset
3
  from transformers import pipeline
4
  import plotly.express as px
5
- import yfinance as yf
6
  import gradio as gr
7
 
8
- # --- CONFIG ---
9
- companies =['Nvidia',
10
- 'Microsoft',
11
- 'Apple Inc.',
12
- 'Amazon',
13
- 'Meta Platforms',
14
- 'Broadcom',
15
- 'Alphabet Inc. (Class A)',
16
- 'Alphabet Inc. (Class C)',
17
- 'Tesla, Inc.',
18
- 'Berkshire Hathaway',
19
- 'Oracle Corporation',
20
- 'JPMorgan Chase',
21
- 'Walmart',
22
- 'Lilly (Eli)',
23
- 'Visa Inc.',
24
- 'Mastercard',
25
- 'Netflix',
26
- 'ExxonMobil',
27
- 'Palantir Technologies',
28
- 'Johnson & Johnson',
29
- 'Costco',
30
- 'Home Depot (The)',
31
- 'AbbVie',
32
- 'Bank of America',
33
- 'Procter & Gamble',
34
- 'GE Aerospace',
35
- 'Chevron Corporation',
36
- 'UnitedHealth Group',
37
- 'Coca-Cola Company (The)',
38
- 'Wells Fargo',
39
- 'Cisco',
40
- 'T-Mobile US',
41
- 'Morgan Stanley',
42
- 'Advanced Micro Devices',
43
- 'Philip Morris International',
44
- 'IBM',
45
- 'Goldman Sachs',
46
- 'American Express',
47
- 'Abbott Laboratories',
48
- 'Salesforce',
49
- 'Linde plc',
50
- 'Caterpillar Inc.',
51
- "McDonald's",
52
- 'RTX Corporation',
53
- 'AT&T',
54
- 'Merck & Co.',
55
- 'Uber',
56
- 'Walt Disney Company (The)',
57
- 'ServiceNow',
58
- 'PepsiCo',
59
- 'Intuit',
60
- 'Citigroup',
61
- 'Arista Networks',
62
- 'Verizon',
63
- 'Micron Technology',
64
- 'Thermo Fisher Scientific',
65
- 'Qualcomm',
66
- 'Booking Holdings',
67
- 'BlackRock',
68
- 'Charles Schwab Corporation',
69
- 'GE Vernova',
70
- 'Boeing',
71
- 'Lam Research',
72
- 'Texas Instruments',
73
- 'Intuitive Surgical',
74
- 'S&P Global',
75
- 'TJX Companies',
76
- 'Adobe Inc.',
77
- 'Applied Materials',
78
- 'Amgen',
79
- 'Amphenol',
80
- 'Accenture',
81
- "Lowe's",
82
- 'Blackstone Inc.',
83
- 'NextEra Energy',
84
- 'Capital One',
85
- 'Boston Scientific',
86
- 'Eaton Corporation',
87
- 'Stryker Corporation',
88
- 'Progressive Corporation',
89
- 'Gilead Sciences',
90
- 'Palo Alto Networks',
91
- 'Pfizer',
92
- 'Danaher Corporation',
93
- 'Intel',
94
- 'KLA Corporation',
95
- 'KKR',
96
- 'Honeywell',
97
- 'Union Pacific Corporation',
98
- 'Deere & Company',
99
- 'CrowdStrike',
100
- 'Medtronic',
101
- 'Analog Devices',
102
- 'Automatic Data Processing',
103
- 'Comcast',
104
- 'ConocoPhillips',
105
- 'DoorDash',
106
- 'Welltower',
107
- 'Lockheed Martin',
108
- 'Altria',
109
- 'Chubb Limited',
110
- 'Prologis',
111
- 'Nike, Inc.',
112
- 'Constellation Energy',
113
- 'Cadence Design Systems',
114
- 'Southern Company',
115
- 'Vertex Pharmaceuticals',
116
- 'Marsh McLennan',
117
- 'Intercontinental Exchange',
118
- 'Starbucks',
119
- 'Parker Hannifin',
120
- 'CVS Health',
121
- 'CME Group',
122
- 'Duke Energy',
123
- 'HCA Healthcare',
124
- 'Newmont',
125
- 'Bristol Myers Squibb',
126
- 'Trane Technologies',
127
- 'Synopsys',
128
- 'American Tower',
129
- 'Royal Caribbean Group',
130
- 'Dell Technologies',
131
- "O'Reilly Auto Parts",
132
- 'Waste Management',
133
- "Moody's Corporation",
134
- 'General Dynamics',
135
- 'Sherwin-Williams',
136
- 'McKesson Corporation',
137
- 'Coinbase Global',
138
- '3M',
139
- 'Mondelez International',
140
- 'Northrop Grumman',
141
- 'Apollo Global Management',
142
- 'PNC Financial Services',
143
- 'Cintas',
144
- 'Motorola Solutions',
145
- 'U.S. Bancorp',
146
- 'Cigna',
147
- 'Airbnb',
148
- 'Equinix',
149
- 'Arthur J. Gallagher & Co.',
150
- 'BNY Mellon',
151
- 'Howmet Aerospace',
152
- 'Illinois Tool Works',
153
- 'Aon',
154
- 'Ecolab',
155
- 'Emerson Electric',
156
- 'Williams Companies',
157
- 'Marriott International',
158
- 'TransDigm Group',
159
- 'Fiserv',
160
- 'Vistra Corp.',
161
- 'United Parcel Service',
162
- 'Republic Services',
163
- 'Johnson Controls',
164
- 'Elevance Health',
165
- 'AutoZone',
166
- 'Autodesk',
167
- 'Corning Inc.',
168
- 'Colgate-Palmolive',
169
- 'PayPal',
170
- 'Zoetis',
171
- 'Freeport-McMoRan',
172
- 'Fortinet',
173
- 'Air Products',
174
- 'TE Connectivity',
175
- 'Norfolk Southern Railway',
176
- 'EOG Resources',
177
- 'Hilton Worldwide',
178
- 'Regeneron Pharmaceuticals',
179
- 'Monster Beverage',
180
- 'Travelers Companies (The)',
181
- 'Workday, Inc.',
182
- 'CSX Corporation',
183
- 'Kinder Morgan',
184
- 'Axon Enterprise',
185
- 'United Rentals',
186
- 'Digital Realty',
187
- 'Truist Financial',
188
- 'Simon Property Group',
189
- 'Cummins',
190
- 'Quanta Services',
191
- 'Aflac',
192
- 'American Electric Power',
193
- 'Marathon Petroleum',
194
- 'NXP Semiconductors',
195
- 'Cencora',
196
- 'General Motors',
197
- 'FedEx',
198
- 'Fastenal',
199
- 'Roper Technologies',
200
- 'Allstate',
201
- 'Sempra',
202
- 'Realty Income',
203
- 'Becton Dickinson',
204
- 'L3Harris',
205
- 'Chipotle Mexican Grill',
206
- 'Idexx Laboratories',
207
- 'Phillips 66',
208
- 'MetLife',
209
- 'Paccar',
210
- 'Schlumberger',
211
- 'Carrier Global',
212
- 'Nasdaq, Inc.',
213
- 'Dominion Energy',
214
- 'Valero Energy',
215
- 'D. R. Horton',
216
- 'Public Storage',
217
- 'CBRE Group',
218
- 'Datadog',
219
- 'Warner Bros. Discovery',
220
- 'Corteva',
221
- 'Ross Stores',
222
- 'W. W. Grainger',
223
- 'Seagate Technology',
224
- 'Paychex',
225
- 'Block, Inc.',
226
- 'Baker Hughes',
227
- 'Take-Two Interactive',
228
- 'Ford Motor Company',
229
- 'Ameriprise Financial',
230
- 'Garmin',
231
- 'Occidental Petroleum',
232
- 'ONEOK',
233
- 'Copart',
234
- 'Exelon',
235
- 'Monolithic Power Systems',
236
- 'Edwards Lifesciences',
237
- 'Ametek',
238
- 'Kroger',
239
- 'Electronic Arts',
240
- 'MSCI',
241
- 'Xcel Energy',
242
- 'American International Group',
243
- 'eBay',
244
- 'Carnival',
245
- 'Crown Castle',
246
- 'Kimberly-Clark',
247
- 'Yum! Brands',
248
- 'Public Service Enterprise Group',
249
- 'Diamondback Energy',
250
- 'ResMed',
251
- 'Target Corporation',
252
- 'Entergy',
253
- 'Sysco',
254
- 'Vulcan Materials Company',
255
- 'Rockwell Automation',
256
- 'Delta Air Lines',
257
- 'Hershey Company (The)',
258
- 'Live Nation Entertainment',
259
- 'Martin Marietta Materials',
260
- 'Western Digital',
261
- 'CoStar Group',
262
- 'Las Vegas Sands',
263
- 'Hartford (The)',
264
- 'Keurig Dr Pepper',
265
- 'Prudential Financial',
266
- 'Charter Communications',
267
- 'Cardinal Health',
268
- 'Fair Isaac',
269
- 'WEC Energy Group',
270
- 'Targa Resources',
271
- 'Agilent Technologies',
272
- 'Otis Worldwide',
273
- 'Microchip Technology',
274
- 'Consolidated Edison',
275
- 'Raymond James Financial',
276
- 'Xylem Inc.',
277
- 'Verisk Analytics',
278
- 'United Airlines Holdings',
279
- 'Fidelity National Information Services',
280
- 'GE HealthCare',
281
- 'Vici Properties',
282
- 'Kenvue',
283
- 'Arch Capital Group',
284
- 'Willis Towers Watson',
285
- 'Hewlett Packard Enterprise',
286
- 'PG&E Corporation',
287
- 'DuPont',
288
- 'Lennar',
289
- 'Cognizant',
290
- 'Wabtec',
291
- 'State Street Corporation',
292
- 'Ingersoll Rand',
293
- 'Equifax',
294
- 'IQVIA',
295
- 'NRG Energy',
296
- 'M&T Bank',
297
- 'Tractor Supply',
298
- 'Estée Lauder Companies (The)',
299
- 'Kraft Heinz',
300
- 'Nucor',
301
- 'EQT Corporation',
302
- 'Fifth Third Bancorp',
303
- 'Ventas',
304
- 'Brown & Brown',
305
- 'Humana',
306
- 'Keysight Technologies',
307
- 'Extra Space Storage',
308
- 'Old Dominion',
309
- 'Iron Mountain',
310
- 'Archer Daniels Midland',
311
- 'Interactive Brokers Group',
312
- 'Synchrony Financial',
313
- 'Broadridge Financial Solutions',
314
- 'DTE Energy',
315
- 'W. R. Berkley Corporation',
316
- 'Expedia Group',
317
- 'AvalonBay Communities',
318
- 'Rollins, Inc.',
319
- 'Supermicro',
320
- 'General Mills',
321
- 'Kellanova',
322
- 'Ameren',
323
- 'Dexcom',
324
- 'Teledyne Technologies',
325
- 'American Water Works',
326
- 'PPL Corporation',
327
- 'Verisign',
328
- 'HP Inc.',
329
- 'PulteGroup',
330
- 'Atmos Energy',
331
- 'Huntington Bancshares',
332
- 'Veralto',
333
- 'Mettler Toledo',
334
- 'Northern Trust',
335
- 'Equity Residential',
336
- 'FirstEnergy',
337
- 'CenterPoint Energy',
338
- 'NetApp',
339
- 'Eversource Energy',
340
- 'PPG Industries',
341
- 'PTC Inc.',
342
- 'Steris',
343
- 'International Paper',
344
- 'Cboe Global Markets',
345
- 'Regions Financial Corporation',
346
- 'Jabil',
347
- 'Williams-Sonoma',
348
- 'Leidos',
349
- 'Tapestry, Inc.',
350
- 'Cincinnati Financial',
351
- 'Expand Energy',
352
- 'Constellation Brands',
353
- 'Dover Corporation',
354
- 'Hubbell Incorporated',
355
- 'Ulta Beauty',
356
- 'T. Rowe Price',
357
- 'Insulet Corporation',
358
- 'LabCorp',
359
- 'Tyler Technologies',
360
- 'Citizens Financial Group',
361
- 'First Solar',
362
- 'Smurfit WestRock',
363
- 'Dollar General',
364
- 'NVR, Inc.',
365
- 'Church & Dwight',
366
- 'Edison International',
367
- 'Darden Restaurants',
368
- 'The Trade Desk, Inc.',
369
- 'Devon Energy',
370
- 'CDW',
371
- 'SBA Communications',
372
- 'Corpay',
373
- 'CMS Energy',
374
- 'Global Payments',
375
- 'Biogen',
376
- 'KeyCorp',
377
- 'ON Semiconductor',
378
- 'Paramount Skydance Corp',
379
- 'Steel Dynamics',
380
- 'Quest Diagnostics',
381
- 'Lululemon Athletica',
382
- 'Loews Corporation',
383
- 'Texas Pacific Land Corporation',
384
- 'Zimmer Biomet',
385
- 'Trimble Inc.',
386
- 'GoDaddy',
387
- 'NiSource',
388
- 'Dollar Tree',
389
- 'Gartner',
390
- 'Teradyne',
391
- 'Genuine Parts Company',
392
- 'Halliburton',
393
- 'Tyson Foods',
394
- 'Amcor',
395
- 'Packaging Corporation of America',
396
- 'Lennox International',
397
- 'Ralph Lauren Corporation',
398
- 'F5, Inc.',
399
- 'Aptiv',
400
- 'Invitation Homes',
401
- 'Principal Financial Group',
402
- 'West Pharmaceutical Services',
403
- 'Pentair',
404
- 'Waters Corporation',
405
- 'Gen Digital',
406
- 'Coterra',
407
- 'Jacobs Solutions',
408
- 'Snap-on',
409
- 'McCormick & Company',
410
- 'Weyerhaeuser',
411
- 'Essex Property Trust',
412
- 'Southwest Airlines',
413
- 'Incyte',
414
- 'Deckers Brands',
415
- 'LyondellBasell',
416
- 'Evergy',
417
- 'Erie Indemnity',
418
- 'Dow Inc.',
419
- 'TKO Group Holdings',
420
- 'Alliant Energy',
421
- 'Mid-America Apartment Communities',
422
- 'Fortive',
423
- 'International Flavors & Fragrances',
424
- 'Expeditors International',
425
- 'Zebra Technologies',
426
- 'C.H. Robinson',
427
- 'Bunge Global',
428
- 'Centene Corporation',
429
- 'Masco',
430
- 'Best Buy',
431
- 'Clorox',
432
- 'Textron',
433
- 'Kimco Realty',
434
- 'Allegion',
435
- 'Hologic',
436
- 'Alexandria Real Estate Equities',
437
- "Domino's",
438
- 'Omnicom Group',
439
- 'Everest Group',
440
- 'CF Industries',
441
- 'Hormel Foods',
442
- 'Builders FirstSource',
443
- 'Cooper Companies (The)',
444
- 'Fox Corporation (Class B)',
445
- 'Wynn Resorts',
446
- 'Brown–Forman',
447
- 'Ball Corporation',
448
- 'Fox Corporation (Class A)',
449
- 'Healthpeak Properties',
450
- 'Avery Dennison',
451
- 'J.B. Hunt',
452
- 'Regency Centers',
453
- 'Solventum',
454
- 'Franklin Resources',
455
- 'Nordson Corporation',
456
- 'UDR, Inc.',
457
- 'Paycom',
458
- 'BXP, Inc.',
459
- 'IDEX Corporation',
460
- 'Host Hotels & Resorts',
461
- 'Universal Health Services',
462
- 'Stanley Black & Decker',
463
- 'Baxter International',
464
- 'Pool Corporation',
465
- 'Skyworks Solutions',
466
- 'Globe Life',
467
- 'News Corp (Class A)',
468
- 'J.M. Smucker Company (The)',
469
- 'Camden Property Trust',
470
- 'Viatris',
471
- 'Norwegian Cruise Line Holdings',
472
- 'Jack Henry & Associates',
473
- 'FactSet',
474
- 'Akamai Technologies',
475
- 'Dayforce',
476
- 'Huntington Ingalls Industries',
477
- 'Mosaic Company (The)',
478
- 'Generac',
479
- 'Assurant',
480
- 'Hasbro',
481
- 'Pinnacle West',
482
- 'A. O. Smith',
483
- 'Revvity',
484
- 'Invesco',
485
- 'Campbell Soup Company',
486
- 'Moderna',
487
- 'MGM Resorts',
488
- 'Albemarle Corporation',
489
- 'Align Technology',
490
- 'Molina Healthcare',
491
- 'Interpublic Group of Companies (The)',
492
- 'DaVita',
493
- 'AES Corporation',
494
- 'Match Group',
495
- 'Molson Coors Beverage Company',
496
- 'Conagra Brands',
497
- 'CarMax',
498
- 'EPAM Systems',
499
- 'Federal Realty Investment Trust',
500
- 'APA Corporation',
501
- 'Bio-Techne',
502
- 'Henry Schein',
503
- 'Mohawk Industries',
504
- 'LKQ Corporation',
505
- 'Lamb Weston',
506
- 'Charles River Laboratories',
507
- 'Eastman Chemical Company',
508
- 'MarketAxess',
509
- 'News Corp (Class B)',
510
- 'Caesars Entertainment',
511
- 'Enphase Energy']
512
-
513
- TICKERS ={'Nvidia': 'NVDA',
514
- 'Microsoft': 'MSFT',
515
- 'Apple Inc.': 'AAPL',
516
- 'Amazon': 'AMZN',
517
- 'Meta Platforms': 'META',
518
- 'Broadcom': 'AVGO',
519
- 'Alphabet Inc. (Class A)': 'GOOGL',
520
- 'Alphabet Inc. (Class C)': 'GOOG',
521
- 'Tesla, Inc.': 'TSLA',
522
- 'Berkshire Hathaway': 'BRK.B',
523
- 'Oracle Corporation': 'ORCL',
524
- 'JPMorgan Chase': 'JPM',
525
- 'Walmart': 'WMT',
526
- 'Lilly (Eli)': 'LLY',
527
- 'Visa Inc.': 'V',
528
- 'Mastercard': 'MA',
529
- 'Netflix': 'NFLX',
530
- 'ExxonMobil': 'XOM',
531
- 'Palantir Technologies': 'PLTR',
532
- 'Johnson & Johnson': 'JNJ',
533
- 'Costco': 'COST',
534
- 'Home Depot (The)': 'HD',
535
- 'AbbVie': 'ABBV',
536
- 'Bank of America': 'BAC',
537
- 'Procter & Gamble': 'PG',
538
- 'GE Aerospace': 'GE',
539
- 'Chevron Corporation': 'CVX',
540
- 'UnitedHealth Group': 'UNH',
541
- 'Coca-Cola Company (The)': 'KO',
542
- 'Wells Fargo': 'WFC',
543
- 'Cisco': 'CSCO',
544
- 'T-Mobile US': 'TMUS',
545
- 'Morgan Stanley': 'MS',
546
- 'Advanced Micro Devices': 'AMD',
547
- 'Philip Morris International': 'PM',
548
- 'IBM': 'IBM',
549
- 'Goldman Sachs': 'GS',
550
- 'American Express': 'AXP',
551
- 'Abbott Laboratories': 'ABT',
552
- 'Salesforce': 'CRM',
553
- 'Linde plc': 'LIN',
554
- 'Caterpillar Inc.': 'CAT',
555
- "McDonald's": 'MCD',
556
- 'RTX Corporation': 'RTX',
557
- 'AT&T': 'T',
558
- 'Merck & Co.': 'MRK',
559
- 'Uber': 'UBER',
560
- 'Walt Disney Company (The)': 'DIS',
561
- 'ServiceNow': 'NOW',
562
- 'PepsiCo': 'PEP',
563
- 'Intuit': 'INTU',
564
- 'Citigroup': 'C',
565
- 'Arista Networks': 'ANET',
566
- 'Verizon': 'VZ',
567
- 'Micron Technology': 'MU',
568
- 'Thermo Fisher Scientific': 'TMO',
569
- 'Qualcomm': 'QCOM',
570
- 'Booking Holdings': 'BKNG',
571
- 'BlackRock': 'BLK',
572
- 'Charles Schwab Corporation': 'SCHW',
573
- 'GE Vernova': 'GEV',
574
- 'Boeing': 'BA',
575
- 'Lam Research': 'LRCX',
576
- 'Texas Instruments': 'TXN',
577
- 'Intuitive Surgical': 'ISRG',
578
- 'S&P Global': 'SPGI',
579
- 'TJX Companies': 'TJX',
580
- 'Adobe Inc.': 'ADBE',
581
- 'Applied Materials': 'AMAT',
582
- 'Amgen': 'AMGN',
583
- 'Amphenol': 'APH',
584
- 'Accenture': 'ACN',
585
- "Lowe's": 'LOW',
586
- 'Blackstone Inc.': 'BX',
587
- 'NextEra Energy': 'NEE',
588
- 'Capital One': 'COF',
589
- 'Boston Scientific': 'BSX',
590
- 'Eaton Corporation': 'ETN',
591
- 'Stryker Corporation': 'SYK',
592
- 'Progressive Corporation': 'PGR',
593
- 'Gilead Sciences': 'GILD',
594
- 'Palo Alto Networks': 'PANW',
595
- 'Pfizer': 'PFE',
596
- 'Danaher Corporation': 'DHR',
597
- 'Intel': 'INTC',
598
- 'KLA Corporation': 'KLAC',
599
- 'KKR': 'KKR',
600
- 'Honeywell': 'HON',
601
- 'Union Pacific Corporation': 'UNP',
602
- 'Deere & Company': 'DE',
603
- 'CrowdStrike': 'CRWD',
604
- 'Medtronic': 'MDT',
605
- 'Analog Devices': 'ADI',
606
- 'Automatic Data Processing': 'ADP',
607
- 'Comcast': 'CMCSA',
608
- 'ConocoPhillips': 'COP',
609
- 'DoorDash': 'DASH',
610
- 'Welltower': 'WELL',
611
- 'Lockheed Martin': 'LMT',
612
- 'Altria': 'MO',
613
- 'Chubb Limited': 'CB',
614
- 'Prologis': 'PLD',
615
- 'Nike, Inc.': 'NKE',
616
- 'Constellation Energy': 'CEG',
617
- 'Cadence Design Systems': 'CDNS',
618
- 'Southern Company': 'SO',
619
- 'Vertex Pharmaceuticals': 'VRTX',
620
- 'Marsh McLennan': 'MMC',
621
- 'Intercontinental Exchange': 'ICE',
622
- 'Starbucks': 'SBUX',
623
- 'Parker Hannifin': 'PH',
624
- 'CVS Health': 'CVS',
625
- 'CME Group': 'CME',
626
- 'Duke Energy': 'DUK',
627
- 'HCA Healthcare': 'HCA',
628
- 'Newmont': 'NEM',
629
- 'Bristol Myers Squibb': 'BMY',
630
- 'Trane Technologies': 'TT',
631
- 'Synopsys': 'SNPS',
632
- 'American Tower': 'AMT',
633
- 'Royal Caribbean Group': 'RCL',
634
- 'Dell Technologies': 'DELL',
635
- "O'Reilly Auto Parts": 'ORLY',
636
- 'Waste Management': 'WM',
637
- "Moody's Corporation": 'MCO',
638
- 'General Dynamics': 'GD',
639
- 'Sherwin-Williams': 'SHW',
640
- 'McKesson Corporation': 'MCK',
641
- 'Coinbase Global': 'COIN',
642
- '3M': 'MMM',
643
- 'Mondelez International': 'MDLZ',
644
- 'Northrop Grumman': 'NOC',
645
- 'Apollo Global Management': 'APO',
646
- 'PNC Financial Services': 'PNC',
647
- 'Cintas': 'CTAS',
648
- 'Motorola Solutions': 'MSI',
649
- 'U.S. Bancorp': 'USB',
650
- 'Cigna': 'CI',
651
- 'Airbnb': 'ABNB',
652
- 'Equinix': 'EQIX',
653
- 'Arthur J. Gallagher & Co.': 'AJG',
654
- 'BNY Mellon': 'BK',
655
- 'Howmet Aerospace': 'HWM',
656
- 'Illinois Tool Works': 'ITW',
657
- 'Aon': 'AON',
658
- 'Ecolab': 'ECL',
659
- 'Emerson Electric': 'EMR',
660
- 'Williams Companies': 'WMB',
661
- 'Marriott International': 'MAR',
662
- 'TransDigm Group': 'TDG',
663
- 'Fiserv': 'FI',
664
- 'Vistra Corp.': 'VST',
665
- 'United Parcel Service': 'UPS',
666
- 'Republic Services': 'RSG',
667
- 'Johnson Controls': 'JCI',
668
- 'Elevance Health': 'ELV',
669
- 'AutoZone': 'AZO',
670
- 'Autodesk': 'ADSK',
671
- 'Corning Inc.': 'GLW',
672
- 'Colgate-Palmolive': 'CL',
673
- 'PayPal': 'PYPL',
674
- 'Zoetis': 'ZTS',
675
- 'Freeport-McMoRan': 'FCX',
676
- 'Fortinet': 'FTNT',
677
- 'Air Products': 'APD',
678
- 'TE Connectivity': 'TEL',
679
- 'Norfolk Southern Railway': 'NSC',
680
- 'EOG Resources': 'EOG',
681
- 'Hilton Worldwide': 'HLT',
682
- 'Regeneron Pharmaceuticals': 'REGN',
683
- 'Monster Beverage': 'MNST',
684
- 'Travelers Companies (The)': 'TRV',
685
- 'Workday, Inc.': 'WDAY',
686
- 'CSX Corporation': 'CSX',
687
- 'Kinder Morgan': 'KMI',
688
- 'Axon Enterprise': 'AXON',
689
- 'United Rentals': 'URI',
690
- 'Digital Realty': 'DLR',
691
- 'Truist Financial': 'TFC',
692
- 'Simon Property Group': 'SPG',
693
- 'Cummins': 'CMI',
694
- 'Quanta Services': 'PWR',
695
- 'Aflac': 'AFL',
696
- 'American Electric Power': 'AEP',
697
- 'Marathon Petroleum': 'MPC',
698
- 'NXP Semiconductors': 'NXPI',
699
- 'Cencora': 'COR',
700
- 'General Motors': 'GM',
701
- 'FedEx': 'FDX',
702
- 'Fastenal': 'FAST',
703
- 'Roper Technologies': 'ROP',
704
- 'Allstate': 'ALL',
705
- 'Sempra': 'SRE',
706
- 'Realty Income': 'O',
707
- 'Becton Dickinson': 'BDX',
708
- 'L3Harris': 'LHX',
709
- 'Chipotle Mexican Grill': 'CMG',
710
- 'Idexx Laboratories': 'IDXX',
711
- 'Phillips 66': 'PSX',
712
- 'MetLife': 'MET',
713
- 'Paccar': 'PCAR',
714
- 'Schlumberger': 'SLB',
715
- 'Carrier Global': 'CARR',
716
- 'Nasdaq, Inc.': 'NDAQ',
717
- 'Dominion Energy': 'D',
718
- 'Valero Energy': 'VLO',
719
- 'D. R. Horton': 'DHI',
720
- 'Public Storage': 'PSA',
721
- 'CBRE Group': 'CBRE',
722
- 'Datadog': 'DDOG',
723
- 'Warner Bros. Discovery': 'WBD',
724
- 'Corteva': 'CTVA',
725
- 'Ross Stores': 'ROST',
726
- 'W. W. Grainger': 'GWW',
727
- 'Seagate Technology': 'STX',
728
- 'Paychex': 'PAYX',
729
- 'Block, Inc.': 'XYZ',
730
- 'Baker Hughes': 'BKR',
731
- 'Take-Two Interactive': 'TTWO',
732
- 'Ford Motor Company': 'F',
733
- 'Ameriprise Financial': 'AMP',
734
- 'Garmin': 'GRMN',
735
- 'Occidental Petroleum': 'OXY',
736
- 'ONEOK': 'OKE',
737
- 'Copart': 'CPRT',
738
- 'Exelon': 'EXC',
739
- 'Monolithic Power Systems': 'MPWR',
740
- 'Edwards Lifesciences': 'EW',
741
- 'Ametek': 'AME',
742
- 'Kroger': 'KR',
743
- 'Electronic Arts': 'EA',
744
- 'MSCI': 'MSCI',
745
- 'Xcel Energy': 'XEL',
746
- 'American International Group': 'AIG',
747
- 'eBay': 'EBAY',
748
- 'Carnival': 'CCL',
749
- 'Crown Castle': 'CCI',
750
- 'Kimberly-Clark': 'KMB',
751
- 'Yum! Brands': 'YUM',
752
- 'Public Service Enterprise Group': 'PEG',
753
- 'Diamondback Energy': 'FANG',
754
- 'ResMed': 'RMD',
755
- 'Target Corporation': 'TGT',
756
- 'Entergy': 'ETR',
757
- 'Sysco': 'SYY',
758
- 'Vulcan Materials Company': 'VMC',
759
- 'Rockwell Automation': 'ROK',
760
- 'Delta Air Lines': 'DAL',
761
- 'Hershey Company (The)': 'HSY',
762
- 'Live Nation Entertainment': 'LYV',
763
- 'Martin Marietta Materials': 'MLM',
764
- 'Western Digital': 'WDC',
765
- 'CoStar Group': 'CSGP',
766
- 'Las Vegas Sands': 'LVS',
767
- 'Hartford (The)': 'HIG',
768
- 'Keurig Dr Pepper': 'KDP',
769
- 'Prudential Financial': 'PRU',
770
- 'Charter Communications': 'CHTR',
771
- 'Cardinal Health': 'CAH',
772
- 'Fair Isaac': 'FICO',
773
- 'WEC Energy Group': 'WEC',
774
- 'Targa Resources': 'TRGP',
775
- 'Agilent Technologies': 'A',
776
- 'Otis Worldwide': 'OTIS',
777
- 'Microchip Technology': 'MCHP',
778
- 'Consolidated Edison': 'ED',
779
- 'Raymond James Financial': 'RJF',
780
- 'Xylem Inc.': 'XYL',
781
- 'Verisk Analytics': 'VRSK',
782
- 'United Airlines Holdings': 'UAL',
783
- 'Fidelity National Information Services': 'FIS',
784
- 'GE HealthCare': 'GEHC',
785
- 'Vici Properties': 'VICI',
786
- 'Kenvue': 'KVUE',
787
- 'Arch Capital Group': 'ACGL',
788
- 'Willis Towers Watson': 'WTW',
789
- 'Hewlett Packard Enterprise': 'HPE',
790
- 'PG&E Corporation': 'PCG',
791
- 'DuPont': 'DD',
792
- 'Lennar': 'LEN',
793
- 'Cognizant': 'CTSH',
794
- 'Wabtec': 'WAB',
795
- 'State Street Corporation': 'STT',
796
- 'Ingersoll Rand': 'IR',
797
- 'Equifax': 'EFX',
798
- 'IQVIA': 'IQV',
799
- 'NRG Energy': 'NRG',
800
- 'M&T Bank': 'MTB',
801
- 'Tractor Supply': 'TSCO',
802
- 'Estée Lauder Companies (The)': 'EL',
803
- 'Kraft Heinz': 'KHC',
804
- 'Nucor': 'NUE',
805
- 'EQT Corporation': 'EQT',
806
- 'Fifth Third Bancorp': 'FITB',
807
- 'Ventas': 'VTR',
808
- 'Brown & Brown': 'BRO',
809
- 'Humana': 'HUM',
810
- 'Keysight Technologies': 'KEYS',
811
- 'Extra Space Storage': 'EXR',
812
- 'Old Dominion': 'ODFL',
813
- 'Iron Mountain': 'IRM',
814
- 'Archer Daniels Midland': 'ADM',
815
- 'Interactive Brokers Group': 'IBKR',
816
- 'Synchrony Financial': 'SYF',
817
- 'Broadridge Financial Solutions': 'BR',
818
- 'DTE Energy': 'DTE',
819
- 'W. R. Berkley Corporation': 'WRB',
820
- 'Expedia Group': 'EXPE',
821
- 'AvalonBay Communities': 'AVB',
822
- 'Rollins, Inc.': 'ROL',
823
- 'Supermicro': 'SMCI',
824
- 'General Mills': 'GIS',
825
- 'Kellanova': 'K',
826
- 'Ameren': 'AEE',
827
- 'Dexcom': 'DXCM',
828
- 'Teledyne Technologies': 'TDY',
829
- 'American Water Works': 'AWK',
830
- 'PPL Corporation': 'PPL',
831
- 'Verisign': 'VRSN',
832
- 'HP Inc.': 'HPQ',
833
- 'PulteGroup': 'PHM',
834
- 'Atmos Energy': 'ATO',
835
- 'Huntington Bancshares': 'HBAN',
836
- 'Veralto': 'VLTO',
837
- 'Mettler Toledo': 'MTD',
838
- 'Northern Trust': 'NTRS',
839
- 'Equity Residential': 'EQR',
840
- 'FirstEnergy': 'FE',
841
- 'CenterPoint Energy': 'CNP',
842
- 'NetApp': 'NTAP',
843
- 'Eversource Energy': 'ES',
844
- 'PPG Industries': 'PPG',
845
- 'PTC Inc.': 'PTC',
846
- 'Steris': 'STE',
847
- 'International Paper': 'IP',
848
- 'Cboe Global Markets': 'CBOE',
849
- 'Regions Financial Corporation': 'RF',
850
- 'Jabil': 'JBL',
851
- 'Williams-Sonoma': 'WSM',
852
- 'Leidos': 'LDOS',
853
- 'Tapestry, Inc.': 'TPR',
854
- 'Cincinnati Financial': 'CINF',
855
- 'Expand Energy': 'EXE',
856
- 'Constellation Brands': 'STZ',
857
- 'Dover Corporation': 'DOV',
858
- 'Hubbell Incorporated': 'HUBB',
859
- 'Ulta Beauty': 'ULTA',
860
- 'T. Rowe Price': 'TROW',
861
- 'Insulet Corporation': 'PODD',
862
- 'LabCorp': 'LH',
863
- 'Tyler Technologies': 'TYL',
864
- 'Citizens Financial Group': 'CFG',
865
- 'First Solar': 'FSLR',
866
- 'Smurfit WestRock': 'SW',
867
- 'Dollar General': 'DG',
868
- 'NVR, Inc.': 'NVR',
869
- 'Church & Dwight': 'CHD',
870
- 'Edison International': 'EIX',
871
- 'Darden Restaurants': 'DRI',
872
- 'The Trade Desk, Inc.': 'TTD',
873
- 'Devon Energy': 'DVN',
874
- 'CDW': 'CDW',
875
- 'SBA Communications': 'SBAC',
876
- 'Corpay': 'CPAY',
877
- 'CMS Energy': 'CMS',
878
- 'Global Payments': 'GPN',
879
- 'Biogen': 'BIIB',
880
- 'KeyCorp': 'KEY',
881
- 'ON Semiconductor': 'ON',
882
- 'Paramount Skydance Corp': 'PSKY',
883
- 'Steel Dynamics': 'STLD',
884
- 'Quest Diagnostics': 'DGX',
885
- 'Lululemon Athletica': 'LULU',
886
- 'Loews Corporation': 'L',
887
- 'Texas Pacific Land Corporation': 'TPL',
888
- 'Zimmer Biomet': 'ZBH',
889
- 'Trimble Inc.': 'TRMB',
890
- 'GoDaddy': 'GDDY',
891
- 'NiSource': 'NI',
892
- 'Dollar Tree': 'DLTR',
893
- 'Gartner': 'IT',
894
- 'Teradyne': 'TER',
895
- 'Genuine Parts Company': 'GPC',
896
- 'Halliburton': 'HAL',
897
- 'Tyson Foods': 'TSN',
898
- 'Amcor': 'AMCR',
899
- 'Packaging Corporation of America': 'PKG',
900
- 'Lennox International': 'LII',
901
- 'Ralph Lauren Corporation': 'RL',
902
- 'F5, Inc.': 'FFIV',
903
- 'Aptiv': 'APTV',
904
- 'Invitation Homes': 'INVH',
905
- 'Principal Financial Group': 'PFG',
906
- 'West Pharmaceutical Services': 'WST',
907
- 'Pentair': 'PNR',
908
- 'Waters Corporation': 'WAT',
909
- 'Gen Digital': 'GEN',
910
- 'Coterra': 'CTRA',
911
- 'Jacobs Solutions': 'J',
912
- 'Snap-on': 'SNA',
913
- 'McCormick & Company': 'MKC',
914
- 'Weyerhaeuser': 'WY',
915
- 'Essex Property Trust': 'ESS',
916
- 'Southwest Airlines': 'LUV',
917
- 'Incyte': 'INCY',
918
- 'Deckers Brands': 'DECK',
919
- 'LyondellBasell': 'LYB',
920
- 'Evergy': 'EVRG',
921
- 'Erie Indemnity': 'ERIE',
922
- 'Dow Inc.': 'DOW',
923
- 'TKO Group Holdings': 'TKO',
924
- 'Alliant Energy': 'LNT',
925
- 'Mid-America Apartment Communities': 'MAA',
926
- 'Fortive': 'FTV',
927
- 'International Flavors & Fragrances': 'IFF',
928
- 'Expeditors International': 'EXPD',
929
- 'Zebra Technologies': 'ZBRA',
930
- 'C.H. Robinson': 'CHRW',
931
- 'Bunge Global': 'BG',
932
- 'Centene Corporation': 'CNC',
933
- 'Masco': 'MAS',
934
- 'Best Buy': 'BBY',
935
- 'Clorox': 'CLX',
936
- 'Textron': 'TXT',
937
- 'Kimco Realty': 'KIM',
938
- 'Allegion': 'ALLE',
939
- 'Hologic': 'HOLX',
940
- 'Alexandria Real Estate Equities': 'ARE',
941
- "Domino's": 'DPZ',
942
- 'Omnicom Group': 'OMC',
943
- 'Everest Group': 'EG',
944
- 'CF Industries': 'CF',
945
- 'Hormel Foods': 'HRL',
946
- 'Builders FirstSource': 'BLDR',
947
- 'Cooper Companies (The)': 'COO',
948
- 'Fox Corporation (Class B)': 'FOX',
949
- 'Wynn Resorts': 'WYNN',
950
- 'Brown–Forman': 'BF.B',
951
- 'Ball Corporation': 'BALL',
952
- 'Fox Corporation (Class A)': 'FOXA',
953
- 'Healthpeak Properties': 'DOC',
954
- 'Avery Dennison': 'AVY',
955
- 'J.B. Hunt': 'JBHT',
956
- 'Regency Centers': 'REG',
957
- 'Solventum': 'SOLV',
958
- 'Franklin Resources': 'BEN',
959
- 'Nordson Corporation': 'NDSN',
960
- 'UDR, Inc.': 'UDR',
961
- 'Paycom': 'PAYC',
962
- 'BXP, Inc.': 'BXP',
963
- 'IDEX Corporation': 'IEX',
964
- 'Host Hotels & Resorts': 'HST',
965
- 'Universal Health Services': 'UHS',
966
- 'Stanley Black & Decker': 'SWK',
967
- 'Baxter International': 'BAX',
968
- 'Pool Corporation': 'POOL',
969
- 'Skyworks Solutions': 'SWKS',
970
- 'Globe Life': 'GL',
971
- 'News Corp (Class A)': 'NWSA',
972
- 'J.M. Smucker Company (The)': 'SJM',
973
- 'Camden Property Trust': 'CPT',
974
- 'Viatris': 'VTRS',
975
- 'Norwegian Cruise Line Holdings': 'NCLH',
976
- 'Jack Henry & Associates': 'JKHY',
977
- 'FactSet': 'FDS',
978
- 'Akamai Technologies': 'AKAM',
979
- 'Dayforce': 'DAY',
980
- 'Huntington Ingalls Industries': 'HII',
981
- 'Mosaic Company (The)': 'MOS',
982
- 'Generac': 'GNRC',
983
- 'Assurant': 'AIZ',
984
- 'Hasbro': 'HAS',
985
- 'Pinnacle West': 'PNW',
986
- 'A. O. Smith': 'AOS',
987
- 'Revvity': 'RVTY',
988
- 'Invesco': 'IVZ',
989
- 'Campbell Soup Company': 'CPB',
990
- 'Moderna': 'MRNA',
991
- 'MGM Resorts': 'MGM',
992
- 'Albemarle Corporation': 'ALB',
993
- 'Align Technology': 'ALGN',
994
- 'Molina Healthcare': 'MOH',
995
- 'Interpublic Group of Companies (The)': 'IPG',
996
- 'DaVita': 'DVA',
997
- 'AES Corporation': 'AES',
998
- 'Match Group': 'MTCH',
999
- 'Molson Coors Beverage Company': 'TAP',
1000
- 'Conagra Brands': 'CAG',
1001
- 'CarMax': 'KMX',
1002
- 'EPAM Systems': 'EPAM',
1003
- 'Federal Realty Investment Trust': 'FRT',
1004
- 'APA Corporation': 'APA',
1005
- 'Bio-Techne': 'TECH',
1006
- 'Henry Schein': 'HSIC',
1007
- 'Mohawk Industries': 'MHK',
1008
- 'LKQ Corporation': 'LKQ',
1009
- 'Lamb Weston': 'LW',
1010
- 'Charles River Laboratories': 'CRL',
1011
- 'Eastman Chemical Company': 'EMN',
1012
- 'MarketAxess': 'MKTX',
1013
- 'News Corp (Class B)': 'NWS',
1014
- 'Caesars Entertainment': 'CZR',
1015
- 'Enphase Energy': 'ENPH'}
1016
-
1017
  HF_DATASET = "SelmaNajih001/FT_MultiCompany"
1018
  MODEL_SENTIMENT = "SelmaNajih001/SentimentBasedOnPriceVariation"
1019
- #MODEL_PRICE_TESLA = "SelmaNajih001/PricePredictionForTesla"
1020
- #MODEL_PRICE_MICROSOFT = "SelmaNajih001/PricePredictionForMicrosoft"
 
 
 
 
 
 
 
 
1021
 
1022
  # --- PIPELINES ---
1023
  sentiment_pipeline = pipeline("sentiment-analysis", model=MODEL_SENTIMENT)
1024
- #price_pipeline_tesla = pipeline("text-classification", model=MODEL_PRICE_TESLA)
1025
- #price_pipeline_msft = pipeline("text-classification", model=MODEL_PRICE_MICROSOFT)
 
1026
 
1027
  # --- LOAD DATASET ---
1028
  df_multi = pd.DataFrame(load_dataset(HF_DATASET)["train"])
@@ -1033,12 +35,14 @@ df_multi.sort_values('date', inplace=True)
1033
  # --- SENTIMENT & PREDICTION ---
1034
  df_multi['Sentiment'] = ""
1035
  df_multi['Confidence'] = 0.0
1036
- #df_multi['Predicted'] = 0.0
 
 
1037
 
1038
  for i, row in df_multi.iterrows():
1039
  company = row['Company']
1040
 
1041
- # Sentiment for all companies
1042
  try:
1043
  res = sentiment_pipeline(row['Summary'])[0]
1044
  df_multi.at[i,'Sentiment'] = res['label'].upper().strip()
@@ -1047,21 +51,25 @@ for i, row in df_multi.iterrows():
1047
  df_multi.at[i,'Sentiment'] = 'ERROR'
1048
  df_multi.at[i,'Confidence'] = 0.0
1049
 
 
 
 
 
 
 
 
 
1050
 
1051
- ### Regression only for Tesla & Microsoft
1052
- # if company == "Tesla":
1053
- # try:
1054
- # val = price_pipeline_tesla(row['Riassunto'])[0]['score']
1055
- # df_multi.at[i,'Predicted'] = min(val, 1.0)
1056
- # except:
1057
- # df_multi.at[i,'Predicted'] = 0.0
1058
- # elif company == "Microsoft":
1059
- # try:
1060
- # val = price_pipeline_msft(row['Riassunto'])[0]['score']
1061
- # df_multi.at[i,'Predicted'] = min(val, 1.0)
1062
- # except:
1063
- # df_multi.at[i,'Predicted'] = 0.0
1064
-
1065
 
1066
  # --- FETCH STOCK PRICES ---
1067
  prices = {}
@@ -1069,150 +77,71 @@ for company, ticker in TICKERS.items():
1069
  start_date = df_multi[df_multi['Company']==company]['date'].min()
1070
  end_date = pd.Timestamp.today()
1071
  df_prices = yf.download(ticker, start=start_date, end=end_date)[['Close']].reset_index()
1072
- # Flatten the columns to a single level
1073
- df_prices.columns = ['_'.join(col).strip() if isinstance(col, tuple) else col for col in df_prices.columns]
1074
  df_prices['date_merge'] = pd.to_datetime(df_prices['Date_']).dt.normalize()
1075
  df_prices['PctChangeDaily'] = df_prices[f'Close_{ticker}'].pct_change().shift(-1)
1076
  prices[company] = df_prices
1077
 
1078
- # --- MERGE & CALCOLA STRATEGIE ---
1079
  dfs_final = {}
1080
-
1081
  for company in companies:
1082
  df_c = df_multi[df_multi['Company'] == company].copy()
1083
-
1084
- # Merge con i prezzi
1085
  if company in prices:
1086
  df_c = pd.merge(df_c, prices[company], on='date_merge', how='inner')
1087
-
1088
- # --- Aggiungi colonne di aggregazione prima di eliminare date ---
1089
  df_c['Day'] = df_c['date'].dt.date
1090
  df_c['Month'] = df_c['date'].dt.to_period('M').dt.to_timestamp()
1091
  df_c['Year'] = df_c['date'].dt.year
1092
 
1093
- # --- Strategy A: Sentiment ---
1094
- df_c['StrategyA_Daily'] = 0.0
1095
  df_c['StrategyA_Cumulative'] = 0.0
1096
  for i in range(1, len(df_c)):
1097
- score = df_c.loc[i, 'Confidence']
1098
- pct = df_c.loc[i, 'PctChangeDaily'] if pd.notnull(df_c.loc[i, 'PctChangeDaily']) else 0
1099
- if df_c.loc[i, 'Sentiment'] == "UP" and score > 0.8:
1100
- df_c.loc[i, 'StrategyA_Daily'] = df_c.loc[i, f'Close_{TICKERS[company]}'] * pct
1101
- elif df_c.loc[i, 'Sentiment'] == "DOWN" and score > 0.8:
1102
- df_c.loc[i, 'StrategyA_Daily'] = df_c.loc[i, f'Close_{TICKERS[company]}'] * pct * -1
1103
- df_c.loc[i, 'StrategyA_Cumulative'] = df_c.loc[i-1, 'StrategyA_Cumulative'] + df_c.loc[i, 'StrategyA_Daily']
1104
-
1105
- # Strategy B (opzionale, commentata)
1106
- # df_c['StrategyB_Daily'] = df_c['Predicted'] * df_c['PctChangeDaily'] * df_c[f'Close_{TICKERS[company]}']
1107
- # df_c['StrategyB_Cumulative'] = df_c['StrategyB_Daily'].cumsum()
1108
-
1109
- # Rimuovi solo colonne non necessarie, non quelle di aggregazione
1110
- df_c = df_c.drop(columns=["date", "date_merge"], errors="ignore")
1111
-
1112
- # Salva nel dizionario finale
1113
- dfs_final[company] = df_c
1114
-
1115
- # --- PLOT STRATEGIES ---
1116
- df_plot_A = pd.concat([df[['Date','StrategyA_Cumulative']].assign(Company=company) for company, df in dfs_final.items()], ignore_index=True)
1117
- #df_plot_B = pd.concat([df[['Data','StrategyB_Cumulative']].assign(Company=company) for company, df in dfs_final.items()], ignore_index=True)
1118
-
1119
- fig_strategy_A = px.line(df_plot_A, x='Date', y='StrategyA_Cumulative', color='Company',
1120
- title="Portfolio Evolution Following Strategy A (Sentiment)",
1121
- labels={'StrategyA_Cumulative':'Cumulative Value','Date':'Date'})
1122
- #fig_strategy_B = px.line(df_plot_B, x='Data', y='StrategyB_Cumulative', color='Company',
1123
- # title="Portfolio Evolution Following Strategy B (Regression)",
1124
- # labels={'StrategyB_Cumulative':'Cumulative Value','Data':'Date'})
1125
-
1126
- # --- FUNCTION FOR GRADIO ---
1127
- import pandas as pd
1128
- import plotly.graph_objects as go
1129
- import gradio as gr
1130
-
1131
- # --- PREPARA COLONNE AGGREGAZIONE ---
1132
- df_multi['Day'] = df_multi['date'].dt.date
1133
- df_multi['Month'] = df_multi['date'].dt.to_period('M').dt.to_timestamp() # Period -> datetime
1134
- df_multi['Year'] = df_multi['date'].dt.year
1135
-
1136
- # --- FUNZIONE PER GRADIO ---
1137
- def show_company_data(selected_companies, aggregation="Day"):
1138
- if not selected_companies:
1139
- return "Select at least one company to visualize.", None
1140
-
1141
- # --- CONCAT DATAFRAMES TOP 10 ---
1142
- tables = pd.concat(
1143
- [dfs_final[c].head(10).assign(Company=c) for c in selected_companies if c in dfs_final],
1144
- ignore_index=True
1145
- )
1146
-
1147
- # --- CREA FIGURA ---
1148
- fig = go.Figure()
1149
- agg_col = {"Day": "Day", "Month": "Month", "Year": "Year"}.get(aggregation, "Day")
1150
-
1151
- for c in selected_companies:
1152
- if c not in dfs_final:
1153
- continue
1154
- df_c = dfs_final[c]
1155
-
1156
- # --- AGGREGAZIONE ---
1157
- df_grouped = df_c.groupby(agg_col).agg({
1158
- 'StrategyA_Cumulative': 'last',
1159
- **({f'Close_{TICKERS[c]}': 'last'} if f'Close_{TICKERS[c]}' in df_c.columns else {})
1160
- }).reset_index()
1161
-
1162
- # --- CONVERSIONE DATETIME PER PLOTLY ---
1163
- if agg_col in ['Day', 'Month'] and not pd.api.types.is_datetime64_any_dtype(df_grouped[agg_col]):
1164
- df_grouped[agg_col] = pd.to_datetime(df_grouped[agg_col])
1165
-
1166
- # --- LINEA STRATEGY A ---
1167
- fig.add_trace(go.Scatter(
1168
- x=df_grouped[agg_col],
1169
- y=df_grouped['StrategyA_Cumulative'],
1170
- mode='lines',
1171
- name=f"{c} Strategy A",
1172
- line=dict(width=2)
1173
- ))
1174
-
1175
- # --- LINEA PREZZO SECONDARY Y ---
1176
- if f'Close_{TICKERS[c]}' in df_grouped.columns:
1177
- fig.add_trace(go.Scatter(
1178
- x=df_grouped[agg_col],
1179
- y=df_grouped[f'Close_{TICKERS[c]}'],
1180
- mode='lines',
1181
- name=f"{c} Price",
1182
- yaxis="y2",
1183
- line=dict(width=2, dash='dot')
1184
- ))
1185
-
1186
- # --- LAYOUT FIGURA ---
1187
- fig.update_layout(
1188
- title="Portfolio Evolution vs Stock Price",
1189
- xaxis_title=aggregation,
1190
- yaxis_title="Strategy A Cumulative Value",
1191
- yaxis2=dict(
1192
- title="Stock Price",
1193
- overlaying="y",
1194
- side="right"
1195
- ),
1196
- legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
1197
- template="plotly_dark",
1198
- hovermode="x unified"
1199
- )
1200
 
1201
- return tables, fig
 
 
 
1202
 
1203
- # --- GRADIO INTERFACE ---
1204
- demo = gr.Interface(
1205
- fn=show_company_data,
1206
- inputs=[
1207
- gr.Dropdown(choices=companies, value=["Microsoft", "Nvidia"], label="Select Companies", multiselect=True),
1208
- gr.Radio(choices=["Day", "Month", "Year"], value="Day", label="Aggregation Level")
1209
- ],
1210
- outputs=[
1211
- gr.Dataframe(label="Top 10 Rows per Company", type="pandas"),
1212
- gr.Plot(label="Strategy A: Sentiment"),
1213
- ],
1214
- title="Interactive Portfolio Evolution",
1215
- description="Select one or more companies to visualize portfolio evolution based on the sentiment of the news."
1216
  )
1217
 
1218
- demo.launch()
 
 
1
  import pandas as pd
2
+ import yfinance as yf
3
  from datasets import load_dataset
4
  from transformers import pipeline
5
  import plotly.express as px
6
+ import plotly.graph_objects as go
7
  import gradio as gr
8
 
9
+ # --- PARAMETRI ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  HF_DATASET = "SelmaNajih001/FT_MultiCompany"
11
  MODEL_SENTIMENT = "SelmaNajih001/SentimentBasedOnPriceVariation"
12
+ MODEL_PRICE_TESLA = "SelmaNajih001/PricePredictionForTesla"
13
+ MODEL_PRICE_MICROSOFT = "SelmaNajih001/PricePredictionForMicrosoft"
14
+ MODEL_FINBERT = "ProsusAI/finbert"
15
+
16
+ TICKERS = {
17
+ "Tesla": "TSLA",
18
+ "Microsoft": "MSFT",
19
+ #"Nvidia": "NVDA"
20
+ }
21
+ companies = list(TICKERS.keys())
22
 
23
  # --- PIPELINES ---
24
  sentiment_pipeline = pipeline("sentiment-analysis", model=MODEL_SENTIMENT)
25
+ price_pipeline_tesla = pipeline("text-classification", model=MODEL_PRICE_TESLA)
26
+ price_pipeline_msft = pipeline("text-classification", model=MODEL_PRICE_MICROSOFT)
27
+ finbert_pipeline = pipeline("sentiment-analysis", model=MODEL_FINBERT)
28
 
29
  # --- LOAD DATASET ---
30
  df_multi = pd.DataFrame(load_dataset(HF_DATASET)["train"])
 
35
  # --- SENTIMENT & PREDICTION ---
36
  df_multi['Sentiment'] = ""
37
  df_multi['Confidence'] = 0.0
38
+ df_multi['Predicted'] = 0.0
39
+ df_multi['FinBERT_Sentiment'] = ""
40
+ df_multi['FinBERT_Confidence'] = 0.0
41
 
42
  for i, row in df_multi.iterrows():
43
  company = row['Company']
44
 
45
+ # --- Sentiment con modello custom ---
46
  try:
47
  res = sentiment_pipeline(row['Summary'])[0]
48
  df_multi.at[i,'Sentiment'] = res['label'].upper().strip()
 
51
  df_multi.at[i,'Sentiment'] = 'ERROR'
52
  df_multi.at[i,'Confidence'] = 0.0
53
 
54
+ # --- FinBERT ---
55
+ try:
56
+ res_f = finbert_pipeline(row['Summary'])[0]
57
+ df_multi.at[i,'FinBERT_Sentiment'] = res_f['label'].upper().strip()
58
+ df_multi.at[i,'FinBERT_Confidence'] = res_f['score']
59
+ except:
60
+ df_multi.at[i,'FinBERT_Sentiment'] = 'ERROR'
61
+ df_multi.at[i,'FinBERT_Confidence'] = 0.0
62
 
63
+ # --- Regression solo per Tesla & Microsoft ---
64
+ try:
65
+ if company == "Tesla":
66
+ val = price_pipeline_tesla(row['Summary'])[0]['score']
67
+ df_multi.at[i,'Predicted'] = min(val, 1.0)
68
+ elif company == "Microsoft":
69
+ val = price_pipeline_msft(row['Summary'])[0]['score']
70
+ df_multi.at[i,'Predicted'] = min(val, 1.0)
71
+ except:
72
+ df_multi.at[i,'Predicted'] = 0.0
 
 
 
 
73
 
74
  # --- FETCH STOCK PRICES ---
75
  prices = {}
 
77
  start_date = df_multi[df_multi['Company']==company]['date'].min()
78
  end_date = pd.Timestamp.today()
79
  df_prices = yf.download(ticker, start=start_date, end=end_date)[['Close']].reset_index()
80
+ df_prices.columns = ['Date_', f'Close_{ticker}']
 
81
  df_prices['date_merge'] = pd.to_datetime(df_prices['Date_']).dt.normalize()
82
  df_prices['PctChangeDaily'] = df_prices[f'Close_{ticker}'].pct_change().shift(-1)
83
  prices[company] = df_prices
84
 
85
+ # --- MERGE & STRATEGIE ---
86
  dfs_final = {}
 
87
  for company in companies:
88
  df_c = df_multi[df_multi['Company'] == company].copy()
89
+
 
90
  if company in prices:
91
  df_c = pd.merge(df_c, prices[company], on='date_merge', how='inner')
92
+
 
93
  df_c['Day'] = df_c['date'].dt.date
94
  df_c['Month'] = df_c['date'].dt.to_period('M').dt.to_timestamp()
95
  df_c['Year'] = df_c['date'].dt.year
96
 
97
+ # --- Strategy A: Sentiment custom ---
 
98
  df_c['StrategyA_Cumulative'] = 0.0
99
  for i in range(1, len(df_c)):
100
+ pct = df_c.loc[i, 'PctChangeDaily'] if pd.notnull(df_c.loc[i,'PctChangeDaily']) else 0
101
+ if df_c.loc[i, 'Sentiment'] == "UP" and df_c.loc[i,'Confidence'] > 0.8:
102
+ df_c.loc[i,'StrategyA_Cumulative'] = df_c.loc[i-1,'StrategyA_Cumulative'] + pct
103
+ elif df_c.loc[i, 'Sentiment'] == "DOWN" and df_c.loc[i,'Confidence'] > 0.8:
104
+ df_c.loc[i,'StrategyA_Cumulative'] = df_c.loc[i-1,'StrategyA_Cumulative'] - pct
105
+ else:
106
+ df_c.loc[i,'StrategyA_Cumulative'] = df_c.loc[i-1,'StrategyA_Cumulative']
107
+
108
+ # --- Strategy B: Regression ---
109
+ df_c['StrategyB_Cumulative'] = (df_c['Predicted'] * df_c['PctChangeDaily']).cumsum()
110
+
111
+ # --- Strategy C: FinBERT ---
112
+ df_c['StrategyC_Cumulative'] = 0.0
113
+ for i in range(1, len(df_c)):
114
+ pct = df_c.loc[i, 'PctChangeDaily'] if pd.notnull(df_c.loc[i,'PctChangeDaily']) else 0
115
+ if df_c.loc[i, 'FinBERT_Sentiment'] == "POSITIVE" and df_c.loc[i,'FinBERT_Confidence'] > 0.8:
116
+ df_c.loc[i,'StrategyC_Cumulative'] = df_c.loc[i-1,'StrategyC_Cumulative'] + pct
117
+ elif df_c.loc[i, 'FinBERT_Sentiment'] == "NEGATIVE" and df_c.loc[i,'FinBERT_Confidence'] > 0.8:
118
+ df_c.loc[i,'StrategyC_Cumulative'] = df_c.loc[i-1,'StrategyC_Cumulative'] - pct
119
+ else:
120
+ df_c.loc[i,'StrategyC_Cumulative'] = df_c.loc[i-1,'StrategyC_Cumulative']
121
+
122
+ dfs_final[company] = df_c.drop(columns=["date", "date_merge"], errors="ignore")
123
+
124
+ # --- PLOT: CONFRONTO STRATEGIE ---
125
+ df_plot = pd.concat([
126
+ df[['Date','StrategyA_Cumulative','StrategyB_Cumulative','StrategyC_Cumulative']].assign(Company=company)
127
+ for company, df in dfs_final.items()
128
+ ], ignore_index=True)
129
+
130
+ fig_strategies = px.line(
131
+ df_plot, x='Date', y=['StrategyA_Cumulative','StrategyB_Cumulative','StrategyC_Cumulative'],
132
+ color='Company',
133
+ title="Confronto Strategie (Custom Sentiment vs Regression vs FinBERT)"
134
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
+ # --- PLOT: PREZZI ---
137
+ df_prices_plot = pd.concat([
138
+ df[[f'Close_{TICKERS[company]}','Date']].assign(Company=company) for company, df in dfs_final.items()
139
+ ], ignore_index=True)
140
 
141
+ fig_prices = px.line(
142
+ df_prices_plot, x='Date', y=df_prices_plot.columns[0], color='Company',
143
+ title="Andamento Prezzi"
 
 
 
 
 
 
 
 
 
 
144
  )
145
 
146
+ fig_strategies.show()
147
+ fig_prices.show()