How I Used AI To Analyze Any Public Company Instantly!
Discover how I leveraged AI to automate SWOT analysis and explored key insights without lifting a finger.

Did you ever wish you had a tool that could help you understand a company’s strengths, weaknesses, opportunities, or threats (SWOT Analysis) without spending hours digging through financial reports? I did! Back in grad school, I took a Policy and Strategy class, and I struggled to piece together SWOT analyses for my projects. If I’d had a tool like the one I’m about to show you, I would’ve saved so much time!
This tool leverages AI, specifically GPT-3.5, to automatically generate a SWOT analysis for any company you select from the S&P 500. All you have to do is pick your companies, and AI does the rest. No financial research, no digging through balance sheets - it’s all done for you in a matter of seconds.
The best part? You can build this tool yourself, and it’s easier than you think. Let’s jump right in! If you don’t have a Medium account, you can get this Blog for FREE if you subscribe to my Substack!
What is a SWOT Analysis?
Before we dive into the technical stuff, let’s quickly cover the basics. SWOT stands for:
Strengths: What makes the company strong? Think brand loyalty, product innovation, etc.
Weaknesses: Where does the company fall short? Maybe it’s too dependent on one product or region.
Opportunities: What external trends or new markets can the company take advantage of?
Threats: What could hurt the company? It could be anything from competition to regulatory changes.
In this project, we’re using AI to automatically generate these insights. No need to manually sort through data - the AI takes care of it all!
Step 1: Setting Up Your Environment
Before we get into coding, you’ll need to set up your environment. Don’t worry, it’s just a couple of commands.
You will need the following Python libraries:
1] Streamlit
2] Pandas
3] OpenAI
To install the necessary Python libraries, open your terminal and run:
pip install streamlit pandas openaiBoom! You’re ready to go. Let’s move on.
Step 2: Fetching S&P 500 Company Data
First, we need a list of S&P 500 companies to choose from. Instead of manually entering them, we’ll grab the latest list from Wikipedia. Here’s a simple function to pull the data:
import pandas as pd
def load_sp500_data():
url = ‘https://en.wikipedia.org/wiki/List_of_S%26P_500_companies’
html = pd.read_html(url)
df = html[0]
return df[[‘Symbol’, ‘Security’]]This will give us a neat list of companies to work with, and we’ll use it to populate dropdowns in our app later.
Step 3: Let AI Handle the SWOT Analysis
Now comes the fun part! Instead of manually digging through financial reports, we’re going to use GPT-3.5, a powerful Large Language Model (LLM), to generate the SWOT analysis for us. Here’s the code to make that happen:
import openai
# Set your OpenAI API Key here
openai.api_key = "your-openai-api-key"
def fetch_swot_via_ai(company_name):
prompt = f"Provide a detailed SWOT (Strengths, Weaknesses, Opportunities, and Threats) analysis for {company_name}. Include recent trends and competitive insights."
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are an expert business and financial analyst."},
{"role": "user", "content": prompt}
],
max_tokens=500 # Adjust this based on the level of detail you want
)
return response['choices'][0]['message']['content'].strip()With this function, you’ll get a fully AI-generated SWOT analysis just by entering the company’s name. No research is needed - how awesome is that?
Alternatively, you could have just as easily used the Yahoo Finance package. Had you done this, you could be just another person using the Yahoo Finance package in Python, and that would set you back by 10 years. This post is all about using a new way of doing an old thing, i.e., SWOT Analysis. If you don’t trust AI for this part, you can use the info module in the “yfinance” package.
Real quick!
If you liked what you read so far and would like me to continue creating similar content, please Clap and Follow my Medium account. It gives me motivation to keep giving you valuable information!
Step 4: Building the User Interface with Streamlit
Let’s make this tool interactive by building a user-friendly interface. We’ll use Streamlit as indicated previously, to create a clean UI where users can select two companies, generate a SWOT analysis for each, and compare the results.
Here’s the code to make it happen:
# Load S&P 500 data
sp500_df = load_sp500_data()
# Title of the app
st.markdown("<h1 style='text-align: center; color: #4CAF50;'>AI-Driven SWOT Analysis for S&P 500 Companies</h1>", unsafe_allow_html=True)
# Dropdowns for company selection
st.markdown("### Select Companies for Comparison")
company1_choice = st.selectbox('Select First Company', sp500_df['Security'].unique())
company2_choice = st.selectbox('Select Second Company', sp500_df['Security'].unique())
# Button to trigger SWOT analysis
if st.button('Generate SWOT Analysis'):
# Fetch SWOT from AI
company1_swot = fetch_swot_via_ai(company1_choice)
company2_swot = fetch_swot_via_ai(company2_choice)
# Display the results side by side
st.markdown(f"## SWOT Analysis: {company1_choice} vs {company2_choice}")
col1, col2 = st.columns(2)
with col1:
st.markdown(f"<div style='background-color:#e0ffe0; padding: 15px; border-radius: 10px;'><b>{company1_choice}</b><br/>{company1_swot}</div>", unsafe_allow_html=True)
with col2:
st.markdown(f"<div style='background-color:#e0ffe0; padding: 15px; border-radius: 10px;'><b>{company2_choice}</b><br/>{company2_swot}</div>", unsafe_allow_html=True)You now have a sleek, user-friendly interface where users can select two companies, hit a button, and compare their AI-generated SWOT analyses side-by-side.
Step 5: Digging Deeper with AI-Driven Insights
Not only does this tool give you a SWOT analysis, but it can also provide extra insights into trends, competition, and more. Here’s how you can fetch those additional insights using GPT-3.5:
def fetch_additional_insights(company_name):
prompt = f"Provide some additional insights, trends, and competitive analysis for {company_name}."
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are an expert financial analyst."},
{"role": "user", "content": prompt}
],
max_tokens=300
)
return response['choices'][0]['message']['content'].strip()44Now, you’ll get even more information about the companies you’re analyzing - everything from emerging market trends to competitive threats. It’s like having a financial analyst at your fingertips.
How Does the Application Look?

