0% found this document useful (0 votes)
112 views16 pages

Python For Quantitative Finance

Python is an interpreted, general-purpose programming language that has become the standard for scientific computing and quantitative finance due to its simplicity, open source nature, and a vast number of libraries. It is typically installed through distributions like Anaconda, which include Python, package management and environment tools, and popular scientific libraries such as NumPy, SciPy, and matplotlib. Python can be used by professional developers, scientists.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views16 pages

Python For Quantitative Finance

Python is an interpreted, general-purpose programming language that has become the standard for scientific computing and quantitative finance due to its simplicity, open source nature, and a vast number of libraries. It is typically installed through distributions like Anaconda, which include Python, package management and environment tools, and popular scientific libraries such as NumPy, SciPy, and matplotlib. Python can be used by professional developers, scientists.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python for Finance

Quantitative
Introduction, why Python, environment, structure, installations
Introduction
Python was initially developed by Guido van Rossum in the
1990s who was a big fan of Monty Python's Flying
Circus1, so the name has no connection with any major
snake
Python is a dynamic and interpreted programming language.
(compiled in bytecode) general purpose
This means that we can write statements in the interpreter and they are executed.
immediately unlike other languages such as Java and C that are
compiled languages
1A series
of comedic sketches by the BBC aired in the late 60s and early 70s, conceived, written, and performed by the comedy geniuses known collectively as
Monty Python (or simply The Pythons)

Gabriela Facciano, FRM, CQF 2


Interpreted language vs compiled
Interpreted Compiled
The programs run in a manner It is the most conventional language.
indirectly through a program Programs are converted into code
interpreter that reads the source code and it
translate in motion, in a series of machine through a compiler and
calculations and system calls then they are executed directly. This
executable file can run without
The source code must be need to consult the source code.
reinterpretation (and the interpreter present) They offer excellent performance with a
each time the code is executed limited access to the operating system and to
Slower than the compiled version, with access underlying hardware
limited to the operating system and the hardware They can be difficult to program
underlying Most of the software we use
Easier to program is delivered as compiled binaries, from a
Less strict with errors of software that the user does not see
coding

Gabriela Facciano, FRM, CQF 3


Why Python?
Python is quickly becoming the standard of computing
scientific, receiving a lot of attention the application of Python to finance
mathematics
Its appeal continues to grow both in the academic world and in
industry. Its characteristics include:
Very simple language to learn and easy to maintain
Open source and free language
Increasing number of complementary modules (add-ons)
•Multiplatform: available on Windows, Mac OS, Linux and almost all systems
operating systems (also Android) used by Google, YouTube, Instagram, NASA, CERN,
Disney
Especially easy to interconnect with C++
Powerful language that can be widely used to solve problems of
finance, economics and data analysis

Gabriela Facciano, FRM, CQF 4


Some characteristics
Open source
Python and most of the available libraries and supporting tools are
open source and generally come with fairly flexible and open licenses
Interpreted
The reference implementation of CPython is an interpreter of the language that translates
the Python code at runtime to executable bytecode
Multiparadigm
Python supports different programming and implementation paradigms, such as
object-oriented and imperative, functional or procedural programming
Multipurpose
Python can be used for rapid and interactive code development, as well as for
large-scale applications; can be used for low system operations
low-level programming, as well as for high-level analysis tasks

Gabriela Facciano, FRM, CQF 5


Some characteristics
Multiplatform
Python is available for the major operating systems, such as Windows,
Linux and macOS. It is used to create desktop applications and web applications.
and it can be used in larger clusters and more servers, thus
like on devices as small as the Raspberry Pi
Dynamic writing
Types in Python are generally inferred at runtime and are not declared.
statically like in most compiled languages
•Consciente de la sangría
Unlike most other programming languages, Python uses indentation.
to mark the code blocks instead of parentheses, brackets or semicolons
•Recolección de basura
Python has automated garbage collection, eliminating the need for
programmer manage memory cleanup

Gabriela Facciano, FRM, CQF 6


The Python ecosystem
Availability of a large number of packages and tools
They generally have to be imported.
Importing means making a package available to the current namespace and process.
current interpretation of Python
Python itself comes with a large set of packages and modules that
they improve the basic interpreter in different directions
Python Standard Library
For example, basic mathematical calculations can be performed without any import.
while more specialized mathematical functions must be imported through the
modulomath
Examples of libraries
•NumPy and SciPy: general mathematical tools
EarthPy: earth sciences
AstroPy: Astronomy
Pygame: writing video games; supports art, music, sound, video projects, mouse interaction
and the keyboard

