Stock Financial Analysis with Streamlit and yfinance
Build and deploy a Streamlit app that pulls Yahoo Finance data with yfinance: price charts, key metrics and post-earnings moves. No API key needed.

This tutorial builds a small stock analysis dashboard in Python with Streamlit and yfinance, an open-source library that reads Yahoo Finance data without an API key. If you're new to Streamlit, start with this introduction. The full code is in my GitHub repository.
What the App Shows
Enter a ticker such as AAPL or BRK-B and pick a time frame. The app shows:
- a price chart for the period you chose, from one day to five years
- company details: country, sector, industry, market cap, enterprise value and headcount
- price details: current price, previous close, day range and 52-week range
- business metrics: forward EPS and P/E, PEG ratio, dividend rate and yield, and the analyst recommendation
- the close-to-close price move after each recent earnings report, as a table and a bar chart
Fetch and Cache Yahoo Data
Every call to Yahoo goes through a cached loader. A repeat lookup within 15 minutes is served from memory instead of going back to Yahoo, which keeps you clear of rate limits. Earnings dates change rarely, so they are cached for six hours.
@st.cache_data(ttl=900, show_spinner=False)
def load_info(symbol):
return yf.Ticker(symbol).info
@st.cache_data(ttl=900, show_spinner=False)
def load_history(symbol, period, interval):
return yf.Ticker(symbol).history(period=period, interval=interval)
@st.cache_data(ttl=21600, show_spinner=False)
def load_earnings_dates(symbol):
return yf.Ticker(symbol).get_earnings_dates(limit=12)Plot the Price History
Each time frame in the sidebar maps to a yfinance period and a bar interval, so the chart stays readable whether it covers one day or five years.
PERIOD_MAP = {
"1D": ("1d", "1h"),
"5D": ("5d", "1d"),
"1M": ("1mo", "1d"),
"6M": ("6mo", "1wk"),
"YTD": ("ytd", "1mo"),
"1Y": ("1y", "1mo"),
"5Y": ("5y", "3mo"),
}
selected_period, interval = PERIOD_MAP[period]
history = load_history(symbol, selected_period, interval)
st.line_chart(history["Close"])Show Key Metrics
The details sit in three columns, each a small dataframe built from the info dictionary. Yahoo leaves some fields empty for some tickers (ETFs have no headcount, for example), so every value goes through a formatter that falls back to N/A instead of crashing.
employees = info.get("fullTimeEmployees")
stock_info = [
("Stock Info", "Value"),
("Country", info.get("country", "N/A")),
("Sector", info.get("sector", "N/A")),
("Industry", info.get("industry", "N/A")),
("Market Cap", format_value(info.get("marketCap"))),
("Enterprise Value", format_value(info.get("enterpriseValue"))),
("Employees", f"{employees:,}" if isinstance(employees, int) else "N/A"),
]
df = pd.DataFrame(stock_info[1:], columns=stock_info[0]).astype(str)
col1.dataframe(df, width=400, hide_index=True)The price and business metric columns follow the same pattern. See the repository for the full code.
Measure the Move After Earnings
For each earnings report, the app compares the last close before the news with the first close after it. A report before the open moves the stock that same day, while one after the close moves it the next day. Reports timed before noon are treated as pre-market and the rest as after the close.
def earnings_moves(earnings, closes):
closes = closes.copy()
closes.index = to_naive(closes.index).normalize()
results = []
for ts in earnings.index:
ts = to_naive(pd.Timestamp(ts))
day = ts.normalize()
if 0 < ts.hour < 12:
after, before = closes[closes.index >= day], closes[closes.index < day]
else:
after, before = closes[closes.index > day], closes[closes.index <= day]
if after.empty or before.empty:
continue
prev_close, next_close = before.iloc[-1], after.iloc[0]
results.append({
"Earnings Date": day.date(),
"Price Date": after.index[0].date(),
"Change (%)": round((next_close - prev_close) / prev_close * 100, 2),
})
return pd.DataFrame(results)The results appear as a table next to a bar chart, green for gains and red for drops.
Handle Yahoo Rate Limits
yfinance is not an official Yahoo API. It reads the same data the Yahoo Finance website uses, and Yahoo throttles heavy traffic, especially from cloud servers. When that happens, yfinance raises YFRateLimitError and the app shows a short warning instead of a stack trace.
except YFRateLimitError:
st.warning("Yahoo Finance is rate-limiting requests right now. Please wait a minute and try again.")If you see this a lot, wait a minute between lookups. The caching above already removes most repeat calls.
Deploy the App on Railway
Deploy it on Railway with the one-click template below. There are no variables to set. Once the build finishes, open the generated xxx.up.railway.app URL. To use your own domain, see the last section of this post.

Choosing between yfinance and a paid data provider? I compare free tiers, fundamentals and usage terms in Best Stock Data APIs for Python.
Frequently Asked Questions
Do I need an API key for yfinance? No. yfinance is free and open source under the Apache 2.0 licence, and it needs no key or account. It is not an official Yahoo product.
Why do I get "Too Many Requests" or YFRateLimitError? Yahoo is throttling your IP address, which happens often on cloud hosts. Wait a minute and try again, and cache responses as the app does.
Can I use yfinance in a commercial product? The yfinance project says it is meant for research and education, and Yahoo's terms limit the data to personal use. For a commercial app, pay for a data plan that includes commercial use. Most providers' standard plans are personal use only, so check before you buy.
Is Railway free for a Streamlit app? New accounts get a 30-day trial with a one-time $5 credit, then move to the Free plan with $1 of usage credit a month. That's enough for a small app like this one.