COMPUTATIONAL TOOLS FOR FINANCE Single channel
Chair (Coordinator) and Rapporteur: FRANCESCA PANERO
Lecturers
Objectives
The course gradually introduces students to applied programming and the simulation of random phenomena in financial contexts, starting from the fundamentals of programming and requiring no prior experience. It provides skills in formalizing uncertainty, implementing probabilistic and stochastic models, and using simulation methods to analyze and interpret the dynamics of financial phenomena. By the end of the course, students will be familiar with the main probabilistic and stochastic models used to formalize problems under uncertainty and will be able to implement simulation models to study financial processes. They will develop practical skills in programming languages and applications to perform simulations and compare numerical results with analytical solutions. Students will be able to independently identify the most appropriate model for studying each financial phenomenon, analyze and understand financial dynamics, and assess the reliability and appropriateness of the results within the considered context. They will be able to communicate rigorously using precise formal language, clearly articulating hypotheses, results, and insights. Finally, students will have acquired a solid foundational knowledge and a systematic study method, essential for understanding more advanced techniques of quantitative modeling and simulation.
Learning outcomes
The course gradually introduces students to applied programming and the simulation of random phenomena in financial contexts.
1) Knowledge and understanding. By the end of the course, students will know how to use the Python programming language to implement basic functions in probability theory and stochastic processes. This will enable them to analyse data and simulate economic, financial, and insurance scenarios. They will also be able to analyse and interpret, through simulations of such random processes, the outcomes of the phenomena under study. This ability to simulate and interpret will give them a new perspective on the meaning of probability, shifting from a more theoretical understanding to a more applied one.
2) Applying knowledge and understanding. By the end of the course, students will have acquired greater knowledge of programming, particularly in Python. Through both theoretical and practical knowledge of simulating the main models used in probability theory and stochastic processes, students will be able to understand the dynamics of financial phenomena and better interpret their characteristics. Furthermore, their knowledge of programming will enable them to simulate and verify the results of problems that will first be solved analytically.
3) Independent judgement. Through solving probability exercises using simulation techniques, students will learn to independently identify appropriate models to describe various random phenomena of a financial nature. They will also be able to numerically calculate the main parameters associated with these models and correctly interpret their meaning.
4) Communication skills. In order to handle both programming concepts in Python and probabilistic concepts, students must become accustomed to expressing themselves rigorously, correctly formalising intuitions and being able to articulate them both orally and in writing. To this end, all lessons will take place in computer labs, and the lecturer will continuously encourage student interaction.
5) Learning skills. The programming tools and probabilistic models developed during the course will provide students with the necessary skills for an analytical approach to the use of predictive and explanatory models in the financial sector. Additionally, students will be able to properly assess the uncertainty associated with forecasts made using statistical and econometric-financial models. Finally, their knowledge of Python and programming more broadly will be crucial not only for entering the job market, but also for accessing advanced studies.
Prerequisites
Some programming experience (not necessarily in Python) is beneficial but not necessary.
Basic notions of probability and statistics are required (those of probability will be developed during the course of Probability and Stochastic Processes).
Programme
The course will focus on learning the basics of the Python programming language, especially applied to probability and statistics.
In the first weeks, we will work our way through the main variables used in the language, such as arrays, matrices, lists, dictionaries and data frames, and the main operations on them. We will then introduce the concepts of for and while loops and the if and else statements, which will allow us to understand and build new functions on the data structures. We will show how to use the main plot functions on the structures of our interest.
The focus will then shift on the applications of these concepts to probability and statistics, by learning how to generate and manipulate random variables, simulate probabilistic experiments, estimate the parameters of statistical models and manipulate simulated or real datasets.
The main packages used will be NumPy, SciPy, pandas, matplotlib and seaborn.
This course is complementary to the course of Probability and Stochastic Processes.
Books
https://www.python.org
All the material can be found on Moodle (https://elearning.uniroma1.it/course/view.php?id=20210 password: CTF_panero_202526)
Lessons mode
The lessons will be held in person, in a computer lab equipped with computers.
Frequency
Attendance is not mandatory, but highly suggested.
Exam mode
Students can complete short exercises during the lectures. These will be evaluated by the teacher and upon sufficient completion of at least half of the sessions, the student will be considered "idoneo" (pass). Otherwise, students can attend the exam session. The exam will be practical and involve solving a set of programming exercises on paper, for 1 hour.
Regarding the exam question examples, question 1 reaches level 1 of Bloom's taxonomy ("Remember") and contributes to achieving a passing grade (18/30). Question 2 reaches levels 2/3 of Bloom's taxonomy ("Understand/Apply"); answering this question contributes to achieving an intermediate grade (up to 26/30). Question 3 reaches levels 4/5 of Bloom's taxonomy ("Analyze/Evaluate"); answering this question contributes to achieving the maximum grade (30/30 cum laude).
Example exam questions
1. Consider the following code.
num_experiment = 100
X = stats.randint(1, 11)
y = []
for i in range(num_experiment):
x = X.rvs(20)
y.append(np.max(x))
a = np.mean(y)
- Which type of variable is y?
- What probability concept does the variable a store?
2. Complete the following code to simulate a random sample of 100 elements from a Binomial(10, 1/2) and extract its empirical probability mass function from the histogram function (you need to specify the name of the function to plot a histogram and the arguments indicated).
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
X = ................... # define the binomial random variable
x = ................... # sample 100 values from X
pmf, _, _ = ...........(x, range=.............., bins=.............., density=..............) # histogram
3. Consider the following code that imports some stock prices from a platform.
import pandas as pd
import datetime as dt
import yfinance as yf
start = dt.datetime(2020, 1, 1)
end = dt.datetime(2024, 12, 31)
aapl = yf.download("AAPL", start, end) # Download historical data
x = aapl["Close"].pct_change()
stats.kstest(x, .............., args=(..............., ..............))
- What does the variable x contain?
- Complete the line that performs a Kolmogorov-Smirnov test to check the normality of x.
- Log returns are defined as ššš(Price_š”/Price_š”ā1) . Compute them as a function of your dataframe returns. Then, plot the histogram of the log returns and overlay it with the pdf of a normal distribution with mean and standard deviation estimated from the data.
More questions are published on the Moodle webpage of the course (https://elearning.uniroma1.it/course/view.php?id=20210 password: CTF_panero_202526).
Arguments
- Lecture 1-3: Variable assignment, calculator, lists, arrays, while loop, ifĀ else statement, for loops, functions, plot
- Lecture 4: Databases with pandas, time series
- Lectures 5-6, 10-11: discrete and continuous random variables
- Lectures 7-8: kernel density estimation and OLS
- Lecture 9:Ā central limit theorem, law of large numbers
- Lecture 12: random walk
Sustainability goals
- Academic year2026/2027
- Degree program to which the course belongsFinance and insurance
- Lesson codeAAF1946
- Year and semester1st year - 1st semester
- Activity typeUlteriori attivitĆ formative (art.10, comma 5, lettera d)
- Academic areaAltre conoscenze utili per l'inserimento nel mondo del lavoro
- Mandatory presenceNo
- LanguageENG
- CFU3 CFU
- Total duration24 hours
- Hours distribution24 classroom hours