Gabriela Facciano, FRM, CQF 7


The Python ecosystem
There are different distributions of Python (official Python, Anaconda Python,
Enthought Canopy, pythonxy
Each distribution provides specific tools: editors, pre-installed packages,
support for a specific platform, etc.
IPython was originally released in two popular versions: a version of
shelly another browser-based one (the Notebook)
What does the term shell mean?
In computing, the shell, command interpreter, or command line interpreter is the computer program that
provides a user interface to access the services of the operating system.
The notebook variant turned out to be so useful and popular that it evolved into
become an independent and language-agnostic project, now called
Jupyter
Considering these antecedentes, it is not surprising that Jupyter Notebook
Here are most of the beneficial features of IPython, and it offers a lot.
more, for example, regarding visualization

Gabriela Facciano, FRM, CQF 8


The battery scientific libraries
NumPy
Provides a multidimensional array object to store homogeneous or heterogeneous data.
It also provides optimized functions/methods to operate on this array object.
SciPy
It is a collection of subpackages and functions that implement important standard functionalities often needed in
science or finance
For example, there are functions for cubic spline interpolation as well as for numerical integration.
matplotlib
Most popular plotting and visualization package for Python, which provides visualization capabilities in both 2D and
in 3D
pandas
It is based on NumPy and provides richer classes to manage and analyze time series and tabular data.
It is closely integrated with matplotlib for plotting and PyTables for data storage and retrieval.
scikit-learn
Popular Machine Learning (ML) package that provides a unified application programming interface (API) for
many different ML algorithms, such as for estimation, classification, or clustering

Gabriela Facciano, FRM, CQF 9


The spectrum of users
Professional software developers
•Desarrolladores científicos o los expertos en la materia
Occasional programmers
Beginner programmers

Gabriela Facciano, FRM, CQF 10


Installing Python
We will use Anaconda for its simple interface.
It is an open-source data science platform from CONTINUUM.
that has many tools
a Python distribution,
a package manager conda,
a way to manage the environment and
many libraries and pre-installed packages: for example, NumPy, SciPy, and Jupyter notebooks
The use of Anaconda greatly facilitates the learning process and prevents
many problems faced by new Python programmers
And what is more important, it is excellent for classroom teaching.
To download it, simply search for Python Anaconda on Google and you will be taken to
[Link]

Gabriela Facciano, FRM, CQF 11


Installing Anaconda

Gabriela Facciano, FRM, CQF 12


How to know if your PC/laptop is a system of
32 or 64 bits?
•Linux uname -a and if you see x64 then 64-bit otherwise 32-bit
•Mac uname -a also
•Windows click on Start, right-click on My Computer and
then click on Properties if you see 64 bits it is a 64-bit system
Windows 11 click on Start, click on System, click on Information

Gabriela Facciano, FRM, CQF 13


Anaconda

Gabriela Facciano, FRM, CQF 14


What is Jupyter Notebook?
The Jupyter Notebook (formerly known as IPython) is a web application
that allows creating and sharing documents that contain live code,
equations, visualizations, and explanatory text
Its uses include: data cleaning and transformation, numerical simulation,
statistical modeling, machine learning, and much, much more
Notebooks have the .ipnb extension, although it is possible to save them a
file .py or other formats (pdf, html)
Using a Jupyter Notebook has a number of advantages:
It is interactive
It is easy to document and share the results
You can access multiple kernels (or languages, for example, R)

Gabriela Facciano, FRM, CQF 15


Google Colab
Google Colab or Google Colaboratory is a new interface for running code.
Python created by Google
Notebooks can easily be shared with others to collaborate (hence the name) in the
programming project
The platform is free and can be accessed using a Gmail account.
• Paso 1: Crear un Drive en [Link]
Step 2: Once the Drive is created, you can access the new tab and can
access multiple kernels (languages - for example, R)
By clicking the New tab to create a new document using the Google option, there are
What to look for in Google's Colaboratory, usually found in the option further down.
Once Google Colaboratory is found, it can be selected.
Step 3: Name the notebook by clicking next to the ipynb located at the side
upper right

Gabriela Facciano, FRM, CQF 16

You might also like