💹 Financial Programming in R (MPhil F540 Classes)

Table of Contents

Class Content

By the end of these classes, students should be able to implement straightforward applications of asset management theory in R on their own. The focus of this course is on independence, giving students the general skills in R and knowledge of applications necessary for further research and employment in asset management and finance more generally.

What you will learn

  • Class 1 (Week 4) – Introduction to Financial Programming in R
    • The very basics of R (illustrated by the first exercise)
    • Data sources at Cambridge [still needs section on Capital IQ]
    • Loading financial data into R, basic financial manipulations
  • Class 2 (Week 5) – Mean-Variance Portfolio Optimisation in R
    • Plots
    • Building portfolios, Sharpe ratio tests, backtesting
    • PortfolioAnalytics
  • Class 3 (Week 6) – Portfolio Optimisation in R
    • Mean-variance efficiency and spanning tests
    • Parametric portfolio policies (PPP)
    • Regression-based portfolio optimisation
  • Class 4 (Week 7) – Risk Measures and Classical Factor Models
    • Covariance estimation; Gerber statistic, Value at Risk, Maximum Drawdown
    • Reward-to-risk ratios
    • Fama-French factor models
  • Class 5 (Week 8) – Statistical Factor Models and Machine Learning
    • Random forests
    • Causal machine learning

Class structure

  • Exercises, similar to the applications studied in class, will be distributed at the end of each class.
  • Classes will be divided into a lecture part and an office hour part at the end. The office hour part can be used to:
    • Ask questions about material from the lecture part
    • Start work on the exercises (bring your laptop if you want to do this), and ask questions as needed
    • Ask questions about previous weeks’ exercises
  • Feel free to stay after the lecture part to listen to others’ questions.
  • Exercises will not be marked, but full solutions will be distributed.


Take-home project with theory and applied section in R (usually 12 days). The project solution should preferably be written in R Markdown and must be fully reproducible from the submitted code.


Are there prerequisites?

There are no formal requisites. Any students enrolled in any of the MPhil programmes organised by the Faculy of Economics can take this course as an optional module. We do however require that students familiarise themselves with R before the start of the course, e.g. by taking R Programming course on Coursera.

How many lectures and classes are there?

16 lectures are held in week 1-8 of Lent term. Professor Mark Salmon explains the theory behind asset management in those lectures and discusses topical papers. In 2021, there are five R classes, which occur weekly from week 4 to 8 of Lent term. After the classes, students have the chance to ask questions during the office hour.