This repository (https://github.com/gabrielepompa88/IT-For-Business-And-Finance-2019-20) provides course informations and material supporting the first year master course of IT For Business and Finance held at University of Siena in 2019/20.
WARNING: the course and this repository is under ongoing update.
Symbols conventions: updated sections/material in this README.md file will be highlited with 🔴 (a big red circle) displayed next to it.
- Objectives: To acquire practice in the use of financial models through Python programming language
- Contents: IT tools for modeling in Finance; Python
- Teaching Methods: Lessons in IT lab
- Verification of learning: written exam
- Learning Material:
- Textbook: Python for Finance, 2nd Edition, by Yves Hilpisch (O’Reilly). Copyright 2019 Yves Hilpisch, 978-1-492-02433-0.
- All the reading and programming resources are listed in the class github repository: IT-For-Business-And-Finance-2019-20
The e-learning for IT for Business and Finance course at http://elearning.unisi.it/moodle/ (more info to come) is now active. You can access with your unisiPass credentials at http://elearning.unisi.it/moodle/ and type "IT pompa" in the "Cerca Corso" search window (top right corner of screen). E-learning material is under ongoing production and addition.
- Exam dates: these below are the exam dates of the IT for Business and Finance course terms:
- Summer term – 1st session: Thursday June 4th, 2020 h 10:30 – 12:30
- Summer term – 2nd session: Monday June 29th, 2020 h 10:30 – 12:30
- Fall term – 1st session: Tuesday September 1st, 2020 h 10:30 – 12:30
- Fall term – 2nd session: Friday September 18th, 2020 h 10:30 -12:30
- Winter term - 2nd session: Friday February 12th, 2021 h 10:00 - 12:00
- March term - Monday March 15th, 2021 h 10:00 - 12:00
For additional informations see Exams section of Moodle page for IT for Business and Finance class
General Informations
On the exam date, at the beginning of the exam time window (next exam: Monday March 15th, 2021 at 10:00, Rome time, you will find attached an exam sheet to the specific exam activity section (next: March Term; The exam sheet is a Jupyter Notebook with questions/exercises and empty Code cells for your answers. A Jupyter Notebook is a file with .ipynb extension. It is the kind of file on which lecture notes have been delivered so far, so you should be already familiar with this (see Prerequisites);
Operational Instructions
Answer to the questions on the exam sheet offline, on your personal computer, following these operational instructions:
- download the exam sheet on your personal computer;
- move the exam sheet downloaded to the Exams sub-folder of your class folder (IT_For_Business_And_Finance_2019_20\Exams); (see Prerequisites)
- open the exam sheet using the Jupyter Notebook app of the Anaconda Navigator (see Prerequisites);
- answer to the exam questions directly on the exam sheet;
- once done, save and download (as Notebook) the exam sheet completed;
- before the end of the exam time window: upload the exam sheet as an attachement, using the dedicated upload form.
Prerequisites
These are the prerequisites you must fulfill before taking the exam: You should have already the latest updated version of the class folder IT_For_Business_And_Finance_2019_20 on your personal computer. You should have the Anaconda Navigator installed on your personal computer. Using the Jupyter Notebook application of the Anaconda Navigator, you should be able to (these are all step you should have already be well familiar with, if you have followed the class):
- navigate to the directory containing the notebook you want to open,
- open the notebook,
- making changes to it,
- run it,
- save it,
- download it (as Notebook .ipynb file).
As per exam, it will be assumed that all of you satisfy these prerequisites. Should you still be missing some of those, please follow these instructions on how to work this class: https://github.com/gabrielepompa88/IT-For-Business-And-Finance-2019-20/blob/master/How-to-work-this-class.md and please do let me know if you need assistance.
About the exam
- Exam questions can ask you to write code or answer theoretical questions.
- Comment extensively your code. A well written and commented code which does not run is more valuable (and will be graded accordingly) than a poorly written and not-commented code that does run.
- You can use whatever you want to do the exam (textbook, books, internet, etc.)
- In the exam sheet you will find further instructions to be followed. In particular: even if the exam sheet will be unique for everybody, you will be asked to use your unisi identification number unisi_id (e.g. 589160) in several ways to make it unique (for example: you might be asked to set the lenght of a NumPy array to the second digit (e.g. 8) of your unisi_id, or to input the full unisi_id as a seed for a random number generation, like: np.random.seed(589160) )
Extra
Upon suggestions, you may do some extra work and prepare a financial project . The following rules apply:
- The project is not compulsory and, in particulary, does not substitute the Exam;
- The project might be helpful for exam preparation and, in particular, for your future to show off your ability (to recruiters and/or hiring managers);
- The project shall take the form of the development of a personal GitHub repository, on the footprints of the class one;
- I will be happy (write me to take an appointment) to discuss with you project topics of mutual interest and to help you with the project;
For any question, I’m here to help you ([email protected], Skype: gabriele.pompa)
Exam: https://elearning.unisi.it/mod/assign/view.php?id=146803
Exam Schedule
Exam timing: Monday MArch 15th, 2021 h 10:00 - 12:00 (2 hours), Rome time;
Exam sheet: Exam_March_Term.ipynb (you'll find it attached by the beginning of the exam time-window: 10:00 Rome time);
Complete exam sheets must be submitted using this form before the end of the exam time-window: 12:00 Rome time).
Registrations are now open and will close on Monday March 8th, 2021.
Exam: https://elearning.unisi.it/mod/assign/view.php?id=139180
Exam Schedule
Exam timing: Friday February 12th, 2021 h 10:00 - 12:00 (2 hours), Rome time;
Exam sheet: II_Exam_Winter_Term.ipynb (you'll find it attached by the beginning of the exam time-window: 10:00 Rome time);
Complete exam sheets must be submitted using this form before the end of the exam time-window: 12:00 Rome time).
Registrations are now open and will close on Sunday February 7th, 2021.
Exam: https://elearning.unisi.it/mod/assign/view.php?id=112760
Exam Schedule
Exam timing: Friday September 18th, 2020 h 10:30 - 12:30 (2 hours), Rome time;
Exam sheet: II_Exam_Fall_Term.ipynb (you'll find it attached by the beginning of the exam time-window: 10:30 Rome time);
Complete exam sheets must be submitted using this form before the end of the exam time-window: 12:30 Rome time).
Registrations are now open and will close on Wednesday September 16th, 2020.
Exam: https://elearning.unisi.it/mod/assign/view.php?id=106971
Exam Schedule
Exam timing: Monday June 29th, 2020 h 10:30 - 12:30 (2 hours), Rome time;
Exam sheet: II_Exam_Summer_Term.ipynb (you'll find it attached by the beginning of the exam time-window: 10:30 Rome time);
Complete exam sheets must be submitted using this form before the end of the exam time-window: 12:30 Rome time).
Registrations are closed.
Exam: https://elearning.unisi.it/mod/assign/view.php?id=104104
Exam Schedule
Exam timing: Thursday June 4th, 2020 h 10:30 - 12:30 (2 hours), Rome time;
Exam sheet: I_Exam_Summer_Term.ipynb (you'll find it attached by the beginning of the exam time-window: 10:30 Rome time);
Complete exam sheets must be submitted using this form before the end of the exam time-window: 12:30 Rome time).
Registrations are closed.
Classes start on Monday, February 24 2020 at 14:00 in Aula informatica 1. The timetable is:
Monday: 14:00-16:00
Tuesday: 18:00-19:30 this lesson starts sharply at 18:00
Wednesday: 14:00-16:00
Currently known amendements to this schedule are the following:
Monday 16/3: Aula 1
Wednesday 4/3 and 18/3: Aula 12
Gabriele Pompa ([email protected])
This is the diary of the class. Here the topics covered during the lessons are listed, as well as the corresponding reading material.
Conventions for reading material: sections from
A. the TextBook Python for Finance (2nd ed.) are labelled as TB.ChapterNumber.SectionName to refer to a whole Section (e.g. TB.1.The Python Programming Language) or as TB.ChapterNumber.SubSectionName to refer to a particular sub-Section (e.g. TB.1.Data-Driven Finance ).
B. the Python Tutorial are labelled as PyT.SectionNumber.SubSectionNumber.SubSubSectionNumber (SubSubSectionName)_ (e.g.: section 3.1.2 on Strings is labelled PyT.3.1.2 (Strings) ).
C. the Numpy Quickstart Tutorial are labelled as Numpy Quickstart Tutorial - SectionName (list of SubSections).
D. the Pandas - Getting started tutorials are mentioned by section name (e.g.: What kind of data does pandas handle?).
Below the list of lessons with relevant related material:
-
Lesson 1 (24/02): class presentation. introduction to: programming in Python, Anaconda platform, Jupyter Notebooks and interactive programming, Spyder IDE and programmatic programming, Python modules and
import
expressions. -
Lesson 2 (25/02): motivations for adopting Python in Finance.
- TB.1.Python for Finance, TB.1.Data-Driven Finance, TB.2.Basic Operations with conda, TB.2.conda as a Virtual Environment Manager.
-
Lesson 3 (26/02): random number generation. Histogram. Empirical distribution (normalized histogram). Template for
.py
files (scripts) in Spyder.- Spyder Template file template_example.py: use this file as a template example. Any script (
.py
file) that you write in Spyder IDE has to follow the structure of this template. - Lecture Notes Introduction II .ipynb | .pdf: Sec. 1, 2, 3.
- Spyder Template file template_example.py: use this file as a template example. Any script (
-
Lesson 4 (2/03):
int
data type,.bit_length()
method forint
, binary representation of integers (examples).float
data type, issues of finite precision of internal binary representation of decimal numbers, arbitrary precision in Python (Decimal
module). Normal random variables in Python (Scipynorm
class),.pdf()
method ofnorm
class, Normal fit to empirical distribution,.fit()
method ofnorm
class. -
μετα-Lesson 5 (3/03): gentle introduction to github. Teacher-Student(s) workflow (push-pull flow). Edit - Stage (
git add
) - Commit (git commit
) pattern. Setup of a local development clone of a repository already established (hands-on example:git clone
of the class repository into computers of Aula Informatica 1). Syncing local clone with updated class repository (the hard way) withgit fetch
andgit reset
. -
Lesson 6 (4/03): how to work this class, class/home study work-flow, how to take notes in class and at home (the
Personal_Notes
personal folder). Random number generation: Normal fit of a distribution, higher moments of a distribution (Skewness and Kurtosis), sample skewness and kurtosis, Jarque-Bera test of Normality, null-hypothesis and use of p-value of a test for decision-making.- How To Work This Class tutorial.
- Lecture Notes Introduction II .ipynb | .pdf:: Sec. 5 and 6.
-
Lesson 7 (9/03): introduction to the e-learning platform moodle.
bool
data type,while
loop,if
statement.str
data type (definition, indexing, slicing). -
Lesson 8 (10/03): introduction to data-structures in Python,
tuple
data structure,list
data structure,for
loop,dict
data structure,set
data structure.- TB.3.Basic Data Structures (TB.3.Excursus: Functional Programming is optional reading).
- PyT.3.1.3 (Lists), PyT.4.2 (for Statements), PyT.4.3 (The range() Function), PyT.4.4 (break and continue Statemenents, and else Clauses on Loops), PyT.5.1 (More on Lists), PyT.5.3 (Tuples and Sequences), PyT.5.4 (Sets), PyT.5.5 (Dictionaries).
- Lecture Notes Basics_II___Data_Structures .ipynb | .pdf
- Videos:
-
Lesson 9 (11/03): NumPy
ndarray
data-structure: arrays creation, indexing, slicing, iterating over arrays, basic operations, built-in methods, universal functions, shape manipulation, stacking of arrays- TB.4.Regular Numpy Arrays, TB.4.Basic Vectorization.
- Numpy Quickstart Tutorial - The Basics (An Example; Array Creation; Printing Arrays; Basic Operations; Universal Functions; Indexing, Slicing and Iterating), Numpy Quickstart Tutorial - Shape Manipulation (Changing the shape of an array; Stacking together different arrays), Numpy Quickstart Tutorial - Indexing with Boolean Arrays (boolean arrays and how to use to do conditional selection).
- Lecture Notes Numerical_Computing___Numpy_Arrays .ipynb | .pdf
- Exercises: Exercise Sheet 1 - ERRATA CORRIGE (Exercise 5) - Solutions: Ex_1, Ex_2, Ex_3, Ex_4, Ex_5
- Exercises: Exercise Sheet 2 - Solutions: Ex_1, Ex_2, Ex_3, Ex_4, Ex_5, Ex_6, Ex_7
- Videos:
-
Lesson 10 (16/03): Pandas
Series
data-structure: creation from 1-dim NumPy array usingpd.Series()
constructor, indexing and slicing using[]
access operator, basic plotting, basic analytics, built-in methods, interface with NumPy's universal functions. Returns time-series: log-normal i.i.d. time-series (using NumPy'srandom.lognormal
function), step-by-step computation, direct computation using.shift()
, linear and log-returns.- TB.5.The Series Class.
- Pandas - Intro to data structures - Series.
- Lecture Notes Data_Analysis___Introduction_to_Pandas .ipynb | .pdf: Sec. 1. Series.
- Exercises: Exercise Sheet 3 - Solutions: Ex_1, Ex_2, Ex_3, Ex_4, Ex_5
- Videos:
-
Lesson 11 (18/03): Pandas
DataFrame
data-structure: creation from multi-dim NumPy array usingpd.DataFrame()
constructor, columns selection using[]
access operator, indexing and slicing of rows and columns using.loc[]
and.iloc[]
access operators, basic plotting, creation and deletion of columns, basic analytics on row- and column-wise base and.groupby()
method, built-in methods, interface with NumPy's universal functions. Concatenation, Joining and Merging of two DataFrames using.join()
method andpd.merge()
function.- TB.5.The DataFrame Class, TB.5.Basic Analytics, TB.5.Basic Visualization, TB.5.Complex Selection, TB.5.Concatenation, Joining, and Merging, TB.5.Performance Aspects.
- Pandas - Intro to data structures - DataFrame. From Pandas - Getting started tutorials:
- Lecture Notes Data_Analysis___Introduction_to_Pandas .ipynb | .pdf: Sec. 2. DataFrames.
- Exercises: Exercise Sheet 4 - Solutions: Ex_1, Ex_2, Ex_3, Ex_4
- Videos:
-
Lesson 12 (30/03): Python serializations protocols: JSON (
json
module) and Pickle (pickle
module). IO operations in Pandas with output formats (.to_*()
DataFrame methods andpd.read_*()
function): SQL (SQLite engine andsqlite3
module), CSV and Excel.- TB.9.Basic I/O with Python, TB.9.I/O with Pandas.
- PyT.7.1.2 (the String
.format()
method), PyT.7.2 (reading and writing files). - From Pandas - Getting started tutorials:
- Lecture Notes Data_Analysis___IO_with_Pandas .ipynb | .pdf.
- Exercises: practice with I/O operations using the lesson Notebook. Focus on doing I/O of Pandas DataFrames in CSV format.
- Videos:
-
Lesson 13 (01/04):
yfinance
API: installation, Yahoo! Finance tickers lookup page. Basic usage: get market and meta data for one (yf.Ticker()
) and multiple (yf.Tickers()
) security/s, mass download of market data (yf.download()
).- yfinance library:
- Github page for yfinance library: https://github.com/ranaroussi/yfinance;
- Blog post form the author (Ran Aroussi) with a yfinance tutorial: https://aroussi.com/post/python-yahoo-finance.
- Lecture Notes Data Analysis - Financial Time Series .ipynb | [.pdf]: Section 1.Introduction to yfinance library
- Exercises: practice with
yfinance
API:- download ticker data for "General Electric Company" stock from Jan 1st, 1985;
- save its "Close" price Pandas Series as a 'GE_Close_Price.csv' file in
/Data
folder; - open both the 'Securities_Close_Price_Dataset.csv' and the, just saved 'GE_Close_Price.csv';
- integrate GE Close price data with other data as an additional column 'GE' of the
closePrice
DataFrame in 'Securities_Close_Price_Dataset.csv' file; - save the extended
closePrice
DataFrame as 'Extended_Securities_Close_Price_Dataset.csv' file.
- Videos:
- yfinance library:
-
Lesson 14 (06/04): Data Analysis: first look at DataFrame (
.head()
,.tail()
and.plot()
methods), buy-and-hold portfolio, summary statistics, returns: simple (.pct_change()
method) and log-returns (.shift()
method), resampling (.resample()
method), graphical test of normality (Normal fit, Q-Q plot), rolling statistics (.rolling()
method), rolling correlation matrix (not for exam), SPX/VIX inverse relationship analysis: OLS regression (np.polyfit()
function), correlation analysis.- TB.8.Financial Data, TB.8Rolling Statistics, TB.8.Correlation Analysis, TB.13.Real-World Data.
- Lecture Notes Data Analysis - Financial Time Series .ipynb | [.pdf]: Section 2.Data Analysis
- Exercises:
- practice on the Data Analysis (summary statistics, returns, resampling, rolling statistics etc.) topics covered using the 'Extended_Securities_Close_Price_Dataset.csv' file, which includes closing prices for the 'GE' Stock;
- In particular: do the graphical tests of normality (histogram, normal fit and Q-Q plot) on the 'GE' stock. Do this in a script file named 'GE_Returns_Graphical_Normality_Tests.py' and save it in the 'Scripts' folder (Hint: you can modify SPX_Returns_Graphical_Normality_Tests.py which you can find in the 'Scripts' folder already)
- Videos:
-
Lesson 15 (08/04): introduction to Object-Oriented Programming (OOP) paradygm. Non-financial example (
Person
class). Call-option Black-Scholes pricer (CallOption
class). Encapsulation: name hiding, getters and setters methods. GeneralPlainVanillaOption
class to price put options too.- TB.6.Object-Oriented Programming, TB.Appendinx A. Dates and Times. (Python section)
- Object-Oriented Programming in Python: Section Classes
- Lecture Notes Derivatives Analytics - Introduction to Object Oriented Programming .ipynb | [.pdf].
- Videos:
-
Lesson 16 (15/04): digital Cash-Or-Nothing options. Inheritance. Polymorphism: in functions, in classes methods. Polymorphism in overridden methods. Abstract classes.
- TB.6.Object-Oriented Programming
- Object-Oriented Programming in Python: Section Object-oriented programming
- Lecture Notes Derivatives Analytics - Inheritance and Polymorphism .ipynb | [.pdf].
- Videos: - Playlist: Lesson 16 - Inheritance and Polymorphism
-
Lesson 17 (17/04): default parameters in functions; optional parameters:
*args
,**kwargs
, input flexibility and agnostic flow in functions and classes. Objects Composition and Aggregation. P&L computation (.PnL()
method). Portfolio of options (Portfolio
). Plotting functionalities (Plotter
class and sub-classes for single options and portfolios of options). Option Strategies: short positions, Bull Spread (synthtetic cash-or-nothing digital replication), Straddle, Calendar Spread- TB.6.Object-Oriented Programming
- Object-Oriented Programming in Python: From Errors and exceptions: Errors and Handling exceptions sections. From Functions: up to
*args
and**kwargs
section. Section Object-oriented programming - Lecture Notes Lecture Notes Derivatives Analytics - Objects Composition .ipynb | [.pdf].
- Videos:
-
🔴 BONUS Lesson 18 - NOT FOR THE EXAM: Option greeks: Black-Scholes analytic greeks for plain-vanilla and digital optinos. Numeric derivatives (finite-differences methods,
NumericDerivatives
class). Root-finding: Newton-Rhapsod method, implied volatility estimation. Introduction topyBlackScholesAnalytics
Python package.- Lecture Notes Derivatives Analytics - Objects Composition .ipynb | [.pdf].
- Videos:
- Textbook: Python for Finance -- Mastering Data-Driven Finance (2nd edition) by Yves Hilpisch (O'Reilly).
-
Python tutorial: Python 3.7 online tutorial.
-
Numpy tutorial(s):
-
Scipy tutorial: Scipy Tutorial
-
Pandas tutorial(s):
-
Other useful resources online: Beginner's Guide To Python.
-
Tutorial from Guido van Rossum (Python's first developer): Python Tutorial Release 3.7.0 (September 02, 2018).
-
Anaconda platform is a free and open-source distribution of the Python and R programming languages for scientific computing (data science, machine learning applications, large-scale data processing, predictive analytics, etc.), that aims to simplify package management and deployment. Package versions are managed by the package management system
conda
The Anaconda distribution includes data-science packages suitable for Windows, Linux, and MacOS (quoting wikipedia page)Tips:
-
Jupyter Notebooks (included in Anaconda distribution) is a web-based interactive computational environment for creating Jupyter notebook documents (quoting wikipedia page)
Tips:
-
Spyder IDE (also shipped with Anaconda distribution) is an open source integrated development environment (IDE) for scientific programming in the Python language (quoting wikipedia page)
This section describes practical informations on how to work this class. Daily activities and once-for-all setup(s) are separately described both for in-class lessons and study from-home.
-
For a step-by-step guide see How-to-work-this-class.md file. Take a look at it if you are new to the class.
-
For the checklist version of the same file see How-to-work-this-class - checklist version.md file. This file serves as a quick reference in case you forgot something.
Feel free to contact me at [email protected] in case something is not clear or if you spot errors or if you have suggestions for improvement. Thanks.