File size: 26,191 Bytes
0fe92d3
 
 
 
 
 
 
 
 
 
 
 
 
 
7ca1cc5
 
0fe92d3
 
 
 
 
 
 
 
 
 
332e7e6
1b3843c
4fbc81d
1b3843c
 
 
 
7ca1cc5
0fe92d3
7ca1cc5
 
0fe92d3
dce13dd
0fe92d3
 
 
 
 
 
 
 
 
 
 
151fa57
0fe92d3
 
151fa57
0fe92d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151fa57
0fe92d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151fa57
0fe92d3
 
151fa57
0fe92d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9591812
0fe92d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9591812
0fe92d3
 
 
 
 
 
 
 
 
 
 
 
911f184
0fe92d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pandas_datareader.data as web
import datetime as dt
import yfinance as yf
from sklearn.preprocessing import MinMaxScaler
from keras.models import load_model
import streamlit as st
import plotly.graph_objects as go
import base64
import plotly.express as px
from datetime import datetime

st.set_page_config(page_title='Stocks Analysis',  layout='wide', page_icon=':rocket:')

st.sidebar.title("Stock Option")
sidebar_css = """
<style>
    div[data-testid="stSidebar"] > div:first-child {
        width: 350px;  # Adjust the width as needed
        background-color: #FF6969;
    }
</style>
"""

