Financial data doesn't appear from nowhere โ it flows from many sources:
| Source | What It Contains | Example |
|---|---|---|
| ๐ Ledgers | Every transaction recorded by a company | Sales, purchases, payroll entries |
| ๐ข ERP systems | Combined business data (inventory, HR, finance) | SAP, Oracle Financials |
| ๐ Market feeds | Real-time stock prices, exchange rates | Bloomberg, Yahoo Finance |
| ๐ Financial statements | Summaries released quarterly or annually | Income statement, balance sheet |
Most financial data is a time series โ a sequence of values recorded over time. Think of a stock price, a company's monthly revenue, or your bank balance.
Key idea: order matters. Yesterday's value usually tells you something about today's. That's totally different from random data like survey answers. We'll learn to respect time in every model we build โ never peek into the future.
Real financial data is messy. Three common problems:
Missing values: a payment wasn't recorded. Fill in with a reasonable estimate โ or mark it clearly and let the model handle it.
Outliers: a huge transaction that doesn't fit the pattern. Sometimes real (a big sale!), sometimes a typo (someone added an extra zero). Investigate before deleting.
Restatements: a company re-reports past numbers. Use the latest restated values, and never mix old and new numbers.
Raw data is like a block of wood. Feature engineering shapes it into something a model can use. Two of the most powerful techniques:
Lags: use yesterday's or last month's value as a feature. revenue_t-1 helps predict revenue_t.
Rolling windows: summarize the last N periods. average_revenue_last_3_months smooths out noise and captures trends.
Both tell the model: "here's what happened recently, now predict what's next."
Accountants have been computing ratios for over a century โ and for good reason. Ratios pack a lot of information into one number. Some favorites:
| Ratio | Formula | What It Tells You |
|---|---|---|
| Profit Margin | Net income รท Revenue | How much profit per dollar earned |
| Current Ratio | Current assets รท Current liabilities | Can the company pay its short-term bills? |
| Debt-to-Equity | Total debt รท Total equity | How much is borrowed vs. owned |
| Return on Equity (ROE) | Net income รท Equity | How well the company uses investor money |
For ML, ratios are features โ they let the model compare companies of different sizes fairly.
Data leakage happens when your model accidentally sees information it wouldn't have at prediction time. It looks great in testing and then fails in real life.
Examples: using tomorrow's stock price as a feature to predict today's. Or using "total revenue at year-end" to predict monthly sales โ you wouldn't have that at month-end.
Rule of thumb: at prediction time, only use what you would actually know at that moment. If a feature "feels too good to be true," it probably is.
Source scavenger hunt: List 5 places financial data exists in your daily life (bank statements, receipts, school fees, stock apps, chore money). For each, note whether it's time-ordered.
Clean the toy dataset: Take a small CSV with 10 rows, 2 missing values, and 1 obvious typo (like a price of 1000000). Decide how to handle each case and document your decision.
Lag feature lab: Given a list of 10 monthly sales numbers, create a new column that shifts them by 1 (so the value at month 2 is the sales from month 1). Notice how the first row becomes empty โ that's real and expected.
Rolling average: Extend your dataset with a "3-month rolling average" column. Compare a single month's raw value to the smoothed value. Which is easier to spot a trend in?
Ratio practice: For a company with net income 50, revenue 500, and equity 250, compute profit margin and ROE. Then do the same for a company twice the size. Compare โ did the ratios change as much as the raw numbers?
Leakage detective: Review three example features and identify which would leak information: (a) "sales from last month," (b) "end-of-year total revenue," (c) "number of items sold yesterday." Explain your choices.
By the end of this module, you'll be able to: identify financial data sources, explain time-series basics, clean messy financial data, create lag and rolling-window features, compute key ratios, and avoid the trap of data leakage.