Search for contacts, projects,
courses and publications

Programming in Finance and Economics I


Gruber P.

Course director


The course is structured along computational concepts, not applications.

The topics include

  • Recap of basic R: variables, types, operators and main commands
  • How computers calculate: floating point numbers
  • Modular programming: User-defined functions and loops
  • Working with data in R, data sources and data APIs
  • A short introduction to numerical algorithms
  • Random number generation and simple simulations
  • Optimization
  • Finding and installing R packages
  • How to write a successful program or an entire research report in R
  • Finding errors and improving R programs



This course requires basic knowledge of a programming language, as specified in the admission criteria to the Master in Finance. For USI bachelor graduates, Informatica I is sufficient. Students from other universities require a similar introduction to programming. Students with little or no programming experience in R have to follow a tutorial before the start of the semester.


Many interesting problems in economics and finance can only be solved with the help of the computer, as no analytical solution exist or large amounts of data are involved. This course teaches how to solve quantitative problems with the help of R, a powerful and widely used open source programming environment.

The course has the following goals:

  • Learn the most important elements of the R language
  • Understand the differences between analytical and numerical problem solving
  • Learn how to translate mathematical or statistical problems into the R language
  • Learn how to organize data efficiently with the help of R
  • Learn how to write efficient and durable R programs

After this course, students should be able and confident to use R independently for project work, courses such as numerical methods or for their master thesis.

Teaching mode

In presence

Learning methods

The course is organized in seven blocks of four hours. Each block introduces a new concept and employs learning-by-doing to move from theory to practice. Students start with short online tutorial before each class (flipped classroom). The course block itself starts with a presentation of a new concept. Next, we study a sample R program that illustrates this concept and try to understand the underlying ideas. Students will then train their skills with programming exercises that are submitted to an online system that provides instant feedback.

Students should bring a laptop with R and R Studio installed to all classes.

This class is generously supported by Datacamp.

Examination information

10% participation in online tutorials

  • Grading is based on timely completion

30% individual programming exercises during the course phase

  • Grading is based on the correctness of the results and on programming style
    • Students receive automatic feedback and have multiple chances to submit their solution
    • At each subsequent submission, a small deduction in points is performed

60% programming project in small groups, due at the end of the semester

  • Grading is based on four criteria:
    • Completeness and correctness (Does the program work, produce correct results and perform all the tasks required?)
    • Programming style (Is the program written elegantly, efficiently and well documented?)
    • User documentation (Completeness, style)
    • Complexity of the problem and the solution (Are requirements over/under satisfied in a relevant way?)