Turn Financial APIs into Classroom Data: A Hands‑On Project for Statistics Students
Use free KPI and financial-ratio APIs to give students real datasets for hypothesis tests, regression, and visualizations with Python and spreadsheets.
Turn Financial APIs into Classroom Data: A Hands‑On Project for Statistics Students
Bring real, live datasets into your statistics class by tapping free KPI and financial-ratio APIs. This hands-on project shows teachers and students how to fetch financial ratios and KPIs, clean them, run hypothesis tests, build regressions, and create visualizations using Python and spreadsheets. Use these techniques for student projects that emphasize data literacy, reproducibility, and applied statistics.
Why use financial APIs in class?
Financial APIs provide standardized KPI and financial ratios (for example, ROE, ROA, current ratio, margin metrics) across publicly traded firms. They give students real-world, up-to-date data without manually scraping 10-Ks. Projects using these APIs teach statistical concepts (sampling, hypothesis testing, regression), programming basics (Python for data), and spreadsheet analysis — all useful for students, teachers, and lifelong learners.
What you'll need
- A free API key from a provider that offers KPI and ratio endpoints (many providers like Financial Modeling Prep offer free tiers).
- Python 3 with pandas, requests, matplotlib/seaborn, and scikit-learn or statsmodels.
- A spreadsheet program: Google Sheets or Excel.
- Basic familiarity with hypothesis testing, linear regression, and plotting.
Step-by-step: Set up in Python
The following is a compact workflow to pull KPI/financial ratios, prepare a dataset, and run a simple regression.
- Install dependencies:
pip install pandas requests matplotlib seaborn scikit-learn statsmodels. - Fetch data from the API (replace
YOUR_API_KEYand endpoint as required):
import requests
import pandas as pd
api_key = 'YOUR_API_KEY'
url = f'https://financialmodelingprep.com/api/v3/ratios/AAPL?apikey={api_key}'
resp = requests.get(url)
data = resp.json()
# Many endpoints return a list of yearly/quarterly ratios
df = pd.DataFrame(data)
print(df.columns)
3) Clean and combine: select columns such as 'date', 'netProfitMargin', 'returnOnEquity' and merge with market/industry labels if available. 4) Example: run a simple OLS regression to predict net profit margin from ROE and debt ratio:
import statsmodels.api as sm
X = df[['returnOnEquity', 'debtEquityRatio']].astype(float)
X = sm.add_constant(X)
y = df['netProfitMargin'].astype(float)
model = sm.OLS(y, X, missing='drop').fit()
print(model.summary())
5) Visualize: use seaborn for scatterplots, residual plots, and time series. Example: seaborn.regplot(x='returnOnEquity', y='netProfitMargin', data=df).
Step-by-step: Spreadsheet analysis (Google Sheets / Excel)
If students prefer spreadsheets, export the cleaned CSV from Python or import the API output directly into Google Sheets via Apps Script or a CSV import.
- Import the CSV into the sheet.
- Use formulas to compute derived metrics: e.g., =IFERROR(NetIncome/Revenue,"") for net margin.
- Use pivot tables to group by sector or year.
- Run regressions: Excel's Data Analysis Toolpak or Google Sheets' LINEST for linear regressions.
- Create charts: scatter plots for regressions, line charts for time series, bar charts for KPI comparisons.
Class project ideas
- Hypothesis testing: Do technology firms have higher average ROE than utilities? Use t-tests on ROE samples by sector.
- Regression project: Predict net profit margin from ROE, asset turnover, and leverage across firms; interpret coefficients and goodness-of-fit.
- Time-series visualization: Compare quarterly EPS and revenue growth for a cohort of companies — teach decomposition and seasonality.
- Classification experiment: Use logistic regression or a simple classifier to predict whether a firm will beat earnings estimates based on recent KPIs.
Practical tips for instructors
- Start small: give students one ticker or one sector to avoid overwhelming them with missing values.
- Teach data validation: check for NaNs, outliers, and inconsistent date formats.
- Provide starter code and a rubric that emphasizes interpretation over perfect R².
- Show them how to document the API source and rate limits — reproducibility matters.
Ethics, licensing, and reliability
Always review the API's terms of use and attribution requirements. Teach students to respect rate limits and cache results for class demos. Note that API data are standardized estimates and may differ from company filings — encourage critical evaluation and cross-checking.
Further resources
For visualization tips and teaching-friendly graphs, see our guide Visualizing Equations: The Power of Graphs in Understanding Algebra. To connect coding and pedagogy, try Coding Made Easy: How Claude Code Sparks Creativity in Students. These internal resources pair well with API-based projects to build intuition about data and models.
Using KPI and financial-ratio APIs converts abstract formulas into living datasets students can query, model, and visualize. With Python and spreadsheets, instructors can create reproducible, engaging projects that teach statistical thinking and real-world data skills.
Related Topics
Alex Mercer
Senior SEO Editor
Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.
Up Next
More stories handpicked for you
Engaging with Audience: What ‘The Traitors’ Can Teach Students About Team Dynamics
Embracing Change: Lessons from Charli XCX’s Transformation for Student Resilience
Exploring Difficult Themes: How ‘Leviticus’ Discusses Social Issues Relevant to Students
Crisis Management in Sports: What Students Can Learn from Transfer Rumors
Maximizing Potential: Lessons from Foo Fighters’ Exclusive Gigs
From Our Network
Trending stories across our publication group