How to Use LLMs and FMP Market Data to Generate Smart AI-Driven Trading Recommendations

How I reduced analysis time from 40 minutes to 40 seconds using FMP data, news sentiment, and an LLM-powered workflowhe biggest risk is not taking any risk.” — Mark Zuckerberg1. The Real Problem: Too Much Data, Too Little ClarityFinancial markets produ…


This content originally appeared on Level Up Coding - Medium and was authored by Kevin Meneses González

How I reduced analysis time from 40 minutes to 40 seconds using FMP data, news sentiment, and an LLM-powered workflow

he biggest risk is not taking any risk.” — Mark Zuckerberg

1. The Real Problem: Too Much Data, Too Little Clarity

Financial markets produce an insane amount of information every single day:

  • Prices
  • Volume
  • Indicators
  • Company earnings
  • Analyst opinions
  • Macro news
  • Social sentiment
  • Rumors
  • Geopolitical shocks

Most traders don’t fail because they lack tools — they fail because:

They cannot synthesize information fast enough and they make decisions influenced by emotion instead of structured analysis.

Even if you know how to code, backtest, or read charts…
You’re constantly fighting information overload.

2. The Solution: LLMs + FMP Market Data + News Sentiment

Large Language Models (LLMs) solve a simple but painful problem:

They can consume large amounts of data and summarize it instantly.

If you combine:

You get something extremely powerful:

➜ A fully automated “market research assistant”

that can break down everything into:

  • Clear summaries
  • Trend analysis
  • Risks
  • Opportunities
  • Recommendations (not financial advice)

This workflow has helped me personally to:

  • Reduce research time from 30–40 minutes to under 40seconds
  • Remove emotional bias
  • Understand market context better
  • Act with more confidence and less stress

And now I’ll show you how to build it too.

3. What We’re Going to Build

A complete pipeline that:

  1. Fetches price history from FMP
  2. Computes a moving average indicator
  3. Fetches recent news + sentiment using FMP’s /stock_news endpoint
  4. Formats all the data clearly
  5. Sends it to an LLM
  6. Receives a detailed, AI-generated trading insight summary

4. Step-by-Step Python Implementation

4.1. Install Dependencies

pip install requests pandas python-dotenv openai

4.2. Load Environment Variables

