Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import pandas_datareader.data as web
|
5 |
+
import datetime as dt
|
6 |
+
import yfinance as yf
|
7 |
+
from sklearn.preprocessing import MinMaxScaler
|
8 |
+
from keras.models import load_model
|
9 |
+
import streamlit as st
|
10 |
+
import plotly.graph_objects as go
|
11 |
+
import base64
|
12 |
+
import plotly.express as px
|
13 |
+
from datetime import datetime
|
14 |
+
|
15 |
+
st.set_page_config(page_title='Stock Comparison', layout='wide', page_icon='📊')
|
16 |
+
|
17 |
+
st.title("Stock Comparison")
|
18 |
+
|
19 |
+
st.sidebar.header("Select Stocks and Date Ranges")
|
20 |
+
|
21 |
+
option = st.sidebar.selectbox(
|
22 |
+
"Choose desired company",
|
23 |
+
('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'),
|
24 |
+
index=None,
|
25 |
+
placeholder="Enter ticker...",
|
26 |
+
)
|
27 |
+
|
28 |
+
stock1 = st.sidebar.text_input("Select a Stock", "DIS")
|
29 |
+
stock2 = st.sidebar.text_input("Select a Stock", "NVDA")
|
30 |
+
|
31 |
+
start_date_stock1 = st.sidebar.date_input(f"Start date for {stock1}", datetime(2018, 1, 1), key=f"start_date_{stock1}")
|
32 |
+
end_date_stock1 = st.sidebar.date_input(f"End date for {stock1}", datetime(2023, 12, 1), key=f"end_date_{stock1}")
|
33 |
+
start_date_stock2 = st.sidebar.date_input(f"Start date for {stock2}", datetime(2018, 1, 1), key=f"start_date_{stock2}")
|
34 |
+
end_date_stock2 = st.sidebar.date_input(f"End date for {stock2}", datetime(2023, 12, 1), key=f"end_date_{stock2}")
|
35 |
+
|
36 |
+
if st.sidebar.button("Compare"):
|
37 |
+
data_stock1 = yf.download(stock1, start=start_date_stock1, end=end_date_stock1)
|
38 |
+
data_stock2 = yf.download(stock2, start=start_date_stock2, end=end_date_stock2)
|
39 |
+
|
40 |
+
fig = go.Figure()
|
41 |
+
|
42 |
+
fig.add_trace(go.Scatter(x=data_stock1.index, y=data_stock1['Close'], mode='lines', name=f'{stock1}'))
|
43 |
+
fig.add_trace(go.Scatter(x=data_stock2.index, y=data_stock2['Close'], mode='lines', name=f'{stock2}'))
|
44 |
+
|
45 |
+
fig.update_layout(title=f"Comparison of {stock1} and {stock2}", xaxis_title="Date", yaxis_title="Closing Price")
|
46 |
+
|
47 |
+
st.plotly_chart(fig)
|