How to Analyze Financial Data with Python and ChatGPT

The Problem: Drowning in Numbers, Starving for Meaning

“The stock market is filled with individuals who know the price of everything, but the value of nothing.” — Philip Fisher

When I first started analyzing stocks, I used to rely only on charts.
Green candles meant “good,” red ones “bad.”
But as my portfolio stagnated, I realized something: I was staring at prices, not value.

That’s when I discovered the power of financial data — not just any data, but fundamental data: revenues, debt ratios, and profitability metrics that reveal the story behind a company.

The problem?
Accessing that kind of structured financial data usually meant paying hundreds per month or dealing with messy, incomplete sources.

The Solution: The EODHD Fundamentals API + Python

In this guide, you’ll learn how to:

  • Retrieve fundamental financial data with Python
  • Build a Streamlit dashboard for investors
  • Use financial data using ChatGPT to generate AI-powered insights

By the end, you’ll have your own mini “AI financial analyst” built from scratch.

Step 1: Get Your EODHD API Key

Head over to EODHD Fundamentals Data Feed.
Create a free account and grab your API key.
Test it right away:

https://eodhd.com/api/fundamentals/AAPL.US?api_token=YOUR_TOKEN&fmt=json

If you see a JSON response, you’re ready to go, in the final section of the article you find the complete code. The streamlit interface help you follow step by step

API KEY EODHD

Step 2: Connect to the Fundamentals Endpoint

Let’s start simple — a “Hello World” for financial data:

import requests
API_TOKEN = "YOUR_TOKEN"
symbol = "AAPL.US"
url = f"https://eodhd.com/api/fundamentals/{symbol}?api_token={API_TOKEN}&fmt=json"
r = requests.get(url)
data = r.json()
print(data["General"]["Name"])
print(data["Highlights"]["MarketCapitalization"])

✅ You’ll get the company name and its market cap.
Welcome to the world of live financial data with Python.

Hello World — Finance API

Step 3: Extract Key Fundamentals

The JSON includes dozens of sections.
We’ll focus on what investors actually care about

  • MarketCapitalization
  • TrailingPE
  • PriceBookMRQ
  • ReturnOnEquityTTM
  • DividendYield
  • QuarterlyRevenueGrowthYOY

Here’s how to extract those:

fields = ["MarketCapitalization", "TrailingPE", "PriceBookMRQ",
"ReturnOnEquityTTM", "DividendYield", "QuarterlyRevenueGrowthYOY"]
fundamentals = {}
for f in fields:
fundamentals[f] = (
data.get("Highlights", {}).get(f)
or data.get("Valuation", {}).get(f)
or None
)
print(fundamentals)

Now you’ve got the essentials for financial analysis — clean and structured.

Fundamental data with EODHD

Step 4: Build an Interactive Dashboard with Streamlit

“An investment in knowledge pays the best interest.” — Benjamin Franklin

A dashboard makes your analysis visual and actionable.
Let’s create one that compares companies side by side.

Install dependencies:

pip install streamlit pandas requests

Then save this as fundamentals_dashboard.py:

import streamlit as st
import pandas as pd
import requests
st.title("📊 Financial Data Dashboard with EODHD")
api_token = st.text_input("Enter your EODHD API token", type="password")
tickers_input = st.text_area("Enter tickers (comma-separated, e.g. AAPL.US, MSFT.US)")
if api_token and tickers_input:
tickers = [t.strip() for t in tickers_input.split(",") if t.strip()]
data_rows = []
for t in tickers:
url = f"https://eodhd.com/api/fundamentals/{t}?api_token={api_token}&fmt=json"
r = requests.get(url)
if r.ok:
d = r.json()
data_rows.append({
"Ticker": t,
"MarketCap": d["Highlights"].get("MarketCapitalization"),
"P/E": d["Valuation"].get("TrailingPE"),
"P/B": d["Valuation"].get("PriceBookMRQ"),
"ROE": d["Highlights"].get("ReturnOnEquityTTM"),
"DivYield": d["Highlights"].get("DividendYield"),
"RevGrowthQ": d["Highlights"].get("QuarterlyRevenueGrowthYOY"),
})
df = pd.DataFrame(data_rows)
st.dataframe(df)
st.bar_chart(df.set_index("Ticker")[["ROE", "DivYield", "RevGrowthQ"]].fillna(0))

Run it:

streamlit run fundamentals_dashboard.py

You’ll see your company side by side — fundamentals visualized in seconds.

Finance fundamental data — Stocks
ROE MSFT VS APPL

Step 5: Add Intelligence — Financial Data Using ChatGPT 🤖

Here’s where things get exciting.
You can use financial data using ChatGPT to turn your raw metrics into natural-language insights.

Install the OpenAI package:

pip install openai

Then use this snippet:

from openai import OpenAI
import json
client = OpenAI(api_key="YOUR_OPENAI_KEY")
prompt = f"""
You are a financial analyst. Based on this data:
{json.dumps(fundamentals, indent=2)}
Explain in under 100 words whether this stock appears undervalued or overvalued.
"""
completion = client.chat.completions.create(
model="gpt-4-turbo",
messages=[{"role": "user", "content": prompt}]
)
print(completion.choices[0].message.content)

Example output:

“Apple demonstrates strong profitability (ROE > 140%) but trades at a premium (P/E > 30). Dividend yield is modest. Valuation looks stretched.”

Boom. You just turned financial data into insightful commentary.

Step 6: Combine It All — ChatGPT + Dashboard Integration

Now imagine a dashboard that not only shows data but explains it.
Here’s how to integrate the ChatGPT analysis right into Streamlit:

from openai import OpenAI
client = OpenAI(api_key=st.secrets["OPENAI_KEY"])
if st.button("Analyze with ChatGPT"):
for t in df["Ticker"]:
fundamentals_str = df[df["Ticker"] == t].to_dict(orient="records")[0]
analysis_prompt = f"Analyze {t} financial data: {fundamentals_str}. Provide a short investment summary."
ai = client.chat.completions.create(
model="gpt-4-turbo",
messages=[{"role": "user", "content": analysis_prompt}]
)
st.markdown(f"**{t}:** {ai.choices[0].message.content}")

Now, each stock in your dashboard comes with a mini analyst’s opinion.

Chatgpt for stock analysis with EODHD API

Step 7: What’s Next

Here are a few creative expansions:

  • Add historical charts from EODHD’s prices endpoint
  • Generate automated PDF reports combining metrics + ChatGPT summaries
  • Create sector-level comparisons or portfolio insights
  • Build alerts when P/E or ROE exceed thresholds

Each addition deepens your ability to transform financial data into strategic intelligence.

Final Thoughts

“In investing, what is comfortable is rarely profitable.” — Robert Arnott

Most people drown in numbers.
Few turn those numbers into knowledge.

By combining the EODHD Fundamentals API, Python, and ChatGPT, you bridge the gap between raw financial data and real insight.
You’re not just coding — you’re learning to think like a data-driven investor.

Start your journey with real financial data today.
Get your free API key from EODHD and build your own AI-powered dashboard.

If you enjoyed this tutorial, follow me for more guides on Python, automation, and financial data using ChatGPT.

If you’re interested in consulting or collaboration, feel free to reach out at [email protected].

Leave a Reply