option = st.sidebar.selectbox(
   "Choose desired company",
   ('MMM,3M', 'AOS,A. O. Smith', 'ABT,Abbott', 'ABBV,AbbVie', 'ACN,Accenture', 'ADBE,Adobe Inc.', 'AMD,Advanced Micro Devices', 'AES,AES Corporation', 'AFL,Aflac', 'A,Agilent Technologies', 'APD,Air Products and Chemicals', 'ABNB,Airbnb', 'AKAM,Akamai', 'ALB,Albemarle Corporation', 'ARE,Alexandria Real Estate Equities', 'ALGN,Align Technology', 'ALLE,Allegion', 'LNT,Alliant Energy', 'ALL,Allstate', 'GOOGL,Alphabet Inc. (Class A)', 'GOOG,Alphabet Inc. (Class C)', 'MO,Altria', 'AMZN,Amazon', 'AMCR,Amcor', 'AEE,Ameren', 'AAL,American Airlines Group', 'AEP,American Electric Power', 'AXP,American Express', 'AIG,American International Group', 'AMT,American Tower', 'AWK,American Water Works', 'AMP,Ameriprise Financial', 'AME,Ametek', 'AMGN,Amgen', 'APH,Amphenol', 'ADI,Analog Devices', 'ANSS,Ansys', 'AON,Aon', 'APA,APA Corporation', 'AAPL,Apple Inc.', 'AMAT,Applied Materials', 'APTV,Aptiv', 'ACGL,Arch Capital Group', 'ADM,Archer-Daniels-Midland', 'ANET,Arista Networks', 'AJG,Arthur J. Gallagher & Co.', 'AIZ,Assurant', 'T,AT&T', 'ATO,Atmos Energy', 'ADSK,Autodesk', 'ADP,Automatic Data Processing', 'AZO,AutoZone', 'AVB,AvalonBay Communities', 'AVY,Avery Dennison', 'AXON,Axon Enterprise', 'BKR,Baker Hughes', 'BALL,Ball Corporation', 'BAC,Bank of America', 'BK,Bank of New York Mellon', 'BBWI,Bath & Body Works, Inc.', 'BAX,Baxter International', 'BDX,Becton Dickinson', 'BRK.B,Berkshire Hathaway', 'BBY,Best Buy', 'BIO,Bio-Rad', 'TECH,Bio-Techne', 'BIIB,Biogen', 'BLK,BlackRock', 'BX,Blackstone', 'BA,Boeing', 'BKNG,Booking Holdings', 'BWA,BorgWarner', 'BXP,Boston Properties', 'BSX,Boston Scientific', 'BMY,Bristol Myers Squibb', 'AVGO,Broadcom Inc.', 'BR,Broadridge Financial Solutions', 'BRO,Brown & Brown', 'BF.B,Brown–Forman', 'BLDR,Builders FirstSource', 'BG,Bunge Global SA', 'CDNS,Cadence Design Systems', 'CZR,Caesars Entertainment', 'CPT,Camden Property Trust', 'CPB,Campbell Soup Company', 'COF,Capital One', 'CAH,Cardinal Health', 'KMX,CarMax', 'CCL,Carnival', 'CARR,Carrier Global', 'CTLT,Catalent', 'CAT,Caterpillar Inc.', 'CBOE,Cboe Global Markets', 'CBRE,CBRE Group', 'CDW,CDW', 'CE,Celanese', 'COR,Cencora', 'CNC,Centene Corporation', 'CNP,CenterPoint Energy', 'CF,CF Industries', 'CHRW,CH Robinson', 'CRL,Charles River Laboratories', 'SCHW,Charles Schwab Corporation', 'CHTR,Charter Communications', 'CVX,Chevron Corporation', 'CMG,Chipotle Mexican Grill', 'CB,Chubb Limited', 'CHD,Church & Dwight', 'CI,Cigna', 'CINF,Cincinnati Financial', 'CTAS,Cintas', 'CSCO,Cisco', 'C,Citigroup', 'CFG,Citizens Financial Group', 'CLX,Clorox', 'CME,CME Group', 'CMS,CMS Energy', 'KO,Coca-Cola Company (The)', 'CTSH,Cognizant', 'CL,Colgate-Palmolive', 'CMCSA,Comcast', 'CMA,Comerica', 'CAG,Conagra Brands', 'COP,ConocoPhillips', 'ED,Consolidated Edison', 'STZ,Constellation Brands', 'CEG,Constellation Energy', 'COO,CooperCompanies', 'CPRT,Copart', 'GLW,Corning Inc.', 'CPAY,Corpay', 'CTVA,Corteva', 'CSGP,CoStar Group', 'COST,Costco', 'CTRA,Coterra', 'CCI,Crown Castle', 'CSX,CSX', 'CMI,Cummins', 'CVS,CVS Health', 'DHR,Danaher Corporation', 'DRI,Darden Restaurants', 'DVA,DaVita Inc.', 'DAY,Dayforce', 'DECK,Deckers Brands', 'DE,John Deere', 'DAL,Delta Air Lines', 'DVN,Devon Energy', 'DXCM,Dexcom', 'FANG,Diamondback Energy', 'DLR,Digital Realty', 'DFS,Discover Financial', 'DG,Dollar General', 'DLTR,Dollar Tree', 'D,Dominion Energy', "DPZ,Domino's", 'DOV,Dover Corporation', 'DOW,Dow Inc.', 'DHI,DR Horton', 'DTE,DTE Energy', 'DUK,Duke Energy', 'DD,DuPont', 'EMN,Eastman Chemical Company', 'ETN,Eaton Corporation', 'EBAY,eBay', 'ECL,Ecolab', 'EIX,Edison International', 'EW,Edwards Lifesciences', 'EA,Electronic Arts', 'ELV,Elevance Health', 'LLY,Eli Lilly and Company', 'EMR,Emerson Electric', 'ENPH,Enphase', 'ETR,Entergy', 'EOG,EOG Resources', 'EPAM,EPAM Systems', 'EQT,EQT', 'EFX,Equifax', 'EQIX,Equinix', 'EQR,Equity Residential', 'ESS,Essex Property Trust', 'EL,Estée Lauder Companies (The)', 'ETSY,Etsy', 'EG,Everest Re', 'EVRG,Evergy', 'ES,Eversource', 'EXC,Exelon', 'EXPE,Expedia Group', 'EXPD,Expeditors International', 'EXR,Extra Space Storage', 'XOM,ExxonMobil', 'FFIV,F5, Inc.', 'FDS,FactSet', 'FICO,Fair Isaac', 'FAST,Fastenal', 'FRT,Federal Realty', 'FDX,FedEx', 'FIS,Fidelity National Information Services', 'FITB,Fifth Third Bank', 'FSLR,First Solar', 'FE,FirstEnergy', 'FI,Fiserv', 'FMC,FMC Corporation', 'F,Ford Motor Company', 'FTNT,Fortinet', 'FTV,Fortive', 'FOXA,Fox Corporation (Class A)', 'FOX,Fox Corporation (Class B)', 'BEN,Franklin Templeton', 'FCX,Freeport-McMoRan', 'GRMN,Garmin', 'IT,Gartner', 'GE,GE Aerospace', 'GEHC,GE HealthCare', 'GEV,GE Vernova', 'GEN,Gen Digital', 'GNRC,Generac', 'GD,General Dynamics', 'GIS,General Mills', 'GM,General Motors', 'GPC,Genuine Parts Company', 'GILD,Gilead Sciences', 'GPN,Global Payments', 'GL,Globe Life', 'GS,Goldman Sachs', 'HAL,Halliburton', 'HIG,Hartford (The)', 'HAS,Hasbro', 'HCA,HCA Healthcare', 'DOC,Healthpeak', 'HSIC,Henry Schein', "HSY,Hershey's", 'HES,Hess Corporation', 'HPE,Hewlett Packard Enterprise', 'HLT,Hilton Worldwide', 'HOLX,Hologic', 'HD,Home Depot (The)', 'HON,Honeywell', 'HRL,Hormel Foods', 'HST,Host Hotels & Resorts', 'HWM,Howmet Aerospace', 'HPQ,HP Inc.', 'HUBB,Hubbell Incorporated', 'HUM,Humana', 'HBAN,Huntington Bancshares', 'HII,Huntington Ingalls Industries', 'IBM,IBM', 'IEX,IDEX Corporation', 'IDXX,Idexx Laboratories', 'ITW,Illinois Tool Works', 'ILMN,Illumina', 'INCY,Incyte', 'IR,Ingersoll Rand', 'PODD,Insulet', 'INTC,Intel', 'ICE,Intercontinental Exchange', 'IFF,International Flavors & Fragrances', 'IP,International Paper', 'IPG,Interpublic Group of Companies (The)', 'INTU,Intuit', 'ISRG,Intuitive Surgical', 'IVZ,Invesco', 'INVH,Invitation Homes', 'IQV,IQVIA', 'IRM,Iron Mountain', 'JBHT,J.B. Hunt', 'JBL,Jabil', 'JKHY,Jack Henry & Associates', 'J,Jacobs Solutions', 'JNJ,Johnson & Johnson', 'JCI,Johnson Controls', 'JPM,JPMorgan Chase', 'JNPR,Juniper Networks', 'K,Kellanova', 'KVUE,Kenvue', 'KDP,Keurig Dr Pepper', 'KEY,KeyCorp', 'KEYS,Keysight', 'KMB,Kimberly-Clark', 'KIM,Kimco Realty', 'KMI,Kinder Morgan', 'KLAC,KLA Corporation', 'KHC,Kraft Heinz', 'KR,Kroger', 'LHX,L3Harris', 'LH,LabCorp', 'LRCX,Lam Research', 'LW,Lamb Weston', 'LVS,Las Vegas Sands', 'LDOS,Leidos', 'LEN,Lennar', 'LIN,Linde plc', 'LYV,Live Nation Entertainment', 'LKQ,LKQ Corporation', 'LMT,Lockheed Martin', 'L,Loews Corporation', "LOW,Lowe's", 'LULU,Lululemon Athletica', 'LYB,LyondellBasell', 'MTB,M&T Bank', 'MRO,Marathon Oil', 'MPC,Marathon Petroleum', 'MKTX,MarketAxess', 'MAR,Marriott International', 'MMC,Marsh McLennan', 'MLM,Martin Marietta Materials', 'MAS,Masco', 'MA,Mastercard', 'MTCH,Match Group', 'MKC,McCormick & Company', "MCD,McDonald's", 'MCK,McKesson', 'MDT,Medtronic', 'MRK,Merck & Co.', 'META,Meta Platforms', 'MET,MetLife', 'MTD,Mettler Toledo', 'MGM,MGM Resorts', 'MCHP,Microchip Technology', 'MU,Micron Technology', 'MSFT,Microsoft', 'MAA,Mid-America Apartment Communities', 'MRNA,Moderna', 'MHK,Mohawk Industries', 'MOH,Molina Healthcare', 'TAP,Molson Coors Beverage Company', 'MDLZ,Mondelez International', 'MPWR,Monolithic Power Systems', 'MNST,Monster Beverage', "MCO,Moody's Corporation", 'MS,Morgan Stanley', 'MOS,Mosaic Company (The)', 'MSI,Motorola Solutions', 'MSCI,MSCI', 'NDAQ,Nasdaq, Inc.', 'NTAP,NetApp', 'NFLX,Netflix', 'NEM,Newmont', 'NWSA,News Corp (Class A)', 'NWS,News Corp (Class B)', 'NEE,NextEra Energy', 'NKE,Nike, Inc.', 'NI,NiSource', 'NDSN,Nordson Corporation', 'NSC,Norfolk Southern Railway', 'NTRS,Northern Trust', 'NOC,Northrop Grumman', 'NCLH,Norwegian Cruise Line Holdings', 'NRG,NRG Energy', 'NUE,Nucor', 'NVDA,Nvidia', 'NVR,NVR, Inc.', 'NXPI,NXP Semiconductors', "ORLY,O'Reilly Auto Parts", 'OXY,Occidental Petroleum', 'ODFL,Old Dominion', 'OMC,Omnicom Group', 'ON,ON Semiconductor', 'OKE,ONEOK', 'ORCL,Oracle Corporation', 'OTIS,Otis Worldwide', 'PCAR,Paccar', 'PKG,Packaging Corporation of America', 'PANW,Palo Alto Networks', 'PARA,Paramount Global', 'PH,Parker Hannifin', 'PAYX,Paychex', 'PAYC,Paycom', 'PYPL,PayPal', 'PNR,Pentair', 'PEP,PepsiCo', 'PFE,Pfizer', 'PCG,PG&E Corporation', 'PM,Philip Morris International', 'PSX,Phillips 66', 'PNW,Pinnacle West', 'PNC,PNC Financial Services', 'POOL,Pool Corporation', 'PPG,PPG Industries', 'PPL,PPL Corporation', 'PFG,Principal Financial Group', 'PG,Procter & Gamble', 'PGR,Progressive Corporation', 'PLD,Prologis', 'PRU,Prudential Financial', 'PEG,Public Service Enterprise Group', 'PTC,PTC', 'PSA,Public Storage', 'PHM,PulteGroup', 'QRVO,Qorvo', 'PWR,Quanta Services', 'QCOM,Qualcomm', 'DGX,Quest Diagnostics', 'RL,Ralph Lauren Corporation', 'RJF,Raymond James', 'RTX,RTX Corporation', 'O,Realty Income', 'REG,Regency Centers', 'REGN,Regeneron', 'RF,Regions Financial Corporation', 'RSG,Republic Services', 'RMD,ResMed', 'RVTY,Revvity', 'RHI,Robert Half', 'ROK,Rockwell Automation', 'ROL,Rollins, Inc.', 'ROP,Roper Technologies', 'ROST,Ross Stores', 'RCL,Royal Caribbean Group', 'SPGI,S&P Global', 'CRM,Salesforce', 'SBAC,SBA Communications', 'SLB,Schlumberger', 'STX,Seagate Technology', 'SRE,Sempra Energy', 'NOW,ServiceNow', 'SHW,Sherwin-Williams', 'SPG,Simon Property Group', 'SWKS,Skyworks Solutions', 'SJM,J.M. Smucker Company (The)', 'SNA,Snap-on', 'SOLV,Solventum', 'SO,Southern Company', 'LUV,Southwest Airlines', 'SWK,Stanley Black & Decker', 'SBUX,Starbucks', 'STT,State Street Corporation', 'STLD,Steel Dynamics', 'STE,Steris', 'SYK,Stryker Corporation', 'SMCI,Supermicro', 'SYF,Synchrony Financial', 'SNPS,Synopsys', 'SYY,Sysco', 'TMUS,T-Mobile US', 'TROW,T. Rowe Price', 'TTWO,Take-Two Interactive', 'TPR,Tapestry, Inc.', 'TRGP,Targa Resources', 'TGT,Target Corporation', 'TEL,TE Connectivity', 'TDY,Teledyne Technologies', 'TFX,Teleflex', 'TER,Teradyne', 'TSLA,Tesla, Inc.', 'TXN,Texas Instruments', 'TXT,Textron', 'TMO,Thermo Fisher Scientific', 'TJX,TJX Companies', 'TSCO,Tractor Supply', 'TT,Trane Technologies', 'TDG,TransDigm Group', 'TRV,Travelers Companies (The)', 'TRMB,Trimble Inc.', 'TFC,Truist', 'TYL,Tyler Technologies', 'TSN,Tyson Foods', 'USB,U.S. Bank', 'UBER,Uber', 'UDR,UDR, Inc.', 'ULTA,Ulta Beauty', 'UNP,Union Pacific Corporation', 'UAL,United Airlines Holdings', 'UPS,United Parcel Service', 'URI,United Rentals', 'UNH,UnitedHealth Group', 'UHS,Universal Health Services', 'VLO,Valero Energy', 'VTR,Ventas', 'VLTO,Veralto', 'VRSN,Verisign', 'VRSK,Verisk', 'VZ,Verizon', 'VRTX,Vertex Pharmaceuticals', 'VTRS,Viatris', 'VICI,Vici Properties', 'V,Visa Inc.', 'VST,Vistra', 'VMC,Vulcan Materials Company', 'WRB,W. R. Berkley Corporation', 'GWW,W. W. Grainger', 'WAB,Wabtec', 'WBA,Walgreens Boots Alliance', 'WMT,Walmart', 'DIS,Walt Disney Company (The)', 'WBD,Warner Bros. Discovery', 'WM,Waste Management', 'WAT,Waters Corporation', 'WEC,WEC Energy Group', 'WFC,Wells Fargo', 'WELL,Welltower', 'WST,West Pharmaceutical Services', 'WDC,Western Digital', 'WRK,WestRock', 'WY,Weyerhaeuser', 'WMB,Williams Companies', 'WTW,Willis Towers Watson', 'WYNN,Wynn Resorts', 'XEL,Xcel Energy', 'XYL,Xylem Inc.', 'YUM,Yum! Brands', 'ZBRA,Zebra Technologies', 'ZBH,Zimmer Biomet', 'ZTS,Zoetis'),
   index=None,
   placeholder="Enter ticker...",
)

