# Financial Modeling in Python  ## What is Financial Modeling in Python?

Financial Modeling in Python refers to the method that is used to build a financial model using high-level python programming language that has a rich collection of built-in data types. This language can be used for modification and analysis of excel spreadsheets as well as automation of certain tasks that exhibit repetition. Given that financial models use spreadsheets extensively, Python has become one of the most popular programming languages in the field of finance.

### PPF Package for Python

The PPF package or library refers to the Python package that comprises a family of sub-packages. In other words, it is a mixture of various supporting extension modules that facilitate the implementation of Python programming. Please find below the summary of the various PPF sub-packages: For eg:
Source: Financial Modeling in Python (wallstreetmojo.com)

• com: It is used for trade, market, and pricing functionality.
• core: It is used in the representation of types and functions of financial quantities.
• date_time: It is used in the manipulation and calculation of date and time.
• market: It is used in the representation of types and functions of common curves and surfaces in financial programming (e.g., volatility surfaces, discount factor curves, etc.).
• math: It is used for general mathematical algorithms.
• model: It is used for coding various numerical pricing models.
• pricer: It is for types and functions used for valuing .
• text: It is used for the test suite.
• utility: It is used for tasks that are general in nature (e.g., algorithms for searching and sorting).

### Mathematical Tools for Python

Some of the major mathematical tools available in Python are as follows:

For eg:
Source: Financial Modeling in Python (wallstreetmojo.com)

1. N(.): It is a function in the ppf.math.special functions module that helps in the approximation of the standard normal cumulative distribution function, which is used in the Black–Scholes option pricing model.
2. Interpolation: It is the process that is used to estimate the values of a function y(x) for arguments between several known data points (x0, y0), (x1, y1) . . . , (xn, yn). The ppf.utility.bound module is used in its implementation. Some of the variants of interpolation are:
3. Root Finding: It is used to find the root with or without derivative information using the ppf.math.root finding module. Some of the variants of root finding are:
1. Bisection method
2. Newton-Raphson method
4. Linear Algebra: The linear algebra functions are mostly covered in the NumPy package. It is implemented using the ppf.math.linear-algebra module. Some of the variants of linear algebra are:
1. Matrix Multiplication
2. Matrix Inversion
3. Matrix Pseudo-Inverse
4. Solving Linear Systems
5. Solving Tridiagonal Systems
5. Generalized Linear Least Squares: It is the process that is used to fit a set of data points to a linear combination of some basic functions. The algorithms for this function are implemented using the ppf.math.generalized least squares module.
6. Quadratic and Cubic Roots: These functions are used to find the real roots of a quadratic or cubic equation. The ppf.math.quadratic roots module is used to find the real roots of a quadratic equation, while the ppf.math.cubic roots module is used for the cubic roots algorithm.
7. Integration: This tool is used to calculate the of a function with random variables. It is primarily used in the calculation of financial payoffs. Some of the variants of integration are:
1. Piecewise Constant Polynomial Fitting
2. Piecewise Polynomial Integration
3. Semi-analytic Conditional Expectations

### Extending Python

There are certain limitations in Python that can be overcome with the extension modules using C. These extension modules can be used to add new built-in object types to Python and can call functions from the C library. A certain set of functions, macros, and variables available in Python API to support such extensions. The header ‘Python.h’ is included in a C source file for Python API.

### Python Excel Integration

Some of the Python Excel integration tools that can be used to supercharge the existing excel functionality are as follows:

• xlwings: This package can be used to move the backend processing from VBA to Python. After that, the users can continue using Excel seamlessly while using each control button to call Python scripts.
• Jupyter Notebook: It allows users to leverage Python for creating interactive, shareable, and web-based documents that can contain visualizations, code, and text.
• Pandas Library: It can be used to quickly load data from excel spreadsheets into SQL database or pandas DataFrames. In either case, data can be analyzed and explored swiftly.

### Python Data Model

Objects are the underlying essence of a Python data model. All the data in a Python program is either represented by objects straightaway or by the relationship between objects. An object can be recognized by its identity, type, and value.

1. Identity: It refers to the address of an object in the memory, and it never changes once created.
2. Type: It defines the operations that an object supports along with the possible value for that object type.
3. Value: The value of an object may change. The ones that change are known as mutable, while the unchangeable ones are known as immutable.

• It is a pure scripting language as it uses simple syntax and cross-platform support.
• It doesn’t have a compiler like other languages.
• It lacks scalability, and as such, it can’t support any significantly large user base.
• It is perceived to be very slow.
• It doesn’t support concurrency.

### Significance of Financial Modeling in Python

Python has grown to become one of the most popular programming languages used for . Companies nowadays seek innovative tools for handling large volumes of financial data in a much easier way and Python fits into that criteria perfectly.

### Recommended Articles

This has been a guide to Financial Modeling in Python. Here we discuss the PPF package and excel integration for python with mathematical tools and significance. You can learn more about from the following articles –