Aarhus University · Master's course

Machine Learning in Finance

Programming and machine learning for finance and economics students, starting from zero. Everything you need for each session is below.

Start here

how the lectures, the exercises and the case work

If this is your first visit, two minutes on this card will save you time later. Everything on this site is free to use, and nothing needs to be installed to begin.

What each session gives you

  1. The interactive lecture. The slides from class, with the code still runnable. Use it in class if you like, and again afterwards when you want to try changing something and see what happens.
  2. The exercises. Short tasks that drill one idea at a time, rated one to five stars. You are not expected to finish them all. Hints and full solutions are folded under each task, so you are never stuck for long.
  3. The case. One investigation of real market data that runs through the course, a part after most sessions: Parts 1 to 12, with none for the case lectures of Sessions 7, 10 and 13. Each part picks up the numbers the part before worked out, and opens with a quick-load cell, so you can start it even if you skipped the one before. It is where the separate pieces become an analysis.

Do the exercises before the case. The exercises teach the moves, the case asks you to choose which move to make.

Using the interactive lecture

It runs entirely in your browser, so there is nothing to install. Code cells are editable: change a number, press Run, and see what happens. The first cell takes a moment: the page fetches Python itself, and from Session 3 NumPy, pandas and matplotlib (from Session 5 also scikit-learn, about 50 MB in all). On a good connection the first result appears after 7 to 15 seconds; every cell after that is quick.

Three keys worth knowing

  • m opens a menu listing every slide by title, so you can jump straight to the part you want. Its Course tab has the session's exercises, case and PDF.
  • e lays the whole lecture out as one long page you can scroll and search with your browser's own find. This is the one to use when you are revising. Press e again to go back to slides. To keep a copy, take the lecture's PDF from the Exam info page rather than printing: printing leaves out the results of the code.
  • Ctrl+Enter runs the code cell you are typing in (Cmd+Enter on a Mac), which is quicker than reaching for the Run button.

Working on the notebooks

The exercises and the case open in Google Colab, which runs Python for you in the browser. Save your own copy before you start (File, then Save a copy in Drive), or your work is lost when you close the tab. If you would rather work on your own machine, the setup guide walks through it and the downloads page has every notebook and data file. Both routes use exactly the same data, so your numbers will match the ones shown in class.