user_input = st.sidebar.text_input("Select a Stock", "TSLA")

start_date = st.sidebar.date_input("Select start date:", datetime(2024, 1, 1))
end_date = st.sidebar.date_input("Select end date:", datetime(2024, 3, 1))

st.title("IN-Depth Analysis")

try:
    stock_info = yf.Ticker(user_input).info

    if 'longName' in stock_info:
        stock_name = stock_info['longName']
    else:
        stock_name = user_input

    news_data = yf.Ticker(user_input).news

    title = f"<h1 style='color: while; font-size: 25px; text-align: center; '>{stock_name}'s Fundamental Analysis</h1>"
    st.markdown(title, unsafe_allow_html=True)

    with st.expander("Expand"):
        if 'longName' in stock_info:
            company_name = stock_info['longName']
            st.write(f"Company Name: {company_name}")
        else:
            st.write("Company name information not available for this stock.")

        if 'industry' in stock_info:
            Industry = stock_info['industry']
            st.write(f"Industry: {Industry}")
        else:
            st.write("Industry information not available for this stock.")

        if 'sector' in stock_info:
            Sector = stock_info['sector']
            st.write(f"Sector: {Sector}")
        else:
            st.write("Sector information not available for this stock.")

        if 'website' in stock_info:
            Website = stock_info['website']
            st.write(f"Website: {Website}")
        else:
            st.write("Website information not available for this stock.")

        if 'marketCap' in stock_info:
            MarketCap = stock_info['marketCap']
            st.write(f"Market Cap: {MarketCap}")
        else:
            st.write("Market Cap information not available for this stock.")

        if 'previousClose' in stock_info:
            PreviousClose = stock_info['previousClose']
            st.write(f"Previous Close: {PreviousClose}")
        else:
            st.write("Previous Close information not available for this stock.")

        if 'dividendYield' in stock_info:
            dividend_yield = stock_info['dividendYield'] * 100  # Convert to percentage
            st.write(f"Dividend Yield: {dividend_yield:.2f}%")
        else:
            st.write("Dividend Yield information not available for this stock.")

        st.subheader('Financial Metrics')
        if 'trailingEps' in stock_info:
            trailing_eps = stock_info['trailingEps']
            st.write(f"Earnings Per Share (EPS): {trailing_eps:.2f}")
        else:
            st.write("Earnings Per Share (EPS) information not available for this stock.")

        if 'trailingPE' in stock_info:
            trailing_pe = stock_info['trailingPE']
            st.write(f"Price-to-Earnings (P/E) Ratio: {trailing_pe:.2f}")
        else:
            st.write("Price-to-Earnings (P/E) Ratio information not available for this stock.")

        if 'priceToSalesTrailing12Months' in stock_info:
            priceToSalesTrailing_12Months = stock_info['priceToSalesTrailing12Months']
            st.write(f"Price-to-Sales (P/S) Ratio: {priceToSalesTrailing_12Months:.2f}")
        else:
            st.write("Price-to-Sales (P/S) Ratio information not available for this stock.")

        if 'priceToBook' in stock_info:
            price_ToBook = stock_info['priceToBook']
            st.write(f"Price-to-Book (P/B) Ratio: {price_ToBook:.2f}")
        else:
            st.write("Price-to-Book (P/B) Ratio information not available for this stock.")

        st.subheader('Company Summary')
        if 'longBusinessSummary' in stock_info:
            LongBusinessSummary = stock_info['longBusinessSummary']
            st.write(f"{LongBusinessSummary}")
        else:
            st.write("Company Summary information not available for this stock.")

        st.subheader('Company Officers')
        if 'fullTimeEmployees' in stock_info:
            FullTimeEmployees = stock_info['fullTimeEmployees']
            st.write(f"Full Time Employees: {FullTimeEmployees}")
        else:
            st.write("Full Time Employees information not available for this stock.")

        if 'companyOfficers' in stock_info:
            officers = stock_info['companyOfficers']
            officer_data = []

            df = pd.DataFrame(columns=["Name", "Title", "Age"])

            for officer in officers:
                name = officer.get('name', 'N/A')
                title = officer.get('title', 'N/A')
                age = officer.get('age', 'N/A')
                officer_data.append([name, title, age])


            df = pd.concat([df, pd.DataFrame(officer_data, columns=["Name", "Title", "Age"])], ignore_index=True)

            # Display the DataFrame using Markdown without the index column
            st.markdown(df.to_markdown(index=False))

        else:
            st.write("Company Officers information not available for this stock.")

        st.subheader('Latest News')

        news_data_for_dataframe = []
        for news_item in news_data:
            news_title = news_item['title']
            news_publisher = news_item['publisher']
            news_provider_publish_time = pd.to_datetime(news_item['providerPublishTime'], unit='s')
            news_type = news_item['type']
            news_link = f"[Link]({news_item['link']})"
            news_data_for_dataframe.append([news_title, news_publisher, news_provider_publish_time, news_type, news_link])

        df = pd.DataFrame(news_data_for_dataframe, columns=["Title", "Publisher", "Provider Publish Time", "Type", "Link"])

        st.markdown(df.to_markdown(index=False), unsafe_allow_html=True)

    title = f"<h1 style='color: white; font-size: 25px; text-align: center; '>{stock_name}'s Technical Analysis</h1>"
    st.markdown(title, unsafe_allow_html=True)

    with st.expander("Expand"):
        st.subheader(f'Data from {start_date} - {end_date}')
        data = yf.download(user_input, start_date, end_date)

        if data.empty:
            st.warning(f"No data available for stock symbol {stock_name} in the specified date range.")
        else:
            data = data.reset_index()
            fig = go.Figure(data=[go.Table(
                    header=dict(values=list(data.columns),
                                font=dict(size=12, color='white'),
                                fill_color='#264653',
                                line_color='rgba(255,255,255,0.2)',
                                align=['left', 'center'],
                                height=20),
                    cells=dict(values=[data[k].tolist() for k in data.columns],
                              font=dict(size=12),
                              align=['left', 'center'],
                              line_color='rgba(255,255,255,0.2)',
                              height=20))])

            fig.update_layout(title_text=f"Data for {stock_name}", title_font_color='#264653', title_x=0, margin=dict(l=0, r=10, b=10, t=30))

            st.plotly_chart(fig, use_container_width=True)

            # Stock Price Over Time
            g1, g2, g3 = st.columns((1.2,1.2,1))

            fig1 = px.line(data, x='Date', y='Close', template='seaborn')
            fig1.update_traces(line_color='#264653')
            fig1.update_layout(title_text="Stock Price Over Time", title_x=0, margin=dict(l=20, r=20, b=20, t=30), yaxis_title=None, xaxis_title=None, height=400, width=700)
            g1.plotly_chart(fig1, use_container_width=True)

            # Volume of Stocks Traded Over Time
            fig2 = px.bar(data, x='Date', y='Volume', template='seaborn')
            fig2.update_traces(marker_color='#7A9E9F')
            fig2.update_layout(title_text="Volume of Stocks Traded Over Time", title_x=0, margin=dict(l=20, r=20, b=20, t=30), yaxis_title=None, xaxis_title=None, height=400, width=700)
            g2.plotly_chart(fig2, use_container_width=True)

            # Moving Averages
            short_window = 40
            long_window = 100
            data['Short_MA'] = data['Close'].rolling(window=short_window).mean()
            data['Long_MA'] = data['Close'].rolling(window=long_window).mean()
            fig3 = px.line(data, x='Date', y='Close', template='seaborn')
            fig3.add_scatter(x=data['Date'], y=data['Short_MA'], mode='lines', line=dict(color="red"), name=f'Short {short_window}D MA')
            fig3.add_scatter(x=data['Date'], y=data['Long_MA'], mode='lines', line=dict(color="blue"), name=f'Long {long_window}D MA')
            fig3.update_layout(title_text="Stock Price with Moving Averages", title_x=0, margin=dict(l=20, r=20, b=20, t=30), yaxis_title=None, xaxis_title=None, legend=dict(orientation="h", yanchor="bottom", y=0.9, xanchor="right", x=0.99), height=400, width=700)
            g3.plotly_chart(fig3, use_container_width=True)

            ## ............................................... ##
            # Daily Returns
            g4, g5, g6 = st.columns((1,1,1))
            data['Daily_Returns'] = data['Close'].pct_change()
            fig4 = px.line(data, x='Date', y='Daily_Returns', template='seaborn')
            fig4.update_traces(line_color='#E76F51')
            fig4.update_layout(title_text="Daily Returns", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
            g4.plotly_chart(fig4, use_container_width=True)

            # Cumulative Returns
            data['Cumulative_Returns'] = (1 + data['Daily_Returns']).cumprod()
            fig5 = px.line(data, x='Date', y='Cumulative_Returns', template='seaborn')
            fig5.update_traces(line_color='#2A9D8F')
            fig5.update_layout(title_text="Cumulative Returns", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
            g5.plotly_chart(fig5, use_container_width=True)
            # Stock Price Distribution
            fig6 = px.histogram(data, x='Close', template='seaborn', nbins=50)
            fig6.update_traces(marker_color='#F4A261')
            fig6.update_layout(title_text="Stock Price Distribution", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
            g6.plotly_chart(fig6, use_container_width=True)

            ## ............................................... ##

            # Bollinger Bands
            g7, g9, g10 = st.columns((1,1,1))
            rolling_mean = data['Close'].rolling(window=20).mean()
            rolling_std = data['Close'].rolling(window=20).std()
            data['Bollinger_Upper'] = rolling_mean + (rolling_std * 2)
            data['Bollinger_Lower'] = rolling_mean - (rolling_std * 2)
            fig7 = px.line(data, x='Date', y='Close', template='seaborn')
            fig7.add_scatter(x=data['Date'], y=data['Bollinger_Upper'], mode='lines', line=dict(color="green"), name='Upper Bollinger Band')
            fig7.add_scatter(x=data['Date'], y=data['Bollinger_Lower'], mode='lines', line=dict(color="red"), name='Lower Bollinger Band')
            fig7.update_layout(title_text="Bollinger Bands", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
            g7.plotly_chart(fig7, use_container_width=True)

            # MACD
            data['12D_EMA'] = data['Close'].ewm(span=12, adjust=False).mean()
            data['26D_EMA'] = data['Close'].ewm(span=26, adjust=False).mean()
            data['MACD'] = data['12D_EMA'] - data['26D_EMA']
            data['Signal_Line'] = data['MACD'].ewm(span=9, adjust=False).mean()
            fig9 = px.line(data, x='Date', y='MACD', template='seaborn', title="MACD")
            fig9.add_scatter(x=data['Date'], y=data['Signal_Line'], mode='lines', line=dict(color="orange"), name='Signal Line')
            fig9.update_layout(title_text="MACD", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
            g9.plotly_chart(fig9, use_container_width=True)

            # Relative Strength Index (RSI)
            
            delta = data['Close'].diff()
            gain = (delta.where(delta > 0, 0)).fillna(0)
            loss = (-delta.where(delta < 0, 0)).fillna(0)
            avg_gain = gain.rolling(window=14).mean()
            avg_loss = loss.rolling(window=14).mean()
            rs = avg_gain / avg_loss
            data['RSI'] = 100 - (100 / (1 + rs))
            fig10 = px.line(data, x='Date', y='RSI', template='seaborn')
            fig10.update_layout(title_text="Relative Strength Index (RSI)", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
            g10.plotly_chart(fig10, use_container_width=True)

            # Candlestick Chart
            g11, g13, g14 = st.columns((1,1,1))
            fig11 = go.Figure(data=[go.Candlestick(x=data['Date'],
                            open=data['Open'],
                            high=data['High'],
                            low=data['Low'],
                            close=data['Close'])])
            fig11.update_layout(title_text="Candlestick Chart", title_x=0, margin=dict(l=0, r=10, b=10, t=30))
            g11.plotly_chart(fig11, use_container_width=True)

            # Price Rate of Change (ROC)
            n = 12
            data['ROC'] = ((data['Close'] - data['Close'].shift(n)) / data['Close'].shift(n)) * 100
            fig13 = px.line(data, x='Date', y='ROC', template='seaborn')
            fig13.update_layout(title_text="Price Rate of Change (ROC)", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
            g13.plotly_chart(fig13, use_container_width=True)

            # Stochastic Oscillator
            low_min = data['Low'].rolling(window=14).min()
            high_max = data['High'].rolling(window=14).max()
            data['%K'] = (100 * (data['Close'] - low_min) / (high_max - low_min))
            data['%D'] = data['%K'].rolling(window=3).mean()
            fig14 = px.line(data, x='Date', y='%K', template='seaborn')
            fig14.add_scatter(x=data['Date'], y=data['%D'], mode='lines', line=dict(color="orange"), name='%D (3-day SMA of %K)')
            fig14.update_layout(title_text="Stochastic Oscillator", title_x=0, margin=dict(l=0, r=10, b=10, t=30), yaxis_title=None, xaxis_title=None)
            g14.plotly_chart(fig14, use_container_width=True)

except Exception as e:
    st.error(f"An error fetching stock information: {str(e)}")