Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
← Machine Learning for Finnace & Accounting Level Three · Lesson 3 of 10

Module Two

📖 Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
3
Module 2: Forecasting Cash Flow, Revenue & Expenses for Young Coders
⭐ Module 2 · Level Three

Forecasting:
Cash Flow, Revenue & Expenses

🔮 Teaching machines to see the financial future

🎯 What you'll learn in this module

  • ✔ Classic baselines: ARIMA and exponential smoothing
  • ✔ ML forecasting with gradient boosting and random forests
  • ✔ Deep learning for sequences: LSTM and Transformers
  • ✔ Hierarchical forecasting for many accounts at once
  • ✔ How to backtest with rolling‑origin evaluation
  • ✔ Uncertainty quantification with prediction intervals
🔮
Why Forecasting Matters in Finance
The Big Idea

Every business decision depends on a guess about the future. Will we have enough cash next month? Will revenue grow or shrink? Should we hire now or wait?

Good forecasts save companies from running out of money, overpaying for inventory, or missing growth opportunities. Machine learning can spot patterns in historical data that humans would miss — and forecast them more accurately.

☂️ A weather forecast tells you whether to bring an umbrella. A cash flow forecast tells a business whether to save or spend. Both help you prepare.
📈
Classic Baselines: ARIMA & Exponential Smoothing
Classical

Before ML, accountants and statisticians used classic time‑series models:

Exponential smoothing gives more weight to recent data than older data. It's simple and surprisingly strong.

ARIMA (Auto‑Regressive Integrated Moving Average) models the pattern in the past values, the trend, and the noise together. It's the workhorse of financial forecasting for decades.

Why learn old methods? Because they're your baseline — if your fancy ML model can't beat ARIMA, it's not actually adding value.

🚴 Before you race with a motorcycle (ML), prove you can win on a bicycle (classical models). If you can't, the problem isn't the vehicle.
🌲
ML Forecasting: Gradient Boosting & Random Forests
ML Models

ML treats forecasting as a supervised learning problem. You feed the model "last month's revenue, last 3 months average, day of week," and it learns to predict "next month's revenue."

Random forests build many small decision trees and average their answers. Gradient boosting (like XGBoost or LightGBM) builds trees one at a time, each fixing the previous tree's mistakes. Both are powerful and fast.

👥 A random forest is like polling a crowd of experts. Gradient boosting is like each expert learning from the last one's mistakes.
🧠
Deep Learning: LSTM & Transformers
Deep Learning

For very complex sequences, deep learning shines. LSTM (Long Short‑Term Memory) networks remember patterns across long time windows — great for sales with seasonal cycles.

Transformers, the technology behind ChatGPT, are now used for financial sequences too. They learn which historical moments matter most, then weigh them carefully to predict the future.

Warning: deep learning needs lots of data. For small financial datasets, tree‑based ML usually wins.

🎬 LSTM is like a film critic remembering the plot twist from hour one. A transformer is like a critic who can instantly jump to any scene and rate its importance.
🌳
Hierarchical Forecasting: Many Levels at Once
Scale

Real companies have many levels of forecasting: sales by product, by store, by region, and by company total. If you forecast each one independently, the numbers might not add up — that's a problem!

Hierarchical forecasting solves this by forecasting all levels together and reconciling them. The bottom‑up approach sums the details. The top‑down approach splits the total. Modern methods combine both.

🏢 Company total
→
🌍 Regions
→
🏪 Stores
→
📦 Products
🧩 Forecasting hierarchy is like puzzle pieces: each level must fit with the others to complete the picture.
🔍
Backtesting with Rolling‑Origin Evaluation
Evaluation

You can't test a forecasting model the same way you test a classifier. You have to respect time. That's backtesting.

Rolling‑origin evaluation works like this: train on months 1–12, predict month 13. Then retrain on 2–13, predict 14. Repeat. It mimics how you'd actually use the model in production — always predicting the future from the past.

Never split randomly for time series. That would leak the future into the past.

🎓 Rolling‑origin backtesting is like taking a test after each chapter, then a final exam at the end: each test only covers what you've already studied.
🎯
Prediction Intervals: Not Just One Number
Uncertainty

A single forecast ("revenue will be $100,000") sounds confident, but reality always has uncertainty. Prediction intervals say "revenue will be between $90,000 and $110,000, 90% of the time."

In finance, this matters enormously. A CFO needs to know the range of possible cash flows, not just a single point. Methods: quantile regression, conformal prediction, or bootstrap ensembles.

🎯 A single arrow aims at one point. A good archer tells you how wide their arrow might scatter. Both help the target practice.
⚠️ Common trap: Financial time series have look‑ahead bias if you're not careful. If your model uses this month's closing balance to predict this month's cash flow, it's cheating. Always ask: "at the moment of prediction, would I actually know this number?"

🛠️ Hands-on activities (no boring stuff!)

1

Eyeball forecast: Look at a simple 12‑month revenue chart. Write down your guess for the next 3 months. Then compute the average of the last 3 months as a baseline. Compare your guess to the baseline — which is more stable?

2

Baseline first: Compute a simple "naive forecast": predict next month = this month. Then a "seasonal naive": predict next month = same month last year. Which feels more useful for a toy store at Christmas?

3

Rolling split demo: Take a toy 12‑month dataset. Split it manually: train on months 1–8, test on 9. Then retrain on 1–9, test on 10. Notice how the training window moves — that's rolling origin.

4

Uncertainty sense: For a company with very volatile sales (swings wildly) vs. a stable company (steady), which forecast would you trust more? Write a sentence explaining why uncertainty is information.

5

Hierarchy reconciliation: You forecast three store sales: 100, 200, and 300. The company total should be 600. But your regional model predicts 580. Decide: adjust each store proportionally, or trust one level more? Justify your choice.

6

Choose a model: For each scenario, pick classical or ML and justify in one sentence: (a) 3 years of monthly data for a small bakery, (b) 10 years of hourly stock data, (c) forecasting 200 store sales with stable patterns.

🏆

By the end of this module, you'll be able to: choose the right forecasting model for financial data, explain ARIMA and exponential smoothing, use ML trees and deep learning for time series, backtest with rolling origin, and quantify uncertainty with prediction intervals.

🏆 Get Certified

🔒

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (₦2,000 or 20,000 coins), and get a verified certificate with your name on it.

🎓 Sign Up to Get Certified
🛠️ Practice Tools
Hands-on simulators & labs - subscription required.
→
🎯 Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
→