When you get stuck. The cheatsheet lists everything taught so far, one line per function with the session it came from. The maths brush-up revises the notation the course assumes: matrices, vectors, and how to read a formula like (X'X)-1X'y without effort. The resources page covers the official documentation, free books, and where AI genuinely helps rather than hurts. If you are still stuck, ask a friend or email jobo@econ.au.dk.

All sessions

Session 1 · Beginning Python for financial data

Notebooks, variables, types, functions and methods, lists, and reading errors. The lecture runs in your browser; the exercises and case open directly in Google Colab. Save your own copy in Colab before you start.

Prefer to work offline? Download this session's notebooks and data.

Session 2 · Functions, loops and dictionaries

For and while loops, if / elif / else, writing your own functions, and dictionaries, ending with volatility computed from every daily return of a year.

Prefer to work offline? Download this session's notebooks and data.

Session 3 · Packages: NumPy, pandas and matplotlib

Working locally in VS Code, finding documentation offline, and the three packages every analysis rests on: arrays and matrix algebra, tables of prices, and figures. The case reaches all eleven instruments.

Prefer to work offline? Download this session's notebooks and data.

Session 4 · Foundations of machine learning

The statistical learning framework, supervised against unsupervised, the three things always wrong with real data, the metrics that score a prediction, and the bias-variance trade-off. Theory, maths and code together. No model is fitted.

Prefer to work offline? Download this session's notebooks and data.

Session 5 · Model selection and cross-validation

The first model of the course, fitted with scikit-learn in three lines, and then the harder half: scoring it against rules that use no model, discovering that one validation split gives two different answers, and cross-validating with folds that respect the calendar.

Prefer to work offline? Download this session's notebooks and data.

Session 6 · Penalised regression

A table with nineteen columns, and what ordinary least squares does with it. Then the cure: a penalty on the coefficients (ridge, lasso, elastic net), the scaling it needs, a pipeline to hold the two together, and a grid search over how strong the penalty should be.

Prefer to work offline? Download this session's notebooks and data.

Session 7 · Pricing a house in Aarhus

A recap with no new tool: one investigation from a raw file of 7,621 Aarhus house sales to a valued house, using every tool from the six sessions before it. Many slides hold a working cell to change as you like, so open the deck on your own laptop and play along.

There are no exercises and no case for this session: the deck is the exercise. The data is on the downloads page.

Session 8 · Classification with logistic regression

The same nineteen-column table, with a label as the target: will the market be more volatile next month than this month? Where a straight line fails on a label, the curve that replaces it, the probabilities it gives, the confusion matrix, precision, recall and AUC, and the penalty's strength under its new name, C.

Prefer to work offline? Download this session's notebooks and data.

Session 9 · Classification in practice

What happens when the thing you predict is rare, where the threshold belongs once each mistake has a price, whether a probability of 0.3 means 0.3, a label with three classes instead of two, and a second classifier judged against the first on the same folds.

Prefer to work offline? Download this session's notebooks and data.

Session 10 · Electricity prices in West Denmark

Will tomorrow's price at this hour be higher than today's? Three years of hourly prices and wind forecasts for West Denmark, a bet on the direction with a trading cost, and k-nearest neighbours against logistic regression. Forecast eight hours at the start, revise them at the end, and see how you did against the models.

There are no exercises and no case for this session: the deck is the exercise. The data is on the downloads page.

Session 11 · Trees and forests

A model that asks questions instead of fitting slopes. How a tree chooses its cuts, why a deep tree fits the training days and misses the next ones, and how bagging and random forests average that away; then what a grid of settings costs to run, and a tree for a label.

Prefer to work offline? Download this session's notebooks and data.

Session 12 · Boosting and reading a model

Small trees added one at a time, each fitted to what the trees before it still get wrong. How many to add, chosen on later days instead of the test days; XGBoost and LightGBM, the libraries used in practice; and two ways to read which columns a model relies on. The case ends here, with every model of the report side by side.

Prefer to work offline? Download this session's notebooks and data.

Session 13 · The two cases with trees

The last session. The houses of Session 7 and the hours of Session 10 again, now with trees, forests and boosted trees: do the stronger models win, and by how much? Then what to weigh when choosing a model, from the time a fit takes to whether its answers can be explained, a short look back over the course, and time for questions about the exam.

There are no exercises and no case for this session. The data is on the downloads page.

Questions students ask

How do I keep my work in Colab?

Before you type anything, choose File → Save a copy in Drive. The copy is yours; the notebook the button opened is not, and closing its tab loses what you wrote in it.

Do I have to finish every exercise?

No. They are rated one to five stars, and the hints and full solutions are folded under each task. Do what you can, then the case.

Where are Parts 7, 10 and 13 of the case?

Parts are numbered by session, and Sessions 7, 10 and 13 are case lectures of their own, so they have none. The case page shows all twelve parts.

The first code cell of a lecture takes a while. Is it broken?

No. The page downloads Python into the browser first: 7 to 15 seconds on a good connection, longer on a slow one. Every cell after that is quick.

My number differs from the notebook's in the third decimal.

Your package versions differ from the course's. The install line on the setup page gives you the same versions; in Colab, Session 12's notebooks install the XGBoost they need by themselves.

Can I print a lecture?

Use its PDF instead: printing from the browser leaves out the results of the code cells. Every lecture's PDF is on its card above and on the Exam info page.

Can I work on my own laptop?

Yes, and the exam is written that way. The setup guide walks through Python, VS Code and the packages, and the downloads page has every notebook and data file.

What can I bring to the exam?

Anything that works offline and is not built on AI: your notes, the course materials and cheatsheet saved on your laptop, and VS Code's suggestion list (type df. and pick head). Nothing that needs the internet, and no AI, including AI code completion such as GitHub Copilot. The Exam info page has the details, a checklist and three mock exams.

I cannot remember a function.

The cheatsheet lists every function the course has used, one row each, and its filter finds one by name. Search looks through the lectures, exercises and glossary as well: press / on any page.