from dotenv import load_dotenv
import os
load_dotenv()
FMP_API_KEY = os.getenv("FMP_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

4.3. Fetch Price History from FMP

import requests
import pandas as pd
def get_price_history(symbol: str, limit: int = 120):
url = "https://financialmodelingprep.com/api/v3/historical-price-full/" + symbol.upper()
params = {"timeseries": limit, "apikey": FMP_API_KEY}
r = requests.get(url, params=params)
r.raise_for_status()
df = pd.DataFrame(r.json()["historical"])
df["date"] = pd.to_datetime(df["date"])
return df.sort_values("date").reset_index(drop=True)

What this does:

  • Calls FMP
  • Returns OHLCV data sorted by date
  • Ready for indicator calculation

4.4. Add Simple Indicators

def add_indicators(df):
df = df.copy()
df["ma20"] = df["close"].rolling(20).mean()
return df

4.5. Format Market Context for the LLM

def format_market_context(df, symbol):
latest = df.iloc[-1]
context = f"""
Market Data Summary for {symbol}:Latest Close: {latest['close']:.2f}
20-day MA: {latest['ma20']:.2f}
Trend: {"Bullish" if latest['close'] > latest['ma20'] else "Bearish"}
1-Day Change: {latest['close'] - df.iloc[-2]['close']:.2f}
Last 5 Sessions:
{df.tail(5).to_string(index=False)}
"""
return context

4.6. Fetch News + Sentiment

Using the correct FMP endpoint:

/api/v3/stock_news

def get_news_sentiment(symbol: str, limit: int = 8):
url = "https://financialmodelingprep.com/api/v3/stock_news"
params = {
"tickers": symbol.upper(),
"limit": limit,
"apikey": FMP_API_KEY
}
r = requests.get(url, params=params)
r.raise_for_status()
articles = r.json()
processed = []
for a in articles:
processed.append({
"title": a.get("title"),
"text": a.get("text"),
"site": a.get("site"),
"published": a.get("publishedDate"),
"symbol": a.get("symbol")
})
return processed

4.7. Format News for the LLM

def format_sentiment_context(news_list):
if not news_list:
return "No recent news found."
output = "Recent News:\n"
for n in news_list:
output += f"- {n['published']} | {n['site']} | {n['title']}\n"
return output

4.8. LLM Insight Generator

from openai import OpenAI
client = OpenAI(api_key=OPENAI_API_KEY)
def generate_ai_insights(market_context, news_context):
prompt = f"""
You are a financial analyst.
Based on the MARKET DATA and NEWS provided, generate a clear trading insight summary including:
1. Market context
2. Trend analysis
3. Interpretation of news sentiment
4. Risks or opportunities
5. A simple trading recommendation (NOT financial advice)
MARKET DATA:
{market_context}
NEWS:
{news_context}
"""
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content

4.9. Full Script

symbol = "AAPL"
df = get_price_history(symbol)
df = add_indicators(df)
market_context = format_market_context(df, symbol)
news_list = get_news_sentiment(symbol)
news_context = format_sentiment_context(news_list)
insights = generate_ai_insights(market_context, news_context)
print(insights)

5. Example Output (Typical LLM Summary)

“AAPL shows mild bullish momentum as price trades above the 20-day MA.
Recent news sentiment is moderately positive, with headlines centered on product launches and earnings stability.
Combined, this suggests a constructive short-term trend with opportunities on pullbacks, though watch for macro-driven volatility
.”

This is exactly the type of clarity most traders need.

And it takes less than 20 seconds.

6. Tips to Improve Your Workflow

- Add more indicators

RSI, MACD, ATR, volatility bands…

- Compute a “sentiment score”

Count positive vs negative headlines.

- Add fundamentals

FMP lets you fetch:

  • P/E
  • P/S
  • EBITDA
  • Debt levels
  • Revenue growth
  • Analyst ratings

- Let the LLM compare multiple assets

Feed 3 tickers at once and ask:

“Which asset has the strongest combination of trend + sentiment?”

- Automate the system

Run it daily with a cron job and email yourself the report.

7. FAQ

Why use FMP instead of Yahoo Finance?

Because FMP provides:

✔ Reliable historical data
✔ Stock news + timestamps
✔ Fast JSON responses
✔ Crypto, ETFs, Forex, indices
✔ Financial statements
✔ Easy API authentication

All in one place.

Do LLMs replace technical analysis?

No.
They synthesize data — you still decide the final action.

Can this system be automated?

Absolutely:

  • Cron jobs
  • AWS Lambda
  • GitHub Actions
  • Airflow

8. Final Ideas

If you want to build powerful AI-driven trading assistants:

👉 Get your FMP API Key— better data = better decisions
👉 Use Python to automate your research
👉 Add news sentiment for deeper context
👉 Use LLMs to generate instant, structured insights

This workflow has helped me think clearly, act more calmly, and make more rational financial decisions.

And you can build it today with less than 100 lines of code.


How to Use LLMs and FMP Market Data to Generate Smart AI-Driven Trading Recommendations was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Kevin Meneses González


Print Share Comment Cite Upload Translate Updates
APA

Kevin Meneses González | Sciencx (2025-11-25T14:51:44+00:00) How to Use LLMs and FMP Market Data to Generate Smart AI-Driven Trading Recommendations. Retrieved from https://www.scien.cx/2025/11/25/how-to-use-llms-and-fmp-market-data-to-generate-smart-ai-driven-trading-recommendations-2/

MLA
" » How to Use LLMs and FMP Market Data to Generate Smart AI-Driven Trading Recommendations." Kevin Meneses González | Sciencx - Tuesday November 25, 2025, https://www.scien.cx/2025/11/25/how-to-use-llms-and-fmp-market-data-to-generate-smart-ai-driven-trading-recommendations-2/
HARVARD
Kevin Meneses González | Sciencx Tuesday November 25, 2025 » How to Use LLMs and FMP Market Data to Generate Smart AI-Driven Trading Recommendations., viewed ,<https://www.scien.cx/2025/11/25/how-to-use-llms-and-fmp-market-data-to-generate-smart-ai-driven-trading-recommendations-2/>
VANCOUVER
Kevin Meneses González | Sciencx - » How to Use LLMs and FMP Market Data to Generate Smart AI-Driven Trading Recommendations. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/25/how-to-use-llms-and-fmp-market-data-to-generate-smart-ai-driven-trading-recommendations-2/
CHICAGO
" » How to Use LLMs and FMP Market Data to Generate Smart AI-Driven Trading Recommendations." Kevin Meneses González | Sciencx - Accessed . https://www.scien.cx/2025/11/25/how-to-use-llms-and-fmp-market-data-to-generate-smart-ai-driven-trading-recommendations-2/
IEEE
" » How to Use LLMs and FMP Market Data to Generate Smart AI-Driven Trading Recommendations." Kevin Meneses González | Sciencx [Online]. Available: https://www.scien.cx/2025/11/25/how-to-use-llms-and-fmp-market-data-to-generate-smart-ai-driven-trading-recommendations-2/. [Accessed: ]
rf:citation
» How to Use LLMs and FMP Market Data to Generate Smart AI-Driven Trading Recommendations | Kevin Meneses González | Sciencx | https://www.scien.cx/2025/11/25/how-to-use-llms-and-fmp-market-data-to-generate-smart-ai-driven-trading-recommendations-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.