This compares Google with Meta (previously called Facebook). While this is done in a way to showcase two companies for which we would do a SWOT analysis, we can just as well look at each company’s SWOT analysis separately. Ignore the other company’s SWOT Analysis. The Button in Red helps you generate the SWOT Analysis. There is only one button on here so I wanted to make it stand out. A great User-Interface was not the goal here so I haven’t focused on that here. The above screenshot from the application compares the strengths of the two companies. One thing to note is, it is not a direct comparison. So it can be used for each company individually as well. The AI would need to be prompted further to perform a direct comparison.

Both companies are huge tech giants, so expansion into new markets is a huge opportunity for both. GCP or Google Cloud Platform’s rise is just continuing to benefit Google and Meta’s Marketplace growth is a big revenue potential for them.

We know Google’s big competitors are the other big ones: Amazon, Facebook and Microsoft in advertising. In Phones, it competes with Samsung and Apple, in Cloud Services, it (Google Cloud Platform) competes with Amazon (Web Services) and Microsoft (Azure Cloud)

Meta on the other hand is focusing on VR and AR technologies as can be seen in the screenshot above. A Lot more emphasis has been placed on its security these days.
Next Steps
You may now wonder, “What else can I do from this?” OR “Where do I go from here?”.
Well, you can ask the AI to get Financial statements for the companies,
You can also ask the AI to do a more direct line-by-line comparison of each point in the SWOT Analysis.
You can see the trends in the stock price for the last 5 years for both stocks and see which ones performed better on average.
You can compare more than 2 stocks as well.
…… And, Lots More!
Final Thoughts
From the next steps, you may have gathered there are a lot of directions that you can go from here. My use case here was a just SWOT Analysis so I chose to stop here.
And there you have it - a fully AI-powered SWOT analysis tool that you can use to instantly compare companies in the S&P 500. Whether you’re a student, a professional, or just curious about business strategy, this tool is going to save you a ton of time and effort.
What I love about this approach is how simple it is to implement, yet how powerful it becomes with AI handling all the heavy lifting. So give it a try, play around with the tool, and let me know how it works for you and if you have better suggestions on how to make this better, including UI changes, feel free to let me know! If you’re still here and would like me to make more content, please consider supporting me by following my Medium!


