In a world where everything is connected, an event in one country can quickly affect markets in another. As developers, we have access to a lot of data, but the interesting part is figuring out how world news and stock markets relate to each other.
I built an app called the Geo-Eco Navigator. It’s a Streamlit application that tries to show the link between current events and economic performance. It started as a simple data tool, but now uses AI to help explain what the news actually means for the economy.
The Goal: Real Data, Not Just Numbers
Most financial dashboards just show charts and numbers. I wanted something that gives more context. I specifically wanted to show why a market might be moving based on what’s happening in the news.
One important rule I had was to use real-time data. Nothing is hardcoded. Everything—from stock prices to news—is fetched live when you use the app.
🛠 The Tech Stack
I kept the technology simple so the app stays fast:
- Streamlit: To build the web interface easily.
- YFinance: To get stock market data for 25 different countries.
- DuckDuckGo Search: To find the latest news without needing a paid API.
- Google Gemini: An AI used to analyze how news impacts the economy.
- Plotly: To create the charts where news events are marked.
🧠 How the App Processes Information
The app doesn’t just list news; it tries to analyze it in a few ways.
1. Finding the Right News
Searching for “2026 outlook” or “past events” can sometimes give irrelevant results. I improved this by:
- Using different search types for current news vs historical context.
- Adding a simple language filter. Since I wanted English results, the app checks if the text looks like English. If a search result for the USA is in another language, the app filters it out.
2. Using AI for Better Insights
The app uses Gemini to do the heavy lifting. Instead of you reading 10 news articles, the AI does it and provides:
- A short summary of what’s happening.
- An analysis of how events affect specific areas like Tech, Energy, and Finance.
- A forecast of potential risks to watch out for.
🛠 A Look at the Code
Here are a few technical details on how the app works.
1. Getting Market Data
Since I track 25 countries, the data formats can vary. I wrote a function to clean up the data so it’s always consistent.
def get_economic_data(ticker, period="1y"):
data = yf.download(ticker, period=period)
# Make sure we can always access the data correctly
if isinstance(data.columns, pd.MultiIndex):
data.columns = data.columns.get_level_values(0)
return data
2. Filtering Languages
To keep the data clean, I added a small check to ensure most of the characters are standard (ASCII).
# Simple check to filter out non-English results
non_ascii = len([c for c in text_to_check if ord(c) > 127])
if non_ascii / len(text_to_check) < 0.25:
filtered_results.append(r)
3. AI Sentiment and Risk Scoring
Before the AI hub kicks in, the app does a simple keyword-based check to estimate the general mood. It looks for positive and negative words in the headlines to verify the market trend.
def analyze_sentiment_and_risk(country):
news = fetch_intelligence(country, "sentiment")
positive_words = ["growth", "surge", "recovery", "positive", "strong"]
negative_words = ["slump", "risk", "decline", "crisis", "tension"]
text = " ".join([n['title'].lower() for n in news])
pos_count = sum(1 for w in positive_words if w in text)
neg_count = sum(1 for w in negative_words if w in text)
# Logic to decide if we are Bullish or Bearish
sentiment = "Bullish" if pos_count > neg_count else "Bearish"
risk = "High" if neg_count > 2 else "Moderate"
return sentiment, risk
4. Directing the AI (Prompt Engineering)
The AI reasoning isn’t just a generic chatbot. I created specific prompts that force the AI to focus on how news headlines actually interact with different parts of the economy.
prompts = {
# This prompt forces the AI to be concise and focused on sectors
"sector": f"Analyze how recent events in {country} impact Tech, Energy, and Finance. Provide concise bullet points.\nContext:\n{news_snippet}",
"risks": f"List the 2 biggest geopolitical risks for {country} in the next 6 months.\nContext:\n{news_snippet}"
}
5. Custom Styling (Glassmorphism)
I wanted the app to have a modern look, so I used custom CSS to create a “glass” effect on the metric cards. This involved using backdrop filters and semi-transparent backgrounds.
st.markdown("""
<style>
.stMetric {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
border-radius: 15px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
</style>
""", unsafe_allow_html=True)
6. Adding News to Charts
I wanted to show news events directly on the stock chart. Since news doesn’t always have a perfect timestamp that matches market data, I spread out the latest news events across the chart timeline so you can see the general context of recent price changes.
🌍 What I Learned
Managing data for 25 countries means dealing with a lot of “noise.” I learned that AI works much better when you give it clean, relevant data. By refining the search terms to include “English” and “Economic Outlook,” the AI’s analysis became much more useful.
What’s Next?
Right now, the app is a good way to see what’s happening. In the future, I might add a way to simulate scenarios—like seeing what might happen to the market if a specific trade deal is signed.
But for now, it’s a helpful tool to see how world news and the economy fit together.
Github – https://github.com/sethlahaul/geopolitics-economy-correlator
