Python For Finance: Introduction and Basics of Python
Python For Finance: Introduction and Basics of Python
Andras Niedermayer
Outline
1 Introduction
2 Why Python?
5 Variables
7 Antigravity
• Andras Niedermayer
• Professor of Economics at Université Paris-Dauphine
• Co-founder and CTO of a fintech company (SolvencyAnalytics
AG) that uses Python for data analysis
• mail: [email protected]
• office: P135
• slides will be availabe at http://andras.niedermayer.ch
Textbook
Yan, Yuxing, Python for Finance: Build real-life Python application
for quantitative finance and financial engineering, 2014, Pack
Publishing
Other sources
• Python 3 documentation at: https://docs.python.org/3/.
• Stanford lectures at
http://web.stanford.edu/~arbenson/cme193.html
• UPenn lectures at
http://www.cis.upenn.edu/~cis192/spring2014/
• Forums such as http://stackoverflow.com/
Wednesday, January 9, 2019 Python for Finance - Lecture 1
Andras Niedermayer - Université Paris-Dauphine 4/45
Structure of Course
1 Introduction
2 Why Python?
5 Variables
7 Antigravity
1 Introduction
2 Why Python?
5 Variables
7 Antigravity
1 Introduction
2 Why Python?
5 Variables
7 Antigravity
In [1]: quit ()
In [1]: x =2
In [2]: X
------------------------------------------
---------------------------------
NameError
Traceback ( most recent call last )
< ipython - input -4 -253 bcac7dd80 > in < module >()
----> 1 X
Help!
In [1]: help ()
• Google + Stackoverflow
• http://python.org
• Excercise 1
In [1]: area = 3.14159 * 10**2
In [2]: area
Out [2]: 314.159
• Excercise 2
In [1]: diag = 2**0.5
In [2]: diag
Out [2]: 1.4142 135 62 37 30 95 1
• Excercise 3
In [1]: 127 + 127 + 127 + 127
Out [1]: 508
1 Introduction
2 Why Python?
5 Variables
7 Antigravity
Introspection:
In [1]: dir ()
Out [1]: [ ’ __builtin__ ’ , ’ __doc__ ’ ,
’ __name__ ’ , ’ __package__ ’]
Deleting a variable:
In [1]: a = 1
In [2]: dir ()
Out [2]: [ ’ __builtin__ ’ , ’ __doc__ ’ ,
’ __name__ ’ , ’ __package__ ’ , ’a ’]
In [3]: del a
In [4]: dir ()
Out [4]: [ ’ __builtin__ ’ , ’ __doc__ ’ ,
’ __name__ ’ , ’ __package__ ’]
1 Introduction
2 Why Python?
5 Variables
7 Antigravity
Basic Operations:
In [1]: 1+1
In [2]: 1 -2
In [3]: 2*2
In [4]: 3/2
In [5]: 3/2.
In [6]: 3//2.
In [7]: int (2.5)
1 Introduction
2 Why Python?
5 Variables
7 Antigravity
1 Introduction
2 Why Python?
5 Variables
7 Antigravity
But attention
In [1]: payment * pow (10 ,6)
Out [1]: 428571.428571 4285
In [2]: payment2 * pow (10 ,6)
Out [2]: 428600.0
But attention
In [1]: payment * pow (10 ,6)
Out [1]: 428571.428571 4285
In [2]: payment2 * pow (10 ,6)
Out [2]: 428600.0
In [1]: x = 5.566
In [2]: round (x ,2)
Out [2]: 5.57
• Excercise 4
In [1]: dir ( __builtins__ )
• Exercise 5
In [1]: s = ’ This is a simple exercise ’. upper ()
In [2]: print ( s )
• Excercise 6
In [1]: print ( ’ With {} students there will \
... : be {} groups with {} students and \
... : there will remain {}. ’. format (
... : 41 , 41//3 , 3 , 41%3))